Designing a matrix library for D

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 23 20:28:15 PDT 2014


On Tue, Jun 24, 2014 at 03:04:53AM +0000, David Bregman via Digitalmars-d wrote:
> Have you looked at armadillo for inspiration? http://arma.sourceforge.net/
> 
> It's a C++ matrix/linear algebra library which has:
> -expression templates for high level optimizations (could be done even
> better in D of course, moving more stuff to compile time)
> -high performance via lapack/blas
> -deliberately matlab-like syntax which is appealing to a large subset
> of people who would use such a library
> 
> I think this approach would also be good for D, at least if the idea
> is to target numeric computing people. I am skeptical about making the
> library too generic, since performance is typically a primary concern
> for matrix code. I didn't read the linked paper, but the performance
> quoted in the abstract "comparable (from 48% to 100%) to that of
> lower-level Java programs" sounds pretty underwhelming.

Using lapack/blas as the backend would guarantee good performance,
though I'm not sure if the Phobos maintainers would be too thrilled at
the idea, after the fiasco with libcurl.

For high performance, I would implement matrix algebra completely within
a compile-time DSL instead of hack tricks like expression templates and
operator overloading. That way, the implementation can algebraically
manipulate the expressions to maximize opportunities for optimizations.

As for genericity, I think D has the ability to generate performant code
*and* be generic at the same time. At least, it'd worth shooting for to
see how far we can get. I believe the key is to separate the algorithms
from the concrete types, and use specialization for the
performance-sensitive cases. This way, the generic cases will work, and
the specific cases will be high-performance.


T

-- 
Nothing in the world is more distasteful to a man than to take the path that leads to himself. -- Herman Hesse


More information about the Digitalmars-d mailing list