11#ifndef _AUROSTD_XTENSOR_CPP_
12#define _AUROSTD_XTENSOR_CPP_
32#define _DEBUG_XTENSOR_ false
60#define AST_TEMPLATE(utype) template _subtensor<utype>::_subtensor(const int&, utype*, const xtensor<utype>&);
65 const uint isize = ind.size();
68 for (
uint i = 0; i < isize; i++) {
73#define AST_TEMPLATE(utype) template _subtensor<utype>::_subtensor(const std::vector<int>&, utype*, const xtensor<utype>&);
80 for (
int i = 0, ixvec = ind.
lrows; ixvec <= ind.
urows; i++, ixvec++) {
81 shift += (ind[ixvec] - _tensor.lindex[i]) * _tensor.shifts[i];
85#define AST_TEMPLATE(utype) template _subtensor<utype>::_subtensor(const aurostd::xvector<int>&, utype*, const xtensor<utype>&);
91#define AST_TEMPLATE(utype) template _subtensor<utype>::~_subtensor();
98 std::stringstream message;
99 if (indexed_dim == _tensor.ndim) {
100 message <<
"Cannot subscribe tensor any further (tensor size: " << _tensor.ndim <<
").";
102 }
else if ((i < _tensor.lindex[indexed_dim]) || (i > _tensor.uindex[indexed_dim])) {
103 message <<
"Index " << i <<
" out of bounds for dimension " << (indexed_dim);
104 message <<
" (lindex = " << _tensor.lindex[indexed_dim] <<
", uindex = ";
105 message << _tensor.uindex[indexed_dim] <<
")";
109 shift += (i - _tensor.lindex[indexed_dim]) * _tensor.shifts[indexed_dim];
113#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator[](const int&);
120 std::stringstream message;
121 if (indexed_dim + isize > _tensor.ndim) {
122 message <<
"Too many indices for tensor with " << _tensor.ndim <<
" dimensions";
123 message <<
" (" << (indexed_dim + isize) <<
" provided).";
127 for (
uint i = 0; i < isize; i++) {
129 if ((ind[i] < _tensor.lindex[i + indexed_dim]) || (ind[i] > _tensor.uindex[i + indexed_dim])) {
130 message <<
"Index " << ind[i] <<
" out of bounds for dimension " << (i + indexed_dim);
131 message <<
" (lindex = " << _tensor.lindex[i + indexed_dim];
132 message <<
", uindex = " << _tensor.uindex[i + indexed_dim] <<
")";
136 shift += (ind[i] - _tensor.lindex[indexed_dim]) * _tensor.shifts[indexed_dim];
141#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator()(const std::vector<int>&);
147 std::stringstream message;
149 message <<
"Too many indices for tensor with " <<
_tensor.ndim <<
" dimensions";
154 for (
int i = ind.
lrows; i <= ind.
urows; i++) {
157 message <<
"Index " << ind[i] <<
" out of bounds for dimension " <<
indexed_dim;
168#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator()(const aurostd::xvector<int>&);
174 for (
int s = 0; s < n; s++) {
178#define AST_TEMPLATE(utype) template void _subtensor<utype>::set(const utype&);
185#define AST_TEMPLATE(utype) template void _subtensor<utype>::set(const utype&, const int&);
192#define AST_TEMPLATE(utype) template utype _subtensor<utype>::get(const int&) const;
204 for (
int s = 0; s < n; s++) {
210#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator+=(utype);
219 for (
int s = 0; s < n; s++) {
225#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator-=(utype);
234 for (
int s = 0; s < n; s++) {
240#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator*=(utype);
249 for (
int s = 0; s < n; s++) {
255#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator/=(utype);
269 for (
int s = 0; s < n; s++) {
274 const std::string message =
"Subtensors have different shapes.";
279#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator+=(const _subtensor<utype>&);
289 for (
int s = 0; s < n; s++) {
294 const std::string message =
"Subtensors have different shapes.";
299#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator-=(const _subtensor<utype>&);
308 for (
int i = 0; i < tensor.
nelements; i++) {
313 const std::string message =
"Subtensor and tensor have different shapes.";
318#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator+=(const xtensor<utype>&);
327 for (
int i = 0; i < tensor.
nelements; i++) {
332 const std::string message =
"Subtensor and tensor have different shapes.";
337#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator-=(const xtensor<utype>&);
348#define AST_TEMPLATE(utype) template xtensor<utype> operator+(const _subtensor<utype>&);
356#define AST_TEMPLATE(utype) template xtensor<utype> operator-(const _subtensor<utype>&);
369#define AST_TEMPLATE(utype) template _subtensor<utype>::operator utype() const;
379 std::stringstream message;
380 message <<
"Cannot assign single value to tensor of size " << (
_tensor.ndim -
indexed_dim) <<
".";
385#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator=(const utype&);
393 for (
int i =
shift, ist = st.
shift; i < end; i++, ist++) {
397 const std::string message =
"Subtensors have different shapes.";
402#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator=(const _subtensor<utype>&);
413 const std::string message =
"Subtensor and tensor have different shapes.";
418#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator=(const xtensor<utype>&);
424 bool throw_exception =
false;
425 std::stringstream message;
429 const int vsize = (int) vec.size();
431 for (
int i = 0, ist =
shift; i < vsize; i++, ist++) {
436 throw_exception =
true;
437 message <<
"Tensor slice and vector have different sizes. ";
439 message <<
"size of vector: " << vec.size() <<
".";
442 throw_exception =
true;
443 message <<
"Tensor slice must be 1D to assign vector (is " << (
_tensor.ndim -
indexed_dim) <<
"D).";
445 if (throw_exception) {
450#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator=(const std::vector<utype>&);
456 bool throw_exception =
false;
457 std::stringstream message;
467 throw_exception =
true;
468 message <<
"Tensor slice and xvector have different sizes. ";
470 message <<
"size of xvector: " << xvec.
rows <<
".";
473 throw_exception =
true;
474 message <<
"Tensor slice must be 1D to assign xvector (is " << (
_tensor.ndim -
indexed_dim) <<
"D).";
476 if (throw_exception) {
481#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator=(const aurostd::xvector<utype>&);
487 bool throw_exception =
false;
488 std::stringstream message;
493 for (
int i = xmat.
lrows; i <= xmat.
urows; i++) {
494 for (
int j = xmat.
lcols; j <= xmat.
ucols; j++) {
500 throw_exception =
true;
501 message <<
"Tensor slice and xmatrix have different shapes. ";
503 message <<
"shape of xmatrix: (" << xmat.
rows <<
", " << xmat.
cols <<
").";
506 throw_exception =
true;
507 message <<
"Tensor slice must be 2D to assign xmatrix (is " << (
_tensor.ndim -
indexed_dim) <<
"D).";
509 if (throw_exception) {
514#define AST_TEMPLATE(utype) template _subtensor<utype>& _subtensor<utype>::operator=(const aurostd::xmatrix<utype>&);
528#define AST_TEMPLATE(utype) template int _subtensor<utype>::getNumElements() const;
536 if (size1 != size2) {
539 const int diff = (int) (size2 - size1);
548#define AST_TEMPLATE(utype) template bool _subtensor<utype>::sameShape(const _subtensor<utype>&);
554 if (size != tensor.
ndim) {
557 for (
uint i = 0; i < size; i++) {
565#define AST_TEMPLATE(utype) template bool _subtensor<utype>::sameShape(const xtensor<utype>&);
585 const std::vector<int> uind(3, 3);
586 const std::vector<int> lind(3, 1);
589#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor();
594 const std::vector<int> lind(uind.size(), 1);
597#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor(const std::vector<int>&);
604#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor(const std::vector<int>&, const std::vector<int>&);
610 const std::vector<int> lind(uind.size(), 1);
613#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor(const aurostd::xvector<int>&);
622#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor(const aurostd::xvector<int>&, const aurostd::xvector<int>&);
629 const int n = ui - li + 1;
630 const std::vector<int> uind(n, n);
631 const std::vector<int> lind(n, li);
634#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor(const int&, const int&);
639 std::vector<int> uind;
640 std::vector<int> lind;
648 for (
int i = 0; i <
size; i++) {
655 for (
int i = 0, ist = st.
shift; ist < end; i++, ist++) {
659#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor(const _subtensor<utype>&);
683 std::cerr <<
" " <<
shape[i];
685 std::cerr << std::endl;
688 for (
uint s = 0; s <
ndim - 1; s++) {
689 for (
uint i = s + 1; i <
ndim; i++) {
695 if ((uind.size() == 1) && ((
uindex[0] -
lindex[0]) == 0)) {
716 size = (char) (
sizeof(utype));
725 std::cerr <<
"is_cubic = " << ((
is_cubic) ?
"true" :
"false");
726 std::cerr <<
", sizeof = " <<
size <<
", tsize = " <<
tsize << std::endl;
729 const std::string message =
"Allocation failure in xtensor constructor.";
735 std::stringstream message;
737 if (uind.size() != lind.size()) {
738 message <<
"uindex and lindex are of different size.";
741 if (uind.empty() || lind.empty()) {
742 message <<
"Cannot initialize tensor with empty vector.";
744 message <<
"Vector describing tensor indices contains illegal values (uindex < lindex).";
751#define AST_TEMPLATE(utype) template void xtensor<utype>::buildTensor(const std::vector<int>&, const std::vector<int>&);
778#define AST_TEMPLATE(utype) template xtensor<utype>::xtensor(const xtensor<utype>&);
813#define AST_TEMPLATE(utype) template xtensor<utype> xtensor<utype>::operator=(const xtensor<utype>&);
822#define AST_TEMPLATE(utype) template xtensor<utype> xtensor<utype>::operator=(const _subtensor<utype>&);
836#define AST_TEMPLATE(utype) template xtensor<utype>::~xtensor();
845 if (uind.size() != lind.size()) {
848 if (uind.empty() || lind.empty()) {
851 for (
size_t i = 0; i < uind.size(); i++) {
852 if (uind[i] < lind[i]) {
858#define AST_TEMPLATE(utype) template bool xtensor<utype>::checkInit(const std::vector<int>&, const std::vector<int>&);
873#define AST_TEMPLATE(utype) template bool xtensor<utype>::sameShape(const xtensor<utype>&) const;
890#define AST_TEMPLATE(utype) template bool xtensor<utype>::sameShape(const _subtensor<utype>&) const;
899 std::stringstream message;
900 uint isize = indices.size();
902 message <<
"Too many indices for tensor with " <<
ndim <<
" dimensions (" << isize <<
" provided).";
905 for (
uint i = 0; i < isize; i++) {
906 if ((indices[i] <
lindex[i]) || indices[i] >
uindex[i]) {
907 message <<
"Index " << indices[i] <<
" out of bounds for dimension " << i;
908 message <<
" (lindex = " <<
lindex[i] <<
", uindex = " <<
uindex[i] <<
").";
916#define AST_TEMPLATE(utype) template _subtensor<utype> xtensor<utype>::operator()(std::vector<int>) const;
922 std::stringstream message;
924 message <<
"Too many indices for tensor with " <<
ndim <<
" dimensions (" << indices.
rows <<
" provided).";
927 for (
int i = 0, ixvec = indices.
lrows; ixvec <= indices.
urows; i++, ixvec++) {
928 if (indices[ixvec] <
lindex[i] || indices[ixvec] >
uindex[i]) {
929 message <<
"Index " << indices[i] <<
" out of bounds for dimension " << i;
930 message <<
" (lindex = " <<
lindex[i] <<
", uindex = " <<
uindex[i] <<
").";
938#define AST_TEMPLATE(utype) template _subtensor<utype> xtensor<utype>::operator()(aurostd::xvector<int>) const;
945 std::stringstream message;
946 message <<
"Index " << i <<
" out of bounds for dimension 0";
947 message <<
" (lindex = " <<
lindex[0] <<
", uindex = " <<
uindex[0] <<
").";
953#define AST_TEMPLATE(utype) template _subtensor<utype> xtensor<utype>::operator[](int) const;
966#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator+=(utype);
976#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator-=(utype);
986#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator*=(utype);
996#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator/=(utype);
1007 std::cerr <<
" " <<
shape[i];
1009 std::cerr <<
", dimensions tensor 2:";
1010 for (
uint i = 0; i < tensor.
ndim; i++) {
1011 std::cerr <<
" " << tensor.
shape[i];
1013 std::cerr << std::endl;
1022 const std::string message =
"Tensors are of different size.";
1026#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator+=(const xtensor<utype>&);
1035 std::cerr <<
" " <<
shape[i];
1037 std::cerr <<
", dimensions tensor 2:";
1038 for (
uint i = 0; i < tensor.
ndim; i++) {
1039 std::cerr <<
" " << tensor.
shape[i];
1041 std::cerr << std::endl;
1050 const std::string message =
"Tensors are of different size.";
1054#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator-=(const xtensor<utype>&);
1061#define AST_TEMPLATE(utype) template xtensor<utype> operator+(const xtensor<utype>&);
1069#define AST_TEMPLATE(utype) template xtensor<utype> operator-(const xtensor<utype>);
1080 std::cerr <<
" " <<
shape[i];
1082 std::cerr <<
", dimensions subtensor:";
1084 std::cerr <<
" 1" << std::endl;
1087 std::cerr <<
" " << st.
_tensor.shape[i];
1089 std::cerr << std::endl;
1097 for (
int i = 0, ist = st.
shift; i < n; i++, ist++) {
1103 const std::string message =
"Tensor and subtensor are of different size.";
1107#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator+=(const _subtensor<utype>&);
1116 std::cerr <<
" " <<
shape[i];
1118 std::cerr <<
", dimensions subtensor:";
1120 std::cerr <<
" 1" << std::endl;
1123 std::cerr <<
" " << st.
_tensor.shape[i];
1125 std::cerr << std::endl;
1133 for (
int i = 0, ist = st.
shift; i < n; i++, ist++) {
1139 const std::string message =
"Tensor and subtensor are of different size.";
1143#define AST_TEMPLATE(utype) template xtensor<utype>& xtensor<utype>::operator-=(const _subtensor<utype>&);
1155#define AST_TEMPLATE(utype) template xtensor<utype> operator*(xtensor<utype>, const utype&);
1160 return tensor * scalar;
1162#define AST_TEMPLATE(utype) template xtensor<utype> operator*(const utype&, const xtensor<utype>&);
1170#define AST_TEMPLATE(utype) template xtensor<utype> operator/(xtensor<utype>, const utype&);
1180 for (
uint i = 0; i < tensor1.
ndim; i++) {
1181 std::cerr <<
" " << tensor1.
shape[i];
1183 std::cerr <<
", dimensions tensor 2:";
1184 for (
uint i = 0; i < tensor2.
ndim; i++) {
1185 std::cerr <<
" " << tensor2.
shape[i];
1187 std::cerr << std::endl;
1194 const std::string message =
"Tensors are of different size.";
1198#define AST_TEMPLATE(utype) template xtensor<utype> operator+(xtensor<utype>, const xtensor<utype>&);
1206 for (
uint i = 0; i < tensor1.
ndim; i++) {
1207 std::cerr <<
" " << tensor1.
shape[i];
1209 std::cerr <<
", dimensions tensor 2:";
1210 for (
uint i = 0; i < tensor2.
ndim; i++) {
1211 std::cerr <<
" " << tensor2.
shape[i];
1213 std::cerr << std::endl;
1220 const std::string message =
"Tensors are of different size.";
1224#define AST_TEMPLATE(utype) template xtensor<utype> operator-(xtensor<utype>, const xtensor<utype>&);
1232 return tensor + tensor_from_st;
1234#define AST_TEMPLATE(utype) template xtensor<utype> operator+(const xtensor<utype>&, const _subtensor<utype>&);
1241#define AST_TEMPLATE(utype) template xtensor<utype> operator+(const _subtensor<utype>&, const xtensor<utype>&);
1248 return tensor1 + tensor2;
1250#define AST_TEMPLATE(utype) template xtensor<utype> operator+(const _subtensor<utype>&, const _subtensor<utype>&);
1256 return tensor - tensor_from_st;
1258#define AST_TEMPLATE(utype) template xtensor<utype> operator-(const xtensor<utype>&, const _subtensor<utype>&);
1263 return -tensor + st;
1265#define AST_TEMPLATE(utype) template xtensor<utype> operator-(const _subtensor<utype>&, const xtensor<utype>&);
1272 return tensor1 - tensor2;
1274#define AST_TEMPLATE(utype) template xtensor<utype> operator-(const _subtensor<utype>&, const _subtensor<utype>&);
1286 corpus[i] = (utype) value;
1289#define AST_TEMPLATE(utype) template void xtensor<utype>::set(const utype&);
1296#define AST_TEMPLATE(utype) template void xtensor<utype>::set(const utype&, const int&);
1305#define AST_TEMPLATE(utype) template void xtensor<utype>::reset();
1312#define AST_TEMPLATE(utype) template void xtensor<utype>::clear();
1319#define AST_TEMPLATE(utype) template utype xtensor<utype>::get(const int&) const;
1333 if (tensor.
ndim > 1) {
1335 std::stringstream message;
1336 message <<
"Cannot convert xtensor with " << tensor.
ndim <<
" dimensions to vector.";
1339 const int rows = tensor.
shape[0];
1340 std::vector<utype> vec(rows);
1341 for (
int i = 0; i < rows; i++) {
1342 vec[i] = tensor[i + tensor.
lindex[0]];
1347#define AST_TEMPLATE(utype) template std::vector<utype> xtensor2vector(xtensor<utype>&);
1355#define AST_TEMPLATE(utype) template std::vector<utype> xtensor2vector(const _subtensor<utype>&);
1362 std::cerr <<
_XTENSOR_ERR_PREFIX_ <<
"xtensor2xvector - Number of tensor dimensions: " << tensor.
ndim << std::endl;
1364 if (tensor.
ndim > 1) {
1366 std::stringstream message;
1367 message <<
"Cannot convert xtensor with " << tensor.
ndim <<
" dimensions to xvector.";
1370 const int rows = tensor.
shape[0];
1372 for (
int i = 0; i < rows; i++) {
1373 xvec(i + xvec.
lrows) = tensor[i + tensor.
lindex[0]];
1378#define AST_TEMPLATE(utype) template xvector<utype> xtensor2xvector(xtensor<utype>&);
1386#define AST_TEMPLATE(utype) template xvector<utype> xtensor2xvector(const _subtensor<utype>&);
1393 std::cerr <<
_XTENSOR_ERR_PREFIX_ <<
"xtensor2xmatrix - Number of tensor dimensions: " << tensor.
ndim << std::endl;
1395 if (tensor.
ndim > 2) {
1397 std::stringstream message;
1398 message <<
"Cannot convert xtensor with " << tensor.
ndim <<
" dimensions to xmatrix.";
1403 rows = tensor.
shape[0];
1404 if (tensor.
ndim > 1) {
1405 cols = tensor.
shape[1];
1410 for (
int i = 0; i < rows; i++) {
1411 if (tensor.
ndim > 1) {
1412 for (
int j = 0; j < cols; j++) {
1413 mat(i + 1, j + 1) = tensor[i + tensor.
lindex[0]][j + tensor.
lindex[1]];
1416 mat(i, 1) = tensor[i + tensor.
lindex[0]];
1422#define AST_TEMPLATE(utype) template xmatrix<utype> xtensor2xmatrix(xtensor<utype>&);
1430#define AST_TEMPLATE(utype) template xmatrix<utype> xtensor2xmatrix(const _subtensor<utype>&);
1436 const std::vector<int> dim(1, vec.size());
1438 for (
size_t i = 0; i < vec.size(); i++) {
1439 tensor[i + 1] = vec[i];
1443#define AST_TEMPLATE(utype) template xtensor<utype> vector2xtensor(const std::vector<utype>&);
1448 const std::vector<int> dim(1, xvec.
rows);
1450 for (
int i = 0; i < xvec.
rows; i++) {
1451 tensor[i + 1] = xvec(xvec.
lrows + i);
1455#define AST_TEMPLATE(utype) template xtensor<utype> xvector2xtensor(const aurostd::xvector<utype>&);
1460 std::vector<int> dim(2);
1464 for (
int i = 0; i < xmat.
rows; i++) {
1465 for (
int j = 0; j < xmat.
cols; j++) {
1466 tensor[i + 1][j + 1] = xmat(xmat.
lrows + i, xmat.
lcols + j);
1471#define AST_TEMPLATE(utype) template xtensor<utype> xmatrix2xtensor(const aurostd::xmatrix<utype>&);
1482#define AST_TEMPLATE(utype) template xtensor<utype> abs(xtensor<utype>);
1491#define AST_TEMPLATE(utype) template void xtensor<utype>::abs();
1497 return abs(tensor_out);
1499#define AST_TEMPLATE(utype) template xtensor<utype> abs(const _subtensor<utype>&);
1507#define AST_TEMPLATE(utype) template xtensor<utype> ceil(xtensor<utype>);
1516#define AST_TEMPLATE(utype) template void xtensor<utype>::ceil();
1522 return ceil(tensor_out);
1524#define AST_TEMPLATE(utype) template xtensor<utype> ceil(const _subtensor<utype>&);
1532#define AST_TEMPLATE(utype) template xtensor<utype> floor(xtensor<utype>);
1541#define AST_TEMPLATE(utype) template void xtensor<utype>::floor();
1547 return floor(tensor_out);
1549#define AST_TEMPLATE(utype) template xtensor<utype> floor(const _subtensor<utype>&);
1557#define AST_TEMPLATE(utype) template xtensor<utype> nint(xtensor<utype>);
1566#define AST_TEMPLATE(utype) template void xtensor<utype>::nint();
1572 return nint(tensor_out);
1574#define AST_TEMPLATE(utype) template xtensor<utype> nint(const _subtensor<utype>&);
1582#define AST_TEMPLATE(utype) template xtensor<utype> round(xtensor<utype>, const utype&);
1591#define AST_TEMPLATE(utype) template void xtensor<utype>::round(const utype&);
1597 return round(tensor_out, tol);
1599#define AST_TEMPLATE(utype) template xtensor<utype> round(const _subtensor<utype>&, const utype&);
1607#define AST_TEMPLATE(utype) template xtensor<utype> sign(xtensor<utype>);
1616#define AST_TEMPLATE(utype) template void xtensor<utype>::sign();
1622 return sign(tensor_out);
1624#define AST_TEMPLATE(utype) template xtensor<utype> sign(const _subtensor<utype>&);
1628 template <
class utype>
1635 tensor.
set((utype) 0.0);
1636 std::vector<int> diag(n);
1637 for (
int i = 1; i <= n; i++) {
1638 for (
int j = 0; j < n; j++) {
1641 tensor(diag) = (utype) 1;
1645#define AST_TEMPLATE(utype) template xtensor<utype> identity_tensor(const utype&, int);
1652 return tensor.
max();
1654#define AST_TEMPLATE(utype) template utype max(xtensor<utype>);
1667#define AST_TEMPLATE(utype) template utype xtensor<utype>::max();
1673 return max(tensor_out);
1675#define AST_TEMPLATE(utype) template utype max(const _subtensor<utype>&);
1680 return tensor.
min();
1682#define AST_TEMPLATE(utype) template utype min(xtensor<utype>);
1695#define AST_TEMPLATE(utype) template utype xtensor<utype>::min();
1701 return min(tensor_out);
1703#define AST_TEMPLATE(utype) template utype min(const _subtensor<utype>&);
1708 return tensor.
sum();
1710#define AST_TEMPLATE(utype) template utype sum(xtensor<utype>);
1721#define AST_TEMPLATE(utype) template utype xtensor<utype>::sum();
1727 return sum(tensor_out);
1729#define AST_TEMPLATE(utype) template utype sum(const _subtensor<utype>&);
1737 for (
uint i = 0; i < tensor.
ndim; i++) {
1738 std::cerr <<
" " << tensor.
shape[i];
1740 std::cerr << std::endl;
1745 std::vector<int> diag(n);
1746 for (
uint i = 0; i < n; i++) {
1747 for (
uint j = 0; j < n; j++) {
1748 diag[j] = i + tensor.
lindex[j];
1750 trc += tensor(diag);
1754 const std::string message =
"Trace is only defined for cubic tensors.";
1758#define AST_TEMPLATE(utype) template utype trace(const xtensor<utype>&);
1764 return trace(tensor_out);
1766#define AST_TEMPLATE(utype) template utype trace(const _subtensor<utype>&);
1780 const int ii = (i - 1) % 3 + 1;
1781 const int jj = (j - 1) % 3 + 1;
1782 const int kk = (k - 1) % 3 + 1;
1783 if ((ii == 1) && (jj == 2) && (kk == 3)) {
1786 if ((ii == 2) && (jj == 3) && (kk == 1)) {
1789 if ((ii == 3) && (jj == 1) && (kk == 2)) {
1792 if ((ii == 1) && (jj == 3) && (kk == 2)) {
1795 if ((ii == 3) && (jj == 2) && (kk == 1)) {
1798 if ((ii == 2) && (jj == 1) && (kk == 3)) {
1805 return eijk(ijk[1], ijk[2], ijk[3]);
1809 const int ii = (i - 1) % 3 + 1;
1810 const int jj = (j - 1) % 3 + 1;
1811 const int kk = (k - 1) % 3 + 1;
1812 if ((ii == 1) && (jj == 2) && (kk == 3)) {
1815 if ((ii == 2) && (jj == 3) && (kk == 1)) {
1818 if ((ii == 3) && (jj == 1) && (kk == 2)) {
1825 return estarijk(ijk[1], ijk[2], ijk[3]);
This file contains the preprocessor macros to ensure a proper instantiation of all aurostd functions.
#define AST_GEN_1(type_selection)
autogenerate 1D code based on AST_TEMPLATE
static const std::string _XTENSOR_ERR_PREFIX_
static const std::string _SUBTENSOR_ERR_PREFIX_
_subtensor< utype > & operator[](const int &)
const xtensor< utype > & _tensor
_subtensor< utype > & operator*=(utype scalar)
_subtensor< utype > & operator()(const std::vector< int > &)
bool sameShape(const _subtensor< utype > &)
_subtensor(const int &, utype *, const xtensor< utype > &)
utype get(const int &) const
_subtensor< utype > & operator-=(utype scalar)
int getNumElements() const
_subtensor< utype > & operator+=(utype scalar)
_subtensor< utype > & operator=(const utype &)
_subtensor< utype > & operator/=(utype scalar)
_subtensor< utype > operator[](int) const
xtensor< utype > & operator-=(utype)
xtensor< utype > & operator+=(utype)
xtensor< utype > & operator/=(utype)
xtensor< utype > & operator*=(utype)
bool checkInit(const std::vector< int > &, const std::vector< int > &)
void buildTensor(const std::vector< int > &, const std::vector< int > &)
utype get(const int &) const
xtensor< utype > operator=(const xtensor< utype > &)
_subtensor< utype > operator()(std::vector< int >) const
void round(const utype &)
bool sameShape(const xtensor< utype > &) const
xmatrix< utype > xtensor2xmatrix(xtensor< utype > &tensor)
xvector< utype > xtensor2xvector(xtensor< utype > &tensor)
int estarijk(int i, int j, int k)
void set(xmatrix< utype > &a, const utype &s)
xmatrix< utype > sign(const xmatrix< utype > &a)
xtensor< utype > xmatrix2xtensor(const aurostd::xmatrix< utype > &xmat)
utype abs(const xcomplex< utype > &x)
xtensor< utype > identity_tensor(const utype &_type, int n)
vector< utype > reset(vector< utype > &v)
xcomplex< utype > operator+(const xcomplex< utype > &x, const xcomplex< utype > &y)
std::vector< utype > xtensor2vector(xtensor< utype > &tensor)
xmatrix< utype > ceil(const xmatrix< utype > &a)
xmatrix< utype > floor(const xmatrix< utype > &a)
utype max(const vector< utype > vec)
xcomplex< utype > operator*(const xcomplex< utype > &x, const xcomplex< utype > &y)
xtensor< utype > xvector2xtensor(const aurostd::xvector< utype > &xvec)
int eijk(int i, int j, int k)
utype trace(const xmatrix< utype > &a)
utype min(const vector< utype > vec)
utype sum(const vector< utype > vec)
xmatrix< utype > nint(const xmatrix< utype > &a)
vector< utype > xvector2vector(const xvector< utype > &xvec)
xmatrix< utype > roundoff(const xmatrix< utype > &a, utype _tol_)
xcomplex< utype > operator-(const xcomplex< utype > &x, const xcomplex< utype > &y)
xcomplex< utype > operator/(const xcomplex< utype > &x, const xcomplex< utype > &y)
xtensor< utype > vector2xtensor(const std::vector< utype > &vec)
xmatrix< utype > round(const xmatrix< utype > &a)