Skip to content

Commit 8de8ad1

Browse files
committed
implement fsl in fuzz/
Signed-off-by: Connor Tsui <[email protected]>
1 parent 1172c56 commit 8de8ad1

7 files changed

Lines changed: 21 additions & 30 deletions

File tree

‎fuzz/src/array/compare.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn compare_canonical_array(
107107
operator,
108108
)
109109
}),
110-
DType::Struct(..) | DType::List(..) => {
110+
DType::Struct(..) | DType::List(..) | DType::FixedSizeList(..) => {
111111
let scalar_vals: Vec<Scalar> = (0..array.len()).map(|i| array.scalar_at(i)).collect();
112112
Ok(BoolArray::from_iter(
113113
scalar_vals
@@ -116,7 +116,6 @@ pub fn compare_canonical_array(
116116
)
117117
.into_array())
118118
}
119-
DType::FixedSizeList(..) => unimplemented!("TODO(connor)[FixedSizeList]"),
120119
d @ (DType::Null | DType::Extension(_)) => {
121120
unreachable!("DType {d} not supported for fuzzing")
122121
}

‎fuzz/src/array/filter.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn filter_canonical_array(array: &dyn Array, filter: &[bool]) -> VortexResul
9999
)
100100
.map(|a| a.into_array())
101101
}
102-
DType::List(..) => {
102+
DType::List(..) | DType::FixedSizeList(..) => {
103103
let mut indices = Vec::new();
104104
for (idx, bool) in filter.iter().enumerate() {
105105
if *bool {
@@ -108,7 +108,6 @@ pub fn filter_canonical_array(array: &dyn Array, filter: &[bool]) -> VortexResul
108108
}
109109
take_canonical_array_non_nullable_indices(array, indices.as_slice())
110110
}
111-
DType::FixedSizeList(..) => unimplemented!("TODO(connor)[FixedSizeList]"),
112111
d @ (DType::Null | DType::Extension(_)) => {
113112
unreachable!("DType {d} not supported for fuzzing")
114113
}

‎fuzz/src/array/mod.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,18 @@ impl<'a> Arbitrary<'a> for FuzzArrayAction {
215215
}
216216

217217
fn actions_for_dtype(dtype: &DType) -> HashSet<usize> {
218+
// We exclude compare on the nested types.
219+
let nested_actions = [0, 1, 2, 3, 4, 6];
220+
218221
match dtype {
219222
DType::Struct(sdt, _) => sdt
220223
.fields()
221224
.map(|child| actions_for_dtype(&child))
222225
// exclude compare
223-
.fold((0..=4).chain(iter::once(6)).collect(), |acc, actions| {
226+
.fold(nested_actions.into(), |acc, actions| {
224227
acc.intersection(&actions).copied().collect()
225228
}),
226-
// Once we support more list operations also recurse here on child dtype
227-
// compress, slice
228-
DType::List(..) => [0, 1].into_iter().collect(),
229+
DType::List(..) | DType::FixedSizeList(..) => nested_actions.into(),
229230
_ => ALL_ACTIONS.collect(),
230231
}
231232
}

‎fuzz/src/array/search_sorted.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,10 @@ pub fn search_sorted_canonical_array(
116116
};
117117
Ok(SearchNullableSlice(opt_values).search_sorted(&Some(to_find), side))
118118
}
119-
DType::Struct(..) => {
119+
DType::Struct(..) | DType::List(..) | DType::FixedSizeList(..) => {
120120
let scalar_vals = (0..array.len()).map(|i| array.scalar_at(i)).collect_vec();
121121
Ok(scalar_vals.search_sorted(&scalar.cast(array.dtype())?, side))
122122
}
123-
DType::List(..) => {
124-
let scalar_vals = (0..array.len()).map(|i| array.scalar_at(i)).collect_vec();
125-
Ok(scalar_vals.search_sorted(&scalar.cast(array.dtype())?, side))
126-
}
127-
DType::FixedSizeList(..) => unimplemented!("TODO(connor)[FixedSizeList]"),
128123
d @ (DType::Null | DType::Extension(_)) => {
129124
unreachable!("DType {d} not supported for fuzzing")
130125
}

‎fuzz/src/array/slice.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
use vortex_array::accessor::ArrayAccessor;
55
use vortex_array::arrays::{
6-
BoolArray, DecimalArray, ListArray, PrimitiveArray, StructArray, VarBinViewArray,
6+
BoolArray, DecimalArray, FixedSizeListArray, ListArray, PrimitiveArray, StructArray,
7+
VarBinViewArray,
78
};
89
use vortex_array::validity::Validity;
910
use vortex_array::{Array, ArrayRef, IntoArray, ToCanonical};
@@ -86,7 +87,15 @@ pub fn slice_canonical_array(
8687
.into_array();
8788
ListArray::try_new(elements, offsets, validity).map(|a| a.into_array())
8889
}
89-
DType::FixedSizeList(..) => unimplemented!("TODO(connor)[FixedSizeList]"),
90+
DType::FixedSizeList(..) => {
91+
let fsl_array = array.to_fixed_size_list();
92+
let list_size = fsl_array.list_size() as usize;
93+
let elements =
94+
slice_canonical_array(fsl_array.elements(), start * list_size, stop * list_size)?;
95+
96+
FixedSizeListArray::try_new(elements, fsl_array.list_size(), validity, array.len())
97+
.map(|a| a.into_array())
98+
}
9099
DType::Decimal(decimal_dtype, _) => {
91100
let decimal_array = array.to_decimal();
92101
Ok(

‎fuzz/src/array/sort.rs‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn sort_canonical_array(array: &dyn Array) -> VortexResult<ArrayRef> {
6161
opt_values.sort();
6262
Ok(VarBinViewArray::from_iter(opt_values, array.dtype().clone()).into_array())
6363
}
64-
DType::Struct(..) => {
64+
DType::Struct(..) | DType::List(..) | DType::FixedSizeList(..) => {
6565
let mut sort_indices = (0..array.len()).collect::<Vec<_>>();
6666
sort_indices.sort_by(|a, b| {
6767
array
@@ -71,17 +71,6 @@ pub fn sort_canonical_array(array: &dyn Array) -> VortexResult<ArrayRef> {
7171
});
7272
take_canonical_array_non_nullable_indices(array, &sort_indices)
7373
}
74-
DType::List(..) => {
75-
let mut sort_indices = (0..array.len()).collect::<Vec<_>>();
76-
sort_indices.sort_by(|a, b| {
77-
array
78-
.scalar_at(*a)
79-
.partial_cmp(&array.scalar_at(*b))
80-
.vortex_expect("must be a valid comparison")
81-
});
82-
take_canonical_array_non_nullable_indices(array, &sort_indices)
83-
}
84-
DType::FixedSizeList(..) => unimplemented!("TODO(connor)[FixedSizeList]"),
8574
d @ (DType::Null | DType::Extension(_)) => {
8675
unreachable!("DType {d} not supported for fuzzing")
8776
}

‎fuzz/src/array/take.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn take_canonical_array(
113113
)
114114
.map(|a| a.into_array())
115115
}
116-
DType::List(..) => {
116+
DType::List(..) | DType::FixedSizeList(..) => {
117117
let mut builder = builder_with_capacity(array.dtype(), indices_slice_non_opt.len());
118118
for idx in indices {
119119
if let Some(idx) = idx {
@@ -124,7 +124,6 @@ pub fn take_canonical_array(
124124
}
125125
Ok(builder.finish())
126126
}
127-
DType::FixedSizeList(..) => unimplemented!("TODO(connor)[FixedSizeList]"),
128127
d @ (DType::Null | DType::Extension(_)) => {
129128
unreachable!("DType {d} not supported for fuzzing")
130129
}

0 commit comments

Comments
 (0)