Skip to content

Commit 44c1556

Browse files
committed
Make set_array to work with all supported data types.
`Ndarray.set_fancy*` functions unfortunately don't work for array kinds other than Float32, Float64, Complex32 and Complex64. See: owlbarn/owl#671 . As a workaround we manually set each coordinate one-at-time using the basic set function which does not suffer from this bug. It is likely much slower for large Zarr chunks but necessary for usability.
1 parent 0441ad6 commit 44c1556

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

Diff for: lib/storage/storage.ml

+8-13
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,14 @@ module Make (M : STORE) : S with type t = M.t = struct
175175
| Error _ ->
176176
Ok (Ndarray.create repr.kind repr.shape repr.fill_value))
177177
>>= fun arr ->
178-
(* find_all returns bindings in reverse order. To restore the
179-
* C-ordering of elements we must call List.rev. *)
180-
let coords, vals =
181-
List.split @@
182-
List.rev @@
183-
Arraytbl.find_all tbl idx in
184-
let slice' = Indexing.slice_of_coords coords in
185-
let shape' = Indexing.slice_shape slice' repr.shape in
186-
let x' = Ndarray.of_array repr.kind (Array.of_list vals) shape' in
187-
(* Ndarray.set_fancy* unfortunately doesn't work for array kinds
188-
other than Float32, Float64, Complex32 and Complex64.
189-
See: https://github.com/owlbarn/owl/issues/671 *)
190-
Ndarray.set_fancy_ext slice' arr x'; (* possible to rewrite this function? *)
178+
(* NOTE: Ndarray.set_fancy* functions unfortunately don't work for array
179+
kinds other than Float32, Float64, Complex32 and Complex64.
180+
See: https://github.com/owlbarn/owl/issues/671 . As a workaround
181+
we manually set each coordinate one-at-time using the basic
182+
set function which does not suffer from this bug. It is likely
183+
much slower for large Zarr chunks but necessary for usability.*)
184+
List.iter
185+
(fun (c, v) -> Ndarray.set arr c v) @@ Arraytbl.find_all tbl idx;
191186
Codecs.Chain.encode codecs arr >>| fun encoded ->
192187
set t chunkkey encoded) cindices (Ok ())
193188

0 commit comments

Comments
 (0)