Xmipp
v3.23.11-Nereus
|
#include <mask.h>
Public Member Functions | |
Constructors | |
Matrix2D () | |
Matrix2D (const FileName &fnMappedMatrix, int Ydim, int Xdim, size_t offset=0) | |
Matrix2D (int Ydim, int Xdim) | |
Matrix2D (const Matrix2D< T > &v) | |
~Matrix2D () | |
Matrix2D< T > & | operator= (const Matrix2D< T > &op1) |
Core memory operations for Matrix2D | |
void | clear () |
void | convertTo (float out[3][3]) const |
void | coreInit (const FileName &fn, int Ydim, int Xdim, size_t offset=0) |
void | coreInit () |
void | coreAllocate (int _mdimy, int _mdimx) |
void | coreDeallocate () |
Size and shape of Matrix2D | |
void | resize (size_t Ydim, size_t Xdim, bool noCopy=false) |
template<typename T1 > | |
void | resize (const Matrix2D< T1 > &v) |
void | resizeNoCopy (int Ydim, int Xdim) |
template<typename T1 > | |
void | resizeNoCopy (const Matrix2D< T1 > &v) |
void | mapToFile (const FileName &fn, int Ydim, int Xdim, size_t offset=0) |
void | submatrix (int i0, int j0, int iF, int jF) |
template<typename T1 > | |
bool | sameShape (const Matrix2D< T1 > &op) const |
size_t | Xdim () const |
size_t | Ydim () const |
Initialization of Matrix2D values | |
void | initConstant (T val) |
void | initConstant (size_t Ydim, size_t Xdim, T val) |
void | initZeros () |
void | initZeros (size_t Ydim, size_t Xdim) |
template<typename T1 > | |
void | initZeros (const Matrix2D< T1 > &op) |
void | initRandom (size_t Ydim, size_t Xdim, double op1, double op2, RandomMode mode=RND_UNIFORM) |
void | initGaussian (int Ydim, int Xdim, double op1=0., double op2=1.) |
void | initIdentity () |
void | initIdentity (int dim) |
void | initGaussian (int dim, double var) |
Public Attributes | |
T * | mdata |
bool | destroyData |
bool | mappedData |
int | fdMap |
char * | mdataOriginal |
size_t | mdimx |
size_t | mdimy |
size_t | mdim |
Operators for Matrix2D | |
T & | operator() (int i, int j) const |
void | setVal (T val, int y, int x) |
T | getVal (int y, int x) const |
Matrix2D< T > | operator* (T op1) const |
Matrix2D< T > | operator/ (T op1) const |
void | operator*= (T op1) |
void | operator/= (T op1) |
Matrix1D< T > | operator* (const Matrix1D< T > &op1) const |
Matrix2D< T > | operator* (const Matrix2D< T > &op1) const |
Matrix2D< T > | operator+ (const Matrix2D< T > &op1) const |
void | operator+= (const Matrix2D< T > &op1) const |
Matrix2D< T > | operator- (const Matrix2D< T > &op1) const |
void | operator-= (const Matrix2D< T > &op1) const |
bool | equal (const Matrix2D< T > &op, double accuracy=XMIPP_EQUAL_ACCURACY) const |
bool | equalAbs (const Matrix2D< T > &op, double accuracy=XMIPP_EQUAL_ACCURACY) const |
Matrix2D< T > | operator* (T op1, const Matrix2D< T > &op2) |
Utilities for Matrix2D | |
T | computeMax () const |
T | computeMin () const |
void | computeMaxAndMin (T &maxValue, T &minValue) const |
void | rowSum (Matrix1D< T > &sum) const |
void | colSum (Matrix1D< T > &sum) const |
void | rowEnergySum (Matrix1D< T > &sum) const |
T ** | adaptForNumericalRecipes () const |
T * | adaptForNumericalRecipes2 () const |
void | loadFromNumericalRecipes (T **m, int Ydim, int Xdim) |
void | killAdaptationForNumericalRecipes (T **m) const |
void | killAdaptationForNumericalRecipes2 (T **m) const |
void | read (const FileName &fn) |
void | write (const FileName &fn) const |
void | fromVector (const Matrix1D< T > &op1) |
void | toVector (Matrix1D< T > &op1) const |
void | copyToVector (std::vector< T > &v) |
void | copyFromVector (std::vector< T > &v, int Xdim, int Ydim) |
void | getRow (size_t i, Matrix1D< T > &v) const |
void | getCol (size_t j, Matrix1D< T > &v) const |
void | setRow (size_t i, const Matrix1D< T > &v) |
void | setCol (size_t j, const Matrix1D< T > &v) |
void | computeRowMeans (Matrix1D< double > &Xmr) const |
void | computeColMeans (Matrix1D< double > &Xmr) const |
void | setConstantCol (size_t j, T v) |
void | getDiagonal (Matrix1D< T > &d) const |
T | trace () const |
T | det () const |
T | det3x3 () const |
determinat of 3x3 matrix More... | |
double | norm () |
Matrix2D< T > | transpose () const |
void | inv (Matrix2D< T > &result) const |
void | invAlgLib (Matrix2D< T > &result, bool use_lu=false) const |
void | svd (Matrix2D< double > &U, Matrix1D< double > &W, Matrix2D< double > &V) const |
void | eigs (Matrix2D< double > &U, Matrix1D< double > &W, Matrix2D< double > &V, Matrix1D< int > &indexes) const |
Matrix2D< T > | inv () const |
void | selfInverse () |
bool | isIdentity () const |
std::ostream & | operator<< (std::ostream &ostrm, const Matrix2D< T > &v) |
Empty constructor
Definition at line 423 of file matrix2d.h.
|
inline |
Definition at line 428 of file matrix2d.h.
T ** Matrix2D< T >::adaptForNumericalRecipes | ( | ) | const |
Produce a 2D array suitable for working with Numerical Recipes
This function must be used only as a preparation for routines which need that the first physical index is 1 and not 0 as it usually is in C. New memory is needed to hold the new double pointer array.
Definition at line 1280 of file matrix2d.cpp.
|
inline |
Produce a 1D pointer suitable for working with Numerical Recipes (2)
This function meets the same goal as the one before, however this one work with 2D arrays as a single pointer. The first element of the array is pointed by result[1*Xdim+1], and in general result[i*Xdim+j]
Definition at line 875 of file matrix2d.h.
|
inline |
T Matrix2D< T >::computeMax | ( | ) | const |
Maximum of the values in the array.
The returned value is of the same type as the type of the array.
Definition at line 1236 of file matrix2d.cpp.
void Matrix2D< T >::computeMaxAndMin | ( | T & | maxValue, |
T & | minValue | ||
) | const |
T Matrix2D< T >::computeMin | ( | ) | const |
Minimum of the values in the array.
The returned value is of the same type as the type of the array.
Definition at line 1249 of file matrix2d.cpp.
|
inline |
Method will convert Matrix2D matrix to float[3][3]
Definition at line 480 of file matrix2d.h.
|
inline |
|
inline |
void Matrix2D< T >::coreAllocate | ( | int | _mdimy, |
int | _mdimx | ||
) |
void Matrix2D< T >::coreDeallocate | ( | ) |
void Matrix2D< T >::coreInit | ( | const FileName & | fn, |
int | Ydim, | ||
int | Xdim, | ||
size_t | offset = 0 |
||
) |
Core init from mapped file. Offset is in bytes.
Definition at line 75 of file matrix2d.cpp.
void Matrix2D< T >::coreInit | ( | ) |
T Matrix2D< T >::det | ( | ) | const |
Determinant of a matrix
An exception is thrown if the matrix is not squared or it is empty.
Definition at line 38 of file matrix2d.cpp.
|
inline |
void Matrix2D< T >::eigs | ( | Matrix2D< double > & | U, |
Matrix1D< double > & | W, | ||
Matrix2D< double > & | V, | ||
Matrix1D< int > & | indexes | ||
) | const |
Perform SVD decomposition and add an index vector with the descending order of singular values
Definition at line 719 of file matrix2d.cpp.
bool Matrix2D< T >::equal | ( | const Matrix2D< T > & | op, |
double | accuracy = XMIPP_EQUAL_ACCURACY |
||
) | const |
Equality.
Returns true if this object has got the same shape (origin and size) than the argument and the same values (within accuracy).
Definition at line 1202 of file matrix2d.cpp.
bool Matrix2D< T >::equalAbs | ( | const Matrix2D< T > & | op, |
double | accuracy = XMIPP_EQUAL_ACCURACY |
||
) | const |
Equality.
Returns true if this object has got the same shape (origin and size) than the argument and the same values (within accuracy and without SIGN).
Definition at line 1219 of file matrix2d.cpp.
Makes a matrix from a vector
The origin of the matrix is set such that it has one of the index origins (X or Y) to the same value as the vector, and the other set to 0 according to the shape.
Definition at line 803 of file matrix2d.cpp.
Get Column
This function returns a column vector corresponding to the chosen column.
Definition at line 890 of file matrix2d.cpp.
Get row
This function returns a row vector corresponding to the chosen row inside the nth 2D matrix, the numbering of the rows is also logical not physical.
Definition at line 871 of file matrix2d.cpp.
|
inline |
|
inline |
Same value in all components.
The constant must be of a type compatible with the array type, ie, you cannot assign a double to an integer array without a casting. It is not an error if the array is empty, then nothing is done.
Definition at line 602 of file matrix2d.h.
|
inline |
void Matrix2D< T >::initGaussian | ( | int | Ydim, |
int | Xdim, | ||
double | op1 = 0. , |
||
double | op2 = 1. |
||
) |
Initialize to gaussian numbers
Definition at line 1118 of file matrix2d.cpp.
void Matrix2D< T >::initGaussian | ( | int | dim, |
double | var | ||
) |
2D gaussian matrix of a given size and with a given variance. The amplitude of the Gaussian is set to 1.
A (dim x dim) gaussian matrix is generated.
Definition at line 1125 of file matrix2d.cpp.
|
inline |
2D Identity matrix of current size
If actually the matrix is not squared then an identity matrix is generated of size (Xdim x Xdim).
Definition at line 673 of file matrix2d.h.
|
inline |
2D Identity matrix of a given size
A (dim x dim) identity matrix is generated.
Definition at line 686 of file matrix2d.h.
void Matrix2D< T >::initRandom | ( | size_t | Ydim, |
size_t | Xdim, | ||
double | op1, | ||
double | op2, | ||
RandomMode | mode = RND_UNIFORM |
||
) |
Initialize to random random numbers, uniform or gaussian
Definition at line 1108 of file matrix2d.cpp.
|
inline |
Initialize to zeros with current size.
All values are set to 0. The current size and origin are kept. It is not an error if the array is empty, then nothing is done.
Definition at line 626 of file matrix2d.h.
|
inline |
|
inline |
Initialize to zeros following a pattern.
All values are set to 0, and the origin and size of the pattern are adopted.
Definition at line 650 of file matrix2d.h.
Inverse of a matrix
The matrix is inverted using a SVD decomposition. In fact the pseudoinverse is returned.
Definition at line 663 of file matrix2d.cpp.
void Matrix2D< T >::invAlgLib | ( | Matrix2D< T > & | result, |
bool | use_lu = false |
||
) | const |
Inverse of a matrix
The matrix is inverted using a AlgLib. Set LU to use LU decomposition
bool Matrix2D< T >::isIdentity | ( | ) | const |
True if the matrix is identity
Definition at line 1323 of file matrix2d.cpp.
|
inline |
Kill a 2D array produced for numerical recipes
The allocated memory is freed.
Definition at line 888 of file matrix2d.h.
|
inline |
Kill a 2D array produced for numerical recipes, 2.
Nothing needs to be done.
Definition at line 897 of file matrix2d.h.
void Matrix2D< T >::loadFromNumericalRecipes | ( | T ** | m, |
int | Ydim, | ||
int | Xdim | ||
) |
void Matrix2D< T >::mapToFile | ( | const FileName & | fn, |
int | Ydim, | ||
int | Xdim, | ||
size_t | offset = 0 |
||
) |
Map to file. The matrix is mapped to a file. The file is presumed to be already created with enough space for a matrix of size Ydim x Xdim. Offset is in bytes.
Definition at line 1079 of file matrix2d.cpp.
|
inline |
|
inline |
Matrix by Matrix multiplication
Definition at line 1135 of file matrix2d.cpp.
|
inline |
|
inline |
Assignment.
You can build as complex assignment expressions as you like. Multiple assignment is allowed.
Definition at line 957 of file matrix2d.cpp.
Read this matrix from file. The matrix is assumed to be already resized.
Definition at line 101 of file matrix2d.cpp.
void Matrix2D< T >::resize | ( | size_t | Ydim, |
size_t | Xdim, | ||
bool | noCopy = false |
||
) |
Resize to a given size
Definition at line 1022 of file matrix2d.cpp.
|
inline |
Resize according to a pattern.
This function resize the actual array to the same size and origin as the input pattern. If the actual array is larger than the pattern then the trailing values are lost, if it is smaller then 0's are added at the end
Definition at line 526 of file matrix2d.h.
|
inline |
Resize to a given size (don't copy old elements)
Definition at line 534 of file matrix2d.h.
|
inline |
Resize according to a pattern. Do not copy old elements.
Definition at line 543 of file matrix2d.h.
|
inline |
Same shape.
Returns true if this object has got the same shape (origin and size) than the argument
Definition at line 566 of file matrix2d.h.
|
inline |
Set Column
This function sets a column vector corresponding to the chosen column inside matrix.
Definition at line 929 of file matrix2d.cpp.
|
inline |
Set constant column. Set a given column to a constant value A(i,j)=val;
Definition at line 1028 of file matrix2d.h.
Set Row
This function sets a row vector corresponding to the chosen row in the 2D Matrix
Definition at line 910 of file matrix2d.cpp.
|
inline |
void Matrix2D< T >::submatrix | ( | int | i0, |
int | j0, | ||
int | iF, | ||
int | jF | ||
) |
|
inline |
Perform SVD decomposition *this = U * W * V^t
Definition at line 1124 of file matrix2d.h.
Makes a vector from a matrix
An exception is thrown if the matrix is not a single row or a single column. The origin of the vector is set according to the one of the matrix.
Definition at line 832 of file matrix2d.cpp.
T Matrix2D< T >::trace | ( | ) | const |
Algebraic transpose of a Matrix
You can use the transpose in as complex expressions as you like. The origin of the vector is not changed.
Definition at line 1314 of file matrix2d.cpp.
|
inline |
|
inline |
|
friend |
bool Matrix2D< T >::destroyData |
Definition at line 398 of file matrix2d.h.
int Matrix2D< T >::fdMap |
Definition at line 404 of file matrix2d.h.
bool Matrix2D< T >::mappedData |
Definition at line 401 of file matrix2d.h.
T* Matrix2D< T >::mdata |
Definition at line 395 of file matrix2d.h.
char* Matrix2D< T >::mdataOriginal |
Definition at line 407 of file matrix2d.h.
size_t Matrix2D< T >::mdim |
Definition at line 416 of file matrix2d.h.
size_t Matrix2D< T >::mdimx |
Definition at line 410 of file matrix2d.h.
size_t Matrix2D< T >::mdimy |
Definition at line 413 of file matrix2d.h.