Minsky
minsky::SwitchTensor Class Reference
Inheritance diagram for minsky::SwitchTensor:
Inheritance graph
Collaboration diagram for minsky::SwitchTensor:
Collaboration graph

Public Member Functions

void setArguments (const std::vector< TensorPtr > &a, const Args &av={"", 0}) override
 
size_t size () const override
 return number of elements in tensor - maybe less than hypercube.numElements if sparse More...
 
Timestamp timestamp () const override
 timestamp indicating how old the dependendent data might be. Used in CachedTensorOp to determine when to invalidate the cache More...
 
double operator[] (size_t i) const override
 
- Public Member Functions inherited from civita::ITensor
 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...
 
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 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 > &a1, const std::vector< TensorPtr > &a2, const ITensor::Args &args={"", 0})
 
- Public Member Functions inherited from minsky::OpState
void setState (const OperationPtr &s) override
 
void throw_error (const std::string &msg) const
 
- Public Member Functions inherited from minsky::SetState
virtual ~SetState ()
 

Private Attributes

size_t m_size =1
 
vector< TensorPtrargs
 

Additional Inherited Members

- Public Types inherited from civita::ITensor
using Timestamp = std::chrono::time_point< std::chrono::high_resolution_clock >
 
- Public Attributes inherited from minsky::OpState
OperationPtr state
 
- Protected Member Functions inherited from civita::ITensor
void notImpl () const
 
- Protected Attributes inherited from civita::ITensor
Hypercube m_hypercube
 
Index m_index
 

Detailed Description

Definition at line 1432 of file minskyTensorOps.cc.

Member Function Documentation

◆ operator[]()

double minsky::SwitchTensor::operator[] ( size_t  i) const
inlineoverride

Definition at line 1472 of file minskyTensorOps.cc.

1472  {
1473  if (args.size()<2) return nan("");
1474 
1475  double selector=0;
1476  if (args[0])
1477  {
1478  if (args[0]->rank()==0) // scalar selector, so broadcast
1479  selector = (*args[0])[0];
1480  else
1481  selector = (*args[0])[i];
1482  }
1483  const ssize_t idx = selector+1.5; // selector selects between args 1..n
1484 
1485  if (idx>0 && idx<int(args.size()))
1486  {
1487  if (args[idx]->rank()==0)
1488  return (*args[idx])[0];
1489  return args[idx]->atHCIndex(index()[i]);
1490  }
1491  return nan("");
1492  }
std::size_t rank() const
virtual const Index & index() const
the index vector - assumed to be ordered and unique
vector< TensorPtr > args

◆ setArguments()

void minsky::SwitchTensor::setArguments ( const std::vector< TensorPtr > &  a,
const Args av = {"",0} 
)
inlineoverridevirtual

Reimplemented from civita::ITensor.

Definition at line 1437 of file minskyTensorOps.cc.

1437  {"",0}) override {
1438  args=a;
1439  if (args.size()<2)
1440  hypercube(Hypercube());
1441  else
1442  hypercube(args[1]->hypercube());
1443 
1444  m_size=1;
1445  set<size_t> indices;
1446  for (auto& i: args)
1447  {
1448  for (auto& j: i->index())
1449  checkCancel(), indices.insert(j);
1450  if (i->size()>1)
1451  {
1452  if (m_size==1)
1453  m_size=i->size();
1454  else if (m_size!=i->size())
1455  // TODO - should we check and throw on nonconformat hypercubes?
1456  throw_error("nonconformant tensor arguments in switch");
1457  }
1458  }
1459  m_index=indices;
1460  if (!m_index.empty()) m_size=m_index.size();
1461  }
void throw_error(const std::string &msg) const
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
vector< TensorPtr > args

◆ size()

size_t minsky::SwitchTensor::size ( ) const
inlineoverridevirtual

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

Reimplemented from civita::ITensor.

Definition at line 1462 of file minskyTensorOps.cc.

1462 {return m_size;}

◆ timestamp()

Timestamp minsky::SwitchTensor::timestamp ( ) const
inlineoverridevirtual

timestamp indicating how old the dependendent data might be. Used in CachedTensorOp to determine when to invalidate the cache

Implements civita::ITensor.

Definition at line 1463 of file minskyTensorOps.cc.

1463  {
1464  Timestamp t;
1465  for (auto& i: args)
1466  {
1467  auto tt=i->timestamp();
1468  if (tt>t) t=tt;
1469  }
1470  return t;
1471  }
std::chrono::time_point< std::chrono::high_resolution_clock > Timestamp
vector< TensorPtr > args

Member Data Documentation

◆ args

vector<TensorPtr> minsky::SwitchTensor::args
private

Definition at line 1435 of file minskyTensorOps.cc.

◆ m_size

size_t minsky::SwitchTensor::m_size =1
private

Definition at line 1434 of file minskyTensorOps.cc.


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