Minsky
minsky::TensorOpFactory Class Reference

As it says on the tin, this is a factory for creating a TensorOp which can compute the result of op applied to its arguments and so on until all the argument terminate in variables. More...

#include <minskyTensorOps.h>

Inheritance diagram for minsky::TensorOpFactory:
Inheritance graph
Collaboration diagram for minsky::TensorOpFactory:
Collaboration graph

Public Member Functions

 TensorOpFactory ()
 
std::shared_ptr< ITensorcreate (const ItemPtr &, const TensorsFromPort &tp={})
 create a tensor representation of the expression rooted at op. If expression doesn't contain any references variables, then the tp parameter may be omitted. More...
 

Private Types

enum  Type
 

Detailed Description

As it says on the tin, this is a factory for creating a TensorOp which can compute the result of op applied to its arguments and so on until all the argument terminate in variables.

Definition at line 72 of file minskyTensorOps.h.

Member Enumeration Documentation

◆ Type

=>["constant","time","integrate","differentiate","data","ravel","add","subtract","multiply","divide","log","pow","lt","le","eq","min","max","and_","or_","copy","sqrt","exp","ln","sin","cos","tan","asin","acos","atan","sinh","cosh","tanh","abs","floor","frac","not_","sum","product","infimum","supremum","any","all","infIndex","supIndex","runningSum","runningProduct","difference","innerProduct","outerProduct","index","gather","numOps"]

and variable types with

/

Definition at line 29 of file operationType.h.

29  {constant, // deprecated - left to support legacy schemas
30  time, // zero input port ops
31  integrate,
32  differentiate, // with respect to time
33  data, // an interpolated data item
34  ravel, // Ravelâ„¢
35  euler, pi, zero, one, inf, percent,// fundamental constants
36  // multiwire binary ops
37  add, subtract, multiply, divide, min, max,
38  // underscores to avoid C++ keywords. Can be filtered at UI
39  and_, or_,
40  // single wire binops
41  log, pow, polygamma,
42  lt, le, eq,
43  userFunction,
44  // functions
45  copy, sqrt, exp, ln, sin, cos, tan, asin, acos, atan,
46  sinh, cosh, tanh, abs,
47  floor, frac, not_, Gamma, fact,
48  // reductions
49  sum, product, infimum, supremum, any, all, infIndex, supIndex,
50  // scans
51  runningSum, runningProduct, difference, differencePlus,
52  // other tensor ops
53  innerProduct, outerProduct, index, gather, meld, merge, slice, size, shape,
54  // statistics
55  mean, median, stdDev, moment, histogram, covariance, correlation, linearRegression,
56  numOps // last operation, for iteration purposes
57  };
Expr sin(const Expr &x)
Definition: expr.h:131
Expr cos(const Expr &x)
Definition: expr.h:137
Expr polygamma(const Expr &x, const Expr &y)
Definition: expr.h:166
UnitsExpressionWalker pow(const UnitsExpressionWalker &x, const UnitsExpressionWalker &y)
Expr sqrt(const Expr &x)
Definition: expr.h:154
Expr Gamma(const Expr &x)
Definition: expr.h:160
Expr exp(const Expr &x)
Definition: expr.h:126
Expr sinh(const Expr &x)
Definition: expr.h:142
Expr cosh(const Expr &x)
Definition: expr.h:148
Expr fact(const Expr &x)
Definition: expr.h:173
Expr log(const Expr &x)
Definition: expr.h:120

Constructor & Destructor Documentation

◆ TensorOpFactory()

minsky::TensorOpFactory::TensorOpFactory ( )

Definition at line 328 of file minskyTensorOps.cc.

329  {
330  registerType<TimeOp>(OperationType::time);
331  registerOps<MinskyTensorOp, OperationType::euler, OperationType::add>(*this);
332  registerOps<MultiWireBinOp, OperationType::add, OperationType::log>(*this);
333  registerOps<TensorBinOp, OperationType::log, OperationType::copy>(*this);
334  registerOps<MinskyTensorOp, OperationType::copy, OperationType::sum>(*this);
335  registerOps<GeneralTensorOp, OperationType::sum, OperationType::numOps>(*this);
336  }

