11 #ifndef __utlNDArrayFunctions_h 12 #define __utlNDArrayFunctions_h 33 template <
class T,
unsigned int Dim >
36 template <
class T,
unsigned int Dim >
40 template <
class T1,
class T2,
unsigned Dim1,
unsigned Dim2>
54 template <
class T,
unsigned int Dim,
class EType>
65 template <
class T,
unsigned int Dim,
class EType>
66 utl_shared_ptr< NDArray<T,Dim> >
74 template <
class T,
class EType>
75 utl_shared_ptr< NDArray<T,1> >
78 utl_shared_ptr< NDArray<T,1> > vec (
new NDArray<T,1>(expr));
83 template <
class T,
class EType>
84 utl_shared_ptr< NDArray<T,2> >
87 utl_shared_ptr< NDArray<T,2> > mat(
new NDArray<T,2>(expr));
95 std::vector<T> v(vec.
Size());
96 for (
int i = 0; i < vec.
Size(); i += 1 )
106 for (
int i = 0; i < vec.size(); ++i )
120 for (
int i = 0; i < in.
Rows(); i += 1 )
121 utl::spherical2Cartesian(in(i,0), in(i,1), in(i,2), out(i,0), out(i,1), out(i,2));
125 for (
int i = 0; i < in.
Columns(); i += 1 )
126 utl::spherical2Cartesian(in(0,i), in(1,i), in(2,i), out(0,i), out(1,i), out(2,i));
139 for (
int i = 0; i < in.
Rows(); i += 1 )
140 utl::cartesian2Spherical(in(i,0), in(i,1), in(i,2), out(i,0), out(i,1), out(i,2));
144 for (
int i = 0; i < in.
Columns(); i += 1 )
145 utl::cartesian2Spherical(in(0,i), in(1,i), in(2,i), out(0,i), out(1,i), out(2,i));
155 utlAssert(flip.size()==3,
"flip should have 3 elements");
159 for (
int i = 0; i < in.
Rows(); i += 1 )
161 for (
int j = 0; j < 3; ++j )
162 out(i,j)= flip[j]? -in(i,j) : in(i,j);
167 for (
int i = 0; i < in.
Columns(); i += 1 )
169 for (
int j = 0; j < 3; ++j )
170 out(j,i)= flip[j]? -in(j,i) : in(j,i);
196 unsigned int const* shape = tensor.
GetShape();
198 utlException(shape[0]!=3 || shape[1]!=3 || shape[2]!=3 || shape[3]!=3,
"It should be in 3D space");
203 mat(0,0)=tensor(0,0,0,0), mat(0,1)=tensor(0,0,1,1), mat(0,2)=tensor(0,0,2,2), mat(0,3)=s2*tensor(0,0,0,1), mat(0,4)=s2*tensor(0,0,0,2), mat(0,5)=s2*tensor(0,0,1,2);
204 mat(1,0)=tensor(1,1,0,0), mat(1,1)=tensor(1,1,1,1), mat(1,2)=tensor(1,1,2,2), mat(1,3)=s2*tensor(1,1,0,1), mat(1,4)=s2*tensor(1,1,0,2), mat(1,5)=s2*tensor(1,1,1,2);
205 mat(2,0)=tensor(2,2,0,0), mat(2,1)=tensor(2,2,1,1), mat(2,2)=tensor(2,2,2,2), mat(2,3)=s2*tensor(2,2,0,1), mat(2,4)=s2*tensor(2,2,0,2), mat(2,5)=s2*tensor(2,2,1,2);
206 mat(3,0)=s2*tensor(0,1,0,0), mat(3,1)=s2*tensor(0,1,1,1), mat(3,2)=s2*tensor(0,1,2,2), mat(3,3)=2.0*tensor(0,1,0,1), mat(3,4)=2.0*tensor(0,1,0,2), mat(3,5)=2.0*tensor(0,1,1,2);
207 mat(4,0)=s2*tensor(0,2,0,0), mat(4,1)=s2*tensor(0,2,1,1), mat(4,2)=s2*tensor(0,2,2,2), mat(4,3)=2.0*tensor(0,2,0,1), mat(4,4)=2.0*tensor(0,2,0,2), mat(4,5)=2.0*tensor(0,2,1,2);
208 mat(5,0)=s2*tensor(1,2,0,0), mat(5,1)=s2*tensor(1,2,1,1), mat(5,2)=s2*tensor(1,2,2,2), mat(5,3)=2.0*tensor(1,2,0,1), mat(5,4)=2.0*tensor(1,2,0,2), mat(5,5)=2.0*tensor(1,2,1,2);
220 tensor(0,0,0,0)=mat(0,0);
221 tensor(0,0,0,1)=si2*mat(0,3); tensor(0,0,1,0)=tensor(0,0,0,1);
222 tensor(0,0,0,2)=si2*mat(0,4); tensor(0,0,2,0)=tensor(0,0,0,2);
223 tensor(0,0,1,1)=mat(0,1);
224 tensor(0,0,1,2)=si2*mat(0,5); tensor(0,0,2,1)=tensor(0,0,1,2);
225 tensor(0,0,2,2)=mat(0,2);
226 tensor(0,1,0,0)=si2*mat(3,0); tensor(1,0,0,0)=tensor(0,1,0,0);
227 tensor(0,1,0,1)=0.5*mat(3,3); tensor(1,0,0,1)=tensor(0,1,0,1); tensor(0,1,1,0)=tensor(0,1,0,1); tensor(1,0,1,0)=tensor(0,1,0,1);
228 tensor(0,1,0,2)=0.5*mat(3,4); tensor(0,1,2,0)=tensor(0,1,0,2); tensor(1,0,0,2)=tensor(0,1,0,2); tensor(1,0,2,0)=tensor(0,1,0,2);
229 tensor(0,1,1,1)=si2*mat(3,1); tensor(1,0,1,1)=tensor(0,1,1,1);
230 tensor(0,1,1,2)=0.5*mat(3,5); tensor(1,0,1,2)=tensor(0,1,1,2); tensor(0,1,2,1)=tensor(0,1,1,2); tensor(1,0,2,1)=tensor(0,1,1,2);
231 tensor(0,1,2,2)=si2*mat(3,2); tensor(1,0,2,2)=tensor(0,1,2,2);
232 tensor(0,2,0,0)=si2*mat(4,0); tensor(2,0,0,0)=tensor(0,2,0,0);
233 tensor(0,2,0,1)=0.5*mat(4,3); tensor(0,2,1,0)=tensor(0,2,0,1); tensor(2,0,0,1)=tensor(0,2,0,1); tensor(2,0,1,0)=tensor(0,2,0,1);
234 tensor(0,2,0,2)=0.5*mat(4,4); tensor(2,0,0,2)=tensor(0,2,0,2); tensor(0,2,2,0)=tensor(0,2,0,2); tensor(2,0,2,0)=tensor(0,2,0,2);
235 tensor(0,2,1,1)=si2*mat(4,1); tensor(2,0,1,1)=tensor(0,2,1,1);
236 tensor(0,2,1,2)=0.5*mat(4,5); tensor(2,0,1,2)=tensor(0,2,1,2); tensor(0,2,2,1)=tensor(0,2,1,2); tensor(2,0,2,1)=tensor(0,2,1,2);
237 tensor(0,2,2,2)=si2*mat(4,2); tensor(2,0,2,2)=tensor(0,2,2,2);
238 tensor(1,1,0,0)=mat(1,0);
239 tensor(1,1,0,1)=si2*mat(1,3); tensor(1,1,1,0)=tensor(1,1,0,1);
240 tensor(1,1,0,2)=si2*mat(1,4); tensor(1,1,2,0)=tensor(1,1,0,2);
241 tensor(1,1,1,1)=mat(1,1);
242 tensor(1,1,1,2)=si2*mat(1,5); tensor(1,1,2,1)=tensor(1,1,1,2);
243 tensor(1,1,2,2)=mat(1,2);
244 tensor(1,2,0,0)=si2*mat(5,0); tensor(2,1,0,0)=tensor(1,2,0,0);
245 tensor(1,2,0,1)=0.5*mat(5,3); tensor(2,1,0,1)=tensor(1,2,0,1); tensor(1,2,1,0)=tensor(1,2,0,1); tensor(2,1,1,0)=tensor(1,2,0,1);
246 tensor(1,2,0,2)=0.5*mat(5,4); tensor(2,1,0,2)=tensor(1,2,0,2); tensor(1,2,2,0)=tensor(1,2,0,2); tensor(2,1,2,0)=tensor(1,2,0,2);
247 tensor(1,2,1,1)=si2*mat(5,1); tensor(2,1,1,1)=tensor(1,2,1,1);
248 tensor(1,2,1,2)=0.5*mat(5,5); tensor(2,1,1,2)=tensor(1,2,1,2); tensor(1,2,2,1)=tensor(1,2,1,2); tensor(2,1,2,1)=tensor(1,2,1,2);
249 tensor(1,2,2,2)=si2*mat(5,2); tensor(2,1,2,2)=tensor(1,2,2,2);
250 tensor(2,2,0,0)=mat(2,0);
251 tensor(2,2,0,1)=si2*mat(2,3); tensor(2,2,1,0)=tensor(2,2,0,1);
252 tensor(2,2,0,2)=si2*mat(2,4); tensor(2,2,2,0)=tensor(2,2,0,2);
253 tensor(2,2,1,1)=mat(2,1);
254 tensor(2,2,1,2)=si2*mat(2,5); tensor(2,2,2,1)=tensor(2,2,1,2);
255 tensor(2,2,2,2)=mat(2,2);
267 utl::PrintMatrix<NDArray<T,2> >(mat, mat.
Rows(), mat.Columns(), str, separate, os);
272 PrintUtlVector(
const NDArray<T,1>& vec,
const std::string& str=
"",
const char* separate=
" ", std::ostream& os=std::cout,
bool showStats=
true)
277 template <
class T,
unsigned int Dim>
281 arr.
Print(os<< str, separate );
284 template <
class T=
double>
286 Eye(
const int n,
const T val=1.0)
294 template <
class T=
double>
303 template <
class T=
double>
312 template<
typename T,
unsigned int Dim >
314 operator<<(std::ostream & os, const NDArray<T,Dim> & arr)
316 arr.
Print(os<<
"utl::NDArray<T,Dim>" );
320 template<
typename T >
322 operator<<(std::ostream & os, const NDArray<T,1> & arr)
328 template<
typename T >
330 operator<<(std::ostream & os, const NDArray< T,2 > & arr)
360 __utl_gemv_MatrixTimesVector(T,
gemv_UtlMatrixTimesVector, Utl,
utl::NDArray<T UTL_COMMA 2>, Rows, Cols, GetData,
utl::NDArray<T UTL_COMMA 1>, Size, GetData, ReSize);
381 __utl_gevm_MatrixTimesVector(T,
gevm_UtlVectorTimesMatrix, Utl,
utl::NDArray<T UTL_COMMA 2>, Rows, Cols, GetData,
utl::NDArray<T UTL_COMMA 1>, Size, GetData, ReSize);
498 template <
class T>
inline void 502 char JOBZ=
'V', UPLO=
'U';
503 int N = mat.
Rows(),INFO=0, LWORK=-1;
516 INFO = utl::syev<T>(LAPACK_COL_MAJOR, JOBZ,UPLO,N,eigenVectors.
GetData(), N, eigenValues.
GetData());
517 utlGlobalException(INFO,
"LAPACK library function dsyev_() returned error code INFO=" << INFO);
529 template <
class T>
inline void 533 char JOBZ=
'V', UPLO=
'U';
534 int N = mat.
Rows(),INFO=0, LWORK=-1, LIWORK=-1;
551 INFO = utl::syevd<T>(LAPACK_COL_MAJOR, JOBZ,UPLO,N,eigenVectors.
GetData(), N, eigenValues.
GetData());
552 utlGlobalException(INFO,
"LAPACK library function dsyevd_() returned error code INFO=" << INFO);
565 template <
class T>
inline void 568 utlException(format!=
'S' && format!=
'A',
"wrong format. format should be 'A' or 'S' ");
569 int M=mat.
Rows(), N=mat.
Cols(), INFO=0;
584 char formatU=format, formatV=format;
585 int LDA=M, LDU=M, LWORK=-1;
598 T* superb =
new T[min_MN];
599 INFO=utl::gesvd<T>(LAPACK_COL_MAJOR, formatU, formatV, M, N, matTmp.
GetData(), LDA, s.
GetData(), U.
GetData(), LDU, V.
GetData(), LDVT, superb);
604 utlGlobalException(INFO,
"LAPACK library function dgesvd_() returned error code INFO=" << INFO);
619 template <
class T>
inline void 622 utlException(format!=
'S' && format!=
'A',
"wrong format. format should be 'A' or 'S' ");
623 int M=mat.
Rows(), N=mat.
Cols(), INFO=0;
638 char formatU=format, formatV=format;
639 int LDA=M, LDU=M, LWORK;
657 INFO=
utl::gesdd(LAPACK_COL_MAJOR, format, M, N, matTmp.
GetData(), LDA, s.GetData(), U.
GetData(), LDU, V.
GetData(), LDVT);
661 utlGlobalException(INFO,
"LAPACK library function dgesdd_() returned error code INFO=" << INFO);
672 template <
class T,
unsigned int Dim>
681 template <
class T,
unsigned int Dim>
689 template <
unsigned int Dim>
690 inline std::complex<double>
693 utlSAException(v1.Size() != v2.Size())(v1.Size())(v2.Size()).msg(
"vector sizes mismatch");
694 std::complex<double> result;
719 unsigned int const* shapeT = tensor.
GetShape();
720 unsigned int const* shapeM = matrix.
GetShape();
722 (shapeT[2])(shapeM[0])(shapeT[3])(shapeM[1]).msg(
"sizes do not match");
724 result.
ReSize(shapeT[0], shapeT[1]);
728 for (
int i = 0; i < shapeT[0]; ++i )
730 for (
int j = 0; j < shapeT[1]; ++j )
744 unsigned int const* shapeT = tensor.
GetShape();
745 unsigned int const* shapeM = matrix.
GetShape();
747 (shapeT[0])(shapeM[0])(shapeT[1])(shapeM[1]).msg(
"sizes do not match");
749 result.
ReSize(shapeT[2], shapeT[3]);
752 for (
int k = 0; k < shapeT[2]; ++k )
754 for (
int l = 0; l < shapeT[3]; ++l )
758 for (
int i = 0; i < shapeT[0]; ++i )
760 for (
int j = 0; j < shapeT[1]; ++j )
762 result[nn] += tensor(i,j,k,l) * matrix[off];
776 unsigned const* shape1 = mat1.
GetShape();
777 unsigned const* shape2 = mat2.
GetShape();
778 size[0]=shape1[0], size[1]=shape1[1];
779 size[2]=shape2[0], size[3]=shape2[1];
784 for (
int i = 0; i < size[0]; ++i )
786 for (
int j = 0; j < size[1]; ++j )
789 for (
int k = 0; k < size[2]; ++k )
791 for (
int l = 0; l < size[3]; ++l )
793 tensor[off0] = mat1[off1] * mat2[off2];
807 bool isComplex = std::is_same<T, std::complex<double>>::value ||std::is_same<T, std::complex<float>>::value;
809 for (
int i = 0; i < v1.
Size(); ++i )
810 for (
int j = 0; j < v2.
Size(); ++j )
813 mat(i,j) = v1[i]*std::conj(v2[j]);
815 mat(i,j) = v1[i]*v2[j];
846 template<
typename T >
878 template<
typename T >
888 template<
typename T >
898 template<
typename T,
typename EType >
902 utl_shared_ptr<NDArray<T,2> > mat = ToMatrix<T>(expr);
942 int lwork=-1, INFO=0;
943 int* ipiv=
new int[n];
957 utl::sytrf<T>(LAPACK_COL_MAJOR, uplo,n,result.
GetData(),n,ipiv);
958 INFO=utl::sytri<T>(LAPACK_COL_MAJOR, uplo,n,result.
GetData(),n,ipiv);
961 utlGlobalException(INFO>0,
"The matrix is singular and its inverse could not be computed. \ 962 LAPACK library function sytrid_() returned error code INFO=" << INFO);
963 utlGlobalException(INFO<0,
"LAPACK library function sytrid_() returned error code INFO=" << INFO);
966 for (
int i = 0; i < n; ++i )
967 for (
int j = 0; j < i; ++j )
968 data[j*n+i] = data[i*n+j];
985 for (
unsigned i=0; i<N; ++i)
988 S(i,i) = 1.0/eigenValues[i];
1005 mat.
SVD(U, S, V,
'S');
1008 for (
int i = 0; i < S.
Size(); i += 1 )
1011 diag(i,i) = 1.0/S[i];
1025 int m1Size = m1.
Size();
1026 for (
int i = 0; i < m1Size; i += 1 )
1028 for (
int i = 0; i < m2.
Size(); i += 1 )
1029 result[i+m1Size] = m2[i];
1041 int m1Rows = m1.
Rows();
1042 for (
int j = 0; j < m1.
Columns(); j += 1 )
1044 for (
int i = 0; i < m1.
Rows(); i += 1 )
1045 result(i,j) = m1(i,j);
1046 for (
int i = 0; i < m2.
Rows(); i += 1 )
1047 result(i+m1Rows,j) = m2(i,j);
1056 for (
int i = 0; i < m1.
Rows(); i += 1 )
1058 for (
int j = 0; j < m1.
Columns(); j += 1 )
1059 result(i,j) = m1(i,j);
1060 for (
int j = 0; j < m2.
Columns(); j += 1 )
1061 result(i,j+m1Columns) = m2(i,j);
1067 template <
class T,
unsigned Dim>
1069 Real (
const NDArray<std::complex<T>, Dim >& mat )
1072 for (
int i = 0; i < mat.Size(); ++i )
1073 result[i] = std::real(mat[i]);
1077 template <
class T,
unsigned Dim>
1079 Imag (
const NDArray<std::complex<T>, Dim >& mat )
1082 for (
int i = 0; i < mat.Size(); ++i )
1083 result[i] = std::imag(mat[i]);
1089 template <
class T,
unsigned Dim>
1094 typedef std::complex<T> VT;
1096 for (
int i = 0; i < result.Size(); ++i )
1097 result[i] = VT(arrReal[i], arrImg[i]);
1102 template <
class T,
unsigned Dim>
1103 NDArray<std::complex<T>, Dim>
1106 typedef std::complex<T> VT;
1108 for (
int i = 0; i < result.Size(); ++i )
1109 result[i] = VT(val, arrImg[i]);
1114 template <
class T,
unsigned Dim>
1115 NDArray<std::complex<T>, Dim>
1118 typedef std::complex<T> VT;
1120 for (
int i = 0; i < result.Size(); ++i )
1121 result[i] = VT(arrReal[i], val);
1131 int n = QInverse.
Rows();
1155 int N = matrixVec.size();
1161 mat.FillDiagonal(1.0);
1168 tangentVec.Fill(0.0);
1169 for (
int i = 0; i < N; ++i )
1172 matTmp = matTmp.
LogM() ;
1173 tangentVec += matTmp % weights[i];
1176 mat = mat * tangentVec.ExpM();
1178 }
while ( normVec>eps );
1187 int N = matrixVec.size();
1204 (rotMat.
Rows())(rotMat.
Cols()).msg(
"wrong size of rotMat");
1207 theta = std::acos((rotMat(0,0)+rotMat(1,1)+rotMat(2,2)-1.0)/2.0);
1210 axis[0]= rotMat(2,1)-rotMat(1,2);
1211 axis[1]= rotMat(0,2)-rotMat(2,0);
1212 axis[2]= rotMat(1,0)-rotMat(0,1);
1221 matTmp.
SVD(U, S, V);
1241 double c=std::cos(theta), s=std::sin(theta);
1245 rotMat(0,0) = t*v[0]*v[0] + c; rotMat(0,1) = t*v[0]*v[1] - v[2]*s; rotMat(0,2) = t*v[0]*v[2] + v[1]*s;
1246 rotMat(1,0) = t*v[0]*v[1] + v[2]*s; rotMat(1,1) = t*v[1]*v[1] + c; rotMat(1,2) = t*v[1]*v[2] - v[0]*s;
1247 rotMat(2,0) = t*v[0]*v[2] - v[1]*s; rotMat(2,1) = t*v[1]*v[2] + v[0]*s; rotMat(2,2) = t*v[2]*v[2] + c;
1254 int N = dirVec.size();
1257 int dim = dirVec[0].Size();
1261 for (
int i = 0; i < N; ++i )
1269 if (mat.GetTwoNorm()>1e-10)
1272 meanV = eigenVectors.
GetRow(dim-1);
1276 return meanV % eigenValues[dim-1];
NDArray is a N-Dimensional array class (row-major, c version)
void InverseSmallMatrix(const TMatrixType &mat, TMatrixType &result, const int row)
NDArray<T,1> is a vector class which uses blas mkl.
void PrintContainer(IteratorType v1, IteratorType v2, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
bool gemm_UtlMatrixTimesMatrix(const bool bATrans, const bool bBTrans, const T alpha, const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 2 > &B, const T beta, utl::NDArray< T, 2 > &C)
typename remove_complex< T >::type remove_complex_t
#define __utl_geev_Matrix(T, FuncName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, MatrixGetDataFuncName, VectorName, VectorGetDataFuncName, ReSizeFuncName)
geev_VnlMatrix Calculate non-symmetric eigen-decomposition. Define 3 functions. 1) calculate only eig...
bool IsSameShape(const NDArray< T1, Dim1 > &arr1, const NDArray< T2, Dim2 > &arr2)
void GetRow(const int index, T *vec) const
utl::NDArray< T, 2 > GetMeanOfRotationMatrix(const std::vector< NDArray< T, 2 > > &matrixVec, const utl::NDArray< T, 1 > &weights)
base class for expression
bool ReSize(const SizeType s0, const SizeType s1, const SizeType s2, const SizeType s3)
void syevd_UtlMatrix(const NDArray< T, 2 > &mat, NDArray< T, 1 > &eigenValues, NDArray< T, 2 > &eigenVectors)
dsyevd_UtlMatrix eigen-decomposition for symmetric matrix. dsyevd is faster than dsyev http://www...
NDArray< T, 2 > operator*(const NDArray< T, 2 > &mat1, const NDArray< T, 2 > &mat2)
void Print(std::ostream &os, const char *separate=" ") const
NDArray< T, 2 > SetIdentity()
bool IsSameShape(const EType &src) const
void gesdd_UtlMatrix(const NDArray< T, 2 > &mat, NDArray< T, 2 > &U, NDArray< utl::remove_complex_t< T >, 1 > &s, NDArray< T, 2 > &V, char format='S')
dgesdd_UtlMatrix dgesdd is faster than dgesvd. http://www.netlib.org/lapack/explore-html/db/db4/dgesd...
void Convert4To2Tensor(const utl::NDArray< T, 4 > &tensor, utl::NDArray< T, 2 > &mat)
void PrintUtlNDArray(const NDArrayBase< T, Dim > &arr, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout)
void PrintUtlMatrix(const NDArray< T, 2 > &mat, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout)
void SVD(NDArray< T, 2 > &U, NDArray< ScalarValueType, 1 > &S, NDArray< T, 2 > &V, char format='S') const
SVD.
NDArray< T, 2 > ConnectUtlMatrix(const NDArray< T, 2 > &m1, const NDArray< T, 2 > &m2, const bool isConnectRow)
static constexpr double SQRT1_2
#define utlException(cond, expout)
NDArray< T, 2 > GetTranspose(const T scale=1.0) const
void spherical2Cartesian(const T r, const T theta, const T phi, T &x, T &y, T &z)
NDArray< T, 1 > DifferenceOfDirection(const NDArray< T, 1 > v1, const NDArray< T, 1 > &v0)
NDArray<T,2> is a row-major matrix.
double GetTwoNorm() const
void RotationMatrixToAxisAngle(const NDArray< T, 2 > &rotMat, NDArray< T, 1 > &axis, double &theta)
NDArray< T, 1 > StdVectorToUtlVector(const std::vector< T > &vec)
NDArray< T, 2 > CartesianToSpherical(const NDArray< T, 2 > &in)
NDArray< T, 2 > FlipOrientations(const NDArray< T, 2 > &in, const std::vector< int > &flip)
NDArray< T, 2 > PInverseSymmericMatrix(const NDArray< T, 2 > &mat, const double eps=1e-10)
void gesvd_UtlMatrix(const NDArray< T, 2 > &mat, NDArray< T, 2 > &U, NDArray< T, 1 > &s, NDArray< T, 2 > &V, char format='S')
dgesvd_UtlMatrix
void AxisAngleToRotationMatrix(const NDArray< T, 1 > &axis, const double theta, NDArray< T, 2 > &rotMat)
const T & min(const T &a, const T &b)
Return the minimum between a and b.
void ProductUtlvM(const utl::NDArray< T, 1 > &b, const utl::NDArray< T, 2 > &A, utl::NDArray< T, 1 > &c, const double alpha=1.0, const double beta=0.0)
utl::NDArray< T, 1 > Ones(const int n)
utl::NDArray< T, 1 > MeanDirector(const std::vector< utl::NDArray< T, 1 > > &dirVec, const bool isUnitNorm=true)
std::shared_ptr< NDArray< T, 1 > > ToVector(const Expr< EType, typename EType::ValueType > &expr)
bool gemv_UtlMatrixTimesVector(const bool bATrans, const T alpha, const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 1 > &X, const T beta, utl::NDArray< T, 1 > &Y)
void ProductUtlMM(const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 2 > &B, utl::NDArray< T, 2 > &C, const double alpha=1.0, const double beta=0.0)
NDArray< T, 2 > InverseMatrix(const NDArray< T, 2 > &mat, const double eps=1e-10)
int gesdd(int matrix_order, char JOBZ, int M, int N, T *A, int LDA, T *S, T *U, int LDU, T *VT, int LDVT)
T abs(const T x)
template version of the fabs function
Base class for utl::NDArray.
double DotProduct(const TVector1 &v1, const TVector2 &v2, const int N1)
#define utlGlobalException(cond, expout)
utl::NDArray< T, 2 > Eye(const int n, const T val=1.0)
NDArray< T, 2 > & FillDiagonal(const T val)
#define __utl_gemv_MatrixTimesVector(T, FuncName, FuncHelperName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, MatrixGetDataFuncName, VectorName, GetSizeFuncName, VectorGetDataFuncName, ReSizeFuncName)
void getri_UtlMatrix(const utl::NDArray< T, 2 > &mat, utl::NDArray< T, 2 > &result)
geev_UtlMatrix calculate inverse of a general matrix via LU decomposition.
NDArray< T, Dim > Real(const NDArray< std::complex< T >, Dim > &mat)
#define __utl_syrk_Matrix(T, FuncName, FuncHelperName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, GetDataFuncName, ReSizeFuncName)
macro for syrk and row-major matrix
void Fill(const T &value)
std::vector< T > UtlVectorToStdVector(const NDArray< T, 1 > &vec)
void GetEqualityConstraintProjection(const NDArray< T, 2 > &Aeq, const NDArray< T, 1 > &beq, const NDArray< T, 2 > &QInverse, NDArray< T, 2 > &projMatrix, NDArray< T, 1 > &projVector)
std::shared_ptr< NDArray< T, Dim > > ToNDArray(const Expr< EType, typename EType::ValueType > &expr)
void syrk_UtlMatrix(const bool trans, const T alpha, const utl::NDArray< T, 2 > &A, const T beta, utl::NDArray< T, 2 > &C)
syrk_UtlMatrix
NDArray< T, 2 > PInverseMatrix(const NDArray< T, 2 > &mat, const double eps=1e-10)
#define utlSAException(expr)
void EigenDecompositionSymmetricMatrix(NDArray< T, 1 > &eigenValues, NDArray< T, 2 > &eigenVectors) const
Eigen-decomposition for symmetric matrix.
void OuterProduct(const TVector1 &v1, const int N1, const TVector2 &v2, const int N2, TMatrix &mat)
#define __utl_gemm_MatrixTimesMatrix(T, FuncName, FuncHelperName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, GetDataFuncName, ReSizeFuncName)
void cblas_zdotu_sub(const int N, const void *X, const int incX, const void *Y, const int incY, void *dotu)
NDArray< T, Dim > Imag(const NDArray< std::complex< T >, Dim > &mat)
NDArray< T, 2 > InverseSymmericMatrix(const NDArray< T, 2 > &mat, const double eps=1e-10)
NDArray< T, 2 > SphericalToCartesian(const NDArray< T, 2 > &in)
void GetColumn(const int index, T *vec) const
NDArray< T, 2 > GetRefSubMatrix(const int i, const int j) const
std::shared_ptr< NDArray< T, 2 > > ToMatrix(const Expr< EType, typename EType::ValueType > &expr)
#define utlAssert(cond, expout)
#define __utl_getri_Matrix(T, FuncName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, MatrixGetDataFuncName, ReSizeFuncName)
bool gevm_UtlVectorTimesMatrix(const bool bATrans, const T alpha, const utl::NDArray< T, 1 > &X, const utl::NDArray< T, 2 > &A, const T beta, utl::NDArray< T, 1 > &Y)
void cartesian2Spherical(const T x, const T y, const T z, T &r, T &theta, T &phi)
double InnerProduct(const TVector1 &v1, const TVector2 &v2, const int N1)
void ProductUtlMtM(const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 2 > &B, utl::NDArray< T, 2 > &C, const double alpha=1.0, const double beta=0.0)
void ProductUtlMMt(const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 2 > &B, utl::NDArray< T, 2 > &C, const double alpha=1.0, const double beta=0.0)
const ShapeType GetShape() const
void PrintUtlVector(const NDArray< T, 1 > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
NDArray< T, 1 > ConnectUtlVector(const NDArray< T, 1 > &m1, const NDArray< T, 1 > &m2)
NDArray< std::complex< T >, Dim > ComplexCombine(const NDArray< T, Dim > &arrReal, const NDArray< T, Dim > &arrImg)
void geev_UtlMatrix(const utl::NDArray< T, 2 > &mat, utl::NDArray< T, 1 > &valReal, utl::NDArray< T, 1 > &valImg, utl::NDArray< T, 2 > &vecRealR, utl::NDArray< T, 2 > &vecImgR, utl::NDArray< T, 2 > &vecRealL, utl::NDArray< T, 2 > &vecImgL)
geev_UtlMatrix calculate non-symmetric eigen-decomposition.
bool ReSize(const SizeType rows, const SizeType cols)
NDArray< T, Dim > Eval(const Expr< EType, typename EType::ValueType > &expr)
bool ReSize(const SizeType size)
static constexpr double SQRT2
#define __utl_gevm_MatrixTimesVector(T, FuncName, FuncHelperName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, MatrixGetDataFuncName, VectorName, GetSizeFuncName, VectorGetDataFuncName, ReSizeFuncName)
void ProductUtlMv(const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 1 > &b, utl::NDArray< T, 1 > &c, const double alpha=1.0, const double beta=0.0)
NDArray<T,4> is a 4th order tensor.
void Convert2To4Tensor(const utl::NDArray< T, 2 > &mat, utl::NDArray< T, 4 > &tensor)
void syev_UtlMatrix(const NDArray< T, 2 > &mat, NDArray< T, 1 > &eigenValues, NDArray< T, 2 > &eigenVectors)
dsyev_VnlMatrix eigen-decomposition for symmetric matrix. http://www.netlib.org/lapack/explore-html/d...