Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Christophe TROESTLER <del-con@tiscali.be>
To: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: [Caml-list] Array1.fold_left
Date: Tue, 12 Aug 2003 01:56:08 +0200 (CEST)	[thread overview]
Message-ID: <20030812.015608.19060385.del-con@tiscali.be> (raw)

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


                 reply	other threads:[~2003-08-12  0:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030812.015608.19060385.del-con@tiscali.be \
    --to=del-con@tiscali.be \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox