52 static double time_[30];
78 static double& time(
int i) {
return time_[i]; }
115 for (i =
rank - 1; i >= 0; i--) {
132 SRConf(
const long&
ndim,
const std::array<long,TENSOR_MAXDIM>& dimensions,
140 const long&
ndim,
const long&
dims,
const long nci)
151 const long&
ndim,
const long*
dims,
const long nci)
161 if (&rhs ==
this)
return *
this;
173 if (rhs.
rank() == 0) {
180 for (
unsigned int i = 0; i < rhs.
vector_.size(); i++) {
205 std::array<long,TENSOR_MAXDIM>
dims;
212 std::array<std::array<long,TENSOR_MAXDIM>, 2> dimensions;
213 for (
int i = 0; i <
nci_left; ++i) dimensions[0][i + 1] = this->
dim(i);
216 dimensions[0][0] =
rank;
217 dimensions[1][0] =
rank;
265 template <
typename Archive>
275 return (
size() != 0);
282 const std::vector<Slice>&
c0(
const int idim)
const {
283 if (idim == 0)
return s0;
284 else if (idim == 1)
return s1;
320 vector0(s00) = rhs.
vector_[0](rhs.
c0(0));
321 vector1(s10) = rhs.
vector_[1](rhs.
c0(1));
324 std::swap(vector0,
vector_[0]);
325 std::swap(vector1,
vector_[1]);
349 std::random_device rd;
352 std::mt19937 gen(rd());
358 long iran = distrib(gen);
360 print(
"checking orthonormality in add_SVD");
367 print(
"vector in add_svd not orthogonal");
386 time(25) += cpu1 - cpu0;
396 std::array<Slice,TENSOR_MAXDIM> rhs_s,
const double alpha,
const double beta) {
424 std::swap(*
this, result);
446 std::array<long,TENSOR_MAXDIM>
k;
447 for (
int i = 0; i < s.size(); ++i) {
448 if (s[i].end == -1)
k[i] =
dim(i);
449 else k[i] = s[i].end - s[i].start + 1;
471 long finalrank = this->
rank() * other.
rank();
475 if ((this->
rank() == 0) or (other.
rank() == 0)) {
483 for (
int i = 0; i < 2; ++i) {
488 for (
int k = 0;
k <
a1.dim(1); ++
k) {
512 std::array<std::vector<Slice>, 2>
make_slices(
const std::array<Slice,TENSOR_MAXDIM>& s)
const {
519 for (
int idim = 0; idim <
ndim(); ++idim) {
520 if (idim <
nci_left) s00[idim + 1] = s[idim];
524 std::array<std::vector<Slice>, 2> result = {s00, s10};
548 long kVec(
const int idim)
const {
593 if (
rank() == 0)
return;
597 const unsigned int rank = this->
rank();
603 for (
unsigned int r = 0; r <
rank; r++) {
605 for (
unsigned int idim = 0; idim < 2; idim++) {
610 const double norm = this->vector_[idim](s).
normf();
611 const double fac =
norm;
612 double oofac = 1.0 / fac;
613 if (fac < 1.e-13) oofac = 0.0;
636 if (
rank() == 0)
return true;
640 for (
int i = 0; i < S.
dim(0); i++) S(i, i) -= 1.0;
645 return (
small < 1.e-10);
658 for (
int i = 0; i <
vector_[0].ndim(); ++i) {
659 if (vector_dimensions[0][i] !=
vector_[0].
dim(i))
return false;
661 for (
int i = 0; i <
vector_[1].ndim(); ++i) {
662 if (vector_dimensions[1][i] !=
vector_[1].
dim(i))
return false;
675 return vector_[idim].ndim() - 1;
701 for (
unsigned int r = 0; r <
rank(); r++)
v(r,
_) *=
weights(r);
722 for (
size_t i = 0; i <
vector_.size(); ++i) {
727 n += 2 *
s1.size() *
sizeof(
Slice);
732 template <
typename Q>
741 template <
typename Q>
747 if ((lhs.
rank() == 0) or (rhs.
rank() == 0))
return 0.0;
761 const unsigned int dim_eff = 2;
768 for (
unsigned int idim = 0; idim < dim_eff; idim++) {
775 weightMatrix.
emul(ovlp);
802 for (
unsigned int idim = 0; idim < 2; idim++) {
808 weightMatrix.
emul(ovlp);
812 const resultT overlap =
std::abs(weightMatrix.
sum());
813 return sqrt(overlap);
860 template <
typename Q>
874 for (
long i = 0; i <
nci_left; ++i) left =
inner(left,
c[i], 0, 0);
922 template <
typename T>
930 const long rank = x.
dim(0);
931 const double w_max =
weights.absmax() * rank;
959 if ((e1_max * w_max <
thresh) or (e2_max * w_max <
thresh)) {
975 for (
unsigned int r = 0; r < rank; r++) {
976 if (
e1(r) * w_max <
thresh) lo1 = r + 1;
977 if (e2(r) * w_max <
thresh) lo2 = r + 1;
984 sqrt_e1 = sqrt_e1(
Slice(lo1, -1));
985 sqrt_e2 = sqrt_e2(
Slice(lo2, -1));
986 unsigned int rank1 = rank - lo1;
987 unsigned int rank2 = rank - lo2;
1000 for (
unsigned int i = 0; i < rank1; i++) {
1001 for (
unsigned int j = 0; j < rank2; j++) {
1002 for (
unsigned int r = 0; r < rank; r++) {
1003 M(i, j) += U1(r, i) * sqrt_e1(i) *
weights(r) * U2(r, j) * sqrt_e2(j);
1011 for (
unsigned int r = 0; r < rank1; r++) {
1013 for (
unsigned int t = 0; t < rank; t++) {
1019 for (
unsigned int r = 0; r < rank2; r++) {
1021 for (
unsigned int t = 0; t < rank; t++) {
1034 svd(M, Up, Sp, VTp);
1041 Up =
inner(Up, U1, 0, 1);
1042 VTp =
inner(VTp, U2, 1, 1);
1069 x =
inner(Up, x, 1, 0);
1070 y =
inner(VTp, y, 1, 0);
1095 template <
typename T>
1104 const long rank1 = x1.
dim(0);
1105 const long rank2 = x2.
dim(0);
1106 const long rank = rank1 + rank2;
1109 const Slice s0(0, rank1 - 1), s1(rank1, rank - 1);
1111 const double w_max = std::max(w1.absmax(), w2.absmax());
1112 const double norm_max = w_max * rank;
1127 for (
long i = 0; i < rank; i++) {
1157 const double e1_max =
e1.absmax();
1158 const double e2_max = e2.
absmax();
1161 if ((e1_max * norm_max <
thresh) or (e2_max * norm_max <
thresh)) {
1177 for (
unsigned int r = 0; r < rank; r++) {
1178 if (
e1(r) <
thresh / norm_max) lo1 = r + 1;
1180 if (e2(r) <
thresh / norm_max) lo2 = r + 1;
1181 else sqrt_e2(r) = sqrt(
std::abs(e2(r)));
1186 sqrt_e1 = sqrt_e1(
Slice(lo1, -1));
1187 sqrt_e2 = sqrt_e2(
Slice(lo2, -1));
1188 unsigned int rank_x = rank - lo1;
1189 unsigned int rank_y = rank - lo2;
1201 for (
unsigned int i = 0; i < rank1; ++i) UU1(i,
_) *= w1(i);
1202 for (
unsigned int i = rank1; i < rank; ++i) UU1(i,
_) *= w2(i - rank1);
1209 for (
unsigned int r = 0; r < rank_x; r++) {
1210 double fac = 1.0 / sqrt_e1(r);
1214 for (
unsigned int r = 0; r < rank_y; r++) {
1215 double fac = 1.0 / sqrt_e2(r);
1227 svd(M, Up, Sp, VTp);
1234 Up =
inner(Up, U1, 0, 1);
1235 VTp =
inner(VTp, U2, 1, 1);
1245 for (i = Sp.
dim(0) - 1; i >= 0; i--) {
1259 x1 =
inner(Up1, x1, 0, 0);
1261 y1 =
inner(VTp1, y1, 0, 0);
1263 w1 = Sp(
Slice(0, i));
1278 template <
typename T>
1281 s <<
"dim_ " << sr.
ndim() <<
"\n";;
1282 s <<
"rank_ " << sr.rank_ <<
"\n";;
1283 s <<
"vector_.size()" << sr.
vector_.size() <<
"\n";
1284 s <<
"has_data() " << sr.
has_data() <<
"\n";
1285 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 ...
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
const long * dims() const
Returns the array of tensor dimensions.
Definition basetensor.h:153
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
BaseTensor()
Definition basetensor.h:116
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:94
TensorTypeData< T >::float_scalar_type float_scalar_type
Definition srconf.h:74
SRConf(const long &ndim, const std::array< long, TENSOR_MAXDIM > &dimensions, const long nci)
Definition srconf.h:132
Tensor< T > & ref_vector(const unsigned int &idim)
return reference to one of the vectors F
Definition srconf.h:538
SRConf< T > transform_dir(const Tensor< T > &c, const int &axis) const
Definition srconf.h:884
size_t real_size() const
return the real size of this
Definition srconf.h:720
SRConf< TENSOR_RESULT_TYPE(T, Q)> general_transform(const Tensor< Q > c[]) const
Definition srconf.h:861
const SRConf get_configs(const int &start, const int &end) const
Definition srconf.h:246
unsigned int nCoeff() const
return the number of coefficients
Definition srconf.h:715
std::array< Tensor< T >, 2 > vector_
Definition srconf.h:91
Tensor< T > make_left_vector_with_weights() const
Definition srconf.h:694
void clear()
Definition srconf.h:236
SRConf()
default ctor
Definition srconf.h:123
SRConf< T > transform(const Tensor< T > &c) const
Definition srconf.h:834
bool check_vector_orthonormality(const int ivec) const
check if the terms are orthogonal
Definition srconf.h:634
SRConf & operator=(const T &number)
assign a number to this;
Definition srconf.h:192
bool has_structure() const
return if this has a tensor structure (has not been flattened)
Definition srconf.h:655
bool has_no_data() const
does this have any data?
Definition srconf.h:279
void make_slices()
redo the Slices for getting direct access to the configurations
Definition srconf.h:504
void add_SVD(const SRConf< T > &rhs, const double &thresh)
add two orthonormal configurations, yielding an optimal SVD decomposition
Definition srconf.h:337
void serialize(Archive &ar)
Definition srconf.h:266
Tensor< T >::scalar_type scalar_type
the scalar type of T
Definition srconf.h:73
bool check_dimensions() const
Definition srconf.h:621
void append(const SRConf< T > &rhs, const double_complex fac=1.0)
Definition srconf.h:331
SRConf(const SRConf &rhs)=default
copy ctor (tested); shallow copy
std::vector< Slice > s0
Definition srconf.h:98
void normalize()
normalize the vectors (tested)
Definition srconf.h:592
Tensor< T > tensorT
Definition srconf.h:81
SRConf(const long &ndim, const long *dimensions, const long nci)
Definition srconf.h:125
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:561
TensorTypeData< T >::float_scalar_type svd_normf() const
calculate the Frobenius norm, if this is in SVD form
Definition srconf.h:784
double weights(const unsigned int &i) const
return the weight
Definition srconf.h:679
void set_size_and_dim(long ndim, long k)
Definition srconf.h:204
SRConf< T > copy_slice(const std::array< Slice, TENSOR_MAXDIM > &s) const
return a slice of this (deep copy)
Definition srconf.h:445
std::array< std::vector< Slice >, 2 > make_slices(const std::array< Slice, TENSOR_MAXDIM > &s) const
Definition srconf.h:512
std::vector< Slice > s1
Definition srconf.h:98
Tensor< T > reconstruct() const
reconstruct this to return a full tensor
Definition srconf.h:682
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:150
Tensor< typename Tensor< T >::scalar_type > weights_
for each configuration the weight; length should be r
Definition srconf.h:87
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:139
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:709
long kVec(const int idim) const
Definition srconf.h:548
const Tensor< T > & ref_vector(const unsigned int &idim) const
return reference to one of the vectors F
Definition srconf.h:543
int dim_per_vector(int idim) const
return the number of physical dimensions
Definition srconf.h:673
void set_vectors_and_weights(const Tensor< typename Tensor< T >::scalar_type > &weights, const Tensor< T > &vector1, const Tensor< T > &vector2)
Definition srconf.h:229
long rank() const
return the logicalrank
Definition srconf.h:669
SRConf & operator=(const SRConf &rhs)
assignment operator (tested), shallow copy of vectors
Definition srconf.h:159
static int max_sigma(const double &thresh, const long &rank, const Tensor< double > &w)
Definition srconf.h:109
friend SRConf< T > copy(const SRConf< T > &rhs)
deep copy of rhs, shrink
Definition srconf.h:429
SRConf< T > & emul(const SRConf< T > &other)
perform elementwise Hadamard product
Definition srconf.h:467
~SRConf()
dtor
Definition srconf.h:263
bool has_data() const
does this have any data?
Definition srconf.h:274
friend bool compatible(const SRConf &lhs, const SRConf &rhs)
check compatibility
Definition srconf.h:825
std::enable_if<(TensorTypeData< T >::iscomplexorTensorTypeData< Q >::iscomplex), TENSOR_RESULT_TYPE(T, Q)>::type friend trace(const SRConf< T > &rhs, const SRConf< Q > &lhs)
Definition srconf.h:735
void append(const SRConf< T > &rhs, const double fac=1.0)
append configurations of rhs to this
Definition srconf.h:294
void scale(const double &fac)
scale this by a number
Definition srconf.h:818
TensorTypeData< T >::float_scalar_type normf() const
calculate the Frobenius norm
Definition srconf.h:790
Tensor< T > make_vector_with_weights(const int dim) const
Definition srconf.h:699
bool is_flat() const
return if this has only one additional dimension (apart from rank)
Definition srconf.h:649
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:553
void scale(const double_complex &fac)
Definition srconf.h:820
void make_empty_vectors_and_weights(const long rank)
Definition srconf.h:221
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:395
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:211
void make_structure(bool force=false)
Definition srconf.h:528
std::enable_if<!(TensorTypeData< T >::iscomplexorTensorTypeData< 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:744
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:282
static const long check_orthonormality_frequency
check orthonormality at low rank additions at every xth addition
Definition srconf.h:84
implements a temporary(!) slice of a LowRankTensor
Definition lowranktensor.h:957
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 multidimensional array.
Definition tensor.h:313
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:1759
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition tensor.h:1731
T sum() const
Returns the sum of all elements of the tensor.
Definition tensor.h:1667
Tensor< T > reshape(int ndimnew, const long *d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition tensor.h:1389
TensorTypeData< T >::scalar_type scalar_type
C++ typename of the real type associated with a complex type.
Definition tensor.h:405
Tensor< T > & emul(const Tensor< T > &t)
Inplace multiply by corresponding elements of argument Tensor.
Definition tensor.h:1804
Tensor< T > & screen(double x)
Inplace set elements of *this less than x in absolute magnitude to zero.
Definition tensor.h:763
void clear()
Frees all memory and resests to state of default constructor.
Definition tensor.h:1905
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
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:2327
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition tensor.h:2039
const double beta
Definition gygi_soltion.cc:62
static const double v
Definition hatom_sf_dirac.cc:20
#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
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
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
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:452
double FunctionDefaults< NDIM >::thresh
Definition mraimpl.h:3879
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:2254
int FunctionDefaults< NDIM >::k
Definition mraimpl.h:3878
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:923
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:2300
Tensor< double > tensorT
Definition distpm.cc:21
static Tensor< double > weights[max_npt+1]
Definition legendre.cc:99
static const Slice _(0,-1, 1)
std::enable_if< std::is_base_of< ProjectorBase, projT >::value, OuterProjector< projT, projQ > >::type outer(const projT &p0, const projQ &p1)
Definition projector.h:476
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
void print(const T &t, Ts &&... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:232
GenTensor< TENSOR_RESULT_TYPE(R, Q)> transform_dir(const GenTensor< R > &t, const Tensor< Q > &c, const int axis)
Definition lowranktensor.h:1108
constexpr Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition vector.h:750
Function< T, CCPairFunction< T, NDIM >::LDIM > inner(const CCPairFunction< T, NDIM > &c, const Function< T, CCPairFunction< T, NDIM >::LDIM > &f, const std::tuple< int, int, int > v1, const std::tuple< int, int, int > v2)
Definition ccpairfunction.h:1007
const FunctionCommonData< T, NDIM > * FunctionCommonData< T, NDIM >::data[MAXK]
Definition mraimpl.h:3875
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:2239
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:979
static long abs(long a)
Definition tensor.h:214
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 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
double norm(const T i1)
Definition test_cloud.cc:85
F residual(const F &f)
Definition testcomplexfunctionsolver.cc:69
static const double alpha
Definition testcosine.cc:10
std::size_t axis
Definition testpdiff.cc:59
#define TENSOR_RESULT_TYPE(L, R)
This macro simplifies access to TensorResultType.
Definition type_data.h:205
const double a1
Definition vnucso.cc:85
FLOAT e1(FLOAT z)
Definition y1.cc:144