Boost logo

Boost :

Subject: Re: [boost] different matrix library?
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2009-08-17 09:17:45


Edward Grace wrote:

> I don't quite understand why you wouldn't want a DSL like MATLAB?
> After all, MATLAB remember is essentially FORTRAN with different
> horse shoes, that's why so many scientific / engineering types pick
> it up so fast - there is very little that's new to learn.

Not saying that I wouldn't want it, saying that perhaps there are some gems
in other languages, too. I do not have a Fortran background, but I have to
admit that I have used R rather extensively. R/S stuff like

A[row(A)==col(A)] <- 2

is easy to use, but does not really match with something like

std::fill( diag(A).begin(), diag(A).end(), 2 );

which would perhaps be the C++ way.

> For example,
>
> alpha(2:10)=alpha(1:9)
>
> Is the above MATLAB or FORTRAN? How would you express this in C++
> (note the aliasing)? Perhaps
>
> alpha(range(2,10))=alpha(range(1,9));
>
> or some-such?

Not sure, but given your example, something like

std::rotate( alpha.begin(), alpha.begin()+1, alpha.end() );

:-). I agree the Matlab code is more readable in this case.

> How about,
>
> vec=mat(:,4)
>
> (Again, is that MATLAB or is it FORTRAN?)

Are you copying or keeping a reference? Anyway,

vec = row(mat,4)
vec = diag(mat)
etc.
 
>> Have you considered creating a more C++-like domain-specific
>> language, taking elements from various domain-specific languages?
>
> Can you give some examples?
>

E.g., I would prefer

x = solve( A, b )

over x = A\b;

> If you go and write a whole new paradigm (interface) for linear
> algebra without at least a nod to it's heritage it will probably be
> ignored by many of the people who actually *do* it for a living and
> get used just by hobbyists who enjoy the process rather than the
> result. (I'm guilty of that myself - hence I'm here).

I'm not after that. I'm just saying that there might be people who actually
do stuff in other packages than Matlab (like R et al.).

What I also wanted to add is that many (real-life) examples of algorithms do
not contain that much linear algebra. I've seen a great deal of .m files
which have about 20% linear algebra. About 80% is conditional program flow
and bookkeeping stuff. This is where C++ has a clear edge. If we're going to
mix them, it should look natural.

> In my humble opinion, for C++ to really take off in next generation
> scientific applications (believe me I'd love to see it happen), the
> language should keep out of the way. Ultimately application writers
> just want the answer - they really don't want to have to figure out
> how the minutiae of template meta-programming works.

Indeed, it should be easy to write. Just as an example, a function "solve"
would already cover a large portion of the whole of LAPACK. A DSL for linear
algebra does not need to be complex. The more expressiveness, the better, I
would say.

Cheers,

Rutger


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk