* [Caml-list] Array1.fold_left
@ 2003-08-11 23:56 Christophe TROESTLER
0 siblings, 0 replies; only message in thread
From: Christophe TROESTLER @ 2003-08-11 23:56 UTC (permalink / raw)
To: O'Caml Mailing List
Hi all,
For the following discussion, one assumes to be in the scope of an
[open Bigarray].
Suppose for example I want to compute the maximum of [a] of type
(float, float64_elt, 'a) Array1.t. I can imagine the following code:
let array1_max a =
let m = ref (-. infinity) in
if Array1.layout a = (Obj.magic c_layout : 'a Bigarray.layout) then
for i = 0 to Array1.dim a - 1 do
if !m < a.{i} then m := a.{i}
done
else (* fortran layout *)
for i = 1 to Array1.dim a do
if !m < a.{i} then m := a.{i}
done;
!m
Actually, the test on the layout is superfluous since all elements of
the array are accessed. But there is no way to get rid of it unless
one writes a C function. Wouldn't be nicer (and more efficient?) to
have primitives like Array1.fold_left ? Is there a reason such
functions are not part of the standard library?
Another interesting functions may be:
c_to_fortran : ('a, 'b, c_layout) Array1.t -> ('a, 'b, fortran_layout) Array1.t
fortran_to_c : ('a, 'b, fortran_layout) Array1.t -> ('a, 'b, c_layout) Array1.t
(permuting the dimension).
Maybe other people working with numerical code could speak up -- I
guess I am not the only one with this kind of needs, am I.
Cheers,
ChriS
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-08-12 0:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-11 23:56 [Caml-list] Array1.fold_left Christophe TROESTLER
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox