Minsky
civita::ReduceAllOp Struct Reference

reduce all elements to a single number More...

#include <tensorOp.h>

Inheritance diagram for civita::ReduceAllOp:
Inheritance graph
Collaboration diagram for civita::ReduceAllOp:
Collaboration graph

Public Member Functions

void setArgument (const TensorPtr &a, const ITensor::Args &) override
 
template<class F >
 ReduceAllOp (F f, double init, const std::shared_ptr< ITensor > &arg={})
 
double operator[] (std::size_t) 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})
 

Public Attributes

std::function< void(double &, double, std::size_t)> f
 
double init
 
std::shared_ptr< ITensorarg
 

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

reduce all elements to a single number

Definition at line 96 of file tensorOp.h.

Constructor & Destructor Documentation

◆ ReduceAllOp()

template<class F >
civita::ReduceAllOp::ReduceAllOp ( f,
double  init,
const std::shared_ptr< ITensor > &  arg = {} 
)
inline

Definition at line 104 of file tensorOp.h.

104  {}):
105  f(f),init(init), arg(arg) {}
std::shared_ptr< ITensor > arg
Definition: tensorOp.h:100
std::function< void(double &, double, std::size_t)> f
Definition: tensorOp.h:98

Member Function Documentation

◆ operator[]()

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

return or compute data at a location

Implements civita::ITensor.

Reimplemented in civita::StdDeviation, civita::Average, and civita::ReductionOp.

Definition at line 90 of file tensorOp.cc.

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

91  {
92  double r=init;
93  for (size_t i=0; i<arg->size(); ++i)
94  {
95  double x=(*arg)[i];
96  if (!isnan(x)) f(r,x,i);
97  }
98  return r;
99  }
std::shared_ptr< ITensor > arg
Definition: tensorOp.h:100
std::function< void(double &, double, std::size_t)> f
Definition: tensorOp.h:98
Here is the call graph for this function:

◆ setArgument()

void civita::ReduceAllOp::setArgument ( const TensorPtr a,
const ITensor::Args  
)
inlineoverridevirtual

Reimplemented from civita::ITensor.

Reimplemented in civita::ReductionOp.

Definition at line 101 of file tensorOp.h.

References arg.

101 {arg=a;}
std::shared_ptr< ITensor > arg
Definition: tensorOp.h:100

◆ timestamp()

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

References arg.

108 {return arg->timestamp();}
std::shared_ptr< ITensor > arg
Definition: tensorOp.h:100

Member Data Documentation

◆ arg

std::shared_ptr<ITensor> civita::ReduceAllOp::arg

Definition at line 100 of file tensorOp.h.

Referenced by setArgument(), and timestamp().

◆ f

std::function<void(double&,double,std::size_t)> civita::ReduceAllOp::f

Definition at line 98 of file tensorOp.h.

◆ init

double civita::ReduceAllOp::init

Definition at line 99 of file tensorOp.h.


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