46 #ifndef _NUMTNS_DECL_HPP_
47 #define _NUMTNS_DECL_HPP_
83 if(
m_>0 &&
n_>0 &&
p_>0) {
data_ =
new F[
m_*
n_*
p_];
if(
data_ == NULL )
throw std::runtime_error(
"Cannot allocate memory."); }
else data_=NULL;
87 if(
m_>0 &&
n_>0 &&
p_>0) {
data_ =
new F[
m_*
n_*
p_];
if(
data_ == NULL )
throw std::runtime_error(
"Cannot allocate memory."); }
else data_=NULL;
95 if(
m_>0 &&
n_>0 &&
p_>0) {
data_ =
new F[
m_*
n_*
p_];
if(
data_ == NULL )
throw std::runtime_error(
"Cannot allocate memory."); }
else data_=NULL;
106 NumTns& operator=(
const NumTns& C) {
112 if(
m_>0 &&
n_>0 &&
p_>0) {
data_ =
new F[
m_*
n_*
p_];
if(
data_ == NULL )
throw std::runtime_error(
"Cannot allocate memory."); }
else data_=NULL;
113 if(
m_>0 &&
n_>0 &&
p_>0) {
for(Int i=0; i<
m_*
n_*
p_; i++)
data_[i] = C.data_[i]; }
119 void Resize(Int m, Int n, Int p) {
121 throw std::logic_error(
"Tensor being resized must own data.");
123 if(
m_!=m ||
n_!=n ||
p_!=p) {
126 if(
m_>0 &&
n_>0 &&
p_>0) {
data_ =
new F[
m_*
n_*
p_];
if(
data_ == NULL )
throw std::runtime_error(
"Cannot allocate memory."); }
else data_=NULL;
129 const F& operator()(Int i, Int j, Int k)
const {
130 if( i < 0 || i >=
m_ ||
133 throw std::logic_error(
"Index is out of bound." );
137 F& operator()(Int i, Int j, Int k) {
138 if( i < 0 || i >=
m_ ||
141 throw std::logic_error(
"Index is out of bound." );
148 F* Data()
const {
return data_; }
150 F* MatData (Int j)
const {
151 if( j < 0 || j >=
p_ ) {
152 throw std::logic_error(
"Index is out of bound." );
157 F* VecData (Int j, Int k)
const {
158 if( j < 0 || j >=
n_ ||
160 throw std::logic_error(
"Index is out of bound." );
166 Int m()
const {
return m_; }
167 Int n()
const {
return n_; }
168 Int p()
const {
return p_; }
173 typedef NumTns<bool> BolNumTns;
174 typedef NumTns<Int> IntNumTns;
175 typedef NumTns<Real> DblNumTns;
176 typedef NumTns<Complex> CpxNumTns;
182 template <
class F>
inline void SetValue(NumTns<F>& T, F val);
185 template <
class F>
inline Real
Energy(
const NumTns<F>& T);
189 #endif // _NUMTNS_DECL_HPP_
Int n_
The size of second dimension.
Definition: numtns_decl.hpp:71
Int m_
The size of the first dimension.
Definition: numtns_decl.hpp:68
Real Energy(const NumMat< F > &M)
Energy computes the L2 norm of a matrix (treated as a vector).
Definition: nummat_impl.hpp:70
bool owndata_
Whether it owns the data.
Definition: numtns_decl.hpp:77
void SetValue(NumMat< F > &M, F val)
SetValue sets a numerical matrix to a constant val.
Definition: nummat_impl.hpp:61
Numerical tensor.
Definition: numtns_decl.hpp:64
Implementation of numerical matrix.
F * data_
The pointer for the actual data.
Definition: numtns_decl.hpp:80
Int p_
The size of third dimension.
Definition: numtns_decl.hpp:74