QuantEcon.py icon indicating copy to clipboard operation
QuantEcon.py copied to clipboard

Migrate np.dot(), .dot() methods in test suite to @ operator

Open Copilot opened this issue 6 months ago • 1 comments

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.

Copilot avatar Sep 02 '25 02:09 Copilot