GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-norm.cc File Reference
#include <cmath>
#include <algorithm>
#include <iostream>
#include <limits>
#include <type_traits>
#include <vector>
#include "Array-oct.h"
#include "CColVector.h"
#include "CMatrix.h"
#include "CRowVector.h"
#include "CSparse.h"
#include "MArray.h"
#include "blas-proto.h"
#include "dColVector.h"
#include "dDiagMatrix.h"
#include "dMatrix.h"
#include "dRowVector.h"
#include "dSparse.h"
#include "f77-fcn.h"
#include "fCColVector.h"
#include "fCMatrix.h"
#include "fCRowVector.h"
#include "fColVector.h"
#include "fDiagMatrix.h"
#include "fMatrix.h"
#include "fRowVector.h"
#include "lapack-proto.h"
#include "lo-ieee.h"
#include "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 "oct-error.h"
#include "oct-norm.h"
#include "quit.h"
#include "svd.h"
#include "eigs-base.h"

Go to the source code of this file.

Macros

#define DEFINE_COLROW_DISPATCHER(FCN_NAME, ARG_TYPE, RES_TYPE)
 
#define DEFINE_COLROW_NORM_FCNS(PREFIX, RPREFIX, RTYPE)
 
#define DEFINE_XNORM_FCNS(PREFIX, RTYPE)
 
#define DEFINE_XNORM_SPARSE_FCNS(PREFIX, RTYPE)
 

Typedefs

template<typename R >
using accum_type = std::conditional_t< std::is_same_v< R, float >, double, R >
 

Functions

template<typename T , typename R >
void array_norm_2 (const T *v, octave_idx_type n, R &res)
 
double blas_nrm2 (octave_idx_type n, const Complex *x, octave_idx_type incx)
 
double blas_nrm2 (octave_idx_type n, const double *x, octave_idx_type incx)
 
float blas_nrm2 (octave_idx_type n, const float *x, octave_idx_type incx)
 
float blas_nrm2 (octave_idx_type n, const FloatComplex *x, octave_idx_type incx)
 
template<typename T , typename R , typename ACC >
void column_norms (const MArray< 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 , typename ACC >
void column_norms (const MSparse< T > &m, MArray< R > &res, ACC acc)
 
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)
 
double lange (char norm_type, const ComplexMatrix &m)
 
float lange (char norm_type, const FloatComplexMatrix &m)
 
float lange (char norm_type, const FloatMatrix &m)
 
double lange (char norm_type, const Matrix &m)
 
template<typename T , typename R >
lange_inf_fixup (R result, const T *data, octave_idx_type numel)
 
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 >
MArray< R > row_norms (const MArray< T > &v, R p)
 
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 MSparse< T > &v, R p)
 
template<typename T >
constexpr T safe_conj (T x)
 
template<typename MatrixT , typename VectorT , typename R >
sparse_2norm (const MatrixT &m, R tol, int maxiter, VectorT)
 
double sparse_2norm_arpack (const SparseComplexMatrix &m, double tol, int maxiter)
 
double sparse_2norm_arpack (const SparseMatrix &m, double tol, int maxiter)
 
template<typename MatrixT , typename VectorT , typename R >
sparse_2norm_power (const MatrixT &m, R tol, int maxiter, VectorT)
 
template<typename MatrixT , typename VectorT , typename R >
svd_matrix_norm (const MatrixT &m, R p, VectorT)
 
template<typename VectorT >
auto vector_dot (const VectorT &x, const VectorT &y)
 
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)
 
template<typename T , typename R , typename ACC >
void vector_norm (const MSparse< T > &v, R &res, ACC acc)
 
template<typename T , typename R >
vector_norm (const MSparse< T > &v, R p)
 
template<typename T , typename R >
vector_norm_2_blas (const MArray< T > &v)
 
RowVector xcolnorms (const ComplexMatrix &m, double p)
 
FloatRowVector xcolnorms (const FloatComplexMatrix &m, float p)
 
FloatRowVector xcolnorms (const FloatMatrix &m, float p)
 
RowVector xcolnorms (const Matrix &m, double p)
 
RowVector xcolnorms (const SparseComplexMatrix &m, double p)
 
RowVector xcolnorms (const SparseMatrix &m, double p)
 
double xfrobnorm (const ComplexMatrix &x)
 
float xfrobnorm (const FloatComplexMatrix &x)
 
