Skip to content

Conversation

@Zeroto521
Copy link
Contributor

@Zeroto521 Zeroto521 commented Oct 21, 2025

Yeah, it seems like the tests are not passing, I'm gonna skip the test. Are you sure this is faster?

My bad, I should use np.ndarray.sum instead of np.sum.
np.sum is still using the subclass sum method.

import numpy as np


def quicksum(a: np.ndarray):
    res = 0
    for i in a.flat:
        res += i
    return res


class Matrix(np.ndarray):
    def sum(self, *args, **kwargs):
        if kwargs.get("axis") is None:   
            print("sum via quicksum")
            return quicksum(self)
        else:
            print("sum via np.sum")
            return super().sum(*args, **kwargs)

m = Matrix((2, 2))
m.flat = [[1, 1], [1, 1]]
print(m.sum())
print("----")
print(np.ndarray.sum(m))
print("-----")
print(np.sum(m))

Output:

sum via quicksum
4.0
----
4.0
-----
sum via quicksum
4.0

Originally posted by @Zeroto521 in #1078 (comment)

Replaces the skipped performance test with a parameterized test for matrix sizes 500, 1000, and 2000 to allow benchmarking across different input sizes.
use `np.ndarray.sum` instead of `np.sum`
40min is still running
7min is still running
7min is still running
@Joao-Dionisio Joao-Dionisio merged commit 803e447 into scipopt:master Oct 21, 2025
1 check passed
@Zeroto521 Zeroto521 deleted the fix/1078 branch October 21, 2025 07:36
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.

2 participants