GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-norm.cc File Reference
#include <cmath>
#include <algorithm>
#include <limits>
#include <vector>
#include "Array.h"
#include "CColVector.h"
#include "CMatrix.h"
#include "CRowVector.h"
#include "CSparse.h"
#include "MArray.h"
#include "dColVector.h"
#include "dDiagMatrix.h"
#include "dMatrix.h"
#include "dRowVector.h"
#include "dSparse.h"
#include "fCColVector.h"
#include "fCMatrix.h"
#include "fCRowVector.h"
#include "fColVector.h"
#include "fDiagMatrix.h"
#include "fMatrix.h"
#include "fRowVector.h"
#include "lo-error.h"
#include "lo-ieee.h"
#include "lo-mappers.h"
#include "mx-cm-s.h"
#include "mx-fcm-fs.h"
#include "mx-fs-fcm.h"
#include "mx-s-cm.h"
#include "oct-cmplx.h"
#include "quit.h"
#include "svd.h"
Include dependency graph for oct-norm.cc:

Go to the source code of this file.

Classes

class  norm_accumulator_0< R >
 
class  norm_accumulator_1< R >
 
class  norm_accumulator_2< R >
 
class  norm_accumulator_inf< R >
 
class  norm_accumulator_minf< R >
 
class  norm_accumulator_mp< R >
 
class  norm_accumulator_p< R >
 

Macros

#define DEFINE_COLROW_NORM_FUNCS(PREFIX, RPREFIX, RTYPE)
 
#define DEFINE_DISPATCHER(FUNC_NAME, ARG_TYPE, RES_TYPE)
 
#define DEFINE_XNORM_FUNCS(PREFIX, RTYPE)
 
#define DEFINE_XNORM_SPARSE_FUNCS(PREFIX, RTYPE)
 

Functions

template<typename T , typename R >
void array_norm_2 (const T *v, octave_idx_type n, R &res)
 
template<typename T , typename R , typename ACC >
void column_norms (const MArray< T > &m, MArray< R > &res, ACC acc)
 
template<typename T , typename R , typename ACC >
void column_norms (const MSparse< T > &m, MArray< R > &res, ACC acc)
 
template<typename T , typename R >
MArray< R > column_norms (const MArray< T > &v, R p)
 
template<typename T , typename R >
MArray< R > column_norms (const MSparse< T > &v, R p)
 
template<typename VectorT , typename R >
VectorT dual_p (const VectorT &x, R p, R q)
 
template<typename T , typename R >
elem_dual_p (T x, R p)
 
template<typename MatrixT , typename VectorT , typename R >
higham (const MatrixT &m, R p, R tol, int maxiter, VectorT &x)
 
template<typename ColVectorT , typename R >
static void higham_subp (const ColVectorT &y, const ColVectorT &col, octave_idx_type nsamp, R p, R &lambda, R &mu)
 
template<typename ColVectorT , typename R >
static void higham_subp (const ColVectorT &y, const ColVectorT &col, octave_idx_type nsamp, R p, std::complex< R > &lambda, std::complex< R > &mu)
 
template<typename MatrixT , typename VectorT , typename R >
matrix_norm (const MatrixT &m, R p, VectorT)
 
template<typename T , typename R , typename ACC >
void row_norms (const MArray< T > &m, MArray< R > &res, ACC acc)
 
template<typename T , typename R , typename ACC >
void row_norms (const MSparse< T > &m, MArray< R > &res, ACC acc)
 
template<typename T , typename R >
MArray< R > row_norms (const MArray< T > &v, R p)
 
template<typename T , typename R >
MArray< R > row_norms (const MSparse< T > &v, R p)
 
template<typename MatrixT , typename VectorT , typename R >
svd_matrix_norm (const MatrixT &m, R p, VectorT)
 
template<typename T , typename R , typename ACC >
void vector_norm (const Array< T > &v, R &res, ACC acc)
 
template<typename T , typename R >
vector_norm (const MArray< T > &v, R p)
 
OCTAVE_API RowVector xcolnorms (const Matrix &m, double p)
 
OCTAVE_API RowVector xcolnorms (const ComplexMatrix &m, double p)
 
OCTAVE_API FloatRowVector xcolnorms (const FloatMatrix &m, float p)
 
OCTAVE_API FloatRowVector xcolnorms (const FloatComplexMatrix &m, float p)
 
OCTAVE_API RowVector xcolnorms (const SparseMatrix &m, double p)
 
OCTAVE_API RowVector xcolnorms (const SparseComplexMatrix &m, double p)
 