float xfrobnorm (const FloatMatrix &x)
 
double xfrobnorm (const Matrix &x)
 
double xfrobnorm (const SparseComplexMatrix &x)
 
double xfrobnorm (const SparseMatrix &x)
 
double xnorm (const ColumnVector &x, double p)
 
double xnorm (const ComplexColumnVector &x, double p)
 
double xnorm (const ComplexMatrix &x, double p)
 
double xnorm (const ComplexRowVector &x, double p)
 
float xnorm (const FloatColumnVector &x, float p)
 
float xnorm (const FloatComplexColumnVector &x, float p)
 
float xnorm (const FloatComplexMatrix &x, float p)
 
float xnorm (const FloatComplexRowVector &x, float p)
 
float xnorm (const FloatMatrix &x, float p)
 
float xnorm (const FloatRowVector &x, float p)
 
double xnorm (const Matrix &x, double p)
 
double xnorm (const RowVector &x, double p)
 
double xnorm (const SparseComplexMatrix &x, double p)
 
double xnorm (const SparseMatrix &x, double p)
 
ColumnVector xrownorms (const ComplexMatrix &m, double p)
 
FloatColumnVector xrownorms (const FloatComplexMatrix &m, float p)
 
FloatColumnVector xrownorms (const FloatMatrix &m, float p)
 
ColumnVector xrownorms (const Matrix &m, double p)
 
ColumnVector xrownorms (const SparseComplexMatrix &m, double p)
 
ColumnVector xrownorms (const SparseMatrix &m, double p)
 

Variables

constexpr int max_norm_iter = 256
 
constexpr const char * p_less1_gripe = "xnorm: p must be >= 1"
 

Macro Definition Documentation

◆ DEFINE_COLROW_DISPATCHER

#define DEFINE_COLROW_DISPATCHER (   FCN_NAME,
  ARG_TYPE,
  RES_TYPE 
)
Value:
template <typename T, typename R> \
RES_TYPE FCN_NAME (const ARG_TYPE& v, R p) \
{ \
RES_TYPE res; \
if (p == 2) \
FCN_NAME (v, res, norm_accumulator_2<R> ()); \
else if (p == 1) \
FCN_NAME (v, res, norm_accumulator_1<R> ()); \
else if (math::isinf (p)) \
{ \
if (p > 0) \
FCN_NAME (v, res, norm_accumulator_inf<R> ()); \
else \
FCN_NAME (v, res, norm_accumulator_minf<R> ()); \
} \
else if (p == 0) \
FCN_NAME (v, res, norm_accumulator_0<R> ()); \
else if (p > 0) \
FCN_NAME (v, res, norm_accumulator_p<R> (p)); \
else \
FCN_NAME (v, res, norm_accumulator_mp<R> (p)); \
return res; \
}

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

◆ DEFINE_COLROW_NORM_FCNS

