32 #ifndef MADNESS_TENSOR_TENSOR_H__INCLUDED
33 #define MADNESS_TENSOR_TENSOR_H__INCLUDED
64 #ifdef ENABLE_GENTENSOR
65 #define HAVE_GENTENSOR 1
67 #define HAVE_GENTENSOR 0
215 #ifndef HAVE_STD_ABS_LONG
216 #ifndef HAVE_STD_LABS
219 return a>=0 ?
a : -
a;
224 static long abs(
long a) {
233 #define IS_ODD(n) ((n)&0x1)
234 #define IS_UNALIGNED(p) (((unsigned long)(p))&0x7)
238 template <
typename Q,
bool iscomplex>
246 template <
typename Q>
254 template <
typename Q>
263 template <
typename T=
int>
double mynorm(
int t) {
264 return double(t)*double(t);
267 template <
typename T>
T mynorm(std::complex<T> t) {
272 template <
class T>
class SliceTensor;
277 #ifdef TENSOR_USE_SHARED_ALIGNED_ARRAY
278 #define TENSOR_SHARED_PTR detail::SharedAlignedArray
287 template <
typename T>
class SharedAlignedArray {
290 void dec() {
if (
p && ((*cnt)-- == 1)) {free(
p);
p = 0;}}
291 void inc() {
if (
p) (*cnt)++;}
293 SharedAlignedArray() :
p(0), cnt(0) {}
294 T* allocate(std::size_t size,
unsigned int alignment) {
295 std::size_t
offset = (size*
sizeof(
T)-1)/
sizeof(AtomicInt) + 1;
296 std::size_t nbyte = (
offset+1)*
sizeof(AtomicInt);
298 cnt = (AtomicInt*)(
p) +
offset;
302 SharedAlignedArray<T>& operator=(
const SharedAlignedArray<T>& other) {
303 if (
this != &other) {dec();
p = other.p; cnt = other.cnt; inc();}
306 void reset() {dec();
p = 0;}
307 ~SharedAlignedArray() {dec();}
311 #define TENSOR_SHARED_PTR std::shared_ptr
336 for (
int i=0; i<nd; ++i) {
337 TENSOR_ASSERT(
d[i]>=0 &&
d[i]<268435456,
"invalid dimension size in new tensor",
d[i],0);
344 #define TENSOR_ALIGNMENT 16
346 #define TENSOR_ALIGNMENT 32
347 #elif MADNESS_HAVE_AVX2
350 #define TENSOR_ALIGNMENT 32
351 #elif MADNESS_HAVE_AVX512
353 #define TENSOR_ALIGNMENT 64
356 #define TENSOR_ALIGNMENT 64
359 #ifdef TENSOR_USE_SHARED_ALIGNED_ARRAY
361 #elif defined WORLD_GATHER_MEM_STATS
373 std::printf(
"new failed nd=%ld type=%ld size=%ld\n", nd,
id(),
_size);
374 std::printf(
" %ld %ld %ld %ld %ld %ld\n",
375 d[0],
d[1],
d[2],
d[3],
d[4],
d[5]);
384 memset((
void *)
_p, 0,
_size*
sizeof(
T));
491 explicit Tensor(
long d0,
long d1,
long d2) :
_p(0) {
502 explicit Tensor(
long d0,
long d1,
long d2,
long d3) :
_p(0) {
514 explicit Tensor(
long d0,
long d1,
long d2,
long d3,
long d4) :
_p(0) {
527 explicit Tensor(
long d0,
long d1,
long d2,
long d3,
long d4,
long d5) {
536 explicit Tensor(
const std::vector<long>&
d,
bool dozero=
true) :
_p(0) {
537 allocate(
d.size(),
d.size() ? &(
d[0]) : 0, dozero);
545 explicit Tensor(
long nd,
const long d[],
bool dozero=
true) :
_p(0) {
571 template <
typename Q>
581 template <
typename Q>
591 template <
typename Q>
603 template <
typename Q>
615 template <
typename Q>
628 template <
typename Q>
641 template <
typename Q>
654 template <
typename Q>
657 return (*
this) + (-x);
673 template <
typename Q>
684 template <
typename Q>
694 template <
typename Q>
705 template <
typename Q>
726 madness::RandomVector<T>(
size(),
ptr());
769 #ifdef TENSOR_BOUNDS_CHECKING
781 #ifdef TENSOR_BOUNDS_CHECKING
792 #ifdef TENSOR_BOUNDS_CHECKING
803 #ifdef TENSOR_BOUNDS_CHECKING
814 #ifdef TENSOR_BOUNDS_CHECKING
826 #ifdef TENSOR_BOUNDS_CHECKING
839 #ifdef TENSOR_BOUNDS_CHECKING
853 #ifdef TENSOR_BOUNDS_CHECKING
868 #ifdef TENSOR_BOUNDS_CHECKING
884 #ifdef TENSOR_BOUNDS_CHECKING
902 #ifdef TENSOR_BOUNDS_CHECKING
921 #ifdef TENSOR_BOUNDS_CHECKING
941 #ifdef TENSOR_BOUNDS_CHECKING
962 #ifdef TENSOR_BOUNDS_CHECKING
984 #ifdef TENSOR_BOUNDS_CHECKING
1004 #ifdef TENSOR_BOUNDS_CHECKING
1005 TENSOR_ASSERT(i>=0 && i<
_dim[0],
"non-PC general indexing bounds check failed dim=",
d,
this);
1020 #ifdef TENSOR_BOUNDS_CHECKING
1021 TENSOR_ASSERT(i>=0 && i<
_dim[0],
"non-PC general indexing bounds check failed dim=",
d,
this);
1033 TENSOR_ASSERT(ind.size()>=(
unsigned int)
_ndim,
"invalid number of dimensions",ind.size(),
this);
1047 TENSOR_ASSERT(ind.size()>=(
unsigned int)
_ndim,
"invalid number of dimensions",ind.size(),
this);
1061 TENSOR_ASSERT(s.size()>=(
unsigned)(this->ndim()),
"invalid number of dimensions",
1071 TENSOR_ASSERT(s.size()>=(
unsigned)(this->ndim()),
"invalid number of dimensions",
1327 const Slice& s3)
const {
1341 Slice s[5] = {
s0,s1,s2,s3,s4};
1352 Slice s[5] = {
s0,s1,s2,s3,s4};
1363 Slice s[6] = {
s0,s1,s2,s3,s4,s5};
1375 Slice s[6] = {
s0,s1,s2,s3,s4,s5};
1406 return reshape(
d.size(),
d.size() ? &
d[0] : 0);
1414 return reshape(
d.size(),
d.size() ? &
d[0] : 0);
1440 long d[2] = {dim0,dim1};
1450 long d[2] = {dim0,dim1};
1461 long d[3] = {dim0,dim1,dim2};
1472 long d[3] = {dim0,dim1,dim2};
1484 long d[4] = {dim0,dim1,dim2,dim3};
1496 long d[4] = {dim0,dim1,dim2,dim3};
1509 long d[5] = {dim0,dim1,dim2,dim3,dim4};
1522 long d[5] = {dim0,dim1,dim2,dim3,dim4};
1536 long d[6] = {dim0,dim1,dim2,dim3,dim4,dim5};
1549 const Tensor<T> reshape(
long dim0,
long dim1,
long dim2,
long dim3,
long dim4,
long dim5)
const {
1550 long d[6] = {dim0,dim1,dim2,dim3,dim4,dim5};
1684 T result = *(this->
_p);
1686 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1689 if (result > *_p0) {
1691 for (
long i=0; i<nd; ++i) ind[i]=iter.ind[i];
1704 T result = *(this->
_p);
1706 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1709 if (result < *_p0) {
1711 for (
long i=0; i<nd; ++i) ind[i]=iter.ind[i];
1736 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1740 if (result > absval) {
1742 for (
long i=0; i<nd; ++i) ind[i]=iter.ind[i];
1757 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1761 if (result < absval) {
1763 for (
long i=0; i<nd; ++i) ind[i]=iter.ind[i];
1791 template <
typename opT>
1806 T* MADNESS_RESTRICT
a =
ptr();
1807 const T* MADNESS_RESTRICT
b = t.
ptr();
1849 iterlevel, optimize,
fusedim, jdim);
1860 iterlevel, optimize,
fusedim, jdim);
1864 template <
class Q,
class R>
1872 iterlevel, optimize,
fusedim, jdim);
1891 std::ostream&
operator << (std::ostream& out,
const Tensor<T>& t);
1896 template <
class Archive,
typename T>
1911 template <
class Archive,
typename T>
1914 long sz = 0l,
id = 0l;
1916 if (
id != t.
id())
throw "type mismatch deserializing a tensor";
1921 if (sz != t.
size())
throw "size mismatch deserializing a tensor";
1935 template <
typename T,
typename Q>
1936 typename IsSupported < TensorTypeData<Q>, Tensor<T> >
::type
1944 template <
typename T,
typename Q>
1945 typename IsSupported < TensorTypeData<Q>, Tensor<T> >
::type
1953 template <
typename T,
typename Q>
1954 typename IsSupported < TensorTypeData<Q>, Tensor<T> >
::type
1978 template <
class Q,
class T>
2001 template <
class T,
class Q>
2058 long nd = 0,
size=1;
2059 for (
long i=0; i<t.
_ndim; ++i) {
2060 long start=s[i].start,
end=s[i].end, step=s[i].step;
2063 if (start < 0) start += this->
_dim[i];
2065 long len =
end-start+1;
2066 if (step) len /= step;
2070 end = start + (len-1)*step;
2075 TENSOR_ASSERT(start>=0 && start<this->
_dim[i],
"slice start invalid",start,
this);
2077 TENSOR_ASSERT(len>0,
"slice length must be non-zero",len,
this);
2083 this->
_dim[nd] = len;
2143 if (t.
size() == 0) {
2144 s <<
"[empty tensor]\n";
2149 long index_width = 0;
2150 for (
int i = 0; i<(t.
ndim()-1); ++i) {
2151 if (maxdim < t.
dim(i)) maxdim = t.
dim(i);
2155 else if (maxdim < 100)
2157 else if (maxdim < 1000)
2159 else if (maxdim < 10000)
2164 std::ios::fmtflags oldflags = s.setf(std::ios::scientific);
2165 long oldprec = s.precision();
2166 long oldwidth = s.width();
2170 const T*
p = iter._p0;
2171 long inc = iter._s0;
2172 long dimj = iter.dimj;
2173 s.unsetf(std::ios::scientific);
2175 for (
long i=0; i<iter.ndim; ++i) {
2176 s.width(index_width);
2183 s.setf(std::ios::fixed);
2184 for (
long j=0; j<dimj; ++j,
p+=inc) {
2191 s.unsetf(std::ios::scientific);
2194 s.setf(oldflags,std::ios::floatfield);
2195 s.precision(oldprec);
2207 long nd = left.
ndim() + right.
ndim();
2211 for (
long i = 0; i < left.
ndim(); ++i)
d[i] = left.
dim(i);
2212 for (
long i = 0; i < right.
ndim(); ++i)
d[i + left.
ndim()] = right.
dim(i);
2225 T *ptr = result.
ptr();
2230 for (iter.
reset(); iter.
_p0; ++iter) {
2231 long dimj = iter.
dimj;
2233 long Tstride = iter.
_s0;
2234 for (
long _j=0; _j<dimj; ++_j, _p0+=Tstride) {
2235 *ptr++ = val1 * (*_p0);
2250 template <
class T,
class Q>
2252 long k0=-1,
long k1=0) {
2255 long nd = left.
ndim() + right.
ndim() - 2;
2256 TENSOR_ASSERT(nd!=0,
"result is a scalar but cannot return one ... use dot",
2261 right.
dim(
k1), &left);
2264 "invalid number of dimensions in the result", nd,0);
2269 for (
long i=0; i<
k0; ++i)
d[i] = left.
dim(i);
2270 for (
long i=
k0+1; i<left.
ndim(); ++i)
d[i-1] = left.
dim(i);
2271 base = left.
ndim()-1;
2272 for (
long i=0; i<
k1; ++i)
d[i+base] = right.
dim(i);
2274 for (
long i=
k1+1; i<right.
ndim(); ++i)
d[i+base] = right.
dim(i);
2294 template <
class T,
class Q>
2302 resultT* ptr = result.ptr();
2308 if (
k0==0 &&
k1==0) {
2310 long dimk = left.
dim(
k0);
2311 long dimj = right.
stride(0);
2312 long dimi = left.
stride(0);
2313 mTxm(dimi,dimj,dimk,ptr,left.
ptr(),right.
ptr());
2316 else if (
k0==(left.
ndim()-1) &&
k1==(right.
ndim()-1)) {
2318 long dimk = left.
dim(
k0);
2319 long dimi = left.
size()/dimk;
2320 long dimj = right.
size()/dimk;
2321 mxmT(dimi,dimj,dimk,ptr,left.
ptr(),right.
ptr());
2324 else if (
k0==0 &&
k1==(right.
ndim()-1)) {
2326 long dimk = left.
dim(
k0);
2327 long dimi = left.
stride(0);
2328 long dimj = right.
size()/dimk;
2332 else if (
k0==(left.
ndim()-1) &&
k1==0) {
2334 long dimk = left.
dim(
k0);
2335 long dimi = left.
size()/dimk;
2336 long dimj = right.
stride(0);
2337 mxm(dimi,dimj,dimk,ptr,left.
ptr(),right.
ptr());
2342 long dimj = left.
dim(
k0);
2346 iter0._p0; ++iter0) {
2347 T* MADNESS_RESTRICT xp0 = iter0._p0;
2348 long s0 = iter0._s0;
2349 for (iter1.
reset(); iter1.
_p0; ++iter1) {
2350 T* MADNESS_RESTRICT p0 = xp0;
2351 Q* MADNESS_RESTRICT p1 = iter1.
_p0;
2352 long s1 = iter1.
_s0;
2354 for (
long j=0; j<dimj; ++j,p0+=
s0,p1+=s1) {
2355 sum += (*p0) * (*p1);
2376 template <
class T,
class Q>
2379 TENSOR_ASSERT(
c.ndim() == 2,
"second argument must be a matrix",
c.ndim(),&
c);
2387 for (
long i=0; i<t.
ndim(); ++i) {
2388 result =
inner(result,
c,0,0);
2404 template <
class T,
class Q>
2408 for (
long i=0; i<t.
ndim(); ++i) {
2409 result =
inner(result,
c[i],0,0);
2442 template <
class T,
class Q>
2446 const Q *pc=
c.ptr();
2447 resultT *t0=workspace.ptr(), *t1=result.ptr();
2450 t1 = workspace.ptr();
2453 long dimj =
c.dim(1);
2455 for (
int n=1; n<t.
ndim(); ++n) dimi *= dimj;
2458 long nij = dimi*dimj;
2460 for (
long i=0; i<nij; ++i) t0[i] = 0.0;
2461 mTxm(dimi, dimj, dimj, t0, t.
ptr(), pc);
2462 for (
int n=1; n<t.
ndim(); ++n) {
2463 for (
long i=0; i<nij; ++i) t1[i] = 0.0;
2464 mTxm(dimi, dimj, dimj, t1, t0, pc);
2470 for (
int n=1; n<t.
ndim(); ++n) {
2477 mTxmq(dimi, dimj, dimj, t0, t.
ptr(), pc);
2478 for (
int n=1; n<t.
ndim(); ++n) {
2479 mTxmq(dimi, dimj, dimj, t1, t0, pc);
2542 #undef TENSOR_SHARED_PTR
double q(double t)
Definition: DKops.h:18
Provides routines for internal use optimized for aligned data.
Interface templates for the archives (serialization).
std::complex< double > double_complex
Definition: cfft.h:14
The base class for tensors defines generic capabilities.
Definition: basetensor.h:85
bool conforms(const BaseTensor *t) const
Returns true if this and *t are the same shape and size.
Definition: basetensor.h:159
long dim(int i) const
Returns the size of dimension i.
Definition: basetensor.h:147
bool iscontiguous() const
Returns true if the tensor refers to contiguous memory locations.
Definition: basetensor.h:168
void mapdim_inplace(const std::vector< long > &map)
General permutation of dimensions.
Definition: basetensor.cc:156
long _stride[TENSOR_MAXDIM]
Increment between elements in each dimension.
Definition: basetensor.h:97
long stride(int i) const
Returns the stride associated with dimension i.
Definition: basetensor.h:150
long _size
Number of elements in the tensor.
Definition: basetensor.h:93
long id() const
Returns the typeid of the tensor (c.f., TensorTypeData<T> )
Definition: basetensor.h:141
void set_dims_and_size(long nd, const long d[])
Definition: basetensor.h:99
long _id
Id from TensorTypeData<T> in type_data.h.
Definition: basetensor.h:95
const long * dims() const
Returns the array of tensor dimensions.
Definition: basetensor.h:153
void splitdim_inplace(long i, long dimi0, long dimi1)
Splits dimension i.
Definition: basetensor.cc:88
void swapdim_inplace(long i, long j)
Swaps the dimensions.
Definition: basetensor.cc:124
void fusedim_inplace(long i)
Fuses dimensions i and i+1.
Definition: basetensor.cc:107
long _dim[TENSOR_MAXDIM]
Size of each dimension.
Definition: basetensor.h:96
long ndim() const
Returns the number of dimensions in the tensor.
Definition: basetensor.h:144
long size() const
Returns the number of elements in the tensor.
Definition: basetensor.h:138
void cycledim_inplace(long shift, long start, long end)
Cyclic shift of dimensions.
Definition: basetensor.cc:134
long _ndim
Number of dimensions (-1=invalid; 0=no supported; >0=tensor)
Definition: basetensor.h:94
void reshape_inplace(const std::vector< long > &d)
Reshapes the tensor inplace.
Definition: basetensor.cc:76
Indexing a non-constant tensor with slices returns a SliceTensor.
Definition: tensor.h:2041
virtual ~SliceTensor()
Definition: tensor.h:2126
SliceTensor(const Tensor< T > &t, const Slice s[])
Definition: tensor.h:2052
SliceTensor< T > & operator=(const SliceTensor< Q > &t)
Definition: tensor.h:2105
SliceTensor< T > & operator=(const Tensor< T > &t)
Definition: tensor.h:2110
SliceTensor< T > & operator=(const T &t)
Definition: tensor.h:2121
SliceTensor(const Tensor< T > &t, const std::array< Slice, TENSOR_MAXDIM > s)
Definition: tensor.h:2048
SliceTensor< T > & operator=(const Tensor< Q > &t)
Definition: tensor.h:2116
SliceTensor< T > & operator=(const SliceTensor< T > &t)
Definition: tensor.h:2099
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
Definition: tensoriter.h:61
long dimj
Definition: tensoriter.h:70
long _s0
Definition: tensoriter.h:71
void reset()
Reset the iterator back to the start ...
Definition: tensoriter.h:354
T * _p0
Definition: tensoriter.h:66
Traits class to specify support of numeric types.
Definition: type_data.h:56
A tensor is a multidimension array.
Definition: tensor.h:317
scalar_type absmax(long *ind=0) const
Return the absolute maximum value (and if ind is non-null, its index) in the Tensor.
Definition: tensor.h:1754
Tensor< T > reshape(const std::vector< long > &d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition: tensor.h:1405
const T & operator()(long i, long j, long k, long l) const
4-d indexing operation without bounds checking.
Definition: tensor.h:901
T & operator()(const std::vector< long > ind)
General indexing operation with bounds checking.
Definition: tensor.h:1032
void deallocate()
Definition: tensor.h:397
const Tensor< T > operator()(const Slice &s0) const
Return a 1d SliceTensor that views the specified range of the 1d Tensor.
Definition: tensor.h:1105
T *MADNESS_RESTRICT _p
Definition: tensor.h:321
const Tensor< T > reshape(long dim0, long dim1, long dim2) const
Returns new view/tensor rehaping to conforming 3-d tensor with given dimensions.
Definition: tensor.h:1471
Tensor< T > reshape(long dim0, long dim1, long dim2)
Returns new view/tensor rehaping to conforming 3-d tensor with given dimensions.
Definition: tensor.h:1460
Tensor(const std::vector< long > &d, bool dozero=true)
Create and optionally zero new n-d tensor. This is the most general constructor.
Definition: tensor.h:536
T * ptr()
Returns a pointer to the internal data.
Definition: tensor.h:1824
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition: tensor.h:1726
IsSupported< TensorTypeData< Q >, Tensor< TENSOR_RESULT_TYPE(T, Q)> >::type operator*(const Q &x) const
Multiplication of tensor by a scalar of a supported type to produce a new tensor.
Definition: tensor.h:617
Tensor(long d0, long d1)
Create and zero new 2-d tensor.
Definition: tensor.h:481
SliceTensor< T > operator()(long i, const Slice &s1, const Slice &s2)
Return a 2d SliceTensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1195
Tensor< T > fusedim(long i)
Returns new view/tensor fusing contiguous dimensions i and i+1.
Definition: tensor.h:1587
Tensor< TENSOR_RESULT_TYPE(T, Q) > operator+(const Tensor< Q > &t) const
Addition of two tensors to produce a new tensor.
Definition: tensor.h:592
const T & operator()(const long ind[]) const
Politically incorrect general indexing operation without bounds checking.
Definition: tensor.h:1016
IsSupported< TensorTypeData< Q >, Tensor< TENSOR_RESULT_TYPE(T, Q)> >::type operator/(const Q &x) const
Divide tensor by a scalar of a supported type to produce a new tensor.
Definition: tensor.h:630
scalar_type absmin(long *ind=0) const
Return the absolute minimum value (and if ind is non-null, its index) in the Tensor.
Definition: tensor.h:1733
const Tensor< T > fusedim(long i) const
Returns new view/tensor fusing contiguous dimensions i and i+1.
Definition: tensor.h:1596
SliceTensor< T > operator()(const std::array< Slice, TENSOR_MAXDIM > &s)
General slicing operation.
Definition: tensor.h:1080
const Tensor< T > swapdim(long idim, long jdim) const
Returns new view/tensor swaping dimensions i and j.
Definition: tensor.h:1614
const Tensor< T > mapdim(const std::vector< long > &map) const
Returns new view/tensor permuting the dimensions.
Definition: tensor.h:1633
Tensor< T > mapdim(const std::vector< long > &map)
Returns new view/tensor permuting the dimensions.
Definition: tensor.h:1624
Tensor< T > splitdim(long i, long dimi0, long dimi1)
Returns new view/tensor splitting dimension i as dimi0*dimi1 to produce conforming d+1 dimension tens...
Definition: tensor.h:1569
const Tensor< T > operator()(long i, const Slice &s1, long k) const
Return a 1d constant Tensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1285
T sum() const
Returns the sum of all elements of the tensor.
Definition: tensor.h:1662
const Tensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2) const
Return a 3d constant Tensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1185
SliceTensor< T > operator()(const Slice &s0, long j, long k)
Return a 1d SliceTensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1295
BaseTensor * base()
Returns a pointer to the base class.
Definition: tensor.h:1834
TensorTypeData< T >::scalar_type scalar_type
C++ typename of the real type associated with a complex type.
Definition: tensor.h:409
Tensor(long d0, long d1, long d2, long d3, long d4, long d5)
Create and zero new 6-d tensor.
Definition: tensor.h:527
T type
C++ typename of this tensor.
Definition: tensor.h:406
SliceTensor< T > operator()(long i, const Slice &s1)
Return a 1d SliceTensor that views the specified range of the 2d Tensor.
Definition: tensor.h:1115
SliceTensor< T > operator()(const std::vector< Slice > &s)
General slicing operation.
Definition: tensor.h:1060
SliceTensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2, const Slice &s3, const Slice &s4, const Slice &s5)
Return a 1-6d SliceTensor that views the specified range of the 6d Tensor.
Definition: tensor.h:1359
SliceTensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2, const Slice &s3)
Return a 1-4d SliceTensor that views the specified range of the 4d Tensor.
Definition: tensor.h:1315
Tensor< T > reshape(long dim0, long dim1, long dim2, long dim3)
Returns new view/tensor rehaping to conforming 4-d tensor with given dimensions.
Definition: tensor.h:1483
bool conforms(const Tensor< Q > &t) const
Test if *this and t conform.
Definition: tensor.h:1657
const BaseTensor * base() const
Returns a pointer to the base class.
Definition: tensor.h:1839
Tensor< T > & fill(T x)
Inplace fill with a scalar (legacy name)
Definition: tensor.h:562
T & operator()(long i, long j)
2-d indexing operation without bounds checking.
Definition: tensor.h:825
TensorIterator< T, Q > binary_iterator(const Tensor< Q > &q, long iterlevel=0, bool optimize=true, bool fusedim=true, long jdim=default_jdim) const
Return iterator over two tensors.
Definition: tensor.h:1854
const Tensor< T > reshape(long dim0, long dim1, long dim2, long dim3, long dim4, long dim5) const
Returns new view/tensor rehaping to conforming 6-d tensor with given dimensions.
Definition: tensor.h:1549
IsSupported< TensorTypeData< Q >, Tensor< TENSOR_RESULT_TYPE(T, Q)> >::type operator+(const Q &x) const
Add a scalar of the same type to all elements of a tensor producing a new tensor.
Definition: tensor.h:643
const Tensor< T > operator()(const Slice &s0, long j, const Slice &s2) const
Return a 2d constant Tensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1225
const Tensor< T > operator()(const Slice &s0, long j) const
Return a 1d constant Tensor that views the specified range of the 2d Tensor.
Definition: tensor.h:1145
const Tensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2, const Slice &s3, const Slice &s4) const
Return a 1-5d constant Tensor that views the specified range of the 5d Tensor.
Definition: tensor.h:1348
Tensor< T > & operator=(const Tensor< T > &t)
Assignment is shallow (same as copy constructor)
Definition: tensor.h:443
const Tensor< T > operator()(const std::vector< Slice > &s) const
General slicing operation (const)
Definition: tensor.h:1070
Tensor< T > reshape(int ndimnew, const long *d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition: tensor.h:1384
SliceTensor< T > operator()(const Slice &s0, const Slice &s1, long k)
Return a 2d SliceTensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1235
Tensor< T > & gaxpy(T alpha, const Tensor< T > &t, T beta)
Inplace generalized saxpy ... this = this*alpha + other*beta.
Definition: tensor.h:1804
const T & operator()(long i, long j, long k, long l, long m) const
5-d indexing operation without bounds checking.
Definition: tensor.h:940
Tensor< T > flat()
Returns new view/tensor rehshaping to flat (1-d) tensor.
Definition: tensor.h:1555
TensorIterator< T > unary_iterator(long iterlevel=0, bool optimize=true, bool fusedim=true, long jdim=default_jdim) const
Return iterator over single tensor.
Definition: tensor.h:1844
TensorTypeData< T >::float_scalar_type float_scalar_type
C++ typename of the floating point type associated with scalar real type.
Definition: tensor.h:412
Tensor< T > & conj()
Inplace complex conjugate.
Definition: tensor.h:716
Tensor< T > & operator=(T x)
Inplace fill tensor with scalar.
Definition: tensor.h:553
Tensor(const Tensor< T > &t)
Copy constructor is shallow (same as assignment)
Definition: tensor.h:428
const Tensor< T > cycledim(long nshift, long start, long end) const
Returns new view/tensor cycling the sub-dimensions (start,...,end) with shift steps.
Definition: tensor.h:1649
SliceTensor< T > operator()(const Slice &s0, long j, const Slice &s2)
Return a 2d SliceTensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1215
const Tensor< T > operator()(const Slice &s0, const Slice &s1) const
Return a 2d constant Tensor that views the specified range of the 2d Tensor.
Definition: tensor.h:1165
Tensor< T > & operator+=(const Tensor< Q > &t)
Inplace addition of two tensors.
Definition: tensor.h:572
SliceTensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2)
Return a 3d SliceTensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1175
T trace(const Tensor< T > &t) const
Return the trace of two tensors (no complex conjugate invoked)
Definition: tensor.h:1776
T & operator()(const long ind[])
Politically incorrect general indexing operation without bounds checking.
Definition: tensor.h:1000
T & operator[](long i)
1-d indexing operation using [] without bounds checking.
Definition: tensor.h:780
Tensor< T > cycledim(long nshift, long start, long end)
Returns new view/tensor cycling the sub-dimensions (start,...,end) with shift steps.
Definition: tensor.h:1641
Tensor< T > & fillindex()
Inplace fill with the index of each element.
Definition: tensor.h:748
const Tensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2, const Slice &s3, const Slice &s4, const Slice &s5) const
Return a 1-6d constant Tensor that views the specified range of the 6d Tensor.
Definition: tensor.h:1371
const Tensor< T > operator()(const Slice &s0, const Slice &s1, long k) const
Return a 2d constant Tensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1245
T max(long *ind=0) const
Return the maximum value (and if ind is non-null, its index) in the Tensor.
Definition: tensor.h:1703
Tensor(long d0)
Create and zero new 1-d tensor.
Definition: tensor.h:472
T product() const
Return the product of all elements of the tensor.
Definition: tensor.h:1676
SliceTensor< T > operator()(long i, const Slice &s1, long k)
Return a 1d SliceTensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1275
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type operator*=(const Q &x)
Inplace multiplication by scalar of supported type.
Definition: tensor.h:675
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type operator+=(const Q &x)
Inplace increment by scalar of supported type.
Definition: tensor.h:696
const Tensor< T > reshape(long dim0, long dim1, long dim2, long dim3) const
Returns new view/tensor rehaping to conforming 4-d tensor with given dimensions.
Definition: tensor.h:1495
Tensor< T > & unaryop(opT &op)
Inplace apply a unary function to each element of the tensor.
Definition: tensor.h:1792
const Tensor< T > operator()(long i, const Slice &s1) const
Return a 1d SliceTensor that views the specified range of the 2d Tensor.
Definition: tensor.h:1125
T min(long *ind=0) const
Return the minimum value (and if ind is non-null, its index) in the Tensor.
Definition: tensor.h:1683
Tensor< T > operator-() const
Unary negation producing a new tensor.
Definition: tensor.h:663
Tensor< T > reshape(long dim0, long dim1)
Returns new view/tensor rehaping to conforming 2-d tensor with given dimensions.
Definition: tensor.h:1439
virtual ~Tensor()
Definition: tensor.h:1881
const Tensor< T > reshape(const std::vector< long > &d) const
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition: tensor.h:1413
void allocate(long nd, const long d[], bool dozero)
Definition: tensor.h:324
const Tensor< T > reshape(long dim0, long dim1, long dim2, long dim3, long dim4) const
Returns new view/tensor rehaping to conforming 5-d tensor with given dimensions.
Definition: tensor.h:1521
T sumsq() const
Returns the sum of the squares of the elements.
Definition: tensor.h:1669
const Tensor< T > flat() const
Returns new view/tensor rehshaping to flat (1-d) tensor.
Definition: tensor.h:1561
Tensor< T > & emul(const Tensor< T > &t)
Inplace multiply by corresponding elements of argument Tensor.
Definition: tensor.h:1798
const Tensor< T > reshape(long dim0, long dim1) const
Returns new view/tensor rehaping to conforming 2-d tensor with given dimensions.
Definition: tensor.h:1449
Tensor(long d0, long d1, long d2, long d3)
Create and zero new 4-d tensor.
Definition: tensor.h:502
Tensor(long d0, long d1, long d2)
Create and zero new 3-d tensor.
Definition: tensor.h:491
const T & operator[](long i) const
1-d indexing operation using [] without bounds checking.
Definition: tensor.h:791
Tensor< T > & operator-=(const Tensor< Q > &t)
Inplace subtraction of two tensors.
Definition: tensor.h:582
TensorIterator< T, Q, R > ternary_iterator(const Tensor< Q > &q, const Tensor< R > &r, long iterlevel=0, bool optimize=true, bool fusedim=true, long jdim=default_jdim) const
Return iterator over three tensors.
Definition: tensor.h:1865
const T & operator()(long i) const
1-d indexing operation without bounds checking.
Definition: tensor.h:813
const Tensor< T > operator()(const Slice &s0, long j, long k) const
Return a 1d constant Tensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1305
const T & operator()(long i, long j) const
2-d indexing operation without bounds checking.
Definition: tensor.h:838
bool has_data() const
Definition: tensor.h:1886
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type operator-=(const Q &x)
Inplace decrement by scalar of supported type.
Definition: tensor.h:707
T & operator()(long i, long j, long k)
3-d indexing operation without bounds checking.
Definition: tensor.h:852
const T & operator()(long i, long j, long k) const
3-d indexing operation without bounds checking.
Definition: tensor.h:867
Tensor< T > swapdim(long idim, long jdim)
Returns new view/tensor swaping dimensions i and j.
Definition: tensor.h:1605
IsSupported< TensorTypeData< Q >, Tensor< TENSOR_RESULT_TYPE(T, Q)> >::type operator-(const Q &x) const
Subtract a scalar of the same type from all elements producing a new tensor.
Definition: tensor.h:656
TENSOR_RESULT_TYPE(T, Q) trace_conj(const Tensor< Q > &t) const
Return the trace of two tensors with complex conjugate of the leftmost (i.e., this)
Definition: tensor.h:1784
Tensor< T > reshape(long dim0, long dim1, long dim2, long dim3, long dim4)
Returns new view/tensor rehaping to conforming 5-d tensor with given dimensions.
Definition: tensor.h:1508
T & operator()(long i, long j, long k, long l, long m, long n)
6-d indexing operation without bounds checking.
Definition: tensor.h:961
SliceTensor< T > operator()(const Slice &s0, long j)
Return a 1d SliceTensor that views the specified range of the 2d Tensor.
Definition: tensor.h:1135
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type scale(Q x)
Inplace multiplication by scalar of supported type (legacy name)
Definition: tensor.h:686
const Tensor< T > splitdim(long i, long dimi0, long dimi1) const
Returns new view/tensor splitting dimension i as dimi0*dimi1 to produce conforming d+1 dimension tens...
Definition: tensor.h:1578
Tensor(long d0, long d1, long d2, long d3, long d4)
Create and zero new 5-d tensor.
Definition: tensor.h:514
const Tensor< T > operator()(long i, const Slice &s1, const Slice &s2) const
Return a 2d constant Tensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1205
Tensor()
Default constructor does not allocate any data and sets ndim=-1, size=0, _p=0, and id.
Definition: tensor.h:415
const TensorIterator< T > & end() const
End point for forward iteration.
Definition: tensor.h:1876
const T & operator()(const std::vector< long > ind) const
General indexing operation with bounds checking.
Definition: tensor.h:1046
T & operator()(long i, long j, long k, long l, long m)
5-d indexing operation without bounds checking.
Definition: tensor.h:920
const Tensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2, const Slice &s3) const
Return a 1-4d constant Tensor that views the specified range of the 4d Tensor.
Definition: tensor.h:1326
SliceTensor< T > operator()(const Slice &s0)
Return a 1d SliceTensor that views the specified range of the 1d Tensor.
Definition: tensor.h:1095
static bool bounds_checking()
Return true if bounds checking was enabled at compile time.
Definition: tensor.h:768
T & operator()(long i)
1-d indexing operation without bounds checking.
Definition: tensor.h:802
void clear()
Frees all memory and resests to state of default constructor.
Definition: tensor.h:1884
T & operator()(long i, long j, long k, long l)
4-d indexing operation without bounds checking.
Definition: tensor.h:883
const T * ptr() const
Returns a pointer to the internal data.
Definition: tensor.h:1829
TENSOR_SHARED_PTR< T > _shptr
Definition: tensor.h:322
const Tensor< T > operator()(const std::array< Slice, TENSOR_MAXDIM > &s) const
General slicing operation (const)
Definition: tensor.h:1088
SliceTensor< T > operator()(long i, long j, const Slice &s2)
Return a 1d SliceTensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1255
const Tensor< T > operator()(long i, long j, const Slice &s2) const
Return a 1d constant Tensor that views the specified range of the 3d Tensor.
Definition: tensor.h:1265
Tensor(long nd, const long d[], bool dozero=true)
Politically incorrect general constructor.
Definition: tensor.h:545
Tensor< T > reshape(long dim0, long dim1, long dim2, long dim3, long dim4, long dim5)
Returns new view/tensor rehaping to conforming 6-d tensor with given dimensions.
Definition: tensor.h:1535
const Tensor< T > reshape(long dim0) const
Returns new view/tensor rehapings to conforming 1-d tensor with given dimension.
Definition: tensor.h:1429
Tensor< T > & fillrandom()
Inplace fill with random values ( [0,1] for floats, [0,MAXSIZE] for integers)
Definition: tensor.h:724
const T & operator()(long i, long j, long k, long l, long m, long n) const
6-d indexing operation without bounds checking.
Definition: tensor.h:983
SliceTensor< T > operator()(const Slice &s0, const Slice &s1, const Slice &s2, const Slice &s3, const Slice &s4)
Return a 1-5d SliceTensor that views the specified range of the 5d Tensor.
Definition: tensor.h:1337
Tensor< T > & screen(double x)
Inplace set elements of *this less than x in absolute magnitude to zero.
Definition: tensor.h:758
Tensor< T > reshape(long dim0)
Returns new view/tensor rehapings to conforming 1-d tensor with given dimension.
Definition: tensor.h:1421
Tensor< TENSOR_RESULT_TYPE(T, Q) > operator-(const Tensor< Q > &t) const
Subtraction of two tensors to produce a new tensor.
Definition: tensor.h:604
SliceTensor< T > operator()(const Slice &s0, const Slice &s1)
Return a 2d SliceTensor that views the specified range of the 2d Tensor.
Definition: tensor.h:1155
const Tensor< T > reshape(int ndimnew, const long *d) const
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition: tensor.h:1395
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition: derivatives.cc:72
const double m
Definition: gfit.cc:199
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
archive_array< T > wrap(const T *, unsigned int)
Factory function to wrap a dynamically allocated pointer as a typed archive_array.
Definition: archive.h:913
Tensor< T > conj_transpose(const Tensor< T > &t)
Returns a new deep copy of the complex conjugate transpose of the input tensor.
Definition: tensor.h:2027
Tensor< typename Tensor< T >::scalar_type > real(const Tensor< T > &t)
Return a new tensor holding the real part of each element of t (complex types only)
Definition: tensor.h:2513
Tensor< TENSOR_RESULT_TYPE(T, Q) > & fast_transform(const Tensor< T > &t, const Tensor< Q > &c, Tensor< TENSOR_RESULT_TYPE(T, Q) > &result, Tensor< TENSOR_RESULT_TYPE(T, Q) > &workspace)
Restricted but heavily optimized form of transform()
Definition: tensor.h:2443
void inner_result(const Tensor< T > &left, const Tensor< Q > &right, long k0, long k1, Tensor< TENSOR_RESULT_TYPE(T, Q) > &result)
Accumulate inner product into user provided, contiguous, correctly sized result tensor.
Definition: tensor.h:2295
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition: tensor.h:2502
Tensor< typename Tensor< T >::scalar_type > imag(const Tensor< T > &t)
Return a new tensor holding the imaginary part of each element of t (complex types only)
Definition: tensor.h:2524
const double beta
Definition: gygi_soltion.cc:62
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
Macros and tools pertaining to the configuration of MADNESS.
#define MADNESS_PRAGMA_GCC(x)
Definition: madness_config.h:205
double norm(const T &t)
Definition: adquad.h:42
T mynorm(T t)
Definition: tensor.h:260
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
std::vector< CCPairFunction< T, NDIM > > operator+(const std::vector< CCPairFunction< T, NDIM >> c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition: ccpairfunction.h:1047
double abs(double x)
Definition: complexfun.h:48
void mTxmT(long dimi, long dimj, long dimk, T *MADNESS_RESTRICT c, const T *a, const T *b)
Matrix += Matrix transpose * matrix transpose ... MKL interface version.
Definition: mxm.h:238
void outer_result(const Tensor< T > &left, const Tensor< T > &right, Tensor< T > &result)
Outer product ... result(i,j,...,p,q,...) = left(i,k,...)*right(p,q,...)
Definition: tensor.h:2222
Q conditional_conj(const Q &coeff)
For real types return value, for complex return conjugate.
Definition: tensor.h:255
GenTensor< TENSOR_RESULT_TYPE(R, Q)> general_transform(const GenTensor< R > &t, const Tensor< Q > c[])
Definition: gentensor.h:274
std::vector< CCPairFunction< T, NDIM > > operator-(const std::vector< CCPairFunction< T, NDIM >> c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition: ccpairfunction.h:1055
Function< T, NDIM > conj(const Function< T, NDIM > &f, bool fence=true)
Return the complex conjugate of the input function with the same distribution and optional fence.
Definition: mra.h:2046
void mxm(long dimi, long dimj, long dimk, T *MADNESS_RESTRICT c, const T *a, const T *b)
Matrix += Matrix * matrix ... BLAS/MKL interface version.
Definition: mxm.h:199
GenTensor< TENSOR_RESULT_TYPE(R, Q)> transform_dir(const GenTensor< R > &t, const Tensor< Q > &c, const int axis)
Definition: lowranktensor.h:1099
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition: mra.h:2002
void mTxm(long dimi, long dimj, long dimk, T *MADNESS_RESTRICT c, const T *a, const T *b)
Matrix += Matrix transpose * matrix ... MKL interface version.
Definition: mxm.h:212
Function< Q, NDIM > convert(const Function< T, NDIM > &f, bool fence=true)
Type conversion implies a deep copy. No communication except for optional fence.
Definition: mra.h:2032
response_space transpose(response_space &f)
Definition: basic_operators.cc:10
void mTxmq_padding(long dimi, long dimj, long dimk, long ext_b, cT *c, const aT *a, const bT *b)
Definition: mtxmq.h:96
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition: lowrankfunction.h:397
TENSOR_RESULT_TYPE(T, R) inner(const Function< T
Computes the scalar/inner product between two functions.
Definition: vmra.h:1059
static double pop(std::vector< double > &v)
Definition: SCF.cc:113
Function< T, NDIM > sum(World &world, const std::vector< Function< T, NDIM > > &f, bool fence=true)
Returns new function — q = sum_i f[i].
Definition: vmra.h:1421
static void aligned_zero(long n, T *a)
Definition: aligned.h:55
std::vector< CCPairFunction< T, NDIM > > operator*(const double fac, const std::vector< CCPairFunction< T, NDIM > > &arg)
Definition: ccpairfunction.h:1084
double inner(response_space &a, response_space &b)
Definition: response_functions.h:442
double imag(double x)
Definition: complexfun.h:56
std::string type(const PairType &n)
Definition: PNOParameters.h:18
static const long default_jdim
Definition: tensoriter.h:57
double real(double x)
Definition: complexfun.h:52
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition: vmra.h:689
void mxmT(long dimi, long dimj, long dimk, T *MADNESS_RESTRICT c, const T *a, const T *b)
Matrix += Matrix * matrix transpose ... MKL interface version.
Definition: mxm.h:225
std::enable_if< std::is_base_of< ProjectorBase, projT >::value, OuterProjector< projT, projQ > >::type outer(const projT &p0, const projQ &p1)
Definition: projector.h:457
void swap(Vector< T, N > &l, Vector< T, N > &r)
Swap the contents of two Vectors.
Definition: vector.h:497
void mTxmq(long dimi, long dimj, long dimk, T *MADNESS_RESTRICT c, const T *a, const T *b, long ldb=-1)
Matrix = Matrix transpose * matrix ... MKL interface version.
Definition: mxm.h:257
static long abs(long a)
Definition: tensor.h:218
static const double b
Definition: nonlinschro.cc:119
static const double a
Definition: nonlinschro.cc:118
Implement dummy posix_memalign if it is missing on the system.
int posix_memalign(void **memptr, std::size_t alignment, std::size_t size)
Definition: posixmem.h:44
std::complex< float > float_complex
Definition: ran.h:39
double Q(double a)
Definition: relops.cc:20
static const double c
Definition: relops.cc:10
static const long k
Definition: rk.cc:44
Definition: test_ccpairfunction.cc:22
Definition: type_data.h:146
static void load(const Archive &s, Tensor< T > &t)
Definition: tensor.h:1913
Default load of an object via serialize(ar, t).
Definition: archive.h:666
static void store(const Archive &s, const Tensor< T > &t)
Definition: tensor.h:1898
Default store of an object via serialize(ar, t).
Definition: archive.h:611
static Q op(const Q &coeff)
Definition: tensor.h:248
For real types return value, for complex return conjugate.
Definition: tensor.h:239
static Q op(const Q &coeff)
Definition: tensor.h:240
static const double s0
Definition: tdse4.cc:83
#define IS_UNALIGNED(p)
Definition: tensor.h:234
#define UNARY_UNOPTIMIZED_ITERATOR(X, x, exp)
Definition: tensor_macros.h:678
#define BINARY_OPTIMIZED_ITERATOR(X, x, Y, y, exp)
Definition: tensor_macros.h:701
#define UNARY_OPTIMIZED_ITERATOR(X, x, exp)
Definition: tensor_macros.h:658
#define TERNARY_OPTIMIZED_ITERATOR(X, x, Y, y, Z, z, exp)
Definition: tensor_macros.h:719
#define TENSOR_MAXDIM
Definition: tensor_macros.h:194
Declares and implements TensorException.
#define TENSOR_ASSERT(condition, msg, value, t)
Definition: tensorexcept.h:130
#define TENSOR_EXCEPTION(msg, value, t)
Definition: tensorexcept.h:126
const double alpha
Definition: test_coulomb.cc:54
void d()
Definition: test_sig.cc:79
const double offset
Definition: testfuns.cc:143
std::size_t axis
Definition: testpdiff.cc:59
double k0
Definition: testperiodic.cc:66
double k1
Definition: testperiodic.cc:67