Skip to content

Commit e8bc68b

Browse files
authored
Feature: add a take compute trait (#5503)
In the new operator world, `take` as a compute function just becomes a `DictArray` (since arrays are lazy), so it is nice to have `take` as a standalone trait (like `filter`). Signed-off-by: Connor Tsui <[email protected]>
1 parent 98b31fb commit e8bc68b

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

vortex-compute/src/filter/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ mod slice_mut;
1111
mod vector;
1212

1313
/// Function for filtering based on a selection mask.
14-
pub trait Filter<By: ?Sized> {
14+
pub trait Filter<Selection: ?Sized> {
1515
/// The result type after performing the operation.
1616
type Output;
1717

18-
/// Filters the vector using the provided mask, returning a new value.
18+
/// Filters an object using the provided mask, returning a new value.
1919
///
2020
/// The result value will have length equal to the true count of the provided mask.
2121
///
2222
/// # Panics
2323
///
2424
/// If the length of the mask does not equal the length of the value being filtered.
25-
fn filter(self, selection: &By) -> Self::Output;
25+
fn filter(self, selection: &Selection) -> Self::Output;
2626
}

vortex-compute/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ pub mod expand;
1616
pub mod filter;
1717
pub mod logical;
1818
pub mod mask;
19+
pub mod take;

vortex-compute/src/take/mod.rs

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+
//! Take function.
5+
6+
/// Function for taking based on indices (which can have different representations).
7+
pub trait Take<Indices: ?Sized> {
8+
/// The result type after performing the operation.
9+
type Output;
10+
11+
/// Creates a new object using the elements from the input indexed by `indices`.
12+
///
13+
/// For example, if we have an array `[1, 2, 3, 4, 5]` and `indices` `[4, 2]`, the resulting
14+
/// array would be `[5, 3]`.
15+
///
16+
/// The output should have the same length as the `indices`.
17+
///
18+
/// # Panics
19+
///
20+
/// This should panic if an index in `indices` is out-of-bounds with respect to `self`.
21+
fn take(self, indices: &Indices) -> Self::Output;
22+
}

0 commit comments

Comments
 (0)