Skip to content

Commit

Permalink
Sketch of kind values for bigarrays that expose the storage type.
Browse files Browse the repository at this point in the history
(Actually expose the ctypes equivalent of the storage type; for
example, for Bigarray.int16_unsigned_elt we expose uint16.)
  • Loading branch information
yallop committed Dec 5, 2013
1 parent a282c8b commit 0d15800
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 184 deletions.
73 changes: 50 additions & 23 deletions src/ctypes/bigarray_stubs.ml
Expand Up @@ -6,21 +6,48 @@
*)

type _ kind =
Kind_float32 : float kind
| Kind_float64 : float kind
| Kind_int8_signed : int kind
| Kind_int8_unsigned : int kind
| Kind_int16_signed : int kind
| Kind_int16_unsigned : int kind
| Kind_int32 : int32 kind
| Kind_int64 : int64 kind
| Kind_int : int kind
| Kind_nativeint : nativeint kind
| Kind_complex32 : Complex.t kind
| Kind_complex64 : Complex.t kind
| Kind_char : char kind

external kind : ('a, 'b) Bigarray.kind -> 'a kind
| Ba_float32 : < element: float;
ba_repr: Bigarray.float32_elt;
storage_type: float > kind
| Ba_float64 : < element: float;
ba_repr: Bigarray.float64_elt;
storage_type: float > kind
| Ba_int8_signed : < element: int;
ba_repr: Bigarray.int8_signed_elt;
storage_type: int > kind
| Ba_int8_unsigned : < element: int;
ba_repr: Bigarray.int8_unsigned_elt;
storage_type: Unsigned.uint8 > kind
| Ba_int16_signed : < element: int;
ba_repr: Bigarray.int16_signed_elt;
storage_type: int > kind
| Ba_int16_unsigned : < element: int;
ba_repr: Bigarray.int16_unsigned_elt;
storage_type: Unsigned.uint16 > kind
| Ba_int32 : < element: int32;
ba_repr: Bigarray.int32_elt;
storage_type: int32 > kind
| Ba_int64 : < element: int64;
ba_repr: Bigarray.int64_elt;
storage_type: int64 > kind
| Ba_int : < element: int;
ba_repr: Bigarray.int_elt;
storage_type: int > kind
| Ba_nativeint : < element: nativeint;
ba_repr: Bigarray.nativeint_elt;
storage_type: nativeint > kind
| Ba_complex32 : < element: Complex.t;
ba_repr: Bigarray.complex32_elt;
storage_type: Complex.t > kind
| Ba_complex64 : < element: Complex.t;
ba_repr: Bigarray.complex64_elt;
storage_type: Complex.t > kind
| Ba_char : < element: char;
ba_repr: Bigarray.int8_unsigned_elt;
storage_type: char > kind

