<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/12/094da94c51e0ab2565dee6e84a1f4b0d"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2003-12-27T09:41:14"
  subject="Re: [Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML"
  prev="2003/12/7571a6148d8c280edb0db625b83346de"
  next="2003/12/2b4c84dc2cfda3711e7e10dbe2e58598"
  prev-in-thread="2003/12/7571a6148d8c280edb0db625b83346de"
  prev-thread="2003/12/68fb62727bb19539682c9f2f2f52efda"
  next-thread="2003/12/2b4c84dc2cfda3711e7e10dbe2e58598"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML">
<msg 
  url="2003/12/7571a6148d8c280edb0db625b83346de"
  from="Grégory Guyomarc&apos;h &lt;gregory@g...&gt;"
  author="Grégory Guyomarc&apos;h"
  date="2003-12-26T06:06:51"
  subject="[Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML">
<msg 
  url="2003/12/094da94c51e0ab2565dee6e84a1f4b0d"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2003-12-27T09:41:14"
  subject="Re: [Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML">
</msg>
</msg>
</thread>

<contents>
On Thursday 25 December 2003 21:41, Grégory Guyomarc'h wrote:
&gt; Hello,
&gt;
&gt; Does anyone know how to index bigarrays with negative integers as in
&gt; fortran (either through a modified version of Bigarray or some
&gt; pre-Processing macro with caml-p4)? For those who wonder, it is for a pde
&gt; numerical code, i wish i could index boundary cells naturally as u.{-1}
&gt; u.{-2}, ... and u.{n+1}, u.{n+2}, ... Or if you have any experience in
&gt; implementing such numerical code in OCaml and want to suggest better
&gt; options, i am also interested :o).

One way is to make a record type like this

type ifunc = 
{
  lo: int; (* lowest index inside the boundaries *)
  hi: int; (* highest index inside the boundaries *)
  f: int -&gt; float;
}

and then wrap your bigarray like this:

#load "bigarray.cma";;
open Bigarray
let b = Array1.create float64 c_layout 32;;
let ifunc_of_ba ba = 
  let n = Array1.dim ba in
  let rec f = fun i -&gt;
    if i &lt; 0 then f(n+i) 
    else if i &gt;= n then f(i-n)
    else ba.{i}
  in
  { 
     lo = 0; 
     hi = n-1;
     f = f;
  }
# let b2 = ifunc_of_ba b;;
val b2 : ifunc = {lo = 0; hi = 31; f = &lt;fun&gt;}
(* now let's look at the uninitialized values in the bigarray **)
# b2.f(-1);;
- : float = 8.75916002045846257e+189
# b2.f(-2);;
- : float = 1.96098134143591667e+243
# b2.f(32+1);;
- : float = 5.66882172258997e-228
# b2.f(32+2);;
- : float = -1.24992649718407699e+65
# b2.f(1);;
- : float = 5.66882172258997e-228
# b2.f(2);;
- : float = -1.24992649718407699e+65

It wasn't really clear from your message how you wanted to handle the boundary 
conditions, so I made them periodic.

I hope this helps.  

--
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

</contents>

</message>

