TiledArray  0.7.0
TiledArray::SparseShape< T > Class Template Reference

Arbitrary sparse shape. More...

#include <sparse_shape.h>

Public Types

typedef SparseShape< T > SparseShape_
 This object type. More...
 
typedef T value_type
 The norm value type. More...
 
typedef Tensor< value_type >::size_type size_type
 Size type. More...
 

Public Member Functions

 SparseShape ()
 Default constructor. More...
 
 SparseShape (const Tensor< value_type > &tile_norms, const TiledRange &trange)
 Constructor. More...
 
template<typename SparseNormSequence >
 SparseShape (const SparseNormSequence &tile_norms, const TiledRange &trange)
 "Sparse" constructor More...
 
 SparseShape (World &world, const Tensor< value_type > &tile_norms, const TiledRange &trange)
 Collective "dense" constructor. More...
 
template<typename SparseNormSequence >
 SparseShape (World &world, const SparseNormSequence &tile_norms, const TiledRange &trange)
 Collective "sparse" constructor. More...
 
 SparseShape (const SparseShape< T > &other)
 Copy constructor. More...
 
SparseShape< T > & operator= (const SparseShape< T > &other)
 Copy assignment operator. More...
 
bool validate (const Range &range) const
 Validate shape range. More...
 
template<typename Index >
bool is_zero (const Index &i) const
 Check that a tile is zero. More...
 
float sparsity () const
 Sparsity of the shape. More...
 
template<typename Index >
value_type operator[] (const Index &index) const
 Tile norm accessor. More...
 
template<typename Op >
SparseShape_ transform (Op &&op) const
 Transform the norm tensor with an operation. More...
 
const Tensor< value_type > & data () const
 Data accessor. More...
 
bool empty () const
 Initialization check. More...
 
SparseShape_ mask (const SparseShape_ &mask_shape) const
 Compute union of two shapes. More...
 
template<typename Index >
SparseShape update_block (const Index &lower_bound, const Index &upper_bound, const SparseShape &other) const
 Update sub-block of shape. More...
 
template<typename Index >
SparseShape block (const Index &lower_bound, const Index &upper_bound) const
 Create a copy of a sub-block of the shape. More...
 
template<typename Index , typename Factor >
SparseShape block (const Index &lower_bound, const Index &upper_bound, const Factor factor) const
 Create a scaled sub-block of the shape. More...
 
template<typename Index >
SparseShape block (const Index &lower_bound, const Index &upper_bound, const Permutation &perm) const
 Create a copy of a sub-block of the shape. More...
 
template<typename Index , typename Factor >
SparseShape block (const Index &lower_bound, const Index &upper_bound, const Factor factor, const Permutation &perm) const
 Create a copy of a sub-block of the shape. More...
 
SparseShape_ perm (const Permutation &perm) const
 Create a permuted shape of this shape. More...
 
template<typename Factor >
SparseShape_ scale (const Factor factor) const
 Scale shape. More...
 
template<typename Factor >
SparseShape_ scale (const Factor factor, const Permutation &perm) const
 Scale and permute shape. More...
 
SparseShape_ add (const SparseShape_ &other) const
 Add shapes. More...
 
SparseShape_ add (const SparseShape_ &other, const Permutation &perm) const
 Add and permute shapes. More...
 
template<typename Factor >
SparseShape_ add (const SparseShape_ &other, const Factor factor) const
 Add and scale shapes. More...
 
template<typename Factor >
SparseShape_ add (const SparseShape_ &other, const Factor factor, const Permutation &perm) const
 Add, scale, and permute shapes. More...
 
SparseShape_ add (value_type value) const
 
SparseShape_ add (const value_type value, const Permutation &perm) const
 
SparseShape_ subt (const SparseShape_ &other) const
 
SparseShape_ subt (const SparseShape_ &other, const Permutation &perm) const
 
template<typename Factor >
SparseShape_ subt (const SparseShape_ &other, const Factor factor) const
 
template<typename Factor >
SparseShape_ subt (const SparseShape_ &other, const Factor factor, const Permutation &perm) const
 
SparseShape_ subt (const value_type value) const
 
SparseShape_ subt (const value_type value, const Permutation &perm) const
 
SparseShape_ mult (const SparseShape_ &other) const
 
SparseShape_ mult (const SparseShape_ &other, const Permutation &perm) const
 
template<typename Factor >
SparseShape_ mult (const SparseShape_ &other, const Factor factor) const
 
