Repository navigation
Fix numpy >= 2 scalar conversions (fixes #311) - #317
Merged
brookshsmith merged 1 commit intoOct 31, 2026
Merged
brookshsmith merged 1 commit into
brookshsmith merged 1 commit into
Conversation
numpy 2 no longer converts a one-element array to a Python scalar, so pycufsm raised on its first call with numpy 2.3+ (the test suite could not collect): - pre/cutwp.py prop2: np.diff([a, b]) returns array([b - a]); use b - a. - solve/analysis_p.py and solve/analysis_c.pyx k_kg_global and kglobal_transv: take the matched material row with reshape(1)[0], keeping the check that exactly one material matches. - helpers.load_cufsm_mat: read lengths as a 1-D float array instead of an (n, 1) column, so each length reaches k_kg_global as a scalar. With numpy 2.5.3 the suite goes from 11 collection errors to all tests passing.
brookshsmith
approved these changes
Oct 31, 2026
brookshsmith
left a comment
Owner
There was a problem hiding this comment.
Simple, targeted fix - thank you!
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.
Hi! Another Melbournite here. I've been porting CUFSM to Rust (cufsm-rs) for speed, and so it can run in the browser as WebAssembly for our tool CivilKit Buckling, which we hope to release as open source in a few days. pycufsm was one of the references I checked it against, and along the way I hit this on a current numpy and found #311 had already described it, so here's a PR for it.
Summary
numpy 2 no longer converts a one-element array to a Python scalar, so with a current numpy
(2.3 and later) pycufsm raises on its first call. The test suite can't even collect (11 errorson numpy 2.5.3). This implements the fixes described in #311, plus one site it didn't list.
Changes
pre/cutwp.py(prop2):np.diff([a, b])returnsarray([b - a]); assignb - adirectly(4 lines, as suggested in pycufsm 0.2.0 does not run on numpy >= 2 (5 one-line sites; cp314 wheels install but raise on first call) #311).
solve/analysis_p.pyandsolve/analysis_c.pyx(k_kg_global,kglobal_transv): take thematched material row with
reshape(1)[0], which keeps the existing check that exactly onematerial matches.
helpers.load_cufsm_mat: readlengthsas a 1-D float array instead of an(n, 1)column.Each length then reaches
k_kg_globalas a scalar (itsdouble lengthargument raised thesame TypeError).
Testing
pytest tests/goes from 11 collectionerrors to all 46 tests passing.
black --check,pylintandmypy(versions frompoetry.lock) report nothing new.Thanks for pycufsm!