Skip to content

Commit 56d6222

Browse files
committed
feat: add an arrays slots macro
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent a30de02 commit 56d6222

61 files changed

Lines changed: 872 additions & 277 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
# Core crates in dependency order
4+
"vortex-array-macros",
45
"vortex-error",
56
"vortex-buffer",
67
"vortex-mask",
@@ -238,6 +239,7 @@ tempfile = "3"
238239
termtree = { version = "1.0" }
239240
test-with = "0.15"
240241
thiserror = "2.0.3"
242+
vortex-array-macros = { path = "./vortex-array-macros" }
241243
tokio = { version = "1.48" }
242244
tokio-stream = "0.1.17"
243245
tokio-util = "0.7.17"

encodings/alp/public-api.lock

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,58 @@ pub fn vortex_alp::ALPRDMetadata::clear(&mut self)
296296

297297
pub fn vortex_alp::ALPRDMetadata::encoded_len(&self) -> usize
298298

299+
pub struct vortex_alp::ALPSlots
300+
301+
pub vortex_alp::ALPSlots::encoded: vortex_array::array::erased::ArrayRef
302+
303+
pub vortex_alp::ALPSlots::patch_chunk_offsets: core::option::Option<vortex_array::array::erased::ArrayRef>
304+
305+
pub vortex_alp::ALPSlots::patch_indices: core::option::Option<vortex_array::array::erased::ArrayRef>
306+
307+
pub vortex_alp::ALPSlots::patch_values: core::option::Option<vortex_array::array::erased::ArrayRef>
308+
309+
impl vortex_alp::ALPSlots
310+
311+
pub const vortex_alp::ALPSlots::COUNT: usize
312+
313+
pub const vortex_alp::ALPSlots::ENCODED: usize
314+
315+
pub const vortex_alp::ALPSlots::NAMES: [&'static str; 4]
316+
317+
pub const vortex_alp::ALPSlots::PATCH_CHUNK_OFFSETS: usize
318+
319+
pub const vortex_alp::ALPSlots::PATCH_INDICES: usize
320+
321+
pub const vortex_alp::ALPSlots::PATCH_VALUES: usize
322+
323+
pub fn vortex_alp::ALPSlots::from_slots(slots: alloc::vec::Vec<core::option::Option<vortex_array::array::erased::ArrayRef>>) -> Self
324+
325+
pub fn vortex_alp::ALPSlots::into_slots(self) -> alloc::vec::Vec<core::option::Option<vortex_array::array::erased::ArrayRef>>
326+
327+
pub struct vortex_alp::ALPSlotsView<'a>
328+
329+
pub vortex_alp::ALPSlotsView::encoded: &'a vortex_array::array::erased::ArrayRef
330+
331+
pub vortex_alp::ALPSlotsView::patch_chunk_offsets: core::option::Option<&'a vortex_array::array::erased::ArrayRef>
332+
333+
pub vortex_alp::ALPSlotsView::patch_indices: core::option::Option<&'a vortex_array::array::erased::ArrayRef>
334+
335+
pub vortex_alp::ALPSlotsView::patch_values: core::option::Option<&'a vortex_array::array::erased::ArrayRef>
336+
337+
impl<'a> vortex_alp::ALPSlotsView<'a>
338+
339+
pub fn vortex_alp::ALPSlotsView<'a>::from_slots(slots: &'a [core::option::Option<vortex_array::array::erased::ArrayRef>]) -> Self
340+
341+
impl<'a> core::clone::Clone for vortex_alp::ALPSlotsView<'a>
342+
343+
pub fn vortex_alp::ALPSlotsView<'a>::clone(&self) -> vortex_alp::ALPSlotsView<'a>
344+
345+
impl<'a> core::fmt::Debug for vortex_alp::ALPSlotsView<'a>
346+
347+
pub fn vortex_alp::ALPSlotsView<'a>::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
348+
349+
impl<'a> core::marker::Copy for vortex_alp::ALPSlotsView<'a>
350+
299351
pub struct vortex_alp::Exponents
300352

301353
pub vortex_alp::Exponents::e: u8
@@ -338,18 +390,14 @@ pub fn vortex_alp::RDEncoder::from_parts(right_bit_width: u8, codes: alloc::vec:
338390

339391
pub fn vortex_alp::RDEncoder::new<T>(sample: &[T]) -> Self where T: vortex_alp::ALPRDFloat + vortex_array::dtype::ptype::NativePType, <T as vortex_alp::ALPRDFloat>::UINT: vortex_array::dtype::ptype::NativePType
340392

341-
pub trait vortex_alp::ALPArrayExt: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>
342-
343-
pub fn vortex_alp::ALPArrayExt::encoded(&self) -> &vortex_array::array::erased::ArrayRef
393+
pub trait vortex_alp::ALPArrayExt: vortex_alp::ALPArraySlotsExt
344394

345395
pub fn vortex_alp::ALPArrayExt::exponents(&self) -> vortex_alp::Exponents
346396

347397
pub fn vortex_alp::ALPArrayExt::patches(&self) -> core::option::Option<vortex_array::patches::Patches>
348398

349399
impl<T: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>> vortex_alp::ALPArrayExt for T
350400

351-
pub fn T::encoded(&self) -> &vortex_array::array::erased::ArrayRef
352-
353401
pub fn T::exponents(&self) -> vortex_alp::Exponents
354402

355403
pub fn T::patches(&self) -> core::option::Option<vortex_array::patches::Patches>
@@ -362,6 +410,30 @@ impl vortex_alp::ALPArrayOwnedExt for vortex_array::array::typed::Array<vortex_a
362410

363411
pub fn vortex_array::array::typed::Array<vortex_alp::ALP>::into_parts(self) -> (vortex_array::array::erased::ArrayRef, vortex_alp::Exponents, core::option::Option<vortex_array::patches::Patches>)
364412

413+
pub trait vortex_alp::ALPArraySlotsExt: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>
414+
415+
pub fn vortex_alp::ALPArraySlotsExt::encoded(&self) -> &vortex_array::array::erased::ArrayRef
416+
417+
pub fn vortex_alp::ALPArraySlotsExt::patch_chunk_offsets(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
418+
419+
pub fn vortex_alp::ALPArraySlotsExt::patch_indices(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
420+
421+
pub fn vortex_alp::ALPArraySlotsExt::patch_values(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
422+
423+
pub fn vortex_alp::ALPArraySlotsExt::slots_view(&self) -> vortex_alp::ALPSlotsView<'_>
424+
425+
impl<T: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>> vortex_alp::ALPArraySlotsExt for T
426+
427+
pub fn T::encoded(&self) -> &vortex_array::array::erased::ArrayRef
428+
429+
pub fn T::patch_chunk_offsets(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
430+
431+
pub fn T::patch_indices(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
432+
433+
pub fn T::patch_values(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
434+
435+
pub fn T::slots_view(&self) -> vortex_alp::ALPSlotsView<'_>
436+
365437
pub trait vortex_alp::ALPFloat: vortex_alp::alp::private::Sealed + num_traits::float::Float + core::fmt::Display + vortex_array::dtype::ptype::NativePType
366438

367439
pub type vortex_alp::ALPFloat::ALPInt: num_traits::int::PrimInt + core::fmt::Display + num_traits::cast::ToPrimitive + core::marker::Copy + vortex_array::dtype::ptype::NativePType + core::convert::Into<vortex_array::scalar::typed_view::primitive::pvalue::PValue>

encodings/alp/src/alp/array.rs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ impl VTable for ALP {
8585
dtype,
8686
len,
8787
data.exponents,
88-
slots[ENCODED_SLOT]
89-
.as_ref()
90-
.vortex_expect("ALPArray encoded slot"),
88+
ALPSlotsView::from_slots(slots).encoded,
9189
patches_from_slots(
9290
slots,
9391
data.patch_offset,
@@ -170,16 +168,16 @@ impl VTable for ALP {
170168
}
171169

172170
fn slot_name(_array: ArrayView<'_, Self>, idx: usize) -> String {
173-
SLOT_NAMES[idx].to_string()
171+
ALPSlots::NAMES[idx].to_string()
174172
}
175173

176174
fn execute(array: Array<Self>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
177-
let array = require_child!(array, array.encoded(), ENCODED_SLOT => Primitive);
175+
let array = require_child!(array, array.encoded(), ALPSlots::ENCODED => Primitive);
178176
require_patches!(
179177
array,
180-
PATCH_INDICES_SLOT,
181-
PATCH_VALUES_SLOT,
182-
PATCH_CHUNK_OFFSETS_SLOT
178+
ALPSlots::PATCH_INDICES,
179+
ALPSlots::PATCH_VALUES,
180+
ALPSlots::PATCH_CHUNK_OFFSETS
183181
);
184182

185183
Ok(ExecutionResult::done(
@@ -205,21 +203,17 @@ impl VTable for ALP {
205203
}
206204
}
207205

208-
/// The ALP-encoded values array.
209-
pub(super) const ENCODED_SLOT: usize = 0;
210-
/// The indices of exception values that could not be ALP-encoded.
211-
pub(super) const PATCH_INDICES_SLOT: usize = 1;
212-
/// The exception values that could not be ALP-encoded.
213-
pub(super) const PATCH_VALUES_SLOT: usize = 2;
214-
/// Chunk offsets for the patch indices/values.
215-
pub(super) const PATCH_CHUNK_OFFSETS_SLOT: usize = 3;
216-
pub(super) const NUM_SLOTS: usize = 4;
217-
pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = [
218-
"encoded",
219-
"patch_indices",
220-
"patch_values",
221-
"patch_chunk_offsets",
222-
];
206+
#[vortex_array::array_slots(ALP)]
207+
pub struct ALPSlots {
208+
/// The ALP-encoded values array.
209+
pub encoded: ArrayRef,
210+
/// The indices of exception values that could not be ALP-encoded.
211+
pub patch_indices: Option<ArrayRef>,
212+
/// The exception values that could not be ALP-encoded.
213+
pub patch_values: Option<ArrayRef>,
214+
/// Chunk offsets for the patch indices/values.
215+
pub patch_chunk_offsets: Option<ArrayRef>,
216+
}
223217

224218
#[derive(Clone, Debug)]
225219
pub struct ALPData {
@@ -439,13 +433,7 @@ impl ALPData {
439433
}
440434
}
441435

442-
pub trait ALPArrayExt: TypedArrayRef<ALP> {
443-
fn encoded(&self) -> &ArrayRef {
444-
self.as_ref().slots()[ENCODED_SLOT]
445-
.as_ref()
446-
.vortex_expect("ALPArray encoded slot")
447-
}
448-
436+
pub trait ALPArrayExt: ALPArraySlotsExt {
449437
fn exponents(&self) -> Exponents {
450438
self.exponents
451439
}
@@ -466,7 +454,8 @@ fn patches_from_slots(
466454
patch_offset_within_chunk: Option<usize>,
467455
len: usize,
468456
) -> Option<Patches> {
469-
match (&slots[PATCH_INDICES_SLOT], &slots[PATCH_VALUES_SLOT]) {
457+
let view = ALPSlotsView::from_slots(slots);
458+
match (view.patch_indices, view.patch_values) {
470459
(Some(indices), Some(values)) => {
471460
let patch_offset = patch_offset.vortex_expect("has patch slots but no patch_offset");
472461
Some(unsafe {
@@ -475,7 +464,7 @@ fn patches_from_slots(
475464
patch_offset,
476465
indices.clone(),
477466
values.clone(),
478-
slots[PATCH_CHUNK_OFFSETS_SLOT].clone(),
467+
view.patch_chunk_offsets.cloned(),
479468
patch_offset_within_chunk,
480469
)
481470
})

encodings/alp/src/alp/compress.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ mod tests {
135135

136136
use super::*;
137137
use crate::alp::array::ALPArrayExt;
138+
use crate::alp::array::ALPArraySlotsExt;
138139
use crate::decompress_into_array;
139140

140141
#[test]

encodings/alp/src/alp/compute/between.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex_error::VortexResult;
2020
use crate::ALP;
2121
use crate::ALPFloat;
2222
use crate::alp::array::ALPArrayExt;
23+
use crate::alp::array::ALPArraySlotsExt;
2324
use crate::match_each_alp_float_ptype;
2425

2526
impl BetweenReduce for ALP {
@@ -103,6 +104,7 @@ mod tests {
103104

104105
use crate::ALPArray;
105106
use crate::alp::array::ALPArrayExt;
107+
use crate::alp::array::ALPArraySlotsExt;
106108
use crate::alp::compute::between::between_impl;
107109
use crate::alp_encode;
108110

encodings/alp/src/alp/compute/cast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use vortex_array::scalar_fn::fns::cast::CastReduce;
1111
use vortex_error::VortexResult;
1212

1313
use crate::ALPArrayExt;
14+
use crate::ALPArraySlotsExt;
1415
use crate::alp::ALP;
1516

1617
impl CastReduce for ALP {
@@ -72,6 +73,7 @@ mod tests {
7273
use vortex_error::VortexResult;
7374

7475
use crate::alp::array::ALPArrayExt;
76+
use crate::alp::array::ALPArraySlotsExt;
7577
use crate::alp_encode;
7678

7779
#[test]

encodings/alp/src/alp/compute/compare.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex_error::vortex_err;
2020

2121
use crate::ALP;
2222
use crate::ALPArrayExt;
23+
use crate::ALPArraySlotsExt;
2324
use crate::ALPFloat;
2425
use crate::match_each_alp_float_ptype;
2526

encodings/alp/src/alp/compute/filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use vortex_mask::Mask;
1111

1212
use crate::ALP;
1313
use crate::ALPArrayExt;
14+
use crate::ALPArraySlotsExt;
1415

1516
impl FilterKernel for ALP {
1617
fn filter(

encodings/alp/src/alp/compute/mask.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use vortex_error::VortexResult;
1313

1414
use crate::ALP;
1515
use crate::ALPArrayExt;
16+
use crate::ALPArraySlotsExt;
1617

1718
impl MaskReduce for ALP {
1819
fn mask(array: ArrayView<'_, Self>, mask: &ArrayRef) -> VortexResult<Option<ArrayRef>> {
@@ -66,6 +67,7 @@ mod test {
6667
use vortex_buffer::buffer;
6768

6869
use crate::alp::array::ALPArrayExt;
70+
use crate::alp::array::ALPArraySlotsExt;
6971
use crate::alp_encode;
7072

7173
#[rstest]

0 commit comments

Comments
 (0)