From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA08441; Sat, 27 Dec 2003 10:41:14 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 KAA08021 for ; Sat, 27 Dec 2003 10:41:12 +0100 (MET) Received: from pop19.ucdavis.edu (pop19.ucdavis.edu [169.237.105.29]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBR9fAv11422 for ; Sat, 27 Dec 2003 10:41:11 +0100 (MET) Received: from 128.120.141.214 ([128.120.141.214]) by pop19.ucdavis.edu (8.12.10/8.12.9/it-std-5.2.0) with ESMTP id hBR9f7CT010052 for ; Sat, 27 Dec 2003 01:41:08 -0800 (PST) From: Issac Trotts To: caml-list@inria.fr Subject: Re: [Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML Date: Sat, 27 Dec 2003 01:42:18 -0800 User-Agent: KMail/1.5.4 References: <20031226054132.53C8780176@server2.messagingengine.com> In-Reply-To: <20031226054132.53C8780176@server2.messagingengine.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200312270142.18979.ijtrotts@ucdavis.edu> X-Loop: caml-list@inria.fr X-Spam: no; 0.00; issac:01 trotts:01 ijtrotts:01 caml-list:01 bigarrays:01 val:01 issac:01 trotts:01 bigarray:01 bigarray:01 ocaml:01 ocaml:01 int:01 int:01 rec:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday 25 December 2003 21:41, Gr=E9gory Guyomarc'h wrote: > Hello, > > Does anyone know how to index bigarrays with negative integers as in > fortran (either through a modified version of Bigarray or some > pre-Processing macro with caml-p4)? For those who wonder, it is for a pde > numerical code, i wish i could index boundary cells naturally as u.{-1} > u.{-2}, ... and u.{n+1}, u.{n+2}, ... Or if you have any experience in > implementing such numerical code in OCaml and want to suggest better > options, i am also interested :o). One way is to make a record type like this type ifunc =3D=20 { lo: int; (* lowest index inside the boundaries *) hi: int; (* highest index inside the boundaries *) f: int -> float; } and then wrap your bigarray like this: #load "bigarray.cma";; open Bigarray let b =3D Array1.create float64 c_layout 32;; let ifunc_of_ba ba =3D=20 let n =3D Array1.dim ba in let rec f =3D fun i -> if i < 0 then f(n+i)=20 else if i >=3D n then f(i-n) else ba.{i} in {=20 lo =3D 0;=20 hi =3D n-1; f =3D f; } # let b2 =3D ifunc_of_ba b;; val b2 : ifunc =3D {lo =3D 0; hi =3D 31; f =3D } (* now let's look at the uninitialized values in the bigarray **) # b2.f(-1);; =2D : float =3D 8.75916002045846257e+189 # b2.f(-2);; =2D : float =3D 1.96098134143591667e+243 # b2.f(32+1);; =2D : float =3D 5.66882172258997e-228 # b2.f(32+2);; =2D : float =3D -1.24992649718407699e+65 # b2.f(1);; =2D : float =3D 5.66882172258997e-228 # b2.f(2);; =2D : float =3D -1.24992649718407699e+65 It wasn't really clear from your message how you wanted to handle the bound= ary=20 conditions, so I made them periodic. I hope this helps. =20 =2D- Issac Trotts ------------------- 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