Skip to content

v6.1.2: Optimize Q loading for the 2<=M<K branch (6.1.2) (#51)

Choose a tag to compare

@github-actions github-actions released this 16 Jul 21:14
· 7 commits to main since this release
701020b
## Summary

Micro-optimizes the improved Y-loadings `Q` update in the `2 <= M < K` branch of the
shared Improved Kernel PLS inner loop (`ikpls._impl.pls_steps`, used by
`ikpls.numpy.PLS` and `ikpls.fast_cross_validation.numpy.PLS`). Performance-only up to
a ~1-ULP floating-point reassociation; NumPy backend only.

```diff
- q = q * np.sqrt(eig_vals[-1]) / tTt
+ q = q * (np.sqrt(eig_vals[-1]) / tTt_val)

Folding the two scalar factors before the single array multiply — reusing the Python
float tTt_val (already materialized for the score-norm stability guard) and
precomputing sqrt(eig_vals[-1]) / tTt_val — turns two array ufuncs (a multiply and
a divide by the (1, 1) array tTt) into one array multiply, and drops the
(1, 1)-array broadcast.

Motivation

For small M this update is dominated by per-call NumPy dispatch, not arithmetic. Under
the previous form the improved element-wise Q was measurably slower in-fit than the
original matmul (rᵀ XᵀY)ᵀ / tTt at small M — the original's BLAS matmul stays
cache/branch-warm alongside the surrounding fit while the element-wise dispatch does not.
The reassociation roughly halves the dispatch and removes that regression.