4 ms·
This is a fascinating topic I have had to spend a lot of time studying as I was writing http://nd4j.org http://nd4j.org (numpy port for the jvm) When you want
by agibsonccc 11y ago
This is a fascinating topic I have had to spend a lot of time studying as I was writing http://nd4j.org http://nd4j.org (numpy port for the jvm)
When you want to represent say 6d data you have to account for all sorts of interesting details.
One interesting detail is strides along particular dimensions.
For example given an ndarray of
2 x 3 x 1 x 5
You will have a stride to get to the next element along a dimension in the linear buffer.
The strides along k dimensions are determined by ordering.
The crazy thing here though is that 1 in the middle for the shape.
If you find a 1 in the shape you actually skip that stride when indexing into the array.
Numpy's internals go in to this quite a bit:
https://scipy-lectures.github.io/advanced/advanced_numpy/ https://scipy-lectures.github.io/advanced/advanced_numpy/
The great thing about the linear storage of these arrays also helps with distributed systems and reading blocks of bytes.
Lots of interesting little things in here to consider.
Without going ok another tangent this is also highly relates to blas. There is a lot more to this in practice. This is a wonderful introduction to the topic though.
- Retra 11y agoYou can also use space-filling curves to produce nice cache behavior under certain assumptions. If you're only needing to view a small, contiguous portion of a very large array, for instance.
- agibsonccc 11y agoRight. It's neat seeing this kind of mix of linear algebra + CS come together.
- lispit 11y agoGPUs use tiling and morder-order storage for textures for this reason. https://fgiesen.wordpress.com/2011/01/17/texture-tiling-and-swizzling/ https://fgiesen.wordpress.com/2011/01/17/texture-tiling-and-...
- kxyvr 11y agoIn case anyone is interested, Michael Bader has a book called "Space-Filling Curves: An Introduction with Applications in Scientific Computing" that talks about this: https://books.google.com/books?id=zmMBMFbia-0C https://books.google.com/books?id=zmMBMFbia-0C