Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025

This PR migrates deprecated np.dot() and .dot() method usage in the test suite to the modern @ operator for matrix multiplication, following NumPy best practices.

Changes Made

Updated 7 test files with 13 migration patterns:

  • quantecon/tests/test_ricatti.py: Migrated np.dot(A.T, A) and np.dot(A.T, np.linalg.solve(R + I, A)) to @ operator
  • quantecon/tests/test_lqnash.py: Migrated .dot() methods: b1.dot(f1), b2.dot(f2), tfi.dot(aaa[:2, 2])
  • quantecon/tests/test_lqcontrol.py: Migrated np.dot(x0, P).dot(x0) and removed unused from numpy import dot import
  • quantecon/tests/test_kalman.py: Migrated 6 matrix multiplication patterns to @ operator
  • quantecon/tests/test_matrix_eqn.py: Migrated nested np.dot() calls to @ operator
  • quantecon/markov/tests/test_core.py: Migrated stationary distribution verification patterns
  • quantecon/markov/tests/test_gth_solve.py: Migrated left eigenvector tests

Migration Examples

# Before
Q = I - np.dot(A.T, A) + np.dot(A.T, np.linalg.solve(R + I, A))
aaa = a - b1.dot(f1) - b2.dot(f2)
val_func_lq = np.dot(x0, P).dot(x0)

# After  
Q = I - A.T @ A + A.T @ np.linalg.solve(R + I, A)
aaa = a - b1 @ f1 - b2 @ f2
val_func_lq = x0 @ P @ x0

Validation

  • All 553 tests pass (no regressions introduced)
  • No new linting issues
  • Careful handling of scalar operations that don't work with @ operator
  • np.sum() usage reviewed and kept as appropriate for mathematical operations

This completes the test suite portion of the numpy modernization effort, building on the library code changes that were completed previously.

Fixes #790.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Migrate np.sum(), np.dot and some .dot() methods in test suite Migrate np.dot(), .dot() methods in test suite to @ operator Sep 2, 2025
Copilot finished work on behalf of mmcky September 2, 2025 02:38
@Copilot Copilot AI requested a review from mmcky September 2, 2025 02:38
@coveralls
Copy link

Coverage Status

coverage: 92.578% (-0.001%) from 92.579%
when pulling c569fc4 on copilot/fix-790
into 6eaa314 on main.

@@ -49,7 +48,7 @@ def test_scalar_sequences(self):
(2*lq_scalar.Q+lq_scalar.beta*lq_scalar.Rf*2*lq_scalar.B**2) \
* x0
x_1 = lq_scalar.A * x0 + lq_scalar.B * u_0 + \
dot(lq_scalar.C, w_seq[0, -1])
lq_scalar.C * w_seq[0, -1]
Copy link
Contributor

Choose a reason for hiding this comment

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

@HumphreyYang seems to have picked up the scalar case here.

Copy link
Contributor

@mmcky mmcky left a comment

Choose a reason for hiding this comment

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

@HumphreyYang this looks pretty good to me.

From memory there was another pattern we needed to update (is that right?)

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.

Migrate np.sum(), np.dot and some .dot() methods in test suite
3 participants