Psi4
Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Attributes | List of all members
psi::Tensor Class Referenceabstract

#include <thce.h>

Inheritance diagram for psi::Tensor:
psi::CoreTensor psi::DiskTensor

Public Member Functions

 Tensor (const std::string &name, std::vector< std::string > &dimensions, std::vector< int > &sizes)
 Master constructor. More...
 
virtual ~Tensor ()
 Master destructor. More...
 
std::string name () const
 Name of this Tensor. More...
 
std::string filename () const
 Unique filename of this Tensor. More...
 
size_t numel () const
 Total number of elements in this Tensor. More...
 
int order () const
 Order (number of dimensions) in this Tensor. More...
 
std::vector< std::string > & dimensions ()
 Classes of dimensions. More...
 
std::vector< int > & sizes ()
 Allocated sizes of dimensions. More...
 
std::vector< int > & active_sizes ()
 Active sizes of dimensions. More...
 
virtual bool core () const =0
 Is this a core tensor? More...
 
virtual bool disk () const =0
 Is this a disk tensor? More...
 
virtual bool trust () const =0
 Is this a trust core tensor? More...
 
virtual bool swapped () const =0
 Is this a swapped-out core tensor? More...
 
virtual void swap_check () const =0
 Throw an exception if the tensor is swapped out or disk based. More...
 
virtual size_t core_doubles () const =0
 How many core doubles are currently allocated by this tensor? More...
 
virtual size_t disk_doubles () const =0
 How many disk doubles are currently allocated by this tensor? More...
 
virtual void print (std::string fh="outfile", int level=2) const =0
 Print the full tensor data in scalar/vector/matrix/pages style if print >= 2. More...
 
void print_header (std::string fh="outfile") const
 Print only name and sizing data. More...
 
virtual void zero ()=0
 Zero the tensor out (ignores active dims). Prestripes if DiskTensor. More...
 
virtual void slice (std::shared_ptr< Tensor > A, std::vector< std::tuple< bool, int, int, bool, int, int > > &topology)
 
virtual double * pointer () const
 Access the data pointer. More...
 
virtual FILE * file_pointer ()
 Access the file pointer. More...
 
virtual void swap_out (bool changed=true)
 Swap this tensor out to disk (does not write if existing disk mirror and not changed) More...
 
virtual void swap_in (bool read=true)
 Swap this tensor in to core (explicitly reads if true) More...
 
virtual void scale (double val)
 Scale the tensor by val (ignores active dims) More...
 
virtual void set_data (double *data)
 Copy contents of data (ignores active dims) More...
 
virtual void set_pointer (double *data)
 Update the trust pointer to data (throws if not trust) More...
 
virtual void add (std::shared_ptr< Tensor > A, double alpha=1.0, double beta=0.0)
 Direct elementwise generalized DAXPY: C = alpha * A + beta * C (ignores active dims) More...
 
virtual void permute (std::shared_ptr< Tensor > A, std::vector< int > &topology)
 
virtual void contract (std::shared_ptr< Tensor > A, std::shared_ptr< Tensor > B, std::vector< std::tuple< std::string, int, int, int > > &topology, double alpha=1.0, double beta=0.0)
 
virtual void set_save (bool save)
 Set save flag in DiskTensor. More...
 

Protected Member Functions

void set_filename ()
 Set the filename to scratch, PID, namespace, unique ID, name. More...
 

Protected Attributes

std::string name_
 Name of this Tensor. More...
 
std::string filename_
 Unique filename to prevent disk clash. More...
 
size_t numel_
 Total number of elements in this Tensor. More...
 
int order_
 Order (number of dimensions) in this Tensor. More...
 
std::vector< std::string > dimensions_
 Classes of dimensions. More...
 
std::vector< int > sizes_
 Sizes of dimensions (lda-style) More...
 
std::vector< int > active_sizes_
 Active sizes of dimensions (gimp-style) More...
 

Static Private Attributes

static long int unique_id = 0
 Unique ID to prevent disk clash. More...
 

Detailed Description

Abstract class Tensor provides the high-level interface for Tensor creation and manipulation in disk or core forms

Constructor & Destructor Documentation

psi::Tensor::Tensor ( const std::string &  name,
std::vector< std::string > &  dimensions,
std::vector< int > &  sizes 
)

Master constructor.

