Designing a matrix library for D

w0rp via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 7 10:39:13 PDT 2014


I have implemented a couple of matrices which may be of interest. 
One is heap allocated with garbage collection, another is based 
on 2D static arrays. I didn't implement a spare matrix.

https://github.com/w0rp/dstruct/blob/master/source/dstruct/matrix.d

There's very little which can be shared between sparse matrices 
and full matrices, as they optimise for very different scenarios. 
I wouldn't attempt write too many functions which work on both.

The one very interesting thing I got out of working on the 
matrices is that you can get a reference to the 2D static array 
matrix as a 1D static array, which means that you can do the 
following.

Matrix!(float, M, N) matrix;

fillArrayInC(matrix.array1D.ptr, matrix.array1D.length);

That's the one interesting thing I'd take away from everything I 
did. The ability to do that in D might be useful for someone else 
some time.


More information about the Digitalmars-d mailing list