@@ -39,6 +39,7 @@ use crate::builders::ArrayBuilder;
3939use crate :: builders:: PrimitiveBuilder ;
4040use crate :: dtype:: DType ;
4141use crate :: dtype:: NativePType ;
42+ use crate :: dtype:: PType ;
4243use crate :: match_each_native_ptype;
4344use crate :: serde:: ArrayChildren ;
4445use crate :: stats:: ArrayStats ;
@@ -64,6 +65,8 @@ impl ValidityChild<Patched> for Patched {
6465pub struct PatchedMetadata {
6566 #[ prost( uint32, tag = "1" ) ]
6667 pub ( crate ) offset : u32 ,
68+ #[ prost( uint32, tag = "2" ) ]
69+ pub ( crate ) n_patches : u32 ,
6770}
6871
6972impl VTable for Patched {
@@ -111,21 +114,19 @@ impl VTable for Patched {
111114 }
112115
113116 fn nbuffers ( _array : & Self :: Array ) -> usize {
114- 3
117+ 1
115118 }
116119
117120 fn buffer ( array : & Self :: Array , idx : usize ) -> BufferHandle {
118121 match idx {
119122 0 => array. lane_offsets . clone ( ) ,
120- 1 => array. indices . clone ( ) ,
121123 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
122124 }
123125 }
124126
125127 fn buffer_name ( _array : & Self :: Array , idx : usize ) -> Option < String > {
126128 match idx {
127129 0 => Some ( "lane_offsets" . to_string ( ) ) ,
128- 1 => Some ( "patch_indices" . to_string ( ) ) ,
129130 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
130131 }
131132 }
@@ -137,15 +138,17 @@ impl VTable for Patched {
137138 fn child ( array : & Self :: Array , idx : usize ) -> ArrayRef {
138139 match idx {
139140 0 => array. inner . clone ( ) ,
140- 1 => array. values . clone ( ) ,
141+ 1 => array. indices . clone ( ) ,
142+ 2 => array. values . clone ( ) ,
141143 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
142144 }
143145 }
144146
145147 fn child_name ( _array : & Self :: Array , idx : usize ) -> String {
146148 match idx {
147149 0 => "inner" . to_string ( ) ,
148- 1 => "patch_values" . to_string ( ) ,
150+ 1 => "patch_indices" . to_string ( ) ,
151+ 2 => "patch_values" . to_string ( ) ,
149152 _ => vortex_panic ! ( "invalid buffer index for PatchedArray: {idx}" ) ,
150153 }
151154 }
@@ -154,6 +157,7 @@ impl VTable for Patched {
154157 fn metadata ( array : & Self :: Array ) -> VortexResult < Self :: Metadata > {
155158 Ok ( ProstMetadata ( PatchedMetadata {
156159 offset : array. offset as u32 ,
160+ n_patches : array. indices . len ( ) as u32 ,
157161 } ) )
158162 }
159163
@@ -198,7 +202,7 @@ impl VTable for Patched {
198202 let offset = array. offset ;
199203 let lane_offsets: Buffer < u32 > =
200204 Buffer :: from_byte_buffer ( array. lane_offsets . clone ( ) . unwrap_host ( ) ) ;
201- let indices: Buffer < u16 > = Buffer :: from_byte_buffer ( array. indices . clone ( ) . unwrap_host ( ) ) ;
205+ let indices = array. indices . clone ( ) . execute :: < PrimitiveArray > ( ctx ) ? ;
202206 let values = array. values . clone ( ) . execute :: < PrimitiveArray > ( ctx) ?;
203207
204208 match_each_native_ptype ! ( ptype, |V | {
@@ -219,7 +223,7 @@ impl VTable for Patched {
219223 array. n_chunks,
220224 array. n_lanes,
221225 & lane_offsets,
222- & indices,
226+ indices. as_slice :: < u16 > ( ) ,
223227 values. as_slice:: <V >( ) ,
224228 ) ;
225229 } ) ;
@@ -234,19 +238,16 @@ impl VTable for Patched {
234238 buffers : & [ BufferHandle ] ,
235239 children : & dyn ArrayChildren ,
236240 ) -> VortexResult < PatchedArray > {
237- let inner = children. get ( 0 , dtype, len) ?;
238-
239241 let n_chunks = len. div_ceil ( 1024 ) ;
240-
241242 let n_lanes = match_each_native_ptype ! ( dtype. as_ptype( ) , |P | { patch_lanes:: <P >( ) } ) ;
242243
243- let & [ lane_offsets, indices ] = & buffers else {
244+ let & [ lane_offsets] = & buffers else {
244245 vortex_bail ! ( "invalid buffer count for PatchedArray" ) ;
245246 } ;
246247
247- // values and indices should have same len.
248- let expected_len = indices . as_host ( ) . reinterpret :: < u16 > ( ) . len ( ) ;
249- let values = children. get ( 1 , dtype, expected_len ) ?;
248+ let inner = children . get ( 0 , dtype , len) ? ;
249+ let indices = children . get ( 1 , PType :: U16 . into ( ) , metadata . n_patches as usize ) ? ;
250+ let values = children. get ( 1 , dtype, metadata . n_patches as usize ) ?;
250251
251252 Ok ( PatchedArray {
252253 inner,
@@ -255,7 +256,7 @@ impl VTable for Patched {
255256 offset : metadata. offset as usize ,
256257 len,
257258 lane_offsets : lane_offsets. clone ( ) ,
258- indices : indices . clone ( ) ,
259+ indices,
259260 values,
260261 stats_set : ArrayStats :: default ( ) ,
261262 } )
@@ -288,10 +289,10 @@ impl VTable for Patched {
288289
289290 let lane_offsets: Buffer < u32 > =
290291 Buffer :: from_byte_buffer ( array. lane_offsets . clone ( ) . unwrap_host ( ) ) ;
291- let indices: Buffer < u16 > = Buffer :: from_byte_buffer ( array. indices . clone ( ) . unwrap_host ( ) ) ;
292- let values = array. values . clone ( ) . execute :: < PrimitiveArray > ( ctx) ?;
292+ let indices = array. indices . clone ( ) . execute :: < PrimitiveArray > ( ctx) ?;
293293
294- // TODO(aduffy): add support for non-primitive PatchedArray patches application.
294+ // TODO(aduffy): add support for non-primitive PatchedArray patches application (?)
295+ let values = array. values . clone ( ) . execute :: < PrimitiveArray > ( ctx) ?;
295296
296297 let patched_values = match_each_native_ptype ! ( values. ptype( ) , |V | {
297298 let mut output = Buffer :: <V >:: from_byte_buffer( buffer. unwrap_host( ) ) . into_mut( ) ;
@@ -306,7 +307,7 @@ impl VTable for Patched {
306307 array. n_chunks,
307308 array. n_lanes,
308309 & lane_offsets,
309- & indices,
310+ indices. as_slice :: < u16 > ( ) ,
310311 values. as_slice:: <V >( ) ,
311312 ) ;
312313
0 commit comments