@@ -5,19 +5,17 @@ mod compare;
55mod filter;
66mod invert;
77mod search_sorted;
8+ mod sum;
89mod take;
910
10- use num_traits:: { CheckedMul , ToPrimitive } ;
11- use vortex_dtype:: { NativePType , PType , match_each_native_ptype} ;
12- use vortex_error:: { VortexExpect , VortexResult , vortex_err} ;
13- use vortex_scalar:: { FromPrimitiveOrF16 , PrimitiveScalar , Scalar } ;
11+ use vortex_error:: VortexResult ;
12+ use vortex_scalar:: Scalar ;
1413
1514use crate :: arrays:: ConstantEncoding ;
1615use crate :: arrays:: constant:: ConstantArray ;
1716use crate :: compute:: {
18- CastFn , InvertFn , ScalarAtFn , SearchSortedFn , SliceFn , SumFn , TakeFn , UncompressedSizeFn ,
17+ CastFn , InvertFn , ScalarAtFn , SearchSortedFn , SliceFn , TakeFn , UncompressedSizeFn ,
1918} ;
20- use crate :: stats:: Stat ;
2119use crate :: vtable:: ComputeVTable ;
2220use crate :: { Array , ArrayRef } ;
2321
@@ -42,10 +40,6 @@ impl ComputeVTable for ConstantEncoding {
4240 Some ( self )
4341 }
4442
45- fn sum_fn ( & self ) -> Option < & dyn SumFn < & dyn Array > > {
46- Some ( self )
47- }
48-
4943 fn take_fn ( & self ) -> Option < & dyn TakeFn < & dyn Array > > {
5044 Some ( self )
5145 }
@@ -79,51 +73,6 @@ impl UncompressedSizeFn<&ConstantArray> for ConstantEncoding {
7973 }
8074}
8175
82- impl SumFn < & ConstantArray > for ConstantEncoding {
83- fn sum ( & self , array : & ConstantArray ) -> VortexResult < Scalar > {
84- let sum_dtype = Stat :: Sum
85- . dtype ( array. dtype ( ) )
86- . ok_or_else ( || vortex_err ! ( "Sum not supported for dtype {}" , array. dtype( ) ) ) ?;
87- let sum_ptype = PType :: try_from ( & sum_dtype) . vortex_expect ( "sum dtype must be primitive" ) ;
88-
89- let scalar = array. scalar ( ) ;
90-
91- let scalar_value = match_each_native_ptype ! (
92- sum_ptype,
93- unsigned: |$T | { sum_integral:: <u64 >( scalar. as_primitive( ) , array. len( ) ) ?. into( ) }
94- signed: |$T | { sum_integral:: <i64 >( scalar. as_primitive( ) , array. len( ) ) ?. into( ) }
95- floating: |$T | { sum_float( scalar. as_primitive( ) , array. len( ) ) ?. into( ) }
96- ) ;
97-
98- Ok ( Scalar :: new ( sum_dtype, scalar_value) )
99- }
100- }
101-
102- fn sum_integral < T > (
103- primitive_scalar : PrimitiveScalar < ' _ > ,
104- array_len : usize ,
105- ) -> VortexResult < Option < T > >
106- where
107- T : FromPrimitiveOrF16 + NativePType + CheckedMul ,
108- Scalar : From < Option < T > > ,
109- {
110- let v = primitive_scalar. as_ :: < T > ( ) ?;
111- let array_len =
112- T :: from ( array_len) . ok_or_else ( || vortex_err ! ( "array_len must fit the sum type" ) ) ?;
113- let sum = v. and_then ( |v| v. checked_mul ( & array_len) ) ;
114-
115- Ok ( sum)
116- }
117-
118- fn sum_float ( primitive_scalar : PrimitiveScalar < ' _ > , array_len : usize ) -> VortexResult < Option < f64 > > {
119- let v = primitive_scalar. as_ :: < f64 > ( ) ?;
120- let array_len = array_len
121- . to_f64 ( )
122- . ok_or_else ( || vortex_err ! ( "array_len must fit the sum type" ) ) ?;
123-
124- Ok ( v. map ( |v| v * array_len) )
125- }
126-
12776#[ cfg( test) ]
12877mod test {
12978 use vortex_dtype:: half:: f16;
0 commit comments