26 #ifndef CORE_MATRIX1D_H_ 27 #define CORE_MATRIX1D_H_ 58 #define MATRIX1D_ARRAY(v) ((v).vdata) 72 #define FOR_ALL_ELEMENTS_IN_MATRIX1D(v) \ 73 for (size_t i=0; i<v.vdim; i++) 77 #define VEC_XSIZE(m) ((m).vdim) 85 #define XX(v) (v).vdata[0] 93 #define YY(v) (v).vdata[1] 101 #define ZZ(v) (v).vdata[2] 112 #define VECTOR_R2(v, x, y) { \ 113 XX(v) = x; YY(v) = y; } 124 #define VECTOR_R3(v, x, y, z) { \ 125 XX(v) = x; YY(v) = y; ZZ(v) = z;} 134 #define V2_PLUS_V2(a, b, c) { \ 135 XX(a) = XX(b) + XX(c); \ 136 YY(a) = YY(b) + YY(c); } 145 #define V2_MINUS_V2(a, b, c) { \ 146 XX(a) = XX(b) - XX(c); \ 147 YY(a) = YY(b) - YY(c); } 162 #define V2_PLUS_CT(a, b, k) { \ 163 XX(a) = XX(b) + (k); \ 164 YY(a) = YY(b) + (k); } 179 #define V2_BY_CT(a, b, k) { \ 180 XX(a) = XX(b) * (k); \ 181 YY(a) = YY(b) * (k); } 190 #define V3_PLUS_V3(a, b, c) { \ 191 XX(a) = XX(b) + XX(c); \ 192 YY(a) = YY(b) + YY(c); \ 193 ZZ(a) = ZZ(b) + ZZ(c); } 202 #define V3_MINUS_V3(a, b, c) { \ 203 XX(a) = XX(b) - XX(c); \ 204 YY(a) = YY(b) - YY(c); \ 205 ZZ(a) = ZZ(b) - ZZ(c); } 220 #define V3_PLUS_CT(a, b, c) { \ 221 XX(a) = XX(b) + (c); \ 222 YY(a) = YY(b) + (c); \ 223 ZZ(a) = ZZ(b) + (c); } 238 #define V3_BY_CT(a, b, c) { \ 239 XX(a) = XX(b) * (c); \ 240 YY(a) = YY(b) * (c); \ 241 ZZ(a) = ZZ(b) * (c); } 245 #define VEC_ELEM(v,i) ((v).vdata[(i)]) 246 #define dMi(v, i) ((v).vdata[(i)]) 248 #define VEC_SWAP(v, i, j, aux) {aux = dMi(v, i); dMi(v, i) = dMi(v, j); dMi(v, j) = aux; } 380 memset(vdata, 0, vdim *
sizeof(T));
391 if (vdata != NULL && destroyData)
410 inline void resize(
size_t Xdim,
bool copy =
true)
424 new_vdata =
new T[(size_t) Xdim];
425 memset(new_vdata, 0, Xdim *
sizeof(T));
427 catch (std::bad_alloc &)
436 for (
size_t j = 0;
j < Xdim;
j++)
475 template<
typename T1>
484 template<
typename T1>
496 template<
typename T1>
499 return (vdim == op.
vdim);
594 memset(vdata, 0, vdim *
sizeof(T));
603 memset(vdata, 0, vdim *
sizeof(T));
615 template<
typename T1>
620 memset(vdata, 0, vdim *
sizeof(T));
653 size_t iBlockMax = op2.
vdim / 4;
654 for (
size_t i = 0;
i < iBlockMax;
i++)
656 (*ptr1++) = (*ptr2++) * op1;
657 (*ptr1++) = (*ptr2++) * op1;
658 (*ptr1++) = (*ptr2++) * op1;
659 (*ptr1++) = (*ptr2++) * op1;
661 for (
size_t i = iBlockMax * 4;
i < op2.
vdim; ++
i)
662 (*ptr1++) = (*ptr2++) * op1;
673 size_t iBlockMax = op2.
vdim / 4;
674 for (
size_t i = 0;
i < iBlockMax;
i++)
676 (*ptr1++) = op1 / (*ptr2++);
677 (*ptr1++) = op1 / (*ptr2++);
678 (*ptr1++) = op1 / (*ptr2++);
679 (*ptr1++) = op1 / (*ptr2++);
681 for (
size_t i = iBlockMax * 4;
i < op2.
vdim; ++
i)
682 (*ptr1++) = op1 / (*ptr2++);
693 size_t iBlockMax = op2.
vdim / 4;
694 for (
size_t i = 0;
i < iBlockMax;
i++)
696 (*ptr1++) = (*ptr2++) + op1;
697 (*ptr1++) = (*ptr2++) + op1;
698 (*ptr1++) = (*ptr2++) + op1;
699 (*ptr1++) = (*ptr2++) + op1;
701 for (
size_t i = iBlockMax * 4;
i < op2.
vdim; ++
i)
702 (*ptr1++) = (*ptr2++) + op1;
713 size_t iBlockMax = op2.
vdim / 4;
714 for (
size_t i = 0;
i < iBlockMax;
i++)
716 (*ptr1++) = op1 - (*ptr2++);
717 (*ptr1++) = op1 - (*ptr2++);
718 (*ptr1++) = op1 - (*ptr2++);
719 (*ptr1++) = op1 - (*ptr2++);
721 for (
size_t i = iBlockMax * 4;
i < op2.
vdim; ++
i)
722 (*ptr1++) = op1 - (*ptr2++);
957 double sum(
bool average =
false)
const;
995 return atan2((
double)
YY(*
this), (
double)
XX(*
this));
1011 void showWithGnuPlot(
const std::string& xlabel,
const std::string& title);
1048 friend std::ostream& operator<<(std::ostream& ostrm, const Matrix1D<T>& v)
1051 ostrm <<
"NULL Array\n";
1055 double max_val =
ABS(v.vdata[0]);
1057 for (
size_t j = 0;
j < v.vdim;
j++)
1065 for (
size_t j = 0;
j < v.vdim;
j++)
1071 for (
size_t j = 0;
j < v.vdim;
j++)
1139 template<
typename T>
1144 "Dot product: vectors of different size or shape");
1147 for (
size_t j = 0;
j < v1.
vdim;
j++)
1164 template<
typename T>
1172 "Vector_product: vectors are of different shape");
1185 template<
typename T>
1189 XX(result) =
YY(v1) *
ZZ(v2) -
ZZ(v1) *
YY(v2);
1190 YY(result) =
ZZ(v1) *
XX(v2) -
XX(v1) *
ZZ(v2);
1191 ZZ(result) =
XX(v1) *
YY(v2) -
YY(v1) *
XX(v2);
1205 template<
typename T>
1211 "sortTwoVectors: vectors are not of the same shape");
1213 for (
size_t j = 0;
j < v1.
vdim;
j++)
1226 template<
typename T1,
typename T2>
1236 for (
size_t j = 0;
j < v1.
vdim;
j++)
1243 template<
typename T1>
friend std::istream & operator>>(std::istream &in, Matrix1D< T > &v)
Matrix1D< double > DVector
void sortTwoVectors(Matrix1D< T > &v1, Matrix1D< T > &v2)
friend Matrix1D< T > operator+(T op1, const Matrix1D< T > &op2)
#define REPORT_ERROR(nerr, ErrormMsg)
void initZeros(size_t Xdim)
void computeMinMax(T &minval, T &maxval) const
Problem with matrix size.
Matrix1D< T > operator-() const
void indexSort(Matrix1D< int > &indx) const
void coreAllocate(int _vdim)
void sqrt(Image< double > &op)
Matrix1D< T > operator*(T op1) const
Matrix1D< double > vectorR3(double x, double y, double z)
There is not enough memory for allocation.
void showWithGnuPlot(const std::string &xlabel, const std::string &title)
void resizeNoCopy(const Matrix1D< T1 > &v)
int bestPrecision(float F, int _width)
Matrix1D< T > vectorProduct(const Matrix1D< T > &v1, const Matrix1D< T > &v2)
Matrix1D(const Matrix1D< T > &v)
void operator+=(const Matrix1D< T > &op1) const
bool sameShape(const Matrix1D< T1 > &op) const
String floatToString(float F, int _width, int _prec)
void write(const FileName &fn) const
Matrix1D< T > transpose() const
void read(const FileName &fn)
void operator-=(const Matrix1D< T > &op1) const
double computeMean() const
friend Matrix1D< T > operator-(T op1, const Matrix1D< T > &op2)
double dotProduct(const Matrix1D< T > &op1) const
void resize(const Matrix1D< T1 > &v)
void initZeros(const Matrix1D< T1 > &op)
void resize(size_t Xdim, bool copy=true)
friend Matrix1D< T > operator/(T op1, const Matrix1D< T > &op2)
bool row
<0=column vector (default), 1=row vector
double sum(bool average=false) const
Matrix1D< double > vectorR2(double x, double y)
basic_istream< char, std::char_traits< char > > istream
Matrix1D< T > operator/(T op1) const
Matrix1D< T > operator+(T op1) const
#define MATRIX1D_ARRAY(v)
Matrix1D(T1 dim, bool column=true)
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
T & operator()(int i) const
Matrix1D(bool column=true)
void numericalDerivative(Matrix1D< double > &result) const
void resizeNoCopy(int Xdim)
void computeMeanAndStddev(double &mean, double &stddev) const
Matrix1D< T > sort() const
T * vdata
The array itself.
T * adaptForNumericalRecipes() const
friend Matrix1D< T > operator*(T op1, const Matrix1D< T > &op2)
bool operator==(const Matrix1D< T > &op1) const
bool destroyData
Destroy data.
Matrix1D< T > & operator=(const Matrix1D< T > &op1)
void killAdaptationForNumericalRecipes(T *m) const
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
size_t vdim
Number of elements.