From: Florent Monnier <fmonnier@linux-nantes.fr.eu.org>
To: caml-list@inria.fr
Subject: Bigarray.c_layout
Date: Fri, 14 Apr 2006 16:04:28 +0200 [thread overview]
Message-ID: <200604141604.29147.fmonnier@linux-nantes.fr.eu.org> (raw)
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
;;
next reply other threads:[~2006-04-14 14:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-14 14:04 Florent Monnier [this message]
[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
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=200604141604.29147.fmonnier@linux-nantes.fr.eu.org \
--to=fmonnier@linux-nantes.fr.eu.org \
--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;
as well as URLs for NNTP newsgroup(s).