template<typename Factor >
SparseShape_ mult (const SparseShape_ &other, const Factor factor, const Permutation &perm) const
 
template<typename Factor >
SparseShape_ gemm (const SparseShape_ &other, const Factor factor, const math::GemmHelper &gemm_helper) const
 
template<typename Factor >
SparseShape_ gemm (const SparseShape_ &other, const Factor factor, const math::GemmHelper &gemm_helper, const Permutation &perm) const
 

Static Public Member Functions

static constexpr bool is_dense ()
 Check density. More...
 
static value_type threshold ()
 Threshold accessor. More...
 
static void threshold (const value_type thresh)
 Set threshold to thresh. More...
 

Detailed Description

template<typename T>
class TiledArray::SparseShape< T >

Arbitrary sparse shape.

Sparse shape uses a Tensor of Frobenius norms to estimate the magnitude of the data contained in tiles of an Array object. Because tiles may have an arbitrary size, the norm data is normalized, internally, by dividing the norms by the number of elements in each tile.

\[ {\rm{shape}}_{ij...} = \frac{\|A_{ij...}\|}{N_i N_j ...} \]

where $ij...$ are tile indices, $\|A_{ij}\|$ is norm of tile $ij...$, and $N_i N_j ...$ is the product of tile $ij...$ in each dimension.

Template Parameters
TThe sparse element value type
Note
Scaling operations, such as SparseShape<T>::scale , SparseShape<T>::gemm , etc. accept generic scaling factors; internally (modulus of) the scaling factor is first converted to T, then used (see SparseShape<T>::to_abs_factor).

Definition at line 55 of file sparse_shape.h.

Member Typedef Documentation

◆ size_type

template<typename T>
typedef Tensor<value_type>::size_type TiledArray::SparseShape< T >::size_type

Size type.

Definition at line 60 of file sparse_shape.h.

◆ SparseShape_

template<typename T>
typedef SparseShape<T> TiledArray::SparseShape< T >::SparseShape_

This object type.

Definition at line 57 of file sparse_shape.h.

◆ value_type

template<typename T>
typedef T TiledArray::SparseShape< T >::value_type

The norm value type.

Definition at line 58 of file sparse_shape.h.

Constructor & Destructor Documentation

◆ SparseShape() [1/6]

template<typename T>
TiledArray::SparseShape< T >::SparseShape ( )
inline

Default constructor.

Construct a shape with no data.

Definition at line 210 of file sparse_shape.h.

Here is the caller graph for this function:

◆ SparseShape() [2/6]

template<typename T>
TiledArray::SparseShape< T >::SparseShape ( const Tensor< value_type > &  tile_norms,
const TiledRange trange 
)
inline

Constructor.

This constructor will normalize the tile norm, where the normalization constant for each tile is the inverse of the number of elements in the tile.

Parameters
tile_normsThe Frobenius norm of tiles
trangeThe tiled range of the tensor

Definition at line 219 of file sparse_shape.h.

Here is the call graph for this function:

◆ SparseShape() [3/6]

template<typename T>
template<typename SparseNormSequence >
TiledArray::SparseShape< T >::SparseShape ( const SparseNormSequence &  tile_norms,
const TiledRange trange 
)
inline

"Sparse" constructor

This constructor uses tile norms given as a sparse tensor, represented as a sequence of {index,value_type} data. The tile norms are normalized to per-element norms by dividing each norm by the number of elements in the corresponding tile.

Template Parameters
SparseNormSequencethe sequence of std::pair<index,value_type> objects, where index is a directly-addressable sequence indices.
Parameters
tile_normsThe Frobenius norm of tiles
trangeThe tiled range of the tensor

Definition at line 240 of file sparse_shape.h.

Here is the call graph for this function:

◆ SparseShape() [4/6]

template<typename T>
TiledArray::SparseShape< T >::SparseShape ( World &  world,
const Tensor< value_type > &  tile_norms,
const TiledRange trange 
)
inline

Collective "dense" constructor.

This constructor uses tile norms given as a dense tensor. The tile norms data are summed across all processes (via an all reduce). Next, the norms are converted to per-element norms by dividing each norm by the number of elements in the corresponding tile.

Parameters
worldThe world where the shape will live
tile_normsThe Frobenius norm of tiles
trangeThe tiled range of the tensor

Definition at line 271 of file sparse_shape.h.

Here is the call graph for this function:

◆ SparseShape() [5/6]

