MADNESS 0.10.1
madness::SRConf< T > Class Template Reference

#include <srconf.h>

Inheritance diagram for madness::SRConf< T >:
Collaboration diagram for madness::SRConf< T >:

Public Types

typedef Tensor< T > tensorT

Public Member Functions

 SRConf ()
 default ctor
 SRConf (const long &ndim, const long *dimensions, const long nci)
 SRConf (const long &ndim, const std::array< long, TENSOR_MAXDIM > &dimensions, const long nci)
 SRConf (const SRConf &rhs)=default
 copy ctor (tested); shallow copy
 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
 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
 ~SRConf ()
 dtor
void add_SVD (const SRConf< T > &rhs, const double &thresh)
 add two orthonormal configurations, yielding an optimal SVD decomposition
void append (const SRConf< T > &rhs, const double fac=1.0)
 append configurations of rhs to this
void append (const SRConf< T > &rhs, const double_complex fac=1.0)
const std::vector< Slice > & c0 (const int idim) const
 return a Slice that corresponds the that part of vector_ that holds coefficients
void clear ()
SRConf< T > copy_slice (const std::array< Slice, TENSOR_MAXDIM > &s) const
 return a slice of this (deep copy)
int dim_per_vector (int idim) const
 return the number of physical dimensions
SRConf< T > & emul (const SRConf< T > &other)
 perform elementwise Hadamard product
Tensor< T > flat_vector (const unsigned int &idim)
 return shallow copy of a slice of one of the vectors, flattened to (r,kVec)
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)
Tensor< T > flat_vector_with_weights (const int dim) const
 return flat (r,i) view of the tensor with the weights multiplied in
template<typename Q>
SRConf< TENSOR_RESULT_TYPE(T, Q)> general_transform (const Tensor< Q > c[]) const
const SRConf get_configs (const int &start, const int &end) const
bool has_data () const
 does this have any data?
bool has_no_data () const
 does this have any data?
bool has_structure () const
 return if this has a tensor structure (has not been flattened)
long kVec (const int idim) const
void make_empty_vectors_and_weights (const long rank)
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
Tensor< T > make_vector_with_weights (const int dim) const
SRConf & operator= (const SRConf &rhs)
 assignment operator (tested), shallow copy of vectors
SRConf & operator= (const T &number)
 assign a number to this;
long rank () const
 return the logicalrank
Tensor< T > reconstruct () const
 reconstruct this to return a full tensor
Tensor< T > & ref_vector (const unsigned int &idim)
 return reference to one of the vectors F
const Tensor< T > & ref_vector (const unsigned int &idim) const
 return reference to one of the vectors F
template<typename Archive>
void serialize (Archive &ar)
void set_size_and_dim (long ndim, long k)
void set_vectors_and_weights (const Tensor< typename Tensor< T >::scalar_type > &weights, const Tensor< T > &vector1, const Tensor< T > &vector2)
SRConf< T > transform_dir (const Tensor< T > &c, const int &axis) const
double weights (const unsigned int &i) const
 return the weight
Public Member Functions inherited from madness::BaseTensor
 BaseTensor ()
virtual ~BaseTensor ()
bool conforms (const BaseTensor *t) const
 Returns true if this and *t are the same shape and size.
long dim (int i) const
 Returns the size of dimension i.
const long * dims () const
 Returns the array of tensor dimensions.
long id () const
 Returns the typeid of the tensor (c.f., TensorTypeData<T> ).
bool iscontiguous () const
 Returns true if the tensor refers to contiguous memory locations.
long ndim () const
 Returns the number of dimensions in the tensor.
long size () const
 Returns the number of elements in the tensor.
long stride (int i) const
 Returns the stride associated with dimension i.
const long * strides () const
 Returns the array of tensor strides.

Static Public Member Functions

static int max_sigma (const double &thresh, const long &rank, const Tensor< double > &w)
Static Public Member Functions inherited from madness::BaseTensor
static int get_instance_count ()
 Returns the count of all current instances of tensors & slice tensors of all types.

Public Attributes

long nci_left = -1
 separation dimensions: A(n,m) -> A(r,n) B(r,m), with n={k1,k2},m={k3,k4,k5..) multi-indices
std::vector< Slice > s0
std::vector< Slice > s1
std::array< Tensor< T >, 2 > vector_
Tensor< typename Tensor< T >::scalar_type > weights_
 for each configuration the weight; length should be r

Static Public Attributes

static const long check_orthonormality_frequency = 100000
 check orthonormality at low rank additions at every xth addition

