Repository navigation
Support cupy arrays: subsetting, dtype preservation, and standardization matching the Rust path - #25
Open
CarlKCarlK wants to merge 9 commits into
Open
CarlKCarlK wants to merge 9 commits into
CarlKCarlK wants to merge 9 commits into
Conversation
This was referenced Nov 15, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets
SnpDataand otherPstDataobjects hold CuPy (GPU) arrays end to end, as FaST-LMM'ssingle_snp(xp="cupy")needs, and makes CuPy results and errors match the numpy (Rust) path.sub_matrix: a CuPy array used to reach the numpy-only Rust helper and fail withTypeError, so any subsetting of a CuPy-backedSnpDatafailed. CuPy arrays are now detected directly (sys.modules.get("cupy"), so cupy is never imported) and subset with CuPy indexing, with the same validation as the numpy path and no extra GPU copy. Because CuPy silently wraps negative and out-of-range indexes, they are checked and raiseIndexError. Non-CuPy inputs take the numpy path exactly as before.PstData._fixup_input_val: avalmoved between numpy and CuPy now keeps the dtype that same-module input keeps: float32 or float64, or any dtype (for example, int8) when_require_float32_64=False; anything else (for example, a list) still becomes float64. Before, numpy float32 and int8 were upcast to float64 on CuPy, and a CuPyvalunder numpy raised CuPy's implicit-conversionTypeError.ValueError("No individual observed for the SNP.")like the Rust path, instead of silently becoming zeros.Betastandardization failed on CuPy (SciPy received a CuPy array); it now computes the per-SNP weights on the host.Validation
test_sub_matrix_cupy: exact equality with the Rust path across 2-D/3-D shapes, F/C input orders, A/F/C output orders, float32/float64 in and out, repeated indexes, and rejection of bad indexes.test_snpdata_subset_cupy: subsetting a CuPy-backedSnpData.test_snpdata_cupy_keeps_dtype: both directions, with and without_require_float32_64, against the same-module baseline.test_standardize_cupy_matches_rust:UnitandBeta, float64 and float32, missing/constant/single-value SNPs (within 8 ulp), and the all-missing error.tests/test.py(legacy suite) at 2640a5e: 745 OK, 4 skipped (the CuPy tests, in an environment without CuPy).gpu-f32) pass with this branch.PR #27 adds the same
_checked_indexhelper to the numpy path; whichever PR merges second keeps one copy.FaST-LMM's GPU path will need a PySnpTools release containing this change, followed by a raised lower bound in FaST-LMM.