Skip to content

Commit 62b9519

Browse files
Use non debug asserts in compute function entry points (#2914)
1 parent 1c2b7f0 commit 62b9519

File tree

17 files changed

+96
-69
lines changed

17 files changed

+96
-69
lines changed

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ impl TakeFn<&ConstantArray> for ConstantEncoding {
1111
fn take(&self, array: &ConstantArray, indices: &dyn Array) -> VortexResult<ArrayRef> {
1212
match indices.validity_mask()?.boolean_buffer() {
1313
AllOr::All => {
14-
Ok(ConstantArray::new(array.scalar().clone(), indices.len()).into_array())
14+
let nullability = array.dtype().nullability() | indices.dtype().nullability();
15+
let scalar = Scalar::new(
16+
array.scalar().dtype().with_nullability(nullability),
17+
array.scalar().value().clone(),
18+
);
19+
Ok(ConstantArray::new(scalar, indices.len()).into_array())
20+
}
21+
AllOr::None => {
22+
Ok(ConstantArray::new(
23+
Scalar::null(array.dtype().with_nullability(
24+
array.dtype().nullability() | indices.dtype().nullability(),
25+
)),
26+
indices.len(),
27+
)
28+
.into_array())
1529
}
16-
AllOr::None => Ok(ConstantArray::new(
17-
Scalar::null(array.dtype().clone()),
18-
indices.len(),
19-
)
20-
.into_array()),
2130
AllOr::Some(v) => {
2231
let arr = ConstantArray::new(array.scalar().clone(), indices.len()).into_array();
2332

@@ -38,6 +47,7 @@ impl TakeFn<&ConstantArray> for ConstantEncoding {
3847
#[cfg(test)]
3948
mod tests {
4049
use vortex_buffer::buffer;
50+
use vortex_dtype::Nullability;
4151
use vortex_mask::AllOr;
4252

4353
use crate::arrays::{ConstantArray, PrimitiveArray};
@@ -58,6 +68,10 @@ mod tests {
5868
)
5969
.unwrap();
6070
let valid_indices: &[usize] = &[1usize];
71+
assert_eq!(
72+
&array.dtype().with_nullability(Nullability::Nullable),
73+
taken.dtype()
74+
);
6175
assert_eq!(
6276
taken.to_primitive().unwrap().as_slice::<i32>(),
6377
&[42, 42, 42]
@@ -67,4 +81,23 @@ mod tests {
6781
AllOr::Some(valid_indices)
6882
);
6983
}
84+
85+
#[test]
86+
fn take_all_valid_indices() {
87+
let array = ConstantArray::new(42, 10).to_array();
88+
let taken = take(
89+
&array,
90+
&PrimitiveArray::new(buffer![0, 5, 7], Validity::AllValid).into_array(),
91+
)
92+
.unwrap();
93+
assert_eq!(
94+
&array.dtype().with_nullability(Nullability::Nullable),
95+
taken.dtype()
96+
);
97+
assert_eq!(
98+
taken.to_primitive().unwrap().as_slice::<i32>(),
99+
&[42, 42, 42]
100+
);
101+
assert_eq!(taken.validity_mask().unwrap().indices(), AllOr::All);
102+
}
70103
}

vortex-array/src/compute/between.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ pub fn between(
8888
upper: &dyn Array,
8989
options: &BetweenOptions,
9090
) -> VortexResult<ArrayRef> {
91-
debug_assert!(arr.dtype().eq_ignore_nullability(lower.dtype()));
92-
debug_assert!(arr.dtype().eq_ignore_nullability(upper.dtype()));
93-
debug_assert_eq!(arr.len(), lower.len());
94-
debug_assert_eq!(arr.len(), upper.len());
91+
assert!(arr.dtype().eq_ignore_nullability(lower.dtype()));
92+
assert!(arr.dtype().eq_ignore_nullability(upper.dtype()));
93+
assert_eq!(arr.len(), lower.len());
94+
assert_eq!(arr.len(), upper.len());
9595

9696
// A quick check to see if either array might is a null constant array.
9797
if lower.is_invalid(0)? || upper.is_invalid(0)? {
@@ -110,8 +110,8 @@ pub fn between(
110110

111111
let result = between_impl(arr, lower, upper, options)?;
112112

113-
debug_assert_eq!(result.len(), arr.len());
114-
debug_assert_eq!(
113+
assert_eq!(result.len(), arr.len());
114+
assert_eq!(
115115
result.dtype(),
116116
&DType::Bool(
117117
arr.dtype().nullability() | lower.dtype().nullability() | upper.dtype().nullability()

vortex-array/src/compute/binary_numeric.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ fn arrow_numeric(
171171

172172
#[inline(always)]
173173
fn check_numeric_result(result: ArrayRef, lhs: &dyn Array, rhs: &dyn Array) -> ArrayRef {
174-
debug_assert_eq!(
174+
assert_eq!(
175175
result.len(),
176176
lhs.len(),
177177
"Numeric operation length mismatch {}",
178178
rhs.encoding()
179179
);
180-
debug_assert_eq!(
180+
assert_eq!(
181181
result.dtype(),
182182
&DType::Primitive(
183183
PType::try_from(lhs.dtype())

vortex-array/src/compute/boolean.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ pub fn binary_boolean(
115115
.and_then(|f| f.binary_boolean(lhs, rhs, op).transpose())
116116
.transpose()?
117117
{
118-
debug_assert_eq!(
118+
assert_eq!(
119119
result.len(),
120120
lhs.len(),
121121
"Boolean operation length mismatch {}",
122122
lhs.encoding()
123123
);
124-
debug_assert_eq!(
124+
assert_eq!(
125125
result.dtype(),
126126
&DType::Bool((lhs.dtype().is_nullable() || rhs.dtype().is_nullable()).into()),
127127
"Boolean operation dtype mismatch {}",
@@ -136,13 +136,13 @@ pub fn binary_boolean(
136136
.and_then(|f| f.binary_boolean(rhs, lhs, op).transpose())
137137
.transpose()?
138138
{
139-
debug_assert_eq!(
139+
assert_eq!(
140140
result.len(),
141141
lhs.len(),
142142
"Boolean operation length mismatch {}",
143143
rhs.encoding()
144144
);
145-
debug_assert_eq!(
145+
assert_eq!(
146146
result.dtype(),
147147
&DType::Bool((lhs.dtype().is_nullable() || rhs.dtype().is_nullable()).into()),
148148
"Boolean operation dtype mismatch {}",

vortex-array/src/compute/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ pub fn try_cast(array: &dyn Array, dtype: &DType) -> VortexResult<ArrayRef> {
3131

3232
let casted = try_cast_impl(array, dtype)?;
3333

34-
debug_assert_eq!(
34+
assert_eq!(
3535
casted.len(),
3636
array.len(),
3737
"Cast length mismatch {}",
3838
array.encoding()
3939
);
40-
debug_assert_eq!(
40+
assert_eq!(
4141
casted.dtype(),
4242
dtype,
4343
"Cast dtype mismatch {}",

vortex-array/src/compute/compare.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ fn arrow_compare(
211211

212212
#[inline(always)]
213213
fn check_compare_result(result: &dyn Array, lhs: &dyn Array, rhs: &dyn Array) {
214-
debug_assert_eq!(
214+
assert_eq!(
215215
result.len(),
216216
lhs.len(),
217217
"CompareFn result length ({}) mismatch for left encoding {}, left len {}, right encoding {}, right len {}",
@@ -221,7 +221,7 @@ fn check_compare_result(result: &dyn Array, lhs: &dyn Array, rhs: &dyn Array) {
221221
rhs.encoding(),
222222
rhs.len()
223223
);
224-
debug_assert_eq!(
224+
assert_eq!(
225225
result.dtype(),
226226
&DType::Bool((lhs.dtype().is_nullable() || rhs.dtype().is_nullable()).into()),
227227
"CompareFn result dtype ({}) mismatch for left encoding {}, right encoding {}",

vortex-array/src/compute/fill_forward.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ pub fn fill_forward(array: &dyn Array) -> VortexResult<ArrayRef> {
4141
))
4242
})?;
4343

44-
debug_assert_eq!(
44+
assert_eq!(
4545
filled.len(),
4646
array.len(),
4747
"FillForward length mismatch {}",
4848
array.encoding()
4949
);
50-
debug_assert_eq!(
50+
assert_eq!(
5151
filled.dtype(),
5252
array.dtype(),
5353
"FillForward dtype mismatch {}",

vortex-array/src/compute/fill_null.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ pub fn fill_null(array: &dyn Array, fill_value: Scalar) -> VortexResult<ArrayRef
4040
let fill_value_nullability = fill_value.dtype().nullability();
4141
let filled = fill_null_impl(array, fill_value)?;
4242

43-
debug_assert_eq!(
43+
assert_eq!(
4444
filled.len(),
4545
array.len(),
4646
"FillNull length mismatch {}",
4747
array.encoding()
4848
);
49-
debug_assert_eq!(
49+
assert_eq!(
5050
filled.dtype(),
5151
&array.dtype().with_nullability(fill_value_nullability),
5252
"FillNull dtype mismatch {}",

vortex-array/src/compute/filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ impl ComputeFn for Filter {
9292

9393
let filtered = filter_impl(array, mask)?;
9494

95-
debug_assert_eq!(
95+
assert_eq!(
9696
filtered.len(),
9797
true_count,
9898
"Filter length mismatch {}",
9999
array.encoding()
100100
);
101-
debug_assert_eq!(
101+
assert_eq!(
102102
filtered.dtype(),
103103
array.dtype(),
104104
"Filter dtype mismatch {}",

vortex-array/src/compute/is_constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn is_constant_impl(array: &dyn Array, opts: &IsConstantOpts) -> VortexResult<Op
117117
}
118118
}
119119

120-
debug_assert!(
120+
assert!(
121121
all_valid,
122122
"All values must be valid as an invariant of the VTable."
123123
);

0 commit comments

Comments
 (0)