Minsky
civita::Scan Class Reference

#include <tensorOp.h>

Inheritance diagram for civita::Scan:
Inheritance graph
Collaboration diagram for civita::Scan:
Collaboration graph

Public Member Functions

template<class F >
 Scan (F f, const TensorPtr &arg={}, const std::string &dimName="", double av=0)
 
void setArgument (const TensorPtr &arg, const ITensor::Args &args) override
 
void computeTensor () const override
 computeTensor updates the above two mutable fields, but is logically const More...
 
- Public Member Functions inherited from civita::DimensionedArgCachedOp
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::CachedTensorOp
const Index & index () const override
 the index vector - assumed to be ordered and unique More...
 
std::size_t size () const override
 return number of elements in tensor - maybe less than hypercube.numElements if sparse More...
 
double operator[] (std::size_t i) const override
 return or compute data at a location More...
 
const Hypercube & hypercube () const override
 information describing the axes, types and labels of this tensor 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})
 

Public Attributes

std::function< void(double &, double, std::size_t)> f
 
- Public Attributes inherited from civita::DimensionedArgCachedOp
std::size_t dimension =std::numeric_limits<std::size_t>::max()
 dimension to apply operation over. >rank = all dims More...
 
double argVal =0
 op arg value, eg binsize or delta in difference op More...
 
TensorPtr arg
 

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

Definition at line 208 of file tensorOp.h.

Constructor & Destructor Documentation

◆ Scan()

template<class F >
civita::Scan::Scan ( f,
const TensorPtr arg = {},
const std::string &  dimName = "",
double  av = 0 
)
inline

Definition at line 213 of file tensorOp.h.

213  {}, const std::string& dimName="", double av=0): f(f)
214  {Scan::setArgument(arg,{dimName,av});}
std::function< void(double &, double, std::size_t)> f
Definition: tensorOp.h:211
void setArgument(const TensorPtr &arg, const ITensor::Args &args) override
Definition: tensorOp.h:215

Member Function Documentation

◆ computeTensor()

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

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

Implements civita::CachedTensorOp.

Definition at line 199 of file tensorOp.cc.

References f.

200  {
201  if (dimension<rank())
202  {
203  auto argDims=arg->hypercube().dims();
204  size_t stride=1;
205  for (size_t j=0; j<dimension; ++j)
206  stride*=argDims[j];
207  if (argVal>=1 && argVal<argDims[dimension])
208  // argVal is interpreted as the binning window. -ve argVal ignored
209  for (size_t i=0; i<hypercube().numElements(); i+=stride*argDims[dimension])
210  for (size_t j=0; j<stride; ++j)
211  for (size_t j1=0; j1<argDims[dimension]*stride; j1+=stride)
212  {
213  size_t k=i+j+max(ssize_t(0), ssize_t(j1-ssize_t(argVal-1)*stride));
214  cachedResult[i+j+j1]=arg->atHCIndex(i+j+j1);
215  for (; k<i+j+j1; k+=stride)
216  {
217  f(cachedResult[i+j+j1], arg->atHCIndex(k), k);
218  }
219  }
220  else // scan over whole dimension
221  for (size_t i=0; i<hypercube().numElements(); i+=stride*argDims[dimension])
222  for (size_t j=0; j<stride; ++j)
223  {
224  cachedResult[i+j]=arg->atHCIndex(i+j);
225  for (size_t k=i+j+stride; k<i+j+stride*argDims[dimension]; k+=stride)
226  {
227  cachedResult[k] = cachedResult[k-stride];
228  f(cachedResult[k], arg->atHCIndex(k), k);
229  }
230  }
231  }
232  else
233  {
234  cachedResult[0]=arg->atHCIndex(0);
235  for (size_t i=1; i<hypercube().numElements(); ++i)
236  {
237  cachedResult[i]=cachedResult[i-1];
238  f(cachedResult[i], arg->atHCIndex(i), i);
239  }
240  }
241  }
double argVal
op arg value, eg binsize or delta in difference op
Definition: tensorOp.h:202
std::size_t rank() const
const Hypercube & hypercube() const override
information describing the axes, types and labels of this tensor
Definition: tensorOp.h:141
std::size_t dimension
dimension to apply operation over. >rank = all dims
Definition: tensorOp.h:200
std::function< void(double &, double, std::size_t)> f
Definition: tensorOp.h:211
TensorVal cachedResult
Definition: tensorOp.h:132

◆ setArgument()

void civita::Scan::setArgument ( const TensorPtr arg,
const ITensor::Args args 
)
inlineoverridevirtual

Reimplemented from civita::DimensionedArgCachedOp.

Definition at line 215 of file tensorOp.h.

References civita::DimensionedArgCachedOp::arg, civita::CachedTensorOp::cachedResult, and civita::DimensionedArgCachedOp::setArgument().

215  {
217  if (arg)
218  cachedResult.hypercube(arg->hypercube());
219  // TODO - can we handle sparse data?
220  }
void setArgument(const TensorPtr &a, const ITensor::Args &) override
Definition: tensorOp.cc:184
TensorVal cachedResult
Definition: tensorOp.h:132
Here is the call graph for this function:

Member Data Documentation

◆ f

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

Definition at line 211 of file tensorOp.h.


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