Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ufunc of NDVarArray #341

Open
IgnaceBleukx opened this issue Jun 2, 2023 · 3 comments
Open

Ufunc of NDVarArray #341

IgnaceBleukx opened this issue Jun 2, 2023 · 3 comments
Labels

Comments

@IgnaceBleukx
Copy link
Collaborator

Helene exposed an issue with our implementation of the NDVarArray overridden functions (mul, add....) in pull request #337

To reproduce:

import cpmpy as cp

w = cp.cpm_array([10,20,30])
x = cp.intvar(0,10, shape=3)

w *x 
>> NDVarArray(NotImplemented,NotImplemented,NotImplemented)

What happens is the __mul__ method of NDVarArray w tries to call __mul__ on each of the elements in that array. I.e., 10.__mul__(x[0]), 20.__mul__(x[1])... but the built-in type int has no idea how to multiply with our custom objects.
Instead of calling __rmul__ on our objects as it does when expressing 10 * x[0], a NotImplementedError is returned.

Did some research on how to properly subclass a np.ndarray and it seems we don't really need the _vectorized thingy...
https://numpy.org/doc/stable/reference/arrays.classes.html

@363734
Copy link
Contributor

363734 commented Jun 23, 2023

This is the code that triggered the discovery: tentative of refactoring the decompose method of the cumulative cst:

for t in range(lb,ub+1):
            demand_at_t = 0
            for job in range(len(start)):
                if is_num(demand):
                    demand_at_t += demand * ((start[job] <= t) & (t < end[job]))
                else:
                    demand_at_t += demand[job] * ((start[job] <= t) & (t < end[job]))
            cons += [capacity >= demand_at_t]

to

for t in range(lb, ub+1):
            cons += [capacity >= sum(demand * ((start <= t) & (t < end)))]

@Wout4
Copy link
Collaborator

Wout4 commented Jun 30, 2023

this issue also mentions ufunc of ndvararray, so might also be solved? #124

@Wout4
Copy link
Collaborator

Wout4 commented Jun 30, 2023

another issue that might be fixed here: #71
can we support something like x[x!=2] (like numpy array does)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants