Minsky
civita::ITensor Class Referenceabstract

#include <tensorInterface.h>

Inheritance diagram for civita::ITensor:
Inheritance graph
Collaboration diagram for civita::ITensor:
Collaboration graph

Classes

struct  Args
 arguments relevant for tensor expressions, not always meaningful. Exception thrown if not. More...
 

Public Types

using Timestamp = std::chrono::time_point< std::chrono::high_resolution_clock >
 

Public Member Functions

 CLASSDESC_ACCESS (ITensor)
 
 ITensor ()
 
 ITensor (const Hypercube &hc)
 
 ITensor (Hypercube &&hc)
 
 ITensor (const std::vector< unsigned > &dims)
 
 ITensor (const ITensor &)=default
 
 ITensor (ITensor &&)=default
 
ITensoroperator= (const ITensor &)=default
 
ITensoroperator= (ITensor &&)=default
 
virtual ~ITensor ()
 
virtual const Hypercube & hypercube () const
 information describing the axes, types and labels of this tensor More...
 
virtual const Hypercube & hypercube (const Hypercube &hc)
 
virtual const Hypercube & hypercube (Hypercube &&hc)
 
std::size_t rank () const
 
std::vector< unsigned > shape () const
 
void imposeDimensions (const Dimensions &dimensions)
 impose dimensions according to dimension map dimensions More...
 
virtual const Index & index () const
 the index vector - assumed to be ordered and unique More...
 
virtual double operator[] (std::size_t) const =0
 return or compute data at a location More...
 
virtual std::size_t size () const
 return number of elements in tensor - maybe less than hypercube.numElements if sparse More...
 
double atHCIndex (std::size_t hcIdx) const
 returns the data value at hypercube index hcIdx, or NaN if More...
 
template<class T >
std::size_t hcIndex (const std::initializer_list< T > &indices) const
 
template<class T >
double operator() (const std::initializer_list< T > &indices) const
 
virtual Timestamp timestamp () const =0
 timestamp indicating how old the dependendent data might be. Used in CachedTensorOp to determine when to invalidate the cache More...
 
virtual void setArgument (const TensorPtr &, const ITensor::Args &args={"", 0})
 
virtual void setArguments (const TensorPtr &, const TensorPtr &, const ITensor::Args &args={})
 
virtual void setArguments (const std::vector< TensorPtr > &a, const ITensor::Args &args={"", 0})
 
virtual void setArguments (const std::vector< TensorPtr > &a1, const std::vector< TensorPtr > &a2, const ITensor::Args &args={"", 0})
 

Protected Member Functions

void notImpl () const
 

Protected Attributes

Hypercube m_hypercube
 
Index m_index
 

Detailed Description

Definition at line 36 of file tensorInterface.h.

Member Typedef Documentation

◆ Timestamp

using civita::ITensor::Timestamp = std::chrono::time_point<std::chrono::high_resolution_clock>

Definition at line 103 of file tensorInterface.h.

Constructor & Destructor Documentation

◆ ITensor() [1/6]

civita::ITensor::ITensor ( )
inline

Definition at line 40 of file tensorInterface.h.

40 {}

◆ ITensor() [2/6]

civita::ITensor::ITensor ( const Hypercube &  hc)
inline

Definition at line 41 of file tensorInterface.h.

41 : m_hypercube(hc) {}
Hypercube m_hypercube

◆ ITensor() [3/6]

civita::ITensor::ITensor ( Hypercube &&  hc)
inline

Definition at line 42 of file tensorInterface.h.

42 : m_hypercube(std::move(hc)) {}
Hypercube m_hypercube

◆ ITensor() [4/6]

civita::ITensor::ITensor ( const std::vector< unsigned > &  dims)
inline

Definition at line 43 of file tensorInterface.h.

References m_hypercube.

43 {m_hypercube.dims(dims);}
Hypercube m_hypercube

◆ ITensor() [5/6]

civita::ITensor::ITensor ( const ITensor )
default

◆ ITensor() [6/6]

civita::ITensor::ITensor ( ITensor &&  )
default

◆ ~ITensor()

virtual civita::ITensor::~ITensor ( )
inlinevirtual

Definition at line 48 of file tensorInterface.h.

48 {}

Member Function Documentation

◆ atHCIndex()

double civita::ITensor::atHCIndex ( std::size_t  hcIdx) const
inline

returns the data value at hypercube index hcIdx, or NaN if

Definition at line 82 of file tensorInterface.h.

References index(), and size().

Referenced by operator()().

82  {
83  auto& idx=index();
84  if (idx.empty()) {// this is dense
85  if (hcIdx<size())
86  return (*this)[hcIdx];
87  } else {
88  auto i=idx.linealOffset(hcIdx);
89  if (i<idx.size())
90  return (*this)[i];
91  }
92  return nan(""); //element not found
93  }
virtual const Index & index() const
the index vector - assumed to be ordered and unique
virtual std::size_t size() const
return number of elements in tensor - maybe less than hypercube.numElements if sparse ...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CLASSDESC_ACCESS()

civita::ITensor::CLASSDESC_ACCESS ( ITensor  )

◆ hcIndex()

template<class T >
std::size_t civita::ITensor::hcIndex ( const std::initializer_list< T > &  indices) const
inline

Definition at line 96 of file tensorInterface.h.

References hypercube().