Member Function Documentation

◆ create()

std::shared_ptr< ITensor > minsky::TensorOpFactory::create ( const ItemPtr it,
const TensorsFromPort tp = {} 
)

create a tensor representation of the expression rooted at op. If expression doesn't contain any references variables, then the tp parameter may be omitted.

Definition at line 1545 of file minskyTensorOps.cc.

References minsky::cminsky(), civita::createRavelChain(), minsky::Minsky::displayErrorItem(), minsky::TensorsFromPort::ev, minsky::op, minsky::TensorsFromPort::tensorsFromPort(), and minsky::TensorsFromPort::tensorsFromPorts().

Referenced by MathDAG::anonymous_namespace{equations.cc}::addTensorOp(), minsky::Ravel::exportAsCSV(), minsky::TensorEval::TensorEval(), and minsky::TensorsFromPort::tensorsFromPort().

1546  {
1547  if (auto ravel=dynamic_cast<const Ravel*>(it.get()))
1548  {
1549  auto r=make_shared<RavelTensor>(*ravel);
1550  r->setArguments(tfp.tensorsFromPorts(*it));
1551  return r;
1552  }
1553  if (auto op=it->operationCast())
1554  try
1555  {
1556  TensorPtr r{create(op->type())};
1557  if (auto ss=dynamic_cast<SetState*>(r.get()))
1558  ss->setState(dynamic_pointer_cast<OperationBase>(it));
1559  switch (op->portsSize())
1560  {
1561  case 2:
1562  r->setArguments(tfp.tensorsFromPort(*op->ports(1).lock()),{op->axis,op->arg});
1563  break;
1564  case 3:
1565  r->setArguments(tfp.tensorsFromPort(*op->ports(1).lock()), tfp.tensorsFromPort(*op->ports(2).lock()),{op->axis,op->arg});
1566  break;
1567  }
1568  return r;
1569  }
1570  catch (const InvalidType&)
1571  {return {};}
1572  catch (const TensorOpError&)
1573  {throw;}
1574  catch (const FallBackToScalar&)
1575  {throw;}
1576  catch (const std::exception& ex)
1577  {
1578  // mark op on canvas, and rethrow as TensorOpError to indicate op is marked
1580  throw TensorOpError(ex.what());
1581  }
1582  else if (auto v=it->variableCast())
1583  return make_shared<ConstTensorVarVal>(v->vValue(), tfp.ev);
1584  else if (auto sw=dynamic_cast<const SwitchIcon*>(it.get()))
1585  {
1586  auto r=make_shared<SwitchTensor>();
1587  r->setArguments(tfp.tensorsFromPorts(*it));
1588  return r;
1589  }
1590  else if (auto l=dynamic_cast<const Lock*>(it.get()))
1591  {
1592  if (l->locked())
1593  {
1594  if (auto r=l->ravelInput())
1595  if (auto p=r->ports(1).lock())
1596  {
1597  assert(!tfp.tensorsFromPort(*p).empty());
1598  auto chain=createRavelChain(l->lockedState, tfp.tensorsFromPort(*p)[0]);
1599  if (!chain.empty())
1600  return chain.back();
1601  }
1602  }
1603  else
1604  if (auto tensors=tfp.tensorsFromPort(*l->ports(1).lock()); !tensors.empty())
1605  return tensors.front();
1606  }
1607  return {};
1608  }
void displayErrorItem(const Item &op) const
indicate operation item has error, if visible, otherwise contining group
Definition: minsky.cc:1230
vector< TensorPtr > createRavelChain(const ravel::RavelState &state, const TensorPtr &arg)
creates a chain of tensor operations that represents a Ravel in state state, operating on arg ...
Definition: tensorOp.cc:497
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 Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
std::shared_ptr< ITensor > TensorPtr
Here is the call graph for this function:
Here is the caller graph for this function:

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