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

Bug when add a numpy.array from the left #23

Open
armando-palacio opened this issue Mar 21, 2024 · 0 comments
Open

Bug when add a numpy.array from the left #23

armando-palacio opened this issue Mar 21, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@armando-palacio
Copy link
Owner

Something strange happens when I try to sum a numpy array (as a first summand) with an object of type electrical_signal or optical_signal, like this:

x = np.array([1,2,3])
y = electrical_signal([1,2,3])
x+y

Raise an exception

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operands could not be broadcast together with shapes (3,) (3,2)

It seems that numpy's implementation of the __add__ operand somehow manages to interpret the object and translate it into an array of shape (3,2).

This problem don't appear when the first summand is an object other than an np.ndarray. For example:

from opticomlib import *
y = electrical_signal([1,2,3])

for x in [[1,2,3], (1,2,3), '1,2,3']:
    print((x+y).__repr__())

It return:

electrical_signal([2 4 6])
electrical_signal([2 4 6])
electrical_signal([2 4 6])

When electrical_signal or optical_signal objects are first summand, the addition works well in all cases (because __add__ of these objects is executed).

from opticomlib import *
import numpy as np
y = electrical_signal([1,2,3])

for x in [np.array([1,2,3]), [1,2,3], (1,2,3), '1,2,3']:
    print((y+x).__repr__())
electrical_signal([2 4 6])
electrical_signal([2 4 6])
electrical_signal([2 4 6])
electrical_signal([2 4 6])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant