Minsky
civita::ReduceArguments Class Reference

elementwise reduction over a vector of arguments More...

#include <tensorOp.h>

Inheritance diagram for civita::ReduceArguments:
Inheritance graph
Collaboration diagram for civita::ReduceArguments:
Collaboration graph

Public Member Functions

template<class F >
 ReduceArguments (F f, double init)
 
void setArguments (const std::vector< 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 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})
 

Private Attributes

std::vector< TensorPtrargs
 
std::function< void(double &, double)> f
 
double init
 

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

elementwise reduction over a vector of arguments

Definition at line 82 of file tensorOp.h.

Constructor & Destructor Documentation

◆ ReduceArguments()

template<class F >
civita::ReduceArguments::ReduceArguments ( f,
double  init 
)
inline

Definition at line 88 of file tensorOp.h.

88 : f(f), init(init) {}
std::function< void(double &, double)> f
Definition: tensorOp.h:85

Member Function Documentation

◆ operator[]()

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

return or compute data at a location

Implements civita::ITensor.

Definition at line 69 of file tensorOp.cc.

References f, TCLcmd::trap::init, and minsky::anonymous_namespace{userFunction.cc}::isnan().

70  {
71  if (args.empty()) return init;
72  assert(i<size());
73  double r=init;
74  for (const auto& j: args)
75  {
76  auto x=j->rank()==0? (*j)[0]: (*j)[i];
77  if (!isnan(x)) f(r, x);
78  }
79  return r;
80  }
std::vector< TensorPtr > args
Definition: tensorOp.h:84
std::function< void(double &, double)> f
Definition: tensorOp.h:85
virtual std::size_t size() const
return number of elements in tensor - maybe less than hypercube.numElements if sparse ...
Here is the call graph for this function:

◆ setArguments()

void civita::ReduceArguments::setArguments ( const std::vector< TensorPtr > &  a,
const ITensor::Args  
)
overridevirtual

Reimplemented from civita::ITensor.

Definition at line 49 of file tensorOp.cc.

50  {
51  hypercube({});
52  if (!a.empty())
53  {
54  auto hc=a[0]->hypercube();
55  hypercube(hc);
56  size_t cnt=0;
57  set<size_t> idx;
58  for (const auto& i: a)
59  {
60  if (i->rank()>0 && i->hypercube()!=hc)
61  throw runtime_error("arguments not conformal");
62  idx.insert(i->index().begin(), i->index().end());
63  }
64  m_index=idx;
65  }
66  args=a;
67  }
std::vector< TensorPtr > args
Definition: tensorOp.h:84
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor

◆ timestamp()

ITensor::Timestamp civita::ReduceArguments::timestamp ( ) const
overridevirtual

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 82 of file tensorOp.cc.

83  {
84  Timestamp t;
85  for (const auto& i: args)
86  t=max(t, i->timestamp());
87  return t;
88  }
std::vector< TensorPtr > args
Definition: tensorOp.h:84
std::chrono::time_point< std::chrono::high_resolution_clock > Timestamp

Member Data Documentation

◆ args

std::vector<TensorPtr> civita::ReduceArguments::args
private

Definition at line 84 of file tensorOp.h.

◆ f

std::function<void(double&,double)> civita::ReduceArguments::f
private

Definition at line 85 of file tensorOp.h.

◆ init

double civita::ReduceArguments::init
private

Definition at line 86 of file tensorOp.h.


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