17 #include <hdf5/serial/H5Cpp.h> 18 #include <hdf5/openmpi/hdf5.h> 23 #include <unsupported/Eigen/MatrixFunctions> 38 std::vector<T>
operator/(
const std::vector<T>& vec, T scalar) {
39 std::vector<T> newvec = vec;
40 for (
auto&& v : newvec) {
47 std::vector<std::vector<T>>
operator/(
const std::vector<std::vector<T>>& veclist, T scalar) {
48 std::vector<std::vector<T>> newveclist = veclist;
49 for (
auto&& vec : newveclist) {
50 for (
auto&& v : vec) {
59 for (
auto&& v : vec) {
66 for (
auto&& v : vec) {
72 std::vector<T>
operator*(
const std::vector<T>& vec,
const T scalar) {
73 std::vector<T> newvec = vec;
79 std::vector<T>
operator*(
const T scalar,
const std::vector<T>& vec) {
84 std::vector<std::vector<T>>
operator*(T scalar,
const std::vector<std::vector<T>>& veclist) {
85 return veclist*scalar;
89 std::vector<T>
abs(
const std::vector<T>& vec) {
90 std::vector<T> absVec = vec;
91 for (
auto&& v : absVec) {
98 T
min(
const std::vector<T>& vec) {
99 T val = *(std::min_element(vec.begin(), vec.end()));
103 template <
typename T>
104 T
max(
const std::vector<T>& vec) {
105 T val = *(std::max_element(vec.begin(), vec.end()));
109 template <
typename T>
110 std::vector<T>
operator-(
const std::vector<T>& vec1,
const std::vector<T>& vec2) {
111 unsigned int n = vec1.size();
112 if (n != vec2.size()) {
113 throw std::runtime_error(
"Vector size mismatch.");
115 std::vector<T> vecout(n);
116 for (
unsigned int i=0; i<n; i++) {
117 vecout[i] = vec1[i] - vec2[i];
127 template <
typename T>
128 T
prod(
const std::vector<T>& vec) {
130 for (
auto&& v : vec) {
137 template <
typename T>
138 std::ostream& operator<<(std::ostream& out, const std::vector<T>& vec)
141 for (
unsigned int i=0; i<vec.size(); i++) {
143 if (i != vec.size()-1) {
150 template <
typename T>
151 std::ostream& operator<<(std::ostream& out, const std::valarray<T>& vec)
154 for (
unsigned int i=0; i<vec.size(); i++) {
156 if (i != vec.size()-1) {
169 explicit TensorError (
const std::string &val) : std::runtime_error::runtime_error(val) {}
185 inline idx2d unflat(
unsigned int flatIdx,
unsigned int n1,
unsigned int n2)
190 idx.
j = flatIdx - idx.
i*n2;
193 idx.
i = flatIdx - idx.
j*n1;
219 inline idx4d unflat(
unsigned int flatIdx,
unsigned int n1,
unsigned int n2,
220 unsigned int n3,
unsigned int n4)
224 idx.
i = flatIdx/(n2*n3*n4);
225 idx.
j = (flatIdx - idx.
i*n2*n3*n4)/(n3*n4);
226 idx.
k = (flatIdx - idx.
i*n2*n3*n4 - idx.
j*n3*n4)/(n4);
227 idx.
l = (flatIdx - idx.
i*n2*n3*n4 - idx.
j*n3*n4 - idx.
k*n4);
229 idx.
i = flatIdx/(n3*n2*n1);
230 idx.
j = (flatIdx - idx.
i*n3*n2*n1)/(n2*n1);
231 idx.
k = (flatIdx - idx.
i*n3*n2*n1 - idx.
j*n2*n1)/(n1);
232 idx.
l = (flatIdx - idx.
i*n3*n2*n1 - idx.
j*n2*n1 - idx.
k*n1);
240 template <
typename T,
typename U>
241 std::vector<T>
unflatC(T flatIdx, std::vector<U> dims) {
243 unsigned int rank = dims.size();
246 std::vector<T> idx(rank);
249 T remainingIdx = flatIdx;
252 unsigned int stride = 1;
253 for (
unsigned int i=0; i<rank; i++) {
258 for (
unsigned int i=0; i<rank; i++) {
263 idx[i] = remainingIdx/stride;
266 remainingIdx -= idx[i]*stride;
270 if (remainingIdx != 0) {
271 throw std::runtime_error(
"Something has gone wrong with the index calculation.");
278 template <
typename T,
typename U>
279 T
flatC(std::vector<T> idx, std::vector<U> dims) {
280 unsigned int rank = dims.size();
281 if (idx.size() != rank)
throw TensorError(
"Dimensions mismatch.");
283 unsigned int stride = 1;
284 for (
int i=rank-1; i>=0; i--) {
285 flatIdx += idx[i]*stride;
292 template <
typename T>
293 std::vector<T>
ones(
unsigned int n) {
294 std::vector<T> vec(n);
295 for (
auto&& v : vec) {
302 template <
typename T>
304 template <
typename T>
308 template <
typename T>
322 template <
typename T>
326 template<
typename U,
unsigned int M,
unsigned int N>
friend class Tensor2CUDA;
333 Tensor2(
const unsigned int n1,
const unsigned int n2);
339 unsigned int getn1()
const {
return n1;}
340 unsigned int getn2()
const {
return n2;}
344 T getVal(
const unsigned int i,
const unsigned int j)
const;
347 T getValFlat(
const unsigned int flatIdx)
const;
350 void setVal(
const unsigned int i,
const unsigned int j, T val);
351 T &operator()(
const unsigned int i,
const unsigned int j);
352 T &operator()(
const unsigned int flatIdx);
353 void copyValuesOut(T* outVals)
const;
362 void printToStream(std::ostream& out)
const;
365 Tensor2(H5::DataSet& dataset, std::vector<hsize_t> gridOffset, std::vector<hsize_t> tensorDims);
366 void writeToExistingHDF5Dataset(H5::DataSet& dataset, std::vector<hsize_t> arrayOffset);
368 Tensor2(H5::H5File& file,
const H5std_string& datasetName, std::vector<hsize_t> tensorDims);
369 void writeToNewHDF5(
const H5std_string& filename,
const H5std_string& datasetName);
370 void addAsNewHDF5Dataset(H5::H5File& file,
const H5std_string& datasetName);
373 Tensor2(hid_t dset_id, hid_t plist_id, std::vector<hsize_t> gridOffset, std::vector<hsize_t> tensorDims);
374 void writeToExistingHDF5Dataset(hid_t dset_id, hid_t plist_id, std::vector<hsize_t> arrayOffset);
384 void assertSquare()
const;
387 bool isRotationMatrix()
const;
395 T spectralNorm()
const;
396 T frobeniusNorm()
const;
406 Tensor2<T> constrainedTo(
const T minVal,
const T maxVal)
const;
407 void constrainInPlace(
const T minVal,
const T maxVal);
414 void evecDecomposition(std::valarray<T>& evals,
Tensor2<T>& evecs);
421 template <
typename U>
423 template <
typename U>
425 template <
typename U>
427 template <
typename U>
429 template <
typename U>
433 template <
typename U>
435 template <
typename U>
437 template <
typename U>
441 template <
typename U>
443 template <
typename U>
445 template <
typename U>
447 template <
typename U>
449 template <
typename U>
451 template <
typename U>
453 template <
typename U>
455 template <
typename U>
459 template <
typename U>
461 template <
typename U>
463 template <
typename U>
465 template <
typename U>
467 template <
typename U>
469 template <
typename U>
473 template <
typename U>
475 template <
typename U>
477 template <
typename U>
479 template <
typename U>
481 template <
typename U>
485 template <
typename U>
487 template <
typename U>
489 template <
typename U>
493 template <
typename U>
495 template <
typename U>
499 template <
typename U>
508 unsigned int nVals = 0;
515 void initialize(
const unsigned int n1,
const unsigned int n2);
521 void constructFromHDF5Dataset(H5::DataSet& dataset, std::vector<hsize_t> gridOffset, std::vector<hsize_t> tensorDims);
524 void constructFromHDF5Dataset(hid_t dset_id, hid_t plist_id, std::vector<hsize_t> gridOffset, std::vector<hsize_t> tensorDims);
527 Tensor2(
const unsigned int n1,
const unsigned int n2,
const T* inArray);
528 Tensor2(
const unsigned int n1,
const unsigned int n2,
const std::valarray<T>& inVec);
531 unsigned int flat(
const unsigned int i,
const unsigned int j)
const;
544 template <
typename T>
562 template <
typename T>
568 idx.
j = flat_idx - idx.
i*n2;
571 idx.
i = flat_idx - idx.
j*n1;
587 template <
typename T>
590 unsigned int flatIdx = this->flat(i,j);
591 return vals[flatIdx];
603 template <
typename T>
606 return vals[flatIdx];
617 template <
typename T>
620 unsigned int flatIdx = this->flat(i,j);
621 return vals[flatIdx];
624 template <
typename T>
627 return vals[flatIdx];
630 template <
typename T>
632 unsigned int flatIdx = this->flat(i,j);
639 template <
typename T>
644 for (
int i=0; i<n1; i++) {
645 for (
int j=0; j<n2; j++) {
652 template <
typename T>
654 unsigned int n1 = A.size();
655 unsigned int n2 = B.size();
657 for (
unsigned int i=0; i<n1; i++) {
658 for (
unsigned int j=0; j<n2; j++) {
665 template <
typename T>
670 for (
int i=0; i<n1; i++) {
671 for (
int j=0; j<n2; j++) {
683 for (
unsigned int i=0; i<n; i++) {
684 for (
unsigned int j=0; j<n; j++) {
695 throw std::runtime_error(
"Wrong dimensions.");
698 for (
unsigned int i=0; i<n; i++) {
707 for (
unsigned int i=0; i<A.
getNVals(); i++) {
717 unsigned int n = vals.size();
719 for (
unsigned int i=0; i<n; i++) {
728 unsigned int n = vals.size();
730 for (
unsigned int i=0; i<n; i++) {
738 if (A.
n1 != B.
n1)
return false;
739 if (A.
n2 != B.
n2)
return false;
741 for (
unsigned int i=0; i<A.
getNVals(); i++) {
760 template <
typename T>
762 return areEqual(A, B, (T)(10.0*std::numeric_limits<T>::epsilon()));
766 template <
typename T>
772 template <
typename T>
774 return (A.
n1 == B.
n1 && A.
n2 == B.
n2);
777 template <
typename T>
780 throw TensorError(std::string(
"Dimension mismatch."));
793 template <
typename T>
801 template <
typename T>
806 template <
typename T>
813 template <
typename T>
818 template <
typename T>
823 template <
typename T>
826 MPI_Allreduce(&(local.
vals[0]), &(global.vals[0]), local.
getNVals(), MPIType<T>(), MPI_SUM, comm);
831 template <
typename T>
845 template <
typename T>
850 template <
typename T>
857 template <
typename T>
862 template <
typename T>
870 template <
typename T>
877 template <
typename T>
882 template <
typename T>
892 template <
typename T>
899 template <
typename T>
904 template <
typename T>
907 throw TensorError(
"Shapes are incompatible for multiplication.");
916 unsigned int m = A.
n1;
917 unsigned int n = A.
n2;
918 unsigned int p = B.
n2;
920 for (
unsigned int i=0; i<m; i++) {
921 for (
unsigned int j=0; j<p; j++) {
922 for (
unsigned int k=0; k<n; k++) {
931 template <
typename T>
936 unsigned int m = A.
n1;
938 for (
unsigned int i=0; i<m; i++) {
939 for (
unsigned int j=0; j<m; j++) {
940 for (
unsigned int k=0; k<m; k++) {
954 for (
unsigned int i=0; i<A.
getNVals(); i++) {
961 template <
typename T>
962 std::ostream& operator<<(std::ostream& out, const Tensor2<T>& A)
964 A.printToStream(out);
980 template <
typename T>
984 template<
typename U,
unsigned int M,
unsigned int N,
unsigned int P,
unsigned int Q>
friend class Tensor4CUDA;
991 Tensor4(
unsigned int n1,
unsigned int n2,
unsigned int n3,
unsigned int n4);
1007 T& operator()(
unsigned int i,
unsigned int j,
unsigned int k,
unsigned int l);
1008 T& operator()(
unsigned int flatIdx);
1011 T getVal(
unsigned int i,
unsigned int j,
unsigned int k,
unsigned int l)
const;
1012 T getValFlat(
unsigned int flatIdx)
const;
1015 T frobeniusNorm()
const;
1022 void printToStream(std::ostream& out);
1033 template <
typename U>
1035 template <
typename U>
1037 template <
typename U>
1039 template <
typename U>
1043 template <
typename U>
1045 template <
typename U>
1047 template <
typename U>
1049 template <
typename U>
1051 template <
typename U>
1053 template <
typename U>
1057 template <
typename U>
1059 template <
typename U>
1063 template <
typename U>
1065 template <
typename U>
1067 template <
typename U>
1069 template <
typename U>
1071 template <
typename U>
1075 template <
typename U>
1077 template <
typename U>
1079 template <
typename U>
1081 template <
typename U>
1083 template <
typename U>
1085 template <
typename U>
1089 template <
typename U>
1091 template <
typename U>
1093 template <
typename U>
1097 template <
typename U>
1099 template <
typename U>
1103 unsigned int n1 = 0;
1104 unsigned int n2 = 0;
1105 unsigned int n3 = 0;
1106 unsigned int n4 = 0;
1107 unsigned int nVals = 0;
1115 void initialize(
unsigned int n1,
unsigned int n2,
unsigned int n3,
unsigned int n4);
1118 unsigned int flat(
unsigned int i,
unsigned int j,
unsigned int k,
unsigned int l)
const;
1136 template <
typename T>
1137 inline unsigned int Tensor4<T>::flat(
unsigned int i,
unsigned int j,
unsigned int k,
unsigned int l)
const 1139 return i*n2*n3*n4 + j*n3*n4 + k*n4 + l;
1148 template <
typename T>
1152 idx.
i = flat_idx/(n2*n3*n4);
1153 idx.
j = (flat_idx - idx.
i*n2*n3*n4)/(n3*n4);
1154 idx.
k = (flat_idx - idx.
i*n2*n3*n4 - idx.
j*n3*n4)/(n4);
1155 idx.
l = (flat_idx - idx.
i*n2*n3*n4 - idx.
j*n3*n4 - idx.
k*n4);
1160 template <
typename T>
1163 unsigned int flatIdx = this->flat(i,j,k,l);
1164 return vals[flatIdx];
1168 template <
typename T>
1171 return vals[flatIdx];
1174 template <
typename T>
1177 unsigned int flatIdx = this->flat(i,j,k,l);
1178 return vals[flatIdx];
1181 template <
typename T>
1184 return vals[flatIdx];
1190 template <
typename T>
1191 std::ostream& operator<<(std::ostream& out, Tensor4<T>& A)
1193 A.printToStream(out);
1198 template<
typename T>
1202 for (
unsigned int i=0; i<n; i++) {
1203 for (
unsigned int j=0; j<n; j++) {
1204 for (
unsigned int k=0; k<n; k++) {
1205 for (
unsigned int l=0; l<n; l++) {
1206 A(i,j,k,l) = (i==k)*(j==l);
1214 template<
typename T>
1218 throw std::runtime_error(
"Wrong dimensions.");
1220 for (
unsigned int i=0; i<n; i++) {
1221 for (
unsigned int j=0; j<n; j++) {
1222 for (
unsigned int k=0; k<n; k++) {
1223 for (
unsigned int l=0; l<n; l++) {
1224 A(i,j,k,l) = (i==k)*(j==l);
1232 template <
typename T>
1237 template <
typename T>
1240 throw TensorError(std::string(
"Dimension mismatch."));
1253 template <
typename T>
1255 if (A.
n1 != B.
n1)
return false;
1256 if (A.
n2 != B.
n2)
return false;
1257 if (A.
n3 != B.
n3)
return false;
1258 if (A.
n4 != B.
n4)
return false;
1260 for (
unsigned int i=0; i<A.
getNVals(); i++) {
1262 if (
std::abs(diff) > 10.0*std::numeric_limits<T>::epsilon()) {
1271 template <
typename T>
1283 template <
typename T>
1291 template <
typename T>
1296 template <
typename T>
1303 template <
typename T>
1308 template <
typename T>
1314 template <
typename T>
1322 template <
typename T>
1336 template <
typename T>
1341 template <
typename T>
1348 template <
typename T>
1353 template <
typename T>
1361 template <
typename T>
1368 template <
typename T>
1373 template <
typename T>
1383 template <
typename T>
1390 template <
typename T>
1398 template<
typename T>
1401 unsigned int m = A.
n1;
1402 unsigned int n = A.
n2;
1403 unsigned int p = B.
n1;
1404 unsigned int q = B.
n2;
1406 for (
unsigned int i=0; i<m; i++) {
1407 for (
unsigned int j=0; j<n; j++) {
1408 for (
unsigned int k=0; k<p; k++) {
1409 for (
unsigned int l=0; l<q; l++) {
1418 template <
typename T>
1421 throw TensorError(
"Shapes are incompatible for contraction.");
1425 template<
typename T>
1428 unsigned int m = A.
n1;
1429 unsigned int n = A.
n2;
1430 unsigned int p = B.
n1;
1431 unsigned int q = B.
n2;
1433 for (
unsigned int i=0; i<m; i++) {
1434 for (
unsigned int j=0; j<n; j++) {
1435 for (
unsigned int k=0; k<p; k++) {
1436 for (
unsigned int l=0; l<q; l++) {
1445 template <
typename T>
1447 if (A.
n3 != B.
n1 || A.
n4 != B.
n2) {
1448 throw TensorError(
"Shapes are incompatible for contraction.");
1452 template <
typename T>
1455 throw TensorError(
"Shapes are incompatible for contraction.");
1460 template <
typename T>
1464 unsigned int m = A.
n1;
1465 unsigned int n = A.
n2;
1466 unsigned int p = A.
n3;
1467 unsigned int q = A.
n4;
1469 for (
unsigned int i=0; i<m; i++) {
1470 for (
unsigned int j=0; j<n; j++) {
1471 for (
unsigned int k=0; k<p; k++) {
1472 for (
unsigned int l=0; l<q; l++) {
1481 template <
typename T>
1485 unsigned int m = A.
n1;
1486 unsigned int n = A.
n2;
1487 unsigned int p = A.
n3;
1488 unsigned int q = A.
n4;
1490 for (
unsigned int i=0; i<m; i++) {
1491 for (
unsigned int j=0; j<n; j++) {
1492 for (
unsigned int k=0; k<p; k++) {
1493 for (
unsigned int l=0; l<q; l++) {
1501 template <
typename U>
1503 if (A.
n3 != B.
n1 || A.
n4 != B.
n2) {
1504 throw TensorError(
"Shapes are incompatible for contraction.");
1508 template <
typename U>
1511 unsigned int m = A.
n1;
1512 unsigned int n = A.
n2;
1513 unsigned int p = A.
n3;
1514 unsigned int q = A.
n4;
1515 unsigned int r = B.
n3;
1516 unsigned int s = B.
n4;
1518 for (
unsigned int im=0; im<m; im++) {
1519 for (
unsigned int in=0; in<n; in++) {
1520 for (
unsigned int ir=0; ir<r; ir++) {
1521 for (
unsigned int is=0; is<s; is++) {
1522 C(im,in,ir,is) = 0.0;
1523 for (
unsigned int ip=0; ip<p; ip++) {
1524 for (
unsigned int iq=0; iq<q; iq++) {
1525 C(im,in,ir,is) += A.
getVal(im,in,ip,iq)*B.
getVal(ip,iq,ir,is);
1536 template <
typename T>
1539 unsigned int m = A.
getn1();
1540 unsigned int n = A.
getn2();
1541 if (n != x.size()) {
1542 throw hpp::TensorError(
"Incompatible tensor vector multiplication sizes.");
1544 std::vector<T> b(m);
1545 for (
unsigned int i=0; i<m; i++) {
1546 for (
unsigned int j=0; j<n; j++) {
1547 b[i] += A.
getVal(i,j)*x[j];
1554 template <
typename T>
1557 unsigned int m = A.
getn1();
1558 unsigned int n = A.
getn2();
1559 if (n != x.size()) {
1560 throw hpp::TensorError(
"Incompatible tensor vector multiplication sizes.");
1562 std::valarray<T> b(m);
1563 for (
unsigned int i=0; i<m; i++) {
1564 for (
unsigned int j=0; j<n; j++) {
1565 b[i] += A.
getVal(i,j)*x[j];
1578 template <
typename T>
1581 unsigned int m = A.
getn1();
1582 unsigned int n = A.
getn2();
1583 if (n != x.size()) {
1584 throw hpp::TensorError(
"Incompatible vector tensor multiplication sizes.");
1587 for (
unsigned int i=0; i<m; i++) {
1588 for (
unsigned int j=0; j<n; j++) {
1601 template <
typename T>
1603 return Q.
trans()*A*Q;
1612 template <
typename T>
1614 return Q*A_star*Q.
trans();
1624 template <
typename T>
1627 for (
int m=0; m<3; m++) {
1628 for (
int n=0; n<3; n++) {
1629 for (
int p=0; p<3; p++) {
1630 for (
int q=0; q<3; q++) {
1632 for (
int i=0; i<3; i++) {
1633 for (
int j=0; j<3; j++) {
1634 for (
int k=0; k<3; k++) {
1635 for (
int l=0; l<3; l++) {
unsigned int getNVals() const
Definition: tensor.h:341
Tensor2< T > transformOutOfFrame(const Tensor2< T > &A_star, const Tensor2< T > &Q)
Transform tensor out of the frame given by the columns of .
Definition: tensor.h:1613
void operator+=(GSHCoeffs< T > &A, const GSHCoeffs< T > &B)
Definition: gsh.h:231
Tensor2< T > diag2(const std::vector< T > &vals)
Definition: tensor.h:715
void ABPlusBTransposeAInPlace(const hpp::Tensor2< T > &A, const hpp::Tensor2< T > &B, hpp::Tensor2< T > &C)
Definition: tensor.h:932
Tensor2< T > outer(const std::vector< T > &A, const std::vector< T > &B)
Definition: tensor.h:640
unsigned int j
Definition: tensor.h:214
Tensor2< T > transformIntoFrame(const Tensor2< T > &A, const Tensor2< T > &Q)
Transform tensor into the frame given by the columns of .
Definition: tensor.h:1602
Definition: tensorCUDA.h:28
unsigned int getn2() const
Definition: tensor.h:1026
Tensor2< T > ones2(unsigned int n)
Definition: tensor.h:704
unsigned int flat(unsigned int i, unsigned int j, unsigned int k, unsigned int l) const
Flatten the four indices of the tensor.
Definition: tensor.h:1137
void operator/=(GSHCoeffs< T > &A, const T B)
Definition: gsh.h:257
Definition: casesUtils.cpp:4
void operator-=(Tensor2< T > &A, const Tensor2< T > &B)
Definition: tensor.h:846
void assertSameShape(const Tensor2< T > &A, const Tensor2< T > &B)
Definition: tensor.h:778
Header file for helper functions with HDF, C++ API.
std::vector< T > operator*(const std::vector< T > &vec, const T scalar)
Definition: tensor.h:72
unsigned int j
Definition: tensor.h:182
Tensor2< T > R
Definition: tensor.h:310
unsigned int getn1() const
Definition: tensor.h:1025
unsigned int flat(const unsigned int i, const unsigned int j) const
Flatten the two indices of the tensor.
Definition: tensor.h:545
T MPISum(const T &localVal, MPI_Comm comm)
Definition: mpiUtils.h:66
unsigned int getn3() const
Definition: tensor.h:1027
Tensor2< T > U
Definition: tensor.h:311
Tensor2< T > identityTensor2(unsigned int n)
Definition: tensor.h:680
A 2D index.
Definition: tensor.h:180
T getValFlat(unsigned int flatIdx) const
Definition: tensor.h:1169
std::vector< T > ones(unsigned int n)
Definition: tensor.h:293
GSHCoeffs< T > operator/(const GSHCoeffs< T > &coeffs, const T val)
Definition: gsh.h:236
void operator*=(std::vector< T > &vec, const T scalar)
Definition: tensor.h:58
unsigned int getn4() const
Definition: tensor.h:1028
T getVal(const unsigned int i, const unsigned int j) const
Get the value of .
Definition: tensor.h:588
void assertCompatibleForContraction(const Tensor4< T > &A, const Tensor2< T > &B)
Definition: tensor.h:1446
std::vector< T > unflatC(T flatIdx, std::vector< U > dims)
Definition: tensor.h:241
Header file for helper functions with HDF.
idx4d unflat(unsigned int idx)
Unflatten the four indices of the tensor.
Definition: tensor.h:1149
bool operator==(const SpectralDatasetID &l, const SpectralDatasetID &r)
Definition: spectralUtils.cpp:132
A 4D index.
Definition: tensor.h:212
unsigned int i
Definition: tensor.h:213
#define DEBUG_ONLY(x)
Definition: config.h:34
void assertCompatibleForOuterProduct(const Tensor2< T > &A, const Tensor2< T > &B, const Tensor4< T > &C)
Definition: tensor.h:1419
A class for second order tensors.
Definition: tensor.h:303
unsigned int getNVals() const
Definition: tensor.h:1004
unsigned int l
Definition: tensor.h:216
unsigned int n2
Definition: tensor.h:1104
void assertSquare() const
Definition: tensor.cpp:334
void identityTensor2InPlace(unsigned int n, Tensor2< T > &A)
Definition: tensor.h:692
bool areEqual(const Tensor2< T > &A, const Tensor2< T > &B, T tol)
Definition: tensor.h:737
unsigned int n3
Definition: tensor.h:1105
unsigned int n1
Definition: tensor.h:1103
std::vector< T > abs(const std::vector< T > &vec)
Definition: tensor.h:89
idx2d unflat(unsigned int flatIdx, unsigned int n1, unsigned int n2)
Definition: tensor.h:185
std::vector< T > operator-(const std::vector< T > &vec1, const std::vector< T > &vec2)
Definition: tensor.h:110
void outerInPlace(const std::vector< T > &A, const std::vector< T > &B, Tensor2< T > &C)
Definition: tensor.h:653
T contract(const Tensor2< T > &A, const Tensor2< T > &B)
Definition: tensor.h:950
bool operator!=(const EulerAngles< T > &l, const EulerAngles< T > &r)
Definition: rotation.h:113
Tensor2< T > trans() const
The transpose of the tensor.
Definition: tensor.cpp:536
#define HPP_ARRAY_LAYOUT
Definition: config.h:25
std::valarray< T > vals
Definition: tensor.h:1110
T & operator()(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
Definition: tensor.h:1175
T & operator()(const unsigned int i, const unsigned int j)
Get the a reference to the value of .
Definition: tensor.h:618
unsigned int n1
the first dimension of the tensor
Definition: tensor.h:504
T getValFlat(const unsigned int flatIdx) const
Get the value of .
Definition: tensor.h:604
void assertCompatibleForMultiplication(const Tensor2< T > &A, const Tensor2< T > &B)
Definition: tensor.h:905
T flatC(std::vector< T > idx, std::vector< U > dims)
Definition: tensor.h:279
T min(const std::vector< T > &vec)
Definition: tensor.h:98
T max(const std::vector< T > &vec)
Definition: tensor.h:104
unsigned int k
Definition: tensor.h:215
unsigned int i
Definition: tensor.h:181
Tensor4< T > identityTensor4(unsigned int n)
Definition: tensor.h:1199
GSHCoeffs< T > operator+(const GSHCoeffs< T > &coeffs1, const GSHCoeffs< T > &coeffs2)
Definition: gsh.h:210
void identityTensor4InPlace(unsigned int n, Tensor4< T > &A)
Definition: tensor.h:1215
unsigned int n4
Definition: tensor.h:1106
void setVal(const unsigned int i, const unsigned int j, T val)
Definition: tensor.h:631
unsigned int getn1() const
Definition: tensor.h:339
void contractInPlace(const Tensor4< T > &A, const Tensor2< T > &B, Tensor2< T > &C)
Definition: tensor.h:1482
T getVal(unsigned int i, unsigned int j, unsigned int k, unsigned int l) const
Definition: tensor.h:1161
T prod(const std::vector< T > &vec)
Product of all the entries of a vector.
Definition: tensor.h:128
std::valarray< T > vals
the underlying 1D array
Definition: tensor.h:511
idx2d unflat(const unsigned int idx) const
Unflatten the two indices of the tensor.
Definition: tensor.h:563
TensorError(const std::string &val)
Definition: tensor.h:169
unsigned int getn2() const
Definition: tensor.h:340
bool areSameShape(const Tensor2< T > &A, const Tensor2< T > &B)
Definition: tensor.h:773
unsigned int n2
the second dimension of the tensor
Definition: tensor.h:506
Definition: tensorCUDA.h:902