Protected Member Functions

bool check_dimensions () const
bool check_vector_orthonormality (const int ivec) const
 check if the terms are orthogonal
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)
bool is_flat () const
 return if this has only one additional dimension (apart from rank)
Tensor< T > make_left_vector_with_weights () const
void make_slices ()
 redo the Slices for getting direct access to the configurations
std::array< std::vector< Slice >, 2 > make_slices (const std::array< Slice, TENSOR_MAXDIM > &s) const
void make_structure (bool force=false)
unsigned int nCoeff () const
 return the number of coefficients
void normalize ()
 normalize the vectors (tested)
TensorTypeData< T >::float_scalar_type normf () const
 calculate the Frobenius norm
size_t real_size () const
 return the real size of this
void scale (const double &fac)
 scale this by a number
void scale (const double_complex &fac)
TensorTypeData< T >::float_scalar_type svd_normf () const
 calculate the Frobenius norm, if this is in SVD form
template<typename Q>
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)
template<typename Q>
std::enable_if<(TensorTypeData< T >::iscomplexorTensorTypeData< Q >::iscomplex), TENSOR_RESULT_TYPE(T, Q)>::type friend trace (const SRConf< T > &rhs, const SRConf< Q > &lhs)
SRConf< T > transform (const Tensor< T > &c) const
Protected Member Functions inherited from madness::BaseTensor
void cycledim_inplace (long shift, long start, long end)
 Cyclic shift of dimensions.
void flat_inplace ()
 Reshapes the tensor inplace into 1D.
void fusedim_inplace (long i)
 Fuses dimensions i and i+1.
void mapdim_inplace (const std::vector< long > &map)
 General permutation of dimensions.
void reshape_inplace (const std::vector< long > &d)
 Reshapes the tensor inplace.
void reshape_inplace (int ndimnew, const long *d)
 Reshapes the tensor inplace.
void set_dims_and_size (long nd, const long d[])
void splitdim_inplace (long i, long dimi0, long dimi1)
 Splits dimension i.
void swapdim_inplace (long i, long j)
 Swaps the dimensions.

Private Types

typedef TensorTypeData< T >::float_scalar_type float_scalar_type
typedef Tensor< T >::scalar_type scalar_type
 the scalar type of T

Friends

bool compatible (const SRConf &lhs, const SRConf &rhs)
 check compatibility
SRConf< T > copy (const SRConf< T > &rhs)
 deep copy of rhs, shrink
class GenTensor< T >
class SliceLowRankTensor< T >

Additional Inherited Members

Protected Attributes inherited from madness::BaseTensor
long _dim [TENSOR_MAXDIM]
 Size of each dimension.
long _id
 Id from TensorTypeData<T> in type_data.h.
long _ndim
 Number of dimensions (-1=invalid; 0=no supported; >0=tensor).
long _size
 Number of elements in the tensor.
long _stride [TENSOR_MAXDIM]
 Increment between elements in each dimension.

Detailed Description

template<typename T>
class madness::SRConf< T >

A SRConf handles all the configurations in a Separated Representation.

Member Typedef Documentation

◆ float_scalar_type

template<typename T>
typedef TensorTypeData<T>::float_scalar_type madness::SRConf< T >::float_scalar_type
private

◆ scalar_type

template<typename T>
typedef Tensor<T>::scalar_type madness::SRConf< T >::scalar_type
private

the scalar type of T

◆ tensorT

template<typename T>
typedef Tensor<T> madness::SRConf< T >::tensorT

Constructor & Destructor Documentation

◆ SRConf() [1/6]

◆ SRConf() [2/6]

template<typename T>
madness::SRConf< T >::SRConf ( const long & ndim,
const long * dimensions,
const long nci )
inline

◆ SRConf() [3/6]

template<typename T>
madness::SRConf< T >::SRConf ( const long & ndim,
const std::array< long, TENSOR_MAXDIM > & dimensions,
const long nci )
inline

◆ SRConf() [4/6]

template<typename T>
madness::SRConf< T >::SRConf ( const SRConf< T > & rhs)
default

copy ctor (tested); shallow copy

References SRConf().

◆ SRConf() [5/6]

template<typename T>
madness::SRConf< T >::SRConf ( const Tensor< double > & weights,
const std::vector< Tensor< T > > & vectors,
const long & ndim,
const long & dims,
const long nci )
inline

◆ SRConf() [6/6]

