@@ -86,7 +86,6 @@ impl VTable for Patched {
8686
8787 fn array_hash < H : Hasher > ( array : & Self :: Array , state : & mut H , precision : Precision ) {
8888 array. inner . array_hash ( state, precision) ;
89- array. values_ptype . hash ( state) ;
9089 array. n_chunks . hash ( state) ;
9190 array. n_lanes . hash ( state) ;
9291 array. lane_offsets . array_hash ( state, precision) ;
@@ -97,7 +96,6 @@ impl VTable for Patched {
9796 fn array_eq ( array : & Self :: Array , other : & Self :: Array , precision : Precision ) -> bool {
9897 array. n_chunks == other. n_chunks
9998 && array. n_lanes == other. n_lanes
100- && array. values_ptype == other. values_ptype
10199 && array. inner . array_eq ( & other. inner , precision)
102100 && array. lane_offsets . array_eq ( & other. lane_offsets , precision)
103101 && array. indices . array_eq ( & other. indices , precision)
@@ -112,7 +110,6 @@ impl VTable for Patched {
112110 match idx {
113111 0 => array. lane_offsets . clone ( ) ,
114112 1 => array. indices . clone ( ) ,
115- 2 => array. values . clone ( ) ,
116113 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
117114 }
118115 }
@@ -121,28 +118,27 @@ impl VTable for Patched {
121118 match idx {
122119 0 => Some ( "lane_offsets" . to_string ( ) ) ,
123120 1 => Some ( "patch_indices" . to_string ( ) ) ,
124- 2 => Some ( "patch_values" . to_string ( ) ) ,
125121 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
126122 }
127123 }
128124
129125 fn nchildren ( _array : & Self :: Array ) -> usize {
130- 1
126+ 2
131127 }
132128
133129 fn child ( array : & Self :: Array , idx : usize ) -> ArrayRef {
134- if idx == 0 {
135- array. inner . clone ( )
136- } else {
137- vortex_panic ! ( "invalid child index for PatchedArray: {idx}" ) ;
130+ match idx {
131+ 0 => array. inner . clone ( ) ,
132+ 1 => array . values . clone ( ) ,
133+ _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
138134 }
139135 }
140136
141137 fn child_name ( _array : & Self :: Array , idx : usize ) -> String {
142- if idx == 0 {
143- "inner" . to_string ( )
144- } else {
145- vortex_panic ! ( "invalid child index for PatchedArray: {idx}" ) ;
138+ match idx {
139+ 0 => "inner" . to_string ( ) ,
140+ 1 => "patch_values" . to_string ( ) ,
141+ _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
146142 }
147143 }
148144
@@ -181,10 +177,14 @@ impl VTable for Patched {
181177
182178 let n_lanes = match_each_native_ptype ! ( dtype. as_ptype( ) , |P | { patch_lanes:: <P >( ) } ) ;
183179
184- let & [ lane_offsets, indices, values ] = & buffers else {
180+ let & [ lane_offsets, indices] = & buffers else {
185181 vortex_bail ! ( "invalid buffer count for PatchedArray" ) ;
186182 } ;
187183
184+ // values and indices should have same len.
185+ let expected_len = indices. as_host ( ) . reinterpret :: < u16 > ( ) . len ( ) ;
186+ let values = children. get ( 1 , dtype, expected_len) ?;
187+
188188 Ok ( PatchedArray {
189189 inner,
190190 n_chunks,
@@ -193,19 +193,19 @@ impl VTable for Patched {
193193 len,
194194 lane_offsets : lane_offsets. clone ( ) ,
195195 indices : indices. clone ( ) ,
196- values : values. clone ( ) ,
197- values_ptype : dtype. as_ptype ( ) ,
196+ values,
198197 stats_set : ArrayStats :: default ( ) ,
199198 } )
200199 }
201200
202201 fn with_children ( array : & mut Self :: Array , mut children : Vec < ArrayRef > ) -> VortexResult < ( ) > {
203202 vortex_ensure ! (
204- children. len( ) == 1 ,
205- "PatchedArray must have exactly 1 child "
203+ children. len( ) == 2 ,
204+ "PatchedArray must have exactly 2 children "
206205 ) ;
207206
208207 array. inner = children. remove ( 0 ) ;
208+ array. values = children. remove ( 0 ) ;
209209
210210 Ok ( ( ) )
211211 }
@@ -226,23 +226,25 @@ impl VTable for Patched {
226226 let lane_offsets: Buffer < u32 > =
227227 Buffer :: from_byte_buffer ( array. lane_offsets . clone ( ) . unwrap_host ( ) ) ;
228228 let indices: Buffer < u16 > = Buffer :: from_byte_buffer ( array. indices . clone ( ) . unwrap_host ( ) ) ;
229+ let values = array. values . clone ( ) . execute :: < PrimitiveArray > ( ctx) ?;
230+
231+ // TODO(aduffy): add support for non-primitive PatchedArray patches application.
229232
230- let patched_values = match_each_native_ptype ! ( array . values_ptype , |V | {
233+ let patched_values = match_each_native_ptype ! ( values . ptype ( ) , |V | {
231234 let mut output = Buffer :: <V >:: from_byte_buffer( buffer. unwrap_host( ) ) . into_mut( ) ;
232- let values: Buffer <V > = Buffer :: from_byte_buffer( array. values. clone( ) . unwrap_host( ) ) ;
233235
234236 let offset = array. offset;
235237 let len = array. len;
236238
237- apply :: <V >(
239+ apply_patches_primitive :: <V >(
238240 & mut output,
239241 offset,
240242 len,
241243 array. n_chunks,
242244 array. n_lanes,
243245 & lane_offsets,
244246 & indices,
245- & values,
247+ values. as_slice :: < V > ( ) ,
246248 ) ;
247249
248250 // The output will always be aligned to a chunk boundary, we apply the offset/len
@@ -276,7 +278,7 @@ impl VTable for Patched {
276278
277279/// Apply patches on top of the existing value types.
278280#[ allow( clippy:: too_many_arguments) ]
279- fn apply < V : NativePType > (
281+ fn apply_patches_primitive < V : NativePType > (
280282 output : & mut [ V ] ,
281283 offset : usize ,
282284 len : usize ,
0 commit comments