41 if (mdimx == 0 || mdimy == 0)
47 for (
size_t i = 0;
i < mdimy;
i++)
49 bool all_zeros =
true;
50 for (
size_t j = 0;
j < mdimx;
j++)
65 ludcmp(*
this, LU, indx, d);
68 for (
size_t i = 0;
i < mdimx;
i++)
84 fdMap = open(fn.c_str(), O_RDWR, S_IREAD | S_IWRITE);
87 const size_t pagesize=sysconf(_SC_PAGESIZE);
88 size_t offsetPages=(offset/pagesize)*pagesize;
89 size_t offsetDiff=offset-offsetPages;
90 if ( (mdataOriginal = (
char*) mmap(0,Ydim*Xdim*
sizeof(T)+offsetDiff, PROT_READ | PROT_WRITE, MAP_SHARED, fdMap, offsetPages)) == MAP_FAILED )
92 mdata=(T*)(mdataOriginal+offsetDiff);
104 fhIn.open(fn.c_str());
116 fhOut.open(fn.c_str());
223 double maxValue,minValue;
225 double iMaxValue=1.0/(maxValue-minValue);
274 bool ok=
smatrixgevd(a, N,
true, b,
true,
true, 1, d, z);
290 bool ok=
smatrixevdi(a, N, Pneeded,
false, N-M, N-1, d, z);
311 bool ok=
smatrixevdi(a, N,
true,
false, 0, M-1, d, z);
326 size_t M = I2 - I1 + 1;
332 bool ok=
smatrixevdi(a, N,
true,
false, I1, I2, d, z);
356 for (
int n=0;
n<N; ++
n)
357 eigs.push_back(std::complex<double>(wr(
n),wi(
n)));
368 std::queue<size_t> toExplore;
386 int currentComponent=nextComponent;
389 VEC_ELEM(component,seed)=currentComponent;
390 toExplore.push(seed);
391 while (toExplore.size()>0)
393 seed=toExplore.front();
395 for (
size_t j=seed+1;
j<N; ++
j)
568 double K=1.0/
sqrt(norm);
573 for(
size_t j2=j1+1; j2<
MAT_XSIZE(M); j2++)
625 return this->
inv(result);
629 const auto N = this->
mdimx;
632 for(
size_t i = 0;
i < N; ++
i) {
634 auto src = this->
mdata + (
i * N);
635 memcpy(dest, src, N *
sizeof(
double));
648 if (1 != (
int)info) {
654 for(
size_t i = 0;
i < N; ++
i) {
656 auto dest = result.
mdata + (
i * N);
657 memcpy(dest, src, N *
sizeof(
double));
691 bool invertible =
false;
844 "toVector: Matrix cannot be converted to vector");
920 "setRow: Vector dimension different from matrix one");
939 "setCol: Vector dimension different from matrix one");
984 if (_mdimy <= 0 ||_mdimx<=0)
1001 template<
typename T>
1021 template<
typename T>
1028 if (Xdim <= 0 || Ydim <= 0)
1035 size_t YXdim=Ydim*
Xdim;
1039 new_mdata =
new T [YXdim];
1041 catch (std::bad_alloc &)
1050 for (
size_t i = 0;
i <
Ydim;
i++)
1051 for (
size_t j = 0;
j <
Xdim;
j++)
1060 new_mdata[
i*Xdim+
j] = *val;
1064 memset(new_mdata,0,YXdim*
sizeof(T));
1078 template<
typename T>
1094 template<
typename T>
1107 template<
typename T>
1112 for (
size_t j = 0;
j <
mdim;
j++)
1117 template<
typename T>
1124 template<
typename T>
1127 double center = ((double)dim)/2;
1129 for (
int i = 0;
i < dim;
i++)
1130 for (
int j = 0;
j < dim;
j++)
1131 MAT_ELEM(*
this,
i,
j) = std::exp(-( (
i-center)*(
i-center)+(
j-center)*(
j-center) )/(2*var*var));
1134 template<
typename T>
1143 for (
size_t j = 0;
j < op1.
mdimx;
j++)
1149 template<
typename T>
1159 result(
i,
j) = (*this)(
i,
j) + op1(i,
j);
1164 template<
typename T>
1175 template<
typename T>
1185 result(
i,
j) = (*this)(
i,
j) - op1(i,
j);
1190 template<
typename T>
1201 template<
typename T>
1203 double accuracy)
const 1218 template<
typename T>
1220 double accuracy)
const 1235 template<
typename T>
1239 return static_cast< T
>(0);
1241 T maxval =
mdata[0];
1242 for (
size_t n = 0;
n <
mdim;
n++)
1248 template<
typename T>
1252 return static_cast< T
>(0);
1254 T minval =
mdata[0];
1255 for (
size_t n = 0;
n <
mdim;
n++)
1261 template<
typename T>
1264 maxValue=minValue=0;
1268 maxValue = minValue =
mdata[0];
1269 for (
size_t n = 0;
n <
mdim;
n++)
1274 else if (val > maxValue)
1279 template<
typename T>
1292 template<
typename T>
1298 for (
int i = 1;
i <=
Ydim;
i++)
1299 for (
int j = 1;
j <=
Xdim;
j++)
1303 template<
typename T>
1308 for (
size_t i=0;
i<
d; ++
i)
1313 template<
typename T>
1322 template<
typename T>
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
void eraseFirstColumn(Matrix2D< double > &A)
void submatrix(int i0, int j0, int iF, int jF)
void min(Image< double > &op1, const Image< double > &op2)
void rmatrixlu(real_2d_array &a, const ae_int_t m, const ae_int_t n, integer_1d_array &pivots)
void rowSum(Matrix1D< T > &sum) const
Matrix2D< T > & operator=(const Matrix2D< T > &op1)
void subtractColumnMeans(Matrix2D< double > &A)
void eigsBetween(const Matrix2D< double > &A, size_t I1, size_t I2, Matrix1D< double > &D, Matrix2D< double > &P)
void getDiagonal(Matrix1D< T > &d) const
void normalizeColumns(Matrix2D< double > &A)
#define VEC_SWAP(v, i, j, aux)
#define REPORT_ERROR(nerr, ErrormMsg)
void fromVector(const Matrix1D< T > &op1)
void colSum(Matrix1D< T > &sum) const
Problem with matrix size.
bool sameShape(const Matrix2D< T1 > &op) const
void mapToFile(const FileName &fn, int Ydim, int Xdim, size_t offset=0)
template void svdcmp< double >(Matrix2D< double > const &, Matrix2D< double > &, Matrix1D< double > &, Matrix2D< double > &)
void matrixOperation_AB(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix2D< double > &C)
bool equal(const Matrix2D< T > &op, double accuracy=XMIPP_EQUAL_ACCURACY) const
void sqrt(Image< double > &op)
union alglib_impl::ae_matrix::@12 ptr
template void svdcmp< float >(Matrix2D< float > const &, Matrix2D< double > &, Matrix1D< double > &, Matrix2D< double > &)
Matrix1D< T > operator*(T op1) const
void computeMaxAndMin(T &maxValue, T &minValue) const
bool smatrixgevd(const real_2d_array &a, const ae_int_t n, const bool isuppera, const real_2d_array &b, const bool isupperb, const ae_int_t zneeded, const ae_int_t problemtype, real_1d_array &d, real_2d_array &z)
There is not enough memory for allocation.
void choldc(double *a, int n, double *p)
void operator+=(const Matrix2D< T > &op1) const
void toVector(Matrix1D< T > &op1) const
String integerToString(int I, int _width, char fill_with)
Matrix2D< T > transpose() const
template void lubksb< double >(Matrix2D< double > const &, Matrix1D< int > &, Matrix1D< double > &)
const alglib_impl::ae_matrix * c_ptr() const
T norm(const std::vector< T > &v)
void matrixOperation_IminusA(Matrix2D< double > &A)
T * adaptForNumericalRecipes2() const
Matrix2D< T > operator+(const Matrix2D< T > &op1) const
void invAlgLib(Matrix2D< T > &result, bool use_lu=false) const
void matrixOperation_AtA(const Matrix2D< double > &A, Matrix2D< double > &B)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
bool smatrixevdi(const real_2d_array &a, const ae_int_t n, const ae_int_t zneeded, const bool isupper, const ae_int_t i1, const ae_int_t i2, real_1d_array &w, real_2d_array &z)
void resizeNoCopy(int Ydim, int Xdim)
#define M4x4_INV(Ainv, A)
void matrixOperation_AAt(const Matrix2D< double > &A, Matrix2D< double > &C)
#define MAT_ELEM(m, i, j)
bool rmatrixevd(const real_2d_array &a, const ae_int_t n, const ae_int_t vneeded, real_1d_array &wr, real_1d_array &wi, real_2d_array &vl, real_2d_array &vr)
void connectedComponentsOfUndirectedGraph(const Matrix2D< double > &G, Matrix1D< int > &component)
Map addressing of file has failed.
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
#define M3x3_INV(Ainv, A)
void normalizeColumnsBetween0and1(Matrix2D< double > &A)
void orthogonalizeColumnsGramSchmidt(Matrix2D< double > &M)
bool rmatrixschur(real_2d_array &a, const ae_int_t n, real_2d_array &s)
void lubksb(const Matrix2D< T > &LU, Matrix1D< int > &indx, Matrix1D< T > &b)
void rmatrixluinverse(real_2d_array &a, const integer_1d_array &pivots, const ae_int_t n, ae_int_t &info, matinvreport &rep)
Matrix2D< T > inv() const
void cholesky(const Matrix2D< double > &M, Matrix2D< double > &L)
Problem with matrix dimensions.
Matrix2D< T > operator*(T op1) const
void matrixOperation_AtB(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix2D< double > &C)
void coreAllocate(int _mdimy, int _mdimx)
#define XMIPP_EQUAL_ACCURACY
void setCol(size_t j, const Matrix1D< T > &v)
void eigs(Matrix2D< double > &U, Matrix1D< double > &W, Matrix2D< double > &V, Matrix1D< int > &indexes) const
void rowEnergySum(Matrix1D< T > &sum) const
void firstEigs(const Matrix2D< double > &A, size_t M, Matrix1D< double > &D, Matrix2D< double > &P, bool Pneeded)
void matrixOperation_IplusA(Matrix2D< double > &A)
Error related to numerical calculation.
void generalizedEigs(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix1D< double > &D, Matrix2D< double > &P)
File or directory does not exist.
void matrixOperation_ABt(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix2D< double > &C)
void matrixOperation_Ax(const Matrix2D< double > &A, const Matrix1D< double > &x, Matrix1D< double > &y)
void loadFromNumericalRecipes(T **m, int Ydim, int Xdim)
void lastEigs(const Matrix2D< double > &A, size_t M, Matrix1D< double > &D, Matrix2D< double > &P)
void schur(const Matrix2D< double > &M, Matrix2D< double > &O, Matrix2D< double > &T)
void allEigs(const Matrix2D< double > &A, std::vector< std::complex< double > > &eigs)
void svdcmp(const Matrix2D< T > &a, Matrix2D< double > &u, Matrix1D< double > &w, Matrix2D< double > &v)
void matrixOperation_Atx(const Matrix2D< double > &A, const Matrix1D< double > &x, Matrix1D< double > &y)
void getCol(size_t j, Matrix1D< T > &v) const
void ludcmp(const Matrix2D< T > &A, Matrix2D< T > &LU, Matrix1D< int > &indx, T &d)
template void ludcmp< double >(Matrix2D< double > const &, Matrix2D< double > &, Matrix1D< int > &, double &)
void setRow(size_t i, const Matrix1D< T > &v)
Matrix2D< T > operator-(const Matrix2D< T > &op1) const
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
void read(const FileName &fn)
void keepColumns(Matrix2D< double > &A, int j0, int jF)
void write(const FileName &fn) const
int SingularValueDecomposition(double *U, long Lines, long Columns, double W[], double *V, long MaxIterations, int *Status)
void initRandom(size_t Ydim, size_t Xdim, double op1, double op2, RandomMode mode=RND_UNIFORM)
T ** adaptForNumericalRecipes() const
void computeRowMeans(Matrix1D< double > &Xmr) const
bool equalAbs(const Matrix2D< T > &op, double accuracy=XMIPP_EQUAL_ACCURACY) const
void resizeNoCopy(int Xdim)
void operator-=(const Matrix2D< T > &op1) const
void setcontent(ae_int_t irows, ae_int_t icols, const double *pContent)
void ask_Tmatrix(T **&m, int nrl, int nrh, int ncl, int nch)
void rmatrixinverse(real_2d_array &a, const ae_int_t n, ae_int_t &info, matinvreport &rep)
T * vdata
The array itself.
#define M2x2_INV(Ainv, A)
void initGaussian(int Ydim, int Xdim, double op1=0., double op2=1.)
T * adaptForNumericalRecipes() const
alglib_impl::ae_int_t ae_int_t
#define MATRIX2D_ARRAY(m)
void getRow(size_t i, Matrix1D< T > &v) const
void matrixOperation_XtAX_symmetric(const Matrix2D< double > &X, const Matrix2D< double > &A, Matrix2D< double > &B)
void matrixOperation_AtBt(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix2D< double > &C)
void setlength(ae_int_t rows, ae_int_t cols)
void resize(size_t Ydim, size_t Xdim, bool noCopy=false)
ql0001_ & zero(ctemp+1),(cvec+1),(a+1),(b+1),(bl+1),(bu+1),(x+1),(w+1), &iout, ifail, &zero,(w+3), &lwar2,(iw+1), &leniw, &glob_grd.epsmac
void svbksb(Matrix2D< double > &u, Matrix1D< double > &w, Matrix2D< double > &v, Matrix1D< double > &b, Matrix1D< double > &x)
void computeColMeans(Matrix1D< double > &Xmr) const