-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make ALP-RD work for f32, more compute fns
- Loading branch information
Showing
9 changed files
with
331 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use vortex::compute::{filter, FilterFn}; | ||
use vortex::{Array, ArrayDType, IntoArray}; | ||
use vortex_error::VortexResult; | ||
|
||
use crate::ALPRDArray; | ||
|
||
impl FilterFn for ALPRDArray { | ||
fn filter(&self, predicate: &Array) -> VortexResult<Array> { | ||
let left_parts_exceptions = match self.left_parts_exceptions() { | ||
None => None, | ||
Some(exc) => Some(filter(&exc, predicate)?), | ||
}; | ||
|
||
Ok(ALPRDArray::try_new( | ||
self.dtype().clone(), | ||
filter(self.left_parts(), predicate)?, | ||
self.left_parts_dict(), | ||
filter(self.right_parts(), predicate)?, | ||
self.right_bit_width(), | ||
left_parts_exceptions, | ||
)? | ||
.into_array()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
use vortex::compute::ArrayCompute; | ||
use vortex::compute::unary::ScalarAtFn; | ||
use vortex::compute::{ArrayCompute, FilterFn, SliceFn, TakeFn}; | ||
|
||
use crate::ALPRDArray; | ||
|
||
mod filter; | ||
mod scalar_at; | ||
mod slice; | ||
mod take; | ||
|
||
impl ArrayCompute for ALPRDArray { | ||
fn filter(&self) -> Option<&dyn FilterFn> { | ||
Some(self) | ||
} | ||
|
||
fn scalar_at(&self) -> Option<&dyn ScalarAtFn> { | ||
Some(self) | ||
} | ||
|
||
fn slice(&self) -> Option<&dyn SliceFn> { | ||
Some(self) | ||
} | ||
|
||
fn take(&self) -> Option<&dyn TakeFn> { | ||
Some(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use vortex::compute::{slice, SliceFn}; | ||
use vortex::{Array, ArrayDType, IntoArray}; | ||
use vortex_error::VortexResult; | ||
|
||
use crate::ALPRDArray; | ||
|
||
impl SliceFn for ALPRDArray { | ||
fn slice(&self, start: usize, stop: usize) -> VortexResult<Array> { | ||
let left_parts_exceptions = match self.left_parts_exceptions() { | ||
None => None, | ||
Some(exc) => Some(slice(&exc, start, stop)?), | ||
}; | ||
|
||
Ok(ALPRDArray::try_new( | ||
self.dtype().clone(), | ||
slice(self.left_parts(), start, stop)?, | ||
self.left_parts_dict(), | ||
slice(self.right_parts(), start, stop)?, | ||
self.right_bit_width(), | ||
left_parts_exceptions, | ||
)? | ||
.into_array()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use vortex::array::PrimitiveArray; | ||
use vortex::compute::slice; | ||
use vortex::IntoArrayVariant; | ||
|
||
use crate::{Encoder, RealDouble}; | ||
|
||
#[test] | ||
fn test_slice() { | ||
let a = 0.1f64.next_up(); | ||
let b = 0.2f64.next_up(); | ||
let outlier = 3e100f64.next_up(); | ||
|
||
let array = PrimitiveArray::from(vec![a, b, outlier]); | ||
let encoded = Encoder::<RealDouble>::new(&[a, b]).encode(&array); | ||
|
||
assert!(encoded.left_parts_exceptions().is_some()); | ||
|
||
let decoded = slice(encoded.as_ref(), 1, 3) | ||
.unwrap() | ||
.into_primitive() | ||
.unwrap(); | ||
|
||
assert_eq!(decoded.maybe_null_slice::<f64>(), &[b, outlier]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use vortex::compute::{take, TakeFn}; | ||
use vortex::{Array, ArrayDType, IntoArray}; | ||
use vortex_error::VortexResult; | ||
|
||
use crate::ALPRDArray; | ||
|
||
impl TakeFn for ALPRDArray { | ||
fn take(&self, indices: &Array) -> VortexResult<Array> { | ||
let left_parts_exceptions = match self.left_parts_exceptions() { | ||
None => None, | ||
Some(exc) => Some(take(&exc, indices)?), | ||
}; | ||
|
||
Ok(ALPRDArray::try_new( | ||
self.dtype().clone(), | ||
take(self.left_parts(), indices)?, | ||
self.left_parts_dict(), | ||
take(self.right_parts(), indices)?, | ||
self.right_bit_width(), | ||
left_parts_exceptions, | ||
)? | ||
.into_array()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use vortex::array::PrimitiveArray; | ||
use vortex::compute::take; | ||
use vortex::IntoArrayVariant; | ||
|
||
use crate::{Encoder, RealDouble}; | ||
|
||
#[test] | ||
fn test_take() { | ||
let a = 0.1f64.next_up(); | ||
let b = 0.2f64.next_up(); | ||
let outlier = 3e100f64.next_up(); | ||
|
||
let array = PrimitiveArray::from(vec![a, b, outlier]); | ||
let encoded = Encoder::<RealDouble>::new(&[a, b]).encode(&array); | ||
|
||
assert!(encoded.left_parts_exceptions().is_some()); | ||
|
||
let taken = take(encoded.as_ref(), PrimitiveArray::from(vec![0, 2]).as_ref()) | ||
.unwrap() | ||
.into_primitive() | ||
.unwrap(); | ||
|
||
assert_eq!(taken.maybe_null_slice::<f64>(), &[a, outlier]); | ||
} | ||
} |
Oops, something went wrong.