Minsky
minsky::Correlation Struct Reference
Inheritance diagram for minsky::Correlation:
Inheritance graph
Collaboration diagram for minsky::Correlation:
Collaboration graph

Public Member Functions

void setArguments (const TensorPtr &a1, const TensorPtr &a2, const ITensor::Args &args) override
 
template<class F >
void performSum (F f, size_t idx) const
 
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 double operator[] (std::size_t) const =0
 return or compute data at a location 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 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 Member Functions inherited from minsky::OpState
void setState (const OperationPtr &s) override
 
void throw_error (const std::string &msg) const
 
- Public Member Functions inherited from minsky::SetState
virtual ~SetState ()
 

Public Attributes

int dimension1
 
int dimension2
 
TensorPtr arg1
 
TensorPtr arg2
 
string errorMsg
 
- Public Attributes inherited from minsky::OpState
OperationPtr state
 

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 929 of file minskyTensorOps.cc.

Member Function Documentation

◆ performSum()

template<class F >
void minsky::Correlation::performSum ( f,
size_t  idx 
) const
inline

Definition at line 1002 of file minskyTensorOps.cc.

References f, and minsky::anonymous_namespace{userFunction.cc}::isfinite().

1003  {
1004  if (!errorMsg.empty()) throw_error(errorMsg);
1005  auto splitted=hypercube().splitIndex(idx);
1006  auto splitIndexIterator=splitted.begin();
1007 
1008  auto computeIndexAndStride=[&](size_t& lineal, size_t& stride, size_t dimension, const vector<unsigned>& dims) {
1009  lineal=0; stride=1;
1010  for (size_t i=0, s=1; i<dims.size(); s*=dims[i], ++i)
1011  if (i!=dimension)
1012  lineal+=*splitIndexIterator++ * s;
1013  else
1014  stride=s;
1015  };
1016 
1017  size_t arg1Lineal, arg1Stride, arg2Lineal, arg2Stride;
1018  computeIndexAndStride(arg1Lineal, arg1Stride, dimension1, arg1->hypercube().dims());
1019  computeIndexAndStride(arg2Lineal, arg2Stride, dimension2, arg2->hypercube().dims());
1020 
1021  for (size_t i=0; i<arg1->hypercube().xvectors[dimension1].size(); ++i)
1022  {
1023  auto x=arg1->atHCIndex(arg1Lineal+i*arg1Stride);
1024  auto y=arg2->atHCIndex(arg2Lineal+i*arg2Stride);
1025  if (isfinite(x) && isfinite(y)) f(x,y);
1026  }
1027 
1028  }
function f
Definition: canvas.m:1
void throw_error(const std::string &msg) const
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
Here is the call graph for this function:

◆ setArguments()

void minsky::Correlation::setArguments ( const TensorPtr a1,
const TensorPtr a2,
const ITensor::Args args 
)
inlineoverridevirtual

Reimplemented from civita::ITensor.

Definition at line 934 of file minskyTensorOps.cc.

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

936  {
937  arg1=a1? a1: a2;
938  arg2=a2? a2: a1;
939  if (!arg1 || !arg2) return;
940  errorMsg="";
941 
942  Hypercube hc;
943  set<string> dimNames; // for ensuring dimension names are unique
944  switch (arg1->rank())
945  {
946  case 0:
947  errorMsg="covariance or ρ needs at least rank 1 arguments";
948  return;
949  case 1:
950  dimension1=0;
951  break;
952  default:
953  dimension1=-1;
954  for (auto& xv:arg1->hypercube().xvectors)
955  if (xv.name==args.dimension)
956  dimension1=&xv-arg1->hypercube().xvectors.data();
957  else
958  {
959  hc.xvectors.push_back(xv);
960  dimNames.insert(xv.name);
961  }
962  break;
963  }
964 
965  switch (arg2->rank())
966  {
967  case 0:
968  errorMsg="covariance or ρ needs at least rank 1 arguments";
969  return;
970  case 1:
971  dimension2=0;
972  break;
973  default:
974  dimension2=-1;
975  for (auto& xv:arg2->hypercube().xvectors)
976  if (xv.name==args.dimension)
977  dimension2=&xv-arg2->hypercube().xvectors.data();
978  else
979  {
980  hc.xvectors.push_back(xv);
981  if (!dimNames.insert(xv.name).second)
982  hc.xvectors.back().name+="'"; // ensure dimension names are unique
983  }
984  break;
985  }
986 
987  if (dimension1<0 || dimension2<0)
988  {
989  errorMsg="dimension "+args.dimension+" not found";
990  return;
991  }
992  if (arg1->hypercube().xvectors[dimension1].size() != arg2->hypercube().xvectors[dimension2].size())
993  {
994  errorMsg="arguments not conformant";
995  return;
996  }
997 
998  hypercube(hc);
999 
1000  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor

◆ timestamp()

Timestamp minsky::Correlation::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 1029 of file minskyTensorOps.cc.

1030  {return max(arg1->timestamp(), arg2->timestamp());}

Member Data Documentation

◆ arg1

TensorPtr minsky::Correlation::arg1

Definition at line 932 of file minskyTensorOps.cc.

◆ arg2

TensorPtr minsky::Correlation::arg2

Definition at line 932 of file minskyTensorOps.cc.

◆ dimension1

int minsky::Correlation::dimension1

Definition at line 931 of file minskyTensorOps.cc.

◆ dimension2

int minsky::Correlation::dimension2

Definition at line 931 of file minskyTensorOps.cc.

◆ errorMsg

string minsky::Correlation::errorMsg

Definition at line 933 of file minskyTensorOps.cc.


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