MADNESS
version 0.9
|
The base class for tensors defines generic capabilities. More...
#include <basetensor.h>
Public Member Functions | |
BaseTensor () | |
virtual | ~BaseTensor () |
long | size () const |
Returns the number of elements in the tensor. More... | |
long | id () const |
Returns the typeid of the tensor (c.f., TensorTypeData<T> ) More... | |
long | ndim () const |
Returns the number of dimensions in the tensor. More... | |
long | dim (int i) const |
Returns the size of dmension i . More... | |
long | stride (int i) const |
Returns the stride associated with dimension i . More... | |
const long * | dims () const |
Returns the array of tensor dimensions. More... | |
const long * | strides () const |
Returns the array of tensor strides. More... | |
bool | conforms (const BaseTensor *t) const |
Returns true if this and *t are the same shape and size. More... | |
bool | iscontiguous () const |
Returns true if the tensor refers to contiguous memory locations. More... | |
Static Public Member Functions | |
static int | get_instance_count () |
Returns the count of all current instances of tensors & slice tensors of all types. More... | |
Protected Member Functions | |
void | set_dims_and_size (long nd, const long d[]) |
void | reshape_inplace (const std::vector< long > &d) |
Reshapes the tensor inplace. More... | |
void | reshape_inplace (int ndimnew, const long *d) |
Reshapes the tensor inplace. More... | |
void | flat_inplace () |
Reshapes the tensor inplace into 1D. More... | |
void | splitdim_inplace (long i, long dimi0, long dimi1) |
Splits dimension i . More... | |
void | fusedim_inplace (long i) |
Fuses dimensions i and i+1 . More... | |
void | swapdim_inplace (long i, long j) |
Swaps the dimensions. More... | |
void | cycledim_inplace (long shift, long start, long end) |
Cyclic shift of dimensions. More... | |
void | mapdim_inplace (const std::vector< long > &map) |
General permutation of dimensions. More... | |
Protected Attributes | |
long | _size |
Number of elements in the tensor. More... | |
long | _ndim |
Number of dimensions (-1=invalid; 0=scalar; >0=tensor) More... | |
long | _id |
Id from TensorTypeData<T> in type_data.h. More... | |
long | _dim [TENSOR_MAXDIM] |
Size of each dimension. More... | |
long | _stride [TENSOR_MAXDIM] |
Increment between elements in each dimension. More... | |
The base class for tensors defines generic capabilities.
The base class manages the size, dimension and stride information, and provides operations to manipulate them.
It also provides methods for type-safe operation on tensors using just the base class pointers. This interface is primarily useful only to the interface to Python, since Python is largely neutral to (and ignorant of) the type. These are still being re-implemented after the big clean up.
Since the base tensor class is virtual, you cannot have an instance of it. Thus, in addition to methods that return information or perform checks, there are two types of base tensor operations.
*this
, and return void
.new
on the heap. The caller is responsible for eventually freeing the memory using delete
.
|
inline |
|
inlinevirtual |
|
inline |
|
protected |
Cyclic shift of dimensions.
Cyclic shift by nshift places of the inclusive range of dimensions [start,....,end].
References _dim, _ndim, _stride, TENSOR_ASSERT, and TENSOR_MAXDIM.
|
inline |
Returns the size of dmension i
.
Referenced by madness::SeparatedConvolution< T, NDIM >::apply2(), madness::SeparatedConvolution< T, NDIM >::apply2_lowdim(), madness::FunctionNode< T, NDIM >::coeff(), madness::FunctionImpl< Q, NDIM >::do_project_out(), madness::SeparatedConvolution< T, NDIM >::estimate_costs(), madness::FunctionImpl< Q, NDIM >::NS_fcube_for_mul(), madness::FunctionImpl< Q, NDIM >::NScoeffs2values(), madness::FunctionImpl< T, NDIM >::multiply_op< LDIM >::operator()(), madness::FunctionImpl< T, NDIM >::do_inner_local< R >::operator()(), madness::FunctionImpl< T, NDIM >::project_out_op< LDIM >::operator()(), madness::FunctionImpl< T, NDIM >::parent_to_child_NS(), madness::FunctionImpl< T, NDIM >::reconstruct_op(), madness::FunctionImpl< T, NDIM >::multiply_op< LDIM >::screen(), madness::FunctionNode< T, NDIM >::set_coeff(), madness::FunctionImpl< Q, NDIM >::values2NScoeffs(), and madness::FunctionImpl< T, NDIM >::verify_tree().
|
inline |
Returns the array of tensor dimensions.
References _dim.
|
protected |
Reshapes the tensor inplace into 1D.
Reshape the current tensor to be the same size and 1-d. It must be contiguous.
References _size, iscontiguous(), set_dims_and_size(), and TENSOR_ASSERT.
|
protected |
Fuses dimensions i
and i+1
.
Fuse the contiguous dimensions i and i+1.
References _dim, _ndim, _stride, and TENSOR_ASSERT.
|
inlinestatic |
Returns the count of all current instances of tensors & slice tensors of all types.
Referenced by main().
|
inline |
Returns the typeid of the tensor (c.f., TensorTypeData<T>
)
References _id.
|
inline |
Returns true if the tensor refers to contiguous memory locations.
Referenced by flat_inplace(), and reshape_inplace().
|
protected |
General permutation of dimensions.
General permuation of the dimensions.
References _dim, _ndim, _stride, TENSOR_ASSERT, and TENSOR_MAXDIM.
|
inline |
Returns the number of dimensions in the tensor.
References _ndim.
Referenced by madness::SeparatedConvolution< T, NDIM >::apply2(), madness::SeparatedConvolution< T, NDIM >::apply2_lowdim(), madness::FunctionNode< T, NDIM >::coeff(), and madness::SeparatedConvolution< T, NDIM >::estimate_costs().
|
protected |
Reshapes the tensor inplace.
Reshape the size and number of dimensions.
Modifies the current tensor to have the number and size of dimensions as described in the vector
d
. The total number of elements must be the same before and after, and the current tensor must be contiguous.
|
protected |
Reshapes the tensor inplace.
Reshape the size and number of dimensions.
Modifies the current tensor to have the number and size of dimensions as described in the vector
d
. The total number of elements must be the same before and after, and the current tensor must be contiguous.
References _size, iscontiguous(), set_dims_and_size(), and TENSOR_ASSERT.
|
inlineprotected |
References _size, L, max, and TENSOR_MAXDIM.
Referenced by flat_inplace(), and reshape_inplace().
|
inline |
Returns the number of elements in the tensor.
References _size.
Referenced by madness::GenTensor< T >::has_data(), madness::GenTensor< T >::real_size(), madness::FunctionNode< T, NDIM >::size(), and madness::FunctionImpl< T, NDIM >::sum_down_spawn().
|
protected |
Splits dimension i
.
Split dimension i in two ... the product of the new dimensions must match the old.
References _dim, _ndim, _stride, TENSOR_ASSERT, and TENSOR_MAXDIM.
|
inline |
Returns the stride associated with dimension i
.
|
inline |
Returns the array of tensor strides.
References _stride.
|
protected |
Swaps the dimensions.
Swap the dimensions i and j.
References _dim, _ndim, _stride, and TENSOR_ASSERT.
|
protected |
Size of each dimension.
Referenced by conforms(), cycledim_inplace(), dims(), fusedim_inplace(), mapdim_inplace(), madness::GenTensor< T >::operator GenTensor< Q >(), splitdim_inplace(), and swapdim_inplace().
|
protected |
Id from TensorTypeData<T> in type_data.h.
Referenced by id().
|
protected |
Number of dimensions (-1=invalid; 0=scalar; >0=tensor)
Referenced by conforms(), cycledim_inplace(), fusedim_inplace(), mapdim_inplace(), ndim(), madness::GenTensor< T >::operator GenTensor< Q >(), splitdim_inplace(), and swapdim_inplace().
|
protected |
Number of elements in the tensor.
Referenced by flat_inplace(), reshape_inplace(), set_dims_and_size(), and size().
|
protected |
Increment between elements in each dimension.
Referenced by cycledim_inplace(), fusedim_inplace(), mapdim_inplace(), splitdim_inplace(), strides(), and swapdim_inplace().