template<typename T>
madness::SRConf< T >::SRConf ( const Tensor< double > & weights,
const tensorT & vector1,
const tensorT & vector2,
const long & ndim,
const long * dims,
const long nci )
inline

◆ ~SRConf()

template<typename T>
madness::SRConf< T >::~SRConf ( )
inline

dtor

Member Function Documentation

◆ add_SVD()

template<typename T>
void madness::SRConf< T >::add_SVD ( const SRConf< T > & rhs,
const double & thresh )
inline

◆ append() [1/2]

template<typename T>
void madness::SRConf< T >::append ( const SRConf< T > & rhs,
const double fac = 1.0 )
inline

append configurations of rhs to this

simplified version of inplace_add for flattened configurations *this += fac*rhs

References SRConf(), c0(), copy, madness::FunctionCommonData< T, NDIM >::data, has_no_data(), has_structure(), MADNESS_ASSERT, make_slices(), make_vector_dimensions(), nci_left, madness::BaseTensor::ndim(), rank(), s0, s1, scale(), vector_, weights(), madness::weights, and weights_.

Referenced by madness::SVDTensor< T >::gaxpy().

◆ append() [2/2]

template<typename T>
void madness::SRConf< T >::append ( const SRConf< T > & rhs,
const double_complex fac = 1.0 )
inline

References SRConf(), and MADNESS_EXCEPTION.

◆ c0()

template<typename T>
const std::vector< Slice > & madness::SRConf< T >::c0 ( const int idim) const
inline

return a Slice that corresponds the that part of vector_ that holds coefficients

References MADNESS_EXCEPTION, s0, and s1.

Referenced by append(), check_vector_orthonormality(), and copy.

◆ check_dimensions()

template<typename T>
bool madness::SRConf< T >::check_dimensions ( ) const
inlineprotected

◆ check_vector_orthonormality()

template<typename T>
bool madness::SRConf< T >::check_vector_orthonormality ( const int ivec) const
inlineprotected

check if the terms are orthogonal

Parameters
[in]ivecwhich vector (0 or 1) to check

References c0(), madness::BaseTensor::dim(), madness::inner(), kVec(), norm(), madness::Tensor< T >::normf(), rank(), ref_vector(), madness::BaseTensor::size(), and small.

Referenced by add_SVD().

◆ clear()

template<typename T>
void madness::SRConf< T >::clear ( )
inline

◆ copy_slice()

template<typename T>
SRConf< T > madness::SRConf< T >::copy_slice ( const std::array< Slice, TENSOR_MAXDIM > & s) const
inline

◆ dim_per_vector()

template<typename T>
int madness::SRConf< T >::dim_per_vector ( int idim) const
inline

return the number of physical dimensions

References MADNESS_ASSERT, and vector_.

Referenced by madness::SeparatedConvolution< double, 3 >::apply2_lowdim(), compatible, normalize(), and transform_dir().

◆ emul()

◆ flat_vector() [1/2]

template<typename T>
Tensor< T > madness::SRConf< T >::flat_vector ( const unsigned int & idim)
inline

return shallow copy of a slice of one of the vectors, flattened to (r,kVec)

References kVec(), MADNESS_ASSERT, rank(), and vector_.

◆ flat_vector() [2/2]

template<typename T>
const Tensor< T > madness::SRConf< T >::flat_vector ( const unsigned int & idim) const
inline

◆ flat_vector_with_weights()

template<typename T>
Tensor< T > madness::SRConf< T >::flat_vector_with_weights ( const int dim) const
inline

return flat (r,i) view of the tensor with the weights multiplied in

return a(r,i) = vec(dim)(r,i) * w(r)

References madness::BaseTensor::dim(), make_vector_with_weights(), rank(), madness::BaseTensor::size(), and vector_.

◆ general_transform()

template<typename T>
template<typename Q>
SRConf< TENSOR_RESULT_TYPE(T, Q)> madness::SRConf< T >::general_transform ( const Tensor< Q > c[]) const
inline
result(i,j,k,...) <-- sum(i',j', k',...) t(i',j',k',...) c(i',i) c(j',j) c(k',k) ...
int FunctionDefaults< NDIM >::k
Definition mraimpl.h:3878
static const double c
Definition relops.cc:10
AtomicInt sum
Definition test_atomicint.cc:46

The input dimensions of t must all be the same .

References SRConf(), c, copy, madness::BaseTensor::dims(), has_no_data(), has_structure(), madness::inner(), MADNESS_ASSERT, nci_left, madness::BaseTensor::ndim(), Q(), rank(), set_vectors_and_weights(), vector_, and weights_.

◆ get_configs()

template<typename T>
const SRConf madness::SRConf< T >::get_configs ( const int & start,
const int & end ) const
inline

◆ has_data()

template<typename T>
bool madness::SRConf< T >::has_data ( ) const
inline

does this have any data?

References madness::BaseTensor::size().

Referenced by copy, GenTensor< T >, and has_no_data().

◆ has_no_data()

◆ has_structure()

template<typename T>
bool madness::SRConf< T >::has_structure ( ) const
inline

◆ inplace_add()

template<typename T>
void madness::SRConf< T >::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 )
inlineprotected