psi::Tensor::~Tensor ( )
virtual

Master destructor.

Member Function Documentation

std::vector<int>& psi::Tensor::active_sizes ( )
inline

Active sizes of dimensions.

virtual void psi::Tensor::add ( std::shared_ptr< Tensor A,
double  alpha = 1.0,
double  beta = 0.0 
)
inlinevirtual

Direct elementwise generalized DAXPY: C = alpha * A + beta * C (ignores active dims)

Reimplemented in psi::CoreTensor.

virtual void psi::Tensor::contract ( std::shared_ptr< Tensor A,
std::shared_ptr< Tensor B,
std::vector< std::tuple< std::string, int, int, int > > &  topology,
double  alpha = 1.0,
double  beta = 0.0 
)
inlinevirtual

Main contraction operation method (respects active dims) C = alpha * Op(A, B) + beta * C Topology contains the specification of the contraction, in the form <name,rC,rA,rB>, e.g., C_{j,i,l} = A_{j,i,k} B_{j,l,k} => <j,0,0,0> % Hadamard Dimension (H) <i,1,1,-1> % Outer Dimension (L) <l,2,-1,1> % Outer Dimension (R) <k,-1,2,2> % Inner Dimension (I)

Active dimensions H, L, and R are inherited in C from A and B tensors. If an index is H or I both A and B active dimensions must agree

Reimplemented in psi::CoreTensor.

virtual bool psi::Tensor::core ( ) const
pure virtual

Is this a core tensor?

Implemented in psi::DiskTensor, and psi::CoreTensor.

virtual size_t psi::Tensor::core_doubles ( ) const
pure virtual

How many core doubles are currently allocated by this tensor?

Implemented in psi::DiskTensor, and psi::CoreTensor.

std::vector<std::string>& psi::Tensor::dimensions ( )
inline

Classes of dimensions.

virtual bool psi::Tensor::disk ( ) const
pure virtual

Is this a disk tensor?

Implemented in psi::DiskTensor, and psi::CoreTensor.

virtual size_t psi::Tensor::disk_doubles ( ) const
pure virtual

How many disk doubles are currently allocated by this tensor?

Implemented in psi::DiskTensor, and psi::CoreTensor.

virtual FILE* psi::Tensor::file_pointer ( )
inlinevirtual

Access the file pointer.

Reimplemented in psi::DiskTensor, and psi::CoreTensor.

std::string psi::Tensor::filename ( ) const
inline

Unique filename of this Tensor.

std::string psi::Tensor::name ( ) const
inline

Name of this Tensor.

size_t psi::Tensor::numel ( ) const
inline

Total number of elements in this Tensor.

int psi::Tensor::order ( ) const
inline

Order (number of dimensions) in this Tensor.

virtual void psi::Tensor::permute ( std::shared_ptr< Tensor A,
std::vector< int > &  topology 
)
inlinevirtual

Permute from A into C (ignores active dims) Topology (P) contains rank of index in C indexed by rank in A C_{P=0,P=1,...} = A_{0,1,...}, e.g., C_{k,i,l,j} = A_{i,j,k,l} => [1,3,0,2]

Reimplemented in psi::CoreTensor.

virtual double* psi::Tensor::pointer ( ) const
inlinevirtual

Access the data pointer.

Reimplemented in psi::CoreTensor.

virtual void psi::Tensor::print ( std::string  fh = "outfile",
int  level = 2 
) const
pure virtual

Print the full tensor data in scalar/vector/matrix/pages style if print >= 2.

Implemented in psi::DiskTensor, and psi::CoreTensor.

void psi::Tensor::print_header ( std::string  fh = "outfile") const
inline

Print only name and sizing data.

virtual void psi::Tensor::scale ( double  val)
inlinevirtual

Scale the tensor by val (ignores active dims)

Reimplemented in psi::CoreTensor.

virtual void psi::Tensor::set_data ( double *  data)
inlinevirtual

Copy contents of data (ignores active dims)

Reimplemented in psi::CoreTensor.

void psi::Tensor::set_filename ( )
protected

Set the filename to scratch, PID, namespace, unique ID, name.

virtual void psi::Tensor::set_pointer ( double *  data)
inlinevirtual

Update the trust pointer to data (throws if not trust)

Reimplemented in psi::CoreTensor.

