sandalwood API Reference
This document provides a detailed API reference for the sandalwood package.
sandalwood Package
The sandalwood package provides tools for working with multivariate Taylor series expansions.
mtf
An alias for the MultivariateTaylorFunction class. It is the main entry point for most users.
sandalwood.taylor_function Module
This module contains the core MultivariateTaylorFunction class.
MultivariateTaylorFunction Class
The fundamental class for representing a function as a DA vector of its Taylor coefficients.
Class Attributes
Attribute |
Type |
Description |
|---|---|---|
|
|
Global setting for the maximum order of Taylor expansions. |
|
|
Global setting for the maximum number of variables. |
|
|
Global tolerance for floating-point comparisons. |
|
|
If |
Instance Attributes
Attribute |
Type |
Description |
|---|---|---|
|
|
A 2D numpy array of shape |
|
|
A 1D numpy array of shape |
|
|
The number of variables in the Taylor series. |
|
|
An optional name for the function. |
Methods
Method |
Description |
Arguments |
Returns |
|---|---|---|---|
|
Initializes global settings for the sandalwood library. Thread-safe: protected by an internal |
|
|
|
Calculates max coefficient count for given order/dimension. |
|
|
|
Returns the precomputed Taylor coefficients for elementary functions. |
|
|
|
Returns initialization status of MTF globals. |
|
|
|
Sets the global maximum order for Taylor series. |
|
|
|
Returns the global maximum order for Taylor series. |
|
|
|
Returns the global maximum dimension (number of variables). |
|
|
|
Sets the global error tolerance (etol) for |
|
|
|
Returns the global error tolerance (etol). |
|
|
|
Sets the global flag to enable or disable automatic coefficient cleanup. |
|
|
|
Creates a MultivariateTaylorFunction representing a constant value. |
|
|
|
Creates a MultivariateTaylorFunction representing a single variable. |
|
|
|
Merges a list of MTFs into a single pandas DataFrame for comparison. |
|
|
|
Converts input to MultivariateTaylorFunction or ComplexMultivariateTaylorFunction. |
|
|
|
Serializes the MTF object to a JSON string. |
|
|
|
Creates an MTF object from a JSON string. |
|
|
|
Evaluates the Taylor function at a single point. |
|
|
|
Evaluates the Taylor function at multiple points in a vectorized manner. When a NumPy array is supplied and Numba is available, a JIT-compiled fast path is used. When a |
|
|
|
Substitutes a variable with a numerical value. |
|
|
|
Truncates the Taylor series to a specified maximum order. |
|
|
|
Truncates the MTF in place to a specified order. |
|
|
|
Substitutes a variable in the MTF with a numerical value IN-PLACE. |
|
|
|
Checks if an MTF is effectively zero. |
|
|
|
Composes this function with other Taylor functions. |
|
|
|
Returns a pandas DataFrame representation of the Taylor function. |
|
|
|
Extracts the coefficient for a given multi-index exponent. |
|
|
|
Sets the coefficient for a given multi-index exponent. |
|
|
|
Finds the maximum absolute value among all coefficients. |
|
|
|
Finds the minimum absolute value among non-negligible coefficients. |
|
|
|
Converts the MTF to a SymPy expression for pretty printing. |
|
|
|
Returns a copy of the MTF. |
|
|
|
Retrieves the constant (zeroth-order) term of the Taylor series. |
|
|
|
Returns a new MTF representing the polynomial part of the function. |
|
|
|
Converts a NumPy array of numbers into a NumPy array of mtf objects. |
|
|
|
Converts a NumPy array of mtf objects into a NumPy array of their constant values. |
|
|
|
Computes the partial derivative of an MTF. |
|
|
|
Performs definite or indefinite integration of an MTF. |
|
|
|
Efficiently creates an array of MTF objects from raw COSY integer indices, bypassing the overhead of individual object instantiation. |
|
|
sandalwood.complex_taylor_function Module
This module provides the ComplexMultivariateTaylorFunction for handling complex coefficients.
ComplexMultivariateTaylorFunction Class
A subclass of MultivariateTaylorFunction for representing Taylor series with complex coefficients. It inherits all methods from MultivariateTaylorFunction and provides the following additional methods.
Methods
Method |
Description |
Arguments |
Returns |
|---|---|---|---|
|
Creates a CMTF representing a constant complex value. |
|
|
|
Creates a CMTF representing a single variable. |
|
|
|
Computes the complex conjugate of the Taylor function. |
|
|
|
Extracts the real part of the Taylor function. |
|
|
|
Extracts the imaginary part of the Taylor function. |
|
|
sandalwood.taylor_map Module
This module provides the TaylorMap class for representing vector-valued functions.
TaylorMap Class
Represents a function from R^n to R^m using Taylor series components.
Instance Attributes
Attribute |
Type |
Description |
|---|---|---|
|
|
A NumPy array of |
|
|
The dimension of the output space (m), which is the number of components. |
Methods
Method |
Description |
Arguments |
Returns |
|---|---|---|---|
|
Composes this map with another, calculating |
|
|
|
Retrieves a component function from the map. |
|
|
|
Gets the coefficient of a specific term in a component function. |
|
|
|
Sets the coefficient of a specific term in a component function. |
|
|
|
Adds a new component function to the map. |
|
|
|
Removes a component function from the map by its index. |
|
|
|
Truncates all component functions to a specified order. |
|
|
|
Calculates the trace of the first-order part of the map. |
|
|
|
Returns a new TaylorMap with coefficients scaled for sensitivity analysis. |
|
|
|
Performs partial or full substitution. |
|
|
|
Computes the inverse of the TaylorMap using fixed-point iteration. |
|
|
sandalwood.backend Module
This module provides the array-backend abstraction layer used by neval and other
numerical routines. It selects the appropriate backend class at runtime based on the
type of the input array.
Type Aliases
Alias |
Definition |
Description |
|---|---|---|
|
|
Union of the two supported concrete array types. |
|
|
Shape argument accepted by |
|
|
Optional dtype accepted by |
get_backend(array) function
from sandalwood.backend import get_backend
Returns the backend class (not an instance) appropriate for the given array type.
Because all backend methods are @staticmethod, the class itself is the callable;
no object construction occurs on each dispatch call.
Parameter |
Type |
Description |
|---|---|---|
|
|
The array for which to find a backend. Subclasses of either type are handled via |
Returns: type[NumpyBackend] or type[TorchBackend]
Raises: TypeError — if the array type is not supported.
NumpyBackend Class
The default backend used when neval receives a numpy.ndarray.
Method |
Signature |
Description |
|---|---|---|
|
|
Wraps |
|
|
Wraps |
|
|
Wraps |
|
|
Wraps |
|
|
Wraps |
|
|
Wraps |
|
|
Converts array to NumPy. |
|
|
Identity conversion via |
TorchBackend Class
Used when neval receives a torch.Tensor. Only available when PyTorch is installed.
Method |
Signature |
Description |
|---|---|---|
|
|
Wraps |
|
|
Wraps |
|
|
Wraps |
|
|
Wraps |
|
|
Wraps |
|
|
Ensures ≥ 2-D. A 0-D scalar → |
|
|
Wraps |
|
|
Safe conversion handling all common failure modes. See table below. |
TorchBackend.to_numpy — Safety Guarantees
Input condition |
Behaviour |
|---|---|
|
Detaches from the autograd graph. Emits |
|
Copies tensor to CPU host. Emits |
Contiguous CPU tensor, no grad |
Zero-copy |
Elementary Functions
These functions are available as static methods on the MultivariateTaylorFunction class (e.g., mtf.sin(...)).
Function |
Description |
Arguments |
Returns |
|---|---|---|---|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of a Gaussian function, |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
|
Computes the Taylor expansion of |
|
|
Utility Functions
Function |
Description |
Arguments |
Returns |
|---|---|---|---|
|
Loads or precomputes Taylor coefficients for elementary functions. |
|
|