NDim-slicing

Norbert Nemec Norbert at Nemec-online.de
Sat Mar 11 23:56:39 PST 2006


pragma wrote:
> Open mouth, insert foot.
> 
> Norbert, all, 
> Please disregard my last post and critique regarding rectangular arrays.  It
> seems that I need to read the docs a little more carefully next time as D does
> indeed support them. :(

I think you should take that foot out of your mouth again. The questions
in the last message were not that pointless after all:

Indeed the documentation talks about something called "rectangular
arrays". However this concept only exists for static arrays, i.e. for
arrays, where the size of all dimensions is known at compile time.

What is seriously missing are dynamic rectangular arrays.

Your first question, why these are seriously missing can be answered in
several ways

* reducing computational and storage overhead
using "dynamical arrays of dynamical arrays" means that every access to
the data takes two dereferencing operations. Furthermore all the rows of
the arrays have to be allocated separately, contributing to memory
fragmentation.

* greatly enhancing the comfort of handling NDim data
especially in the field of numerical computation -- which is a core part
not only of scientific computing, but also also of game programming,
image processing and many other fields of programming -- handling
NDim-data is the daily bread of the programmer. It may not be an issue
to every programmer, but there certainly is a huge group of potential D
users who will consider NDim-array handling a crucial language feature.

* preparing the path towards vectorized expressions
this goes beyond "reducing overhead" towards "enabling tremendous
optimization potential".

The first two points might be solvable by an array library, but I
believe that NDim arrays are such a core feature that they deserve
native support. When we last discussed this issue two years ago, most
people -- including Walter -- agreed that this should eventually become
part of the language, even though it did not get highest priority.

The "Future plans" page of the D homepage contains the point "Array
literal expressions" (which is, what I generalized under the term
"vectorized expressions") -- I believe that the issue of
multidimensional arrays should be solved first, before touching the
issue of array expressions. Both depend strongly no each other. Doing
one step without thinking of the others will make it a lot more
difficult in the end.

> 
> - EricAnderton at yahoo

pragma wrote:
> Perhaps I'm missing the boat, or maybe its just that long since you
posted the
> original NDim array proposal, but what were the advantages to adding
NDim arrays
> in D?
>
> The reason why I ask is that aside from using rectangular arrays for the
> purposes of reducing computational and storage overhead, for very
specific tasks
> (bitmap manipulation and matrices come to mind), the current soluiton
in D works
> quite well.  After all, it doesn't get any more simple, reliable and
easy to
> implement than limiting every array to exactly one dimension.  It's
also quite
> elegant in that by disallowing rectangular arrays, the problems with
wielding
> all of the variations in slicing and indexing become far less
bothersome: this
> last fact is unintentionally implied by your most recent post.
>
> I'm genuinely curious since you've obviously put a lot of effort
behind all
> this, and I'm very much in the dark as to why.  Could you please
enlighten me?
> :)
>
> Thanks,
>
>
> - EricAnderton at yahoo



More information about the Digitalmars-d mailing list