| Attached Files | bigarray.patch [^] (8,821 bytes) 2012-08-09 02:53 [Show Content] [Hide Content]=== modified file 'otherlibs/bigarray/bigarray.ml'
--- old/otherlibs/bigarray/bigarray.ml 2012-07-17 15:31:12 +0000
+++ new/otherlibs/bigarray/bigarray.ml 2012-08-08 12:11:28 +0000
@@ -99,6 +99,13 @@
= "caml_ba_map_file_bytecode" "caml_ba_map_file"
let map_file fd ?(pos = 0L) kind layout shared dims =
map_internal fd kind layout shared dims pos
+
+ external to_float :
+ (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ external to_complex :
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
end
module Array1 = struct
@@ -122,6 +129,13 @@
ba
let map_file fd ?pos kind layout shared dim =
Genarray.map_file fd ?pos kind layout shared [|dim|]
+
+ external to_float :
+ (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ external to_complex :
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
end
module Array2 = struct
@@ -161,6 +175,13 @@
ba
let map_file fd ?pos kind layout shared dim1 dim2 =
Genarray.map_file fd ?pos kind layout shared [|dim1;dim2|]
+
+ external to_float :
+ (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ external to_complex :
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
end
module Array3 = struct
@@ -210,6 +231,13 @@
ba
let map_file fd ?pos kind layout shared dim1 dim2 dim3 =
Genarray.map_file fd ?pos kind layout shared [|dim1;dim2;dim3|]
+
+ external to_float :
+ (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ external to_complex :
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
end
external genarray_of_array1: ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t
=== modified file 'otherlibs/bigarray/bigarray.mli'
--- old/otherlibs/bigarray/bigarray.mli 2012-07-26 19:21:54 +0000
+++ new/otherlibs/bigarray/bigarray.mli 2012-08-08 12:07:06 +0000
@@ -426,6 +426,27 @@
or a SIGBUS signal may be raised. This happens, for instance, if the
file is shrinked. *)
+ external to_float: (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ (** [to_float a] converts [a] into a bigarray of floats, splitting
+ complex numbers as two consecutive floats. The returned
+ bigarray has the same dimensions as [a] except for the last
+ (resp. first) one which is the double of the one of [a] when [a]
+ has [c_layout] (resp. [fortran_layout]). The data is shared
+ between the two arrays. *)
+
+ external to_complex:
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
+ (** [to_complex a] converts [a] into a bigarray of complex numbers,
+ treating two consecutive floats as a complex number. The
+ returned bigarray has the same dimensions as [a] except for the
+ last (resp. first) one which is the half of the one of [a] when
+ [a] has [c_layout] (resp. [fortran_layout]). The data is shared
+ between the two arrays.
+
+ @raise Invalid_argument if the last (resp. first) dimension is odd. *)
+
end
(** {6 One-dimensional arrays} *)
@@ -496,6 +517,19 @@
(** Memory mapping of a file as a one-dimensional big array.
See {!Bigarray.Genarray.map_file} for more details. *)
+ external to_float: (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ (** Converts the bigarray, splitting complex numbers as two
+ consecutive floats. The data is shared.
+ See {!Bigarray.Genarray.to_float} for more details. *)
+
+ external to_complex:
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
+ (** Converts the bigarray, treating two consecutive floats as a
+ complex number. The data is shared.
+ See {!Bigarray.Genarray.to_complex} for more details. *)
+
external unsafe_get: ('a, 'b, 'c) t -> int -> 'a = "%caml_ba_unsafe_ref_1"
(** Like {!Bigarray.Array1.get}, but bounds checking is not always performed.
Use with caution and only when the program logic guarantees that
@@ -601,6 +635,19 @@
(** Memory mapping of a file as a two-dimensional big array.
See {!Bigarray.Genarray.map_file} for more details. *)
+ external to_float: (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ (** Converts the bigarray, splitting complex numbers as two
+ consecutive floats. The data is shared.
+ See {!Bigarray.Genarray.to_float} for more details. *)
+
+ external to_complex:
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
+ (** Converts the bigarray, treating two consecutive floats as a
+ complex number. The data is shared.
+ See {!Bigarray.Genarray.to_complex} for more details. *)
+
external unsafe_get: ('a, 'b, 'c) t -> int -> int -> 'a
= "%caml_ba_unsafe_ref_2"
(** Like {!Bigarray.Array2.get}, but bounds checking is not always
@@ -729,6 +776,19 @@
(** Memory mapping of a file as a three-dimensional big array.
See {!Bigarray.Genarray.map_file} for more details. *)
+ external to_float: (Complex.t, complex64_elt, 'a) t -> (float, float64_elt, 'a) t
+ = "caml_ba_to_float"
+ (** Converts the bigarray, splitting complex numbers as two
+ consecutive floats. The data is shared.
+ See {!Bigarray.Genarray.to_float} for more details. *)
+
+ external to_complex:
+ (float, float64_elt, 'a) t -> (Complex.t, complex64_elt, 'a) t
+ = "caml_ba_to_complex"
+ (** Converts the bigarray, treating two consecutive floats as a
+ complex number. The data is shared.
+ See {!Bigarray.Genarray.to_complex} for more details. *)
+
external unsafe_get: ('a, 'b, 'c) t -> int -> int -> int -> 'a
= "%caml_ba_unsafe_ref_3"
(** Like {!Bigarray.Array3.get}, but bounds checking is not always
=== modified file 'otherlibs/bigarray/bigarray_stubs.c'
--- old/otherlibs/bigarray/bigarray_stubs.c 2012-07-17 15:31:12 +0000
+++ new/otherlibs/bigarray/bigarray_stubs.c 2012-08-08 13:34:09 +0000
@@ -1101,6 +1101,73 @@
#undef b
}
+/* Conversion between float and complex arrays. */
+
+CAMLprim value caml_ba_to_float(value vb)
+{
+ CAMLparam1 (vb); /* Complex bigarray */
+ CAMLlocal1 (res);
+#define b ((struct caml_ba_array *) Caml_ba_array_val(vb))
+ intnat dim[CAML_BA_MAX_NUM_DIMS];
+ intnat flags = b->flags;
+ const mlsize_t num_dims = b->num_dims;
+
+ memcpy(dim, b->dim, num_dims * sizeof(intnat));
+ if ((flags & CAML_BA_LAYOUT_MASK) == CAML_BA_C_LAYOUT) {
+ dim[num_dims - 1] = 2 * dim[num_dims - 1];
+ }
+ else {
+ /* FORTRAN layout */
+ dim[0] = 2 * dim[0];
+ }
+ if (flags & CAML_BA_KIND_MASK == CAML_BA_COMPLEX32)
+ flags = (flags & ~CAML_BA_KIND_MASK) | CAML_BA_FLOAT32;
+ else
+ flags = (flags & ~CAML_BA_KIND_MASK) | CAML_BA_FLOAT64;
+ /* Create bigarray with same data and new dimensions */
+ res = caml_ba_alloc(flags, num_dims, b->data, dim);
+ /* Create or update proxy in case of managed bigarray */
+ caml_ba_update_proxy(b, Caml_ba_array_val(res));
+ /* Return result */
+ CAMLreturn (res);
+}
+
+CAMLprim value caml_ba_to_complex(value vb)
+{
+ CAMLparam1 (vb); /* Float bigarray */
+ CAMLlocal1 (res);
+#define b ((struct caml_ba_array *) Caml_ba_array_val(vb))
+ intnat dim[CAML_BA_MAX_NUM_DIMS];
+ intnat flags = b->flags;
+ const mlsize_t num_dims = b->num_dims;
+
+ memcpy(dim, b->dim, num_dims * sizeof(intnat));
+ if ((flags & CAML_BA_LAYOUT_MASK) == CAML_BA_C_LAYOUT) {
+ if (dim[num_dims - 1] % 2 == 1)
+ caml_invalid_argument("Bigarray.Genarray.to_complex: last dimension "
+ "is odd (c_layout)");
+ dim[num_dims - 1] = dim[num_dims - 1] / 2;
+ }
+ else {
+ /* FORTRAN layout */
+ if (dim[0] % 2 == 1)
+ caml_invalid_argument("Bigarray.Genarray.to_complex: first dimension "
+ "is odd (fortran_layout)");
+ dim[0] = dim[0] / 2;
+ }
+ if (flags & CAML_BA_KIND_MASK == CAML_BA_FLOAT32)
+ flags = (flags & ~CAML_BA_KIND_MASK) | CAML_BA_COMPLEX32;
+ else
+ flags = (flags & ~CAML_BA_KIND_MASK) | CAML_BA_COMPLEX64;
+ /* Create bigarray with same data and new dimensions */
+ res = caml_ba_alloc(flags, num_dims, b->data, dim);
+ /* Create or update proxy in case of managed bigarray */
+ caml_ba_update_proxy(b, Caml_ba_array_val(res));
+ /* Return result */
+ CAMLreturn (res);
+}
+
+
/* Initialization */
CAMLprim value caml_ba_init(value unit)
|