Skip to content

Commit fed289c

Browse files
authored
Add checked arithmetic compute (#5096)
FLUPs: * Arithmetic array to invert lhs/rhs for constant checks * Special handling for vectors with many nulls (iterate only the sparse non-null indices) --------- Signed-off-by: Nicholas Gates <[email protected]>
1 parent d4bab58 commit fed289c

File tree

26 files changed

+1582
-18
lines changed

26 files changed

+1582
-18
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

encodings/alp/src/alp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub trait ALPFloat: private::Sealed + Float + Display + NativePType {
193193
}
194194

195195
fn decode_buffer(encoded: BufferMut<Self::ALPInt>, exponents: Exponents) -> BufferMut<Self> {
196-
encoded.map_each(move |encoded| Self::decode_single(encoded, exponents))
196+
encoded.map_each_in_place(move |encoded| Self::decode_single(encoded, exponents))
197197
}
198198

199199
#[inline(always)]

encodings/alp/src/alp_rd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub fn alp_rd_decode<T: ALPRDFloat>(
311311
// Shift the left-parts and add in the right-parts.
312312
let mut index = 0;
313313
right_parts
314-
.map_each(|right| {
314+
.map_each_in_place(|right| {
315315
let left = values[index];
316316
index += 1;
317317
let left = <T as ALPRDFloat>::from_u16(left);

encodings/datetime-parts/src/canonical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn decode_to_temporal(array: &DateTimePartsArray) -> TemporalArray {
5353
// are constant.
5454
let mut values: BufferMut<i64> = days_buf
5555
.into_buffer_mut::<i64>()
56-
.map_each(|d| d * 86_400 * divisor);
56+
.map_each_in_place(|d| d * 86_400 * divisor);
5757

5858
if let Some(seconds) = array.seconds().as_constant() {
5959
let seconds = seconds

encodings/fastlanes/src/for/compress.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ fn decompress_primitive<T: NativePType + WrappingAdd + PrimInt>(
151151
values: BufferMut<T>,
152152
min: T,
153153
) -> Buffer<T> {
154-
values.map_each(move |v| v.wrapping_add(&min)).freeze()
154+
values
155+
.map_each_in_place(move |v| v.wrapping_add(&min))
156+
.freeze()
155157
}
156158

157159
#[cfg(test)]

encodings/zigzag/src/compress.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ fn zigzag_encode_primitive<T: ExternalZigZag + NativePType>(
3333
where
3434
<T as ExternalZigZag>::UInt: NativePType,
3535
{
36-
PrimitiveArray::new(values.map_each(|v| T::encode(v)).freeze(), validity)
36+
PrimitiveArray::new(
37+
values.map_each_in_place(|v| T::encode(v)).freeze(),
38+
validity,
39+
)
3740
}
3841

3942
pub fn zigzag_decode(parray: PrimitiveArray) -> PrimitiveArray {
@@ -57,7 +60,10 @@ fn zigzag_decode_primitive<T: ExternalZigZag + NativePType>(
5760
where
5861
<T as ExternalZigZag>::UInt: NativePType,
5962
{
60-
PrimitiveArray::new(values.map_each(|v| T::decode(v)).freeze(), validity)
63+
PrimitiveArray::new(
64+
values.map_each_in_place(|v| T::decode(v)).freeze(),
65+
validity,
66+
)
6167
}
6268

6369
#[cfg(test)]

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/arrays/primitive/array/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl PrimitiveArray {
192192
{
193193
let validity = self.validity().clone();
194194
let buffer = match self.try_into_buffer_mut() {
195-
Ok(buffer_mut) => buffer_mut.map_each(f),
195+
Ok(buffer_mut) => buffer_mut.map_each_in_place(f),
196196
Err(parray) => BufferMut::<R>::from_iter(parray.buffer::<T>().iter().copied().map(f)),
197197
};
198198
PrimitiveArray::new(buffer.freeze(), validity)

0 commit comments

Comments
 (0)