external kind : ('a, 'b) Bigarray.kind ->
< element: 'a; ba_repr: 'b; storage_type: 'c > kind
(* Bigarray.kind is simply an int whose values are consecutively numbered
starting from zero, so we can directly transform its values to a variant
with appropriately-ordered constructors.
Expand All @@ -34,18 +61,18 @@ external kind : ('a, 'b) Bigarray.kind -> 'a kind
external address : 'b -> Ctypes_raw.voidp
= "ctypes_bigarray_address"

external view : 'a kind -> dims:int array -> Ctypes_raw.voidp -> offset:int ->
('a, 'b, Bigarray.c_layout) Bigarray.Genarray.t
external view : < element: 'a; .. > kind -> dims:int array ->
Ctypes_raw.voidp -> offset:int -> ('a, 'b, Bigarray.c_layout) Bigarray.Genarray.t
= "ctypes_bigarray_view"

external view1 : 'a kind -> dims:int array -> Ctypes_raw.voidp -> offset:int ->
('a, 'b, Bigarray.c_layout) Bigarray.Array1.t
external view1 : < element: 'a; .. > kind -> dims:int array ->
Ctypes_raw.voidp -> offset:int -> ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t
= "ctypes_bigarray_view"

external view2 : 'a kind -> dims:int array -> Ctypes_raw.voidp -> offset:int ->
('a, 'b, Bigarray.c_layout) Bigarray.Array2.t
external view2 : < element: 'a; .. > kind -> dims:int array ->
Ctypes_raw.voidp -> offset:int -> ('a, 'b, Bigarray.c_layout) Bigarray.Array2.t
= "ctypes_bigarray_view"

external view3 : 'a kind -> dims:int array -> Ctypes_raw.voidp -> offset:int ->
('a, 'b, Bigarray.c_layout) Bigarray.Array3.t
external view3 : < element: 'a; .. > kind -> dims:int array ->
Ctypes_raw.voidp -> offset:int -> ('a, 'b, Bigarray.c_layout) Bigarray.Array3.t
= "ctypes_bigarray_view"
99 changes: 85 additions & 14 deletions src/ctypes/ctypes.mli
Expand Up @@ -178,7 +178,7 @@ val string : string typ

val string_opt : string option typ
(** A high-level representation of the string type. This behaves like {!string},
except that null pointers appear in OCaml as [None].
except that null pointers appear in OCaml as [None].
*)

(** {3 Array types} *)
Expand Down Expand Up @@ -206,44 +206,105 @@ type _ bigarray_class
val genarray :
< element: 'a;
ba_repr: 'b;
storage_type: 'c;
bigarray: ('a, 'b, Bigarray.c_layout) Bigarray.Genarray.t;
carray: 'a array;
carray: 'c array;
dims: int std_array > bigarray_class
(** The class of {!Bigarray.Genarray.t} values *)

val array1 :
< element: 'a;
ba_repr: 'b;
storage_type: 'c;
bigarray: ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t;
carray: 'a array;
carray: 'c array;
dims: int > bigarray_class
(** The class of {!Bigarray.Array1.t} values *)

val array2 :
< element: 'a;
ba_repr: 'b;
storage_type: 'c;
bigarray: ('a, 'b, Bigarray.c_layout) Bigarray.Array2.t;
carray: 'a array array;
carray: 'c array array;
dims: int * int > bigarray_class
(** The class of {!Bigarray.Array2.t} values *)

val array3 :
< element: 'a;
ba_repr: 'b;
storage_type: 'c;
bigarray: ('a, 'b, Bigarray.c_layout) Bigarray.Array3.t;
carray: 'a array array array;
carray: 'c array array array;
dims: int * int * int > bigarray_class
(** The class of {!Bigarray.Array3.t} values *)

type _ bigarray_kind

val ba_float32 : < element: float;
ba_repr: Bigarray.float32_elt;
storage_type: float > bigarray_kind

val ba_float64 : < element: float;
ba_repr: Bigarray.float64_elt;
storage_type: float > bigarray_kind

val ba_complex32 : < element: Complex.t;
ba_repr: Bigarray.complex32_elt;
storage_type: Complex.t > bigarray_kind

val ba_complex64 : < element: Complex.t;
ba_repr: Bigarray.complex64_elt;
storage_type: Complex.t > bigarray_kind

val ba_int8_signed : < element: int;
ba_repr: Bigarray.int8_signed_elt;
storage_type: int > bigarray_kind

val ba_int8_unsigned : < element: int;
ba_repr: Bigarray.int8_unsigned_elt;
storage_type: uint8 > bigarray_kind

val ba_int16_signed : < element: int;
ba_repr: Bigarray.int16_signed_elt;
storage_type: int > bigarray_kind

val ba_int16_unsigned : < element: int;
ba_repr: Bigarray.int16_unsigned_elt;
storage_type: uint16 > bigarray_kind

val ba_int : < element: int;
ba_repr: Bigarray.int_elt;
storage_type: int > bigarray_kind

val ba_int32 : < element: int32;
ba_repr: Bigarray.int32_elt;
storage_type: int32 > bigarray_kind

val ba_int64 : < element: int64;
ba_repr: Bigarray.int64_elt;
storage_type: int64 > bigarray_kind

val ba_nativeint : < element: nativeint;
ba_repr: Bigarray.nativeint_elt;
storage_type: nativeint > bigarray_kind

val ba_char : < element: char;
ba_repr: Bigarray.int8_unsigned_elt;
storage_type: char > bigarray_kind

val bigarray :
< element: 'a;
ba_repr: 'b;
storage_type: 'c;
dims: 'dims;
bigarray: 'bigarray;
carray: _ > bigarray_class ->
'dims -> ('a, 'b) Bigarray.kind -> 'bigarray typ
'dims ->
< element: 'a; ba_repr: 'b; storage_type: 'c > bigarray_kind ->
'bigarray typ
(** Construct a sized bigarray type representation from a bigarray class, the
dimensions, and the {!Bigarray.kind}. *)
dimensions, and an element of {!bigarray_kind}. *)

(** {3 Function types} *)

Expand Down Expand Up @@ -526,33 +587,43 @@ end
(** {4 Bigarray values} *)

val bigarray_start : < element: 'a;
ba_repr: _;
ba_repr: 'r;
storage_type: 'c;
bigarray: 'b;
carray: _;
dims: _ > bigarray_class -> 'b -> 'a ptr
dims: _ > bigarray_class ->
< element: 'a;
ba_repr: 'r;
storage_type: 'c > bigarray_kind -> 'b -> 'c ptr
(** Return the address of the first element of the given Bigarray value. *)

val bigarray_of_ptr : < element: 'a;
ba_repr: 'f;
storage_type: 'c;
bigarray: 'b;
carray: _;
dims: 'i > bigarray_class ->
'i -> ('a, 'f) Bigarray.kind -> 'a ptr -> 'b
'i -> < element: 'a; ba_repr: 'f; storage_type: 'c > bigarray_kind -> 'c ptr -> 'b
(** Convert a C pointer to a bigarray value. *)

val array_of_bigarray : < element: _;
ba_repr: _;
val array_of_bigarray : < element: 'e;
ba_repr: 'r;
storage_type: 's;
bigarray: 'b;
carray: 'c;
dims: _ > bigarray_class -> 'b -> 'c
dims: _ > bigarray_class ->
< element: 'e;
ba_repr: 'r;
storage_type: 's > bigarray_kind -> 'b -> 'c
(** Convert a Bigarray value to a C array. *)

val bigarray_of_array : < element: 'a;
ba_repr: 'f;
storage_type: 's;
bigarray: 'b;
carray: 'c array;
dims: 'i > bigarray_class ->
('a, 'f) Bigarray.kind -> 'c array -> 'b
< element: 'a; ba_repr: 'f; storage_type: 's > bigarray_kind -> 'c array -> 'b
(** Convert a C array to a Bigarray value. *)


Expand Down

0 comments on commit 0d15800

Please sign in to comment.