Minsky
MathDAG::SubexpressionCache Class Reference

#include <equations.h>

Collaboration diagram for MathDAG::SubexpressionCache:
Collaboration graph

Public Member Functions

std::string key (const OperationBase &x) const
 
std::string key (const VariableBase &x) const
 
std::string key (const SwitchIcon &x) const
 
std::string key (const Lock &x) const
 
std::string key (const string &x) const
 strings refer to variable names More...
 
template<class T >
bool exists (const T &x)
 
template<class T >
NodePtr operator[] (const T &x) const
 
template<class T >
const NodePtrinsert (const T &x, const NodePtr &n)
 
void insertIntegralInput (const string &name, const VariableDAGPtr &n)
 
VariableDAGPtr getIntegralInput (const string &name) const
 
std::size_t size () const
 
NodePtr reverseLookup (const Node &x) const
 returns NodePtr corresponding to object , if it exists in cache, nullptr otherwise More...
 
NodePtr insertAnonymous (NodePtr x)
 

Private Attributes

std::map< std::string, NodePtrcache
 
std::map< std::string, VariableDAGPtrintegrationInputs
 
std::map< const Node *, NodePtrreverseLookupCache
 

Detailed Description

Definition at line 292 of file equations.h.

Member Function Documentation

◆ exists()

template<class T >
bool MathDAG::SubexpressionCache::exists ( const T &  x)
inline

Definition at line 315 of file equations.h.

Referenced by MathDAG::SystemOfEquations::getNodeFromVar(), MathDAG::SystemOfEquations::getNodeFromWire(), and MathDAG::SystemOfEquations::makeDAG().

315 {return cache.count(key(x));}
std::string key(const OperationBase &x) const
Definition: equations.h:298
std::map< std::string, NodePtr > cache
Definition: equations.h:294
Here is the caller graph for this function:

◆ getIntegralInput()

VariableDAGPtr MathDAG::SubexpressionCache::getIntegralInput ( const string &  name) const
inline

Definition at line 333 of file equations.h.

Referenced by MathDAG::SystemOfEquations::getDefFromIntVar(), MathDAG::SystemOfEquations::getNodeFromIntVar(), MathDAG::SystemOfEquations::latex(), MathDAG::SystemOfEquations::latexWrapped(), MathDAG::SystemOfEquations::matlab(), and MathDAG::SystemOfEquations::SystemOfEquations().

333  {
334  auto r=integrationInputs.find("input:"+name);
335  if (r!=integrationInputs.end())
336  return r->second;
337  else
338  return VariableDAGPtr();
339  }
shared_ptr< VariableDAG > VariableDAGPtr
Definition: equations.h:208
std::map< std::string, VariableDAGPtr > integrationInputs
Definition: equations.h:295
Here is the caller graph for this function:

◆ insert()

template<class T >
const NodePtr& MathDAG::SubexpressionCache::insert ( const T &  x,
const NodePtr n 
)
inline

Definition at line 325 of file equations.h.

Referenced by MathDAG::SystemOfEquations::makeDAG().

325  {
326  reverseLookupCache[n.get()]=n;
327  return cache.insert(make_pair(key(x),n)).first->second;
328  }
std::string key(const OperationBase &x) const
Definition: equations.h:298
std::map< const Node *, NodePtr > reverseLookupCache
Definition: equations.h:296
std::map< std::string, NodePtr > cache
Definition: equations.h:294
Here is the caller graph for this function:

◆ insertAnonymous()

NodePtr MathDAG::SubexpressionCache::insertAnonymous ( NodePtr  x)
inline

Definition at line 351 of file equations.h.

Referenced by MathDAG::CachedOp< T >::CachedOp(), MathDAG::Expr::Expr(), MathDAG::Expr::newNode(), MathDAG::Expr::operator*(), MathDAG::Expr::operator+(), MathDAG::Expr::operator-(), MathDAG::Expr::operator/(), and MathDAG::SystemOfEquations::SystemOfEquations().

351  {
352  assert(x);
353  return reverseLookupCache.insert(make_pair(x.get(), x)).first->second;
354  }
std::map< const Node *, NodePtr > reverseLookupCache
Definition: equations.h:296
Here is the caller graph for this function:

