54 static double time_[30];
58 template <
class T>
class GenTensor;
59 template <
class T>
class GenTensor;
60 template <
class T>
class SliceLowRankTensor;
77 static double& time(
int i) {
return time_[i];}
116 for (i=
rank-1; i>=0; i--) {
133 SRConf(
const long&
ndim,
const std::array<long,TENSOR_MAXDIM>& dimensions,
142 const long&
ndim,
const long&
dims,
const long nci)
153 const long&
ndim,
const long*
dims,
const long nci)
164 if (&rhs==
this)
return *
this;
183 for (
unsigned int i=0; i<rhs.
vector_.size(); i++) {
210 std::array<long,TENSOR_MAXDIM>
dims;
217 std::array<std::array<long,TENSOR_MAXDIM>, 2> dimensions;
218 for (
int i=0; i<
nci_left; ++i) dimensions[0][i+1]=this->
dim(i);
221 dimensions[0][0]=
rank;
222 dimensions[1][0]=
rank;
271 template <
typename Archive>
288 const std::vector<Slice>&
c0(
const int idim)
const {
289 if (idim==0)
return s0;
290 else if (idim==1)
return s1;
382 std::array<Slice,TENSOR_MAXDIM> rhs_s,
const double alpha,
const double beta) {
436 std::array<long,TENSOR_MAXDIM>
k;
437 for (
int i=0; i<s.size(); ++i) {
438 if (s[i].end==-1)
k[i]=
dim(i);
439 else k[i]= s[i].end-s[i].start+1;
461 long finalrank=this->
rank()*other.
rank();
465 if ((this->
rank()==0) or (other.
rank()==0)) {
473 for (
int i=0; i<2; ++i) {
478 for (
int k=0;
k<
a1.dim(1); ++
k) {
502 std::array<std::vector<Slice>,2>
make_slices(
const std::array<Slice,TENSOR_MAXDIM>& s)
const {
509 for (
int idim=0; idim<
ndim(); ++idim) {
510 if (idim<
nci_left) s00[idim+1]=s[idim];
514 std::array<std::vector<Slice>,2> result={s00,s10};
540 long kVec(
const int idim)
const {
569 for (
unsigned int idim=0; idim<this->dim_eff(); idim++) {
571 vector_[idim].fillrandom();
575 for (
unsigned int idim=0; idim<this->dim_eff(); idim++) {
586 if (
rank()==0)
return;
590 const unsigned int rank=this->
rank();
596 for (
unsigned int r=0; r<
rank; r++) {
598 for (
unsigned int idim=0; idim<2; idim++) {
603 const double norm=this->vector_[idim](s).
normf();
604 const double fac=
norm;
605 double oofac=1.0/fac;
606 if (fac<1.e-13) oofac=0.0;
628 if (
rank()==0)
return true;
632 for (
int i=0; i<S.
dim(0); i++) S(i,i)-=1.0;
637 return (
small<1.e-13);
650 for (
int i=0; i<
vector_[0].ndim(); ++i) {
651 if (vector_dimensions[0][i] !=
vector_[0].
dim(i))
return false;
653 for (
int i=0; i<
vector_[1].ndim(); ++i) {
654 if (vector_dimensions[1][i] !=
vector_[1].
dim(i))
return false;
716 for (
size_t i=0; i<
vector_.size(); ++i) {
740 if ((lhs.
rank()==0) or (rhs.
rank()==0))
return 0.0;
754 const unsigned int dim_eff=2;
761 for (
unsigned int idim=0; idim<dim_eff; idim++) {
768 weightMatrix.
emul(ovlp);
796 for (
unsigned int idim=0; idim<2; idim++) {
802 weightMatrix.
emul(ovlp);
806 const resultT overlap=
std::abs(weightMatrix.
sum());
807 return sqrt(overlap);
928 const long rank=x.
dim(0);
953 const scalar_type e1_max=
e1.absmax();
954 const scalar_type e2_max=e2.
absmax();
973 for (
unsigned int r=0; r<rank; r++) {
975 if (e2(r)*w_max<
thresh) lo2=r+1;
982 sqrt_e1=sqrt_e1(
Slice(lo1,-1));
983 sqrt_e2=sqrt_e2(
Slice(lo2,-1));
984 unsigned int rank1=rank-lo1;
985 unsigned int rank2=rank-lo2;
998 for (
unsigned int i=0; i<rank1; i++) {
999 for (
unsigned int j=0; j<rank2; j++) {
1000 for (
unsigned int r=0; r<rank; r++) {
1001 M(i,j)+=U1(r,i)*sqrt_e1(i)*
weights(r)*U2(r,j) * sqrt_e2(j);
1009 for (
unsigned int r=0; r<rank1; r++) {
1010 scalar_type fac=1.0/sqrt_e1(r);
1011 for (
unsigned int t=0; t<rank; t++) {
1017 for (
unsigned int r=0; r<rank2; r++) {
1018 scalar_type fac=1.0/sqrt_e2(r);
1019 for (
unsigned int t=0; t<rank; t++) {
1039 Up=
inner(Up,U1,0,1);
1040 VTp=
inner(VTp,U2,1,1);
1095 template<
typename T>
1105 const long rank1=x1.
dim(0);
1106 const long rank2=x2.
dim(0);
1107 const long rank=rank1+rank2;
1110 const Slice s0(0,rank1-1), s1(rank1,rank-1);
1112 const double w_max=
std::max(w1.absmax(),w2.absmax());
1113 const double norm_max=w_max*rank;
1128 for (
long i=0; i<rank; i++) {
1158 const double e1_max=
e1.absmax();
1159 const double e2_max=e2.
absmax();
1162 if ((e1_max*norm_max<
thresh) or (e2_max*norm_max<
thresh)) {
1178 for (
unsigned int r=0; r<rank; r++) {
1179 if (
e1(r)<
thresh/norm_max) lo1=r+1;
1181 if (e2(r)<
thresh/norm_max) lo2=r+1;
1182 else sqrt_e2(r)=sqrt(
std::abs(e2(r)));
1187 sqrt_e1=sqrt_e1(
Slice(lo1,-1));
1188 sqrt_e2=sqrt_e2(
Slice(lo2,-1));
1189 unsigned int rank_x=rank-lo1;
1190 unsigned int rank_y=rank-lo2;
1202 for (
unsigned int i=0; i<rank1; ++i) UU1(i,
_)*=w1(i);
1203 for (
unsigned int i=rank1; i<rank; ++i) UU1(i,
_)*=w2(i-rank1);
1210 for (
unsigned int r=0; r<rank_x; r++) {
1211 double fac=1.0/sqrt_e1(r);
1215 for (
unsigned int r=0; r<rank_y; r++) {
1216 double fac=1.0/sqrt_e2(r);
1235 Up=
inner(Up,U1,0,1);
1236 VTp=
inner(VTp,U2,1,1);
1246 for (i=Sp.
dim(0)-1; i>=0; i--) {
1261 x1=
inner(Up1,x1,0,0);
1263 y1=
inner(VTp1,y1,0,0);
1280 template<
typename T>
1284 s <<
"dim_ " << sr.
ndim() <<
"\n";;
1285 s <<
"rank_ " << sr.rank_ <<
"\n";;
1286 s <<
"vector_.size()" << sr.
vector_.size() <<
"\n";
1287 s <<
"has_data() " << sr.
has_data() <<
"\n";
1288 s <<
"TensorType " << sr.type() <<
"\n\n";
double w(double t, double eps)
Definition: DKops.h:22
static const double small
Definition: binaryop.cc:117
std::complex< double > double_complex
Definition: cfft.h:14
C++ interface to LAPACK, either directly via Fortran API (see clapack_fortran.h) or via LAPACKE (see ...
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
long _size
Number of elements in the tensor.
Definition: basetensor.h:93
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
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
long _ndim
Number of dimensions (-1=invalid; 0=no supported; >0=tensor)
Definition: basetensor.h:94
Definition: lowranktensor.h:59
long nci_left
separation dimensions: A(n,m) -> A(r,n) B(r,m), with n={k1,k2},m={k3,k4,k5..) multi-indices
Definition: srconf.h:93
TensorTypeData< T >::float_scalar_type float_scalar_type
Definition: srconf.h:73
SRConf(const long &ndim, const std::array< long, TENSOR_MAXDIM > &dimensions, const long nci)
Definition: srconf.h:133
const Tensor< T > & ref_vector(const unsigned int &idim) const
return reference to one of the vectors F
Definition: srconf.h:535
SRConf & operator=(const SRConf &rhs)
assignment operator (tested), shallow copy of vectors
Definition: srconf.h:161
size_t real_size() const
return the real size of this
Definition: srconf.h:714
Tensor< typename Tensor< T >::scalar_type > weights_
for each configuration the weight; length should be r
Definition: srconf.h:86
const SRConf get_configs(const int &start, const int &end) const
Definition: srconf.h:251
unsigned int nCoeff() const
return the number of coefficients
Definition: srconf.h:709
Tensor< T > reconstruct() const
reconstruct this to return a full tensor
Definition: srconf.h:674
std::enable_if<!(TensorTypeData< T >::iscomplex or TensorTypeData< Q >::iscomplex), TENSOR_RESULT_TYPE(T, Q)>::type friend trace(const SRConf< T > &rhs, const SRConf< Q > &lhs)
calculate the Frobenius inner product (tested)
Definition: srconf.h:736
void clear()
Definition: srconf.h:241
SRConf()
default ctor
Definition: srconf.h:124
bool has_structure() const
return if this has a tensor structure (has not been flattened)
Definition: srconf.h:647
std::array< std::vector< Slice >, 2 > make_slices(const std::array< Slice, TENSOR_MAXDIM > &s) const
Definition: srconf.h:502
bool has_no_data() const
does this have any data?
Definition: srconf.h:285
const Tensor< T > flat_vector(const unsigned int &idim) const
return shallow copy of a slice of one of the vectors, flattened to (r,kVec)
Definition: srconf.h:545
void make_slices()
redo the Slices for getting direct access to the configurations
Definition: srconf.h:494
void add_SVD(const SRConf< T > &rhs, const double &thresh)
add two orthonormal configurations, yielding an optimal SVD decomposition
Definition: srconf.h:345
std::enable_if<(TensorTypeData< T >::iscomplex or TensorTypeData< Q >::iscomplex), TENSOR_RESULT_TYPE(T, Q)>::type friend trace(const SRConf< T > &rhs, const SRConf< Q > &lhs)
Definition: srconf.h:728
void serialize(Archive &ar)
Definition: srconf.h:272
friend SRConf< T > copy(const SRConf< T > &rhs)
deep copy of rhs, shrink
Definition: srconf.h:417
Tensor< T >::scalar_type scalar_type
the scalar type of T
Definition: srconf.h:72
bool check_dimensions() const
Definition: srconf.h:614
void append(const SRConf< T > &rhs, const double_complex fac=1.0)
Definition: srconf.h:339
SRConf(const SRConf &rhs)=default
copy ctor (tested); shallow copy
std::vector< Slice > s0
Definition: srconf.h:97
const std::vector< Slice > & c0(const int idim) const
return a Slice that corresponds the that part of vector_ that holds coefficients
Definition: srconf.h:288
Tensor< T > flat_vector_with_weights(const int dim) const
return flat (r,i) view of the tensor with the weights multiplied in
Definition: srconf.h:703
void normalize()
normalize the vectors (tested)
Definition: srconf.h:584
Tensor< T > tensorT
Definition: srconf.h:80
SRConf(const long &ndim, const long *dimensions, const long nci)
Definition: srconf.h:126
bool check_right_orthonormality() const
check if the terms are orthogonal
Definition: srconf.h:625
double weights(const unsigned int &i) const
return the weight
Definition: srconf.h:671
void set_size_and_dim(long ndim, long k)
Definition: srconf.h:209
Tensor< T > make_left_vector_with_weights() const
Definition: srconf.h:688
Tensor< T > make_vector_with_weights(const int dim) const
Definition: srconf.h:693
std::vector< Slice > s1
Definition: srconf.h:97
SRConf< TENSOR_RESULT_TYPE(T, Q) > general_transform(const Tensor< Q > c[]) const
Definition: srconf.h:855
SRConf(const Tensor< double > &weights, const tensorT &vector1, const tensorT &vector2, const long &ndim, const long *dims, const long nci)
explicit ctor with two vectors (aka SVD), shallow
Definition: srconf.h:152
SRConf< T > & emul(const SRConf< T > &other)
perform elementwise Hadamard product
Definition: srconf.h:457
SRConf(const Tensor< double > &weights, const std::vector< Tensor< T > > &vectors, const long &ndim, const long &dims, const long nci)
ctor with provided weights and effective vectors; shallow copy
Definition: srconf.h:141
long kVec(const int idim) const
Definition: srconf.h:540
SRConf & operator=(const T &number)
assign a number to this;
Definition: srconf.h:196
TensorTypeData< T >::float_scalar_type svd_normf() const
calculate the Frobenius norm, if this is in SVD form
Definition: srconf.h:777
int dim_per_vector(int idim) const
return the number of physical dimensions
Definition: srconf.h:665
void set_vectors_and_weights(const Tensor< typename Tensor< T >::scalar_type > &weights, const Tensor< T > &vector1, const Tensor< T > &vector2)
Definition: srconf.h:234
static const bool check_orthonormality
check orthonormality at low rank additions
Definition: srconf.h:83
long rank() const
return the logicalrank
Definition: srconf.h:661
SRConf< T > copy_slice(const std::array< Slice, TENSOR_MAXDIM > &s) const
return a slice of this (deep copy)
Definition: srconf.h:434
Tensor< T > flat_vector(const unsigned int &idim)
return shallow copy of a slice of one of the vectors, flattened to (r,kVec)
Definition: srconf.h:553
static int max_sigma(const double &thresh, const long &rank, const Tensor< double > &w)
Definition: srconf.h:109
~SRConf()
dtor
Definition: srconf.h:269
bool has_data() const
does this have any data?
Definition: srconf.h:280
friend bool compatible(const SRConf &lhs, const SRConf &rhs)
check compatibility
Definition: srconf.h:819
void append(const SRConf< T > &rhs, const double fac=1.0)
append configurations of rhs to this
Definition: srconf.h:300
void scale(const double &fac)
scale this by a number
Definition: srconf.h:812
SRConf< T > transform(const Tensor< T > &c) const
Definition: srconf.h:828
std::array< Tensor< T >, 2 > vector_
Definition: srconf.h:90
bool is_flat() const
return if this has only one additional dimension (apart from rank)
Definition: srconf.h:641
void scale(const double_complex &fac)
Definition: srconf.h:814
Tensor< T > & ref_vector(const unsigned int &idim)
return reference to one of the vectors F
Definition: srconf.h:530
void make_empty_vectors_and_weights(const long rank)
Definition: srconf.h:226
void inplace_add(const SRConf< T > &rhs, std::array< Slice, TENSOR_MAXDIM > lhs_s, std::array< Slice, TENSOR_MAXDIM > rhs_s, const double alpha, const double beta)
alpha * this(lhs_s) + beta * rhs(rhs_s)
Definition: srconf.h:381
TensorTypeData< T >::float_scalar_type normf() const
calculate the Frobenius norm
Definition: srconf.h:783
std::array< std::array< long, TENSOR_MAXDIM >, 2 > make_vector_dimensions(const long rank) const
deduce the dimensions of the left and right singular vectors from the tensor dimensions
Definition: srconf.h:216
void make_structure(bool force=false)
Definition: srconf.h:518
SRConf< T > transform_dir(const Tensor< T > &c, const int &axis) const
Definition: srconf.h:879
void fillWithRandom(const long &rank=1)
fill this SRConf with 1 flattened random configurations (tested)
Definition: srconf.h:562
implements a temporary(!) slice of a LowRankTensor
Definition: lowranktensor.h:949
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
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
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition: tensor.h:1726
T sum() const
Returns the sum of all elements of the tensor.
Definition: tensor.h:1662
TensorTypeData< T >::scalar_type scalar_type
C++ typename of the real type associated with a complex type.
Definition: tensor.h:409
Tensor< T > reshape(int ndimnew, const long *d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition: tensor.h:1384
Tensor< T > & emul(const Tensor< T > &t)
Inplace multiply by corresponding elements of argument Tensor.
Definition: tensor.h:1798
void clear()
Frees all memory and resests to state of default constructor.
Definition: tensor.h:1884
Tensor< T > & screen(double x)
Inplace set elements of *this less than x in absolute magnitude to zero.
Definition: tensor.h:758
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
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
const double beta
Definition: gygi_soltion.cc:62
static const double v
Definition: hatom_sf_dirac.cc:20
#define max(a, b)
Definition: lda.h:51
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition: madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition: madness_exception.h:134
double norm(const T &t)
Definition: adquad.h:42
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
void ortho5(Tensor< T > &x1, Tensor< T > &y1, Tensor< typename Tensor< T >::scalar_type > &w1, const Tensor< T > &x2, const Tensor< T > &y2, const Tensor< typename Tensor< T >::scalar_type > &w2, const double &thresh)
specialized version of ortho3
Definition: srconf.h:1096
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
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 ortho3(Tensor< T > &x, Tensor< T > &y, Tensor< typename Tensor< T >::scalar_type > &weights, const double &thresh)
sophisticated version of ortho2
Definition: srconf.h:920
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
Tensor< double > tensorT
Definition: distpm.cc:21
static Tensor< double > weights[max_npt+1]
Definition: legendre.cc:99
response_space transpose(response_space &f)
Definition: basic_operators.cc:10
static const Slice _(0,-1, 1)
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
void svd(const Tensor< T > &a, Tensor< T > &U, Tensor< typename Tensor< T >::scalar_type > &s, Tensor< T > &VT)
Compute the singluar value decomposition of an n-by-m matrix using *gesvd.
Definition: lapack.cc:739
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition: timers.cc:48
double inner(response_space &a, response_space &b)
Definition: response_functions.h:442
std::string type(const PairType &n)
Definition: PNOParameters.h:18
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
Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition: vector.h:711
void swap(Vector< T, N > &l, Vector< T, N > &r)
Swap the contents of two Vectors.
Definition: vector.h:497
void syev(const Tensor< T > &A, Tensor< T > &V, Tensor< typename Tensor< T >::scalar_type > &e)
Real-symmetric or complex-Hermitian eigenproblem.
Definition: lapack.cc:969
static long abs(long a)
Definition: tensor.h:218
Defines simple templates for printing to std::cout "a la Python".
double Q(double a)
Definition: relops.cc:20
static const double c
Definition: relops.cc:10
static const double thresh
Definition: rk.cc:45
static const long k
Definition: rk.cc:44
Definition: test_ccpairfunction.cc:22
static const double s0
Definition: tdse4.cc:83
Defines and implements most of Tensor.
Prototypes for a partial interface from Tensor to LAPACK.
#define TENSOR_MAXDIM
Definition: tensor_macros.h:194
const double alpha
Definition: test_coulomb.cc:54
F residual(const F &f)
Definition: testcomplexfunctionsolver.cc:69
std::size_t axis
Definition: testpdiff.cc:59
const double a1
Definition: vnucso.cc:85
FLOAT e1(FLOAT z)
Definition: y1.cc:144