simple Sympy helper functions
- modulus.sympy_utils.functions.line(x, point_x_1, point_y_1, point_x_2, point_y_2)
line function from point intercepts
- xSympy Symbol/Exp
- point_x_1Sympy Symbol/Exp, float, int
- point_y_1Sympy Symbol/Exp, float, int
- point_x_2Sympy Symbol/Exp, float, int
- point_y_2Sympy Symbol/Exp, float, int
the x in equation y=a*x+b
first intercept x position
first intercept y position
second intercept x position
second intercept y position
- ySympy Expr
y=slope*x+intercept
- modulus.sympy_utils.functions.parabola(x, inter_1, inter_2, height)
parabola from point intercepts
- xSympy Symbol/Exp
- inter_1Sympy Symbol/Exp, float, int
- inter_2Sympy Symbol/Exp, float, int
- heightSympy Symbol/Exp, float, int
the x in equation y=a*x*2+b*x+c
first intercept such that y=0 when x=inter_1
second intercept such that y=0 when x=inter_1
max height of parabola
- ySympy Expr
y=factor*(x-inter_1)*(x-+inter_2)
- modulus.sympy_utils.functions.parabola2D(x, y, inter_1_x, inter_2_x, inter_1_y, inter_2_y, height)
square parabola from point intercepts
- xSympy Symbol/Exp
- ySympy Symbol/Exp
- inter_1_xSympy Symbol/Exp, float, int
- inter_2_xSympy Symbol/Exp, float, int
- inter_1_ySympy Symbol/Exp, float, int
- inter_2_ySympy Symbol/Exp, float, int
- heightSympy Symbol/Exp, float, int
the x in equation z=parabola(x)*parabola(y)
the y in equation z=a*x**2+b*y**2+c*xy+d*y+e*x+f
first intercept such that z=0 when x=inter_1_x
second intercept such that z=0 when x=inter_2_x
first intercept such that z=0 when y=inter_1_y
second intercept such that z=0 when y=inter_2_y
max height of parabola
- ySympy Expr
y=factor*(x-inter_1)*(x-+inter_2)
Helper functions for converting sympy equations to numpy
- modulus.sympy_utils.numpy_printer.np_lambdify(f, r)
generates a numpy function from a sympy equation
- fSympy Exp, float, int, bool or list of the previous
- rlist, dict
the equation to convert to a numpy function. If float, int, or bool this gets converted to a constant function of value f. If f is a list then output for each element in list is is concatenated on axis -1.
A list of the arguments for f. If dict then the keys of the dict are used.
np_f : numpy function
Helper functions for converting sympy equations to pytorch
- class modulus.sympy_utils.torch_printer.CustomDerivativePrinter(*args: Any, **kwargs: Any)
Bases: sympy.printing.str.StrPrinter
- class modulus.sympy_utils.torch_printer.SympyToTorch(sympy_expr, name: str, detach_names: List[str] = [])
Bases:
torch.nn.modules.module.Module
- forward(var: Dict[str, torch.Tensor]) → Dict[str, torch.Tensor]
Defines the computation performed at every call.
Should be overridden by all subclasses.
- modulus.sympy_utils.torch_printer.torch_lambdify(f, r, separable=False)
generates a PyTorch function from a sympy equation
- fSympy Exp, float, int, bool
- rlist, dict
the equation to convert to torch. If float, int, or bool this gets converted to a constant function of value f.
A list of the arguments for f. If dict then the keys of the dict are used.
torch_f : PyTorch function