Skip to content

Commit 3e79554

Browse files
authored
Chore: reorganize compute function files in vortex-array (#4984)
Makes sure each compute function implementation has its own file. Note that this is a purely cosmetic change. Yes, this is verbose, but also it's better to be consistent (and it also helps with discoverability, for example "which compute functions exist for this array type?). Signed-off-by: Connor Tsui <[email protected]>
1 parent 4de2926 commit 3e79554

File tree

21 files changed

+364
-274
lines changed

21 files changed

+364
-274
lines changed

vortex-array/src/arrays/constant/compute/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ mod take;
1313

1414
#[cfg(test)]
1515
mod test {
16+
use rstest::rstest;
1617
use vortex_dtype::half::f16;
1718
use vortex_scalar::Scalar;
1819

1920
use crate::IntoArray;
20-
use crate::arrays::constant::ConstantArray;
21+
use crate::arrays::ConstantArray;
22+
use crate::compute::conformance::consistency::test_array_consistency;
2123
use crate::compute::conformance::filter::test_filter_conformance;
2224
use crate::compute::conformance::mask::test_mask_conformance;
2325

@@ -40,15 +42,6 @@ mod test {
4042
&ConstantArray::new(Scalar::from(f16::from_f32(3.0f32)), 5).into_array(),
4143
);
4244
}
43-
}
44-
45-
#[cfg(test)]
46-
mod tests {
47-
use rstest::rstest;
48-
use vortex_scalar::Scalar;
49-
50-
use crate::arrays::ConstantArray;
51-
use crate::compute::conformance::consistency::test_array_consistency;
5245

5346
#[rstest]
5447
// From test_all_consistency

vortex-array/src/arrays/extension/compute/cast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use vortex_dtype::DType;
55

66
use crate::arrays::{ExtensionArray, ExtensionVTable};
7-
use crate::compute::{CastKernel, CastKernelAdapter, cast};
7+
use crate::compute::{self, CastKernel, CastKernelAdapter};
88
use crate::{ArrayRef, IntoArray, register_kernel};
99

1010
impl CastKernel for ExtensionVTable {
@@ -21,7 +21,7 @@ impl CastKernel for ExtensionVTable {
2121
unreachable!("Already verified we have an extension dtype");
2222
};
2323

24-
let new_storage = match cast(array.storage(), ext_dtype.storage_dtype()) {
24+
let new_storage = match compute::cast(array.storage(), ext_dtype.storage_dtype()) {
2525
Ok(arr) => arr,
2626
Err(e) => {
2727
log::warn!("Failed to cast storage array: {e}");
@@ -49,6 +49,7 @@ mod tests {
4949
use super::*;
5050
use crate::IntoArray;
5151
use crate::arrays::PrimitiveArray;
52+
use crate::compute::cast;
5253
use crate::compute::conformance::cast::test_cast_conformance;
5354

5455
#[test]

vortex-array/src/arrays/extension/compute/compare.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use vortex_error::VortexResult;
55

66
use crate::arrays::{ConstantArray, ExtensionArray, ExtensionVTable};
7-
use crate::compute::{CompareKernel, CompareKernelAdapter, Operator, compare};
7+
use crate::compute::{self, CompareKernel, CompareKernelAdapter, Operator};
88
use crate::{Array, ArrayRef, register_kernel};
99

1010
impl CompareKernel for ExtensionVTable {
@@ -17,7 +17,7 @@ impl CompareKernel for ExtensionVTable {
1717
// If the RHS is a constant, we can extract the storage scalar.
1818
if let Some(const_ext) = rhs.as_constant() {
1919
let storage_scalar = const_ext.as_extension().storage();
20-
return compare(
20+
return compute::compare(
2121
lhs.storage(),
2222
ConstantArray::new(storage_scalar, lhs.len()).as_ref(),
2323
operator,
@@ -27,7 +27,7 @@ impl CompareKernel for ExtensionVTable {
2727

2828
// If the RHS is an extension array matching ours, we can extract the storage.
2929
if let Some(rhs_ext) = rhs.as_opt::<ExtensionVTable>() {
30-
return compare(lhs.storage(), rhs_ext.storage(), operator).map(Some);
30+
return compute::compare(lhs.storage(), rhs_ext.storage(), operator).map(Some);
3131
}
3232

3333
// Otherwise, we need the RHS to handle this comparison.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_error::VortexResult;
5+
use vortex_mask::Mask;
6+
7+
use crate::arrays::{ExtensionArray, ExtensionVTable};
8+
use crate::compute::{self, FilterKernel, FilterKernelAdapter};
9+
use crate::{ArrayRef, IntoArray, register_kernel};
10+
11+
impl FilterKernel for ExtensionVTable {
12+
fn filter(&self, array: &ExtensionArray, mask: &Mask) -> VortexResult<ArrayRef> {
13+
Ok(ExtensionArray::new(
14+
array.ext_dtype().clone(),
15+
compute::filter(array.storage(), mask)?,
16+
)
17+
.into_array())
18+
}
19+
}
20+
21+
register_kernel!(FilterKernelAdapter(ExtensionVTable).lift());
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_error::VortexResult;
5+
6+
use crate::arrays::{ExtensionArray, ExtensionVTable};
7+
use crate::compute::{self, IsConstantKernel, IsConstantKernelAdapter, IsConstantOpts};
8+
use crate::register_kernel;
9+
10+
impl IsConstantKernel for ExtensionVTable {
11+
fn is_constant(
12+
&self,
13+
array: &ExtensionArray,
14+
opts: &IsConstantOpts,
15+
) -> VortexResult<Option<bool>> {
16+
compute::is_constant_opts(array.storage(), opts)
17+
}
18+
}
19+
20+
register_kernel!(IsConstantKernelAdapter(ExtensionVTable).lift());
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_error::VortexResult;
5+
6+
use crate::arrays::{ExtensionArray, ExtensionVTable};
7+
use crate::compute::{self, IsSortedKernel, IsSortedKernelAdapter};
8+
use crate::register_kernel;
9+
10+
impl IsSortedKernel for ExtensionVTable {
11+
fn is_sorted(&self, array: &ExtensionArray) -> VortexResult<Option<bool>> {
12+
compute::is_sorted(array.storage())
13+
}
14+
15+
fn is_strict_sorted(&self, array: &ExtensionArray) -> VortexResult<Option<bool>> {
16+
compute::is_strict_sorted(array.storage())
17+
}
18+
}
19+
20+
register_kernel!(IsSortedKernelAdapter(ExtensionVTable).lift());
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use std::sync::Arc;
5+
6+
use vortex_dtype::ExtDType;
7+
use vortex_error::VortexResult;
8+
use vortex_mask::Mask;
9+
10+
use crate::arrays::{ExtensionArray, ExtensionVTable};
11+
use crate::compute::{self, MaskKernel, MaskKernelAdapter};
12+
use crate::{ArrayRef, IntoArray, register_kernel};
13+
14+
impl MaskKernel for ExtensionVTable {
15+
fn mask(&self, array: &ExtensionArray, mask_array: &Mask) -> VortexResult<ArrayRef> {
16+
let masked_storage = compute::mask(array.storage(), mask_array)?;
17+
if masked_storage.dtype().nullability() == array.ext_dtype().storage_dtype().nullability() {
18+
Ok(ExtensionArray::new(array.ext_dtype().clone(), masked_storage).into_array())
19+
} else {
20+
// The storage dtype changed (i.e., became nullable due to masking)
21+
let ext_dtype = Arc::new(ExtDType::new(
22+
array.ext_dtype().id().clone(),
23+
Arc::new(masked_storage.dtype().clone()),
24+
array.ext_dtype().metadata().cloned(),
25+
));
26+
Ok(ExtensionArray::new(ext_dtype, masked_storage).into_array())
27+
}
28+
}
29+
}
30+
31+
register_kernel!(MaskKernelAdapter(ExtensionVTable).lift());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_error::VortexResult;
5+
use vortex_scalar::Scalar;
6+
7+
use crate::arrays::{ExtensionArray, ExtensionVTable};
8+
use crate::compute::{self, MinMaxKernel, MinMaxKernelAdapter, MinMaxResult};
9+
use crate::register_kernel;
10+
11+
impl MinMaxKernel for ExtensionVTable {
12+
fn min_max(&self, array: &ExtensionArray) -> VortexResult<Option<MinMaxResult>> {
13+
Ok(
14+
compute::min_max(array.storage())?.map(|MinMaxResult { min, max }| MinMaxResult {
15+
min: Scalar::extension(array.ext_dtype().clone(), min),
16+
max: Scalar::extension(array.ext_dtype().clone(), max),
17+
}),
18+
)
19+
}
20+
}
21+
22+
register_kernel!(MinMaxKernelAdapter(ExtensionVTable).lift());

vortex-array/src/arrays/extension/compute/mod.rs

Lines changed: 7 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,117 +3,13 @@
33

44
mod cast;
55
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;
11713

11814
#[cfg(test)]
11915
mod test {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_error::VortexResult;
5+
use vortex_scalar::Scalar;
6+
7+
use crate::arrays::{ExtensionArray, ExtensionVTable};
8+
use crate::compute::{self, SumKernel, SumKernelAdapter};
9+
use crate::register_kernel;
10+
11+
impl SumKernel for ExtensionVTable {
12+
fn sum(&self, array: &ExtensionArray) -> VortexResult<Scalar> {
13+
compute::sum(array.storage())
14+
}
15+
}
16+
17+
register_kernel!(SumKernelAdapter(ExtensionVTable).lift());

0 commit comments

Comments
 (0)