alpha * this(lhs_s) + beta * rhs(rhs_s)

bounds checking should have been performed by caller s denotes where in lhs the new contribution from rhs will be inserted

References SRConf(), alpha, beta, madness::BaseTensor::dims(), has_no_data(), has_structure(), MADNESS_ASSERT, make_empty_vectors_and_weights(), make_slices(), nci_left, madness::BaseTensor::ndim(), rank(), s0, s1, vector_, and weights_.

◆ is_flat()

template<typename T>
bool madness::SRConf< T >::is_flat ( ) const
inlineprotected

return if this has only one additional dimension (apart from rank)

References madness::BaseTensor::ndim(), and vector_.

◆ kVec()

template<typename T>
long madness::SRConf< T >::kVec ( const int idim) const
inline

◆ make_empty_vectors_and_weights()

template<typename T>
void madness::SRConf< T >::make_empty_vectors_and_weights ( const long rank)
inline

◆ make_left_vector_with_weights()

template<typename T>
Tensor< T > madness::SRConf< T >::make_left_vector_with_weights ( ) const
inlineprotected

◆ make_slices() [1/2]

template<typename T>
void madness::SRConf< T >::make_slices ( )
inlineprotected

redo the Slices for getting direct access to the configurations

References madness::_(), nci_left, madness::BaseTensor::ndim(), rank(), s0, and s1.

Referenced by add_SVD(), append(), copy_slice(), inplace_add(), and make_structure().

◆ make_slices() [2/2]

template<typename T>
std::array< std::vector< Slice >, 2 > madness::SRConf< T >::make_slices ( const std::array< Slice, TENSOR_MAXDIM > & s) const
inlineprotected

◆ make_structure()

◆ make_vector_dimensions()

template<typename T>
std::array< std::array< long, TENSOR_MAXDIM >, 2 > madness::SRConf< T >::make_vector_dimensions ( const long rank) const
inline

deduce the dimensions of the left and right singular vectors from the tensor dimensions

References madness::BaseTensor::dim(), nci_left, madness::BaseTensor::ndim(), and rank().

Referenced by append(), madness::SVDTensor< T >::concatenate(), has_structure(), make_empty_vectors_and_weights(), and make_structure().

◆ make_vector_with_weights()

◆ max_sigma()

template<typename T>
int madness::SRConf< T >::max_sigma ( const double & thresh,
const long & rank,
const Tensor< double > & w )
inlinestatic

return the index of the last singular vector/value to meet the threshold (returns -1 if all meet threshold, i.e. || A ||_2 < threshold) given a matrix A in SVD form, truncate the singular values such that the accuracy threshold is still met.

Parameters
[in]threshthe threshold eps: || A - A(truncated) || < eps
[in]rankthe number of singular values in w
[in]wthe weights/singular values of A
Returns
i the index of s_max to contribute: w(Slice(0,i)); i.e. inclusive!

References madness::FunctionDefaults< NDIM >::thresh, rank(), residual(), and w().

Referenced by madness::SeparatedConvolution< double, 3 >::apply2(), madness::SVDTensor< T >::compute_svd(), madness::TensorTrain< T >::decompose(), madness::SeparatedConvolution< double, 3 >::estimate_costs(), madness::ortho3(), madness::rank_revealing_decompose(), madness::TensorTrain< T >::splitdim(), test_stuff(), madness::TensorTrain< T >::truncate(), and madness::SVDTensor< T >::truncate_svd().

◆ nCoeff()

template<typename T>
unsigned int madness::SRConf< T >::nCoeff ( ) const
inlineprotected

return the number of coefficients

References vector_, and weights_.

Referenced by madness::SVDTensor< T >::nCoeff().

◆ normalize()

template<typename T>
void madness::SRConf< T >::normalize ( )
inlineprotected

◆ normf()

