Minsky
civita::Pivot Class Reference

corresponds to the OLAP pivot operation More...

#include <tensorOp.h>

Inheritance diagram for civita::Pivot:
Inheritance graph
Collaboration diagram for civita::Pivot:
Collaboration graph

Public Member Functions

void setArgument (const TensorPtr &a, const ITensor::Args &args={"", 0}) override
 
void setOrientation (const std::vector< std::string > &axes)
 set's the pivots orientation More...
 
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 Member Functions

std::size_t pivotIndex (std::size_t i) const
 

Private Attributes

std::vector< std::size_t > permutation
 
std::vector< std::size_t > permutedIndex
 permutation of axes More...
 
TensorPtr arg
 argument indices corresponding to this indices, when sparse More...
 

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 the OLAP pivot operation

Definition at line 237 of file tensorOp.h.

Member Function Documentation

◆ operator[]()

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

return or compute data at a location

Implements civita::ITensor.

Definition at line 386 of file tensorOp.cc.

387  {
388  assert(i<size());
389  if (index().empty())
390  return arg->atHCIndex(pivotIndex(i));
391  return (*arg)[permutedIndex[i]];
392  }
virtual const Index & index() const
the index vector - assumed to be ordered and unique
std::size_t pivotIndex(std::size_t i) const
Definition: tensorOp.cc:377
virtual std::size_t size() const
return number of elements in tensor - maybe less than hypercube.numElements if sparse ...
TensorPtr arg
argument indices corresponding to this indices, when sparse
Definition: tensorOp.h:241
std::vector< std::size_t > permutedIndex
permutation of axes
Definition: tensorOp.h:240

◆ pivotIndex()

size_t civita::Pivot::pivotIndex ( std::size_t  i) const
private

Definition at line 377 of file tensorOp.cc.

378  {
379  auto idx=hypercube().splitIndex(i);
380  auto pidx=idx;
381  for (size_t i=0; i<idx.size(); ++i)
382  pidx[permutation[i]]=idx[i];
383  return arg->hypercube().linealIndex(pidx);
384  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
std::vector< std::size_t > permutation
Definition: tensorOp.h:239
TensorPtr arg
argument indices corresponding to this indices, when sparse
Definition: tensorOp.h:241

◆ setArgument()

void civita::Pivot::setArgument ( const TensorPtr a,
const ITensor::Args args = {"",0} 
)
overridevirtual

Reimplemented from civita::ITensor.

Definition at line 309 of file tensorOp.cc.

310  {
311  arg=a;
312  vector<string> axes;
313  for (auto& i: arg->hypercube().xvectors)
314  axes.push_back(i.name);
315  setOrientation(axes);
316  }
TensorPtr arg
argument indices corresponding to this indices, when sparse
Definition: tensorOp.h:241
void setOrientation(const std::vector< std::string > &axes)
set&#39;s the pivots orientation
Definition: tensorOp.cc:319

◆ setOrientation()

void civita::Pivot::setOrientation ( const std::vector< std::string > &  axes)

set's the pivots orientation

Parameters
axes- list of axes that are the output

Definition at line 319 of file tensorOp.cc.

320  {
321  map<string,size_t> pMap;
322  map<string,XVector> xVectorMap;
323  auto& ahc=arg->hypercube();
324  for (size_t i=0; i<ahc.xvectors.size(); ++i)
325  {
326  pMap[ahc.xvectors[i].name]=i;
327  xVectorMap[ahc.xvectors[i].name]=ahc.xvectors[i];
328  }
329  Hypercube hc;
330  permutation.clear();
331  set<string> axisSet;
332  map<size_t, size_t> invPermutation;
333  for (auto& i: axes)
334  {
335  axisSet.insert(i);
336  auto v=pMap.find(i);
337  if (v==pMap.end())
338  throw runtime_error("axis "+i+" not found in argument");
339  invPermutation[v->second]=permutation.size();
340  permutation.push_back(v->second);
341  hc.xvectors.push_back(xVectorMap[i]);
342  }
343  // add remaining axes to permutation in found order
344  for (size_t i=0; i<ahc.xvectors.size(); ++i)
345  if (!axisSet.count(ahc.xvectors[i].name))
346  {
347  invPermutation[i]=permutation.size();
348  permutation.push_back(i);
349  hc.xvectors.push_back(ahc.xvectors[i]);
350  }
351 
352  assert(hc.rank()==arg->rank());
353  hypercube(move(hc));
354  // permute the index vector
355  map<size_t, size_t> pi;
356  for (size_t i=0; i<arg->index().size(); ++i)
357  {
358  auto idx=arg->hypercube().splitIndex(arg->index()[i]);
359  auto pidx=idx;
360  for (size_t j=0; j<idx.size(); ++j)
361  {
362  assert(invPermutation.count(j));
363  assert(invPermutation[j]<pidx.size());
364  pidx[invPermutation[j]]=idx[j];
365  }
366  auto l=hypercube().linealIndex(pidx);
367  assert(pi.count(l)==0);
368  pi[l]=i;
369  }
370  m_index=pi;
371  // convert to lineal indexing
372  permutedIndex.clear();
373  for (auto& i: pi) permutedIndex.push_back(i.second);
374  if (!permutedIndex.empty()) permutation.clear(); // not used in sparse case
375  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
std::vector< std::size_t > permutation
Definition: tensorOp.h:239
TensorPtr arg
argument indices corresponding to this indices, when sparse
Definition: tensorOp.h:241
std::vector< std::size_t > permutedIndex
permutation of axes
Definition: tensorOp.h:240

◆ timestamp()

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

References arg.

250 {return arg->timestamp();}
TensorPtr arg
argument indices corresponding to this indices, when sparse
Definition: tensorOp.h:241

Member Data Documentation

◆ arg

TensorPtr civita::Pivot::arg
private

argument indices corresponding to this indices, when sparse

Definition at line 241 of file tensorOp.h.

Referenced by timestamp().

◆ permutation

std::vector<std::size_t> civita::Pivot::permutation
private

Definition at line 239 of file tensorOp.h.

◆ permutedIndex

std::vector<std::size_t> civita::Pivot::permutedIndex
private

permutation of axes

Definition at line 240 of file tensorOp.h.


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