Skip to content

Commit 3051184

Browse files
committed
Add arithmetic buffer compute
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 20fd841 commit 3051184

File tree

10 files changed

+44
-44
lines changed

10 files changed

+44
-44
lines changed

vortex-array/src/array/operator.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
use std::sync::Arc;
55

6-
use vortex_error::VortexResult;
6+
use vortex_dtype::DType;
7+
use vortex_error::{VortexResult, vortex_bail};
78
use vortex_vector::Vector;
89

910
use crate::execution::{BatchKernelRef, BindCtx};
@@ -33,6 +34,21 @@ pub trait ArrayOperator: 'static + Send + Sync {
3334

3435
impl ArrayOperator for Arc<dyn Array> {
3536
fn execute_with_selection(&self, selection: Option<&ArrayRef>) -> VortexResult<Vector> {
37+
if let Some(selection) = selection.as_ref() {
38+
if !matches!(selection.dtype(), DType::Bool(_)) {
39+
vortex_bail!(
40+
"Selection array must be of boolean type, got {}",
41+
selection.dtype()
42+
);
43+
}
44+
if selection.len() != self.len() {
45+
vortex_bail!(
46+
"Selection array length {} does not match array length {}",
47+
selection.len(),
48+
self.len()
49+
);
50+
}
51+
}
3652
self.as_ref().execute_with_selection(selection)
3753
}
3854

vortex-array/src/compute/arrays/arithmetic.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
use std::hash::{Hash, Hasher};
55
use std::sync::LazyLock;
66

7-
use enum_map::{enum_map, Enum, EnumMap};
7+
use enum_map::{Enum, EnumMap, enum_map};
88
use vortex_buffer::ByteBuffer;
99
use vortex_compute::arithmetic::{Add, Checked, CheckedOperator, Div, Mul, Sub};
10-
use vortex_dtype::{match_each_native_ptype, DType, NativePType, PTypeDowncastExt};
11-
use vortex_error::{vortex_err, VortexExpect, VortexResult};
10+
use vortex_dtype::{DType, NativePType, PTypeDowncastExt, match_each_native_ptype};
11+
use vortex_error::{VortexExpect, VortexResult, vortex_err};
1212
use vortex_scalar::{PValue, Scalar};
1313

1414
use crate::arrays::ConstantArray;
15-
use crate::execution::{kernel, BatchKernelRef, BindCtx};
15+
use crate::execution::{BatchKernelRef, BindCtx, kernel};
1616
use crate::serde::ArrayChildren;
1717
use crate::stats::{ArrayStats, StatsSetRef};
1818
use crate::vtable::{
1919
ArrayVTable, NotSupported, OperatorVTable, SerdeVTable, VTable, VisitorVTable,
2020
};
2121
use crate::{
22-
vtable, Array, ArrayBufferVisitor, ArrayChildVisitor, ArrayEq, ArrayHash,
23-
ArrayRef, DeserializeMetadata, EmptyMetadata, EncodingId, EncodingRef, IntoArray, Precision,
22+
Array, ArrayBufferVisitor, ArrayChildVisitor, ArrayEq, ArrayHash, ArrayRef,
23+
DeserializeMetadata, EmptyMetadata, EncodingId, EncodingRef, IntoArray, Precision, vtable,
2424
};
2525

2626
/// The set of operators supported by an arithmetic array.
@@ -223,11 +223,9 @@ impl OperatorVTable<ArithmeticVTable> for ArithmeticVTable {
223223
if let Some(rhs) = array.rhs.as_constant() {
224224
if rhs.is_null() {
225225
// If the RHS is null, the result is always null.
226-
return Ok(
227-
ConstantArray::new(Scalar::null(array.dtype().clone()), array.len())
228-
.into_array()
229-
.bind(selection, ctx)?,
230-
);
226+
return ConstantArray::new(Scalar::null(array.dtype().clone()), array.len())
227+
.into_array()
228+
.bind(selection, ctx);
231229
}
232230

233231
let lhs = ctx.bind(&array.lhs, selection)?;
@@ -289,7 +287,7 @@ where
289287

290288
#[cfg(test)]
291289
mod tests {
292-
use vortex_buffer::buffer;
290+
use vortex_buffer::{bitbuffer, buffer};
293291
use vortex_dtype::PTypeDowncastExt;
294292

295293
use crate::arrays::PrimitiveArray;
@@ -365,7 +363,7 @@ mod tests {
365363
let lhs = PrimitiveArray::from_iter([1u32, 2, 3]).into_array();
366364
let rhs = PrimitiveArray::from_iter([10u32, 20, 30]).into_array();
367365

368-
let selection = PrimitiveArray::from_iter([0u64, 2]).into_array();
366+
let selection = bitbuffer![1 0 1].into_array();
369367

370368
let result = add(lhs, rhs)
371369
.execute_with_selection(Some(&selection))

vortex-compute/src/arithmetic/buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ where
145145

146146
#[cfg(test)]
147147
mod tests {
148-
use crate::arithmetic::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub};
149148
use vortex_buffer::buffer;
150149

150+
use crate::arithmetic::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub};
151+
151152
#[test]
152153
fn test_add_buffers() {
153154
let left = buffer![1u32, 2, 3, 4];

vortex-compute/src/arithmetic/pvector.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use crate::arithmetic::{Checked, CheckedOperator};
54
use std::ops::BitAnd;
5+
66
use vortex_buffer::{Buffer, BufferMut};
77
use vortex_dtype::NativePType;
88
use vortex_vector::{PVector, PVectorMut, VectorMutOps, VectorOps};
99

10+
use crate::arithmetic::{Checked, CheckedOperator};
11+
1012
/// Implementation that attempts to downcast to a mutable vector and operates in-place.
1113
impl<Op, T> Checked<Op, &PVector<T>> for PVector<T>
1214
where
@@ -121,11 +123,11 @@ where
121123

122124
#[cfg(test)]
123125
mod tests {
124-
use super::*;
125-
use crate::arithmetic::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub};
126126
use vortex_buffer::buffer;
127127
use vortex_mask::Mask;
128-
use vortex_vector::PVector;
128+
use vortex_vector::{PVector, VectorOps};
129+
130+
use crate::arithmetic::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub};
129131

130132
#[test]
131133
fn test_add_pvectors() {

vortex-compute/src/logical/and.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::ops::BitAnd;
5+
56
use vortex_mask::Mask;
67
use vortex_vector::{BoolVector, VectorOps};
78

vortex-compute/src/logical/and_not.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::ops::BitAnd;
5+
56
use vortex_vector::{BoolVector, VectorOps};
67

78
use crate::logical::LogicalAndNot;

vortex-compute/src/logical/or.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::ops::{BitAnd, BitOr};
5+
56
use vortex_mask::Mask;
67
use vortex_vector::{BoolVector, VectorOps};
78

vortex-dtype/src/ptype.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use num_traits::bounds::UpperBounded;
1313
use num_traits::{
1414
AsPrimitive, Bounded, FromPrimitive, Num, NumCast, PrimInt, ToPrimitive, Unsigned,
1515
};
16-
use vortex_error::{vortex_err, VortexError, VortexResult};
16+
use vortex_error::{VortexError, VortexResult, vortex_err};
1717

18+
use crate::DType;
1819
use crate::half::f16;
1920
use crate::nullability::Nullability::NonNullable;
20-
use crate::DType;
2121

2222
/// Physical type enum, represents the in-memory physical layout but might represent a different logical type.
2323
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Hash, prost::Enumeration)]

vortex-vector/src/primitive/generic.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use vortex_buffer::Buffer;
77
use vortex_dtype::NativePType;
8-
use vortex_error::{vortex_ensure, VortexExpect, VortexResult};
8+
use vortex_error::{VortexExpect, VortexResult, vortex_ensure};
99
use vortex_mask::Mask;
1010

1111
use crate::{PVectorMut, VectorOps};
@@ -111,18 +111,6 @@ impl<T: NativePType> AsRef<[T]> for PVector<T> {
111111
}
112112
}
113113

114-
impl<T: NativePType> PVector<T> {
115-
/// Returns a reference to the internal elements buffer.
116-
pub fn elements(&self) -> &Buffer<T> {
117-
&self.elements
118-
}
119-
120-
/// Returns a reference to the internal validity mask.
121-
pub fn validity(&self) -> &Mask {
122-
&self.validity
123-
}
124-
}
125-
126114
impl<T: NativePType> VectorOps for PVector<T> {
127115
type Mutable = PVectorMut<T>;
128116

vortex-vector/src/primitive/generic_mut.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
use vortex_buffer::BufferMut;
77
use vortex_dtype::NativePType;
8-
use vortex_error::{vortex_ensure, VortexExpect, VortexResult};
8+
use vortex_error::{VortexExpect, VortexResult, vortex_ensure};
99
use vortex_mask::MaskMut;
1010

11-
use crate::{PVector, VectorMutOps};
11+
use crate::{PVector, VectorMutOps, VectorOps};
1212

1313
/// A mutable vector of generic primitive values.
1414
///
@@ -166,14 +166,6 @@ impl<T> PVectorMut<T> {
166166
}
167167
}
168168

169-
impl<T: NativePType> PVectorMut<T> {
170-
/// Decomposes the mutable vector into its constituent parts: the elements buffer and the
171-
/// validity mask.
172-
pub fn into_parts(self) -> (BufferMut<T>, MaskMut) {
173-
(self.elements, self.validity)
174-
}
175-
}
176-
177169
impl<T: NativePType> VectorMutOps for PVectorMut<T> {
178170
type Immutable = PVector<T>;
179171

0 commit comments

Comments
 (0)