Skip to main content

Module function_transformer

Module function_transformer 

Source
Expand description

Function transformer: apply a user-provided function element-wise.

Wraps any Fn(F) -> F callable and applies it to every element in the input matrix. This is useful for applying non-standard transformations such as ln, sqrt, or custom domain-specific functions.

This transformer is stateless — no fitting is required. Call Transform::transform directly.

§## REQ status

Binary (R-DEFER-2), translating sklearn/preprocessing/_function_transformer.py (class FunctionTransformer(TransformerMixin, BaseEstimator)). Design doc: .design/preprocess/function_transformer.md. Expected values from the live sklearn 1.5.2 oracle (R-CHAR-3). HONEST (R-HONEST-3): ferrolearn ships a THIN element-wise wrapper — func is a scalar Fn(F) -> F applied via mapv, NOT sklearn’s whole-array func(X); matches sklearn only on the element-wise/ufunc subset. Consumer: crate re-export (lib.rs, grandfathered S5).

REQStatusEvidence
REQ-1 (element-wise forward transform)SHIPPED (scoped)Transform::transform = x.mapv(|v| (self.func)(v)), shape-preserving, infallible; mirrors sklearn _transform (_function_transformer.py:375-379) for element-wise ufunc func. Critic-verified bit-identical to live sklearn: guard_log1p_/expm1_/sqrt_/log_nan_inf_/empty_matrix_* (5 green) in tests/divergence_function_transformer.rs. Consumer: pub use function_transformer::FunctionTransformer (lib.rs:114). Caveat: scalar Fn(F)->F, not array Fn(X)->X.
REQ-2 (func=None identity default)NOT-STARTEDopen prereq blocker #1112. new requires a closure; no identity default (_identity, :22-24).
REQ-3 (whole-array func, headline)NOT-STARTEDopen prereq blocker #1113. Box<dyn Fn(F)->F> cannot read the array / change shape; sklearn func(X) is array→array (:375-379).
REQ-4 (inverse_func / inverse_transform)NOT-STARTEDopen prereq blocker #1114. No inverse path (sklearn :309-325).
REQ-5 (validate / accept_sparse)NOT-STARTEDopen prereq blocker #1115. No input validation (sklearn :173-182).
REQ-6 (fit / check_inverse / is_fitted)NOT-STARTEDopen prereq blocker #1116. No fit/check_inverse (sklearn :213-235, :184-210).
REQ-7 (feature_names_out / n_features_in_)NOT-STARTEDopen prereq blocker #1117. None (sklearn :327-373).
REQ-8 (kw_args / inv_kw_args)NOT-STARTEDopen prereq blocker #1118. No kwarg forwarding (sklearn :93-101,:379).
REQ-9 (ctor surface + _parameter_constraints)NOT-STARTEDopen prereq blocker #1119. Only func; 7 params + validation missing (R-DEV-2, sklearn :141-171).
REQ-10 (PyO3 binding)NOT-STARTEDopen prereq blocker #1120. No ferrolearn-python registration.
REQ-11 (ferray substrate)NOT-STARTEDopen prereq blocker #1121. ndarray/num_traits, not ferray-core/ferray-ufunc (R-SUBSTRATE-1/2).

Structs§

FunctionTransformer
A stateless element-wise function transformer.