MADNESS  version 0.9
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
madness::BaseTensor Class Reference

The base class for tensors defines generic capabilities. More...

#include <basetensor.h>

Inheritance diagram for madness::BaseTensor:
Inheritance graph
[legend]

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

madness::BaseTensor::BaseTensor ( )
inline
virtual madness::BaseTensor::~BaseTensor ( )
inlinevirtual

Member Function Documentation

bool madness::BaseTensor::conforms ( const BaseTensor t) const
inline

Returns true if this and *t are the same shape and size.

References _dim, and _ndim.

void madness::BaseTensor::cycledim_inplace ( long  shift,
long  start,
long  end 
)
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.

long madness::BaseTensor::dim ( int  i) const
inline
const long* madness::BaseTensor::dims ( ) const
inline

Returns the array of tensor dimensions.

References _dim.

void madness::BaseTensor::flat_inplace ( )
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.

void madness::BaseTensor::fusedim_inplace ( long  i)
protected

Fuses dimensions i and i+1.

Fuse the contiguous dimensions i and i+1.

References _dim, _ndim, _stride, and TENSOR_ASSERT.

static int madness::BaseTensor::get_instance_count ( )
inlinestatic

Returns the count of all current instances of tensors & slice tensors of all types.

Referenced by main().

long madness::BaseTensor::id ( ) const
inline

Returns the typeid of the tensor (c.f., TensorTypeData<T> )

References _id.

bool madness::BaseTensor::iscontiguous ( ) const
inline

Returns true if the tensor refers to contiguous memory locations.

Referenced by flat_inplace(), and reshape_inplace().

void madness::BaseTensor::mapdim_inplace ( const std::vector< long > &  map)
protected

General permutation of dimensions.

General permuation of the dimensions.

References _dim, _ndim, _stride, TENSOR_ASSERT, and TENSOR_MAXDIM.

long madness::BaseTensor::ndim ( ) const
inline
void madness::BaseTensor::reshape_inplace ( const std::vector< long > &  d)
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.

void madness::BaseTensor::reshape_inplace ( int  nd,
const long *  d 
)
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.

void madness::BaseTensor::set_dims_and_size ( long  nd,
const long  d[] 
)
inlineprotected

References _size, L, max, and TENSOR_MAXDIM.

Referenced by flat_inplace(), and reshape_inplace().

long madness::BaseTensor::size ( ) const
inline
void madness::BaseTensor::splitdim_inplace ( long  i,
long  dimi0,
long  dimi1 
)
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.

long madness::BaseTensor::stride ( int  i) const
inline

Returns the stride associated with dimension i.

const long* madness::BaseTensor::strides ( ) const
inline

Returns the array of tensor strides.

References _stride.

void madness::BaseTensor::swapdim_inplace ( long  i,
long  j 
)
protected

Swaps the dimensions.

Swap the dimensions i and j.

References _dim, _ndim, _stride, and TENSOR_ASSERT.

Member Data Documentation

long madness::BaseTensor::_dim[TENSOR_MAXDIM]
protected
long madness::BaseTensor::_id
protected

Id from TensorTypeData<T> in type_data.h.

Referenced by id().

long madness::BaseTensor::_ndim
protected
long madness::BaseTensor::_size
protected

Number of elements in the tensor.

Referenced by flat_inplace(), reshape_inplace(), set_dims_and_size(), and size().

long madness::BaseTensor::_stride[TENSOR_MAXDIM]
protected

Increment between elements in each dimension.

Referenced by cycledim_inplace(), fusedim_inplace(), mapdim_inplace(), splitdim_inplace(), strides(), and swapdim_inplace().


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