Skip to content

Conversation

@jonathanberthias
Copy link
Owner

(stacked on top of scipopt#1141)

(A)I wrote a script to process the output of stubtest to input the correct parameter names to all methods. This reduces the number of remaining "TODO" items to just 3 🎉

Changes:

  1. Use real parameter names
  2. Use ... default if the parameters have default values
  3. Annotate all parameters and return types with Incomplete
  4. Mark "disjoint bases" explicitly

jonathanberthias and others added 12 commits December 30, 2025 17:38
* Fix mypy errors

* Generate stubtest allowlist

* Split expected errors out of todo

* Move all stub-related files to stubs folder

* Add workflow to check stubs

* Simplify file names

* Don't run ruff on everything

* Revert error added for testing

* Clarify requirements for stubtest

* Run mypy in CI
* Add test for matrix sum return type

Adds a test to ensure that summing a matrix variable along an axis returns a MatrixExpr type instead of MatrixVariable, addressing issue scipopt#1117.

* return `MatrixExpr` type

* Update CHANGELOG.md

* Speed up `MatrixExpr.sum(axis=...)`

Enhanced the MatrixExpr.sum method to accept axis as int or tuple, handle keepdims, and provide better error checking for axis bounds. This improves compatibility with numpy's sum behavior and allows more flexible summation over matrix expressions.

* Test `MatrixExpr.sum(axis=...)`

Removed n=200 from the sum performance test to limit test size. Added additional performance assertions comparing np.ndarray.sum and the optimized sum method for matrix variables.

* Test `MatrixExpr.sum(axis=tuple(range(ndim))`

Renamed test_matrix_sum_argument to test_matrix_sum_axis and updated tests to use explicit axis arguments in sum operations. This clarifies the behavior when summing over all axes and improves test coverage for axis handling.

* Refactor MatrixExpr.sum axis handling with numpy utility

Replaces manual axis validation and normalization in MatrixExpr.sum with numpy's normalize_axis_tuple for improved reliability and code clarity. Updates type hints and simplifies logic for summing across all axes.

* Add tests for matrix sum error

Added tests to verify error handling in matrix variable sum operations for invalid axis types, out-of-range values, and duplicate axes.

* Add tests for matrix sum with keepdims parameter

Introduces test cases to verify the shape of matrix variable sums when using the keepdims argument, ensuring correct behavior for both full and axis-specific summation.

* call `.sum` via positional argument

Replaces the use of the 'axis' keyword argument with a positional argument in the z.sum() method call to align with the expected function signature.

* Refactor sum method to use np.apply_along_axis

Replaces np.fromiter with np.apply_along_axis for summing along specified axes in MatrixExpr. This simplifies the code and improves readability.

* Directly test the `.sum` result

Added a comment to clarify the purpose of the test_matrix_sum_axis function, indicating it compares the result of summing a matrix variable after optimization.

* Update CHANGELOG.md

* Expand docstring for MatrixExpr.sum method

The docstring for the MatrixExpr.sum method was updated to provide detailed information about parameters, return values, and behavior, improving clarity and alignment with numpy conventions.

* Clarify MatrixExpr.sum docstring and note quicksum usage

Updated the docstring for MatrixExpr.sum to specify that it uses quicksum for speed optimization instead of numpy.ndarray.sum. Added a detailed note explaining the difference between quicksum (using __iadd__) and numpy's sum (using __add__).

* Split up two costing time test cases

Renamed the existing performance test to clarify it tests the case where axis is None. Added a new test to measure performance when summing along a specific axis.

* Supports numpy 1.x

Co-authored-by: Copilot <[email protected]>

* Supports Python 3.8

* Simplify a bit

Refactored the sum method in MatrixExpr to clarify axis typing and simplify the application of np.apply_along_axis. The new implementation improves readability and maintains the intended behavior.

* suggestion

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Joao-Dionisio <[email protected]>
Co-authored-by: João Dionísio <[email protected]>
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.

4 participants