-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTensor.h
165 lines (99 loc) · 4.25 KB
/
Tensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef TENSOR_H
#define TENSOR_H
#include <armadillo>
#include <vector>
#include <string>
#include "setting.h"
namespace TNSCat{
class Tensor{
public:
Tensor();
Tensor(const Tensor&);
Tensor(arma::uvec size, arma::uword rank);
~Tensor();
// Random tensor
void randu(const arma::uvec& sizei);
void randu(const std::vector<arma::uword>& sizei);
void randn(const std::vector<arma::uword>& sizei);
// zeros
void zeros();
// MPO--Heisenberg model
void edge_i_mpo();
void edge_f_mpo();
void mpo();
void sp();
void sm();
void sz();
//------------------------------------------
// IO
//-----------------------------------------
void print(std::string)const;
void print()const;
//-------------------------------------------
// Tensor operations
//-------------------------------------------
void reset(const std::vector<arma::uword>& sizei);
void reset(const arma::mat& datai, const arma::uvec& sizei);
void reset(const arma::mat& datai, const std::vector<arma::uword>& sizei);
void reset(const arma::mat& datai);
void sum_ind(arma::uword i_ind);
Tensor& operator+=(const Tensor&);
Tensor& operator=(const Tensor&);
void reshape(const arma::uvec& new_size);
void reshape(const std::vector<arma::uword>& new_size);
void tensor_reshape(const std::vector<arma::uvec>& new_inds, const arma::uword* full_oldind, const arma::uword* full_newind);
void permute(const std::vector<arma::uword>& permutation);
void permute(const arma::uword* permutation);
void tensor_permute(const arma::uword* oldorder, const arma::uword* neworder);
Tensor& tensor_product(const std::vector<arma::uword>& final_order, const arma::uword& num_con_inds, const Tensor& T1_,
const std::vector<arma::uword>& order1, const std::vector<arma::uword>& forder1, const Tensor& T2_,
const std::vector<arma::uword>& order2, const std::vector<arma::uword>& forder2);
Tensor& tensor_product(const arma::uword& num_con_inds, const Tensor& T1_,
const std::vector<arma::uword>& order1, const std::vector<arma::uword>& forder1, const Tensor& T2_,
const std::vector<arma::uword>& order2, const std::vector<arma::uword>& forder2);
Tensor& tensor_product(const arma::uword* final_order, const arma::uword& num_con_inds, const Tensor& T1_,
const arma::uword* order1, const arma::uword* forder1, const Tensor& T2_, const arma::uword* order2, const arma::uword* forder2);
Tensor& tensor_product(const arma::uword& num_con_inds, const Tensor& T1_, const arma::uword* order1,
const arma::uword* forder1, const Tensor& T2_, const arma::uword* order2, const arma::uword* forder2);
Tensor& double_tensor(const Tensor& T1, const Tensor& T2);
Tensor& double_tensor(const Tensor& T1, const Tensor& o, const Tensor& T2);
Tensor& tri_tensor(const Tensor& T1, const Tensor& o, const std::vector<arma::uword>& oinds, const Tensor& T2);
Tensor& bi_par(bool& if_mpo, const arma::uvec& size0);
//-----------------------------------------
// Friend/Standalone functions
//-----------------------------------------
friend double dot(const Tensor& T1, const Tensor& T2);
friend double delta(const Tensor& T1, const Tensor& T2);
//-----------------------------------------
// Tensor element access
//-----------------------------------------
double& operator()(const std::vector<arma::uword>& inds);
double& operator()(arma::uword iele);
double& at(const arma::uvec& inds);
double& at(const std::vector<arma::uword>& inds);
double& at(const arma::uword *inds);
double& at(arma::uword iele);
const double& c_at(const arma::uvec& inds)const;
const double& c_at(const std::vector<arma::uword>& inds)const;
const double& c_at(const arma::uword *inds)const;
const double& c_at(arma::uword iele)const;
const arma::mat& c_data()const;
arma::mat& data();
const arma::uvec& size()const;
arma::uword size(arma::uword i_ind)const;
double max_abs()const;
//------------------------------------------------
// Attributes:
//-----------------------------------------------
const arma::uword ndims = 0;
const arma::uword n_elem = 0;
arma::uvec accu_size_;
private:
// Attributes:
arma::mat ele_;
arma::uvec size_;
void set_accusize();
};
double dot(const Tensor& T1, const Tensor& T2);
}
#endif