26 #if defined (HAVE_CONFIG_H)
58 #include "mx-fcm-fs.h"
59 #include "mx-fs-fcm.h"
105 template <
typename R>
112 template <
typename U>
136 template <
typename R>
174 template <
typename R>
179 template <
typename U>
192 template <
typename R>
197 template <
typename U>
213 template <
typename R>
218 template <
typename U>
234 template <
typename R>
239 template <
typename U>
242 if (val !=
static_cast<U
> (0)) ++
m_num;
253 template <
typename T,
typename R,
typename ACC>
263 template <
typename T,
typename R,
typename ACC>
271 accj.accum (
m(i, j));
273 res.
xelem (j) = accj;
277 template <
typename T,
typename R,
typename ACC>
281 std::vector<ACC> acci (
m.rows (), acc);
285 acci[i].accum (
m(i, j));
289 res.
xelem (i) = acci[i];
293 template <
typename T,
typename R,
typename ACC>
301 accj.accum (
m.data (k));
303 res.
xelem (j) = accj;
307 template <
typename T,
typename R,
typename ACC>
311 std::vector<ACC> acci (
m.rows (), acc);
315 acci[
m.ridx (k)].accum (
m.data (k));
319 res.
xelem (i) = acci[i];
323 #define DEFINE_DISPATCHER(FCN_NAME, ARG_TYPE, RES_TYPE) \
324 template <typename T, typename R> \
325 RES_TYPE FCN_NAME (const ARG_TYPE& v, R p) \
329 FCN_NAME (v, res, norm_accumulator_2<R> ()); \
331 FCN_NAME (v, res, norm_accumulator_1<R> ()); \
332 else if (lo_ieee_isinf (p)) \
335 FCN_NAME (v, res, norm_accumulator_inf<R> ()); \
337 FCN_NAME (v, res, norm_accumulator_minf<R> ()); \
340 FCN_NAME (v, res, norm_accumulator_0<R> ()); \
342 FCN_NAME (v, res, norm_accumulator_p<R> (p)); \
344 FCN_NAME (v, res, norm_accumulator_mp<R> (p)); \
358 template <typename ColVectorT, typename R>
367 R
fi = i *
static_cast<R
> (M_PI) / nsamp;
368 R lambda1 = cos (
fi);
372 lambda1 /= lmnr; mu1 /= lmnr;
386 template <
typename ColVectorT,
typename R>
390 std::complex<R>& lambda, std::complex<R>& mu)
392 typedef std::complex<R> CR;
395 CR lamcu = lambda /
std::abs (lambda);
400 R
fi = i *
static_cast<R
> (M_PI) / nsamp;
401 R lambda1 = cos (
fi);
405 lambda1 /= lmnr; mu1 /= lmnr;
406 R nrm1 =
vector_norm (lambda1 * lamcu * y + mu1 * col, p);
409 lambda = lambda1 * lamcu;
419 R
fi = i *
static_cast<R
> (M_PI) / nsamp;
420 lamcu = CR (cos (
fi), sin (
fi));
421 R nrm1 =
vector_norm (lama * lamcu * y + mu * col, p);
424 lambda = lama * lamcu;
431 template <
typename T,
typename R>
441 template <
typename VectorT,
typename R>
444 VectorT res (
x.dims ());
451 template <
typename MatrixT,
typename VectorT,
typename R>
452 R
higham (
const MatrixT&
m, R p, R tol,
int maxiter,
455 x.resize (
m.columns (), 1);
457 VectorT y(
m.rows (), 1, 0), z(
m.rows (), 1);
458 typedef typename VectorT::element_type RR;
464 VectorT col (
m.column (k));
470 y = lambda * y + mu * col;
479 while (iter < maxiter)
511 template <
typename MatrixT,
typename VectorT,
typename R>
521 math::svd<MatrixT> fact (
m, math::svd<MatrixT>::Type::sigma_only);
522 res = fact.singular_values () (0, 0);
531 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
541 template <
typename MatrixT,
typename VectorT,
typename R>
556 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
567 #define DEFINE_XNORM_FCNS(PREFIX, RTYPE) \
568 RTYPE xnorm (const PREFIX##ColumnVector& x, RTYPE p) \
570 return vector_norm (x, p); \
572 RTYPE xnorm (const PREFIX##RowVector& x, RTYPE p) \
574 return vector_norm (x, p); \
576 RTYPE xnorm (const PREFIX##Matrix& x, RTYPE p) \
578 return svd_matrix_norm (x, p, PREFIX##Matrix ()); \
580 RTYPE xfrobnorm (const PREFIX##Matrix& x) \
582 return vector_norm (x, static_cast<RTYPE> (2)); \
591 template <typename T, typename R>
601 #define DEFINE_XNORM_SPARSE_FCNS(PREFIX, RTYPE) \
602 RTYPE xnorm (const Sparse##PREFIX##Matrix& x, RTYPE p) \
604 return matrix_norm (x, p, PREFIX##Matrix ()); \
606 RTYPE xfrobnorm (const Sparse##PREFIX##Matrix& x) \
609 array_norm_2 (x.data (), x.nnz (), res); \
616 #define DEFINE_COLROW_NORM_FCNS(PREFIX, RPREFIX, RTYPE) \
618 xcolnorms (const PREFIX##Matrix& m, RTYPE p) \
620 return column_norms (m, p); \
622 RPREFIX##ColumnVector \
623 xrownorms (const PREFIX##Matrix& m, RTYPE p) \
625 return row_norms (m, p); \
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
OCTAVE_API double max(void) const
Template for N-dimensional array classes with like-type math operators.
OCTAVE_API double max(void) const
Vector representing the dimensions (size) of an Array.
void accum(std::complex< R > val)
norm_accumulator_mp(R pp)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_DBLE * x
std::complex< double > Complex
std::complex< float > FloatComplex
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
VectorT dual_p(const VectorT &x, R p, R q)
void array_norm_2(const T *v, octave_idx_type n, R &res)
R matrix_norm(const MatrixT &m, R p, VectorT)
#define DEFINE_COLROW_NORM_FCNS(PREFIX, RPREFIX, RTYPE)
RowVector xcolnorms(const Matrix &m, double p)
void column_norms(const MArray< T > &m, MArray< R > &res, ACC acc)
static const char * p_less1_gripe
ColumnVector xrownorms(const Matrix &m, double p)
static void higham_subp(const ColVectorT &y, const ColVectorT &col, octave_idx_type nsamp, R p, R &lambda, R &mu)
#define DEFINE_XNORM_SPARSE_FCNS(PREFIX, RTYPE)
void vector_norm(const Array< T > &v, R &res, ACC acc)
void row_norms(const MArray< T > &m, MArray< R > &res, ACC acc)
R svd_matrix_norm(const MatrixT &m, R p, VectorT)
R higham(const MatrixT &m, R p, R tol, int maxiter, VectorT &x)
#define DEFINE_XNORM_FCNS(PREFIX, RTYPE)
#define DEFINE_DISPATCHER(FCN_NAME, ARG_TYPE, RES_TYPE)