Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] productivity improvement
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-10-17 (19:07)
From: Shivkumar Chandrasekaran <shiv@e...>
Subject: Re: [Caml-list] Re: Camlp4 optimizations (was: productivity improvement)

On Thursday, October 17, 2002, at 11:32 AM, Chris Hecker wrote:

> The biggest problem with making ocaml look nice and pretty for 
> numerical code is that there is no overloading (of functions or 
> operators),

I have written thousands of lines of numerical linear algebra code in 
Clean (where such overloading is possible) and in OCaml. I don't miss 
it one bit. (Let me concentrate on matrix multiplication since that was 
what the post talked about.)

The reason for not missing overloading is that in coding *efficient* 
matrix algorithms, matrix multiplications usually have a well-defined 
end-place for the result. This end-place is usually a sub-matrix of an 
existing matrix (canonical examples are classical factorizations: LU, 
QR). Hence I don't just need "a * b", I really need to say "c = a * b, 
but don't generate new space for a * b, just use the space allocated 
for c instead".

Luckily in OCaml and Clean we can solve this by making a HOF of type

( |*| ) : matrix * matrix -> (matrix -> unit)

Then I can say (a |*| b) c, or, with one more definition,

c =$ a |*| b

Note, that even Clean will not allow you to replace |*| with *, since 
the only way to overload * in Clean is as (matrix matrix -> matrix) 
which is not what I want.

Secondly I also need to say, in Matlab notation, a' * b. One cumbersome 
way around is to define a function called transpose that just flags its 
argument to be transposed without actually doing it. This creates its 
own nightmare. A better solution for me (in Clean and OCaml) has been 
to define a ~* b to mean a' * b, and variations thereof.

However, for casual coding a la Matlab style, the lack of overloading 
could be seen as a problem. Of course one must then be prepared to live 
with unnecessary copying and memory accesses.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: