Minsky
civita::SortByValue Class Reference

If a rank 1 argument, sort by the value of the argument. More...

#include <tensorOp.h>

Inheritance diagram for civita::SortByValue:
Inheritance graph
Collaboration diagram for civita::SortByValue:
Collaboration graph

Public Member Functions

 SortByValue (ravel::HandleSort::Order order)
 
void setArgument (const TensorPtr &a, const ITensor::Args &args={"", 0}) override
 
void computeTensor () const override
 computeTensor updates the above two mutable fields, but is logically const 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...
 
const Hypercube & hypercube () const override
 information describing the axes, types and labels of this tensor More...
 
std::size_t size () const override
 return number of elements in tensor - maybe less than hypercube.numElements if sparse More...
 
- Public Member Functions inherited from civita::CachedTensorOp
const Index & index () const override
 the index vector - assumed to be ordered and unique More...
 
double operator[] (std::size_t i) const override
 return or compute data at a location More...
 
const Hypercube & hypercube (const Hypercube &hc) override
 
const Hypercube & hypercube (Hypercube &&hc) 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 ()
 
std::size_t rank () const
 
std::vector< unsigned > shape () const
 
void imposeDimensions (const Dimensions &dimensions)
 impose dimensions according to dimension map dimensions 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
 
ravel::HandleSort::Order order
 

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::CachedTensorOp
TensorVal cachedResult
 
Timestamp m_timestamp
 
- Protected Attributes inherited from civita::ITensor
Hypercube m_hypercube
 
Index m_index
 

Detailed Description

If a rank 1 argument, sort by the value of the argument.

Definition at line 271 of file tensorOp.h.

Constructor & Destructor Documentation

◆ SortByValue()

civita::SortByValue::SortByValue ( ravel::HandleSort::Order  order)
inline

Definition at line 276 of file tensorOp.h.

276 : order(order) {}
ravel::HandleSort::Order order
Definition: tensorOp.h:274

Member Function Documentation

◆ computeTensor()

void civita::SortByValue::computeTensor ( ) const
overridevirtual

computeTensor updates the above two mutable fields, but is logically const

Implements civita::CachedTensorOp.

Definition at line 464 of file tensorOp.cc.

Referenced by hypercube(), and size().

465  {
466  assert(arg->rank()==1);
467  vector<size_t> idx; idx.reserve(arg->size());
468  vector<double> tmp;
469  for (size_t i=0; i<arg->size(); ++i)
470  {
471  idx.push_back(i);
472  tmp.push_back((*arg)[i]);
473  }
474  switch (order)
475  {
476  case ravel::HandleSort::forward:
477  sort(idx.begin(), idx.end(), [&](size_t i, size_t j){return tmp[i]<tmp[j];});
478  break;
479  case ravel::HandleSort::reverse:
480  sort(idx.begin(), idx.end(), [&](size_t i, size_t j){return tmp[i]>tmp[j];});
481  break;
482  default:
483  break;
484  }
485  // reorder labels
486  auto hc=arg->hypercube();
487  XVector xv(hc.xvectors[0]);
488  for (size_t i=0; i<idx.size(); ++i)
489  xv[i]=hc.xvectors[0][idx[i]];
490  hc.xvectors[0].swap(xv);
491  cachedResult.hypercube(move(hc));
492  for (size_t i=0; i<idx.size(); ++i)
493  cachedResult[i]=tmp[idx[i]];
494  }
TensorVal cachedResult
Definition: tensorOp.h:132
ravel::HandleSort::Order order
Definition: tensorOp.h:274
Here is the caller graph for this function:

◆ hypercube()

const Hypercube& civita::SortByValue::hypercube ( ) const
inlineoverridevirtual

information describing the axes, types and labels of this tensor

Reimplemented from civita::CachedTensorOp.

Definition at line 286 of file tensorOp.h.

References civita::CachedTensorOp::cachedResult, computeTensor(), civita::CachedTensorOp::m_timestamp, and timestamp().

286  {
288  return cachedResult.hypercube();
289  }
Timestamp timestamp() const override
timestamp indicating how old the dependendent data might be. Used in CachedTensorOp to determine when...
Definition: tensorOp.h:285
Timestamp m_timestamp
Definition: tensorOp.h:133
void computeTensor() const override
computeTensor updates the above two mutable fields, but is logically const
Definition: tensorOp.cc:464
TensorVal cachedResult
Definition: tensorOp.h:132
Here is the call graph for this function:

◆ setArgument()

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

Reimplemented from civita::ITensor.

Definition at line 277 of file tensorOp.h.

277  {"",0}) override {
278  if (a->rank()!=1)
279  throw std::runtime_error("Sort by Value only applicable for rank 1 tensors");
280  else
281  arg=a;
282  cachedResult.hypercube(a->hypercube()); // no data, unsorted
283  }
TensorVal cachedResult
Definition: tensorOp.h:132

◆ size()

std::size_t civita::SortByValue::size ( ) const
inlineoverridevirtual

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

Reimplemented from civita::CachedTensorOp.

Definition at line 290 of file tensorOp.h.

References civita::CachedTensorOp::cachedResult, computeTensor(), civita::CachedTensorOp::m_timestamp, and timestamp().

290  {
292  return cachedResult.size();
293  }
Timestamp timestamp() const override
timestamp indicating how old the dependendent data might be. Used in CachedTensorOp to determine when...
Definition: tensorOp.h:285
Timestamp m_timestamp
Definition: tensorOp.h:133
void computeTensor() const override
computeTensor updates the above two mutable fields, but is logically const
Definition: tensorOp.cc:464
TensorVal cachedResult
Definition: tensorOp.h:132
Here is the call graph for this function:

◆ timestamp()

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

References arg.

Referenced by hypercube(), and size().

285 {return arg->timestamp();}
Here is the caller graph for this function:

Member Data Documentation

◆ arg

TensorPtr civita::SortByValue::arg
private

Definition at line 273 of file tensorOp.h.

Referenced by timestamp().

◆ order

ravel::HandleSort::Order civita::SortByValue::order
private

Definition at line 274 of file tensorOp.h.


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