Skip to content

Commit 166b2f6

Browse files
committed
Better naming Ndarray.apply
1 parent dbff017 commit 166b2f6

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

arrayjit/lib/cuda_backend.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ end) : Ir.Backend_impl.Lowered_backend = struct
178178
let from_host ~dst_ptr ~dst hosted =
179179
set_ctx @@ ctx_of dst;
180180
let f src = Cu.Stream.memcpy_H_to_D ~dst:dst_ptr ~src dst.stream.runner in
181-
Ndarray.map { f } hosted
181+
Ndarray.apply { f } hosted
182182

183183
let to_host ~src_ptr ~src hosted =
184184
set_ctx @@ ctx_of src;
185185
let f dst = Cu.Stream.memcpy_D_to_H ~dst ~src:src_ptr src.stream.runner in
186-
Ndarray.map { f } hosted
186+
Ndarray.apply { f } hosted
187187

188188
let device_to_device tn ~into_merge_buffer ~dst_ptr ~dst ~src_ptr ~src =
189189
let dev = dst.stream.device in

arrayjit/lib/ndarray.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ let get_prec = function
111111
| Single_nd _ -> Ops.single
112112
| Double_nd _ -> Ops.double
113113

114-
type 'r map_with_prec = {
114+
type 'r apply_with_prec = {
115115
f : 'ocaml 'elt_t. ('ocaml, 'elt_t) Ops.precision -> ('ocaml, 'elt_t) bigarray -> 'r;
116116
}
117117

118-
let map_with_prec { f } = function
118+
let apply_with_prec { f } = function
119119
| Byte_nd arr -> f Ops.Byte arr
120120
| Uint16_nd arr -> f Ops.Uint16 arr
121121
| Int32_nd arr -> f Ops.Int32 arr
@@ -163,9 +163,9 @@ let create_bigarray (type ocaml elt_t) (prec : (ocaml, elt_t) Ops.precision) ~di
163163

164164
(** {2 *** Accessing ***} *)
165165

166-
type 'r map_as_bigarray = { f : 'ocaml 'elt_t. ('ocaml, 'elt_t) bigarray -> 'r }
166+
type 'r apply_as_bigarray = { f : 'ocaml 'elt_t. ('ocaml, 'elt_t) bigarray -> 'r }
167167

168-
let map { f } = function
168+
let apply { f } = function
169169
| Byte_nd arr -> f arr
170170
| Uint16_nd arr -> f arr
171171
| Int32_nd arr -> f arr
@@ -176,11 +176,11 @@ let map { f } = function
176176
| Single_nd arr -> f arr
177177
| Double_nd arr -> f arr
178178

179-
type 'r map2_as_bigarray = {
179+
type 'r apply2_as_bigarray = {
180180
f2 : 'ocaml 'elt_t. ('ocaml, 'elt_t) bigarray -> ('ocaml, 'elt_t) bigarray -> 'r;
181181
}
182182

183-
let map2 { f2 } x1 x2 =
183+
let apply2 { f2 } x1 x2 =
184184
match (x1, x2) with
185185
| Byte_nd arr1, Byte_nd arr2 -> f2 arr1 arr2
186186
| Uint16_nd arr1, Uint16_nd arr2 -> f2 arr1 arr2
@@ -191,15 +191,15 @@ let map2 { f2 } x1 x2 =
191191
| Fp8_nd arr1, Fp8_nd arr2 -> f2 arr1 arr2
192192
| Single_nd arr1, Single_nd arr2 -> f2 arr1 arr2
193193
| Double_nd arr1, Double_nd arr2 -> f2 arr1 arr2
194-
| _ -> invalid_arg "Ndarray.map2: precision mismatch"
194+
| _ -> invalid_arg "Ndarray.apply2: precision mismatch"
195195

196-
let dims = map { f = A.dims }
196+
let dims = apply { f = A.dims }
197197

198198
let get_fatptr_not_managed nd =
199199
let f arr =
200200
Ctypes_memory.make_unmanaged ~reftyp:Ctypes_static.void @@ bigarray_start_not_managed arr
201201
in
202-
map { f } nd
202+
apply { f } nd
203203

204204
let get_voidptr_not_managed nd : unit Ctypes.ptr =
205205
Ctypes_static.CPointer (get_fatptr_not_managed nd)
@@ -278,7 +278,7 @@ let size_in_bytes v =
278278
(* Cheating here because 1 number Bigarray is same size as empty Bigarray: it's more informative
279279
to report the cases differently. *)
280280
let f arr = if Array.is_empty @@ A.dims arr then 0 else A.size_in_bytes arr in
281-
map { f } v
281+
apply { f } v
282282

283283
let get_as_float arr idx =
284284
match arr with
@@ -371,14 +371,14 @@ let set_flat_values _arr _values = ()
371371
let c_ptr_to_string nd =
372372
let prec = get_prec nd in
373373
let f arr = Ops.c_rawptr_to_string (bigarray_start_not_managed arr) prec in
374-
map { f } nd
374+
apply { f } nd
375375

376376
let ptr_to_string_hum nd =
377377
let prec = get_prec nd in
378378
let f arr = Ops.rawptr_to_string_hum (bigarray_start_not_managed arr) prec in
379-
map { f } nd
379+
apply { f } nd
380380

381-
let to_native = map { f = bigarray_start_not_managed }
381+
let to_native = apply { f = bigarray_start_not_managed }
382382
let equal a1 a2 = equal_nativeint (to_native a1) (to_native a2)
383383
let compare a1 a2 = compare_nativeint (to_native a1) (to_native a2)
384384
let hash nd = Nativeint.hash (to_native nd)
@@ -393,7 +393,7 @@ external copy_with_padding_c : ('a, 'b) bigarray -> ('a, 'b) bigarray -> axis_pa
393393
requires that source dimensions + padding = target dimensions. *)
394394
let copy_with_padding ~source ~target ~padding =
395395
let copy_impl source_arr target_arr = copy_with_padding_c source_arr target_arr padding in
396-
map2 { f2 = copy_impl } source target
396+
apply2 { f2 = copy_impl } source target
397397

398398
(** {2 *** Creating ***} *)
399399

@@ -422,7 +422,7 @@ let%track7_sexp create_array ~debug:(_debug : string) (prec : Ops.prec) ~(dims :
422422
(** See {!Bigarray.reshape}. *)
423423
let reshape nd dims =
424424
let f prec arr = as_array prec @@ Bigarray.reshape arr dims in
425-
map_with_prec { f } nd
425+
apply_with_prec { f } nd
426426

427427
let get_used_memory () = Atomic.get used_memory
428428

arrayjit/lib/tnode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ let create_with_reshape ~id ~label ~base_ndarray ~dims ~padding ~from_padded ()
633633
elements"];
634634
Nd.as_array prec (Bigarray.reshape arr target_dims)
635635
in
636-
Some (Nd.map_with_prec { f = f_reshape_with_prec } base_ndarray)
636+
Some (Nd.apply_with_prec { f = f_reshape_with_prec } base_ndarray)
637637
| Some (padding, _), false ->
638638
(* Create new bigarray with padding and copy source into non-padding parts *)
639639
let target = Nd.create_array ~debug prec_val ~dims:target_dims ~padding:target_padding in

0 commit comments

Comments
 (0)