Skip to content

2. Math Nodes (csp.math)

github-actions[bot] edited this page Mar 14, 2024 · 2 revisions

Math and Logic nodes

In an effort not to bloat the wiki, the following boolean and mathematical operations are available which should be self explanatory.

Also note that there is syntactic sugar in place when wiring a graph. Edges have most operators overloaded includes +, -, *, /, **, >, >=, <, <=, ==, !=, so you can have code like csp.const(1) + csp.const(2) work properly. Right hand side values will also automatically be upgraded to csp.const(<value>) if its detected that its not an edge, so something like x = csp.const(1) + 2 will work as well.

Binary logical operators

  • csp.not_(ts[bool]) → ts[bool]
  • csp.and_(x: [ts[bool]]) → ts[bool]
  • csp.or_(x: [ts[bool]]) → ts[bool]

Binary mathematical operators

  • csp.add(x: ts['T'], y: ts['T']) → ts['T']
  • csp.sub(x: ts['T'], y: ts['T']) → ts['T']
  • csp.multiply(x: ts['T'], y: ts['T']) → ts['T']
  • csp.divide(x: ts['T'], y: ts['T']) → ts[float]
  • csp.pow(x: ts['T'], y: ts['T']) → ts['T']
  • csp.min/max(x: ts['T'], y: ts['T']) → ts['T']
  • gt/ge/lt/le/eq/ne(x: ts['T'], y: ts['T']) → ts[bool]

Unary mathematical operators

  • ln/log2/log10(x: ts[float]) → ts[float]
  • exp/exp2(x: ts[float]) → ts[float]
  • sqrt(x: ts[float]) → ts[float]
  • abs(x: ts[float]) → ts[float]
  • sin/cos/tan/arcsin/arccos/arctan/sinh/cosh/tanh/arcsinh/arccosh/arctanh(x: ts[float]) → ts[float]
  • erf(x: ts[float]) → ts[float]

Many of these are also exposed as dunder operators:

Operators

  • __add__
  • __sub__
  • __mul__
  • __truediv__
  • __floordiv__
  • __pow__
  • __invert__: bitwise not
  • __mod__
  • __abs__
  • __pos__
  • __neg__

Comparators

  • __gt__
  • __ge__
  • __lt__
  • __le__
  • __eq__
  • __ne__

Clone this wiki locally