@@ -5,15 +5,15 @@ use std::marker::PhantomData;
55
66use vortex_array:: pipeline:: bit_view:: BitView ;
77use vortex_array:: pipeline:: {
8- BindContext , Kernel , KernelCtx , PipelineInputs , PipelinedNode , VectorId , N ,
8+ BindContext , Kernel , KernelCtx , N , PipelineInputs , PipelinedNode , VectorId ,
99} ;
1010use vortex_array:: vtable:: OperatorVTable ;
1111use vortex_dtype:: PTypeDowncastExt ;
12- use vortex_error:: { vortex_bail , VortexResult } ;
12+ use vortex_error:: { VortexResult , vortex_bail } ;
1313use vortex_vector:: primitive:: PVectorMut ;
1414use vortex_vector:: { VectorMut , VectorMutOps } ;
1515
16- use crate :: { match_each_alp_float_ptype , ALPArray , ALPFloat , ALPVTable , Exponents } ;
16+ use crate :: { ALPArray , ALPFloat , ALPVTable , Exponents , match_each_alp_float_ptype } ;
1717
1818impl OperatorVTable < ALPVTable > for ALPVTable {
1919 fn pipeline_node ( array : & ALPArray ) -> Option < & dyn PipelinedNode > {
@@ -139,11 +139,14 @@ fn sparse_alp<A: ALPFloat>(
139139
140140#[ cfg( test) ]
141141mod test {
142+ use rand:: prelude:: StdRng ;
143+ use rand:: { Rng , SeedableRng } ;
144+ use vortex_array:: IntoArray ;
142145 use vortex_array:: arrays:: PrimitiveArray ;
143146 use vortex_array:: validity:: Validity ;
144- use vortex_array:: IntoArray ;
145- use vortex_buffer:: buffer;
147+ use vortex_buffer:: { Buffer , buffer, buffer_mut} ;
146148 use vortex_dtype:: PTypeDowncastExt ;
149+ use vortex_vector:: VectorOps ;
147150
148151 use crate :: alp_encode;
149152
@@ -161,4 +164,31 @@ mod test {
161164
162165 assert_eq ! ( decoded. elements( ) , & buffer) ;
163166 }
167+
168+ #[ test]
169+ fn test_alp_into_mut ( ) {
170+ let ( n, fraction_patch, fraction_valid) = ( 10_000 , 0.0 , 1.0 ) ;
171+ let mut rng = StdRng :: seed_from_u64 ( 0 ) ;
172+ let mut values = buffer_mut ! [ 1.234f32 ; n] ;
173+ if fraction_patch > 0.0 {
174+ for index in 0 ..values. len ( ) {
175+ if rng. random_bool ( fraction_patch) {
176+ values[ index] = 1000.0f32
177+ }
178+ }
179+ }
180+ let validity = if fraction_valid < 1.0 {
181+ Validity :: from_iter ( ( 0 ..values. len ( ) ) . map ( |_| rng. random_bool ( fraction_valid) ) )
182+ } else {
183+ Validity :: NonNullable
184+ } ;
185+ let values = values. freeze ( ) ;
186+
187+ // We take a copy of the values to ensure we can into_mut
188+ let array = PrimitiveArray :: new ( Buffer :: copy_from ( & values) , validity. clone ( ) ) ;
189+ let array = alp_encode ( & array, None ) . unwrap ( ) . into_array ( ) ;
190+
191+ let vector = array. execute ( ) . unwrap ( ) ;
192+ assert_eq ! ( vector. len( ) , values. len( ) ) ;
193+ }
164194}
0 commit comments