◆ insertIntegralInput()

void MathDAG::SubexpressionCache::insertIntegralInput ( const string &  name,
const VariableDAGPtr n 
)
inline

Definition at line 329 of file equations.h.

Referenced by MathDAG::SystemOfEquations::SystemOfEquations().

329  {
330  integrationInputs.insert(make_pair("input:"+name,n));
331  reverseLookupCache[n.get()]=n;
332  }
std::map< const Node *, NodePtr > reverseLookupCache
Definition: equations.h:296
std::map< std::string, VariableDAGPtr > integrationInputs
Definition: equations.h:295
Here is the caller graph for this function:

◆ key() [1/5]

std::string MathDAG::SubexpressionCache::key ( const OperationBase x) const
inline

Definition at line 298 of file equations.h.

References minsky::Item::ports(), and minsky::to_string().

298  {
299  return "op:"+std::to_string(std::size_t(x.ports(0).lock().get()));
300  }
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
Definition: item.h:180
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
Here is the call graph for this function:

◆ key() [2/5]

std::string MathDAG::SubexpressionCache::key ( const VariableBase x) const
inline

Definition at line 301 of file equations.h.

References minsky::VariableBase::valueId().

301  {
302  return "var:"+x.valueId();
303  }
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
Here is the call graph for this function:

◆ key() [3/5]

std::string MathDAG::SubexpressionCache::key ( const SwitchIcon x) const
inline

Definition at line 304 of file equations.h.

References minsky::Item::ports(), and minsky::to_string().

304  {
305  return "switch:"+std::to_string(std::size_t(x.ports(0).lock().get()));
306  }
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
Definition: item.h:180
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
Here is the call graph for this function:

◆ key() [4/5]

std::string MathDAG::SubexpressionCache::key ( const Lock x) const
inline

Definition at line 307 of file equations.h.

References minsky::Item::ports(), and minsky::to_string().

307  {
308  return "lock:"+std::to_string(std::size_t(x.ports(0).lock().get()));
309  }
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
Definition: item.h:180
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
Here is the call graph for this function:

◆ key() [5/5]

std::string MathDAG::SubexpressionCache::key ( const string &  x) const
inline

strings refer to variable names

Definition at line 311 of file equations.h.

311  {
312  return "var:"+x;
313  }

◆ operator[]()

template<class T >
NodePtr MathDAG::SubexpressionCache::operator[] ( const T &  x) const
inline

Definition at line 317 of file equations.h.

317  {
318  auto r=cache.find(key(x));
319  if (r!=cache.end())
320  return r->second;
321  else
322  return NodePtr();
323  }
std::string key(const OperationBase &x) const
Definition: equations.h:298
std::map< std::string, NodePtr > cache
Definition: equations.h:294
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ reverseLookup()

NodePtr MathDAG::SubexpressionCache::reverseLookup ( const Node x) const
inline

returns NodePtr corresponding to object , if it exists in cache, nullptr otherwise

Definition at line 342 of file equations.h.

342  {
343  auto it=reverseLookupCache.find(&x);
344  if (it==reverseLookupCache.end())
345  return NodePtr();
346  else
347  return it->second;
348  }
std::map< const Node *, NodePtr > reverseLookupCache
Definition: equations.h:296
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ size()

std::size_t MathDAG::SubexpressionCache::size ( ) const
inline

Definition at line 340 of file equations.h.

Referenced by MathDAG::SystemOfEquations::SystemOfEquations().

340 {return cache.size()+integrationInputs.size();}
std::map< std::string, NodePtr > cache
Definition: equations.h:294
std::map< std::string, VariableDAGPtr > integrationInputs
Definition: equations.h:295
Here is the caller graph for this function:

Member Data Documentation

◆ cache

std::map<std::string, NodePtr > MathDAG::SubexpressionCache::cache
private

Definition at line 294 of file equations.h.

◆ integrationInputs

std::map<std::string, VariableDAGPtr> MathDAG::SubexpressionCache::integrationInputs
private

Definition at line 295 of file equations.h.

◆ reverseLookupCache

std::map<const Node*, NodePtr> MathDAG::SubexpressionCache::reverseLookupCache
private

Definition at line 296 of file equations.h.


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