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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
open Base
type t =
| Float of (float, Bigarray.float64_elt) Tensor.t
| Int64 of (int64, Bigarray.int64_elt) Tensor.t
let create_1_float f = Float (Tensor.create_1_float f)
let create_1_int64 i = Int64 (Tensor.create_1_int64 i)
let of_int64_array ?shape t =
let sh =
match shape with
| Some sh -> sh
| None -> Shape.of_array [| Array.length t |]
in
let a = Bigarray.Array1.of_array Bigarray.Int64 Bigarray.c_layout t in
Int64 (Tensor.of_array1 sh a)
let of_float_array ?shape t =
let sh =
match shape with
| Some sh -> sh
| None -> Shape.of_array [| Array.length t |]
in
let a = Bigarray.Array1.of_array Bigarray.Float64 Bigarray.c_layout t in
Float (Tensor.of_array1 sh a)
let shape = function Float f -> Tensor.shape f | Int64 i -> Tensor.shape i