caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Bigarray.c_layout
@ 2006-04-14 14:04 Florent Monnier
       [not found] ` <20060414.193255.24118599.debian00@tiscali.fr>
  0 siblings, 1 reply; 5+ messages in thread
From: Florent Monnier @ 2006-04-14 14:04 UTC (permalink / raw)
  To: caml-list

Hi,
My problem is with the Bigarray.c_layout 

All the items are ordered row by row in OCaml with this layout,
and the library I use through OCaml use the datas ordered line by line.

As a temporary work-around, I've made the function 'reorder' below.
But this way is very too slow.

So what solution would you advice to me ?
- creating an other Bigarray.c_layout : "Bigarray.c_layout_by_line" ?
(and then propose it as a patch to be included in a futur OCaml version)
- or replacing my big arrays of 3 dimensions by big arrays of 1 dimension
and creating a function which converts the index i j k by the unique index ?
- something else ?


-- 
best regards


=========================
let reorder_c_to_ml ~arr =
  let width  = Array3.dim1 arr
  and height = Array3.dim2 arr
  and cells  = Array3.dim3 arr
  and kind   = Array3.kind arr
  in
  assert(cells=3);
  let tmp = Array1.create kind c_layout (width * height * cells)
  and k = ref 0
  in
  for i = 0 to pred(width) do
    for j = 0 to pred(height) do
      tmp.{!k} <- arr.{i,j,0}; incr k;
      tmp.{!k} <- arr.{i,j,1}; incr k;
      tmp.{!k} <- arr.{i,j,2}; incr k;
    done;
  done;
  k := 0;
  for j = 0 to pred(height) do
    for i = 0 to pred(width) do
      arr.{i,j,0} <- tmp.{!k}; incr k;
      arr.{i,j,1} <- tmp.{!k}; incr k;
      arr.{i,j,2} <- tmp.{!k}; incr k;
    done;
  done;
  (arr)
;;

let reorder_ml_to_c ~arr =
  let width  = Array3.dim1 arr
  and height = Array3.dim2 arr
  and cells  = Array3.dim3 arr
  and kind   = Array3.kind arr
  in
  assert(cells=3);
  let tmp = Array1.create kind c_layout (width * height * cells)
  and k = ref 0
  in
  for j = 0 to pred(height) do
    for i = 0 to pred(width) do
      tmp.{!k} <- arr.{i,j,0}; incr k;
      tmp.{!k} <- arr.{i,j,1}; incr k;
      tmp.{!k} <- arr.{i,j,2}; incr k;
    done;
  done;
  k := 0;
  for i = 0 to pred(width) do
    for j = 0 to pred(height) do
      arr.{i,j,0} <- tmp.{!k}; incr k;
      arr.{i,j,1} <- tmp.{!k}; incr k;
      arr.{i,j,2} <- tmp.{!k}; incr k;
    done;
  done;
  (arr)
;;

type dir = ML_to_C | C_to_ML

let reorder ~arr ?(dir=ML_to_C) () =
  match dir with
  | ML_to_C -> reorder_ml_to_c ~arr
  | C_to_ML -> reorder_c_to_ml ~arr
;;


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-04-20 21:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-14 14:04 Bigarray.c_layout Florent Monnier
     [not found] ` <20060414.193255.24118599.debian00@tiscali.fr>
2006-04-14 18:07   ` Bigarray.c_layout Florent Monnier
2006-04-20  9:42     ` [Caml-list] Bigarray.c_layout Damien Doligez
2006-04-20 14:03       ` Florent Monnier
2006-04-20 21:14         ` Remi Vanicat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).