April 16, 2014
On Monday, 17 March 2014 at 17:39:41 UTC, Denis Shelomovskij wrote:
> Multidimensional arrays indexing and slicing syntax is finally added [1] (thanks to Kenji Hara). So it was a good cause to update my multidimensional arrays library implementation and add support for the new syntax. So here we are: [2].
>
> Also should we add it to the standard library?
>
> [1] https://github.com/D-Programming-Language/dmd/pull/443
> [2] http://denis-sh.bitbucket.org/unstandard/unstd.multidimarray.html

First of all, thank you very much for making such nice additions to D available for general use. I finally got around to giving this a spin. I'm using it for a proof-of-context HPC simuation code written in D (currently mostly experimenting with D's features), and as such I'm interfacing with the C MPI library to communicate between processes. The basis of the simulation is a 3D lattice, so I was eagerly awaiting a nice solution in D. So far I've run into two things while using your library. The first is that I need to provide void pointers to the data to the MPI functions, so I currently hacked your code to make the _data storage array publicly accessible and that seems to work. To give an idea, I currently have code like this (just a snippet):

arr = multidimArray!T(nxH, nyH, nzH);
// [...] fill the array with data
// Prepare a buffer to receive a slice from another process.
rbuffer = multidimArray!T(haloSize, nyH, nzH);
// Prepare a buffer to send a slice to another process.
sbuffer = arr[$-2*haloSize-1..$ - haloSize-1, 0..$, 0..$].dup;
// Here I now use the pointer of the storage arrays to send the buffer around.
MPI_Sendrecv(sbuffer._data.ptr, nyH * nzH, MPI_INT, M.nbx[1], 0, rbuffer._data.ptr, nyH * nzH, mpiType, M.nbx[0], 0, M.comm, &mpiStatus);
// Put the buffer in the correct spot in the main array.
arr[0..haloSize, 0..$, 0..$] = rbuffer;

Am I missing a nicer way to accomplish this? I like the compactness of the code (compared to what I'm currently used to with our F90 simulation code). Secondly, the property that returns the dimensions of the array is called 'dimentions' (with a t), this should be fixed.

Regards,

Stefan
April 16, 2014
Stefan Frijters:

> First of all, thank you very much for making such nice additions to D available for general use. I finally got around to giving this a spin.

Recently I've shown a possible usage example of the multidimensional arrays indexing and slicing syntax:
http://forum.dlang.org/thread/cizugfrkaunlkzyjptnp@forum.dlang.org

Bye,
bearophile
April 17, 2014
On Monday, 17 March 2014 at 21:25:34 UTC, bearophile wrote:
> Jared Miller:
>
>> And yes, I think that a matrix / linear algebra library, as well as NumPy-style ND-Arrays are great candidates for future Phobos modules.
>
> I suggest to not put such library in Phobos before few years of usage in the wild.
>

+1

Good matrix support would be awesome. But getting it wrong would be a catastrophe. I don't really support ever putting it in phobos, but if it is, then it should only be added after lots of experience.
April 17, 2014
On Thu, Apr 17, 2014 at 03:16:20PM +0000, CJS via Digitalmars-d wrote:
> On Monday, 17 March 2014 at 21:25:34 UTC, bearophile wrote:
> >Jared Miller:
> >
> >>And yes, I think that a matrix / linear algebra library, as well as NumPy-style ND-Arrays are great candidates for future Phobos modules.
> >
> >I suggest to not put such library in Phobos before few years of usage in the wild.
> >
> 
> +1
> 
> Good matrix support would be awesome. But getting it wrong would be a catastrophe. I don't really support ever putting it in phobos, but if it is, then it should only be added after lots of experience.

I've been longing for a high-quality, flexible, generic linear algebra library in D. I don't have the time / resources to implement it myself, otherwise I would.

But I agree that any such candidate library needs to be put in real-life use for a while before being considered for Phobos.

I think the first step would be to refine Denis' n-dimensional array library until it's Phobos-quality, then linear algebra specific adaptations can be built on top. I think the two should be separated, even if they are still related. Conflating 2D arrays with matrices at a fundamental level is a mistake IMO. 2D arrays are just one of the possible representations of a matrix, and any linear algebra library should be flexible enough to use other representations (e.g., sparse matrices).


T

-- 
He who laughs last thinks slowest.
June 10, 2014
I've been using the multidimensional arrays for a while now, but recently I've run into a problem w.r.t. optimization:

import std.stdio;
import unstd.multidimarray;

void main() {
  MultidimArray!(double, 3) arr;
  arr = multidimArray!double([1,2,42]);
  writeln(arr.lengths);
}

If I compile with 'dmd multidimtest.d unstd/multidimarray.d', I get [1,2,42], as expected, but when I compile in release mode 'dmd multidimtest.d unstd/multidimarray.d -release' I get [0,0,0]. Any ideas what might cause this?

Also, when I compile with -w (which I normally prefer) I get a list of errors of the type

unstd/multidimarray.d(101): Warning: calling unstd.multidimarray.MultidimArray!(double, 3LU).MultidimArray.this without side effects discards return value of type inout(MultidimArray!(double, 3LU)), prepend a cast(void) if intentional

I've acted on these errors in the version I use for my HPC test code, and I have not noticed any deleterious effects; would you accept a pull request to fix these?

Kind regards,

Stefan Frijters
June 10, 2014
Am 17.03.2014 18:39, schrieb Denis Shelomovskij:
> Multidimensional arrays indexing and slicing syntax is finally added [1]
> (thanks to Kenji Hara). So it was a good cause to update my
> multidimensional arrays library implementation and add support for the
> new syntax. So here we are: [2].
>
> Also should we add it to the standard library?
>
> [1] https://github.com/D-Programming-Language/dmd/pull/443
> [2] http://denis-sh.bitbucket.org/unstandard/unstd.multidimarray.html
>

Yes please
June 11, 2014
On Tuesday, 10 June 2014 at 19:04:18 UTC, Stefan Frijters wrote:
> I've been using the multidimensional arrays for a while now, but recently I've run into a problem w.r.t. optimization:
>
> import std.stdio;
> import unstd.multidimarray;
>
> void main() {
>   MultidimArray!(double, 3) arr;
>   arr = multidimArray!double([1,2,42]);
>   writeln(arr.lengths);
> }
>
> If I compile with 'dmd multidimtest.d unstd/multidimarray.d', I get [1,2,42], as expected, but when I compile in release mode 'dmd multidimtest.d unstd/multidimarray.d -release' I get [0,0,0]. Any ideas what might cause this?

I've looked into this and it seems there is required code inside a contract 'in', which is omitted with -release.

I've gone ahead and opened a pull request to fix this: https://bitbucket.org/denis-sh/unstandard/pull-request/2/bugfixes-for-multidimarrayd

Stefan
1 2
Next ›   Last »