From a41b820d267ea8e1cc2bd7464f6b17c00728ee34 Mon Sep 17 00:00:00 2001 From: Runhang Li Date: Sat, 5 Sep 2015 09:12:28 -0700 Subject: [PATCH 1/6] Add byte_size and kind_byte_size to Bigarray --- otherlibs/bigarray/bigarray.ml | 31 ++++++++++++ otherlibs/bigarray/bigarray.mli | 15 ++++++ testsuite/tests/lib-bigarray/bigarrays.ml | 48 +++++++++++++++++++ .../tests/lib-bigarray/bigarrays.reference | 10 ++++ 4 files changed, 104 insertions(+) diff --git a/otherlibs/bigarray/bigarray.ml b/otherlibs/bigarray/bigarray.ml index 960c97241..be7f7f5ea 100644 --- a/otherlibs/bigarray/bigarray.ml +++ b/otherlibs/bigarray/bigarray.ml @@ -62,6 +62,21 @@ let complex32 = Complex32 let complex64 = Complex64 let char = Char +let kind_byte_size : type a b. (a, b) kind -> int = function + | Float32 -> 4 + | Float64 -> 8 + | Int8_signed -> 1 + | Int8_unsigned -> 1 + | Int16_signed -> 2 + | Int16_unsigned -> 2 + | Int32 -> 4 + | Int64 -> 8 + | Int -> Sys.word_size / 8 + | Nativeint -> Sys.word_size / 8 + | Complex32 -> 8 + | Complex64 -> 16 + | Char -> 1 + type c_layout = C_layout_typ type fortran_layout = Fortran_layout_typ @@ -90,9 +105,13 @@ module Genarray = struct let d = Array.make n 0 in for i = 0 to n-1 do d.(i) <- nth_dim a i done; d + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + let byte_size arr = + (kind_byte_size (kind arr)) * (Array.fold_left ( * ) 1 (dims arr)) + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "caml_ba_sub" external sub_right: ('a, 'b, fortran_layout) t -> int -> int -> @@ -126,6 +145,10 @@ module Array1 = struct external dim: ('a, 'b, 'c) t -> int = "%caml_ba_dim_1" external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + let byte_size arr = + (kind_byte_size (kind arr)) * (dim arr) + external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t = "caml_ba_sub" external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" @@ -156,6 +179,10 @@ module Array2 = struct external dim2: ('a, 'b, 'c) t -> int = "%caml_ba_dim_2" external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + let byte_size arr = + (kind_byte_size (kind arr)) * (dim1 arr) * (dim2 arr) + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "caml_ba_sub" external sub_right: @@ -203,6 +230,10 @@ module Array3 = struct external dim3: ('a, 'b, 'c) t -> int = "%caml_ba_dim_3" external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + let byte_size arr = + (kind_byte_size (kind arr)) * (dim1 arr) * (dim2 arr) * (dim3 arr) + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "caml_ba_sub" external sub_right: diff --git a/otherlibs/bigarray/bigarray.mli b/otherlibs/bigarray/bigarray.mli index a45c6799e..b3d01bad4 100644 --- a/otherlibs/bigarray/bigarray.mli +++ b/otherlibs/bigarray/bigarray.mli @@ -168,6 +168,9 @@ val char : (char, int8_unsigned_elt) kind characters instead of arrays of small integers, by using the kind value [char] instead of [int8_unsigned]. *) +val kind_byte_size : ('a, 'b) kind -> int +(** [kind_byte_size k] is the byte length of an element of kind [k]. *) + (** {6 Array layouts} *) type c_layout = C_layout_typ (**) @@ -280,6 +283,9 @@ module Genarray : external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) + val byte_size : ('a, 'b, 'c) t -> int + (** [byte_size a] is [a]'s byte length. *) + external get: ('a, 'b, 'c) t -> int array -> 'a = "caml_ba_get_generic" (** Read an element of a generic big array. [Genarray.get a [|i1; ...; iN|]] returns the element of [a] @@ -490,6 +496,9 @@ module Array1 : sig external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) + val byte_size : ('a, 'b, 'c) t -> int + (** [byte_size a] is [a]'s byte length. *) + external get: ('a, 'b, 'c) t -> int -> 'a = "%caml_ba_ref_1" (** [Array1.get a x], or alternatively [a.{x}], returns the element of [a] at index [x]. @@ -572,6 +581,9 @@ module Array2 : external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) + val byte_size : ('a, 'b, 'c) t -> int + (** [byte_size a] is [a]'s byte length. *) + external get: ('a, 'b, 'c) t -> int -> int -> 'a = "%caml_ba_ref_2" (** [Array2.get a x y], also written [a.{x,y}], returns the element of [a] at coordinates ([x], [y]). @@ -678,6 +690,9 @@ module Array3 : external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) + val byte_size : ('a, 'b, 'c) t -> int + (** [byte_size a] is [a]'s byte length. *) + external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "%caml_ba_ref_3" (** [Array3.get a x y z], also written [a.{x,y,z}], returns the element of [a] at coordinates ([x], [y], [z]). diff --git a/testsuite/tests/lib-bigarray/bigarrays.ml b/testsuite/tests/lib-bigarray/bigarrays.ml index 1f2b5ccbe..3ffd19636 100644 --- a/testsuite/tests/lib-bigarray/bigarrays.ml +++ b/testsuite/tests/lib-bigarray/bigarrays.ml @@ -411,6 +411,12 @@ let _ = test 1 (Array1.dim (from_list int [1;2;3;4;5])) 5; test 2 (Array1.dim (from_list_fortran int [1;2;3])) 3; + testing_function "byte_size"; + test 1 (Array1.byte_size (from_list int [1;2;3;4;5])) 40; + test 2 (Array1.byte_size (from_list int [])) 0; + test 3 (Array1.byte_size (from_list int64 (List.map Int64.of_int [1;2;3;4;5]))) 40; + test 4 (Array1.byte_size (from_list int64 (List.map Int64.of_int []))) 0; + testing_function "kind & layout"; let a = from_list int [1;2;3] in test 1 (Array1.kind a) int; @@ -595,6 +601,10 @@ let _ = test 3 (Array2.dim1 b) 4; test 4 (Array2.dim2 b) 6; + testing_function "byte_size"; + let a = Array2.create int c_layout 4 6 in + test 1 (Array2.byte_size a) 192; + testing_function "sub"; let a = make_array2 int c_layout 0 5 3 id in let b = Array2.sub_left a 2 2 in @@ -746,6 +756,10 @@ let _ = test 5 (Array3.dim2 b) 5; test 6 (Array3.dim3 b) 6; + testing_function "byte_size"; + let a = Array3.create int c_layout 4 5 6 in + test 1 (Array3.byte_size a) 960; + testing_function "slice1"; let a = make_array3 int c_layout 0 3 3 3 id in test 1 (Array3.slice_left_1 a 0 0) (from_list int [0;1;2]); @@ -757,6 +771,40 @@ let _ = test 6 (Array3.slice_right_1 a 1 2) (from_list_fortran int [112;212;312]); test 7 (Array3.slice_right_1 a 3 1) (from_list_fortran int [131;231;331]); +(* Genarray byte_size *) + testing_function "byte_size"; + let a = Genarray.create int c_layout [|2;2;2;2;2|] in + test 1 (Genarray.byte_size a) 256; + +(* Kind size *) + testing_function "kind_byte_size"; + let arr1 = Array1.create Float32 c_layout 1 in + test 1 (kind_byte_size Float32) (Array1.byte_size arr1); + let arr1 = Array1.create Float64 c_layout 1 in + test 2 (kind_byte_size Float64) (Array1.byte_size arr1); + let arr1 = Array1.create Int8_signed c_layout 1 in + test 3 (kind_byte_size Int8_signed) (Array1.byte_size arr1); + let arr1 = Array1.create Int8_unsigned c_layout 1 in + test 4 (kind_byte_size Int8_unsigned) (Array1.byte_size arr1); + let arr1 = Array1.create Int16_signed c_layout 1 in + test 5 (kind_byte_size Int16_signed) (Array1.byte_size arr1); + let arr1 = Array1.create Int16_unsigned c_layout 1 in + test 6 (kind_byte_size Int16_unsigned) (Array1.byte_size arr1); + let arr1 = Array1.create Int32 c_layout 1 in + test 7 (kind_byte_size Int32) (Array1.byte_size arr1); + let arr1 = Array1.create Int64 c_layout 1 in + test 8 (kind_byte_size Int64) (Array1.byte_size arr1); + let arr1 = Array1.create Int c_layout 1 in + test 9 (kind_byte_size Int) (Array1.byte_size arr1); + let arr1 = Array1.create Nativeint c_layout 1 in + test 10 (kind_byte_size Nativeint) (Array1.byte_size arr1); + let arr1 = Array1.create Complex32 c_layout 1 in + test 11 (kind_byte_size Complex32) (Array1.byte_size arr1); + let arr1 = Array1.create Complex64 c_layout 1 in + test 12 (kind_byte_size Complex64) (Array1.byte_size arr1); + let arr1 = Array1.create Char c_layout 1 in + test 13 (kind_byte_size Char) (Array1.byte_size arr1); + (* Reshaping *) print_newline(); testing_function "------ Reshaping --------"; diff --git a/testsuite/tests/lib-bigarray/bigarrays.reference b/testsuite/tests/lib-bigarray/bigarrays.reference index af05f4ca5..66c67cfff 100644 --- a/testsuite/tests/lib-bigarray/bigarrays.reference +++ b/testsuite/tests/lib-bigarray/bigarrays.reference @@ -11,6 +11,8 @@ comparisons 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... 21... 22... 23... 24... 25... 26... 27... 28... 29... 30... 31... 32... 44... 45... 46... 47... 48... 49... dim 1... 2... +byte_size + 1... 2... 3... 4... kind & layout 1... 2... 1... 2... sub @@ -28,6 +30,8 @@ set/get (unsafe, specialized) 1... 2... dim 1... 2... 3... 4... +byte_size + 1... sub 1... 2... slice @@ -43,8 +47,14 @@ set/get (unsafe, specialized) 1... dim 1... 2... 3... 4... 5... 6... +byte_size + 1... slice1 1... 2... 3... 4... 5... 6... 7... +byte_size + 1... +kind_byte_size + 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... ------ Reshaping -------- From aacf9f6c4604951b39e114d9ddfc7c37dd583ac7 Mon Sep 17 00:00:00 2001 From: Runhang Li Date: Wed, 14 Oct 2015 08:18:56 -0700 Subject: [PATCH 2/6] Update changelog --- Changes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changes b/Changes index 1f931b942..0865a0193 100644 --- a/Changes +++ b/Changes @@ -285,6 +285,8 @@ Other libraries: Before, a handled signal could cause Unix.sleep to return early. Now, the sleep is restarted until the given time is elapsed. (Xavier Leroy) +- PR#6263: add kind_byte_size and byte_size functions to Bigarray module. + (Runhang Li) - PR#6289: Unix.utimes uses the current time only if both arguments are exactly 0.0. Also, use sub-second resolution if available. (Xavier Leroy, report by Christophe Troestler) From 829dea35a4ac328efac74e070d4ed543e11aabcc Mon Sep 17 00:00:00 2001 From: Runhang Li Date: Thu, 19 Nov 2015 18:18:09 -0800 Subject: [PATCH 3/6] Change function names, improve documentation. Change ``byte_size'' to ``size_in_bytes``, change ``kind_byte_size`` to ``kind_size_in_bytes``. Add detailed comment indicating size functions do not consider header of OCaml value. --- otherlibs/bigarray/bigarray.ml | 18 +++---- otherlibs/bigarray/bigarray.mli | 25 +++++---- testsuite/tests/lib-bigarray/bigarrays.ml | 51 +++++++++---------- .../tests/lib-bigarray/bigarrays.reference | 10 ++-- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/otherlibs/bigarray/bigarray.ml b/otherlibs/bigarray/bigarray.ml index be7f7f5ea..039e09c31 100644 --- a/otherlibs/bigarray/bigarray.ml +++ b/otherlibs/bigarray/bigarray.ml @@ -62,7 +62,7 @@ let complex32 = Complex32 let complex64 = Complex64 let char = Char -let kind_byte_size : type a b. (a, b) kind -> int = function +let kind_size_in_bytes : type a b. (a, b) kind -> int = function | Float32 -> 4 | Float64 -> 8 | Int8_signed -> 1 @@ -109,8 +109,8 @@ module Genarray = struct external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" - let byte_size arr = - (kind_byte_size (kind arr)) * (Array.fold_left ( * ) 1 (dims arr)) + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (Array.fold_left ( * ) 1 (dims arr)) external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "caml_ba_sub" @@ -146,8 +146,8 @@ module Array1 = struct external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" - let byte_size arr = - (kind_byte_size (kind arr)) * (dim arr) + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (dim arr) external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t = "caml_ba_sub" external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" @@ -180,8 +180,8 @@ module Array2 = struct external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" - let byte_size arr = - (kind_byte_size (kind arr)) * (dim1 arr) * (dim2 arr) + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (dim1 arr) * (dim2 arr) external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "caml_ba_sub" @@ -231,8 +231,8 @@ module Array3 = struct external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" - let byte_size arr = - (kind_byte_size (kind arr)) * (dim1 arr) * (dim2 arr) * (dim3 arr) + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (dim1 arr) * (dim2 arr) * (dim3 arr) external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "caml_ba_sub" diff --git a/otherlibs/bigarray/bigarray.mli b/otherlibs/bigarray/bigarray.mli index b3d01bad4..751051827 100644 --- a/otherlibs/bigarray/bigarray.mli +++ b/otherlibs/bigarray/bigarray.mli @@ -168,8 +168,9 @@ val char : (char, int8_unsigned_elt) kind characters instead of arrays of small integers, by using the kind value [char] instead of [int8_unsigned]. *) -val kind_byte_size : ('a, 'b) kind -> int -(** [kind_byte_size k] is the byte length of an element of kind [k]. *) +val kind_size_in_bytes : ('a, 'b) kind -> int +(** [kind_size_in_bytes k] is the number of bytes used to store + an element of type [k]. *) (** {6 Array layouts} *) @@ -283,8 +284,9 @@ module Genarray : external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) - val byte_size : ('a, 'b, 'c) t -> int - (** [byte_size a] is [a]'s byte length. *) + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is the number of elements in [a] multiplied + by [a]'s {!kind_size_in_bytes}.*) external get: ('a, 'b, 'c) t -> int array -> 'a = "caml_ba_get_generic" (** Read an element of a generic big array. @@ -496,8 +498,9 @@ module Array1 : sig external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) - val byte_size : ('a, 'b, 'c) t -> int - (** [byte_size a] is [a]'s byte length. *) + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is the number of elements in [a] + multiplied by [a]'s {!kind_size_in_bytes}. *) external get: ('a, 'b, 'c) t -> int -> 'a = "%caml_ba_ref_1" (** [Array1.get a x], or alternatively [a.{x}], @@ -581,8 +584,9 @@ module Array2 : external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) - val byte_size : ('a, 'b, 'c) t -> int - (** [byte_size a] is [a]'s byte length. *) + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [[size_in_bytes a] is the number of elements in [a] + multiplied by [a]'s {!kind_size_in_bytes}. *) external get: ('a, 'b, 'c) t -> int -> int -> 'a = "%caml_ba_ref_2" (** [Array2.get a x y], also written [a.{x,y}], @@ -690,8 +694,9 @@ module Array3 : external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" (** Return the layout of the given big array. *) - val byte_size : ('a, 'b, 'c) t -> int - (** [byte_size a] is [a]'s byte length. *) + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is the number of elements in [a] + multiplied by [a]'s {!kind_size_in_bytes}. *) external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "%caml_ba_ref_3" (** [Array3.get a x y z], also written [a.{x,y,z}], diff --git a/testsuite/tests/lib-bigarray/bigarrays.ml b/testsuite/tests/lib-bigarray/bigarrays.ml index 3ffd19636..04e5b5bda 100644 --- a/testsuite/tests/lib-bigarray/bigarrays.ml +++ b/testsuite/tests/lib-bigarray/bigarrays.ml @@ -411,11 +411,11 @@ let _ = test 1 (Array1.dim (from_list int [1;2;3;4;5])) 5; test 2 (Array1.dim (from_list_fortran int [1;2;3])) 3; - testing_function "byte_size"; - test 1 (Array1.byte_size (from_list int [1;2;3;4;5])) 40; - test 2 (Array1.byte_size (from_list int [])) 0; - test 3 (Array1.byte_size (from_list int64 (List.map Int64.of_int [1;2;3;4;5]))) 40; - test 4 (Array1.byte_size (from_list int64 (List.map Int64.of_int []))) 0; + testing_function "size_in_bytes_one"; + test 1 (Array1.size_in_bytes (from_list int [1;2;3;4;5])) 40; + test 2 (Array1.size_in_bytes (from_list int [])) 0; + test 3 (Array1.size_in_bytes (from_list int64 (List.map Int64.of_int [1;2;3;4;5]))) 40; + test 4 (Array1.size_in_bytes (from_list int64 (List.map Int64.of_int []))) 0; testing_function "kind & layout"; let a = from_list int [1;2;3] in @@ -601,9 +601,9 @@ let _ = test 3 (Array2.dim1 b) 4; test 4 (Array2.dim2 b) 6; - testing_function "byte_size"; + testing_function "size_in_bytes_two"; let a = Array2.create int c_layout 4 6 in - test 1 (Array2.byte_size a) 192; + test 1 (Array2.size_in_bytes a) 192; testing_function "sub"; let a = make_array2 int c_layout 0 5 3 id in @@ -756,9 +756,9 @@ let _ = test 5 (Array3.dim2 b) 5; test 6 (Array3.dim3 b) 6; - testing_function "byte_size"; + testing_function "size_in_bytes_three"; let a = Array3.create int c_layout 4 5 6 in - test 1 (Array3.byte_size a) 960; + test 1 (Array3.size_in_bytes a) 960; testing_function "slice1"; let a = make_array3 int c_layout 0 3 3 3 id in @@ -771,39 +771,38 @@ let _ = test 6 (Array3.slice_right_1 a 1 2) (from_list_fortran int [112;212;312]); test 7 (Array3.slice_right_1 a 3 1) (from_list_fortran int [131;231;331]); -(* Genarray byte_size *) - testing_function "byte_size"; + testing_function "size_in_bytes_general"; let a = Genarray.create int c_layout [|2;2;2;2;2|] in - test 1 (Genarray.byte_size a) 256; + test 1 (Genarray.size_in_bytes a) 256; (* Kind size *) - testing_function "kind_byte_size"; + testing_function "kind_size_in_bytes"; let arr1 = Array1.create Float32 c_layout 1 in - test 1 (kind_byte_size Float32) (Array1.byte_size arr1); + test 1 (kind_size_in_bytes Float32) (Array1.size_in_bytes arr1); let arr1 = Array1.create Float64 c_layout 1 in - test 2 (kind_byte_size Float64) (Array1.byte_size arr1); + test 2 (kind_size_in_bytes Float64) (Array1.size_in_bytes arr1); let arr1 = Array1.create Int8_signed c_layout 1 in - test 3 (kind_byte_size Int8_signed) (Array1.byte_size arr1); + test 3 (kind_size_in_bytes Int8_signed) (Array1.size_in_bytes arr1); let arr1 = Array1.create Int8_unsigned c_layout 1 in - test 4 (kind_byte_size Int8_unsigned) (Array1.byte_size arr1); + test 4 (kind_size_in_bytes Int8_unsigned) (Array1.size_in_bytes arr1); let arr1 = Array1.create Int16_signed c_layout 1 in - test 5 (kind_byte_size Int16_signed) (Array1.byte_size arr1); + test 5 (kind_size_in_bytes Int16_signed) (Array1.size_in_bytes arr1); let arr1 = Array1.create Int16_unsigned c_layout 1 in - test 6 (kind_byte_size Int16_unsigned) (Array1.byte_size arr1); + test 6 (kind_size_in_bytes Int16_unsigned) (Array1.size_in_bytes arr1); let arr1 = Array1.create Int32 c_layout 1 in - test 7 (kind_byte_size Int32) (Array1.byte_size arr1); + test 7 (kind_size_in_bytes Int32) (Array1.size_in_bytes arr1); let arr1 = Array1.create Int64 c_layout 1 in - test 8 (kind_byte_size Int64) (Array1.byte_size arr1); + test 8 (kind_size_in_bytes Int64) (Array1.size_in_bytes arr1); let arr1 = Array1.create Int c_layout 1 in - test 9 (kind_byte_size Int) (Array1.byte_size arr1); + test 9 (kind_size_in_bytes Int) (Array1.size_in_bytes arr1); let arr1 = Array1.create Nativeint c_layout 1 in - test 10 (kind_byte_size Nativeint) (Array1.byte_size arr1); + test 10 (kind_size_in_bytes Nativeint) (Array1.size_in_bytes arr1); let arr1 = Array1.create Complex32 c_layout 1 in - test 11 (kind_byte_size Complex32) (Array1.byte_size arr1); + test 11 (kind_size_in_bytes Complex32) (Array1.size_in_bytes arr1); let arr1 = Array1.create Complex64 c_layout 1 in - test 12 (kind_byte_size Complex64) (Array1.byte_size arr1); + test 12 (kind_size_in_bytes Complex64) (Array1.size_in_bytes arr1); let arr1 = Array1.create Char c_layout 1 in - test 13 (kind_byte_size Char) (Array1.byte_size arr1); + test 13 (kind_size_in_bytes Char) (Array1.size_in_bytes arr1); (* Reshaping *) print_newline(); diff --git a/testsuite/tests/lib-bigarray/bigarrays.reference b/testsuite/tests/lib-bigarray/bigarrays.reference index 66c67cfff..40ab1ec49 100644 --- a/testsuite/tests/lib-bigarray/bigarrays.reference +++ b/testsuite/tests/lib-bigarray/bigarrays.reference @@ -11,7 +11,7 @@ comparisons 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... 21... 22... 23... 24... 25... 26... 27... 28... 29... 30... 31... 32... 44... 45... 46... 47... 48... 49... dim 1... 2... -byte_size +size_in_bytes_one 1... 2... 3... 4... kind & layout 1... 2... 1... 2... @@ -30,7 +30,7 @@ set/get (unsafe, specialized) 1... 2... dim 1... 2... 3... 4... -byte_size +size_in_bytes_two 1... sub 1... 2... @@ -47,13 +47,13 @@ set/get (unsafe, specialized) 1... dim 1... 2... 3... 4... 5... 6... -byte_size +size_in_bytes_three 1... slice1 1... 2... 3... 4... 5... 6... 7... -byte_size +size_in_bytes_general 1... -kind_byte_size +kind_size_in_bytes 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... ------ Reshaping -------- From a62ab0e163af88ab316c3e10aa2cb1133d9b2df7 Mon Sep 17 00:00:00 2001 From: Runhang Li Date: Thu, 19 Nov 2015 18:27:38 -0800 Subject: [PATCH 4/6] Update Changelog --- Changes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 0865a0193..5ee74b89a 100644 --- a/Changes +++ b/Changes @@ -285,7 +285,8 @@ Other libraries: Before, a handled signal could cause Unix.sleep to return early. Now, the sleep is restarted until the given time is elapsed. (Xavier Leroy) -- PR#6263: add kind_byte_size and byte_size functions to Bigarray module. +- PR#6263: add kind_size_in_bytes and size_in_bytes functions + to Bigarray module. (Runhang Li) - PR#6289: Unix.utimes uses the current time only if both arguments are exactly 0.0. Also, use sub-second resolution if available. From 0544aac0af61325c6bdd4e2917ed7fd1acda9cc9 Mon Sep 17 00:00:00 2001 From: Runhang Li Date: Sun, 22 Nov 2015 10:10:59 -0800 Subject: [PATCH 5/6] Add Shinwell as reviewer --- Changes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changes b/Changes index 5ee74b89a..cde16fcac 100644 --- a/Changes +++ b/Changes @@ -287,7 +287,7 @@ Other libraries: (Xavier Leroy) - PR#6263: add kind_size_in_bytes and size_in_bytes functions to Bigarray module. - (Runhang Li) + (Runhang Li, review by Mark Shinwell) - PR#6289: Unix.utimes uses the current time only if both arguments are exactly 0.0. Also, use sub-second resolution if available. (Xavier Leroy, report by Christophe Troestler) From 2ef65ed2aa6cb51b4b4f7506cd72f8ae77bb9514 Mon Sep 17 00:00:00 2001 From: Runhang Li Date: Tue, 24 Nov 2015 10:06:57 -0800 Subject: [PATCH 6/6] Fix test Several tests will fail on 32-bit machine. --- testsuite/tests/lib-bigarray/bigarrays.ml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/testsuite/tests/lib-bigarray/bigarrays.ml b/testsuite/tests/lib-bigarray/bigarrays.ml index 04e5b5bda..c37571ff3 100644 --- a/testsuite/tests/lib-bigarray/bigarrays.ml +++ b/testsuite/tests/lib-bigarray/bigarrays.ml @@ -412,9 +412,11 @@ let _ = test 2 (Array1.dim (from_list_fortran int [1;2;3])) 3; testing_function "size_in_bytes_one"; - test 1 (Array1.size_in_bytes (from_list int [1;2;3;4;5])) 40; + test 1 (Array1.size_in_bytes (from_list int [1;2;3;4;5])) + (5 * (kind_size_in_bytes int)); test 2 (Array1.size_in_bytes (from_list int [])) 0; - test 3 (Array1.size_in_bytes (from_list int64 (List.map Int64.of_int [1;2;3;4;5]))) 40; + let int64list = (from_list int64 (List.map Int64.of_int [1;2;3;4;5])) in + test 3 (Array1.size_in_bytes int64list) (5 * (kind_size_in_bytes int64)); test 4 (Array1.size_in_bytes (from_list int64 (List.map Int64.of_int []))) 0; testing_function "kind & layout"; @@ -603,7 +605,7 @@ let _ = testing_function "size_in_bytes_two"; let a = Array2.create int c_layout 4 6 in - test 1 (Array2.size_in_bytes a) 192; + test 1 (Array2.size_in_bytes a) (24 * (kind_size_in_bytes int)); testing_function "sub"; let a = make_array2 int c_layout 0 5 3 id in @@ -758,7 +760,7 @@ let _ = testing_function "size_in_bytes_three"; let a = Array3.create int c_layout 4 5 6 in - test 1 (Array3.size_in_bytes a) 960; + test 1 (Array3.size_in_bytes a) (120 * (kind_size_in_bytes int)); testing_function "slice1"; let a = make_array3 int c_layout 0 3 3 3 id in @@ -773,7 +775,7 @@ let _ = testing_function "size_in_bytes_general"; let a = Genarray.create int c_layout [|2;2;2;2;2|] in - test 1 (Genarray.size_in_bytes a) 256; + test 1 (Genarray.size_in_bytes a) (32 * (kind_size_in_bytes int)); (* Kind size *) testing_function "kind_size_in_bytes";