Skip to content

Commit

Permalink
Make set_array to work with all supported data types.
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
zoj613 committed Jul 5, 2024
1 parent 0441ad6 commit 3523e87
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/storage/storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,14 @@ module Make (M : STORE) : S with type t = M.t = struct
| Error _ ->
Ok (Ndarray.create repr.kind repr.shape repr.fill_value))
>>= fun arr ->
(* find_all returns bindings in reverse order. To restore the
* C-ordering of elements we must call List.rev. *)
let coords, vals =
List.split @@
List.rev @@
Arraytbl.find_all tbl idx in
let slice' = Indexing.slice_of_coords coords in
let shape' = Indexing.slice_shape slice' repr.shape in
let x' = Ndarray.of_array repr.kind (Array.of_list vals) shape' in
(* Ndarray.set_fancy* unfortunately doesn't work for array kinds
other than Float32, Float64, Complex32 and Complex64.
See: https://github.com/owlbarn/owl/issues/671 *)
Ndarray.set_fancy_ext slice' arr x'; (* possible to rewrite this function? *)
(* NOTE: Ndarray.set_fancy* functions unfortunately don't work for array
kinds other than Float32, Float64, Complex32 and Complex64.
See: https://github.com/owlbarn/owl/issues/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.*)
List.iter
(fun (c, v) -> Ndarray.set arr c v) @@ Arraytbl.find_all tbl idx;
Codecs.Chain.encode codecs arr >>| fun encoded ->
set t chunkkey encoded) cindices (Ok ())

Expand Down

0 comments on commit 3523e87

Please sign in to comment.