Thanks, this is exactly what I was looking for. I'll look into what this Diophantine equation is. Also, relatedly, a few months ago Julian Taylor at least wrote what was there in C, which made it faster, if not better.

- James

On Fri, Sep 6, 2013 at 1:27 PM, Robert Kern <robert.kern@gmail.com> wrote:

On Fri, Sep 6, 2013 at 5:58 PM, James Bergstra <bergstrj@iro.umontreal.ca> wrote:

>

> I'm stumped. I can't figure out how to extract from e.g.

>

> view = A[:, 3]

>

> that the view starts at element 3 of A. I was planning to make a may_share_memory implementation based on the idea of swapping in a buffer of 0s, and using the shapes, strides, itemsize etc. to increment just the parts of the 0s buffer touched by the two ndarrays. If there are any 2s in the incremented buffer, it's because the two views overlapped. It's not the best algorithm for comparing tiny views of huge arrays, I was wondering if in my case it would have been quicker than the built-in method (I don't know how it works).It certainly won't be faster. may_share_memory() is very simplistic. It just checks if the outermost bounds of the each array overlap. Thus, it can give false positives for arrays that are interleaved but do not actually intersect. This is why it is named may_share_memory() instead of does_share_memory().> I actually have another data structure around to pull out that shape and stride info, but it's a shame to use it, because then I can't use the algorithm to compare ndarrays in general (or at least ones that have been created by typical construction methods and slicing).All of the information you need is stored in the __array_interface__ attribute of an ndarray.

The right way to solve this is to solve a bounded, linear Diophantine equation. That's where you should be looking if you want to crack this problem.

--

Robert Kern

_______________________________________________

NumPy-Discussion mailing list

NumPy-Discussion@scipy.org

http://mail.scipy.org/mailman/listinfo/numpy-discussion

http://www-etud.iro.umontreal.ca/~bergstrj