OCTAVE_API double xfrobnorm (const Matrix &x)
 
OCTAVE_API double xfrobnorm (const ComplexMatrix &x)
 
OCTAVE_API float xfrobnorm (const FloatMatrix &x)
 
OCTAVE_API float xfrobnorm (const FloatComplexMatrix &x)
 
OCTAVE_API double xfrobnorm (const SparseMatrix &x)
 
OCTAVE_API double xfrobnorm (const SparseComplexMatrix &x)
 
OCTAVE_API double xnorm (const ColumnVector &x, double p)
 
OCTAVE_API double xnorm (const Matrix &x, double p)
 
OCTAVE_API double xnorm (const RowVector &x, double p)
 
OCTAVE_API double xnorm (const ComplexMatrix &x, double p)
 
OCTAVE_API double xnorm (const ComplexRowVector &x, double p)
 
OCTAVE_API double xnorm (const ComplexColumnVector &x, double p)
 
OCTAVE_API float xnorm (const FloatRowVector &x, float p)
 
OCTAVE_API float xnorm (const FloatMatrix &x, float p)
 
OCTAVE_API float xnorm (const FloatColumnVector &x, float p)
 
OCTAVE_API float xnorm (const FloatComplexRowVector &x, float p)
 
OCTAVE_API float xnorm (const FloatComplexMatrix &x, float p)
 
OCTAVE_API float xnorm (const FloatComplexColumnVector &x, float p)
 
OCTAVE_API double xnorm (const SparseMatrix &x, double p)
 
OCTAVE_API double xnorm (const SparseComplexMatrix &x, double p)
 
OCTAVE_API ColumnVector xrownorms (const Matrix &m, double p)
 
OCTAVE_API ColumnVector xrownorms (const ComplexMatrix &m, double p)
 
OCTAVE_API FloatColumnVector xrownorms (const FloatMatrix &m, float p)
 
OCTAVE_API FloatColumnVector xrownorms (const FloatComplexMatrix &m, float p)
 
OCTAVE_API ColumnVector xrownorms (const SparseMatrix &m, double p)
 
OCTAVE_API ColumnVector xrownorms (const SparseComplexMatrix &m, double p)
 

Variables

static int max_norm_iter = 100
 
static const char * p_less1_gripe = "xnorm: p must be >= 1"
 

Macro Definition Documentation

◆ DEFINE_COLROW_NORM_FUNCS

