pub struct FunctionTransformer<F> { /* private fields */ }Expand description
A stateless element-wise function transformer.
Wraps a boxed Fn(F) -> F closure and applies it to every element in
the input matrix.
§Examples
use ferrolearn_preprocess::function_transformer::FunctionTransformer;
use ferrolearn_core::traits::Transform;
use ndarray::array;
// Apply natural logarithm element-wise (values must be > 0)
let ft = FunctionTransformer::<f64>::new(|v| v.ln());
let x = array![[1.0, 2.0], [3.0, 4.0]];
let out = ft.transform(&x).unwrap();Implementations§
Trait Implementations§
Source§impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for FunctionTransformer<F>
impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for FunctionTransformer<F>
Source§fn transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Apply the stored function to every element of x.
§Errors
This implementation never returns an error for well-formed inputs. Note: if the user-provided function produces NaN or infinity for certain inputs, those values will appear in the output without error.
Source§type Error = FerroError
type Error = FerroError
The error type returned by
transform.Auto Trait Implementations§
impl<F> Freeze for FunctionTransformer<F>
impl<F> !RefUnwindSafe for FunctionTransformer<F>
impl<F> Send for FunctionTransformer<F>
impl<F> Sync for FunctionTransformer<F>
impl<F> Unpin for FunctionTransformer<F>
impl<F> UnsafeUnpin for FunctionTransformer<F>
impl<F> !UnwindSafe for FunctionTransformer<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.