40 Y.
write(n_X, inds_X, vals_X);
46 std::vector< Matrix <> > factor_matrices (T.
order);
48 char chars[] = {
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'\0'};
50 int transformed_lens[T.
order];
51 char transformed_arg[T.
order+1];
52 transformed_arg[T.
order] =
'\0';
53 for (
int i = 0; i < T.
order; i++) {
55 transformed_arg[i] = chars[i];
56 transformed_lens[i] = T.
lens[i];
61 for (
int i = 0; i < T.
order; i++) {
62 for (
int j = i; j > 0; j--) {
63 transformed_lens[j] = T.
lens[j-1];
66 transformed_lens[0] = T.
lens[i];
67 for (
int j = 0; j < i; j++) {
68 transformed_arg[j] = arg[j+1];
70 transformed_arg[i] = arg[0];
73 unfold_lens[0] = T.
lens[i];
76 for (
int j = 0; j < T.
order; j++) {
80 unfold_lens[1] = ncol;
83 transformed_T[arg] = T[transformed_arg];
92 M.
svd(U, S, VT, ranks[i]);
104 factor_matrices[i] = U;
108 return factor_matrices;
113 std::vector< Tensor <> > core_tensors(T.
order+1);
116 for (
int i = 0; i < T.
order; i++) {
119 for (
int i = 1; i < T.
order+1; i++) {
120 lens[i-1] = ranks[i-1];
122 core_tensors[i] = core;
126 char chars[] = {
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'\0'};
128 char core_arg[T.
order+1];
129 for (
int i = 0; i < T.
order; i++) {
131 core_arg[i] = chars[i];
134 core_arg[T.
order] =
'\0';
137 matrix_arg[2] =
'\0';
138 for (
int i = 0; i < T.
order; i++) {
140 matrix_arg[1] = arg[i];
142 transpose[
"ij"] = factor_matrices[i][
"ji"];
148 core_tensors[i+1][core_arg] = transpose[matrix_arg] * core_tensors[i][arg];
149 core_arg[i] = arg[i];
151 return core_tensors[T.
order];
160 printf(
"j is %d \n", j);
162 std::vector< Tensor <> > core_tensors(T.
order);
165 for (
int i = 0; i < T.
order; i++) {
168 for (
int i = 1; i < T.
order+1; i++) {
170 lens[i-1] = ranks[i-1];
172 core_tensors[i] = core;
175 lens[i-1] = ranks[i-1];
177 core_tensors[i-1] = core;
182 char chars[] = {
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'\0'};
184 char core_arg[T.
order+1];
185 for (
int i = 0; i < T.
order; i++) {
187 core_arg[i] = chars[i];
190 core_arg[T.
order] =
'\0';
193 matrix_arg[2] =
'\0';
194 for (
int i = 0; i < T.
order; i++) {
197 matrix_arg[1] = arg[i];
199 transpose[
"ij"] = factor_matrices[i][
"ji"];
206 core_tensors[i+1][core_arg] = transpose[matrix_arg] * core_tensors[i][arg];
207 core_arg[i] = arg[i];
210 core_tensors[i+1][core_arg] = transpose[matrix_arg] * core_tensors[i-1][arg];
211 core_arg[i] = arg[i];
215 return core_tensors[T.
order-1];
221 for (
int i = 0; i < T.
order; i++) {
224 std::vector< Matrix<double> > temp_factor_matrices =
get_factor_matrices(temp_core, ranks, dw);
225 factor_matrices[i] = temp_factor_matrices[i];
229 int main(
int argc,
char ** argv) {
234 MPI_Init(&argc, &argv);
235 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
236 MPI_Comm_size(MPI_COMM_WORLD, &np);
237 World dw(argc, argv);
void Cblacs_gridinit(int *, char *, int, int)
Matrix class which encapsulates a 2D tensor.
void Cblacs_get(int, int, int *)
Vector class which encapsulates a 1D tensor.
an instance of the CTF library (world) on a MPI communicator
int order
number of tensor dimensions
void read_local(int64_t *npair, int64_t **global_idx, dtype **data, bool unpack_sym=false) const
Using get_local_data(), which returns an array that must be freed with delete [], is more efficient...
void fill_random(dtype rmin, dtype rmax)
fills local unique tensor elements to random values in the range [min,max] works only for dtype in {f...
void Cblacs_gridinfo(int, int *, int *, int *, int *)
void Cblacs_gridexit(int)
int * lens
unpadded tensor edge lengths
void svd(Matrix< dtype > &U, Vector< dtype > &S, Matrix< dtype > &VT, int rank=0)
int main(int argc, char **argv)
void hosvd(Tensor<> &T, Tensor<> &core, std::vector< Matrix<> > factor_matrices, int *ranks, World &dw)
void print(FILE *fp, dtype cutoff) const
prints tensor data to file using process 0 (modify print(...) overload in set.h if you would like a d...
Tensor< dtype > get_core_tensor(Tensor< dtype > &T, std::vector< Matrix< dtype > > factor_matrices, int *ranks)
void Cblacs_gridmap(int *, int *, int, int, int)
def transpose(init_A, axes=None)
void Cblacs_barrier(int, char *)
std::vector< Matrix< dtype > > get_factor_matrices(Tensor< dtype > &T, int *ranks)
Tensor get_core_tensor_hooi(Tensor<> &T, std::vector< Matrix<> > factor_matrices, int ranks[], World &dw, int j=-1)
an instance of a tensor within a CTF world
void hooi(Tensor<> &T, Tensor<> &core, std::vector< Matrix<> > factor_matrices, int *ranks, World &dw)
void fold_unfold(Tensor< dtype > &X, Tensor< dtype > &Y)
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...
void Cblacs_pinfo(int *, int *)