caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML
@ 2003-12-26  5:41 Grégory Guyomarc'h
  2003-12-27  9:42 ` Issac Trotts
  0 siblings, 1 reply; 2+ messages in thread
From: Grégory Guyomarc'h @ 2003-12-26  5:41 UTC (permalink / raw)
  To: caml-list

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

Merry XMas!!! Joyeux Noel!!!


---------------------------------------------------------------------
Grégory Guyomarc'h
Email: gregory@guyomarch.org
Phone: (+82) (0)16-9355-3799

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


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

* Re: [Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML
  2003-12-26  5:41 [Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML Grégory Guyomarc'h
@ 2003-12-27  9:42 ` Issac Trotts
  0 siblings, 0 replies; 2+ messages in thread
From: Issac Trotts @ 2003-12-27  9:42 UTC (permalink / raw)
  To: caml-list

On Thursday 25 December 2003 21:41, Grégory 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 = 
{
  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 = Array1.create float64 c_layout 32;;
let ifunc_of_ba ba = 
  let n = Array1.dim ba in
  let rec f = fun i ->
    if i < 0 then f(n+i) 
    else if i >= 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 = <fun>}
(* 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


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

end of thread, other threads:[~2003-12-27  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-26  5:41 [Caml-list] Fortran-like array indexing / PDE numerical code with boundary cells in OCAML Grégory Guyomarc'h
2003-12-27  9:42 ` Issac Trotts

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