Minsky
minsky::TensorEval Class Reference

A helper to evaluate a variable value. More...

#include <minskyTensorOps.h>

Inheritance diagram for minsky::TensorEval:
Inheritance graph
Collaboration diagram for minsky::TensorEval:
Collaboration graph

Public Member Functions

Type type () const override
 
 TensorEval (const std::shared_ptr< VariableValue > &v, const shared_ptr< EvalCommon > &ev, const TensorPtr &rhs)
 
 TensorEval (const std::shared_ptr< VariableValue > &dest, const std::shared_ptr< VariableValue > &src)
 
void eval (double *fv, std::size_t, const double *sv) override
 
void deriv (double *df, std::size_t, const double *ds, const double *sv, const double *fv) override
 

Private Attributes

TensorVarVal result
 
TensorPtr rhs
 

Detailed Description

A helper to evaluate a variable value.

Definition at line 157 of file minskyTensorOps.h.

Constructor & Destructor Documentation

◆ TensorEval() [1/2]

minsky::TensorEval::TensorEval ( const std::shared_ptr< VariableValue > &  v,
const shared_ptr< EvalCommon > &  ev,
const TensorPtr rhs 
)
inline

Definition at line 166 of file minskyTensorOps.h.

References minsky::TensorVarVal::hypercube(), minsky::TensorVarValBase< VV, I >::idx(), minsky::TensorVarVal::index(), and minsky::TensorVarValBase< VV, I >::size().

167  : result(v, ev), rhs(rhs) {
168  result.index(rhs->index());
169  assert(!rhs->index().empty() || rhs->hypercube().numElements()==rhs->size());
170  result.hypercube(rhs->hypercube());
171  assert(result.idx()>=0);
172  assert(result.size()==rhs->size());
173  }
const Hypercube & hypercube(const Hypercube &hc) override
const Index & index(Index &&x) override
std::size_t size() const override
Here is the call graph for this function:

◆ TensorEval() [2/2]

minsky::TensorEval::TensorEval ( const std::shared_ptr< VariableValue > &  dest,
const std::shared_ptr< VariableValue > &  src 
)

Definition at line 1651 of file minskyTensorOps.cc.

References minsky::OperationType::copy, minsky::TensorOpFactory::create(), minsky::TensorVarValBase< VV, I >::ev, minsky::TensorVarVal::hypercube(), minsky::TensorVarVal::index(), result, rhs, civita::ITensor::setArgument(), minsky::TensorVarValBase< VV, I >::size(), and minsky::tensorOpFactory.

1651  :
1652  result(dest,make_shared<EvalCommon>())
1653  {
1654  result.index(src->index());
1655  result.hypercube(src->hypercube());
1656  const OperationPtr tmp(OperationType::copy);
1657  auto copy=dynamic_pointer_cast<ITensor>(tensorOpFactory.create(tmp));
1658  copy->setArgument(make_shared<ConstTensorVarVal>(src,result.ev));
1659  rhs=std::move(copy);
1660  assert(result.size()==rhs->size());
1661  }
shared_ptr< EvalCommon > ev
reference to EvalOpVector owning this value, to extract flowVar and stockVarinfo
const Hypercube & hypercube(const Hypercube &hc) override
std::shared_ptr< ITensor > create(const ItemPtr &, const TensorsFromPort &tp={})
create a tensor representation of the expression rooted at op. If expression doesn&#39;t contain any refe...
const Index & index(Index &&x) override
virtual void setArgument(const TensorPtr &, const ITensor::Args &args={"", 0})
TensorOpFactory tensorOpFactory
std::size_t size() const override
Here is the call graph for this function:

Member Function Documentation

◆ deriv()

void minsky::TensorEval::deriv ( double *  df,
std::size_t  ,
const double *  ds,
const double *  sv,
const double *  fv 
)
override

Definition at line 1689 of file minskyTensorOps.cc.

