Minsky
civita::PermuteAxis Class Reference

#include <tensorOp.h>

Inheritance diagram for civita::PermuteAxis:
Inheritance graph
Collaboration diagram for civita::PermuteAxis:
Collaboration graph

Public Member Functions

void setArgument (const TensorPtr &a, const ITensor::Args &args={"", 0}) override
 argument indices corresponding to this indices, when sparse More...
 
void setPermutation (const std::vector< std::size_t > &p)
 
void setPermutation (std::vector< std::size_t > &&)
 
std::size_t axis () const
 
const std::vector< std::size_t > & permutation () const
 
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

TensorPtr arg
 
std::size_t m_axis
 
std::vector< std::size_t > m_permutation
 
std::vector< std::size_t > permutedIndex
 

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

Definition at line 253 of file tensorOp.h.

Member Function Documentation

◆ axis()

std::size_t civita::PermuteAxis::axis ( ) const
inline

Definition at line 264 of file tensorOp.h.

References m_axis.

264 {return m_axis;}
std::size_t m_axis
Definition: tensorOp.h:256

◆ operator[]()

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

return or compute data at a location

Implements civita::ITensor.

Definition at line 451 of file tensorOp.cc.

452  {
453  assert(i<size());
454  if (index().empty())
455  {
456  auto splitted=hypercube().splitIndex(i);
457  splitted[m_axis]=m_permutation[splitted[m_axis]];
458  return arg->atHCIndex(arg->hypercube().linealIndex(splitted));
459  }
460  return (*arg)[permutedIndex[i]];
461  }
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
virtual std::size_t size() const
return number of elements in tensor - maybe less than hypercube.numElements if sparse ...
std::vector< std::size_t > permutedIndex
Definition: tensorOp.h:258
std::size_t m_axis
Definition: tensorOp.h:256
std::vector< std::size_t > m_permutation
Definition: tensorOp.h:257

◆ permutation()

const std::vector<std::size_t>& civita::PermuteAxis::permutation ( ) const
inline

Definition at line 265 of file tensorOp.h.

References m_permutation.

265 {return m_permutation;}
std::vector< std::size_t > m_permutation
Definition: tensorOp.h:257

◆ setArgument()

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

argument indices corresponding to this indices, when sparse

Reimplemented from civita::ITensor.

Definition at line 413 of file tensorOp.cc.

References civita::ITensor::Args::dimension.

Referenced by minsky::GeneralTensorOp< OperationType::slice >::setArgument().

414  {
415  arg=a;
416  hypercube(arg->hypercube());
417  m_index=arg->index();
418  for (m_axis=0; m_axis<m_hypercube.xvectors.size(); ++m_axis)
419  if (m_hypercube.xvectors[m_axis].name==args.dimension)
420  break;
421  if (m_axis==m_hypercube.xvectors.size())
422  throw runtime_error("axis "+args.dimension+" not found");
423  for (size_t i=0; i<m_hypercube.xvectors[m_axis].size(); ++i)
424  m_permutation.push_back(i);
425  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
std::size_t m_axis
Definition: tensorOp.h:256
Hypercube m_hypercube
std::vector< std::size_t > m_permutation
Definition: tensorOp.h:257
Here is the caller graph for this function:

◆ setPermutation() [1/2]

void civita::PermuteAxis::setPermutation ( const std::vector< std::size_t > &  p)
inline

Definition at line 261 of file tensorOp.h.

262  {auto pp(p); setPermutation(std::move(pp));}
void setPermutation(const std::vector< std::size_t > &p)
Definition: tensorOp.h:261

◆ setPermutation() [2/2]

void civita::PermuteAxis::setPermutation ( std::vector< std::size_t > &&  )

◆ timestamp()

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

References arg.

267 {return arg->timestamp();}

Member Data Documentation

◆ arg

TensorPtr civita::PermuteAxis::arg
private

Definition at line 255 of file tensorOp.h.

Referenced by timestamp().

◆ m_axis

std::size_t civita::PermuteAxis::m_axis
private

Definition at line 256 of file tensorOp.h.

Referenced by axis().

◆ m_permutation

std::vector<std::size_t> civita::PermuteAxis::m_permutation
private

Definition at line 257 of file tensorOp.h.

Referenced by permutation().

◆ permutedIndex

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

Definition at line 258 of file tensorOp.h.


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