#define DEFINE_COLROW_NORM_FCNS (   PREFIX,
  RPREFIX,
  RTYPE 
)
Value:
RPREFIX##RowVector \
xcolnorms (const PREFIX##Matrix& m, RTYPE p) \
{ \
return column_norms (m, p); \
} \
RPREFIX##ColumnVector \
xrownorms (const PREFIX##Matrix& m, RTYPE p) \
{ \
return row_norms (m, p); \
} \
const char * PREFIX
void column_norms(const MArray< T > &m, MArray< R > &res, ACC acc)
Definition oct-norm.cc:476
void row_norms(const MArray< T > &m, MArray< R > &res, ACC acc)
Definition oct-norm.cc:491

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

◆ DEFINE_XNORM_FCNS

#define DEFINE_XNORM_FCNS (   PREFIX,
  RTYPE 
)
Value:
RTYPE xnorm (const PREFIX##ColumnVector& x, RTYPE p) \
{ \
return vector_norm (x, p); \
} \
RTYPE xnorm (const PREFIX##RowVector& x, RTYPE p) \
{ \
return vector_norm (x, p); \
} \
RTYPE xnorm (const PREFIX##Matrix& x, RTYPE p) \
{ \
return svd_matrix_norm (x, p, PREFIX##Matrix ()); \
} \
RTYPE xfrobnorm (const PREFIX##Matrix& x) \
{ \
return lange ('F', x); \
}
double xfrobnorm(const Matrix &x)
Definition oct-norm.cc:1065
double xnorm(const ColumnVector &x, double p)
Definition oct-norm.cc:1065
double lange(char norm_type, const Matrix &m)
Definition oct-norm.cc:149
void vector_norm(const Array< T > &v, R &res, ACC acc)
Definition oct-norm.cc:453
R svd_matrix_norm(const MatrixT &m, R p, VectorT)
Definition oct-norm.cc:790
F77_RET_T const F77_DBLE * x

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

◆ DEFINE_XNORM_SPARSE_FCNS

#define DEFINE_XNORM_SPARSE_FCNS (   PREFIX,
  RTYPE 
)
Value:
RTYPE xnorm (const Sparse##PREFIX##Matrix& x, RTYPE p) \
{ \
return matrix_norm (x, p, PREFIX##Matrix ()); \
} \
RTYPE xfrobnorm (const Sparse##PREFIX##Matrix& x) \
{ \
RTYPE res; \
array_norm_2 (x.data (), x.nnz (), res); \
return res; \
}
R matrix_norm(const MatrixT &m, R p, VectorT)
Definition oct-norm.cc:1020

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

Typedef Documentation

◆ accum_type

template<typename R >
using accum_type = std::conditional_t<std::is_same_v<R, float>, double, R>

Definition at line 225 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 1072 of file oct-norm.cc.

◆ blas_nrm2() [1/4]

double blas_nrm2 ( octave_idx_type  n,
const Complex x,
octave_idx_type  incx 
)
inline

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

References F77_CONST_DBLE_CMPLX_ARG, F77_FUNC(), x, and xdznrm2().

◆ blas_nrm2() [2/4]

double blas_nrm2 ( octave_idx_type  n,
const double x,
octave_idx_type  incx 
)
inline

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

References F77_FUNC(), x, and xdnrm2().

Referenced by vector_norm_2_blas().

◆ blas_nrm2() [3/4]

float blas_nrm2 ( octave_idx_type  n,
const float x,
octave_idx_type  incx 
)
inline

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

References F77_FUNC(), x, and xsnrm2().

◆ blas_nrm2() [4/4]

float blas_nrm2 ( octave_idx_type  n,
const FloatComplex x,
octave_idx_type  incx 
)
inline

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

References F77_CONST_CMPLX_ARG, F77_FUNC(), x, and xscnrm2().

◆ column_norms() [1/4]

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

◆ column_norms() [2/4]

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

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

◆ column_norms() [3/4]

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

◆ column_norms() [4/4]

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

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

◆ dual_p()

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

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

References elem_dual_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 707 of file oct-norm.cc.

References 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 729 of file oct-norm.cc.

References dual_p(), gamma(), vector_norm(), and x.

Referenced by matrix_norm(), and svd_matrix_norm().

◆ lange() [1/4]

◆ lange() [2/4]

◆ lange() [3/4]

◆ lange() [4/4]

◆ lange_inf_fixup()

template<typename T , typename R >
R lange_inf_fixup ( result,
const T *  data,
octave_idx_type  numel 
)
inline

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

References numel().

Referenced by lange(), lange(), lange(), and lange().

◆ 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 
)

◆ row_norms() [2/4]

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

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

◆ row_norms() [3/4]

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

◆ row_norms() [4/4]

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

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

References vector_norm().

◆ safe_conj()

template<typename T >
constexpr T safe_conj ( x)
constexpr

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

References x.

Referenced by vector_dot().

◆ sparse_2norm()

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

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

References sparse_2norm_arpack(), and sparse_2norm_power().

Referenced by matrix_norm().

◆ sparse_2norm_arpack() [1/2]

◆ sparse_2norm_arpack() [2/2]

◆ sparse_2norm_power()

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

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

References vector_dot(), vector_norm(), and x.

Referenced by sparse_2norm().

◆ svd_matrix_norm()

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

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

References current_liboctave_error_handler, higham(), lange(), max_norm_iter, p_less1_gripe, and x.

◆ vector_dot()

template<typename VectorT >
auto vector_dot ( const VectorT &  x,
const VectorT &  y 
)

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

References safe_conj(), and x.

Referenced by sparse_2norm_power().

◆ vector_norm() [1/4]

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

◆ vector_norm() [2/4]

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

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

References vector_norm().

◆ vector_norm() [3/4]

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

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

References Sparse< T, Alloc >::data(), and Sparse< T, Alloc >::nnz().

◆ vector_norm() [4/4]

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

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

References vector_norm().

◆ vector_norm_2_blas()

template<typename T , typename R >
R vector_norm_2_blas ( const MArray< T > &  v)
inline

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

References blas_nrm2(), Array< T, Alloc >::data(), and Array< T, Alloc >::numel().

◆ xcolnorms() [1/6]

RowVector xcolnorms ( const ComplexMatrix m,
double  p 
)

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

◆ xcolnorms() [2/6]

FloatRowVector xcolnorms ( const FloatComplexMatrix m,
float  p 
)

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

◆ xcolnorms() [3/6]

FloatRowVector xcolnorms ( const FloatMatrix m,
float  p 
)

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

◆ xcolnorms() [4/6]

RowVector xcolnorms ( const Matrix m,
double  p 
)

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

Referenced by F__icholt__(), F__iluc__(), F__ilutp__(), Fnorm(), and matrix_norm().

◆ xcolnorms() [5/6]

RowVector xcolnorms ( const SparseComplexMatrix m,
double  p 
)

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

◆ xcolnorms() [6/6]

RowVector xcolnorms ( const SparseMatrix m,
double  p 
)

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

◆ xfrobnorm() [1/6]

double xfrobnorm ( const ComplexMatrix x)

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

◆ xfrobnorm() [2/6]

float xfrobnorm ( const FloatComplexMatrix x)

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

◆ xfrobnorm() [3/6]

float xfrobnorm ( const FloatMatrix x)

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

◆ xfrobnorm() [4/6]

double xfrobnorm ( const Matrix x)

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

Referenced by Fnorm(), and Fsqrtm().

◆ xfrobnorm() [5/6]

double xfrobnorm ( const SparseComplexMatrix x)

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

◆ xfrobnorm() [6/6]

double xfrobnorm ( const SparseMatrix x)

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

◆ xnorm() [1/14]

double xnorm ( const ColumnVector x,
double  p 
)

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

Referenced by Fnorm().

◆ xnorm() [2/14]

double xnorm ( const ComplexColumnVector x,
double  p 
)

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

◆ xnorm() [3/14]

double xnorm ( const ComplexMatrix x,
double  p 
)

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

◆ xnorm() [4/14]

double xnorm ( const ComplexRowVector x,
double  p 
)

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

◆ xnorm() [5/14]

float xnorm ( const FloatColumnVector x,
float  p 
)

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

◆ xnorm() [6/14]

float xnorm ( const FloatComplexColumnVector x,
float  p 
)

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

◆ xnorm() [7/14]

float xnorm ( const FloatComplexMatrix x,
float  p 
)

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

◆ xnorm() [8/14]

float xnorm ( const FloatComplexRowVector x,
float  p 
)

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

◆ xnorm() [9/14]

float xnorm ( const FloatMatrix x,
float  p 
)

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

◆ xnorm() [10/14]

float xnorm ( const FloatRowVector x,
float  p 
)

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

◆ xnorm() [11/14]

double xnorm ( const Matrix x,
double  p 
)

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

◆ xnorm() [12/14]

double xnorm ( const RowVector x,
double  p 
)

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

◆ xnorm() [13/14]

double xnorm ( const SparseComplexMatrix x,
double  p 
)

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

◆ xnorm() [14/14]

double xnorm ( const SparseMatrix x,
double  p 
)

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

◆ xrownorms() [1/6]

ColumnVector xrownorms ( const ComplexMatrix m,
double  p 
)

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

◆ xrownorms() [2/6]

FloatColumnVector xrownorms ( const FloatComplexMatrix m,
float  p 
)

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

◆ xrownorms() [3/6]

FloatColumnVector xrownorms ( const FloatMatrix m,
float  p 
)

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

◆ xrownorms() [4/6]

ColumnVector xrownorms ( const Matrix m,
double  p 
)

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

Referenced by F__iluc__(), F__ilutp__(), Fnorm(), and matrix_norm().

◆ xrownorms() [5/6]

ColumnVector xrownorms ( const SparseComplexMatrix m,
double  p 
)

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

◆ xrownorms() [6/6]

ColumnVector xrownorms ( const SparseMatrix m,
double  p 
)

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

Variable Documentation

◆ max_norm_iter

constexpr int max_norm_iter = 256
constexpr

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

Referenced by matrix_norm(), and svd_matrix_norm().

◆ p_less1_gripe

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

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

Referenced by matrix_norm(), and svd_matrix_norm().