symforce.util module¶
- symbolic_eval(func)[source]¶
Build symbolic arguments for a function, and return the function evaluated on those arguments.
Useful for easily visualizing what expressions a symbolic function produces
- Parameters:
func (Callable[[...], _T]) – A callable; args should have type annotations, and those types should be constructible automatically with
symforce.ops.storage_ops.StorageOps.symbolic()
- Returns:
The outputs of ``func`` evaluated on the constructed symbolic args
- Return type:
_T
- lambdify(f, use_numba=False)[source]¶
Convert a symbolic function to a numerical one. This is a thin wrapper around
Codegen.function
provided for convenience.- Parameters:
f (Callable) – A callable with symbolic inputs and outputs - see
Codegen.function
for detailsuse_numba (bool) – If True, use Numba to compile the generated function. This can be much faster, but has some limitations - see
codegen.PythonConfig
for details
- Returns:
A numerical function equivalent to ``f``
- Return type:
- specialize_types(f, type_replacements)[source]¶
Specialize the type annotations on the given function, replacing any types in
type_replacements
For example, this can be used to take a symbolic function that accepts a generic type and generate it for several concrete types:
def f(x: sf.CameraCal) -> sf.Scalar: ... Codegen.function(specialize_types(f, {sf.CameraCal: sf.LinearCameraCal}), ...) Codegen.function(specialize_types(f, {sf.CameraCal: sf.PolynomialCameraCal}), ...)
See also
- specialize_args(f, arg_replacements)[source]¶
Specialize the type annotations on the given function, replacing types for any arguments in
arg_replacements
For example, this can be used to take a symbolic function that accepts a generic type and generate it for several concrete types:
def f(x: sf.CameraCal, y: sf.CameraCal) -> sf.Scalar: ... Codegen.function( specialize_types(f, {"x": sf.LinearCameraCal, "y": sf.PolynomialCameraCal}), ... )
See also