#define DEFINE_COLROW_NORM_FUNCS (   PREFIX,
  RPREFIX,
  RTYPE 
)
Value:
extern OCTAVE_API RPREFIX##RowVector \
xcolnorms (const PREFIX##Matrix& m, RTYPE p) \
{ \
return column_norms (m, p); \
} \
extern OCTAVE_API RPREFIX##ColumnVector \
xrownorms (const PREFIX##Matrix& m, RTYPE p) \
{ \
return row_norms (m, p); \
} \
OCTAVE_API ColumnVector xrownorms(const Matrix &m, double p)
Definition: oct-norm.cc:593
const char * PREFIX
OCTAVE_API RowVector xcolnorms(const Matrix &m, double p)
Definition: oct-norm.cc:593
Definition: dMatrix.h:36
p
Definition: lu.cc:138
void row_norms(const MArray< T > &m, MArray< R > &res, ACC acc)
Definition: oct-norm.cc:251
void column_norms(const MArray< T > &m, MArray< R > &res, ACC acc)
Definition: oct-norm.cc:237

Definition at line 581 of file oct-norm.cc.

◆ DEFINE_DISPATCHER

#define DEFINE_DISPATCHER (   FUNC_NAME,
  ARG_TYPE,
  RES_TYPE 
)
Value:
template <typename T, typename R> \
RES_TYPE FUNC_NAME (const ARG_TYPE& v, R p) \
{ \
RES_TYPE res; \
if (p == 2) \
FUNC_NAME (v, res, norm_accumulator_2<R> ()); \
else if (p == 1) \
FUNC_NAME (v, res, norm_accumulator_1<R> ()); \
else if (lo_ieee_isinf (p)) \
{ \
if (p > 0) \
FUNC_NAME (v, res, norm_accumulator_inf<R> ()); \
else \
FUNC_NAME (v, res, norm_accumulator_minf<R> ()); \
} \
else if (p == 0) \
FUNC_NAME (v, res, norm_accumulator_0<R> ()); \
else if (p > 0) \
FUNC_NAME (v, res, norm_accumulator_p<R> (p)); \
else \
FUNC_NAME (v, res, norm_accumulator_mp<R> (p)); \
return res; \
}
#define lo_ieee_isinf(x)
Definition: lo-ieee.h:113
p
Definition: lu.cc:138

Definition at line 296 of file oct-norm.cc.

◆ DEFINE_XNORM_FUNCS

#define DEFINE_XNORM_FUNCS (   PREFIX,
  RTYPE 
)
Value:
OCTAVE_API RTYPE xnorm (const PREFIX##ColumnVector& x, RTYPE p) \
{ \
return vector_norm (x, p); \
} \
OCTAVE_API RTYPE xnorm (const PREFIX##RowVector& x, RTYPE p) \
{ \
return vector_norm (x, p); \
} \
OCTAVE_API RTYPE xnorm (const PREFIX##Matrix& x, RTYPE p) \
{ \
return svd_matrix_norm (x, p, PREFIX##Matrix ()); \
} \
OCTAVE_API RTYPE xfrobnorm (const PREFIX##Matrix& x) \
{ \
return vector_norm (x, static_cast<RTYPE> (2)); \
}
const char * PREFIX
OCTAVE_API double xnorm(const ColumnVector &x, double p)
Definition: oct-norm.cc:550
Definition: dMatrix.h:36
OCTAVE_API double xfrobnorm(const Matrix &x)
Definition: oct-norm.cc:550
p
Definition: lu.cc:138
void vector_norm(const Array< T > &v, R &res, ACC acc)
Definition: oct-norm.cc:227
R svd_matrix_norm(const MatrixT &m, R p, VectorT)
Definition: oct-norm.cc:484
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x

Definition at line 532 of file oct-norm.cc.

◆ DEFINE_XNORM_SPARSE_FUNCS

#define DEFINE_XNORM_SPARSE_FUNCS (   PREFIX,
  RTYPE 
)
Value:
OCTAVE_API RTYPE xnorm (const Sparse##PREFIX##Matrix& x, RTYPE p) \
{ \
return matrix_norm (x, p, PREFIX##Matrix ()); \
} \
OCTAVE_API RTYPE xfrobnorm (const Sparse##PREFIX##Matrix& x) \
{ \
RTYPE res; \
array_norm_2 (x.data (), x.nnz (), res); \
return res; \
}
const char * PREFIX
OCTAVE_API double xnorm(const ColumnVector &x, double p)
Definition: oct-norm.cc:550
R matrix_norm(const MatrixT &m, R p, VectorT)
Definition: oct-norm.cc:511
Definition: dMatrix.h:36
OCTAVE_API double xfrobnorm(const Matrix &x)
Definition: oct-norm.cc:550
p
Definition: lu.cc:138
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x

Definition at line 566 of file oct-norm.cc.

Function Documentation

◆ array_norm_2()

template<typename T , typename R >
void array_norm_2 ( const T *  v,
octave_idx_type  n,
R &  res 
)
inline

Definition at line 557 of file oct-norm.cc.

References norm_accumulator_2< R >::accum(), and i.

◆ column_norms() [1/4]

template<typename T , typename R , typename ACC >
void column_norms ( const MArray< T > &  m,
MArray< R > &  res,
ACC  acc 
)

Definition at line 237 of file oct-norm.cc.

References Array< T >::columns(), i, Array< T >::rows(), and Array< T >::xelem().

◆ column_norms() [2/4]

template<typename T , typename R , typename ACC >
void column_norms ( const MSparse< T > &  m,
MArray< R > &  res,
ACC  acc 
)

◆ column_norms() [3/4]

template<typename T , typename R >
MArray<R> column_norms ( const MArray< T > &  v,
p 
)

Definition at line 322 of file oct-norm.cc.

◆ column_norms() [4/4]

template<typename T , typename R >
MArray<R> column_norms ( const MSparse< T > &  v,
p 
)

Definition at line 324 of file oct-norm.cc.

◆ dual_p()

template<typename VectorT , typename R >
VectorT dual_p ( const VectorT &  x,
p,
q 
)

Definition at line 414 of file oct-norm.cc.

References elem_dual_p(), i, p, vector_norm(), and x.

Referenced by higham().

◆ elem_dual_p()

template<typename T , typename R >
T elem_dual_p ( x,
p 
)
inline

Definition at line 404 of file oct-norm.cc.

References abs(), p, pow(), octave::math::signum(), and x.

Referenced by dual_p().

◆ higham()

template<typename MatrixT , typename VectorT , typename R >
R higham ( const MatrixT &  m,
p,
tol,
int  maxiter,
VectorT &  x 
)

Definition at line 424 of file oct-norm.cc.

References dual_p(), octave::math::gamma(), higham_subp(), i, k, p, vector_norm(), x, and y.

Referenced by matrix_norm(), and svd_matrix_norm().

◆ higham_subp() [1/2]

template<typename ColVectorT , typename R >
static void higham_subp ( const ColVectorT &  y,
const ColVectorT &  col,
octave_idx_type  nsamp,
p,
R &  lambda,
R &  mu 
)
static

Definition at line 332 of file oct-norm.cc.

References abs(), fi, i, p, pow(), vector_norm(), and y.

Referenced by higham().

◆ higham_subp() [2/2]

template<typename ColVectorT , typename R >
static void higham_subp ( const ColVectorT &  y,
const ColVectorT &  col,
octave_idx_type  nsamp,
p,
std::complex< R > &  lambda,
std::complex< R > &  mu 
)
static

Definition at line 360 of file oct-norm.cc.

References abs(), fi, i, p, pow(), vector_norm(), and y.

◆ matrix_norm()

template<typename MatrixT , typename VectorT , typename R >
R matrix_norm ( const MatrixT &  m,
p,
VectorT   
)

◆ row_norms() [1/4]

template<typename T , typename R , typename ACC >
void row_norms ( const MArray< T > &  m,
MArray< R > &  res,
ACC  acc 
)

Definition at line 251 of file oct-norm.cc.

References Array< T >::columns(), i, Array< T >::rows(), and Array< T >::xelem().

◆ row_norms() [2/4]

template<typename T , typename R , typename ACC >
void row_norms ( const MSparse< T > &  m,
MArray< R > &  res,
ACC  acc 
)

◆ row_norms() [3/4]

template<typename T , typename R >
MArray<R> row_norms ( const MArray< T > &  v,
p 
)

Definition at line 323 of file oct-norm.cc.

◆ row_norms() [4/4]

template<typename T , typename R >
MArray<R> row_norms ( const MSparse< T > &  v,
p 
)

Definition at line 325 of file oct-norm.cc.

◆ svd_matrix_norm()

template<typename MatrixT , typename VectorT , typename R >
R svd_matrix_norm ( const MatrixT &  m,
p,
VectorT   
)

◆ vector_norm() [1/2]

template<typename T , typename R , typename ACC >
void vector_norm ( const Array< T > &  v,
R &  res,
ACC  acc 
)
inline

Definition at line 227 of file oct-norm.cc.

References i, and Array< T >::numel().

Referenced by dual_p(), higham(), and higham_subp().

◆ vector_norm() [2/2]

template<typename T , typename R >
R vector_norm ( const MArray< T > &  v,
p 
)

Definition at line 321 of file oct-norm.cc.

◆ xcolnorms() [1/6]

OCTAVE_API RowVector xcolnorms ( const Matrix m,
double  p 
)

Definition at line 593 of file oct-norm.cc.

Referenced by F__icholt__(), matrix_norm(), and svd_matrix_norm().

◆ xcolnorms() [2/6]

OCTAVE_API RowVector xcolnorms ( const ComplexMatrix m,
double  p 
)

Definition at line 594 of file oct-norm.cc.

◆ xcolnorms() [3/6]

OCTAVE_API FloatRowVector xcolnorms ( const FloatMatrix m,
float  p 
)

Definition at line 595 of file oct-norm.cc.

◆ xcolnorms() [4/6]

OCTAVE_API FloatRowVector xcolnorms ( const FloatComplexMatrix m,
float  p 
)

Definition at line 596 of file oct-norm.cc.

◆ xcolnorms() [5/6]

OCTAVE_API RowVector xcolnorms ( const SparseMatrix m,
double  p 
)

Definition at line 598 of file oct-norm.cc.

◆ xcolnorms() [6/6]

OCTAVE_API RowVector xcolnorms ( const SparseComplexMatrix m,
double  p 
)

Definition at line 599 of file oct-norm.cc.

◆ xfrobnorm() [1/6]

OCTAVE_API double xfrobnorm ( const Matrix x)

Definition at line 550 of file oct-norm.cc.

Referenced by Fsqrtm().

◆ xfrobnorm() [2/6]

OCTAVE_API double xfrobnorm ( const ComplexMatrix x)

Definition at line 551 of file oct-norm.cc.

◆ xfrobnorm() [3/6]

OCTAVE_API float xfrobnorm ( const FloatMatrix x)

Definition at line 552 of file oct-norm.cc.

◆ xfrobnorm() [4/6]

OCTAVE_API float xfrobnorm ( const FloatComplexMatrix x)

Definition at line 553 of file oct-norm.cc.

◆ xfrobnorm() [5/6]

OCTAVE_API double xfrobnorm ( const SparseMatrix x)

Definition at line 578 of file oct-norm.cc.

◆ xfrobnorm() [6/6]

OCTAVE_API double xfrobnorm ( const SparseComplexMatrix x)

Definition at line 579 of file oct-norm.cc.

◆ xnorm() [1/14]

OCTAVE_API double xnorm ( const ColumnVector x,
double  p 
)

Definition at line 550 of file oct-norm.cc.

Referenced by do_mgorth(), do_sqrtm(), and chol< T >::init().

◆ xnorm() [2/14]

OCTAVE_API double xnorm ( const Matrix x,
double  p 
)

Definition at line 550 of file oct-norm.cc.

◆ xnorm() [3/14]

OCTAVE_API double xnorm ( const RowVector x,
double  p 
)

Definition at line 550 of file oct-norm.cc.

◆ xnorm() [4/14]

OCTAVE_API double xnorm ( const ComplexMatrix x,
double  p 
)

Definition at line 551 of file oct-norm.cc.

◆ xnorm() [5/14]

OCTAVE_API double xnorm ( const ComplexRowVector x,
double  p 
)

Definition at line 551 of file oct-norm.cc.

◆ xnorm() [6/14]

OCTAVE_API double xnorm ( const ComplexColumnVector x,
double  p 
)

Definition at line 551 of file oct-norm.cc.

◆ xnorm() [7/14]

OCTAVE_API float xnorm ( const FloatRowVector x,
float  p 
)

Definition at line 552 of file oct-norm.cc.

◆ xnorm() [8/14]

OCTAVE_API float xnorm ( const FloatMatrix x,
float  p 
)

Definition at line 552 of file oct-norm.cc.

◆ xnorm() [9/14]

OCTAVE_API float xnorm ( const FloatColumnVector x,
float  p 
)

Definition at line 552 of file oct-norm.cc.

◆ xnorm() [10/14]

OCTAVE_API float xnorm ( const FloatComplexRowVector x,
float  p 
)

Definition at line 553 of file oct-norm.cc.

◆ xnorm() [11/14]

OCTAVE_API float xnorm ( const FloatComplexMatrix x,
float  p 
)

Definition at line 553 of file oct-norm.cc.

◆ xnorm() [12/14]

OCTAVE_API float xnorm ( const FloatComplexColumnVector x,
float  p 
)

Definition at line 553 of file oct-norm.cc.

◆ xnorm() [13/14]

OCTAVE_API double xnorm ( const SparseMatrix x,
double  p 
)

Definition at line 578 of file oct-norm.cc.

◆ xnorm() [14/14]

OCTAVE_API double xnorm ( const SparseComplexMatrix x,
double  p 
)

Definition at line 579 of file oct-norm.cc.

◆ xrownorms() [1/6]

OCTAVE_API ColumnVector xrownorms ( const Matrix m,
double  p 
)

Definition at line 593 of file oct-norm.cc.

Referenced by matrix_norm(), and svd_matrix_norm().

◆ xrownorms() [2/6]

OCTAVE_API ColumnVector xrownorms ( const ComplexMatrix m,
double  p 
)

Definition at line 594 of file oct-norm.cc.

◆ xrownorms() [3/6]

OCTAVE_API FloatColumnVector xrownorms ( const FloatMatrix m,
float  p 
)

Definition at line 595 of file oct-norm.cc.

◆ xrownorms() [4/6]

OCTAVE_API FloatColumnVector xrownorms ( const FloatComplexMatrix m,
float  p 
)

Definition at line 596 of file oct-norm.cc.

◆ xrownorms() [5/6]

OCTAVE_API ColumnVector xrownorms ( const SparseMatrix m,
double  p 
)

Definition at line 598 of file oct-norm.cc.

◆ xrownorms() [6/6]

OCTAVE_API ColumnVector xrownorms ( const SparseComplexMatrix m,
double  p 
)

Definition at line 599 of file oct-norm.cc.

Variable Documentation

◆ max_norm_iter

int max_norm_iter = 100
static

Definition at line 480 of file oct-norm.cc.

Referenced by matrix_norm(), and svd_matrix_norm().

◆ p_less1_gripe

const char* p_less1_gripe = "xnorm: p must be >= 1"
static

Definition at line 475 of file oct-norm.cc.

Referenced by matrix_norm(), and svd_matrix_norm().