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>
101 init(shape, shape.
size() / 2);
110template <
typename MatrixType>
112 const size_t upper_rank)
114 init(
shape, upper_rank);
123template <
typename MatrixType>
125 const Tensor<lapack::Matrix<value_type>> &t)
127 init(t.shape(), t.get_upper_rank());
128 const size_t n = Mat.local_size();
131 for (
size_t i = 0;
i <
n; ++
i) {
132 t.local_position(global_index(
i),
dummy, idx);
143template <
typename MatrixType>
147 const size_t n = Mat.local_size();
149 for (
size_t i = 0;
i <
n; ++
i) {
150 idx = global_index(
i);
158template <
typename MatrixType>
164template <
typename MatrixType>
173template <
typename MatrixType>
179template <
typename MatrixType>
181 return Mat.local_size();
185template <
typename MatrixType>
197template <
typename MatrixType>
203template <
typename MatrixType>
209template <
typename MatrixType>
215template <
typename MatrixType>
218 return Mat.get_comm();
222template <
typename MatrixType>
224 return Mat.get_comm_size();
228template <
typename MatrixType>
230 return Mat.get_comm_rank();
237template <
typename MatrixType>
246template <
typename MatrixType>
252template <
typename MatrixType>
254 Mat.prep_global_to_local();
258template <
typename MatrixType>
260 Mat.prep_local_to_global();
264template <
typename MatrixType>
266 const size_t rank = Dim.size();
267 const size_t rank0 = upper_rank;
269 const size_t l_row = Mat.local_row_size();
270 const size_t l_col = Mat.local_col_size();
282#pragma omp parallel default(shared)
295 for (
size_t k = 0;
k <
l_row; ++
k) {
296 map = &(l2g_map_row[
k *
rank0]);
298 for (
size_t i = 0;
i <
rank0; ++
i) {
307 for (
size_t k = 0;
k <
l_col; ++
k) {
308 map = &(l2g_map_col[
k *
rank1]);
310 for (
size_t i = 0;
i <
rank1; ++
i) {
329template <
typename MatrixType>
332 const size_t rank = Dim.size();
333 const size_t rank0 = upper_rank;
343 for (
size_t i = 0;
i <
rank0; ++
i) {
346 for (
size_t i = 0;
i <
rank1; ++
i) {
364template <
typename MatrixType>
367 const size_t rank = Dim.size();
368 const size_t rank0 = upper_rank;
378 for (
size_t i = 0;
i <
rank0; ++
i) {
382 for (
size_t i = 0;
i <
rank1; ++
i) {
389template <
typename MatrixType>
403template <
typename MatrixType>
414template <
typename MatrixType>
415void Tensor<MatrixType>::init(
const Shape &shape,
size_t urank,
419 const size_t rank = Dim.size();
425 for (
size_t i = 0;
i < upper_rank; ++
i) n_row *= shape[map[
i]];
426 for (
size_t i = upper_rank;
i < rank; ++
i) n_col *= shape[map[
i]];
427 Mat.init(n_row, n_col);
437template <
typename MatrixType>
439 const std::string &
tag)
const {
440 if (
tag.size() > 0) {
443 out <<
"Tensor: shape= " << Dim <<
" upper_rank= " << upper_rank
444 <<
" axes_map= " << axes_map <<
"\t";
455template <
typename MatrixType>
457 const std::string &
tag)
const {
458 const int mpisize = get_comm_size();
459 const int mpirank = get_comm_rank();
462 for (
int i = 0;
i < mpisize; ++
i) {
464 if (
tag.size() > 0) {
467 out <<
"mpirank: " << mpirank <<
"\t";
483template <
typename MatrixType>
485 const size_t rank =
gindex.size();
486 assert(rank == Dim.size());
490 for (
size_t i = 0;
i < upper_rank; ++
i) {
491 size_t j = axes_map[
i];
495 for (
size_t i = upper_rank;
i < rank; ++
i) {
496 size_t j = axes_map[
i];
508template <
typename MatrixType>
510 const size_t rank = Dim.size();
516 for (
size_t i = 0;
i < upper_rank; ++
i) {
517 size_t j = axes_map[
i];
522 for (
size_t i = upper_rank;
i < rank; ++
i) {
523 size_t j = axes_map[
i];
538template <
typename MatrixType>
540 const size_t rank = Dim.size();
544 for (
size_t i = 0;
i < upper_rank; ++
i) {
545 size_t j = axes_map[
i];
550 for (
size_t i = upper_rank;
i < rank; ++
i) {
551 size_t j = axes_map[
i];
565template <
typename MatrixType>
568 if (local_index(idx,
li)) {
583template <
typename MatrixType>
586 if (local_index(idx,
li)) {
597template <
typename MatrixType>
600 const size_t rank = Dim.size();
603 for (
size_t i = 0;
i < upper_rank; ++
i) {
604 size_t j = axes_map[
i];
608 for (
size_t i = upper_rank;
i < rank; ++
i) {
609 size_t j = axes_map[
i];
624template <
typename MatrixType>
631 const size_t rank = this->rank();
636 for (
size_t i = 0;
i < rank; ++
i) {
644 const size_t local_size =
T_old.local_size();
646 std::vector<size_t> local_position(local_size);
648 T_old.prep_local_to_global();
649 this->prep_global_to_local();
651#pragma omp parallel default(shared)
657 for (
size_t i = 0;
i < local_size; ++
i) {
658 T_old.global_index_fast(
i, index);
662 this->local_position(index,
dest,
pos);
664 local_position[
i] =
pos;
680template <
typename MatrixType>
682 const size_t rank = Dim.size();
689 for (
size_t i = 0;
i < rank; ++
i) {
693 for (
size_t i = 0;
i < rank; ++
i) {
712template <
typename MatrixType>
717 const size_t local_size = this->local_size();
718 prep_local_to_global();
719#pragma omp parallel default(shared)
724 for (
size_t i = 0;
i < local_size; ++
i) {
725 global_index_fast(
i, idx);
745template <
typename MatrixType>
746template <
typename D0,
typename D1>
748 const std::vector<D0> &
vec0,
size_t n_axes0,
const std::vector<D1> &
vec1,
752 const size_t local_size = this->local_size();
753 prep_local_to_global();
754#pragma omp parallel default(shared)
759 for (
size_t i = 0;
i < local_size; ++
i) {
760 global_index_fast(
i, idx);
782template <
typename MatrixType>
783template <
typename D0,
typename D1,
typename D2>
785 const std::vector<D0> &
vec0,
size_t n_axes0,
const std::vector<D1> &
vec1,
790 const size_t local_size = this->local_size();
791 prep_local_to_global();
792#pragma omp parallel default(shared)
797 for (
size_t i = 0;
i < local_size; ++
i) {
798 global_index_fast(
i, idx);
822template <
typename MatrixType>
823template <
typename D0,
typename D1,
typename D2,
typename D3>
825 const std::vector<D0> &
vec0,
size_t n_axes0,
const std::vector<D1> &
vec1,
832 const size_t local_size = this->local_size();
833 prep_local_to_global();
834#pragma omp parallel default(shared)
839 for (
size_t i = 0;
i < local_size; ++
i) {
840 global_index_fast(
i, idx);
859template <
typename MatrixType>
863 const size_t i_end) {
873 std::vector<size_t> local_position(local_size);
876 prep_global_to_local();
878#pragma omp parallel default(shared)
883 for (
size_t i = 0;
i < local_size; ++
i) {
889 this->local_position(index,
dest,
pos);
891 local_position[
i] =
pos;
914template <
typename MatrixType>
918 const size_t nr = rank();
922 for (
size_t r = 0;
r <
nr; ++
r) {
930 std::vector<size_t> local_position(local_size);
933 prep_global_to_local();
935#pragma omp parallel default(shared)
940 for (
size_t i = 0;
i < local_size; ++
i) {
942 for (
size_t r = 0;
r <
nr; ++
r) {
948 this->local_position(index,
dest,
pos);
950 local_position[
i] =
pos;
968template <
typename MatrixType>
970 const size_t n = rank();
971 if (!(axes_map ==
range(
n))) {
972 change_configuration(
n / 2,
range(
n));
984template <
typename MatrixType>
986 const size_t n = rank();
987 if (!(axes_map ==
range(
n))) {
988 change_configuration(
n / 2,
range(
n));
990 return get_matrix().flatten();
994template <
typename MatrixType>
997 change_configuration(
rhs.get_upper_rank(),
rhs.get_axes_map());
998 Mat +=
rhs.get_matrix();
1003template <
typename MatrixType>
1006 change_configuration(
rhs.get_upper_rank(),
rhs.get_axes_map());
1007 Mat -=
rhs.get_matrix();
1012template <
typename MatrixType>
1019template <
typename MatrixType>
1026template <
typename MatrixType>
1028 const size_t n = Mat.local_size();
1029 for (
int i = 0;
i <
n; ++
i) Mat[
i] =
rhs;
1038template <
typename MatrixType>
1039template <
typename UnaryOperation>
1054template <
typename MatrixType>
1056 return T.transpose(
axes);
1069template <
typename MatrixType>
1072 const size_t rank =
T.rank();
1084 for (
size_t r = 0;
r < rank; ++
r) {
1092 const size_t local_size =
T.local_size();
1094 std::vector<size_t> local_position(local_size);
1097 T_new.prep_global_to_local();
1099#pragma omp parallel default(shared)
1102 std::vector<size_t>
d_offset(rank);
1113 Axes axes_map =
T.get_axes_map();
1114 std::vector<size_t>
axes_inv(rank);
1116 for (
size_t r = 0;
r < rank; ++
r) {
1119 for (
size_t r = 0;
r < rank; ++
r) {
1126 for (
size_t i = 0;
i < local_size; ++
i) {
1144 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1145 T_new.get_matrix());
1162template <
typename MatrixType>
1166 const Shape &shape =
T.shape();
1167 const size_t rank = shape.
size();
1174 const size_t local_size =
T.local_size();
1176 std::vector<size_t> local_position(local_size);
1178 T.prep_local_to_global();
1179 T_new.prep_global_to_local();
1181#pragma omp parallel default(shared)
1187 for (
size_t i = 0;
i < local_size; ++
i) {
1188 T.global_index_fast(
i, index);
1191 for (
size_t r = 0;
r < rank; ++
r) {
1205 local_position[
i] =
pos;
1211 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1212 T_new.get_matrix());
1228template <
typename MatrixType>
1231 const int mpisize =
T.get_comm_size();
1232 const Shape &shape =
T.shape();
1244 const size_t local_size =
T.local_size();
1246 std::vector<size_t> local_position(local_size);
1248 T.prep_local_to_global();
1249 T_new.prep_global_to_local();
1251#pragma omp parallel default(shared)
1256 for (
size_t i = 0;
i < local_size; ++
i) {
1257 T.global_index_fast(
i, index);
1265 local_position[
i] =
pos;
1269 local_position[
i] = 0;
1276 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1277 T_new.get_matrix());
1296template <
typename MatrixType>
1299 const int mpisize =
T.get_comm_size();
1300 const Shape &shape =
T.shape();
1301 const size_t rank =
T.rank();
1306 for (
size_t r = 0;
r < rank; ++
r) {
1317 const size_t local_size =
T.local_size();
1319 std::vector<size_t> local_position(local_size);
1321 T.prep_local_to_global();
1322 T_new.prep_global_to_local();
1324#pragma omp parallel default(shared)
1329 for (
size_t i = 0;
i < local_size; ++
i) {
1330 T.global_index_fast(
i, index);
1333 for (
size_t r = 0;
r < rank; ++
r) {
1334 size_t idx = index[
r];
1350 local_position[
i] =
pos;
1354 local_position[
i] = 0;
1361 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1362 T_new.get_matrix());
1376template <
typename MatrixType>
1385 const size_t local_size =
T.local_size();
1387 std::vector<size_t> local_position(local_size);
1389 T.prep_local_to_global();
1390 T_new.prep_global_to_local();
1392#pragma omp parallel default(shared)
1397 for (
size_t i = 0;
i < local_size; ++
i) {
1398 T.global_index_fast(
i, index);
1404 local_position[
i] =
pos;
1410 replace_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1411 T_new.get_matrix());
1422template <
typename MatrixType>
1425 return matrix_trace(
M.get_matrix());
1442template <
typename MatrixType>
1448 if (
T.rank() == 2)
return trace(
T);
1450 const size_t n =
T.local_size();
1451 const size_t l =
axes_1.size();
1454 typename MatrixType::value_type
sum(0.0);
1457 for (
size_t i = 0;
i <
n; ++
i) {
1458 T.global_index_fast(
i, index);
1460 for (
size_t k = 0;
k <
l; ++
k) {
1471 return T.get_matrix().allreduce_sum(
sum);
1488template <
typename MatrixType>
1496 const size_t rank =
A.rank();
1499 Axes axes_map =
A.get_axes_map();
1503 for (
size_t i = 0;
i < rank; ++
i) {
1506 for (
size_t i = 0;
i < rank; ++
i) {
1510 const size_t n =
A.local_size();
1512 typename MatrixType::value_type
sum(0.0);
1514 for (
size_t i = 0;
i <
n; ++
i) {
1518 return A.get_matrix().allreduce_sum(
sum);
1532template <
typename MatrixType>
1535 const int mpisize =
T.get_comm_size();
1538 if (
axes_1.size() == 0)
return T;
1548 size_t n =
v.size();
1549 for (
size_t i = 0;
i <
T.rank(); ++
i) {
1550 if (
k <
n &&
i ==
v[
k]) {
1564 std::vector<size_t> local_position(
T.local_size());
1570 const size_t n =
axes_1.size();
1572 for (
size_t i = 0;
i <
T.local_size(); ++
i) {
1573 T.global_index_fast(
i, index);
1575 for (
size_t k = 0;
k <
n; ++
k) {
1591 local_position[
i] =
pos;
1595 local_position[
i] = 0;
1601 sum_matrix_data(
T.get_matrix(),
dest_mpirank, local_position,
1602 T_new.get_matrix());
1625template <
typename MatrixType>
1636 for (
size_t i = 0;
i <
shape_b.size(); ++
i) {
1661template <
typename MatrixType>
1669 for (
size_t i = 0;
i <
axes_a.size(); ++
i) {
1686 const size_t rank = a.
rank();
1689 std::vector<size_t>
v(rank);
1690 for (
size_t i = 0;
i < rank; ++
i)
v[
i] =
i;
1692 std::sort(
v.begin(),
v.end());
1702 const size_t rank =
b.rank();
1705 std::vector<size_t>
v(rank);
1706 for (
size_t i = 0;
i < rank; ++
i)
v[
i] =
i;
1708 std::sort(
v.begin(),
v.end());
1735template <
typename MatrixType>
1756template <
typename MatrixType>
1776template <
typename MatrixType>
1778 std::vector<double> &
s) {
1783 const size_t rank = a.
rank();
1799 info = matrix_svd(
a_t.get_matrix(),
s);
1824template <
typename MatrixType>
1831 const size_t rank = a.
rank();
1862 info = matrix_svd(
a_t.get_matrix(),
u.get_matrix(),
s,
vt.get_matrix());
1879template <
typename MatrixType>
1903template <
typename MatrixType>
1930template <
typename MatrixType>
1961template <
typename MatrixType>
1987template <
typename MatrixType>
2019template <
typename MatrixType>
2026 const size_t rank = a.
rank();
2084template <
typename MatrixType>
2089 assert(shape[0] == shape[1]);
2093 size_t n = shape[0];
2098 info = matrix_eigh(
a_t.get_matrix(),
w,
z.get_matrix());
2110template <
typename MatrixType>
2114 assert(shape[0] == shape[1]);
2118 size_t n = shape[0];
2122 info = matrix_eigh(
a_t.get_matrix(),
w);
2148template <
typename MatrixType>
2154 const size_t rank = a.
rank();
2178 info = matrix_eigh(
a_t.get_matrix(),
w,
z.get_matrix());
2193template <
typename MatrixType>
2195 std::vector<double> &
w) {
2199 const size_t rank = a.
rank();
2216 info = matrix_eigh(
a_t.get_matrix(),
w);
2253template <
typename MatrixType>
2264 const size_t rank_b =
b.rank();
2294 info = matrix_eigh(
a_t.get_matrix(),
b_t.get_matrix(),
w,
z.get_matrix());
2308template <
typename MatrixType>
2313 assert(shape[0] == shape[1]);
2317 size_t n = shape[0];
2323 info = matrix_eig(
a_t.get_matrix(),
w,
z_t.get_matrix());
2338template <
typename MatrixType>
2342 assert(shape[0] == shape[1]);
2346 size_t n = shape[0];
2350 info = matrix_eig(
a_t.get_matrix(),
w);
2375template <
typename MatrixType>
2381 const size_t rank = a.
rank();
2406 info = matrix_eig(
a_t.get_matrix(),
w,
z_t.get_matrix());
2424template <
typename MatrixType>
2426 std::vector<complex> &
w) {
2430 const size_t rank = a.
rank();
2447 info = matrix_eig(
a_t.get_matrix(),
w);
2460template <
typename MatrixType>
2462 std::vector<typename MatrixType::value_type> &
x) {
2484template <
typename MatrixType>
2488 assert(
b.rank() == 2 ||
b.rank() == 1);
2493 if (
b.rank() == 2) {
2530template <
typename MatrixType>
2564 info = matrix_solve(
a_t.get_matrix(),
b_t.get_matrix());
2570template <
typename MatrixType>
2575template <
typename MatrixType>
2577 return (
rhs *= -1.0);
2580template <
typename MatrixType>
2586template <
typename MatrixType>
2592template <
typename MatrixType,
typename D>
2597template <
typename MatrixType,
typename D>
2602template <
typename MatrixType,
typename D>
2608template <
typename MatrixType>
2613template <
typename MatrixType>
2618template <
typename MatrixType>
2623template <
typename MatrixType>
2629template <
typename MatrixType>
2631 using value_type =
typename MatrixType::value_type;
2632 if constexpr (std::is_same_v<value_type, double>) {
2633 return t.map(
static_cast<double (*)(
double)
>(&std::sqrt));
2635 return t.map(
static_cast<complex (*)(
const complex &)
>(&std::sqrt));
2638template <
typename MatrixType>
2640 using value_type =
typename MatrixType::value_type;
2641 if constexpr (std::is_same_v<value_type, double>) {
2644 return t.map(
static_cast<complex (*)(
const complex &)
>(&std::conj));
2654template <
typename MatrixType>
2660 std::vector<std::size_t>
accum(
dim + 1, 1);
2663 std::vector<std::size_t> idx(
dim);
2664 for (
size_t i = 0;
i < size; ++
i) {
2666 if (idx[
dim - 1] == 0) {
2668 for (
size_t d =
dim;
d != 0 && idx[
d - 1] == 0; --
d) ++
count;
2673 using value_type =
typename MatrixType::value_type;
2676 out <<
' ' <<
val <<
' ';
2678 if (idx[
dim - 1] == shape[
dim - 1] - 1) {
2680 for (
size_t d =
dim;
d != 0 && idx[
d - 1] == shape[
d - 1] - 1; --
d) ++
count;
2691 for (
size_t d = 0;
d <
dim; ++
d)
out <<
'[';
2692 out <<
" distributed tensor ... ";
2693 for (
size_t d = 0;
d <
dim; ++
d)
out <<
']';
void resize(size_t n)
Definition index.hpp:81
void sort()
Definition index.cc:42
size_t size() const
Definition index.hpp:79
Tensor class. The main object of mptensor.
Definition tensor.hpp:54
Tensor< MatrixType > & transpose(const Axes &axes)
Transposition of tensor with lazy evaluation.
Definition tensor_impl.hpp:681
typename MatrixType::value_type value_type
double or complex
Definition tensor.hpp:56
size_t rank() const
Rank of tensor.
Definition tensor_impl.hpp:165
const comm_type & get_comm() const
Communicator.
Definition tensor_impl.hpp:217
const Axes & get_axes_map() const
Map of axes for lazy evaluation of transpose.
Definition tensor_impl.hpp:198
size_t local_size() const
Size of local storage.
Definition tensor_impl.hpp:180
std::vector< value_type > flatten()
Return a copy of the flattened vector.
Definition tensor_impl.hpp:985
Tensor< MatrixType > & map(UnaryOperation op)
Apply a unary operation to each element.
Definition tensor_impl.hpp:1040
void make_l2g_map() const
Preprocess for fast conversion from local index to global one.
Definition tensor_impl.hpp:265
const value_type & operator[](size_t local_idx) const
Const array subscript operator.
Definition tensor_impl.hpp:238
void global_index_fast(size_t i, Index &idx) const
Convert local index to global index fast.
Definition tensor_impl.hpp:539
Tensor< MatrixType > & operator=(value_type rhs)
Initialize all elements by rhs.
Definition tensor_impl.hpp:1027
void global_index_l2g_map_transpose(size_t lindex, const size_t axes_trans[], size_t index_new[]) const
Convert local index to global index of transposed tensor using l2g_map.
Definition tensor_impl.hpp:365
void local_position(const Index &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:598
void global_index_l2g_map(size_t lindex, size_t gindex[]) const
Convert local index to global index using l2g_map.
Definition tensor_impl.hpp:330
Tensor< lapack::Matrix< value_type > > gather()
Gather all elements into a non-distributed tensor.
Definition tensor_impl.hpp:969
bool get_value(const Index &idx, value_type &val) const
Get an element.
Definition tensor_impl.hpp:566
Tensor< MatrixType > & operator-=(const Tensor &rhs)
Subtraction assignment.
Definition tensor_impl.hpp:1004
void prep_local_to_global() const
Preprocess for fast conversion from local index to global one.
Definition tensor_impl.hpp:259
void print_info_mpi(std::ostream &, const std::string &tag="") const
Output information of tensor.
Definition tensor_impl.hpp:456
void print_info(std::ostream &out, const std::string &tag="") const
Output information of tensor.
Definition tensor_impl.hpp:438
size_t ndim() const
Rank of tensor.
Definition tensor_impl.hpp:174
Tensor< MatrixType > & multiply_vector(const std::vector< D > &vec, size_t n_axes)
Element-wise vector multiplication.
Definition tensor_impl.hpp:714
void set_value(const Index &idx, value_type val)
Set an element.
Definition tensor_impl.hpp:584
Tensor< MatrixType > & operator/=(value_type rhs)
Scalar-division assignment.
Definition tensor_impl.hpp:1020
int get_comm_rank() const
Rank of process.
Definition tensor_impl.hpp:229
void local_position_fast(size_t g_row, size_t g_col, int &comm_rank, size_t &local_idx) const
Definition tensor_impl.hpp:390
Index global_index(size_t i) const
Convert local index to global index.
Definition tensor_impl.hpp:509
void prep_global_to_local() const
Preprocess for fast conversion from global index to local one.
Definition tensor_impl.hpp:253
Tensor< MatrixType > & operator*=(value_type rhs)
Scalar-multiplication assignment.
Definition tensor_impl.hpp:1013
Tensor< MatrixType > & set_slice(const Tensor &a, size_t n_axes, size_t i_begin, size_t i_end)
Inverse of slice().
Definition tensor_impl.hpp:860
const Shape & shape() const
Shape of tensor.
Definition tensor_impl.hpp:159
size_t get_upper_rank() const
Upper rank for matrix representation.
Definition tensor_impl.hpp:186
Tensor< MatrixType > & operator+=(const Tensor &rhs)
Addition assignment.
Definition tensor_impl.hpp:995
const MatrixType & get_matrix() const
distributed Matrix
Definition tensor_impl.hpp:204
int get_comm_size() const
Size of communicator.
Definition tensor_impl.hpp:223
typename MatrixType::comm_type comm_type
type of communicator. MPI_Comm or int.
Definition tensor.hpp:58
Define the type of a complex number.
Tensor< MatrixType > operator/(Tensor< MatrixType > lhs, D rhs)
Scalar division.
Definition tensor_impl.hpp:2598
Tensor< MatrixType > operator-(Tensor< MatrixType > rhs)
Unary minus.
Definition tensor_impl.hpp:2576
Tensor< MatrixType > operator*(Tensor< MatrixType > lhs, D rhs)
Tensor-scalar multiplication.
Definition tensor_impl.hpp:2593
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:2309
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:1880
int eigh(const Tensor< MatrixType > &a, std::vector< double > &eigval, Tensor< MatrixType > &eigvec)
Definition tensor_impl.hpp:2085
int qr(const Tensor< MatrixType > &a, Tensor< MatrixType > &q, Tensor< MatrixType > &r)
QR decomposition of matrix (rank-2 tensor)
Definition tensor_impl.hpp:1988
int svd(const Tensor< MatrixType > &a, std::vector< double > &s)
Singular value decomposition for rank-2 tensor (matrix)
Definition tensor_impl.hpp:1736
MatrixType::value_type trace(const Tensor< MatrixType > &a)
Trace of matrix (rank-2 tensor)
Definition tensor_impl.hpp:1423
Tensor< MatrixType > contract(const Tensor< MatrixType > &a, const Axes &axes_1, const Axes &axes_2)
Partial trace of tensor.
Definition tensor_impl.hpp:1533
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:1662
Tensor< MatrixType > kron(const Tensor< MatrixType > &a, const Tensor< MatrixType > &b)
Compute the Kronecker product.
Definition tensor_impl.hpp:1626
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:2461
Tensor< MatrixType > conj(Tensor< MatrixType > t)
Take conjugate of each element.
double min_abs(const Tensor< MatrixType > &t)
Return minimum of the absolute value of an element.
Definition tensor_impl.hpp:2624
Tensor< MatrixType > sqrt(Tensor< MatrixType > t)
Take square-root of each element.
double min(const Tensor< MatrixType > &t)
Return the minimum element. For complex, same as min_abs().
Definition tensor_impl.hpp:2614
double max_abs(const Tensor< MatrixType > &t)
Return maximum of the absolute value of an element.
Definition tensor_impl.hpp:2619
double max(const Tensor< MatrixType > &t)
Return the maximum element. For complex, same as max_abs().
Definition tensor_impl.hpp:2609
Tensor< MatrixType > extend(const Tensor< MatrixType > &a, const Shape &shape_new)
Extend the size of a tensor.
Definition tensor_impl.hpp:1377
Tensor< MatrixType > transpose(Tensor< MatrixType > a, const Axes &axes)
Transposition of tensor with lazy evaluation.
Definition tensor_impl.hpp:1055
Tensor< MatrixType > reshape(const Tensor< MatrixType > &a, const Shape &shape_new)
Change the shape of tensor.
Definition tensor_impl.hpp:1163
Tensor< MatrixType > slice(const Tensor< MatrixType > &a, size_t n_axes, size_t i_begin, size_t i_end)
Slice a tensor.
Definition tensor_impl.hpp:1229
Tensor()
Default constructor of tensor.
Definition tensor_impl.hpp:71
header file of Index class
Index(size_t j0)
Definition index_constructor.hpp:11
List of header files for matrix classes.
mptensor::complex complex
Definition matrix_lapack.cc:36
bool check_total_size(const Shape &s1, const Shape &s2)
Definition tensor.cc:49
bool check_trace_axes(const Axes &axes_1, const Axes &axes_2, size_t rank)
Definition tensor.cc:86
bool check_extend(const Shape &s_old, const Shape &s_new)
Definition tensor.cc:57
bool check_svd_axes(const Axes &axes_row, const Axes &axes_col, size_t rank)
Definition tensor.cc:76
bool check_contract_axes(const Axes &axes_1, const Axes &axes_2, size_t rank)
Definition tensor.cc:114
bool check_transpose_axes(const Axes &axes, size_t rank)
Definition tensor.cc:66
bool check_square(const Shape &shape, size_t urank)
Definition tensor.cc:125
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
Index Shape
Definition tensor.hpp:46
std::ostream & operator<<(std::ostream &os, const Index &idx)
Index range(const size_t start, const size_t stop)
Create an increasing sequence. it is similar to range() in python.
Definition index.cc:91
Index Axes
Definition tensor.hpp:45
bool is_no_transpose(const Axes &axes, const Axes &axes_map, size_t rank)
Definition tensor.cc:35
Index operator+(const Index &, const Index &)