Re: Q: float arrays

Xavier Leroy
 Thorsten Ohl
[
Home
]
[ Index:
by date

by threads
]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
Date:   (:) 
From:  Thorsten Ohl <ohl@c...> 
Subject:  Re: Q: float arrays 
>>>>> "Xavier" == Xavier Leroy <Xavier.Leroy@inria.fr> writes: Xavier> Polymorphism and higherorder functions don't mix well with Xavier> high performance. If you need Fortranlike performance, there Xavier> are cases where you must write Fortranstyle code. I know that I'm asking too much, but wouldn't it be nice it the compiler did it for me? In the example at hand, let f2 = map (function (p,p') > (p*.p')) the compiler could inline the multiplication automagically, iff it still had access to the definition of the map function. A trivial example is code like the following: let exponentiate make_unit eps norm plus minus times scale x = let u = make_unit x in let rec sumup s n x1 xn = if norm (xn) <= eps *. norm (minus s u) then s else sumup (plus s xn) (n +. 1.0) x1 (scale (1.0 /. n) (times x1 xn)) in (* usually, times x u == x, but u can be a projector which will speed up things for special cases. *) sumup u 2.0 x (times x u) let exp_ = exponentiate (fun _ > 1.0) 1e14 abs_float ( +. ) ( . ) ( *. ) ( *. ) let exp_matrix = exponentiate unit_like 1e14 infinity_norm add subtract multiply scale_matrix Here partial application really shines and it could shine even brighter if there was no speed penalty ... Cheers, Thorsten  Thorsten Ohl, Physics Department, TH Darmstadt  PGP: AF 38 FF CE 03 8A 2E A7 http://crunch.ikp.physik.thdarmstadt.de/~ohl/  8F 2A C1 86 8C 06 32 6B