suppy.utils#
Bounds#
- class Bounds(lb=None, ub=None)[source]#
Bases:
objectA class to help with hyperslab calculations.
- Parameters:
lb (
None|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Lower bounds. If None, defaults to negative infinity if ub is provided.ub (
None|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Upper bounds. If None, defaults to positive infinity if lb is provided.
- Attributes:
- larray_like
Lower bounds.
- uarray_like
Upper bounds.
- half_distancearray_like
Half the distance between lower and upper bounds.
- centerarray_like
Center point between lower and upper bounds.
Methods
indexed_residual(x, i)Compute the residuals for the given indices.
project(x)Project the input array x onto the bounds defined by self.l and self.u.
residual(x)Calculate the residuals between the input vector x and the bounds l and u.
single_residual(x, i)Calculate the residuals for a given value for a specific constraint with respect to the lower and upper bounds.
- Raises:
ValueError – If the sizes of the lower and upper bounds do not match. If any lower bound is greater than the corresponding upper bound.
- indexed_residual(x, i)[source]#
Compute the residuals for the given indices.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The input array.i (
Union[List[int],ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]]) – The indices for which to compute the residuals.
- Return type:
tuple[ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]],ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]]- Returns:
A tuple containing two arrays: - The residuals of x with respect to the lower bounds. - The residuals of x with respect to the upper bounds.
- project(x)[source]#
Project the input array x onto the bounds defined by self.l and self.u.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Input array to be projected.- Return type:
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]- Returns:
The projected array where each element is clipped to be within the bounds defined by self.l and self.u.
- residual(x)[source]#
Calculate the residuals between the input vector x and the bounds l and u.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Input vector for which the residuals are to be calculated.- Return type:
tuple[ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]],ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]]- Returns:
A tuple containing two arrays: - The residuals between x and the lower bound l. - The residuals between the upper bound u and x.
- single_residual(x, i)[source]#
Calculate the residuals for a given value for a specific constraint with respect to the lower and upper bounds.
- Parameters:
x (
float) – The value for which the residuals are calculated.i (
int) – The index of the bounds to use.
- Return type:
tuple[float,float]- Returns:
A tuple containing the residuals (x - lower_bound, upper_bound - x).
Decorators#
- ensure_float_array(func)[source]#
Decorator to ensure that the input array is of type float32 or float64. If the input array is not of type float32 or float64, it will be converted to float64.
- Parameters:
func (
Callable) – The function to be decorated.- Return type:
Callable- Returns:
The decorated function which ensures the input array is of type float32 or float64.
- Raises:
TypeError – If the input array cannot be converted to float64.
Warning
- UserWarning
If the input array is not of type float32 or float64 and needs to be converted.
func_wrapper#
- class FuncWrapper(func, args=[])[source]#
Bases:
objectA callable class for a function that keeps track of the number of times it is called.
- Parameters:
func (
Callable) – The function to be wrapped.args (list) – The arguments to be passed to the function.
- Attributes:
- funcCallable
The function to be wrapped.
- argslist
The arguments to be passed to the function.
- fcountint
The number of times the function has been called.
Methods
__call__(x)Call self as a function.
Linear Mapping#
- class LinearMapping(A)[source]#
Bases:
objectThis class is used to allow interoperatibility between numpy, scipy etc.
Methods
get_norm([order, power])Get the norm of the matrix.
getrow(i)Get a row of the matrix.
index_map(x, idx)Apply a linear map to a subset of the matrix.
row_norm([order, power])Get the row norms of the matrix.
single_map(x, i)Apply a linear map to a single row of the matrix.
update_step(x, c, i)Add a scaled row of the matrix to x in-place: x += A[i] * c.
get_flags