◆ operator=() [1/2]

◆ operator=() [2/2]

template<typename T>
SRConf & madness::SRConf< T >::operator= ( const T & number)
inline

◆ rank()

◆ real_size()

template<typename T>
size_t madness::SRConf< T >::real_size ( ) const
inlineprotected

return the real size of this

References s1, vector_, and weights_.

◆ reconstruct()

template<typename T>
Tensor< T > madness::SRConf< T >::reconstruct ( ) const
inline

◆ ref_vector() [1/2]

template<typename T>
Tensor< T > & madness::SRConf< T >::ref_vector ( const unsigned int & idim)
inline

return reference to one of the vectors F

References vector_.

Referenced by madness::SeparatedConvolution< double, 3 >::apply2_lowdim(), check_vector_orthonormality(), and transform_dir().

◆ ref_vector() [2/2]

template<typename T>
const Tensor< T > & madness::SRConf< T >::ref_vector ( const unsigned int & idim) const
inline

return reference to one of the vectors F

References vector_.

◆ scale() [1/2]

template<typename T>
void madness::SRConf< T >::scale ( const double & fac)
inlineprotected

scale this by a number

References weights_.

Referenced by append(), madness::SVDTensor< T >::gaxpy(), and normalize().

◆ scale() [2/2]

template<typename T>
void madness::SRConf< T >::scale ( const double_complex & fac)
inlineprotected

References MADNESS_EXCEPTION.

◆ serialize()

◆ set_size_and_dim()

template<typename T>
void madness::SRConf< T >::set_size_and_dim ( long ndim,
long k )
inline

◆ set_vectors_and_weights()

◆ svd_normf()

template<typename T>
TensorTypeData< T >::float_scalar_type madness::SRConf< T >::svd_normf ( ) const
inlineprotected

calculate the Frobenius norm, if this is in SVD form

References has_no_data(), rank(), and weights_.

◆ trace() [1/2]

template<typename T>
template<typename Q>
std::enable_if<!(TensorTypeData< T >::iscomplexorTensorTypeData< Q >::iscomplex), TENSOR_RESULT_TYPE(T, Q)>::type friend madness::SRConf< T >::trace ( const SRConf< T > & rhs,
const SRConf< Q > & lhs )
inlineprotected

◆ trace() [2/2]

template<typename T>
template<typename Q>
std::enable_if<(TensorTypeData< T >::iscomplexorTensorTypeData< Q >::iscomplex), TENSOR_RESULT_TYPE(T, Q)>::type friend madness::SRConf< T >::trace ( const SRConf< T > & rhs,
const SRConf< Q > & lhs )
inlineprotected

References SRConf(), and MADNESS_EXCEPTION.

◆ transform()

template<typename T>
SRConf< T > madness::SRConf< T >::transform ( const Tensor< T > & c) const
inlineprotected
result(i,j,k,...) <-- sum(i',j', k',...) t(i',j',k',...) c(i',i) c(j',j) c(k',k) ...

The input dimensions of t must all be the same .

References SRConf(), c, copy, madness::BaseTensor::dims(), has_no_data(), has_structure(), madness::inner(), MADNESS_ASSERT, nci_left, madness::BaseTensor::ndim(), rank(), set_vectors_and_weights(), vector_, and weights_.

◆ transform_dir()

template<typename T>
SRConf< T > madness::SRConf< T >::transform_dir ( const Tensor< T > & c,
const int & axis ) const
inline

◆ weights()

◆ compatible

template<typename T>
bool compatible ( const SRConf< T > & lhs,
const SRConf< T > & rhs )
friend

◆ copy

◆ GenTensor< T >

template<typename T>
friend class GenTensor< T >
friend

◆ SliceLowRankTensor< T >

template<typename T>
friend class SliceLowRankTensor< T >
friend

Member Data Documentation

◆ check_orthonormality_frequency

template<typename T>
const long madness::SRConf< T >::check_orthonormality_frequency = 100000
static

check orthonormality at low rank additions at every xth addition

Referenced by add_SVD().

◆ nci_left

◆ s0

template<typename T>
std::vector<Slice> madness::SRConf< T >::s0

Slice containing the actual data in each vector, ignoring "empty" configurations; will maintain contiguity of the data.

Referenced by append(), c0(), inplace_add(), make_slices(), operator=(), and serialize().

◆ s1

template<typename T>
std::vector<Slice> madness::SRConf< T >::s1

◆ vector_

◆ weights_


The documentation for this class was generated from the following files: