Skip to content

Commit 881e4a5

Browse files
committed
Execute primitive comparisons with RowFn
Signed-off-by: Connor Tsui <[email protected]>
1 parent c269954 commit 881e4a5

9 files changed

Lines changed: 528 additions & 91 deletions

File tree

‎encodings/runend/src/trace_tests.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ fn trace_compare_on_runend() -> VortexResult<()> {
7272
iter 0 current=vortex.runend(bool, len=9) builder_active=false
7373
execute_until target=AnyCanonical root=vortex.binary(bool, len=3)
7474
iter 0 current=vortex.binary(bool, len=3) builder_active=false
75+
optimize root=vortex.slice(i32, len=1) session=false
76+
reduce_parent static:SliceReduceAdaptor(Constant) slot=0 parent=vortex.slice(i32, len=1) child=vortex.constant(i32, len=3) -> vortex.constant(i32, len=1)
77+
done output=vortex.constant(i32, len=1)
78+
execute_until target=AnyCanonical root=vortex.constant(i32, len=1)
79+
iter 0 current=vortex.constant(i32, len=1) builder_active=false
80+
Done array=vortex.primitive(i32, len=1)
81+
iter 1 current=vortex.primitive(i32, len=1) builder_active=false
82+
return output=vortex.primitive(i32, len=1)
7583
Done array=vortex.bool(bool, len=3)
7684
iter 1 current=vortex.bool(bool, len=3) builder_active=false
7785
return output=vortex.bool(bool, len=3)

‎vortex-array/benches/compare.rs‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![expect(clippy::unwrap_used)]
55

66
use divan::Bencher;
7+
use divan::counter::ItemsCount;
78
use mimalloc::MiMalloc;
89
use rand::RngExt;
910
use rand::SeedableRng;
@@ -39,6 +40,7 @@ const ARRAY_SIZE: usize = 8_192;
3940
fn bench_compare(bencher: Bencher, lhs: ArrayRef, rhs: ArrayRef, op: Operator) {
4041
let session = vortex_array::array_session();
4142
bencher
43+
.counter(ItemsCount::new(ARRAY_SIZE))
4244
.with_inputs(|| (&lhs, &rhs, session.create_execution_ctx()))
4345
.bench_refs(|input| {
4446
input
@@ -50,6 +52,31 @@ fn bench_compare(bencher: Bencher, lhs: ArrayRef, rhs: ArrayRef, op: Operator) {
5052
});
5153
}
5254

55+
fn u8_array(offset: u8) -> ArrayRef {
56+
(0u8..=u8::MAX)
57+
.cycle()
58+
.take(ARRAY_SIZE)
59+
.map(|value| value.wrapping_add(offset))
60+
.collect::<Buffer<_>>()
61+
.into_array()
62+
}
63+
64+
fn i32_array(offset: i32) -> ArrayRef {
65+
(0i32..)
66+
.take(ARRAY_SIZE)
67+
.map(|value| value.wrapping_mul(31).wrapping_add(offset))
68+
.collect::<Buffer<_>>()
69+
.into_array()
70+
}
71+
72+
fn u64_array(offset: u64) -> ArrayRef {
73+
(0u64..)
74+
.take(ARRAY_SIZE)
75+
.map(|value| value.wrapping_mul(31).wrapping_add(offset))
76+
.collect::<Buffer<_>>()
77+
.into_array()
78+
}
79+
5380
fn bool_array(rng: &mut StdRng) -> ArrayRef {
5481
BoolArray::from_iter((0..ARRAY_SIZE).map(|_| rng.random_bool(0.5))).into_array()
5582
}
@@ -88,6 +115,13 @@ fn float_array(rng: &mut StdRng) -> ArrayRef {
88115
.into_array()
89116
}
90117

118+
fn f32_array(rng: &mut StdRng) -> ArrayRef {
119+
(0..ARRAY_SIZE)
120+
.map(|_| rng.random_range(0.0f32..1.0))
121+
.collect::<Buffer<_>>()
122+
.into_array()
123+
}
124+
91125
fn string_array(rng: &mut StdRng) -> ArrayRef {
92126
VarBinViewArray::from_iter_str((0..ARRAY_SIZE).map(|_| {
93127
let len = rng.random_range(1usize..24);
@@ -154,6 +188,14 @@ fn compare_int_constant(bencher: Bencher) {
154188
bench_compare(bencher, arr, constant, Operator::Gte);
155189
}
156190

191+
#[divan::bench]
192+
fn compare_int_constant_lhs(bencher: Bencher) {
193+
let mut rng = StdRng::seed_from_u64(0);
194+
let constant = ConstantArray::new(50_000_000i64, ARRAY_SIZE).into_array();
195+
let arr = int_array(&mut rng);
196+
bench_compare(bencher, constant, arr, Operator::Gte);
197+
}
198+
157199
#[divan::bench]
158200
fn compare_int_eq(bencher: Bencher) {
159201
let mut rng = StdRng::seed_from_u64(0);
@@ -162,6 +204,55 @@ fn compare_int_eq(bencher: Bencher) {
162204
bench_compare(bencher, arr1, arr2, Operator::Eq);
163205
}
164206

207+
#[divan::bench]
208+
fn compare_i32(bencher: Bencher) {
209+
let lhs = i32_array(1);
210+
let rhs = i32_array(17);
211+
bench_compare(bencher, lhs, rhs, Operator::Gte);
212+
}
213+
214+
#[divan::bench]
215+
fn compare_i32_constant(bencher: Bencher) {
216+
let lhs = i32_array(1);
217+
let rhs = ConstantArray::new(1_000_000i32, ARRAY_SIZE).into_array();
218+
bench_compare(bencher, lhs, rhs, Operator::Gte);
219+
}
220+
221+
#[divan::bench]
222+
fn compare_u8(bencher: Bencher) {
223+
let lhs = u8_array(1);
224+
let rhs = u8_array(17);
225+
bench_compare(bencher, lhs, rhs, Operator::Gte);
226+
}
227+
228+
#[divan::bench]
229+
fn compare_u8_constant(bencher: Bencher) {
230+
let lhs = u8_array(1);
231+
let rhs = ConstantArray::new(127u8, ARRAY_SIZE).into_array();
232+
bench_compare(bencher, lhs, rhs, Operator::Gte);
233+
}
234+
235+
#[divan::bench]
236+
fn compare_u64(bencher: Bencher) {
237+
let lhs = u64_array(1);
238+
let rhs = u64_array(17);
239+
bench_compare(bencher, lhs, rhs, Operator::Gte);
240+
}
241+
242+
#[divan::bench]
243+
fn compare_u64_constant(bencher: Bencher) {
244+
let lhs = u64_array(1);
245+
let rhs = ConstantArray::new(1_000_000u64, ARRAY_SIZE).into_array();
246+
bench_compare(bencher, lhs, rhs, Operator::Gte);
247+
}
248+
249+
#[divan::bench]
250+
fn compare_u64_eq(bencher: Bencher) {
251+
let lhs = u64_array(1);
252+
let rhs = u64_array(17);
253+
bench_compare(bencher, lhs, rhs, Operator::Eq);
254+
}
255+
165256
#[divan::bench]
166257
fn compare_float(bencher: Bencher) {
167258
let mut rng = StdRng::seed_from_u64(0);
@@ -170,6 +261,30 @@ fn compare_float(bencher: Bencher) {
170261
bench_compare(bencher, arr1, arr2, Operator::Gte);
171262
}
172263

264+
#[divan::bench]
265+
fn compare_float_eq(bencher: Bencher) {
266+
let mut rng = StdRng::seed_from_u64(0);
267+
let arr1 = float_array(&mut rng);
268+
let arr2 = float_array(&mut rng);
269+
bench_compare(bencher, arr1, arr2, Operator::Eq);
270+
}
271+
272+
#[divan::bench]
273+
fn compare_f32(bencher: Bencher) {
274+
let mut rng = StdRng::seed_from_u64(0);
275+
let arr1 = f32_array(&mut rng);
276+
let arr2 = f32_array(&mut rng);
277+
bench_compare(bencher, arr1, arr2, Operator::Gte);
278+
}
279+
280+
#[divan::bench]
281+
fn compare_f32_eq(bencher: Bencher) {
282+
let mut rng = StdRng::seed_from_u64(0);
283+
let arr1 = f32_array(&mut rng);
284+
let arr2 = f32_array(&mut rng);
285+
bench_compare(bencher, arr1, arr2, Operator::Eq);
286+
}
287+
173288
#[divan::bench]
174289
fn compare_decimal(bencher: Bencher) {
175290
let mut rng = StdRng::seed_from_u64(0);

‎vortex-array/src/scalar_fn/fns/binary/compare/mod.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
//! Native comparison kernels.
55
//!
66
//! [`execute_compare`] dispatches on the logical [`DType`] of its operands and evaluates every
7-
//! comparison directly over Vortex canonical arrays — bit buffers for booleans, lane kernels from
8-
//! `vortex-compute` for primitives and decimals, binary views for strings/bytes, and a row-wise
9-
//! comparator for nested types. There is no Arrow fallback.
7+
//! comparison directly over Vortex canonical arrays: bit buffers for booleans, row or fused lane
8+
//! kernels for primitives, lane kernels for decimals, binary views for strings and bytes, and a
9+
//! row-wise comparator for nested types. There is no Arrow fallback.
1010
//!
1111
//! Floating point values compare with Vortex's total ordering (`NaN` is the largest value,
1212
//! `-0.0 < +0.0`, and equality is bitwise), matching [`Scalar`] comparison semantics.
@@ -211,7 +211,7 @@ fn compare_arrays(
211211
)
212212
.into_array()),
213213
DType::Bool(_) => boolean::compare_bool(lhs, rhs, op, nullability, ctx),
214-
DType::Primitive(..) => primitive::compare_primitive(lhs, rhs, op, nullability, ctx),
214+
DType::Primitive(..) => primitive::compare_primitive(lhs, rhs, op, ctx),
215215
DType::Decimal(..) => decimal::compare_decimal(lhs, rhs, op, nullability, ctx),
216216
DType::Utf8(_) | DType::Binary(_) => bytes::compare_bytes(lhs, rhs, op, nullability, ctx),
217217
DType::Struct(..) | DType::List(..) | DType::FixedSizeList(..) | DType::Map(..) => {

0 commit comments

Comments
 (0)