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

Lack of out of bounds support for hi() and lo() makes things difficult #14

Open
tustin2121 opened this issue Nov 23, 2014 · 2 comments
Open

Comments

@tustin2121
Copy link

I love the idea of using the hi and lo functions to get a subsection of the array, so that I can pass that subsection to a function and it can work on it oblivious to where it is in the array.

Unfortunately, that doesn't quite work properly. I have a 3D array of cells. For every cell, I need to check all the cells in the cardinal directions around it. I figured I could just use hi() and lo() to give me a 3x3x3 view of the cells around the cell I'm working on (using arr.hi(x-1,y-1,z-1).lo(2,2,2). I was hoping (because the documentation said nothing on edge cases) that when I'm on the edge of one of the dimensions (say, x = 0), this new view would have a view where x=0 pointed to theoretical x=-1 in the parent array. And I figured calling get(0, 1, 1) on that subview would give me null or undefined, as there is nothing to retrieve from the empty space beyond the edge of the array.

Instead, I find the subarray is badly shifted: the hi() function reverts to 0 instead of allowing a negative view range, and now I get a view of the 3D array one off in the +X direction, causing the whole operation to just be wrong.

Not sure how to do an "oblivious array operation" when there's something like this going on. I'm going to have to actually give the for-each function the whole array now or something.

Basically what I think should happen: Allow a view to be partially outside the range of the theoretical array, and return undefined when you try and query it. Throw an exception when you try and set out there.

@wildlyinaccurate
Copy link

I came across this behaviour today as well, but for .get() and .set().

var a = ndarray([1, 2, 3, 4], [2, 2])

a.get(1, 0) // 3
a.get(0, 2) // 3

In a 2-dimensional array which looks like this

1 3
2 4

I would expect [0, 2] to be undefined. Is this not the expected behaviour?

@mikolalysenko
Copy link
Member

ndarray doesn't bounds check the arrays as it slows things down too much. If there is interest in this functionality, I might make a separate module that supports it.

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

3 participants