Skip to content

Fix numpy >= 2 scalar conversions (fixes #311) - #317

Merged
brookshsmith merged 1 commit into
brookshsmith:masterfrom
mageaustralia:fix/numpy2-scalar-conversions
Oct 31, 2026
Merged

brookshsmith merged 1 commit into
brookshsmith:masterfrom
mageaustralia:fix/numpy2-scalar-conversions

Conversation

@mageaustralia

@mageaustralia mageaustralia commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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]) returns array([b - a]); assign b - a directly
    (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.py and solve/analysis_c.pyx (k_kg_global, kglobal_transv): take the
    matched material row with reshape(1)[0], which keeps the existing check that exactly one
    material matches.
  • helpers.load_cufsm_mat: read lengths as a 1-D float array instead of an (n, 1) column.
    Each length then reaches k_kg_global as a scalar (its double length argument raised the
    same TypeError).

Testing

  • numpy 2.5.3, Python 3.12, Cython extension rebuilt: pytest tests/ goes from 11 collection
    errors to all 46 tests passing.
  • black --check, pylint and mypy (versions from poetry.lock) report nothing new.

Thanks for pycufsm!

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 brookshsmith left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Simple, targeted fix - thank you!

@brookshsmith
brookshsmith merged commit 5071993 into brookshsmith:master Oct 31, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants