Utilities#

Cake offers basic utilities pre-written for its users to use, these are usually designed to help assist users with writing there own versions of our elements in the module.

cake.utils.solve_if_possible(__x_v: Any, /, **kwds) Any[source]#

Attempts to solve a given value if possible else returns original value.

>>> f = Sqrt(Variable('x') + 3)
>>> f
Sqrt(x + 3)
>>> utils.solve_if_possible(f, x=6)
Real(3.0)
>>> utils.solve_if_possible(Real(5), x=3)
Real(5.0)
cake.utils.to_degrees(x: Any, *, use_constant: bool = False) Any[source]#

Converts the desired input from radians to degrees

Parameters:
  • x (Any) – Value to convert to radians

  • use_constant (bool) – Whether to use Pi instead of math.pi

cake.utils.to_radians(x: Any, *, use_constant: bool = False) Any[source]#

Converts the desired input from degrees into radians

Parameters:
  • x (Any) – Value to convert to radians

  • use_constant (bool) – Whether to use Pi instead of math.pi