Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion encodings/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl VTable for ALPVTable {
metadata: &Self::Metadata,
_buffers: &[BufferHandle],
children: &dyn ArrayChildren,
) -> VortexResult<ALPArray> {
) -> VortexResult<ArrayRef> {
let encoded_ptype = match &dtype {
DType::Primitive(PType::F32, n) => DType::Primitive(PType::I32, *n),
DType::Primitive(PType::F64, n) => DType::Primitive(PType::I64, *n),
Expand Down Expand Up @@ -187,6 +187,7 @@ impl VTable for ALPVTable {
},
patches,
)
.map(|a| a.into_array())
}

fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()> {
Expand Down
3 changes: 2 additions & 1 deletion encodings/alp/src/alp_rd/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl VTable for ALPRDVTable {
metadata: &Self::Metadata,
_buffers: &[BufferHandle],
children: &dyn ArrayChildren,
) -> VortexResult<ALPRDArray> {
) -> VortexResult<ArrayRef> {
if children.len() < 2 {
vortex_bail!(
"Expected at least 2 children for ALPRD encoding, found {}",
Expand Down Expand Up @@ -252,6 +252,7 @@ impl VTable for ALPRDVTable {
})?,
left_parts_patches,
)
.map(|a| a.into_array())
}

fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()> {
Expand Down
4 changes: 2 additions & 2 deletions encodings/bytebool/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl VTable for ByteBoolVTable {
_metadata: &Self::Metadata,
buffers: &[BufferHandle],
children: &dyn ArrayChildren,
) -> VortexResult<ByteBoolArray> {
) -> VortexResult<ArrayRef> {
let validity = if children.is_empty() {
Validity::from(dtype.nullability())
} else if children.len() == 1 {
Expand All @@ -155,7 +155,7 @@ impl VTable for ByteBoolVTable {
}
let buffer = buffers[0].clone();

Ok(ByteBoolArray::new(buffer, validity))
Ok(ByteBoolArray::new(buffer, validity).into_array())
}

fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()> {
Expand Down
3 changes: 2 additions & 1 deletion encodings/datetime-parts/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl VTable for DateTimePartsVTable {
metadata: &Self::Metadata,
_buffers: &[BufferHandle],
children: &dyn ArrayChildren,
) -> VortexResult<DateTimePartsArray> {
) -> VortexResult<ArrayRef> {
if children.len() != 3 {
vortex_bail!(
"Expected 3 children for datetime-parts encoding, found {}",
Expand All @@ -204,6 +204,7 @@ impl VTable for DateTimePartsVTable {
)?;

DateTimePartsArray::try_new(dtype.clone(), days, seconds, subseconds)
.map(|a| a.into_array())
}

fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()> {
Expand Down
4 changes: 2 additions & 2 deletions encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl VTable for DecimalBytePartsVTable {
metadata: &Self::Metadata,
_buffers: &[BufferHandle],
children: &dyn ArrayChildren,
) -> VortexResult<DecimalBytePartsArray> {
) -> VortexResult<ArrayRef> {
let Some(decimal_dtype) = dtype.as_decimal_opt() else {
vortex_bail!("decoding decimal but given non decimal dtype {}", dtype)
};
Expand All @@ -168,7 +168,7 @@ impl VTable for DecimalBytePartsVTable {
"lower_part_count > 0 not currently supported"
);

DecimalBytePartsArray::try_new(msp, *decimal_dtype)
DecimalBytePartsArray::try_new(msp, *decimal_dtype).map(|a| a.into_array())
}

fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()> {
Expand Down
28 changes: 14 additions & 14 deletions encodings/fastlanes/benches/bitpacking_take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
fn take_10_stratified(bencher: Bencher) {
let values = fixture(1_000_000, 8);
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = PrimitiveArray::from_iter((0..10).map(|i| i * 10_000));

bencher
Expand All @@ -48,7 +48,7 @@ fn take_10_stratified(bencher: Bencher) {
fn take_10_contiguous(bencher: Bencher) {
let values = fixture(1_000_000, 8);
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = buffer![0..10].into_array();

bencher
Expand All @@ -67,7 +67,7 @@ fn take_10k_random(bencher: Bencher) {
let values = fixture(1_000_000, 8);
let range = Uniform::new(0, values.len()).unwrap();
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();

let rng = StdRng::seed_from_u64(0);
let indices = PrimitiveArray::from_iter(rng.sample_iter(range).take(10_000).map(|i| i as u32));
Expand All @@ -87,7 +87,7 @@ fn take_10k_random(bencher: Bencher) {
fn take_10k_contiguous(bencher: Bencher) {
let values = fixture(1_000_000, 8);
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = PrimitiveArray::from_iter(0..10_000);

bencher
Expand All @@ -105,7 +105,7 @@ fn take_10k_contiguous(bencher: Bencher) {
fn take_200k_dispersed(bencher: Bencher) {
let values = fixture(1_000_000, 8);
let uncompressed = PrimitiveArray::new(values.clone(), Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| (i * 42) % values.len() as u64));

bencher
Expand All @@ -123,7 +123,7 @@ fn take_200k_dispersed(bencher: Bencher) {
fn take_200k_first_chunk_only(bencher: Bencher) {
let values = fixture(1_000_000, 8);
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| ((i * 42) % 1024) as u64));

bencher
Expand Down Expand Up @@ -161,7 +161,7 @@ const NUM_EXCEPTIONS: u32 = 10000;
fn patched_take_10_stratified(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();

assert!(packed.patches().is_some());
assert_eq!(
Expand All @@ -186,7 +186,7 @@ fn patched_take_10_stratified(bencher: Bencher) {
fn patched_take_10_contiguous(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();

assert!(packed.patches().is_some());
assert_eq!(
Expand All @@ -211,7 +211,7 @@ fn patched_take_10_contiguous(bencher: Bencher) {
fn patched_take_10k_random(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values.clone(), Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();

let rng = StdRng::seed_from_u64(0);
let range = Uniform::new(0, values.len()).unwrap();
Expand All @@ -232,7 +232,7 @@ fn patched_take_10k_random(bencher: Bencher) {
fn patched_take_10k_contiguous_not_patches(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = PrimitiveArray::from_iter((0u32..NUM_EXCEPTIONS).cycle().take(10000));

bencher
Expand All @@ -250,7 +250,7 @@ fn patched_take_10k_contiguous_not_patches(bencher: Bencher) {
fn patched_take_10k_contiguous_patches(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();

assert!(packed.patches().is_some());
assert_eq!(
Expand All @@ -276,7 +276,7 @@ fn patched_take_10k_contiguous_patches(bencher: Bencher) {
fn patched_take_200k_dispersed(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values.clone(), Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| (i * 42) % values.len() as u64));

bencher
Expand All @@ -294,7 +294,7 @@ fn patched_take_200k_dispersed(bencher: Bencher) {
fn patched_take_200k_first_chunk_only(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| ((i * 42) % 1024) as u64));

bencher
Expand All @@ -312,7 +312,7 @@ fn patched_take_200k_first_chunk_only(bencher: Bencher) {
fn patched_take_10k_adversarial(bencher: Bencher) {
let values = (0u32..BIG_BASE2 + NUM_EXCEPTIONS).collect::<Buffer<u32>>();
let uncompressed = PrimitiveArray::new(values, Validity::NonNullable);
let packed = bitpack_to_best_bit_width(&uncompressed).unwrap();
let (packed, _) = bitpack_to_best_bit_width(&uncompressed).unwrap();
let per_chunk_count = 100;
let indices = PrimitiveArray::from_iter(
(0..(NUM_EXCEPTIONS + 1024) / 1024)
Expand Down
6 changes: 5 additions & 1 deletion encodings/fastlanes/benches/compute_between.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ fn generate_bit_pack_primitive_array<T: NativePType + NumCast>(
.map(|_| T::from_usize(rng.random_range(0..10_000)).vortex_expect(""))
.collect::<PrimitiveArray>();

bitpack_to_best_bit_width(&a).vortex_expect("").into_array()
bitpack_to_best_bit_width(&a)
.vortex_expect("")
.0
.into_array()
}

fn generate_alp_bit_pack_primitive_array<T: NativePType + NumCast>(
Expand All @@ -55,6 +58,7 @@ fn generate_alp_bit_pack_primitive_array<T: NativePType + NumCast>(

let bp = bitpack_to_best_bit_width(&encoded)
.vortex_expect("")
.0
.into_array();
ALPArray::new(bp, alp.exponents(), None).into_array()
}
Expand Down
11 changes: 6 additions & 5 deletions encodings/fastlanes/src/bitpacking/array/bitpack_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use vortex_mask::Mask;
use crate::BitPackedArray;
use crate::bitpack_decompress;

pub fn bitpack_to_best_bit_width(array: &PrimitiveArray) -> VortexResult<BitPackedArray> {
pub fn bitpack_to_best_bit_width(
array: &PrimitiveArray,
) -> VortexResult<(BitPackedArray, Option<Patches>)> {
let bit_width_freq = bit_width_histogram(array)?;
let best_bit_width = find_best_bit_width(array.ptype(), &bit_width_freq)?;
bitpack_encode(array, best_bit_width, Some(&bit_width_freq))
Expand All @@ -38,7 +40,7 @@ pub fn bitpack_encode(
array: &PrimitiveArray,
bit_width: u8,
bit_width_freq: Option<&[usize]>,
) -> VortexResult<BitPackedArray> {
) -> VortexResult<(BitPackedArray, Option<Patches>)> {
let bit_width_freq = match bit_width_freq {
Some(freq) => freq,
None => &bit_width_histogram(array)?,
Expand Down Expand Up @@ -77,7 +79,6 @@ pub fn bitpack_encode(
BufferHandle::new_host(packed),
array.dtype().clone(),
array.validity().clone(),
patches,
bit_width,
array.len(),
0,
Expand All @@ -87,7 +88,8 @@ pub fn bitpack_encode(
.stats_set
.to_ref(bitpacked.as_ref())
.inherit_from(array.statistics());
Ok(bitpacked)

Ok((bitpacked, patches))
}

/// Bitpack an array into the specified bit-width without checking statistics.
Expand All @@ -111,7 +113,6 @@ pub unsafe fn bitpack_encode_unchecked(
BufferHandle::new_host(packed),
array.dtype().clone(),
array.validity().clone(),
None,
bit_width,
array.len(),
0,
Expand Down
Loading
Loading