Functions#

Functions are yet another powerful object in the cake library, which are able to support the use of generic cake objects within them as parameters.

Note

For pre-defined functions visit the Functions section for more info.

Function#

class cake.Function(parameter: Any, coefficient: Any = 1, power: Any = 1)[source]#

Bases: Function, ABC

Represents a basic function in the cake library, this base function can be used to define your own functions in an elegant manner.

from cake import *

class MyFunc(Function):
    def _handler(self, value, **options) -> Any:
        return value * 3

f = MyFunc(Variable('x'))
print(f.evaluate(x=3))
# 9
Parameters:
  • parameter (Any[Like[cake.BasicNode]]:) – Parameter of the function, can be any value which is like a BasicNode.

  • coefficient (Any[Like[cake.BasicNode]]) – Coefficient of the function, can be any value which is like a BasicNode.

  • power (Any[Like[cake.BasicNode]]) –

    The value the function may be raised to, can be any value which is like a BasicNode.

    >>> s = Sin(Variable('x'), power=2)
    # s == sin^2(x)
    

auto_postprocess: bool#

Whether to automatically post process value

auto_prehandle: bool#

Whether to automatically pre-handle a value, this is right before the value is passed through the handler

Warning

this is after the value is converted to radians!

auto_preprocess: bool#

Whether to automatically preprocess value

auto_to_radians: bool#

Convert value to radians before passing through function

coefficient: Any#

Functions coefficient

copy() Function[source]#

Returns a shallow copy of the function

evaluate(to_radians: bool = False, use_preprocess: bool = False, use_postprocess: bool = False, use_prehandler: bool = False, **kwds) Any[source]#

Evaluates the function, returning a result.

Parameters:
  • to_radians (bool) – Whether to convert value given to radians, useful for trig applications.

  • use_preprocess (bool) – Whether to use given pre processor, if any.

  • use_postprocess (bool) – Whether to use given post processor, if any.

  • use_prehandler (bool) – Whether to use given pre handler, if any.

  • **kwds (Any[Like[cake.BasicNode]]) – Any values for variables to use.

parameter: Any#

Internal parameter of function

postprocessor: Callable[[Any], Any]#

postprocessor function

power: Any#

Power function is raised to

prehandler: Callable[[Any], Any]#

prehandler function

preprocessor: Callable[[dict], dict]#

preprocessor function, the value passed is the dictionary of given values, must return a new mapping of values to use instead.