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
[Caml-list] Array1.fold_left
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe TROESTLER <del-con@t...>
Subject: [Caml-list] Array1.fold_left
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}
  else (* fortran layout *)
    for i = 1 to Array1.dim a do
      if !m < a.{i} then m := a.{i}

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.


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