29#ifndef _TENSOR_IMPL_HPP_
30#define _TENSOR_IMPL_HPP_
70template <
typename MatrixType>
79template <
typename MatrixType>
88template <
typename MatrixType>
90 : Mat(comm), upper_rank(0), axes_map(){};
98template <
typename MatrixType>
110template <
typename MatrixType>
112 const size_t upper_rank)
118template <
typename MatrixType>
122 init(shape, upper_rank);
132template <
typename MatrixType>
134 const Tensor<lapack::Matrix<value_type>> &t)
136 init(t.internal_shape(), t.get_upper_rank());
137 const size_t n = Mat.local_size();
142 for (
size_t i = 0;
i <
n; ++
i) {
143 global_index_fast(
i,
g);
144 t.local_position(
g,
dummy, idx);
155template <
typename MatrixType>
159 const size_t n = Mat.local_size();
162 for (
size_t i = 0;
i <
n; ++
i) {
163 global_index_fast(
i, idx);
171template <
typename MatrixType>
177template <
typename MatrixType>
183template <
typename MatrixType>
192template <
typename MatrixType>
198template <
typename MatrixType>
204template <
typename MatrixType>
216template <
typename MatrixType>
222template <
typename MatrixType>
228template <
typename MatrixType>
234template <
typename MatrixType>
241template <
typename MatrixType>
247template <
typename MatrixType>
256template <
typename MatrixType>
265template <
typename MatrixType>
271template <
typename MatrixType>
277template <
typename MatrixType>
283template <
typename MatrixType>
285 const size_t rank = Dim.size();
286 const size_t rank0 = upper_rank;
288 const size_t l_row = Mat.local_row_size();
289 const size_t l_col = Mat.local_col_size();
301#pragma omp parallel default(shared)
314 for (
size_t k = 0;
k <
l_row; ++
k) {
315 map = &(l2g_map_row[
k *
rank0]);
317 for (
size_t i = 0;
i <
rank0; ++
i) {
326 for (
size_t k = 0;
k <
l_col; ++
k) {
327 map = &(l2g_map_col[
k *
rank1]);
329 for (
size_t i = 0;
i <
rank1; ++
i) {
348template <
typename MatrixType>
351 const size_t rank = Dim.size();
352 const size_t rank0 = upper_rank;
362 for (
size_t i = 0;
i <
rank0; ++
i) {
365 for (
size_t i = 0;
i <
rank1; ++
i) {
383template <
typename MatrixType>
386 const size_t rank = Dim.size();
387 const size_t rank0 = upper_rank;
397 for (
size_t i = 0;
i <
rank0; ++
i) {
401 for (
size_t i = 0;
i <
rank1; ++
i) {
408template <
typename MatrixType>
422template <
typename MatrixType>
424 init(shape,
urank, internal::identity_axes(shape.
size()));
433template <
typename MatrixType>
434void Tensor<MatrixType>::init(
const internal::UShape &shape,
size_t urank,
435 const internal::UAxes &map) {
438 const size_t rank = Dim.size();
444 for (
size_t i = 0;
i < upper_rank; ++
i) n_row *= shape[map[
i]];
445 for (
size_t i = upper_rank;
i < rank; ++
i) n_col *= shape[map[
i]];
446 Mat.init(n_row, n_col);
456template <
typename MatrixType>
458 const std::string &
tag)
const {
459 if (
tag.size() > 0) {
462 out <<
"Tensor: shape= " << Dim <<
" upper_rank= " << upper_rank
463 <<
" axes_map= " << axes_map <<
"\t";
474template <
typename MatrixType>
476 const std::string &
tag)
const {
477 const int mpisize = get_comm_size();
478 const int mpirank = get_comm_rank();
481 for (
int i = 0;
i < mpisize; ++
i) {
483 if (
tag.size() > 0) {
486 out <<
"mpirank: " << mpirank <<
"\t";
502template <
typename MatrixType>
504 const size_t rank =
gindex.size();
505 assert(rank == Dim.size());
509 for (
size_t i = 0;
i < upper_rank; ++
i) {
510 size_t j = axes_map[
i];
514 for (
size_t i = upper_rank;
i < rank; ++
i) {
515 size_t j = axes_map[
i];
527template <
typename MatrixType>
542template <
typename MatrixType>
544 const size_t rank = Dim.size();
548 for (
size_t i = 0;
i < upper_rank; ++
i) {
549 size_t j = axes_map[
i];
554 for (
size_t i = upper_rank;
i < rank; ++
i) {
555 size_t j = axes_map[
i];
569template <
typename MatrixType>
587template <
typename MatrixType>
601template <
typename MatrixType>
604 const size_t rank = Dim.size();
607 for (
size_t i = 0;
i < upper_rank; ++
i) {
608 size_t j = axes_map[
i];
612 for (
size_t i = upper_rank;
i < rank; ++
i) {
613 size_t j = axes_map[
i];
628template <
typename MatrixType>
635 const size_t rank = this->rank();
640 for (
size_t i = 0;
i < rank; ++
i) {
645 transpose_internal(
axes);
648 const size_t local_size =
T_old.local_size();
650 std::vector<size_t> local_position(local_size);
652 T_old.prep_local_to_global();
653 this->prep_global_to_local();
655#pragma omp parallel default(shared)
657 internal::UIndex index;
661 for (
size_t i = 0;
i < local_size; ++
i) {
662 T_old.global_index_fast(
i, index);
666 this->local_position(index,
dest,
pos);
668 local_position[
i] =
pos;
684template <
typename MatrixType>
690template <
typename MatrixType>
693 const size_t rank = Dim.size();
694 assert(debug::check_transpose_axes(
axes, rank));
700 for (
size_t i = 0;
i < rank; ++
i) {
703 for (
size_t i = 0;
i < rank; ++
i) {
722template <
typename MatrixType>
728 const size_t local_size = this->local_size();
729 prep_local_to_global();
730#pragma omp parallel default(shared)
735 for (
size_t i = 0;
i < local_size; ++
i) {
736 global_index_fast(
i, idx);
756template <
typename MatrixType>
757template <
typename D0,
typename D1>
759 const std::vector<D0> &
vec0, std::ptrdiff_t
n_axes0,
const std::vector<D1> &
vec1,
765 const size_t local_size = this->local_size();
766 prep_local_to_global();
767#pragma omp parallel default(shared)
772 for (
size_t i = 0;
i < local_size; ++
i) {
773 global_index_fast(
i, idx);
795template <
typename MatrixType>
796template <
typename D0,
typename D1,
typename D2>
798 const std::vector<D0> &
vec0, std::ptrdiff_t
n_axes0,
const std::vector<D1> &
vec1,
806 const size_t local_size = this->local_size();
807 prep_local_to_global();
808#pragma omp parallel default(shared)
813 for (
size_t i = 0;
i < local_size; ++
i) {
814 global_index_fast(
i, idx);
838template <
typename MatrixType>
839template <
typename D0,
typename D1,
typename D2,
typename D3>
841 const std::vector<D0> &
vec0, std::ptrdiff_t
n_axes0,
const std::vector<D1> &
vec1,
843 const std::vector<D3> &
vec3, std::ptrdiff_t
n_axes3) {
852 const size_t local_size = this->local_size();
853 prep_local_to_global();
854#pragma omp parallel default(shared)
859 for (
size_t i = 0;
i < local_size; ++
i) {
860 global_index_fast(
i, idx);
879template <
typename MatrixType>
881 const std::ptrdiff_t
n_axes,
883 const std::ptrdiff_t
i_end) {
885 const std::pair<size_t, size_t>
be =
894 std::vector<size_t> local_position(local_size);
897 prep_global_to_local();
899#pragma omp parallel default(shared)
904 for (
size_t i = 0;
i < local_size; ++
i) {
910 this->local_position(index,
dest,
pos);
912 local_position[
i] =
pos;
935template <
typename MatrixType>
939 const size_t nr = rank();
943 for (
size_t r = 0;
r <
nr; ++
r) {
950 std::vector<size_t> local_position(local_size);
953 prep_global_to_local();
955#pragma omp parallel default(shared)
960 for (
size_t i = 0;
i < local_size; ++
i) {
962 for (
size_t r = 0;
r <
nr; ++
r) {
968 this->local_position(index,
dest,
pos);
970 local_position[
i] =
pos;
988template <
typename MatrixType>
990 const size_t n = rank();
991 if (!(axes_map == internal::identity_axes(
n))) {
992 change_configuration(
n / 2, internal::identity_axes(
n));
996 LocalTensor T(
typename LocalTensor::comm_type{}, get_matrix().flatten());
997 return internal::reshape_impl(
T, Dim);
1006template <
typename MatrixType>
1008 const size_t n = rank();
1009 if (!(axes_map == internal::identity_axes(
n))) {
1010 change_configuration(
n / 2, internal::identity_axes(
n));
1012 return get_matrix().flatten();
1016template <
typename MatrixType>
1019 change_configuration(
rhs.get_upper_rank(),
rhs.get_axes_map());
1020 Mat +=
rhs.get_matrix();
1025template <
typename MatrixType>
1028 change_configuration(
rhs.get_upper_rank(),
rhs.get_axes_map());
1029 Mat -=
rhs.get_matrix();
1034template <
typename MatrixType>
1041template <
typename MatrixType>
1048template <
typename MatrixType>
1051 for (
size_t i = 0;
i <
n; ++
i) Mat[
i] =
rhs;
1060template <
typename MatrixType>
1061template <
typename UnaryOperation>
1076template <
typename MatrixType>
1078 return T.transpose(
axes);
1091template <
typename MatrixType>
1109template <
typename MatrixType>
1115template <
typename MatrixType>
1118 const size_t rank =
T.rank();
1119 assert(debug::check_transpose_axes(
axes, rank));
1130 for (
size_t r = 0;
r < rank; ++
r) {
1138 const size_t local_size =
T.local_size();
1140 std::vector<size_t> local_position(local_size);
1143 T_new.prep_global_to_local();
1145#pragma omp parallel default(shared)
1148 std::vector<size_t>
d_offset(rank);
1159 UAxes axes_map =
T.get_axes_map();
1160 std::vector<size_t>
axes_inv(rank);
1162 for (
size_t r = 0;
r < rank; ++
r) {
1165 for (
size_t r = 0;
r < rank; ++
r) {
1172 for (
size_t i = 0;
i < local_size; ++
i) {
1190 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1191 T_new.get_matrix());
1196template <
typename MatrixType>
1200 const UShape &shape =
T.internal_shape();
1201 const size_t rank = shape.
size();
1209 const size_t local_size =
T.local_size();
1211 std::vector<size_t> local_position(local_size);
1213 T.prep_local_to_global();
1214 T_new.prep_global_to_local();
1216#pragma omp parallel default(shared)
1222 for (
size_t i = 0;
i < local_size; ++
i) {
1223 T.global_index_fast(
i, index);
1226 for (
size_t r = 0;
r < rank; ++
r) {
1240 local_position[
i] =
pos;
1246 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1247 T_new.get_matrix());
1264template <
typename MatrixType>
1267 const int mpisize =
T.get_comm_size();
1270 const std::pair<size_t, size_t>
be =
1272 const size_t begin =
be.first;
1273 const size_t end =
be.second;
1280 internal::normalized);
1283 const size_t local_size =
T.local_size();
1285 std::vector<size_t> local_position(local_size);
1287 T.prep_local_to_global();
1288 T_new.prep_global_to_local();
1290#pragma omp parallel default(shared)
1295 for (
size_t i = 0;
i < local_size; ++
i) {
1296 T.global_index_fast(
i, index);
1304 local_position[
i] =
pos;
1308 local_position[
i] = 0;
1315 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1316 T_new.get_matrix());
1335template <
typename MatrixType>
1338 const int mpisize =
T.get_comm_size();
1340 const size_t rank =
T.rank();
1350 internal::normalized);
1353 const size_t local_size =
T.local_size();
1355 std::vector<size_t> local_position(local_size);
1357 T.prep_local_to_global();
1358 T_new.prep_global_to_local();
1360#pragma omp parallel default(shared)
1365 for (
size_t i = 0;
i < local_size; ++
i) {
1366 T.global_index_fast(
i, index);
1369 for (
size_t r = 0;
r < rank; ++
r) {
1370 const size_t idx = index[
r];
1384 local_position[
i] =
pos;
1388 local_position[
i] = 0;
1395 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1396 T_new.get_matrix());
1410template <
typename MatrixType>
1418 internal::normalized);
1421 const size_t local_size =
T.local_size();
1423 std::vector<size_t> local_position(local_size);
1425 T.prep_local_to_global();
1426 T_new.prep_global_to_local();
1428#pragma omp parallel default(shared)
1433 for (
size_t i = 0;
i < local_size; ++
i) {
1434 T.global_index_fast(
i, index);
1440 local_position[
i] =
pos;
1446 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1447 T_new.get_matrix());
1458template <
typename MatrixType>
1461 return matrix_trace(
M.get_matrix());
1478template <
typename MatrixType>
1486 if (
T.rank() == 2)
return trace(
T);
1488 const size_t n =
T.local_size();
1489 const size_t l =
ax1.size();
1492 typename MatrixType::value_type
sum(0.0);
1495 for (
size_t i = 0;
i <
n; ++
i) {
1496 T.global_index_fast(
i, index);
1498 for (
size_t k = 0;
k <
l; ++
k) {
1499 if (index[
ax1[
k]] != index[
ax2[
k]]) {
1509 return T.get_matrix().allreduce_sum(
sum);
1526template <
typename MatrixType>
1534 assert(debug::check_trace_axes(
ax_a,
ax_b,
A.internal_shape(),
B.internal_shape()));
1536 const size_t rank =
A.rank();
1543 for (
size_t i = 0;
i < rank; ++
i) {
1546 for (
size_t i = 0;
i < rank; ++
i) {
1550 const size_t n =
A.local_size();
1552 typename MatrixType::value_type
sum(0.0);
1554 for (
size_t i = 0;
i <
n; ++
i) {
1558 return A.get_matrix().allreduce_sum(
sum);
1572template <
typename MatrixType>
1575 const int mpisize =
T.get_comm_size();
1580 if (
ax1.size() == 0)
return T;
1590 size_t n =
v.size();
1591 for (
size_t i = 0;
i <
T.rank(); ++
i) {
1592 if (
k <
n &&
i ==
v[
k]) {
1603 internal::normalized);
1607 std::vector<size_t> local_position(
T.local_size());
1613 const size_t n =
ax1.size();
1615 for (
size_t i = 0;
i <
T.local_size(); ++
i) {
1616 T.global_index_fast(
i, index);
1618 for (
size_t k = 0;
k <
n; ++
k) {
1619 if (index[
ax1[
k]] != index[
ax2[
k]]) {
1634 local_position[
i] =
pos;
1638 local_position[
i] = 0;
1644 sum_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1645 T_new.get_matrix());
1668template <
typename MatrixType>
1679 for (
size_t i = 0;
i <
shape_b.size(); ++
i) {
1690 return internal::reshape_impl(
ab,
shape_c);
1705template <
typename MatrixType>
1715 for (
size_t i = 0;
i <
ax_a.size(); ++
i) {
1732 const size_t rank = a.
rank();
1735 std::vector<size_t>
v(rank);
1736 for (
size_t i = 0;
i < rank; ++
i)
v[
i] =
i;
1738 std::sort(
v.begin(),
v.end());
1748 const size_t rank =
b.rank();
1751 std::vector<size_t>
v(rank);
1752 for (
size_t i = 0;
i < rank; ++
i)
v[
i] =
i;
1754 std::sort(
v.begin(),
v.end());
1781template <
typename MatrixType>
1802template <
typename MatrixType>
1822template <
typename MatrixType>
1824 std::vector<double> &
s) {
1832 const size_t rank = a.
rank();
1847 info = matrix_svd(
a_t.get_matrix(),
s);
1872template <
typename MatrixType>
1882 const size_t rank = a.
rank();
1912 info = matrix_svd(
a_t.get_matrix(),
u.get_matrix(),
s,
vt.get_matrix());
1929template <
typename MatrixType>
1933 throw std::invalid_argument(
"mptensor: psvd() target_rank must be positive");
1956template <
typename MatrixType>
1961 throw std::invalid_argument(
"mptensor: psvd() target_rank must be positive");
1986template <
typename MatrixType>
1990 throw std::invalid_argument(
"mptensor: psvd() target_rank must be positive");
2020template <
typename MatrixType>
2025 throw std::invalid_argument(
"mptensor: psvd() target_rank must be positive");
2049template <
typename MatrixType>
2081template <
typename MatrixType>
2091 const size_t rank = a.
rank();
2148template <
typename MatrixType>
2153 assert(shape[0] == shape[1]);
2157 size_t n = shape[0];
2162 info = matrix_eigh(
a_t.get_matrix(),
w,
z.get_matrix());
2174template <
typename MatrixType>
2178 assert(shape[0] == shape[1]);
2182 size_t n = shape[0];
2186 info = matrix_eigh(
a_t.get_matrix(),
w);
2212template <
typename MatrixType>
2221 const size_t rank = a.
rank();
2244 info = matrix_eigh(
a_t.get_matrix(),
w,
z.get_matrix());
2259template <
typename MatrixType>
2261 std::vector<double> &
w) {
2268 const size_t rank = a.
rank();
2284 info = matrix_eigh(
a_t.get_matrix(),
w);
2321template <
typename MatrixType>
2338 const size_t rank_b =
b.rank();
2366 info = matrix_eigh(
a_t.get_matrix(),
b_t.get_matrix(),
w,
z.get_matrix());
2380template <
typename MatrixType>
2385 assert(shape[0] == shape[1]);
2389 size_t n = shape[0];
2394 internal::normalized);
2397 info = matrix_eig(
a_t.get_matrix(),
w,
z_t.get_matrix());
2412template <
typename MatrixType>
2416 assert(shape[0] == shape[1]);
2420 size_t n = shape[0];
2424 info = matrix_eig(
a_t.get_matrix(),
w);
2449template <
typename MatrixType>
2458 const size_t rank = a.
rank();
2479 internal::normalized);
2484 info = matrix_eig(
a_t.get_matrix(),
w,
z_t.get_matrix());
2502template <
typename MatrixType>
2504 std::vector<complex> &
w) {
2511 const size_t rank = a.
rank();
2527 info = matrix_eig(
a_t.get_matrix(),
w);
2540template <
typename MatrixType>
2542 std::vector<typename MatrixType::value_type> &
x) {
2564template <
typename MatrixType>
2568 assert(
b.rank() == 2 ||
b.rank() == 1);
2573 if (
b.rank() == 2) {
2610template <
typename MatrixType>
2648 info = matrix_solve(
a_t.get_matrix(),
b_t.get_matrix());
2654template <
typename MatrixType>
2659template <
typename MatrixType>
2661 return (
rhs *= -1.0);
2664template <
typename MatrixType>
2670template <
typename MatrixType>
2676template <
typename MatrixType,
typename D>
2681template <
typename MatrixType,
typename D>
2686template <
typename MatrixType,
typename D>
2692template <
typename MatrixType>
2697template <
typename MatrixType>
2702template <
typename MatrixType>
2707template <
typename MatrixType>
2713template <
typename MatrixType>
2715 using value_type =
typename MatrixType::value_type;
2716 if constexpr (std::is_same_v<value_type, double>) {
2717 return t.map(
static_cast<double (*)(
double)
>(&std::sqrt));
2719 return t.map(
static_cast<complex (*)(
const complex &)
>(&std::sqrt));
2722template <
typename MatrixType>
2724 using value_type =
typename MatrixType::value_type;
2725 if constexpr (std::is_same_v<value_type, double>) {
2728 return t.map(
static_cast<complex (*)(
const complex &)
>(&std::conj));
2738template <
typename MatrixType>
2744 std::vector<std::size_t>
accum(
dim + 1, 1);
2749 for (
size_t i = 0;
i < size; ++
i) {
2750 for (
size_t d = 0;
d <
dim; ++
d) {
2751 idx[
d] =
static_cast<std::ptrdiff_t
>((
i %
accum[
d]) /
accum[
d + 1]);
2753 if (idx[
dim - 1] == 0) {
2755 for (
size_t d =
dim;
d != 0 && idx[
d - 1] == 0; --
d) ++
count;
2760 using value_type =
typename MatrixType::value_type;
2763 out <<
' ' <<
val <<
' ';
2765 if (
static_cast<size_t>(idx[
dim - 1]) == shape[
dim - 1] - 1) {
2767 for (
size_t d =
dim;
d != 0 &&
static_cast<size_t>(idx[
d - 1]) == shape[
d - 1] - 1; --
d) ++
count;
2778 for (
size_t d = 0;
d <
dim; ++
d)
out <<
'[';
2779 out <<
" distributed tensor ... ";
2780 for (
size_t d = 0;
d <
dim; ++
d)
out <<
']';
void resize(size_t n)
Definition index.hpp:137
void sort()
Definition index.hpp:139
size_t size() const
Definition index.hpp:135
Tensor class. The main object of mptensor.
Definition tensor.hpp:82
typename MatrixType::value_type value_type
double or complex
Definition tensor.hpp:84
size_t rank() const
Rank of tensor.
Definition tensor_impl.hpp:184
const comm_type & get_comm() const
Communicator.
Definition tensor_impl.hpp:236
size_t local_size() const
Size of local storage.
Definition tensor_impl.hpp:199
Tensor< MatrixType > & map(UnaryOperation op)
Apply a unary operation to each element.
Definition tensor_impl.hpp:1062
Shape shape() const
Shape of tensor.
Definition tensor_impl.hpp:172
bool get_value(const Index &idx, value_type &val) const
Get an element.
Definition tensor_impl.hpp:570
void prep_local_to_global() const
Preprocess for fast conversion from local index to global one.
Definition tensor_impl.hpp:278
void print_info(std::ostream &out, const std::string &tag="") const
Output information of tensor.
Definition tensor_impl.hpp:457
size_t ndim() const
Rank of tensor.
Definition tensor_impl.hpp:193
int get_comm_rank() const
Rank of process.
Definition tensor_impl.hpp:248
const internal::UShape & internal_shape() const
Shape as the internal type.
Definition tensor_impl.hpp:178
void local_position(const internal::UIndex &idx, int &comm_rank, size_t &local_idx) const
Calculate rank which has the given global index and its local index.
Definition tensor_impl.hpp:602
void prep_global_to_local() const
Preprocess for fast conversion from global index to local one.
Definition tensor_impl.hpp:272
const MatrixType & get_matrix() const
distributed Matrix
Definition tensor_impl.hpp:223
int get_comm_size() const
Size of communicator.
Definition tensor_impl.hpp:242
void global_index_fast(size_t i, internal::UIndex &idx) const
Convert local index to global index fast.
Definition tensor_impl.hpp:543
typename MatrixType::comm_type comm_type
type of communicator. MPI_Comm or int.
Definition tensor.hpp:86
int comm_type
Definition matrix_lapack.hpp:48
Define the type of a complex number.
Tensor< MatrixType > operator/(Tensor< MatrixType > lhs, D rhs)
Scalar division.
Definition tensor_impl.hpp:2682
Tensor< MatrixType > operator*(Tensor< MatrixType > lhs, D rhs)
Tensor-scalar multiplication.
Definition tensor_impl.hpp:2677
std::complex< double > complex
Definition complex.hpp:38
int eig(const Tensor< MatrixType > &a, std::vector< complex > &eigval, typename Tensor< MatrixType >::template rebind< complex > &eigvec)
Compute the eigenvalues and eigenvectors of a general matrix (rank-2 tensor)
Definition tensor_impl.hpp:2381
int psvd(const Tensor< MatrixType > &a, std::vector< double > &s, const size_t target_rank)
Partial SVD for rank-2 tensor (matrix)
Definition tensor_impl.hpp:1930
int eigh(const Tensor< MatrixType > &a, std::vector< double > &eigval, Tensor< MatrixType > &eigvec)
Definition tensor_impl.hpp:2149
int qr(const Tensor< MatrixType > &a, Tensor< MatrixType > &q, Tensor< MatrixType > &r)
QR decomposition of matrix (rank-2 tensor)
Definition tensor_impl.hpp:2050
int svd(const Tensor< MatrixType > &a, std::vector< double > &s)
Singular value decomposition for rank-2 tensor (matrix)
Definition tensor_impl.hpp:1782
internal::UShape to_internal_shape(const Shape &s)
Definition index.hpp:366
Index to_public(const internal::UIndex &u)
Definition index.hpp:382
internal::UAxes normalize_axes(const Axes &axes, size_t rank)
Definition index.hpp:323
size_t normalize_index(std::ptrdiff_t i, size_t n)
Definition index.hpp:335
size_t normalize_axis(std::ptrdiff_t a, size_t rank)
Definition index.hpp:317
BasicIndex< T > operator+(const BasicIndex< T > &lhs, const BasicIndex< T > &rhs)
Definition index.hpp:203
Tensor< MatrixType > transpose_impl(const Tensor< MatrixType > &a, const UAxes &axes, size_t urank_new)
Definition tensor_impl.hpp:1116
constexpr normalized_t normalized
Definition tensor.hpp:55
UIndex UAxes
Definition index.hpp:224
Tensor< MatrixType > reshape_impl(const Tensor< MatrixType > &a, const UShape &shape_new)
Definition tensor_impl.hpp:1197
MatrixType::value_type trace(const Tensor< MatrixType > &a)
Trace of matrix (rank-2 tensor)
Definition tensor_impl.hpp:1459
Tensor< MatrixType > contract(const Tensor< MatrixType > &a, const Axes &axes_1, const Axes &axes_2)
Partial trace of tensor.
Definition tensor_impl.hpp:1573
Tensor< MatrixType > tensordot(const Tensor< MatrixType > &a, const Tensor< MatrixType > &b, const Axes &axes_a, const Axes &axes_b)
Compute tensor dot product.
Definition tensor_impl.hpp:1706
Tensor< MatrixType > kron(const Tensor< MatrixType > &a, const Tensor< MatrixType > &b)
Compute the Kronecker product.
Definition tensor_impl.hpp:1669
int solve(const Tensor< MatrixType > &a, const std::vector< typename MatrixType::value_type > &b, std::vector< typename MatrixType::value_type > &x)
Solve linear equation .
Definition tensor_impl.hpp:2541
Tensor< MatrixType > conj(Tensor< MatrixType > t)
Take conjugate of each element.
Tensor< MatrixType > extend(const Tensor< MatrixType > &a, const Shape &shape_new)
Extend the size of a tensor.
Definition tensor_impl.hpp:1411
Tensor< MatrixType > transpose(Tensor< MatrixType > a, const Axes &axes)
Transposition of tensor with lazy evaluation.
Definition tensor_impl.hpp:1077
Tensor< MatrixType > reshape(const Tensor< MatrixType > &a, const Shape &shape_new)
Change the shape of tensor.
Definition tensor_impl.hpp:1110
Tensor< MatrixType > slice(const Tensor< MatrixType > &a, std::ptrdiff_t n_axes, std::ptrdiff_t i_begin, std::ptrdiff_t i_end)
Slice a tensor.
Definition tensor_impl.hpp:1265
Tensor()
Default constructor of tensor.
Definition tensor_impl.hpp:71
header file of BasicIndex class template
List of header files for matrix classes.
mptensor::complex complex
Definition matrix_lapack.cc:36
bool check_contract_axes(const internal::UAxes &axes_1, const internal::UAxes &axes_2, size_t rank)
Definition tensor.cc:114
bool check_square(const internal::UShape &shape, size_t urank)
Definition tensor.cc:125
bool check_svd_axes(const internal::UAxes &axes_row, const internal::UAxes &axes_col, size_t rank)
Definition tensor.cc:76
bool check_transpose_axes(const internal::UAxes &axes, size_t rank)
Definition tensor.cc:66
bool check_extend(const internal::UShape &s_old, const internal::UShape &s_new)
Definition tensor.cc:57
bool check_trace_axes(const internal::UAxes &axes_1, const internal::UAxes &axes_2, size_t rank)
Definition tensor.cc:86
bool check_total_size(const internal::UShape &s1, const internal::UShape &s2)
Definition tensor.cc:49
void replace_matrix_data(const Matrix< C > &M, const std::vector< int > &dest_rank, const std::vector< size_t > &local_position, Matrix< C > &M_new)
Definition complex.hpp:34
bool is_no_transpose(const internal::UAxes &axes, const internal::UAxes &axes_map, size_t rank)
Definition tensor.cc:35
double operator-(Timer &t1, Timer &t0)
Definition timer.hpp:64