GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing reasonml.github.io — Reason · Reason lets you write simple, fast and quality type safe code while leveraging both the JavaScript & OCaml ecosystems. Module Bigarraymodule Bigarray: sig .. endLarge, multi-dimensional, numerical arrays. This module implements multi-dimensional arrays of integers and
floating-point numbers, thereafter referred to as 'Bigarrays',
to distinguish them from the standard OCaml arrays described in
The implementation allows efficient sharing of large numerical arrays between OCaml code and C or Fortran numerical libraries. The main differences between 'Bigarrays' and standard OCaml arrays are as follows:
Users of this module are encouraged to do Bigarrays support all the OCaml ad-hoc polymorphic operations:
Element kindsBigarrays can contain elements of the following kinds:
Each element kind is represented at the type level by one of the
type float32_elt =
type float64_elt =
type int8_signed_elt =
type int8_unsigned_elt =
type int16_signed_elt =
type int16_unsigned_elt =
type int32_elt =
type int64_elt =
type int_elt =
type nativeint_elt =
type complex32_elt =
type complex64_elt =
type ('a, 'b) kind =
To each element kind is associated an OCaml type, which is
the type of OCaml values that can be stored in the Bigarray
or read back from it. This type is not necessarily the same
as the type of the array elements proper: for instance,
a Bigarray whose elements are of kind The GADT type Using a generalized algebraic datatype (GADT) here allows writing well-typed polymorphic functions whose return type depend on the argument type, such as: let zero : type a b. (a, b) kind -> a = function
| Float32 -> 0.0 | Complex32 -> Complex.zero
| Float64 -> 0.0 | Complex64 -> Complex.zero
| Int8_signed -> 0 | Int8_unsigned -> 0
| Int16_signed -> 0 | Int16_unsigned -> 0
| Int32 -> 0l | Int64 -> 0L
| Int -> 0 | Nativeint -> 0n
| Char -> '\000'
val float32 : (float, float32_elt) kind See val float64 : (float, float64_elt) kind See val complex32 : (Complex.t, complex32_elt) kind See val complex64 : (Complex.t, complex64_elt) kind See val int8_signed : (int, int8_signed_elt) kind See val int8_unsigned : (int, int8_unsigned_elt) kind See val int16_signed : (int, int16_signed_elt) kind See val int16_unsigned : (int, int16_unsigned_elt) kind See val int : (int, int_elt) kind See val int32 : (int32, int32_elt) kind See val int64 : (int64, int64_elt) kind See val nativeint : (nativeint, nativeint_elt) kind See val char : (char, int8_unsigned_elt) kind As shown by the types of the values above,
Bigarrays of kind val kind_size_in_bytes : ('a, 'b) kind -> int
Array layoutstype c_layout =
type fortran_layout =
To facilitate interoperability with existing C and Fortran code, this library supports two different memory layouts for Bigarrays, one compatible with the C conventions, the other compatible with the Fortran conventions. In the C-style layout, array indices start at 0, and
multi-dimensional arrays are laid out in row-major format.
That is, for a two-dimensional array, all elements of
row 0 are contiguous in memory, followed by all elements of
row 1, etc. In other terms, the array elements at In the Fortran-style layout, array indices start at 1, and
multi-dimensional arrays are laid out in column-major format.
That is, for a two-dimensional array, all elements of
column 0 are contiguous in memory, followed by all elements of
column 1, etc. In other terms, the array elements at Each layout style is identified at the type level by the
phantom types Supported layoutsThe GADT type type 'a layout =
val c_layout : c_layout layout val fortran_layout : fortran_layout layout Generic arrays (of arbitrarily many dimensions)module Genarray: sig .. endZero-dimensional arraysmodule Array0: sig .. endZero-dimensional arrays. One-dimensional arraysmodule Array1: sig .. endOne-dimensional arrays. Two-dimensional arraysmodule Array2: sig .. endTwo-dimensional arrays. Three-dimensional arraysmodule Array3: sig .. endThree-dimensional arrays. Coercions between generic Bigarrays and fixed-dimension Bigarraysval genarray_of_array0 : ('a, 'b, 'c) Array0.t -> ('a, 'b, 'c) Genarray.tReturn the generic Bigarray corresponding to the given zero-dimensional Bigarray.
val genarray_of_array1 : ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.tReturn the generic Bigarray corresponding to the given one-dimensional Bigarray. val genarray_of_array2 : ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.tReturn the generic Bigarray corresponding to the given two-dimensional Bigarray. val genarray_of_array3 : ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.tReturn the generic Bigarray corresponding to the given three-dimensional Bigarray. val array0_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array0.tReturn the zero-dimensional Bigarray corresponding to the given generic Bigarray.
val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.tReturn the one-dimensional Bigarray corresponding to the given generic Bigarray.
val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.tReturn the two-dimensional Bigarray corresponding to the given generic Bigarray.
val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.tReturn the three-dimensional Bigarray corresponding to the given generic Bigarray.
Re-shaping Bigarraysval reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t
val reshape_0 : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array0.tSpecialized version of
val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.tSpecialized version of val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.tSpecialized version of val reshape_3 : ('a, 'b, 'c) Genarray.t -> int -> int -> int -> ('a, 'b, 'c) Array3.tSpecialized version of Bigarrays and concurrency safetyCare must be taken when concurrently accessing bigarrays from multiple domains: accessing a bigarray will never crash a program, but unsynchronized accesses might yield surprising (non-sequentially-consistent) results. AtomicityEvery bigarray operation that accesses more than one array element is not atomic. This includes slicing, bliting, and filling bigarrays. For example, consider the following program: open Bigarray
let size = 100_000_000
let a = Array1.init Int C_layout size (fun _ -> 1)
let update f a () =
for i = 0 to size - 1 do a.{i} <- f a.{i} done
let d1 = Domain.spawn (update (fun x -> x + 1) a)
let d2 = Domain.spawn (update (fun x -> 2 * x + 1) a)
let () = Domain.join d1; Domain.join d2
After executing this code, each field of the bigarray Data racesIf two domains only access disjoint parts of the bigarray, then the observed behaviour is the equivalent to some sequential interleaving of the operations from the two domains. A data race is said to occur when two domains access the same bigarray element without synchronization and at least one of the accesses is a write. In the absence of data races, the observed behaviour is equivalent to some sequential interleaving of the operations from different domains. Whenever possible, data races should be avoided by using synchronization to mediate the accesses to the bigarray elements. Indeed, in the presence of data races, programs will not crash but the observed behaviour may not be equivalent to any sequential interleaving of operations from different domains. TearingBigarrays have a distinct caveat in the presence of data races: concurrent bigarray operations might produce surprising values due to tearing. More precisely, the interleaving of partial writes and reads might create values that would not exist with a sequential execution. For instance, at the end of let res = Array1.init Complex64 c_layout size (fun _ -> Complex.zero)
let d1 = Domain.spawn (fun () -> Array1.fill res Complex.one)
let d2 = Domain.spawn (fun () -> Array1.fill res Complex.i)
let () = Domain.join d1; Domain.join d2
the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |