1 Dec 04:04
Re: convert strides/shape/offset into nd index?
James Bergstra <bergstrj <at> iro.umontreal.ca>
2009-12-01 03:04:44 GMT
2009-12-01 03:04:44 GMT
Your question involves a few concepts: - an integer vector describing the position of an element - the logical shape (another int vector) - the physical strides (another int vector) Ignoring the case of negative offsets, a physical offset is the inner product of the physical strides with the position vector. In these terms, you are asking how to solve the inner-product equation for the position vector. There can be many possible solutions (like, if there is a stride of 1, then you can make that dimension account for the entire offset. This is often not the solution you want.). For valid ndarrays though, there is at most one solution though with the property that every position element is less than the shape. You will also need to take into account that for certain stride vectors, there is no way to get certain offsets. Imagine all the strides were even, and you needed to get at an odd offset... it would be impossible. It would even be impossible if there were a dimension with stride 1 but it had shape of 1 too. I can't think of an algorithm off the top of my head that would do this in a quick and elegant way. James On Sun, Nov 29, 2009 at 10:36 AM, Zachary Pincus(Continue reading)
RSS Feed