32#ifndef MADNESS_TENSOR_TENSOR_H__INCLUDED
33#define MADNESS_TENSOR_TENSOR_H__INCLUDED
65#ifdef ENABLE_GENTENSOR
66#define HAVE_GENTENSOR 1
68#define HAVE_GENTENSOR 0
216#ifndef HAVE_STD_ABS_LONG
219 static long abs(
long a) {
220 return a>=0 ?
a : -
a;
225 static long abs(
long a) {
234#define IS_ODD(n) ((n)&0x1)
235#define IS_UNALIGNED(p) (((unsigned long)(p))&0x7)
239 template <
typename Q,
bool iscomplex>
247 template <
typename Q>
255 template <
typename Q>
264 template <
typename T=
int>
double mynorm(
int t) {
268 template <
typename T>
T mynorm(std::complex<T> t) {
273 template <
class T>
class SliceTensor;
278#ifdef TENSOR_USE_SHARED_ALIGNED_ARRAY
279#define TENSOR_SHARED_PTR detail::SharedAlignedArray
291 void dec() {
if (
p && ((*cnt)-- == 1)) {free(
p);
p = 0;}}
292 void inc() {
if (
p) (*cnt)++;}
294 SharedAlignedArray() :
p(0), cnt(0) {}
295 T* allocate(std::size_t size,
unsigned int alignment) {
296 std::size_t
offset = (size*
sizeof(
T)-1)/
sizeof(AtomicInt) + 1;
297 std::size_t nbyte = (
offset+1)*
sizeof(AtomicInt);
299 cnt = (AtomicInt*)(
p) +
offset;
303 SharedAlignedArray<T>& operator=(
const SharedAlignedArray<T>& other) {
304 if (
this != &other) {dec();
p = other.p; cnt = other.cnt; inc();}
307 void reset() {dec();
p = 0;}
308 ~SharedAlignedArray() {dec();}
312#define TENSOR_SHARED_PTR std::shared_ptr
337 for (
int i=0; i<
nd; ++i) {
338 TENSOR_ASSERT(
d[i]>=0 &&
d[i]<268435456,
"invalid dimension size in new tensor",
d[i],0);
345#define TENSOR_ALIGNMENT 16
347#define TENSOR_ALIGNMENT 32
348#elif MADNESS_HAVE_AVX2
351#define TENSOR_ALIGNMENT 32
352#elif MADNESS_HAVE_AVX512
354#define TENSOR_ALIGNMENT 64
357#define TENSOR_ALIGNMENT 64
360#ifdef TENSOR_USE_SHARED_ALIGNED_ARRAY
362#elif defined WORLD_GATHER_MEM_STATS
374 std::printf(
"new failed nd=%ld type=%ld size=%ld\n",
nd,
id(),
_size);
375 std::printf(
" %ld %ld %ld %ld %ld %ld\n",
376 d[0],
d[1],
d[2],
d[3],
d[4],
d[5]);
572 template <
typename Q>
582 template <
typename Q>
592 template <
typename Q>
604 template <
typename Q>
616 template <
typename Q>
629 template <
typename Q>
642 template <
typename Q>
655 template <
typename Q>
658 return (*
this) + (-x);
674 template <
typename Q>
685 template <
typename Q>
695 template <
typename Q>
706 template <
typename Q>
770#ifdef TENSOR_BOUNDS_CHECKING
782#ifdef TENSOR_BOUNDS_CHECKING
793#ifdef TENSOR_BOUNDS_CHECKING
804#ifdef TENSOR_BOUNDS_CHECKING
815#ifdef TENSOR_BOUNDS_CHECKING
827#ifdef TENSOR_BOUNDS_CHECKING
840#ifdef TENSOR_BOUNDS_CHECKING
854#ifdef TENSOR_BOUNDS_CHECKING
869#ifdef TENSOR_BOUNDS_CHECKING
885#ifdef TENSOR_BOUNDS_CHECKING
903#ifdef TENSOR_BOUNDS_CHECKING
922#ifdef TENSOR_BOUNDS_CHECKING
942#ifdef TENSOR_BOUNDS_CHECKING
963#ifdef TENSOR_BOUNDS_CHECKING
985#ifdef TENSOR_BOUNDS_CHECKING
1005#ifdef TENSOR_BOUNDS_CHECKING
1006 TENSOR_ASSERT(i>=0 && i<
_dim[0],
"non-PC general indexing bounds check failed dim=",
d,
this);
1021#ifdef TENSOR_BOUNDS_CHECKING
1022 TENSOR_ASSERT(i>=0 && i<
_dim[0],
"non-PC general indexing bounds check failed dim=",
d,
this);
1034 TENSOR_ASSERT(ind.size()>=(
unsigned int)
_ndim,
"invalid number of dimensions",ind.size(),
this);
1048 TENSOR_ASSERT(ind.size()>=(
unsigned int)
_ndim,
"invalid number of dimensions",ind.size(),
this);
1062 TENSOR_ASSERT(s.size()>=(
unsigned)(
this->ndim()),
"invalid number of dimensions",
1072 TENSOR_ASSERT(s.size()>=(
unsigned)(
this->ndim()),
"invalid number of dimensions",
1407 return reshape(
d.size(),
d.size() ? &
d[0] : 0);
1415 return reshape(
d.size(),
d.size() ? &
d[0] : 0);
1685 T result = *(this->
_p);
1687 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1690 if (result > *_p0) {
1692 for (
long i=0; i<
nd; ++i) ind[i]=iter.ind[i];
1705 T result = *(this->
_p);
1707 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1710 if (result < *_p0) {
1712 for (
long i=0; i<
nd; ++i) ind[i]=iter.ind[i];
1737 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1743 for (
long i=0; i<
nd; ++i) ind[i]=iter.ind[i];
1758 for (
long i=0; i<
_ndim; ++i) ind[i]=0;
1764 for (
long i=0; i<
nd; ++i) ind[i]=iter.ind[i];
1793 template <
typename opT>
1811 else if (
beta ==
T(0)) {
1818 else if (
alpha ==
T(0)) {
1822 else if (
beta ==
T(0)) {
1831 }
else if (
beta ==
T(0)) {
1881 template <
class Q,
class R>
1913 template <
class Archive,
typename T>
1928 template <
class Archive,
typename T>
1931 long sz = 0l,
id = 0l;
1933 if (
id != t.
id())
throw "type mismatch deserializing a tensor";
1938 if (sz != t.
size())
throw "size mismatch deserializing a tensor";
1952 template <
typename T,
typename Q>
1961 template <
typename T,
typename Q>
1970 template <
typename T,
typename Q>
1995 template <
class Q,
class T>
2018 template <
class T,
class Q>
2076 for (
long i=0; i<t.
_ndim; ++i) {
2077 long start=s[i].start,
end=s[i].end, step=s[i].step;
2080 if (start < 0) start += this->
_dim[i];
2082 long len =
end-start+1;
2083 if (step) len /= step;
2087 end = start + (len-1)*step;
2094 TENSOR_ASSERT(len>0,
"slice length must be non-zero",len,
this);
2160 if (t.
size() == 0) {
2161 s <<
"[empty tensor]\n";
2167 for (
int i = 0; i<(t.
ndim()-1); ++i) {
2181 std::ios::fmtflags
oldflags = s.setf(std::ios::scientific);
2187 const T*
p = iter._p0;
2188 long inc = iter._s0;
2189 long dimj = iter.dimj;
2190 s.unsetf(std::ios::scientific);
2192 for (
long i=0; i<iter.ndim; ++i) {
2200 s.setf(std::ios::fixed);
2201 for (
long j=0; j<dimj; ++j,
p+=inc) {
2208 s.unsetf(std::ios::scientific);
2211 s.setf(
oldflags,std::ios::floatfield);
2228 for (
long i = 0; i < left.
ndim(); ++i)
d[i] = left.
dim(i);
2229 for (
long i = 0; i < right.
ndim(); ++i)
d[i + left.
ndim()] = right.
dim(i);
2242 T *ptr = result.
ptr();
2247 for (iter.
reset(); iter.
_p0; ++iter) {
2248 long dimj = iter.
dimj;
2252 *ptr++ =
val1 * (*_p0);
2267 template <
class T,
class Q>
2269 long k0=-1,
long k1=0) {
2273 TENSOR_ASSERT(
nd!=0,
"result is a scalar but cannot return one ... use dot",
2278 right.
dim(
k1), &left);
2281 "invalid number of dimensions in the result",
nd,0);
2286 for (
long i=0; i<
k0; ++i)
d[i] = left.
dim(i);
2287 for (
long i=
k0+1; i<left.
ndim(); ++i)
d[i-1] = left.
dim(i);
2288 base = left.
ndim()-1;
2289 for (
long i=0; i<
k1; ++i)
d[i+base] = right.
dim(i);
2291 for (
long i=
k1+1; i<right.
ndim(); ++i)
d[i+base] = right.
dim(i);
2311 template <
class T,
class Q>
2319 resultT* ptr = result.
ptr();
2325 if (
k0==0 &&
k1==0) {
2328 long dimj = right.
stride(0);
2333 else if (
k0==(left.
ndim()-1) &&
k1==(right.
ndim()-1)) {
2341 else if (
k0==0 &&
k1==(right.
ndim()-1)) {
2349 else if (
k0==(left.
ndim()-1) &&
k1==0) {
2353 long dimj = right.
stride(0);
2359 long dimj = left.
dim(
k0);
2369 long s1 =
iter1._s0;
2371 for (
long j=0; j<dimj; ++j,
p0+=
s0,p1+=s1) {
2372 sum += (*p0) * (*p1);
2393 template <
class T,
class Q>
2396 TENSOR_ASSERT(
c.ndim() == 2,
"second argument must be a matrix",
c.ndim(),&
c);
2404 for (
long i=0; i<t.
ndim(); ++i) {
2405 result =
inner(result,
c,0,0);
2421 template <
class T,
class Q>
2425 for (
long i=0; i<t.
ndim(); ++i) {
2426 result =
inner(result,
c[i],0,0);
2459 template <
class T,
class Q>
2470 long dimj =
c.dim(1);
2472 for (
int n=1; n<t.
ndim(); ++n)
dimi *= dimj;
2477 for (
long i=0; i<
nij; ++i)
t0[i] = 0.0;
2479 for (
int n=1; n<t.
ndim(); ++n) {
2480 for (
long i=0; i<
nij; ++i) t1[i] = 0.0;
2487 for (
int n=1; n<t.
ndim(); ++n) {
2495 for (
int n=1; n<t.
ndim(); ++n) {
2523 template <
class T,
class Q>
2532 "general_fast_transform requires the matrix type not to "
2533 "promote the result past the tensor type");
2541 const long D = t.
ndim();
2549 for (
long d = 0;
d <
D; ++
d) {
2560 R*
buf1 = result.ptr();
2567 for (
long d = 0;
d <
D; ++
d) {
2568 const long dimk =
c[
d].dim(0);
2569 const long dimj =
c[
d].dim(1);
2585 template <
typename R>
2592 template <
typename R>
2608 template <
typename R>
2611 if (s.a.size() <
need) {
2622 template <
typename R>
2683#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
const long * dims() const
Returns the array of tensor dimensions.
Definition basetensor.h:153
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
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:2058
virtual ~SliceTensor()
Definition tensor.h:2143
SliceTensor(const Tensor< T > &t, const Slice s[])
Definition tensor.h:2069
SliceTensor< T > & operator=(const SliceTensor< Q > &t)
Definition tensor.h:2122
SliceTensor< T > & operator=(const Tensor< Q > &t)
Definition tensor.h:2133
SliceTensor< T > & operator=(const SliceTensor< T > &t)
Definition tensor.h:2116
SliceTensor(const Tensor< T > &t, const std::array< Slice, TENSOR_MAXDIM > s)
Definition tensor.h:2065
SliceTensor< T > & operator=(const Tensor< T > &t)
Definition tensor.h:2127
SliceTensor< T > & operator=(const T &t)
Definition tensor.h:2138
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 multidimensional array.
Definition tensor.h:318
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:1755
void deallocate()
Definition tensor.h:398
T *MADNESS_RESTRICT _p
Definition tensor.h:322
Tensor< T > & operator=(T x)
Inplace fill tensor with scalar.
Definition tensor.h:554
const Tensor< T > swapdim(long idim, long jdim) const
Returns new view/tensor swaping dimensions i and j.
Definition tensor.h:1615
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:537
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:1338
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:1327
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition tensor.h:1727
Tensor< T > & gaxpy(T alpha, const Tensor< T > &other, T beta)
Inplace generalized saxpy ... this = this*alpha + other*beta.
Definition tensor.h:1806
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:1871
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:1276
Tensor(long d0, long d1)
Create and zero new 2-d tensor.
Definition tensor.h:482
const T * ptr() const
Returns a pointer to the internal data.
Definition tensor.h:1846
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:1734
Tensor< T > & unaryop(opT &op)
Inplace apply a unary function to each element of the tensor.
Definition tensor.h:1794
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:644
Tensor< T > & fill(T x)
Inplace fill with a scalar (legacy name)
Definition tensor.h:563
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:1206
Tensor< T > & operator+=(const Tensor< Q > &t)
Inplace addition of two tensors.
Definition tensor.h:573
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:1509
Tensor< T > swapdim(long idim, long jdim)
Returns new view/tensor swaping dimensions i and j.
Definition tensor.h:1606
const Tensor< T > flat() const
Returns new view/tensor rehshaping to flat (1-d) tensor.
Definition tensor.h:1562
T sum() const
Returns the sum of all elements of the tensor.
Definition tensor.h:1663
Tensor< T > reshape(int ndimnew, const long *d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition tensor.h:1385
const T & operator[](long i) const
1-d indexing operation using [] without bounds checking.
Definition tensor.h:792
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:1861
Tensor< T > reshape(long dim0, long dim1)
Returns new view/tensor rehaping to conforming 2-d tensor with given dimensions.
Definition tensor.h:1440
TensorTypeData< T >::scalar_type scalar_type
C++ typename of the real type associated with a complex type.
Definition tensor.h:410
Tensor(long d0, long d1, long d2, long d3, long d4, long d5)
Create and zero new 6-d tensor.
Definition tensor.h:528
T type
C++ typename of this tensor.
Definition tensor.h:407
Tensor< TENSOR_RESULT_TYPE(T, Q) > operator+(const Tensor< Q > &t) const
Addition of two tensors to produce a new tensor.
Definition tensor.h:593
T & operator()(long i)
1-d indexing operation without bounds checking.
Definition tensor.h:803
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:1316
T & operator()(long i, long j, long k, long l, long m)
5-d indexing operation without bounds checking.
Definition tensor.h:921
T * ptr()
Returns a pointer to the internal data.
Definition tensor.h:1841
bool conforms(const Tensor< Q > &t) const
Test if *this and t conform.
Definition tensor.h:1658
const Tensor< T > mapdim(const std::vector< long > &map) const
Returns new view/tensor permuting the dimensions.
Definition tensor.h:1634
T & operator()(long i, long j)
2-d indexing operation without bounds checking.
Definition tensor.h:826
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:1414
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:1642
const Tensor< T > operator()(const std::vector< Slice > &s) const
General slicing operation (const)
Definition tensor.h:1071
Tensor< T > & operator-=(const Tensor< Q > &t)
Inplace subtraction of two tensors.
Definition tensor.h:583
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:1472
const T & operator()(long i, long j, long k) const
3-d indexing operation without bounds checking.
Definition tensor.h:868
SliceTensor< T > operator()(long i, const Slice &s1)
Return a 1d SliceTensor that views the specified range of the 2d Tensor.
Definition tensor.h:1116
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:1372
Tensor< T > mapdim(const std::vector< long > &map)
Returns new view/tensor permuting the dimensions.
Definition tensor.h:1625
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:618
const Tensor< T > operator()(const std::array< Slice, TENSOR_MAXDIM > &s) const
General slicing operation (const)
Definition tensor.h:1089
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:1236
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:1396
const Tensor< T > fusedim(long i) const
Returns new view/tensor fusing contiguous dimensions i and i+1.
Definition tensor.h:1597
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type scale(Q x)
Inplace multiplication by scalar of supported type (legacy name)
Definition tensor.h:687
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type operator-=(const Q &x)
Inplace decrement by scalar of supported type.
Definition tensor.h:708
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:631
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:1156
TensorTypeData< T >::float_scalar_type float_scalar_type
C++ typename of the floating point type associated with scalar real type.
Definition tensor.h:413
Tensor(const Tensor< T > &t)
Copy constructor is shallow (same as assignment)
Definition tensor.h:429
T & operator()(long i, long j, long k)
3-d indexing operation without bounds checking.
Definition tensor.h:853
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:1349
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:1496
Tensor< T > operator-() const
Unary negation producing a new tensor.
Definition tensor.h:664
const T & operator()(long i, long j) const
2-d indexing operation without bounds checking.
Definition tensor.h:839
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:1306
T & operator()(long i, long j, long k, long l, long m, long n)
6-d indexing operation without bounds checking.
Definition tensor.h:962
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:1360
SliceTensor< T > operator()(const Slice &s0)
Return a 1d SliceTensor that views the specified range of the 1d Tensor.
Definition tensor.h:1096
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:1296
const T & operator()(const long ind[]) const
Politically incorrect general indexing operation without bounds checking.
Definition tensor.h:1017
Tensor< T > & emul(const Tensor< T > &t)
Inplace multiply by corresponding elements of argument Tensor.
Definition tensor.h:1800
Tensor< T > & operator=(const Tensor< T > &t)
Assignment is shallow (same as copy constructor)
Definition tensor.h:444
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:1196
T & operator()(long i, long j, long k, long l)
4-d indexing operation without bounds checking.
Definition tensor.h:884
TENSOR_RESULT_TYPE(T, Q) trace(const Tensor< Q > &t) const
Return the trace of two tensors (no complex conjugate invoked)
Definition tensor.h:1778
SliceTensor< T > operator()(const std::array< Slice, TENSOR_MAXDIM > &s)
General slicing operation.
Definition tensor.h:1081
T max(long *ind=0) const
Return the maximum value (and if ind is non-null, its index) in the Tensor.
Definition tensor.h:1704
Tensor(long d0)
Create and zero new 1-d tensor.
Definition tensor.h:473
const T & operator()(long i, long j, long k, long l) const
4-d indexing operation without bounds checking.
Definition tensor.h:902
T product() const
Return the product of all elements of the tensor.
Definition tensor.h:1677
const T & operator()(long i, long j, long k, long l, long m) const
5-d indexing operation without bounds checking.
Definition tensor.h:941
T min(long *ind=0) const
Return the minimum value (and if ind is non-null, its index) in the Tensor.
Definition tensor.h:1684
Tensor< TENSOR_RESULT_TYPE(T, Q) > operator-(const Tensor< Q > &t) const
Subtraction of two tensors to produce a new tensor.
Definition tensor.h:605
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:984
T & operator()(const std::vector< long > ind)
General indexing operation with bounds checking.
Definition tensor.h:1033
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:1570
virtual ~Tensor()
Definition tensor.h:1898
const Tensor< T > operator()(const Slice &s0) const
Return a 1d SliceTensor that views the specified range of the 1d Tensor.
Definition tensor.h:1106
void allocate(long nd, const long d[], bool dozero)
Definition tensor.h:325
const BaseTensor * base() const
Returns a pointer to the base class.
Definition tensor.h:1856
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:1536
T sumsq() const
Returns the sum of the squares of the elements.
Definition tensor.h:1670
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type operator*=(const Q &x)
Inplace multiplication by scalar of supported type.
Definition tensor.h:676
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:1146
T & operator[](long i)
1-d indexing operation using [] without bounds checking.
Definition tensor.h:781
Tensor< T > & screen(double x)
Inplace set elements of *this less than x in absolute magnitude to zero.
Definition tensor.h:759
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:1650
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:1579
Tensor(long d0, long d1, long d2, long d3)
Create and zero new 4-d tensor.
Definition tensor.h:503
Tensor(long d0, long d1, long d2)
Create and zero new 3-d tensor.
Definition tensor.h:492
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:1550
const Tensor< T > reshape(long dim0) const
Returns new view/tensor rehapings to conforming 1-d tensor with given dimension.
Definition tensor.h:1430
bool has_data() const
Definition tensor.h:1903
Tensor< T > reshape(const std::vector< long > &d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition tensor.h:1406
BaseTensor * base()
Returns a pointer to the base class.
Definition tensor.h:1851
const TensorIterator< T > & end() const
End point for forward iteration.
Definition tensor.h:1893
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:1461
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:1484
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:1176
Tensor< T > reshape(long dim0)
Returns new view/tensor rehapings to conforming 1-d tensor with given dimension.
Definition tensor.h:1422
SliceTensor< T > operator()(const Slice &s0, long j)
Return a 1d SliceTensor that views the specified range of the 2d Tensor.
Definition tensor.h:1136
Tensor< T > fusedim(long i)
Returns new view/tensor fusing contiguous dimensions i and i+1.
Definition tensor.h:1588
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:1266
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:1186
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:1786
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:1246
const T & operator()(const std::vector< long > ind) const
General indexing operation with bounds checking.
Definition tensor.h:1047
T & operator()(const long ind[])
Politically incorrect general indexing operation without bounds checking.
Definition tensor.h:1001
Tensor< T > flat()
Returns new view/tensor rehshaping to flat (1-d) tensor.
Definition tensor.h:1556
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:1450
Tensor(long d0, long d1, long d2, long d3, long d4)
Create and zero new 5-d tensor.
Definition tensor.h:515
Tensor()
Default constructor does not allocate any data and sets ndim=-1, size=0, _p=0, and id.
Definition tensor.h:416
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:1286
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:1882
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:1126
static bool bounds_checking()
Return true if bounds checking was enabled at compile time.
Definition tensor.h:769
const T & operator()(long i) const
1-d indexing operation without bounds checking.
Definition tensor.h:814
void clear()
Frees all memory and resests to state of default constructor.
Definition tensor.h:1901
TENSOR_SHARED_PTR< T > _shptr
Definition tensor.h:323
Tensor< T > & fillrandom()
Inplace fill with random values ( [0,1] for floats, [0,MAXSIZE] for integers)
Definition tensor.h:725
Tensor(long nd, const long d[], bool dozero=true)
Politically incorrect general constructor.
Definition tensor.h:546
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:1226
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:657
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:1166
Tensor< T > & fillindex()
Inplace fill with the index of each element.
Definition tensor.h:749
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:1256
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:1522
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type operator+=(const Q &x)
Inplace increment by scalar of supported type.
Definition tensor.h:697
Tensor< T > & conj()
Inplace complex conjugate.
Definition tensor.h:717
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:1216
SliceTensor< T > operator()(const std::vector< Slice > &s)
General slicing operation.
Definition tensor.h:1061
Definition thread_specific.h:82
static const double R
Definition csqrt.cc:46
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:28
archive_array< T > wrap(const T *, unsigned int)
Factory function to wrap a dynamically allocated pointer as a typed archive_array.
Definition archive.h:914
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:2044
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:2643
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:2460
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:2312
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
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
Definition potentialmanager.cc:41
void eval_scratch_clear()
Definition tensor.h:2623
std::pair< Tensor< R > &, Tensor< R > & > eval_scratch(long need)
Definition tensor.h:2609
thread_specific< EvalScratch< R > > & eval_scratch_pool()
Definition tensor.h:2593
T mynorm(T t)
Definition tensor.h:261
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:401
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:2239
Q conditional_conj(const Q &coeff)
For real types return value, for complex return conjugate.
Definition tensor.h:256
GenTensor< TENSOR_RESULT_TYPE(R, Q)> general_transform(const GenTensor< R > &t, const Tensor< Q > c[])
Definition gentensor.h:274
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:2219
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
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:731
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:2233
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
response_space transpose(response_space &f)
Definition basic_operators.cc:10
Tensor< TENSOR_RESULT_TYPE(T, Q)> & general_fast_transform(const Tensor< T > &t, const Tensor< Q > *c, Tensor< TENSOR_RESULT_TYPE(T, Q)> &result, Tensor< TENSOR_RESULT_TYPE(T, Q)> &workspace)
Definition tensor.h:2525
std::vector< CCPairFunction< T, NDIM > > operator*(const double fac, const std::vector< CCPairFunction< T, NDIM > > &arg)
Definition ccpairfunction.h:1089
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::enable_if< std::is_base_of< ProjectorBase, projT >::value, OuterProjector< projT, projQ > >::type outer(const projT &p0, const projQ &p1)
Definition projector.h:457
std::vector< CCPairFunction< T, NDIM > > operator-(const std::vector< CCPairFunction< T, NDIM > > c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition ccpairfunction.h:1060
static double pop(std::vector< double > &v)
Definition SCF.cc:115
static void aligned_zero(long n, T *a)
Definition aligned.h:55
double inner(response_space &a, response_space &b)
Definition response_functions.h:639
double imag(double x)
Definition complexfun.h:56
GenTensor< TENSOR_RESULT_TYPE(R, Q)> transform_dir(const GenTensor< R > &t, const Tensor< Q > &c, const int axis)
Definition lowranktensor.h:1106
std::string type(const PairType &n)
Definition PNOParameters.h:18
static const long default_jdim
Definition tensoriter.h:57
std::vector< CCPairFunction< T, NDIM > > operator+(const std::vector< CCPairFunction< T, NDIM > > c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition ccpairfunction.h:1052
double real(double x)
Definition complexfun.h:52
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
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
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:2172
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:219
static const double d
Definition nonlinschro.cc:121
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 double m
Definition relops.cc:9
static const long k
Definition rk.cc:44
Definition test_ar.cc:204
Definition test_ccpairfunction.cc:22
Definition type_data.h:146
static void load(const Archive &s, Tensor< T > &t)
Definition tensor.h:1930
Default load of an object via serialize(ar, t).
Definition archive.h:667
static void store(const Archive &s, const Tensor< T > &t)
Definition tensor.h:1915
Default store of an object via serialize(ar, t).
Definition archive.h:612
static Q op(const Q &coeff)
Definition tensor.h:249
For real types return value, for complex return conjugate.
Definition tensor.h:240
static Q op(const Q &coeff)
Definition tensor.h:241
Per-thread grow-on-demand buffer pair for general_fast_transform.
Definition tensor.h:2586
Tensor< R > b
Definition tensor.h:2586
Tensor< R > a
Definition tensor.h:2586
static const double s0
Definition tdse4.cc:83
#define IS_UNALIGNED(p)
Definition tensor.h:235
#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
AtomicInt sum
Definition test_atomicint.cc:46
static const double alpha
Definition testcosine.cc:10
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
Reclaimable thread-specific storage (a thread_local you can free).
#define TENSOR_RESULT_TYPE(L, R)
This macro simplifies access to TensorResultType.
Definition type_data.h:205