|
3 | 3 |
|
4 | 4 | mod cast; |
5 | 5 | mod compare; |
6 | | - |
7 | | -use std::sync::Arc; |
8 | | - |
9 | | -use vortex_dtype::ExtDType; |
10 | | -use vortex_error::VortexResult; |
11 | | -use vortex_mask::Mask; |
12 | | -use vortex_scalar::Scalar; |
13 | | - |
14 | | -use crate::arrays::ExtensionVTable; |
15 | | -use crate::arrays::extension::ExtensionArray; |
16 | | -use crate::compute::{ |
17 | | - FilterKernel, FilterKernelAdapter, IsConstantKernel, IsConstantKernelAdapter, IsConstantOpts, |
18 | | - IsSortedKernel, IsSortedKernelAdapter, MaskKernel, MaskKernelAdapter, MinMaxKernel, |
19 | | - MinMaxKernelAdapter, MinMaxResult, SumKernel, SumKernelAdapter, TakeKernel, TakeKernelAdapter, |
20 | | - filter, is_constant_opts, is_sorted, is_strict_sorted, mask, min_max, sum, take, |
21 | | -}; |
22 | | -use crate::{Array, ArrayRef, IntoArray, register_kernel}; |
23 | | - |
24 | | -impl FilterKernel for ExtensionVTable { |
25 | | - fn filter(&self, array: &ExtensionArray, mask: &Mask) -> VortexResult<ArrayRef> { |
26 | | - Ok( |
27 | | - ExtensionArray::new(array.ext_dtype().clone(), filter(array.storage(), mask)?) |
28 | | - .into_array(), |
29 | | - ) |
30 | | - } |
31 | | -} |
32 | | - |
33 | | -register_kernel!(FilterKernelAdapter(ExtensionVTable).lift()); |
34 | | - |
35 | | -impl MaskKernel for ExtensionVTable { |
36 | | - fn mask(&self, array: &ExtensionArray, mask_array: &Mask) -> VortexResult<ArrayRef> { |
37 | | - let masked_storage = mask(array.storage(), mask_array)?; |
38 | | - if masked_storage.dtype().nullability() == array.ext_dtype().storage_dtype().nullability() { |
39 | | - Ok(ExtensionArray::new(array.ext_dtype().clone(), masked_storage).into_array()) |
40 | | - } else { |
41 | | - // The storage dtype changed (i.e., became nullable due to masking) |
42 | | - let ext_dtype = Arc::new(ExtDType::new( |
43 | | - array.ext_dtype().id().clone(), |
44 | | - Arc::new(masked_storage.dtype().clone()), |
45 | | - array.ext_dtype().metadata().cloned(), |
46 | | - )); |
47 | | - Ok(ExtensionArray::new(ext_dtype, masked_storage).into_array()) |
48 | | - } |
49 | | - } |
50 | | -} |
51 | | - |
52 | | -register_kernel!(MaskKernelAdapter(ExtensionVTable).lift()); |
53 | | - |
54 | | -impl SumKernel for ExtensionVTable { |
55 | | - fn sum(&self, array: &ExtensionArray) -> VortexResult<Scalar> { |
56 | | - sum(array.storage()) |
57 | | - } |
58 | | -} |
59 | | - |
60 | | -register_kernel!(SumKernelAdapter(ExtensionVTable).lift()); |
61 | | - |
62 | | -impl TakeKernel for ExtensionVTable { |
63 | | - fn take(&self, array: &ExtensionArray, indices: &dyn Array) -> VortexResult<ArrayRef> { |
64 | | - let taken_storage = take(array.storage(), indices)?; |
65 | | - if taken_storage.dtype().nullability() == array.ext_dtype().storage_dtype().nullability() { |
66 | | - Ok(ExtensionArray::new(array.ext_dtype().clone(), taken_storage).into_array()) |
67 | | - } else { |
68 | | - // The storage dtype changed (i.e., became nullable due to nullable indices) |
69 | | - let ext_dtype = Arc::new(ExtDType::new( |
70 | | - array.ext_dtype().id().clone(), |
71 | | - Arc::new(taken_storage.dtype().clone()), |
72 | | - array.ext_dtype().metadata().cloned(), |
73 | | - )); |
74 | | - Ok(ExtensionArray::new(ext_dtype, taken_storage).into_array()) |
75 | | - } |
76 | | - } |
77 | | -} |
78 | | - |
79 | | -register_kernel!(TakeKernelAdapter(ExtensionVTable).lift()); |
80 | | - |
81 | | -impl MinMaxKernel for ExtensionVTable { |
82 | | - fn min_max(&self, array: &ExtensionArray) -> VortexResult<Option<MinMaxResult>> { |
83 | | - Ok( |
84 | | - min_max(array.storage())?.map(|MinMaxResult { min, max }| MinMaxResult { |
85 | | - min: Scalar::extension(array.ext_dtype().clone(), min), |
86 | | - max: Scalar::extension(array.ext_dtype().clone(), max), |
87 | | - }), |
88 | | - ) |
89 | | - } |
90 | | -} |
91 | | - |
92 | | -register_kernel!(MinMaxKernelAdapter(ExtensionVTable).lift()); |
93 | | - |
94 | | -impl IsConstantKernel for ExtensionVTable { |
95 | | - fn is_constant( |
96 | | - &self, |
97 | | - array: &ExtensionArray, |
98 | | - opts: &IsConstantOpts, |
99 | | - ) -> VortexResult<Option<bool>> { |
100 | | - is_constant_opts(array.storage(), opts) |
101 | | - } |
102 | | -} |
103 | | - |
104 | | -register_kernel!(IsConstantKernelAdapter(ExtensionVTable).lift()); |
105 | | - |
106 | | -impl IsSortedKernel for ExtensionVTable { |
107 | | - fn is_sorted(&self, array: &ExtensionArray) -> VortexResult<Option<bool>> { |
108 | | - is_sorted(array.storage()) |
109 | | - } |
110 | | - |
111 | | - fn is_strict_sorted(&self, array: &ExtensionArray) -> VortexResult<Option<bool>> { |
112 | | - is_strict_sorted(array.storage()) |
113 | | - } |
114 | | -} |
115 | | - |
116 | | -register_kernel!(IsSortedKernelAdapter(ExtensionVTable).lift()); |
| 6 | +mod filter; |
| 7 | +mod is_constant; |
| 8 | +mod is_sorted; |
| 9 | +mod mask; |
| 10 | +mod min_max; |
| 11 | +mod sum; |
| 12 | +mod take; |
117 | 13 |
|
118 | 14 | #[cfg(test)] |
119 | 15 | mod test { |
|
0 commit comments