template<typename T>
template<typename SparseNormSequence >
TiledArray::SparseShape< T >::SparseShape ( World &  world,
const SparseNormSequence &  tile_norms,
const TiledRange trange 
)
inline

Collective "sparse" constructor.

This constructor uses tile norms given as a sparse tensor, represented as a sequence of {index,value_type} data. The tile norms are normalized to per-element norms by dividing each norm by the number of elements in the corresponding tile. Lastly, he norms are sum-reduced across all processors.

Template Parameters
SparseNormSequencethe sequence of std::pair<index,value_type> objects, where index is a directly-addressable sequence of integers.
Parameters
worldThe world where the shape will live
tile_normsThe Frobenius norm of tiles
trangeThe tiled range of the tensor

Definition at line 298 of file sparse_shape.h.

Here is the call graph for this function:

◆ SparseShape() [6/6]

template<typename T>
TiledArray::SparseShape< T >::SparseShape ( const SparseShape< T > &  other)
inline

Copy constructor.

Shallow copy of other.

Parameters
otherThe other shape object to be copied

Definition at line 309 of file sparse_shape.h.

Member Function Documentation

◆ add() [1/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::add ( const SparseShape_ other) const
inline

Add shapes.

Construct a new sum of shapes as:

\[ {(\rm{result})}_{ij...} = (\rm{this})_{ij...} + (\rm{other})_{ij...} \]

Parameters
otherThe shape to be added to this shape
Returns
A sum of shapes

Definition at line 701 of file sparse_shape.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add() [2/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::add ( const SparseShape_ other,
const Permutation perm 
) const
inline

Add and permute shapes.

Construct a new sum of shapes as:

\[ {(\rm{result})}_{ji...} = \rm{perm}(i,j) (\rm{this})_{ij...} + (\rm{other})_{ij...} \]

Parameters
otherThe shape to be added to this shape
permThe permutation that is applied to the result
Returns
the new shape, equals this + other

Definition at line 732 of file sparse_shape.h.

Here is the call graph for this function:

◆ add() [3/6]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::add ( const SparseShape_ other,
const Factor  factor 
) const
inline

Add and scale shapes.

Construct a new sum of shapes as:

\[ {(\rm{result})}_{ij...} = |(\rm{factor})| ((\rm{this})_{ij...} + (\rm{other})_{ij...}) \]

Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)
Parameters
otherThe shape to be added to this shape
factorThe scaling factor
Returns
A scaled sum of shapes

Definition at line 767 of file sparse_shape.h.

Here is the call graph for this function:

◆ add() [4/6]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::add ( const SparseShape_ other,
const Factor  factor,
const Permutation perm 
) const
inline

Add, scale, and permute shapes.

Construct a new sum of shapes as:

\[ {(\rm{result})}_{ij...} = |(\rm{factor})| ((\rm{this})_{ij...} + (\rm{other})_{ij...}) \]

Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)
Parameters
otherThe shape to be added to this shape
factorThe scaling factor
permThe permutation that is applied to the result
Returns
A scaled and permuted sum of shapes

Definition at line 804 of file sparse_shape.h.

Here is the call graph for this function:

◆ add() [5/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::add ( value_type  value) const
inline

Definition at line 831 of file sparse_shape.h.

Here is the call graph for this function:

◆ add() [6/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::add ( const value_type  value,
const Permutation perm 
) const
inline

Definition at line 891 of file sparse_shape.h.

Here is the call graph for this function:

◆ block() [1/4]

template<typename T>
template<typename Index >
SparseShape TiledArray::SparseShape< T >::block ( const Index &  lower_bound,
const Index &  upper_bound 
) const
inline

Create a copy of a sub-block of the shape.

Template Parameters
IndexThe upper and lower bound array type
Parameters
lower_boundThe lower bound of the sub-block
upper_boundThe upper bound of the sub-block

Definition at line 530 of file sparse_shape.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block() [2/4]

template<typename T>
template<typename Index , typename Factor >
SparseShape TiledArray::SparseShape< T >::block ( const Index &  lower_bound,
const Index &  upper_bound,
const Factor  factor 
) const
inline

Create a scaled sub-block of the shape.

Template Parameters
IndexThe upper and lower bound array type
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)
Parameters
lower_boundThe lower bound of the sub-block
upper_boundThe upper bound of the sub-block

Definition at line 565 of file sparse_shape.h.

Here is the call graph for this function:

◆ block() [3/4]

template<typename T>
template<typename Index >
SparseShape TiledArray::SparseShape< T >::block ( const Index &  lower_bound,
const Index &  upper_bound,
const Permutation perm 
) const
inline

Create a copy of a sub-block of the shape.

Parameters
lower_boundThe lower bound of the sub-block
upper_boundThe upper bound of the sub-block

Definition at line 600 of file sparse_shape.h.

Here is the call graph for this function:

◆ block() [4/4]

template<typename T>
template<typename Index , typename Factor >
SparseShape TiledArray::SparseShape< T >::block ( const Index &  lower_bound,
const Index &  upper_bound,
const Factor  factor,
const Permutation perm 
) const
inline

Create a copy of a sub-block of the shape.

Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)
Parameters
lower_boundThe lower bound of the sub-block
upper_boundThe upper bound of the sub-block

