Skip to content

[BUG] Guard default RidgeClassifierCV against LAPACK SVD overflow - #3755

Open
aashoday wants to merge 7 commits into
aeon-toolkit:mainfrom
aashoday:fix/3737-large-memory-precision
Open

[BUG] Guard default RidgeClassifierCV against LAPACK SVD overflow#3755
aashoday wants to merge 7 commits into
aeon-toolkit:mainfrom
aashoday:fix/3737-large-memory-precision

Conversation

@aashoday

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #3737.

What does this implement/fix? Explain your changes.

Several classifiers (RDSTClassifier, RocketClassifier, MultiRocketHydraClassifier)
fit a default RidgeClassifierCV on transformed feature matrices that can exceed the
32-bit LAPACK indexing limit for SVD, causing an unhelpful scipy ValueError on large
datasets.

This PR:

  • Adds check_lapack_svd_safe() to aeon.utils.validation, which raises an
    informative ValueError before fitting when the default estimator is used and
    the transformed matrix would overflow 32-bit LAPACK's SVD indexing.
  • Wires this check into RDSTClassifier and RocketClassifier, ahead of their
    default RidgeClassifierCV fit.
  • Exposes an estimator parameter on MultiRocketHydraClassifier (previously
    hardcoded to RidgeClassifierCV), matching the pattern already used by
    RDSTClassifier RocketClassifier, and applies the same check.
  • The check only runs when the default estimator is in use; behaviour for
    existing custom-estimator users is unchanged.
  • RocketClassifier's internal pipeline was split into
    transform/scale/fit steps (it previously used make_pipeline), since the
    check needs the transformed matrix shape before fitting.

Does your contribution introduce a new dependency? If yes, which one?

No.

Any other comments?

This PR targets only the LAPACK indexing bug not the separate 128GB OOM reported for MultiRocketHydraClassifier on AustraliaRainfall_disc.

AI was used to help understand parts of the codebase and LAPACK, scipy internals
while working through this fix; all changes were written and reviewed by me.

PR checklist

For all contributions
  • I've added myself to the list of contributors. Alternatively, you can use the @all-contributors bot to do this for you after the PR has been merged.
  • The PR title starts with either [ENH], [MNT], [DOC], [BUG], [REF], [DEP] or [GOV] indicating whether the PR topic is related to enhancement, maintenance, documentation, bugs, refactoring, deprecation or governance.
For new estimators and functions
  • I've added the estimator/function to the online API documentation.
  • (OPTIONAL) I've added myself as a __maintainer__ at the top of relevant files and want to be contacted regarding its maintenance. Unmaintained files may be removed. This is for the full file, and you should not add yourself if you are just making minor changes or do not want to help maintain its contents.

Several classifiers (RDSTClassifier, RocketClassifier,
MultiRocketHydraClassifier) fit a default RidgeClassifierCV on
transformed feature matrices that can exceed the 32-bit LAPACK
indexing limit for SVD, raising an unhelpful scipy error on large
datasets.

- Add check_lapack_svd_safe() to aeon.utils.validation, which raises
  an informative ValueError before fitting when the default estimator
  is used and the matrix would overflow.
- Wire this check into RDSTClassifier and RocketClassifier ahead of
  their default RidgeClassifierCV fit.
- Expose an estimator parameter on MultiRocketHydraClassifier
  and apply the same check, matching the
  pattern already used by RDSTClassifier and RocketClassifier.
- The check is skipped entirely when a custom estimator is supplied,
  so behaviour for existing custom-estimator users is unchanged.
- test_check_lapack_svd_safe.py: boundary tests for
  check_lapack_svd_safe (under/at/over the 32-bit limit) and a check
  that the error message includes the computed element count.
- test_rdst.py, test_rocket.py, test_mr_hydra.py: for each classifier,
  confirm check_lapack_svd_safe is called once when the default
  estimator is used, and never called when a custom estimator is
  supplied.
@aeon-actions-bot aeon-actions-bot Bot added bug Something isn't working classification Classification package labels Aug 22, 2026
@aeon-actions-bot

Copy link
Copy Markdown
Contributor

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: [ bug ].
I have added the following labels to this PR based on the changes made: [ classification ]. Feel free to change these if they do not properly represent the PR.

The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our pre-commit code quality check fails, please run pre-commit locally and push the fixes to your PR branch.

Don't hesitate to ask questions on the aeon Discord channel if you have any.

PR CI actions

These checkboxes will add labels to enable or disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

  • Run pre-commit checks for all files
  • Run mypy typecheck tests
  • Run all pytest tests and configurations
  • Run all notebook example tests
  • Run numba-disabled codecov tests
  • Disable numba cache loading
  • Regenerate expected results for testing
  • Push an empty commit to re-run CI checks

def check_lapack_svd_safe(n_samples: int, n_features: int, estimator_name: str) -> None:
"""Raise an informative error if a matrix is too large for LAPACK SVD.

Matrices with more than ``2**31 - 1`` elements may overflow 32-bit integer

@aadya940 aadya940 Sep 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how relevant this is in this context but it is not necessary that LAPACK will overflow for more than 2**31 - 1 elements, it is only the case in the default LP64 scipy build. However, now SciPy supports ILP64 builds which can accomodate far large matrices (upto 64 bit integer indices), see these release notes, if we add these checks it will mostly work okay in the default SciPy but will restrict user who specifically use ILP64 SciPy builds.

Therefore, the more robust way would be to query scipy:

import scipy

try:
    config = scipy.show_config(mode='dicts')
    is_ilp64 = config['Build Dependencies']['blas']['cython_blas_ilp64']
    print(f"Is SciPy ILP64? {is_ilp64}")
except KeyError:
    print("Is SciPy ILP64? False (Default LP64 profile active)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working classification Classification package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Large memory jobs precision issue

2 participants