Skip to content

Fix 1D Cartesian orders in generate_orders_horton_order - #335

Open
SajalDevX wants to merge 3 commits into
theochem:masterfrom
SajalDevX:fix-1d-cartesian-orders
Open

SajalDevX wants to merge 3 commits into
theochem:masterfrom
SajalDevX:fix-1d-cartesian-orders

Conversation

@SajalDevX

Copy link
Copy Markdown

Fixes #334.

generate_orders_horton_order(order, "cartesian", dim=1) returned np.arange(0, order + 1, dtype=np.int):

  • It crashes on current NumPy. np.int was removed in NumPy 1.24, so Grid.moments(..., type_mom="cartesian") on a grid with points of shape (N, 1) raised AttributeError.
  • The shape is wrong. It returns every order from 0 to n instead of the single row [n] that the 2D and 3D branches return, so the np.vstack in Grid.moments couldn't stack the rows even with a valid dtype.

The fix returns [[order]] for dim=1, like the other dimensions.

Tests

  • test_generate_orders_horton_order_cartesian_one_dimension covers the function directly.
  • TestGrid1D.test_cartesian_moments checks the moments up to order 3 against sums computed by hand.

Both fail on master and pass with the change. The full suite passes locally: 640 passed, 1 skipped. Black and ruff report nothing new in the touched files.

I used Claude to help find this and draft the tests. I went through the change and ran the suite myself.

For dim=1 the function returned np.arange(0, order + 1, dtype=np.int).
np.int was removed in NumPy 1.24, so Grid.moments(..., type_mom="cartesian")
on a grid with points of shape (N, 1) raised AttributeError. The result
was also the wrong shape: every order from 0 to n instead of the single
row [n] that the 2D and 3D branches return, so the np.vstack in
Grid.moments could not have stacked the rows anyway.

Return [[order]] for dim=1, matching the other dimensions.

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The focused fix is consistent with higher-dimensional behavior and is adequately covered by direct and integration tests.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes 1D Cartesian order generation so Grid.moments works correctly with modern NumPy.

Changes:

  • Returns a single [[order]] row for 1D Cartesian orders.
  • Adds direct order-generation and end-to-end moment tests.
File Description
src/​grid/​utils.py Corrects 1D Cartesian order output.
src/​grid/​tests/​test_utils.py Tests generated 1D order shape and values.
src/​grid/​tests/​test_grid.py Tests 1D Cartesian moment calculations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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.

Grid.moments with Cartesian orders fails on 1D grids

3 participants