Expression template

Ilya Yaroshenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 24 03:53:41 PDT 2016


On Saturday, 23 July 2016 at 11:05:57 UTC, Etranger wrote:

> 1- Is there a cleaner way to do it ? I had to use struct 
> because I want every thing to happen at compile time and on the 
> stack (without gc). And I had to use string mixins because 
> template mixin does not work the way I tried to use it ( see 
> the error last line).

Yes, but it is more complicated in terms of multidimensional and 
generic abstraction.
First we need to finish and test general matrix multiplication 
[2].

> 2- Is there a safer way to do it (without using pointers) ?

Yes, but it is slower than pointers. See Internal Binary 
Representation for Slice structure [1]. Mir's BLAS will use 
pointers.

> 3- Do you think I'll hit a wall with this approach ?

No idea. In the same time I think that C++ approach is not 
flexible as we can build for D.
Currently we need std.algorithm analog for multidimensional case. 
It would be more flexible than expression templates. But it 
requires more complex architecture analysis.

> 4- Do you known any D libs that uses expression template for 
> linear algebra ?

I don't know. ndslice provides operations like `a[] += b` [1]. I 
just opened a PR to optimise them using SIMD instructions [4]. 
Mir BLAS will have more low level API for matrix multiplication 
then Eigen. See PR for gemm [2]. Expression like API can be build 
on top of Mir's BLAS.

> I'll be very happy if I could contribute something useful for 
> the D community :)

That would be great! See Mir's issues [3]. Feel free to open new 
one and start a discussion or open PR. Mir requires a lot of 
benchmarks, for example versus Eigen. Just Eigen benchmark of 
Level 3 BLAS functionality (like matrix multiplication) with 
proper CSV console output would very helpful. See current charts 
[5] and [6]

[1] 
http://dlang.org/phobos/std_experimental_ndslice_slice.html#.Slice
[2] https://github.com/libmir/mir/pull/255
[3] https://github.com/libmir/mir/issues
[4] https://github.com/dlang/phobos/pull/4647
[5] 
https://s3.amazonaws.com/media-p.slid.es/uploads/546207/images/2854632/Untitled_2.004.png
[6] 
https://s3.amazonaws.com/media-p.slid.es/uploads/546207/images/2854640/Untitled_2.006.png

Best regards,
Ilya


More information about the Digitalmars-d-learn mailing list