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

ndarray.set the i, j vector #32

Open
PetrochukM opened this issue Aug 21, 2016 · 4 comments
Open

ndarray.set the i, j vector #32

PetrochukM opened this issue Aug 21, 2016 · 4 comments

Comments

@PetrochukM
Copy link

Using this library, I have found frequently that I need to set an entire vector at a time when manipulating the ndarray. For example:

const n = ndarray([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]);
const newVector = n.pick(0, 0);
for (let i = 0; i < n.shape[3]; i++) {
    n.set(1, 1, j, newVector.get(j));
}

Is there an intended way to handle this redundancy? Ideally:

const n = ndarray([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]);
const newVector = n.pick(0, 0);
n.set(1, 1, newVector);

Context:
Writing an image processing library. I wrote a median filter for the image. I need iterate over all the pixels and set them to the median of their neighbors.

@GuillaumeLeclerc
Copy link

I think there is no way to do it since the underlying data might not be contiguous in your newVector. Except some cases only you know about, there are no more efficient ways than the one you showed.

@letmaik
Copy link

letmaik commented Oct 14, 2016

I have the same requirement. I need to copy a subset of an ndarray into a different bigger ndarray as efficiently as possible. I think this can be implemented faster than the for loop above by using the compilation techniques that ndarray uses.

@mikolalysenko
Copy link
Member

You can use ndarray ops to do this, or for your median filter it might be faster to use cwise.

@letmaik
Copy link

letmaik commented Oct 15, 2016

Ah, right! I didn't see that, it's under "Special cases". So, it's:

ops.assign(dest, src) copies one array into another

Meaning you slice your source and destination arrays properly and then do assign().

This issue can be closed then.

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

No branches or pull requests

4 participants