151 operator R () {
return scl * std::sqrt (
sum); }
166 operator R () {
return sum; }
181 operator R () {
return max; }
196 operator R () {
return min; }
209 if (val != static_cast<U> (0)) ++
num;
211 operator R () {
return num; }
217 template <
class T,
class R,
class ACC>
227 template <
class T,
class R,
class ACC>
235 accj.accum (m(i, j));
237 res.
xelem (j) = accj;
241 template <
class T,
class R,
class ACC>
245 std::vector<ACC> acci (m.
rows (), acc);
249 acci[i].accum (m(i, j));
253 res.
xelem (i) = acci[i];
257 template <
class T,
class R,
class ACC>
265 accj.accum (m.
data (k));
267 res.
xelem (j) = accj;
271 template <
class T,
class R,
class ACC>
275 std::vector<ACC> acci (m.
rows (), acc);
279 acci[m.
ridx (k)].accum (m.
data (k));
283 res.
xelem (i) = acci[i];
287 #define DEFINE_DISPATCHER(FUNC_NAME, ARG_TYPE, RES_TYPE) \
288 template <class T, class R> \
289 RES_TYPE FUNC_NAME (const ARG_TYPE& v, R p) \
293 FUNC_NAME (v, res, norm_accumulator_2<R> ()); \
295 FUNC_NAME (v, res, norm_accumulator_1<R> ()); \
296 else if (lo_ieee_isinf (p)) \
299 FUNC_NAME (v, res, norm_accumulator_inf<R> ()); \
301 FUNC_NAME (v, res, norm_accumulator_minf<R> ()); \
304 FUNC_NAME (v, res, norm_accumulator_0<R> ()); \
306 FUNC_NAME (v, res, norm_accumulator_p<R> (p)); \
308 FUNC_NAME (v, res, norm_accumulator_mp<R> (p)); \
321 template <class ColVectorT, class R>
330 R
fi = i*M_PI/nsamp, lambda1 = cos (fi), mu1 = sin (fi);
333 lambda1 /= lmnr; mu1 /= lmnr;
347 template <
class ColVectorT,
class R>
351 std::complex<R>& lambda, std::complex<R>& mu)
353 typedef std::complex<R> CR;
356 CR lamcu = lambda /
std::abs (lambda);
361 R
fi = i*M_PI/nsamp, lambda1 = cos (fi), mu1 = sin (fi);
364 lambda1 /= lmnr; mu1 /= lmnr;
365 R nrm1 =
vector_norm (lambda1 * lamcu * y + mu1 * col, p);
368 lambda = lambda1 * lamcu;
379 lamcu = CR (cos (fi), sin (fi));
380 R nrm1 =
vector_norm (lama * lamcu * y + mu * col, p);
383 lambda = lama * lamcu;
390 template <
class T,
class R>
400 template <
class VectorT,
class R>
403 VectorT res (x.dims ());
410 template <
class MatrixT,
class VectorT,
class R>
411 R
higham (
const MatrixT& m, R p, R tol,
int maxiter,
414 x.resize (m.columns (), 1);
416 VectorT y(m.rows (), 1, 0), z(m.rows (), 1);
417 typedef typename VectorT::element_type RR;
418 RR lambda = 0, mu = 1;
422 VectorT col (m.column (k));
428 y = lambda * y + mu * col;
437 while (iter < maxiter)
448 || (gamma - gamma1) <= tol*gamma))
469 template <
class MatrixT,
class VectorT,
class SVDT,
class R>
476 res = svd.singular_values () (0,0);
485 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
486 res =
higham (m, p, sqrteps, max_norm_iter, x);
495 template <
class MatrixT,
class VectorT,
class R>
506 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
507 res =
higham (m, p, sqrteps, max_norm_iter, x);
517 #define DEFINE_XNORM_FUNCS(PREFIX, RTYPE) \
518 OCTAVE_API RTYPE xnorm (const PREFIX##ColumnVector& x, RTYPE p) \
519 { return vector_norm (x, p); } \
520 OCTAVE_API RTYPE xnorm (const PREFIX##RowVector& x, RTYPE p) \
521 { return vector_norm (x, p); } \
522 OCTAVE_API RTYPE xnorm (const PREFIX##Matrix& x, RTYPE p) \
523 { return matrix_norm (x, p, PREFIX##Matrix (), PREFIX##SVD ()); } \
524 OCTAVE_API RTYPE xfrobnorm (const PREFIX##Matrix& x) \
525 { return vector_norm (x, static_cast<RTYPE> (2)); }
533 template <class T, class R>
543 #define DEFINE_XNORM_SPARSE_FUNCS(PREFIX, RTYPE) \
544 OCTAVE_API RTYPE xnorm (const Sparse##PREFIX##Matrix& x, RTYPE p) \
545 { return matrix_norm (x, p, PREFIX##Matrix ()); } \
546 OCTAVE_API RTYPE xfrobnorm (const Sparse##PREFIX##Matrix& x) \
549 array_norm_2 (x.data (), x.nnz (), res); \
556 #define DEFINE_COLROW_NORM_FUNCS(PREFIX, RPREFIX, RTYPE) \
557 extern OCTAVE_API RPREFIX##RowVector xcolnorms (const PREFIX##Matrix& m, RTYPE p) \
558 { return column_norms (m, p); } \
559 extern OCTAVE_API RPREFIX##ColumnVector xrownorms (const PREFIX##Matrix& m, RTYPE p) \
560 { return row_norms (m, p); } \