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] interesting array efficiency observations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-11 (05:04)
From: briand@a...
Subject: Re: [Caml-list] interesting array efficiency observations


Thanks for the link.

However, I have a question :-)

>From the link:

   let f a x y = 1 + a.{x,y}

has a polymorphic type (int, 'a, 'b) Bigarray.Array2.t -> int -> int -> int
and compiles down to a library function call.  However,

    open Bigarray
    let f (a : (int, int_elt, c_layout) Array2.t) x y = 1 + a.{x,y}

is monomorphic and will be compiled much more efficiently by ocamlopt.

So what if I have declared a variable, i.e.

let the_a = Bigarray.Array2.create Bigarray.float64 Bigarray.c_layout 5 5;;

and now I invoke f 

  f the_a 1 2

Why would the_a be treated polymorphically ??

the_a is very clearly defined as a very specific Bigarray and so the
compiler will know this in the call to f, and will do the correct
thing, right ?

Isn't the type annotation in the function redundant in such a case ?



>>>>> "malc" == malc  <> writes:

  malc> On Sat, 8 May 2004 wrote:
  >>  I was investigating the use of 1-D bigarray's vs Array and
  >> noticed that the 1-D bigarray using c_layout seems to be slower
  >> than Array.


  malc> --

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