Skip to content

Commit 40d6a98

Browse files
committed
fixes
Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent 578d83d commit 40d6a98

6 files changed

Lines changed: 247 additions & 167 deletions

File tree

vortex-array/public-api.lock

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,9 +3304,9 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
33043304

33053305
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
33063306

3307-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<Self::Array>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
3307+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
33083308

3309-
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
3309+
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
33103310

33113311
pub fn vortex_array::arrays::patched::Patched::id(&self) -> vortex_array::vtable::ArrayId
33123312

@@ -3318,11 +3318,11 @@ pub fn vortex_array::arrays::patched::Patched::nbuffers(_array: &Self::Array) ->
33183318

33193319
pub fn vortex_array::arrays::patched::Patched::nchildren(_array: &Self::Array) -> usize
33203320

3321-
pub fn vortex_array::arrays::patched::Patched::reduce(array: &Self::Array) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
3321+
pub fn vortex_array::arrays::patched::Patched::reduce(array: &vortex_array::vtable::Array<Self>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
33223322

3323-
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
3323+
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
33243324

3325-
pub fn vortex_array::arrays::patched::Patched::serialize(_metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
3325+
pub fn vortex_array::arrays::patched::Patched::serialize(metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
33263326

33273327
pub fn vortex_array::arrays::patched::Patched::stats(array: &Self::Array) -> vortex_array::stats::StatsSetRef<'_>
33283328

@@ -7152,9 +7152,9 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
71527152

71537153
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
71547154

7155-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<Self::Array>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
7155+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
71567156

7157-
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
7157+
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
71587158

71597159
pub fn vortex_array::arrays::patched::Patched::id(&self) -> vortex_array::vtable::ArrayId
71607160

@@ -7166,11 +7166,11 @@ pub fn vortex_array::arrays::patched::Patched::nbuffers(_array: &Self::Array) ->
71667166

71677167
pub fn vortex_array::arrays::patched::Patched::nchildren(_array: &Self::Array) -> usize
71687168

7169-
pub fn vortex_array::arrays::patched::Patched::reduce(array: &Self::Array) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
7169+
pub fn vortex_array::arrays::patched::Patched::reduce(array: &vortex_array::vtable::Array<Self>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
71707170

7171-
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
7171+
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
71727172

7173-
pub fn vortex_array::arrays::patched::Patched::serialize(_metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
7173+
pub fn vortex_array::arrays::patched::Patched::serialize(metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
71747174

71757175
pub fn vortex_array::arrays::patched::Patched::stats(array: &Self::Array) -> vortex_array::stats::StatsSetRef<'_>
71767176

@@ -22166,9 +22166,9 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
2216622166

2216722167
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
2216822168

22169-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<Self::Array>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
22169+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
2217022170

22171-
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
22171+
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2217222172

2217322173
pub fn vortex_array::arrays::patched::Patched::id(&self) -> vortex_array::vtable::ArrayId
2217422174

@@ -22180,11 +22180,11 @@ pub fn vortex_array::arrays::patched::Patched::nbuffers(_array: &Self::Array) ->
2218022180

2218122181
pub fn vortex_array::arrays::patched::Patched::nchildren(_array: &Self::Array) -> usize
2218222182

22183-
pub fn vortex_array::arrays::patched::Patched::reduce(array: &Self::Array) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
22183+
pub fn vortex_array::arrays::patched::Patched::reduce(array: &vortex_array::vtable::Array<Self>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2218422184

22185-
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
22185+
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2218622186

22187-
pub fn vortex_array::arrays::patched::Patched::serialize(_metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
22187+
pub fn vortex_array::arrays::patched::Patched::serialize(metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
2218822188

2218922189
pub fn vortex_array::arrays::patched::Patched::stats(array: &Self::Array) -> vortex_array::stats::StatsSetRef<'_>
2219022190

@@ -23522,9 +23522,9 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
2352223522

2352323523
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
2352423524

23525-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<Self::Array>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
23525+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
2352623526

23527-
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
23527+
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2352823528

2352923529
pub fn vortex_array::arrays::patched::Patched::id(&self) -> vortex_array::vtable::ArrayId
2353023530

@@ -23536,11 +23536,11 @@ pub fn vortex_array::arrays::patched::Patched::nbuffers(_array: &Self::Array) ->
2353623536

2353723537
pub fn vortex_array::arrays::patched::Patched::nchildren(_array: &Self::Array) -> usize
2353823538

23539-
pub fn vortex_array::arrays::patched::Patched::reduce(array: &Self::Array) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
23539+
pub fn vortex_array::arrays::patched::Patched::reduce(array: &vortex_array::vtable::Array<Self>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2354023540

23541-
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
23541+
pub fn vortex_array::arrays::patched::Patched::reduce_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2354223542

23543-
pub fn vortex_array::arrays::patched::Patched::serialize(_metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
23543+
pub fn vortex_array::arrays::patched::Patched::serialize(metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
2354423544

2354523545
pub fn vortex_array::arrays::patched::Patched::stats(array: &Self::Array) -> vortex_array::stats::StatsSetRef<'_>
2354623546

vortex-array/src/arrays/patched/compute/compare.rs

Lines changed: 51 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -74,78 +74,34 @@ impl CompareKernel for Patched {
7474
.as_::<V>()
7575
.vortex_expect("compare constant not null");
7676

77+
let apply_patches = ApplyPatches {
78+
bits: &mut bits,
79+
offset,
80+
n_lanes,
81+
lane_offsets,
82+
indices,
83+
values,
84+
constant,
85+
};
86+
7787
match operator {
7888
CompareOperator::Eq => {
79-
apply::<V, _>(
80-
&mut bits,
81-
offset,
82-
n_lanes,
83-
lane_offsets,
84-
indices,
85-
values,
86-
constant,
87-
|l, r| NativeValue(l) == NativeValue(r),
88-
)?;
89+
apply_patches.apply(|l, r| NativeValue(l) == NativeValue(r))?;
8990
}
9091
CompareOperator::NotEq => {
91-
apply::<V, _>(
92-
&mut bits,
93-
offset,
94-
n_lanes,
95-
lane_offsets,
96-
indices,
97-
values,
98-
constant,
99-
|l, r| NativeValue(l) != NativeValue(r),
100-
)?;
92+
apply_patches.apply(|l, r| NativeValue(l) != NativeValue(r))?;
10193
}
10294
CompareOperator::Gt => {
103-
apply::<V, _>(
104-
&mut bits,
105-
n_lanes,
106-
offset,
107-
lane_offsets,
108-
indices,
109-
values,
110-
constant,
111-
|l, r| NativeValue(l) > NativeValue(r),
112-
)?;
95+
apply_patches.apply(|l, r| NativeValue(l) > NativeValue(r))?;
11396
}
11497
CompareOperator::Gte => {
115-
apply::<V, _>(
116-
&mut bits,
117-
n_lanes,
118-
offset,
119-
lane_offsets,
120-
indices,
121-
values,
122-
constant,
123-
|l, r| NativeValue(l) >= NativeValue(r),
124-
)?;
98+
apply_patches.apply(|l, r| NativeValue(l) >= NativeValue(r))?;
12599
}
126100
CompareOperator::Lt => {
127-
apply::<V, _>(
128-
&mut bits,
129-
n_lanes,
130-
offset,
131-
lane_offsets,
132-
indices,
133-
values,
134-
constant,
135-
|l, r| NativeValue(l) < NativeValue(r),
136-
)?;
101+
apply_patches.apply(|l, r| NativeValue(l) < NativeValue(r))?;
137102
}
138103
CompareOperator::Lte => {
139-
apply::<V, _>(
140-
&mut bits,
141-
n_lanes,
142-
offset,
143-
lane_offsets,
144-
indices,
145-
values,
146-
constant,
147-
|l, r| NativeValue(l) <= NativeValue(r),
148-
)?;
104+
apply_patches.apply(|l, r| NativeValue(l) <= NativeValue(r))?;
149105
}
150106
}
151107
});
@@ -155,45 +111,47 @@ impl CompareKernel for Patched {
155111
}
156112
}
157113

158-
#[allow(clippy::too_many_arguments)]
159-
fn apply<V: NativePType, F>(
160-
bits: &mut BitBufferMut,
114+
struct ApplyPatches<'a, V: NativePType> {
115+
bits: &'a mut BitBufferMut,
161116
offset: usize,
162117
n_lanes: usize,
163-
lane_offsets: &[u32],
164-
indices: &[u16],
165-
values: &[V],
118+
lane_offsets: &'a [u32],
119+
indices: &'a [u16],
120+
values: &'a [V],
166121
constant: V,
167-
cmp: F,
168-
) -> VortexResult<()>
169-
where
170-
F: Fn(V, V) -> bool,
171-
{
172-
for index in 0..(lane_offsets.len() - 1) {
173-
let chunk = index / n_lanes;
174-
175-
let lane_start = lane_offsets[index] as usize;
176-
let lane_end = lane_offsets[index + 1] as usize;
177-
178-
for (&patch_index, &patch_value) in std::iter::zip(
179-
&indices[lane_start..lane_end],
180-
&values[lane_start..lane_end],
181-
) {
182-
let bit_index = chunk * 1024 + patch_index as usize;
183-
// Skip any indices < the offset.
184-
if bit_index < offset {
185-
continue;
186-
}
187-
let bit_index = bit_index - offset;
188-
if cmp(patch_value, constant) {
189-
bits.set(bit_index)
190-
} else {
191-
bits.unset(bit_index)
122+
}
123+
124+
impl<V: NativePType> ApplyPatches<'_, V> {
125+
fn apply<F>(self, cmp: F) -> VortexResult<()>
126+
where
127+
F: Fn(V, V) -> bool,
128+
{
129+
for index in 0..(self.lane_offsets.len() - 1) {
130+
let chunk = index / self.n_lanes;
131+
132+
let lane_start = self.lane_offsets[index] as usize;
133+
let lane_end = self.lane_offsets[index + 1] as usize;
134+
135+
for (&patch_index, &patch_value) in std::iter::zip(
136+
&self.indices[lane_start..lane_end],
137+
&self.values[lane_start..lane_end],
138+
) {
139+
let bit_index = chunk * 1024 + patch_index as usize;
140+
// Skip any indices < the offset.
141+
if bit_index < self.offset {
142+
continue;
143+
}
144+
let bit_index = bit_index - self.offset;
145+
if cmp(patch_value, self.constant) {
146+
self.bits.set(bit_index)
147+
} else {
148+
self.bits.unset(bit_index)
149+
}
192150
}
193151
}
194-
}
195152

196-
Ok(())
153+
Ok(())
154+
}
197155
}
198156

199157
#[cfg(test)]

vortex-array/src/arrays/patched/vtable/mod.rs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ use crate::serde::ArrayChildren;
4646
use crate::stats::ArrayStats;
4747
use crate::stats::StatsSetRef;
4848
use crate::vtable;
49+
use crate::vtable::Array;
50+
use crate::vtable::ArrayId;
4951
use crate::vtable::VTable;
5052
use crate::vtable::ValidityChild;
5153
use crate::vtable::ValidityVTableFromChild;
52-
use crate::vtable::{Array, ArrayId};
5354

5455
vtable!(Patched);
5556

@@ -265,8 +266,8 @@ impl VTable for Patched {
265266

266267
fn with_children(array: &mut Self::Array, mut children: Vec<ArrayRef>) -> VortexResult<()> {
267268
vortex_ensure!(
268-
children.len() == 2,
269-
"PatchedArray must have exactly 2 children"
269+
children.len() == 3,
270+
"PatchedArray must have exactly 3 children"
270271
);
271272

272273
array.inner = children.remove(0);
@@ -381,9 +382,7 @@ mod tests {
381382
use crate::arrays::PrimitiveArray;
382383
use crate::assert_arrays_eq;
383384
use crate::builders::builder_with_capacity;
384-
use crate::dtype::Nullability;
385385
use crate::patches::Patches;
386-
use crate::scalar::Scalar;
387386
use crate::validity::Validity;
388387

389388
#[test]
@@ -419,43 +418,6 @@ mod tests {
419418
assert_eq!(executed, expected.freeze());
420419
}
421420

422-
#[test]
423-
fn test_scalar_at() {
424-
let values = buffer![0u16; 1024].into_array();
425-
let patches = Patches::new(
426-
1024,
427-
0,
428-
buffer![1u32, 2, 3].into_array(),
429-
buffer![1u16; 3].into_array(),
430-
None,
431-
)
432-
.unwrap();
433-
434-
let session = VortexSession::empty();
435-
let mut ctx = ExecutionCtx::new(session);
436-
437-
let array = PatchedArray::from_array_and_patches(values, &patches, &mut ctx)
438-
.unwrap()
439-
.into_array();
440-
441-
assert_eq!(
442-
array.scalar_at(0).unwrap(),
443-
Scalar::primitive(0u16, Nullability::NonNullable)
444-
);
445-
assert_eq!(
446-
array.scalar_at(1).unwrap(),
447-
Scalar::primitive(1u16, Nullability::NonNullable)
448-
);
449-
assert_eq!(
450-
array.scalar_at(2).unwrap(),
451-
Scalar::primitive(1u16, Nullability::NonNullable)
452-
);
453-
assert_eq!(
454-
array.scalar_at(3).unwrap(),
455-
Scalar::primitive(1u16, Nullability::NonNullable)
456-
);
457-
}
458-
459421
#[test]
460422
fn test_append_to_builder_non_nullable() {
461423
let values = PrimitiveArray::new(buffer![0u16; 1024], Validity::NonNullable).into_array();

0 commit comments

Comments
 (0)