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

Subscript bug using Matft.arange() #38

Closed
nnethery opened this issue Jan 12, 2023 · 4 comments
Closed

Subscript bug using Matft.arange() #38

nnethery opened this issue Jan 12, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@nnethery
Copy link

Numpy version

a = np.zeros([88, 2, 2])
b = np.zeros([32, 88, 2])
print(a[np.arange(88), b[0, :, 0].astype(int), 0].shape) # Outputs to (88,)

Matft version

let a = Matft.nums(0, shape: [88, 2, 2])
let b = Matft.nums(0, shape: [32, 88, 2]).astype(.Int)
print(a[Matft.arange(start: 0, to: 88, by: 1), b[0, Matft.all, 0], 0].shape) // Outputs to [88, 88]

According to Numpy the shape of the MfArray should be [88], not [88, 88].

@jjjkkkjjj
Copy link
Owner

jjjkkkjjj commented Jan 12, 2023

@nnethery
Thank you for reporting the bug. I misunderstood the fancy indexing rule...
Do you know why this operation returned the shape as (88,)?
I misunderstood the returned array's shape will be same as the shape combined by all input's shape. For the example you mentioned, input indexing array's shapes are (88,)=np.arange(88), (88,)=b[0, :, 0].astype(int), (0=scalar,). So, returned shape will be (88, 88, 0) = (88,88) by combining the input indexing array's shapes.

@jjjkkkjjj
Copy link
Owner

Ah, I may understand.
The input indexing shape will be broadcasted.

>>> np.arange(8).reshape(4,2)[[2,3], [0,2,1]]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (3,) 

@jjjkkkjjj jjjkkkjjj added the bug Something isn't working label Jan 12, 2023
jjjkkkjjj pushed a commit that referenced this issue Jan 13, 2023
@jjjkkkjjj
Copy link
Owner

jjjkkkjjj commented Jan 13, 2023

@nnethery
I've just fixed this bug!
Please check it again.

@nnethery
Copy link
Author

@nnethery I've just fixed this bug! Please check it again.

It works great. You rock @jjjkkkjjj 🎉!

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

2 participants