digitalmars.D.learn - multi-dimensional arrays, not arrays of arrays
- XavierAP (30/30) Feb 18 2017 Does D provide anything like this? Otherwise, was this ever
- Ilya Yaroshenko (12/14) Feb 18 2017 They are implemented as part of the Mir project. We call them
- XavierAP (1/1) Feb 18 2017 Nice, thanks! Will check it out
Does D provide anything like this? Otherwise, was this ever considered and were reasons found not to have it? declare two kind of multi-dimensional arrays: T[][][] or T[,,]. The first is the same as the D ones, array of arrays of... declarations IIRC); but the second provides contiguous, rectangular truly multi-dimensional arrays supposedly with one single level of indirection. (Of course static arrays don't exist Is there a reason why this feature would not be really desirable or possible? Does it really exist and I missed it in Andrei's book? As a matter of fact he states in chapter 4.3: «On the minus side, "tall and thin" arrays with many rows and few columns incur a large size overhead as there's one array to keep per column. [...] Jagged arrays may have problems with efciency of access and cache friendliness. Each element access requires two indirections [...] going column-wise through a jagged array is a cache miss bonanza.» It would look that well implemented [,,] arrays would fill some application gaps, even though arrays of arrays (jagged in practice or not) are elsewhere useful as well of course. In the former cases I would think about defining my own struct wrapping a flat array with an n-dimensional api such as return _buff[i*m + j]... but generic in type and maybe also in dimension. Again any special reason why this isn't already provided in the language? Either a generic struct/class like that, or something deeper in the language that allows using the [] operator as Thanks for any input.
Feb 18 2017
On Saturday, 18 February 2017 at 10:37:21 UTC, XavierAP wrote:Does D provide anything like this? Otherwise, was this ever considered and were reasons found not to have it?They are implemented as part of the Mir project. We call them ndslices. https://github.com/libmir/mir-algorithm Docs: http://docs.algorithm.dlang.io/ See also other Mir projects at https://github.com/libmir. std.experimental.ndslice is a deprecated version of mir.ndslice. std.experimental.ndslice provides only numpy like tensors. mir.ndslice provides all kinds of tensors. Sparse tensors can be found at https://github.com/libmir/mir Best, Ilya
Feb 18 2017