Definition at line 614 of file sparse_shape.h.

Here is the call graph for this function:

◆ data()

template<typename T>
const Tensor<value_type>& TiledArray::SparseShape< T >::data ( ) const
inline

Data accessor.

Returns
A reference to the Tensor object that stores shape data

Definition at line 414 of file sparse_shape.h.

◆ empty()

template<typename T>
bool TiledArray::SparseShape< T >::empty ( ) const
inline

Initialization check.

Returns
true when this shape has been initialized.

Definition at line 419 of file sparse_shape.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gemm() [1/2]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::gemm ( const SparseShape_ other,
const Factor  factor,
const math::GemmHelper gemm_helper 
) const
inline
Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)

Definition at line 1041 of file sparse_shape.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gemm() [2/2]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::gemm ( const SparseShape_ other,
const Factor  factor,
const math::GemmHelper gemm_helper,
const Permutation perm 
) const
inline
Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)

Definition at line 1130 of file sparse_shape.h.

Here is the call graph for this function:

◆ is_dense()

template<typename T>
static constexpr bool TiledArray::SparseShape< T >::is_dense ( )
inlinestatic

Check density.

Returns
true

Definition at line 348 of file sparse_shape.h.

◆ is_zero()

template<typename T>
template<typename Index >
bool TiledArray::SparseShape< T >::is_zero ( const Index &  i) const
inline

Check that a tile is zero.

Template Parameters
IndexThe type of the index
Returns
false

Definition at line 340 of file sparse_shape.h.

Here is the call graph for this function:

◆ mask()

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::mask ( const SparseShape_ mask_shape) const
inline

Compute union of two shapes.

Parameters
maskThe input shape, hard zeros are used to mask the output.
Returns
A shape that is masked by the mask.

Definition at line 425 of file sparse_shape.h.

Here is the call graph for this function:

◆ mult() [1/4]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::mult ( const SparseShape_ other) const
inline

Definition at line 978 of file sparse_shape.h.

Here is the call graph for this function:

◆ mult() [2/4]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::mult ( const SparseShape_ other,
const Permutation perm 
) const
inline

Definition at line 990 of file sparse_shape.h.

Here is the call graph for this function:

◆ mult() [3/4]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::mult ( const SparseShape_ other,
const Factor  factor 
) const
inline
Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)

Definition at line 1006 of file sparse_shape.h.

Here is the call graph for this function:

◆ mult() [4/4]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::mult ( const SparseShape_ other,
const Factor  factor,
const Permutation perm 
) const
inline
Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)

Definition at line 1022 of file sparse_shape.h.

Here is the call graph for this function:

◆ operator=()

template<typename T>
SparseShape<T>& TiledArray::SparseShape< T >::operator= ( const SparseShape< T > &  other)
inline

Copy assignment operator.

Shallow copy of other.

Parameters
otherThe other shape object to be copied
Returns
A reference to this object.

Definition at line 319 of file sparse_shape.h.

◆ operator[]()

template<typename T>
template<typename Index >
value_type TiledArray::SparseShape< T >::operator[] ( const Index &  index) const
inline

Tile norm accessor.

Template Parameters
IndexThe index type
Parameters
indexThe index of the tile norm to retrieve
Returns
The norm of the tile at index

Definition at line 374 of file sparse_shape.h.

Here is the call graph for this function:

◆ perm()

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::perm ( const Permutation perm) const
inline

Create a permuted shape of this shape.

Parameters
permThe permutation to be applied
Returns
A new, permuted shape

Definition at line 624 of file sparse_shape.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scale() [1/2]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::scale ( const Factor  factor) const
inline

Scale shape.

Construct a new scaled shape as:

