26 #if defined (HAVE_CONFIG_H)
58 #include "mx-fcm-fs.h"
59 #include "mx-fs-fcm.h"
107 template <
typename U>
127 template <
typename R>
156 operator R () {
return scl * std::sqrt (
sum); }
160 template <
typename R>
166 template <
typename U>
171 operator R () {
return sum; }
175 template <
typename R>
181 template <
typename U>
189 operator R () {
return max; }
193 template <
typename R>
199 template <
typename U>
207 operator R () {
return min; }
211 template <
typename R>
217 template <
typename U>
220 if (val !=
static_cast<U
> (0)) ++
num;
222 operator R () {
return num; }
227 template <
typename T,
typename R,
typename ACC>
237 template <
typename T,
typename R,
typename ACC>
245 accj.accum (
m(i, j));
247 res.
xelem (j) = accj;
251 template <
typename T,
typename R,
typename ACC>
255 std::vector<ACC> acci (
m.rows (), acc);
259 acci[i].accum (
m(i, j));
263 res.
xelem (i) = acci[i];
267 template <
typename T,
typename R,
typename ACC>
275 accj.accum (
m.data (k));
277 res.
xelem (j) = accj;
281 template <
typename T,
typename R,
typename ACC>
285 std::vector<ACC> acci (
m.rows (), acc);
289 acci[
m.ridx (k)].accum (
m.data (k));
293 res.
xelem (i) = acci[i];
297 #define DEFINE_DISPATCHER(FUNC_NAME, ARG_TYPE, RES_TYPE) \
298 template <typename T, typename R> \
299 RES_TYPE FUNC_NAME (const ARG_TYPE& v, R p) \
303 FUNC_NAME (v, res, norm_accumulator_2<R> ()); \
305 FUNC_NAME (v, res, norm_accumulator_1<R> ()); \
306 else if (lo_ieee_isinf (p)) \
309 FUNC_NAME (v, res, norm_accumulator_inf<R> ()); \
311 FUNC_NAME (v, res, norm_accumulator_minf<R> ()); \
314 FUNC_NAME (v, res, norm_accumulator_0<R> ()); \
316 FUNC_NAME (v, res, norm_accumulator_p<R> (p)); \
318 FUNC_NAME (v, res, norm_accumulator_mp<R> (p)); \
331 template <typename ColVectorT, typename R>
340 R
fi = i *
static_cast<R
> (M_PI) / nsamp;
341 R lambda1 = cos (
fi);
345 lambda1 /= lmnr; mu1 /= lmnr;
359 template <
typename ColVectorT,
typename R>
363 std::complex<R>& lambda, std::complex<R>& mu)
365 typedef std::complex<R> CR;
368 CR lamcu = lambda /
std::abs (lambda);
373 R
fi = i *
static_cast<R
> (M_PI) / nsamp;
374 R lambda1 = cos (
fi);
378 lambda1 /= lmnr; mu1 /= lmnr;
379 R nrm1 =
vector_norm (lambda1 * lamcu * y + mu1 * col, p);
382 lambda = lambda1 * lamcu;
392 R
fi = i *
static_cast<R
> (M_PI) / nsamp;
393 lamcu = CR (cos (
fi), sin (
fi));
394 R nrm1 =
vector_norm (lama * lamcu * y + mu * col, p);
397 lambda = lama * lamcu;
404 template <
typename T,
typename R>
414 template <
typename VectorT,
typename R>
417 VectorT res (
x.dims ());
424 template <
typename MatrixT,
typename VectorT,
typename R>
425 R
higham (
const MatrixT&
m, R p, R tol,
int maxiter,
428 x.resize (
m.columns (), 1);
430 VectorT y(
m.rows (), 1, 0), z(
m.rows (), 1);
431 typedef typename VectorT::element_type RR;
437 VectorT col (
m.column (k));
443 y = lambda * y + mu * col;
452 while (iter < maxiter)
484 template <
typename MatrixT,
typename VectorT,
typename R>
501 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
511 template <
typename MatrixT,
typename VectorT,
typename R>
522 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
533 #define DEFINE_XNORM_FUNCS(PREFIX, RTYPE) \
534 OCTAVE_API RTYPE xnorm (const PREFIX##ColumnVector& x, RTYPE p) \
536 return vector_norm (x, p); \
538 OCTAVE_API RTYPE xnorm (const PREFIX##RowVector& x, RTYPE p) \
540 return vector_norm (x, p); \
542 OCTAVE_API RTYPE xnorm (const PREFIX##Matrix& x, RTYPE p) \
544 return svd_matrix_norm (x, p, PREFIX##Matrix ()); \
546 OCTAVE_API RTYPE xfrobnorm (const PREFIX##Matrix& x) \
548 return vector_norm (x, static_cast<RTYPE> (2)); \
557 template <typename T, typename R>
567 #define DEFINE_XNORM_SPARSE_FUNCS(PREFIX, RTYPE) \
568 OCTAVE_API RTYPE xnorm (const Sparse##PREFIX##Matrix& x, RTYPE p) \
570 return matrix_norm (x, p, PREFIX##Matrix ()); \
572 OCTAVE_API RTYPE xfrobnorm (const Sparse##PREFIX##Matrix& x) \
575 array_norm_2 (x.data (), x.nnz (), res); \
582 #define DEFINE_COLROW_NORM_FUNCS(PREFIX, RPREFIX, RTYPE) \
583 extern OCTAVE_API RPREFIX##RowVector \
584 xcolnorms (const PREFIX##Matrix& m, RTYPE p) \
586 return column_norms (m, p); \
588 extern OCTAVE_API RPREFIX##ColumnVector \
589 xrownorms (const PREFIX##Matrix& m, RTYPE p) \
591 return row_norms (m, p); \
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
N Dimensional Array with copy-on-write semantics.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
Template for N-dimensional array classes with like-type math operators.
Vector representing the dimensions (size) of an Array.
void accum(std::complex< R > val)
norm_accumulator_mp(R pp)
DM_T singular_values(void) const
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_XNORM_SPARSE_FUNCS(PREFIX, RTYPE)
OCTAVE_API RowVector xcolnorms(const Matrix &m, double p)
#define DEFINE_COLROW_NORM_FUNCS(PREFIX, RPREFIX, RTYPE)
void column_norms(const MArray< T > &m, MArray< R > &res, ACC acc)
static const char * p_less1_gripe
static void higham_subp(const ColVectorT &y, const ColVectorT &col, octave_idx_type nsamp, R p, R &lambda, R &mu)
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)
#define DEFINE_DISPATCHER(FUNC_NAME, ARG_TYPE, RES_TYPE)
R higham(const MatrixT &m, R p, R tol, int maxiter, VectorT &x)
OCTAVE_API ColumnVector xrownorms(const Matrix &m, double p)
#define DEFINE_XNORM_FUNCS(PREFIX, RTYPE)