Skip to content

Fix in_static_equilibrium for NumPy 2.x (2-D cross product removed) - #15110

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:fix-numpy-2d-cross
Aug 28, 2026
Merged

Fix in_static_equilibrium for NumPy 2.x (2-D cross product removed)#15110
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:fix-numpy-2d-cross

Conversation

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Describe your change:

physics/in_static_equilibrium.py calls numpy.cross() on 2-D input vectors. NumPy deprecated 2-D cross products in 2.0 and removed them in newer releases, so on recent NumPy the doctest now raises:

ValueError: Both input arrays must be (arrays of) 3-dimensional vectors, but they are 2 and 2 dimensional instead.

Current master CI still passes only because its lockfile pins numpy==2.2.5; the failure surfaces on newer NumPy (e.g. the free-threaded 3.14t job resolves numpy==2.5.2). This is a latent break that will hit master on the next NumPy bump.

The 2-D "cross product" is just the scalar z-component x·Fy − y·Fx per row, so I compute it directly. Behaviour is identical to the old cross() and works across all NumPy versions. Doctests and the __main__ self-checks pass unchanged.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? — no, existing doctests unchanged

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one issue, please mention the issue number.

@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Aug 28, 2026
@cclauss
cclauss requested a review from tianyizheng02 August 28, 2026 10:32

@cclauss cclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice find!

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Aug 28, 2026
@cclauss
cclauss merged commit 74f8c78 into TheAlgorithms:master Aug 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants