From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 3BD60BB83 for ; Fri, 14 Apr 2006 16:03:17 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k3EE3GeR028486 for ; Fri, 14 Apr 2006 16:03:16 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA18802 for ; Fri, 14 Apr 2006 16:03:14 +0200 (MET DST) Received: from mail.libertysurf.net (mx-out.libertysurf.net [213.36.80.91]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k3EE3DNc008337 for ; Fri, 14 Apr 2006 16:03:14 +0200 Received: from dyn-83-156-171-225.ppp.tiscali.fr (83.156.171.225) by mail.libertysurf.net (7.2.071) id 44327663001AF7E4 for caml-list@inria.fr; Fri, 14 Apr 2006 16:03:13 +0200 From: Florent Monnier Organization: l'Association Linux-Nantes To: caml-list@inria.fr Subject: Bigarray.c_layout Date: Fri, 14 Apr 2006 16:04:28 +0200 User-Agent: KMail/1.8.2 MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200604141604.29147.fmonnier@linux-nantes.fr.eu.org> X-Face: "`cRNH1ww*pA7BMG\%C8RcGZR33F%q#d~:5U8b[K-NbYLSW_wpx@wk**lzqX3\F'a|gyP"K /emS.&rsSu'a7OiJH&d?,Z6OxW_L}I"z%\><#5LL%uQXl"QY@~9|XyM7{`tAq?Gp@ul&F'# Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 443FABA4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 443FABA1.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bigarray:01 bigarray:01 ocaml:01 ocaml:01 work-around:01 replacing:01 arrays:01 arrays:01 pred:01 pred:01 height:98 height:98 assert:01 assert:01 reorder:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 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 ;;