Referenced by operator()(), civita::BinOp::operator[](), and civita::InterpolateHC::splitAndRotate().

97  {return hypercube().linealIndex(indices);}
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hypercube() [1/3]

virtual const Hypercube& civita::ITensor::hypercube ( ) const
inlinevirtual

◆ hypercube() [2/3]

virtual const Hypercube& civita::ITensor::hypercube ( const Hypercube &  hc)
inlinevirtual

Reimplemented in civita::CachedTensorOp.

Definition at line 51 of file tensorInterface.h.

References m_hypercube.

51 {return m_hypercube=hc;}
Hypercube m_hypercube

◆ hypercube() [3/3]

virtual const Hypercube& civita::ITensor::hypercube ( Hypercube &&  hc)
inlinevirtual

Reimplemented in civita::CachedTensorOp.

Definition at line 52 of file tensorInterface.h.

References m_hypercube.

52 {return m_hypercube=std::move(hc);}
Hypercube m_hypercube

◆ imposeDimensions()

void civita::ITensor::imposeDimensions ( const Dimensions &  dimensions)
inline

impose dimensions according to dimension map dimensions

Definition at line 57 of file tensorInterface.h.

References hypercube().

57  {
58  auto hc=hypercube();
59  for (auto& xv: hc.xvectors)
60  {
61  auto dim=dimensions.find(xv.name);
62  if (dim!=dimensions.end())
63  {
64  xv.dimension=dim->second;
65  xv.imposeDimension();
66  }
67  }
68  hypercube(std::move(hc));
69  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
Here is the call graph for this function:

◆ index()

virtual const Index& civita::ITensor::index ( ) const
inlinevirtual

◆ notImpl()

void civita::ITensor::notImpl ( ) const
inlineprotected

Definition at line 129 of file tensorInterface.h.

130  {throw std::runtime_error("setArgument(s) variant not implemented");}

◆ operator()()

template<class T >
double civita::ITensor::operator() ( const std::initializer_list< T > &  indices) const
inline

Definition at line 100 of file tensorInterface.h.

References atHCIndex(), and hcIndex().

101  {return atHCIndex(hcIndex(indices));}
std::size_t hcIndex(const std::initializer_list< T > &indices) const
double atHCIndex(std::size_t hcIdx) const
returns the data value at hypercube index hcIdx, or NaN if
Here is the call graph for this function:

◆ operator=() [1/2]

ITensor& civita::ITensor::operator= ( const ITensor )
default

◆ operator=() [2/2]

ITensor& civita::ITensor::operator= ( ITensor &&  )
default

◆ operator[]()

◆ rank()

std::size_t civita::ITensor::rank ( ) const
inline

Definition at line 53 of file tensorInterface.h.

References hypercube().

Referenced by civita::InterpolateHC::bodyCentredNeighbourhood(), civita::InterpolateHC::setArgument(), and civita::InterpolateHC::splitAndRotate().

53 {return hypercube().rank();}
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setArgument()

◆ setArguments() [1/3]

◆ setArguments() [2/3]

virtual void civita::ITensor::setArguments ( const std::vector< TensorPtr > &  a,
const ITensor::Args args = {"",0} 
)
inlinevirtual

Reimplemented in minsky::SwitchTensor, civita::ReduceArguments, and minsky::MinskyTensorOp< op >.

Definition at line 118 of file tensorInterface.h.

119  {"",0})
120  {if (a.size()) setArgument(a[0], args);}
virtual void setArgument(const TensorPtr &, const ITensor::Args &args={"", 0})

◆ setArguments() [3/3]

virtual void civita::ITensor::setArguments ( const std::vector< TensorPtr > &  a1,
const std::vector< TensorPtr > &  a2,
const ITensor::Args args = {"",0} 
)
inlinevirtual

Reimplemented in minsky::MultiWireBinOp< op >.

Definition at line 121 of file tensorInterface.h.

123  {"",0})
124  {setArguments(a1.empty()? TensorPtr(): a1[0], a2.empty()? TensorPtr(): a2[0], args);}
virtual void setArguments(const TensorPtr &, const TensorPtr &, const ITensor::Args &args={})
std::shared_ptr< ITensor > TensorPtr

◆ shape()

std::vector<unsigned> civita::ITensor::shape ( ) const
inline

Definition at line 54 of file tensorInterface.h.

References hypercube().

54 {return hypercube().dims();}
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
Here is the call graph for this function:

◆ size()

virtual std::size_t civita::ITensor::size ( ) const
inlinevirtual

return number of elements in tensor - maybe less than hypercube.numElements if sparse

Reimplemented in minsky::RavelTensor, minsky::SwitchTensor, civita::SortByValue, civita::CachedTensorOp, minsky::TimeOp, and civita::ElementWiseOp.

Definition at line 76 of file tensorInterface.h.

References hypercube(), and index().

Referenced by atHCIndex(), minsky::VariableValue::operator=(), civita::BinOp::operator[](), and civita::InterpolateHC::setArgument().

76  {
77  std::size_t s=index().size();
78  return s? s: hypercube().numElements();
79  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
virtual const Index & index() const
the index vector - assumed to be ordered and unique
Here is the call graph for this function:
Here is the caller graph for this function:

◆ timestamp()

Member Data Documentation

◆ m_hypercube

Hypercube civita::ITensor::m_hypercube
protected

◆ m_index

Index civita::ITensor::m_index
protected

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