Skip to content

Commit 5e8278a

Browse files
committed
wip
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent e7cbb4b commit 5e8278a

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

encodings/runend/src/arbitrary.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use vortex_array::LEGACY_SESSION;
99
use vortex_array::VortexSessionExecute;
1010
use vortex_array::arrays::PrimitiveArray;
1111
use vortex_array::arrays::arbitrary::ArbitraryArray;
12+
use vortex_array::arrays::arbitrary::ArbitraryWith;
1213
use vortex_array::dtype::DType;
1314
use vortex_array::dtype::Nullability;
1415
use vortex_array::dtype::PType;
@@ -46,14 +47,28 @@ impl ArbitraryRunEndArray {
4647
if num_runs == 0 {
4748
// Empty RunEndArray
4849
let ends = PrimitiveArray::from_iter(Vec::<u64>::new()).into_array();
49-
let values = ArbitraryArray::arbitrary_with(u, Some(0), dtype)?.0;
50+
let values = ArbitraryArray::arbitrary_with_config(
51+
u,
52+
&vortex_array::arrays::arbitrary::ArbitraryArrayConfig {
53+
dtype: Some(dtype.clone()),
54+
len: 0..=0,
55+
},
56+
)?
57+
.0;
5058
let runend_array = RunEnd::try_new(ends, values, &mut ctx)
5159
.vortex_expect("Empty RunEndArray creation should succeed");
5260
return Ok(ArbitraryRunEndArray(runend_array));
5361
}
5462

5563
// Generate arbitrary values for each run
56-
let values = ArbitraryArray::arbitrary_with(u, Some(num_runs), dtype)?.0;
64+
let values = ArbitraryArray::arbitrary_with_config(
65+
u,
66+
&vortex_array::arrays::arbitrary::ArbitraryArrayConfig {
67+
dtype: Some(dtype.clone()),
68+
len: num_runs..=num_runs,
69+
},
70+
)?
71+
.0;
5772

5873
// Generate strictly increasing ends
5974
// Each end must be > previous end, and first end must be >= 1

vortex-array/src/arrays/arbitrary.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ pub struct ArbitraryArrayConfig {
6060

6161
impl<'a> Arbitrary<'a> for ArbitraryArray {
6262
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
63-
let dtype = u.arbitrary()?;
64-
Self::arbitrary_with(u, None, &dtype)
63+
Self::arbitrary_with_config(
64+
u,
65+
&ArbitraryArrayConfig {
66+
dtype: None,
67+
len: DEFAULT_ARRAY_LEN_RANGE,
68+
},
69+
)
6570
}
6671
}
6772

@@ -84,12 +89,6 @@ impl<'a> ArbitraryWith<'a, ArbitraryArrayConfig> for ArbitraryArray {
8489
}
8590
}
8691

87-
impl ArbitraryArray {
88-
pub fn arbitrary_with(u: &mut Unstructured, len: Option<usize>, dtype: &DType) -> Result<Self> {
89-
random_array(u, dtype, len).map(ArbitraryArray)
90-
}
91-
}
92-
9392
fn split_number_into_parts(n: usize, parts: usize) -> Vec<usize> {
9493
let reminder = n % parts;
9594
let division = (n - reminder) / parts;

vortex-array/src/arrays/dict/arbitrary.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::ArrayRef;
1313
use crate::IntoArray;
1414
use crate::arrays::PrimitiveArray;
1515
use crate::arrays::arbitrary::ArbitraryArray;
16+
use crate::arrays::arbitrary::ArbitraryWith;
1617
use crate::arrays::arbitrary::random_validity;
1718
use crate::dtype::DType;
1819
use crate::dtype::NativePType;
@@ -36,7 +37,14 @@ impl ArbitraryDictArray {
3637
// Generate the number of unique values (dictionary size)
3738
let values_len = u.int_in_range(1..=20)?;
3839
// Generate values array with the given dtype
39-
let values = ArbitraryArray::arbitrary_with(u, Some(values_len), dtype)?.0;
40+
let values = ArbitraryArray::arbitrary_with_config(
41+
u,
42+
&crate::arrays::arbitrary::ArbitraryArrayConfig {
43+
dtype: Some(dtype.clone()),
44+
len: values_len..=values_len,
45+
},
46+
)?
47+
.0;
4048

4149
// Generate codes that index into the values
4250
let codes_len = len.unwrap_or(u.int_in_range(0..=100)?);

0 commit comments

Comments
 (0)