virtual void psi::Tensor::set_save ( bool  save)
inlinevirtual

Set save flag in DiskTensor.

Reimplemented in psi::DiskTensor.

std::vector<int>& psi::Tensor::sizes ( )
inline

Allocated sizes of dimensions.

void psi::Tensor::slice ( std::shared_ptr< Tensor A,
std::vector< std::tuple< bool, int, int, bool, int, int > > &  topology 
)
virtual

Slice assignment from A into C (respects active dims) Topology is a list following the joint rank of A and C, which must be coincidentally ordered (less singletons) in the form <inC?,startC,endC,inA?,startA,endA>, e.g., C_{0,:,2:3,:,1:2} = A{1,:,:,2:3,4:5} => <true,0,1,false,-1,-1> % Singleton A (Singleton A trumps Singleton C) <false,-1,-1,true,1,2> % Singleton C <true,-1,-1,true,-1,-1> % Full/Full <true,2,3,true,-1,-1> % Slice/Full <true,-1,-1,true,2,3> % Full/Slice <true,1,2,true,4,5> % Slice/Slice Slice indices are 0-based, and of the form [start,end)

=> Debug printing <= //

outfile->Printf( "  ==> Slice <==\n\n");
outfile->Printf( "    Total Size: %11zu\n", size_data);
outfile->Printf( "    Slow Size:  %11zu\n", size_slow / delta);
outfile->Printf( "    Fast Size:  %11zu\n", size_fast * delta);
outfile->Printf( "\n");

outfile->Printf( "    Total Dims: %11zu\n", nindex);
outfile->Printf( "    Slow Dims:  %11zu\n", (nslow > 0 ? nslow - 1 : nslow));
outfile->Printf( "    Fast Dims:  %11zu\n", (nslow > 0 ? nfast + 1 : nfast));
outfile->Printf( "\n");

outfile->Printf( "    %11s %11s %11s %11s %11s %11s %11s %11s %11s\n",
    "startC", "endC", "deltaC", "strideC",
    "startA", "endA", "deltaA", "strideA",
    "full?");
for (int ind = 0; ind < nindex; ind++) {
    outfile->Printf( "    %11d %11d %11d %11d %11d %11d %11d %11d %11s\n",
        startC[ind], endC[ind], deltaC[ind], strideC[ind],
        startA[ind], endA[ind], deltaA[ind], strideA[ind],
        (full[ind] ? "Yes" : "No"));
}
outfile->Printf( "\n");
virtual void psi::Tensor::swap_check ( ) const
pure virtual

Throw an exception if the tensor is swapped out or disk based.

Implemented in psi::DiskTensor, and psi::CoreTensor.

virtual void psi::Tensor::swap_in ( bool  read = true)
inlinevirtual

Swap this tensor in to core (explicitly reads if true)

Reimplemented in psi::CoreTensor.

virtual void psi::Tensor::swap_out ( bool  changed = true)
inlinevirtual

Swap this tensor out to disk (does not write if existing disk mirror and not changed)

Reimplemented in psi::CoreTensor.

virtual bool psi::Tensor::swapped ( ) const
pure virtual

Is this a swapped-out core tensor?

Implemented in psi::DiskTensor, and psi::CoreTensor.

virtual bool psi::Tensor::trust ( ) const
pure virtual

Is this a trust core tensor?

Implemented in psi::DiskTensor, and psi::CoreTensor.

virtual void psi::Tensor::zero ( )
pure virtual

Zero the tensor out (ignores active dims). Prestripes if DiskTensor.

Implemented in psi::DiskTensor, and psi::CoreTensor.

Member Data Documentation

std::vector<int> psi::Tensor::active_sizes_
protected

Active sizes of dimensions (gimp-style)

std::vector<std::string> psi::Tensor::dimensions_
protected

Classes of dimensions.

std::string psi::Tensor::filename_
protected

Unique filename to prevent disk clash.

std::string psi::Tensor::name_
protected

Name of this Tensor.

size_t psi::Tensor::numel_
protected

Total number of elements in this Tensor.

int psi::Tensor::order_
protected

Order (number of dimensions) in this Tensor.

std::vector<int> psi::Tensor::sizes_
protected

Sizes of dimensions (lda-style)

long int psi::Tensor::unique_id = 0
staticprivate

Unique ID to prevent disk clash.


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