References minsky::TensorVarValBase< VV, I >::ev, minsky::ValueVector::flowVars, minsky::TensorVarValBase< VV, I >::idx(), result, rhs, minsky::TensorVarValBase< VV, I >::size(), and minsky::ValueVector::stockVars.

1691  {
1692  if (result.idx()<0) return;
1693  if (rhs)
1694  {
1695  result.ev->update(const_cast<double*>(fv), n, sv);
1696  if (auto deriv=dynamic_cast<DerivativeMixin*>(rhs.get()))
1697  {
1698  assert(result.idx()+rhs->size()<=n);
1699  for (size_t i=0; i<rhs->size(); ++i)
1700  {
1701  df[result.idx()+i]=0;
1702  for (int j=0; j<result.idx(); ++j)
1703  df[result.idx()+i] += df[j]*deriv->dFlow(i,j);
1704  // skip self variables
1705  for (size_t j=result.idx()+result.size(); j<ValueVector::flowVars.size(); ++j)
1706  df[result.idx()+i] += df[j]*deriv->dFlow(i,j);
1707  for (size_t j=0; j<ValueVector::stockVars.size(); ++j)
1708  df[result.idx()+i] += ds[j]*deriv->dStock(i,j);
1709  }
1710  }
1711  }
1712  }
shared_ptr< EvalCommon > ev
reference to EvalOpVector owning this value, to extract flowVar and stockVarinfo
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
vector of variables that are integrated via Runge-Kutta. These variables label the columns of the God...
void deriv(double *df, std::size_t, const double *ds, const double *sv, const double *fv) override
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
std::size_t size() const override
Here is the call graph for this function:

◆ eval()

void minsky::TensorEval::eval ( double *  fv,
std::size_t  ,
const double *  sv 
)
override

Definition at line 1663 of file minskyTensorOps.cc.

References minsky::TensorVarValBase< VV, I >::ev, minsky::ValueVector::flowVars, minsky::TensorVarVal::hypercube(), minsky::TensorVarValBase< VV, I >::idx(), minsky::TensorVarVal::index(), minsky::anonymous_namespace{userFunction.cc}::isfinite(), result, rhs, and minsky::TensorVarValBase< VV, I >::size().

1664  {
1665  if (rhs)
1666  {
1667  assert(result.idx()>=0);
1668  const bool fvIsGlobalFlowVars=fv==ValueVector::flowVars.data();
1669  result.index(rhs->index());
1670  result.hypercube(rhs->hypercube());
1671  if (fvIsGlobalFlowVars) // hypercube operation may have resized flowVars, invalidating fv
1672  {
1673  fv=ValueVector::flowVars.data();
1674  n=ValueVector::flowVars.size();
1675  }
1676  else if (n!=ValueVector::flowVars.size())
1677  throw FlowVarsResized();
1678  result.ev->update(fv, n, sv);
1679  assert(result.size()==rhs->size());
1680  for (size_t i=0; i<rhs->size(); ++i)
1681  {
1682  auto v=(*rhs)[i];
1683  result[i]=v;
1684  assert(!isfinite(result[i]) || fv[result.idx()+i]==v);
1685  }
1686  }
1687  }
shared_ptr< EvalCommon > ev
reference to EvalOpVector owning this value, to extract flowVar and stockVarinfo
const Hypercube & hypercube(const Hypercube &hc) override
const Index & index(Index &&x) override
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
std::size_t size() const override
Here is the call graph for this function:

◆ type()

Type minsky::TensorEval::type ( ) const
inlineoverride

Definition at line 165 of file minskyTensorOps.h.

References minsky::OperationType::numOps.

Member Data Documentation

◆ result

TensorVarVal minsky::TensorEval::result
private

Definition at line 160 of file minskyTensorOps.h.

Referenced by deriv(), eval(), and TensorEval().

◆ rhs

TensorPtr minsky::TensorEval::rhs
private

Definition at line 161 of file minskyTensorOps.h.

Referenced by deriv(), eval(), and TensorEval().


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