Minsky
civita::Slice Class Reference

corresponds to OLAP slice operation More...

#include <tensorOp.h>

Inheritance diagram for civita::Slice:
Inheritance graph
Collaboration diagram for civita::Slice:
Collaboration graph

Public Member Functions

void setArgument (const TensorPtr &a, const ITensor::Args &) override
 
double operator[] (std::size_t i) const override
 return or compute data at a location 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...
 
- 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 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 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})
 

Private Attributes

std::size_t stride =1
 
std::size_t split =1
 
std::size_t sliceIndex =0
 
TensorPtr arg
 
std::vector< std::size_t > arg_index
 

Additional Inherited Members

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

Detailed Description

corresponds to OLAP slice operation

Definition at line 225 of file tensorOp.h.

Member Function Documentation

◆ operator[]()

double civita::Slice::operator[] ( std::size_t  ) const
overridevirtual

return or compute data at a location

Implements civita::ITensor.

Definition at line 298 of file tensorOp.cc.

299  {
300  assert(i<size());
301  if (m_index.empty())
302  {
303  auto res=div(ssize_t(i), ssize_t(split));
304  return arg->atHCIndex(res.quot*stride + sliceIndex*split + res.rem);
305  }
306  return (*arg)[arg_index[i]];
307  }
std::size_t sliceIndex
Definition: tensorOp.h:227
std::vector< std::size_t > arg_index
Definition: tensorOp.h:229
virtual std::size_t size() const
return number of elements in tensor - maybe less than hypercube.numElements if sparse ...
std::size_t split
Definition: tensorOp.h:227
TensorPtr arg
Definition: tensorOp.h:228
std::size_t stride
Definition: tensorOp.h:227

◆ setArgument()

void civita::Slice::setArgument ( const TensorPtr a,
const ITensor::Args args 
)
overridevirtual

Reimplemented from civita::ITensor.

Definition at line 244 of file tensorOp.cc.

References civita::ITensor::Args::dimension, and civita::ITensor::Args::val.

245  {
246  arg=a;
247  sliceIndex=args.val;
248  if (arg)
249  {
250  auto& xv=arg->hypercube().xvectors;
251  Hypercube hc;
252  // find axis where slicing along
253  split=1;
254  size_t splitAxis=0;
255  auto i=xv.begin();
256  for (; i!=xv.end(); ++i)
257  if (i->name==args.dimension)
258  {
259  stride=split*i->size();
260  break;
261  }
262  else
263  {
264  hc.xvectors.push_back(*i);
265  split*=i->size();
266  splitAxis++;
267  }
268 
269  if (i==xv.end())
270  split=stride=1;
271  else
272  for (i++; i!=xv.end(); ++i)
273  // finish building hypercube
274  hc.xvectors.push_back(*i);
275  hypercube(hc);
276 
277  // set up index vector
278  auto& ahc=arg->hypercube();
279  map<size_t, size_t> ai;
280  for (size_t i=0; i<arg->index().size(); ++i)
281  {
282  auto splitIdx=ahc.splitIndex(arg->index()[i]);
283  if (splitIdx[splitAxis]==sliceIndex)
284  {
285  splitIdx.erase(splitIdx.begin()+splitAxis);
286  auto l=hc.linealIndex(splitIdx);
287  ai[l]=i;
288  }
289  }
290  m_index=ai;
291  arg_index.resize(ai.size());
292  // convert into lineal addressing
293  size_t j=0;
294  for (auto& i: ai) arg_index[j++]=i.second;
295  }
296  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
std::size_t sliceIndex
Definition: tensorOp.h:227
std::vector< std::size_t > arg_index
Definition: tensorOp.h:229
std::size_t split
Definition: tensorOp.h:227
TensorPtr arg
Definition: tensorOp.h:228
std::size_t stride
Definition: tensorOp.h:227

◆ timestamp()

Timestamp civita::Slice::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 233 of file tensorOp.h.

References arg.

233 {return arg->timestamp();}
TensorPtr arg
Definition: tensorOp.h:228

Member Data Documentation

◆ arg

TensorPtr civita::Slice::arg
private

Definition at line 228 of file tensorOp.h.

Referenced by timestamp().

◆ arg_index

std::vector<std::size_t> civita::Slice::arg_index
private

Definition at line 229 of file tensorOp.h.

◆ sliceIndex

std::size_t civita::Slice::sliceIndex =0
private

Definition at line 227 of file tensorOp.h.

◆ split

std::size_t civita::Slice::split =1
private

Definition at line 227 of file tensorOp.h.

◆ stride

std::size_t civita::Slice::stride =1
private

Definition at line 227 of file tensorOp.h.


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