\[ {(\rm{result})}_{ij...} = |(\rm{factor})| (\rm{this})_{ij...} \]

Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)
Parameters
factorThe scaling factor
Returns
A new, scaled shape

Definition at line 640 of file sparse_shape.h.

Here is the call graph for this function:

◆ scale() [2/2]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::scale ( const Factor  factor,
const Permutation perm 
) const
inline

Scale and permute shape.

Compute a new scaled shape is computed as:

\[ {(\rm{result})}_{ji...} = \rm{perm}(j,i) |(\rm{factor})| (\rm{this})_{ij...} \]

Template Parameters
FactorThe scaling factor type
Note
expression abs(Factor) must be well defined (by default, std::abs will be used)
Parameters
factorThe scaling factor
permThe permutation that will be applied to this tensor.
Returns
A new, scaled-and-permuted shape

Definition at line 672 of file sparse_shape.h.

Here is the call graph for this function:

◆ sparsity()

template<typename T>
float TiledArray::SparseShape< T >::sparsity ( ) const
inline

Sparsity of the shape.

Returns
The fraction of tiles that are zero.

Definition at line 353 of file sparse_shape.h.

Here is the call graph for this function:

◆ subt() [1/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::subt ( const SparseShape_ other) const
inline

Definition at line 897 of file sparse_shape.h.

Here is the call graph for this function:

◆ subt() [2/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::subt ( const SparseShape_ other,
const Permutation perm 
) const
inline

Definition at line 901 of file sparse_shape.h.

Here is the call graph for this function:

◆ subt() [3/6]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::subt ( const SparseShape_ other,
const Factor  factor 
) const
inline

Definition at line 906 of file sparse_shape.h.

Here is the call graph for this function:

◆ subt() [4/6]

template<typename T>
template<typename Factor >
SparseShape_ TiledArray::SparseShape< T >::subt ( const SparseShape_ other,
const Factor  factor,
const Permutation perm 
) const
inline

Definition at line 911 of file sparse_shape.h.

Here is the call graph for this function:

◆ subt() [5/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::subt ( const value_type  value) const
inline

Definition at line 917 of file sparse_shape.h.

Here is the call graph for this function:

◆ subt() [6/6]

template<typename T>
SparseShape_ TiledArray::SparseShape< T >::subt ( const value_type  value,
const Permutation perm 
) const
inline

Definition at line 921 of file sparse_shape.h.

Here is the call graph for this function:

◆ threshold() [1/2]

template<typename T>
static value_type TiledArray::SparseShape< T >::threshold ( )
inlinestatic

Threshold accessor.

Returns
The current threshold

Definition at line 361 of file sparse_shape.h.

Here is the caller graph for this function:

◆ threshold() [2/2]

template<typename T>
static void TiledArray::SparseShape< T >::threshold ( const value_type  thresh)
inlinestatic

Set threshold to thresh.

Parameters
threshThe new threshold

Definition at line 366 of file sparse_shape.h.

◆ transform()

template<typename T>
template<typename Op >
SparseShape_ TiledArray::SparseShape< T >::transform ( Op &&  op) const
inline

Transform the norm tensor with an operation.

Returns
A deep copy of the norms of the object having performed the operation Op.
Op should take a const ref to a Tensor<T> and return a Tensor<T> Since the input tile norms have already been normalized the output norms will avoid normalization, which is neccesary for correct behavior.
One example is when Op is an identity operation the output SparseShape data will have the same values as this.

Definition at line 389 of file sparse_shape.h.

Here is the call graph for this function:

◆ update_block()

template<typename T>
template<typename Index >
SparseShape TiledArray::SparseShape< T >::update_block ( const Index &  lower_bound,
const Index &  upper_bound,
const SparseShape< T > &  other 
) const
inline

Update sub-block of shape.

Update a sub-block shape information with another shape object.

Template Parameters
IndexThe bound index type
Parameters
lower_boundThe lower bound of the sub-block to be updated
upper_boundThe upper bound of the sub-block to be updated
otherThe shape that will be used to update the sub-block
Returns
A new sparse shape object where the specified sub-block contains the data result_tile_norms of other.

Definition at line 460 of file sparse_shape.h.

Here is the call graph for this function:

◆ validate()

template<typename T>
bool TiledArray::SparseShape< T >::validate ( const Range range) const
inline

Validate shape range.

Returns
true when range matches the range of this shape

Definition at line 329 of file sparse_shape.h.

Here is the call graph for this function:

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