pub fn piecewise<T, D>(
x: &Array<T, D>,
condlist: &[Array<bool, D>],
funclist: &[&dyn Fn(T) -> T],
default: T,
) -> FerrayResult<Array<T, D>>Expand description
Evaluate a piecewise-defined function.
For each element position, the first condition in condlist that is true
determines which function from funclist is applied. Elements where no
condition is true receive the default value.
This is equivalent to numpy.piecewise(x, condlist, funclist).
§Arguments
x- The input array.condlist- A slice of boolean arrays, each the same shape asx.funclist- A slice of function references, one per condition. The slice element type is&dyn Fn(T) -> T(notBox<dyn Fn>) so callers can pass stack-allocated closures without heap allocation (#297).default- The default value for elements where no condition is true.
§Errors
- Returns
FerrayError::InvalidValueifcondlistandfunclisthave different lengths. - Returns
FerrayError::ShapeMismatchif any condition array has a different shape thanx.