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

Add fancy indexing #17

Closed
ALMerrill opened this issue Sep 23, 2020 · 10 comments
Closed

Add fancy indexing #17

ALMerrill opened this issue Sep 23, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@ALMerrill
Copy link

Hey, I'm just curious if there are any plans to implement "fancy indexing", where you can pass a list of indeces to an MfArray, and return the items at those indeces, like in numpy. Thanks, its a great library so far.

@jjjkkkjjj
Copy link
Owner

@ALMerrill
I'd like to implement "fancy indexing", of course.
OK, I'll try to do it on this weekend, but don't expect me excessively! 😅

@ALMerrill
Copy link
Author

That would be awesome! Whenever you can would be great

@ALMerrill
Copy link
Author

Also, out of curiosity, is there a way to improve performance with the Boolean indexing? With how I’m using it, it looks like things like array > someNumber is taking the majority of the time. I was just curious if you knew of any way to improve performance on calls like that. Thanks so much!

jjjkkkjjj pushed a commit that referenced this issue Sep 25, 2020
@jjjkkkjjj
Copy link
Owner

jjjkkkjjj commented Sep 25, 2020

it looks like things like array > someNumber is taking the majority of the time.

Yes, your point is correct. The code to improve performance may be here firstly. I think there are much redundant process in this code. So, i should simplify this code.

@jjjkkkjjj
Copy link
Owner

jjjkkkjjj commented Sep 25, 2020

Or use boolean as storedType as you pointed out, but this will change many codes...

@jjjkkkjjj
Copy link
Owner

jjjkkkjjj pushed a commit that referenced this issue Oct 5, 2020
jjjkkkjjj pushed a commit that referenced this issue Oct 6, 2020
jjjkkkjjj pushed a commit that referenced this issue Oct 6, 2020
@jjjkkkjjj
Copy link
Owner

jjjkkkjjj commented Oct 6, 2020

@ALMerrill
I implemented fancy indexing getter!
You can try it by fetching develop branch.
You can pass Int MfArray instead of list to MfArray like this;

let a = MfArray([[1, 2], [3, 4], [5, 6]])
a[MfArray([0, 1, 2]), MfArray([0, 1, 0])]
/*
mfarray = 
[	1,		4,		5], type=Int, shape=[3]
*/

numpy;

>>> x = np.array([[1, 2], [3, 4], [5, 6]])
>>> x[[0, 1, 2], [0, 1, 0]]
array([1, 4, 5])

I don't know if I can implement setter...

@ALMerrill
Copy link
Author

awesome, thank you for the update!

jjjkkkjjj pushed a commit that referenced this issue Oct 7, 2020
jjjkkkjjj pushed a commit that referenced this issue Oct 7, 2020
@jjjkkkjjj
Copy link
Owner

@ALMerrill
I've just implemented fancy setter!!
I didn't check performance, but anyway you can use fancy indexing for MfArray🎉

Setter;

let a = MfArray([[1, 2], [3, 4], [5, 6]])
            
a[MfArray([0, 1, 2]), MfArray([0, -1, 0])] = MfArray([999,888,777])
print(a)
/*
mfarray = 
[[	999,		2],
[	3,		888],
[	777,		6]], type=Int, shape=[3, 2]
*/
            
a.T[MfArray([0, 1, -1]), MfArray([0, 1, 0])] = MfArray([-999,-888,-777])
print(a)
/*
mfarray = 
[[	-999,		-777],
[	3,		-888],
[	777,		6]], type=Int, shape=[3, 2]
*/

@ALMerrill
Copy link
Author

Nice! That's awesome!

@jjjkkkjjj jjjkkkjjj added the enhancement New feature or request label Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants