@@ -91,7 +91,6 @@ impl VTable for Patched {
9191
9292 fn array_hash < H : Hasher > ( array : & Self :: Array , state : & mut H , precision : Precision ) {
9393 array. inner . array_hash ( state, precision) ;
94- array. values_ptype . hash ( state) ;
9594 array. n_chunks . hash ( state) ;
9695 array. n_lanes . hash ( state) ;
9796 array. lane_offsets . array_hash ( state, precision) ;
@@ -102,7 +101,6 @@ impl VTable for Patched {
102101 fn array_eq ( array : & Self :: Array , other : & Self :: Array , precision : Precision ) -> bool {
103102 array. n_chunks == other. n_chunks
104103 && array. n_lanes == other. n_lanes
105- && array. values_ptype == other. values_ptype
106104 && array. inner . array_eq ( & other. inner , precision)
107105 && array. lane_offsets . array_eq ( & other. lane_offsets , precision)
108106 && array. indices . array_eq ( & other. indices , precision)
@@ -117,7 +115,6 @@ impl VTable for Patched {
117115 match idx {
118116 0 => array. lane_offsets . clone ( ) ,
119117 1 => array. indices . clone ( ) ,
120- 2 => array. values . clone ( ) ,
121118 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
122119 }
123120 }
@@ -126,28 +123,27 @@ impl VTable for Patched {
126123 match idx {
127124 0 => Some ( "lane_offsets" . to_string ( ) ) ,
128125 1 => Some ( "patch_indices" . to_string ( ) ) ,
129- 2 => Some ( "patch_values" . to_string ( ) ) ,
130126 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
131127 }
132128 }
133129
134130 fn nchildren ( _array : & Self :: Array ) -> usize {
135- 1
131+ 2
136132 }
137133
138134 fn child ( array : & Self :: Array , idx : usize ) -> ArrayRef {
139- if idx == 0 {
140- array. inner . clone ( )
141- } else {
142- vortex_panic ! ( "invalid child index for PatchedArray: {idx}" ) ;
135+ match idx {
136+ 0 => array. inner . clone ( ) ,
137+ 1 => array . values . clone ( ) ,
138+ _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
143139 }
144140 }
145141
146142 fn child_name ( _array : & Self :: Array , idx : usize ) -> String {
147- if idx == 0 {
148- "inner" . to_string ( )
149- } else {
150- vortex_panic ! ( "invalid child index for PatchedArray: {idx}" ) ;
143+ match idx {
144+ 0 => "inner" . to_string ( ) ,
145+ 1 => "patch_values" . to_string ( ) ,
146+ _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
151147 }
152148 }
153149
@@ -186,10 +182,14 @@ impl VTable for Patched {
186182
187183 let n_lanes = match_each_native_ptype ! ( dtype. as_ptype( ) , |P | { patch_lanes:: <P >( ) } ) ;
188184
189- let & [ lane_offsets, indices, values ] = & buffers else {
185+ let & [ lane_offsets, indices] = & buffers else {
190186 vortex_bail ! ( "invalid buffer count for PatchedArray" ) ;
191187 } ;
192188
189+ // values and indices should have same len.
190+ let expected_len = indices. as_host ( ) . reinterpret :: < u16 > ( ) . len ( ) ;
191+ let values = children. get ( 1 , dtype, expected_len) ?;
192+
193193 Ok ( PatchedArray {
194194 inner,
195195 n_chunks,
@@ -198,19 +198,19 @@ impl VTable for Patched {
198198 len,
199199 lane_offsets : lane_offsets. clone ( ) ,
200200 indices : indices. clone ( ) ,
201- values : values. clone ( ) ,
202- values_ptype : dtype. as_ptype ( ) ,
201+ values,
203202 stats_set : ArrayStats :: default ( ) ,
204203 } )
205204 }
206205
207206 fn with_children ( array : & mut Self :: Array , mut children : Vec < ArrayRef > ) -> VortexResult < ( ) > {
208207 vortex_ensure ! (
209- children. len( ) == 1 ,
210- "PatchedArray must have exactly 1 child "
208+ children. len( ) == 2 ,
209+ "PatchedArray must have exactly 2 children "
211210 ) ;
212211
213212 array. inner = children. remove ( 0 ) ;
213+ array. values = children. remove ( 0 ) ;
214214
215215 Ok ( ( ) )
216216 }
@@ -231,23 +231,25 @@ impl VTable for Patched {
231231 let lane_offsets: Buffer < u32 > =
232232 Buffer :: from_byte_buffer ( array. lane_offsets . clone ( ) . unwrap_host ( ) ) ;
233233 let indices: Buffer < u16 > = Buffer :: from_byte_buffer ( array. indices . clone ( ) . unwrap_host ( ) ) ;
234+ let values = array. values . clone ( ) . execute :: < PrimitiveArray > ( ctx) ?;
235+
236+ // TODO(aduffy): add support for non-primitive PatchedArray patches application.
234237
235- let patched_values = match_each_native_ptype ! ( array . values_ptype , |V | {
238+ let patched_values = match_each_native_ptype ! ( values . ptype ( ) , |V | {
236239 let mut output = Buffer :: <V >:: from_byte_buffer( buffer. unwrap_host( ) ) . into_mut( ) ;
237- let values: Buffer <V > = Buffer :: from_byte_buffer( array. values. clone( ) . unwrap_host( ) ) ;
238240
239241 let offset = array. offset;
240242 let len = array. len;
241243
242- apply :: <V >(
244+ apply_patches_primitive :: <V >(
243245 & mut output,
244246 offset,
245247 len,
246248 array. n_chunks,
247249 array. n_lanes,
248250 & lane_offsets,
249251 & indices,
250- & values,
252+ values. as_slice :: < V > ( ) ,
251253 ) ;
252254
253255 // The output will always be aligned to a chunk boundary, we apply the offset/len
@@ -281,7 +283,7 @@ impl VTable for Patched {
281283
282284/// Apply patches on top of the existing value types.
283285#[ allow( clippy:: too_many_arguments) ]
284- fn apply < V : NativePType > (
286+ fn apply_patches_primitive < V : NativePType > (
285287 output : & mut [ V ] ,
286288 offset : usize ,
287289 len : usize ,
0 commit comments