diff --git a/vortex-alp/src/compress.rs b/vortex-alp/src/compress.rs index 1889992df0..d648f23571 100644 --- a/vortex-alp/src/compress.rs +++ b/vortex-alp/src/compress.rs @@ -98,7 +98,7 @@ where PrimitiveArray::from(exc_pos).into_array(), PrimitiveArray::from_vec(exc, Validity::AllValid).into_array(), len, - Scalar::null(&values.dtype().as_nullable()), + Scalar::null(values.dtype().as_nullable()), ) .into_array() }), diff --git a/vortex-alp/src/compute.rs b/vortex-alp/src/compute.rs index 169bb56a8d..562bf77861 100644 --- a/vortex-alp/src/compute.rs +++ b/vortex-alp/src/compute.rs @@ -30,7 +30,7 @@ impl ScalarAtFn for ALPArray<'_> { use crate::ALPFloat; let encoded_val = scalar_at(&self.encoded(), index)?; match_each_alp_float_ptype!(self.dtype().try_into().unwrap(), |$T| { - let encoded_val: <$T as ALPFloat>::ALPInt = encoded_val.try_into().unwrap(); + let encoded_val: <$T as ALPFloat>::ALPInt = encoded_val.as_ref().try_into().unwrap(); Scalar::from(<$T as ALPFloat>::decode_single( encoded_val, self.exponents(), diff --git a/vortex-dict/src/compress.rs b/vortex-dict/src/compress.rs index 5bf38875b2..60661b35ad 100644 --- a/vortex-dict/src/compress.rs +++ b/vortex-dict/src/compress.rs @@ -11,8 +11,8 @@ use vortex::compress::{CompressConfig, Compressor, EncodingCompression}; use vortex::stats::ArrayStatistics; use vortex::validity::Validity; use vortex::{Array, ArrayDType, ArrayDef, IntoArray, OwnedArray, ToArray}; -use vortex_dtype::NativePType; use vortex_dtype::{match_each_native_ptype, DType}; +use vortex_dtype::{NativePType, ToBytes}; use vortex_error::VortexResult; use crate::dict::{DictArray, DictEncoding}; @@ -92,19 +92,19 @@ impl EncodingCompression for DictEncoding { #[derive(Debug)] struct Value(T); -impl Hash for Value { +impl Hash for Value { fn hash(&self, state: &mut H) { - self.0.as_bytes().hash(state) + self.0.to_le_bytes().hash(state) } } -impl PartialEq for Value { +impl PartialEq for Value { fn eq(&self, other: &Self) -> bool { - self.0.as_bytes().eq(other.0.as_bytes()) + self.0.to_le_bytes().eq(other.0.to_le_bytes()) } } -impl Eq for Value {} +impl Eq for Value {} /// Dictionary encode primitive array with given PType. /// Null values in the original array are encoded in the dictionary. @@ -254,7 +254,8 @@ mod test { use vortex::array::varbin::VarBinArray; use vortex::compute::scalar_at::scalar_at; use vortex::ToArray; - use vortex_scalar::PrimitiveScalar; + use vortex_dtype::PType; + use vortex_scalar::{PrimitiveScalar, Scalar}; use crate::compress::{dict_encode_typed_primitive, dict_encode_varbin}; @@ -285,7 +286,7 @@ mod test { ); assert_eq!( scalar_at(&values.to_array(), 0).unwrap(), - PrimitiveScalar::nullable::(None).into() + Scalar::null(PType::I32.into()) ); assert_eq!( scalar_at(&values.to_array(), 1).unwrap(), diff --git a/vortex-dict/src/compute.rs b/vortex-dict/src/compute.rs index ef26882dd9..2c5a9c8153 100644 --- a/vortex-dict/src/compute.rs +++ b/vortex-dict/src/compute.rs @@ -24,7 +24,7 @@ impl ArrayCompute for DictArray<'_> { impl ScalarAtFn for DictArray<'_> { fn scalar_at(&self, index: usize) -> VortexResult { - let dict_index: usize = scalar_at(&self.codes(), index)?.try_into()?; + let dict_index: usize = scalar_at(&self.codes(), index)?.as_ref().try_into()?; scalar_at(&self.values(), dict_index) } } diff --git a/vortex-dict/src/dict.rs b/vortex-dict/src/dict.rs index b048629faa..2f5ebba372 100644 --- a/vortex-dict/src/dict.rs +++ b/vortex-dict/src/dict.rs @@ -56,7 +56,11 @@ impl ArrayFlatten for DictArray<'_> { impl ArrayValidity for DictArray<'_> { fn is_valid(&self, index: usize) -> bool { - let values_index = scalar_at(&self.codes(), index).unwrap().try_into().unwrap(); + let values_index = scalar_at(&self.codes(), index) + .unwrap() + .as_ref() + .try_into() + .unwrap(); self.values().with_dyn(|a| a.is_valid(values_index)) } diff --git a/vortex-dtype/src/lib.rs b/vortex-dtype/src/lib.rs index 869eff844a..12a7be5aa9 100644 --- a/vortex-dtype/src/lib.rs +++ b/vortex-dtype/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg(target_endian = "little")] + pub use dtype::*; pub use extension::*; pub use half; @@ -12,6 +14,7 @@ mod serialize; pub mod flatbuffers { #[allow(unused_imports)] #[allow(dead_code)] + #[allow(dead_code)] #[allow(clippy::all)] #[allow(non_camel_case_types)] mod generated { diff --git a/vortex-dtype/src/ptype.rs b/vortex-dtype/src/ptype.rs index e216bf596a..e44b77e66f 100644 --- a/vortex-dtype/src/ptype.rs +++ b/vortex-dtype/src/ptype.rs @@ -1,4 +1,5 @@ use std::fmt::{Debug, Display, Formatter}; +use std::hash::Hash; use std::panic::RefUnwindSafe; use num_traits::{FromPrimitive, Num, NumCast}; @@ -249,7 +250,7 @@ impl From for DType { } pub trait ToBytes: Sized { - fn to_le_bytes(&self) -> Vec; + fn to_le_bytes(&self) -> &[u8]; } pub trait TryFromBytes: Sized { @@ -259,8 +260,12 @@ pub trait TryFromBytes: Sized { macro_rules! try_from_bytes { ($T:ty) => { impl ToBytes for $T { - fn to_le_bytes(&self) -> Vec { - <$T>::to_le_bytes(*self).into() + #[inline] + fn to_le_bytes(&self) -> &[u8] { + // NOTE(ngates): this assumes the platform is little-endian. Currently enforced + // with a flag cfg(target_endian = "little") + let raw_ptr = self as *const $T as *const u8; + unsafe { std::slice::from_raw_parts(raw_ptr, std::mem::size_of::<$T>()) } } } diff --git a/vortex-fastlanes/src/bitpacking/compute/mod.rs b/vortex-fastlanes/src/bitpacking/compute/mod.rs index dbb396ead3..d8cabc4fc2 100644 --- a/vortex-fastlanes/src/bitpacking/compute/mod.rs +++ b/vortex-fastlanes/src/bitpacking/compute/mod.rs @@ -236,11 +236,12 @@ mod test { .enumerate() .for_each(|(ti, i)| { assert_eq!( - u32::try_from(scalar_at(packed.array(), *i as usize).unwrap()).unwrap(), + u32::try_from(scalar_at(packed.array(), *i as usize).unwrap().as_ref()) + .unwrap(), values[*i as usize] ); assert_eq!( - u32::try_from(scalar_at(&taken, ti).unwrap()).unwrap(), + u32::try_from(scalar_at(&taken, ti).unwrap().as_ref()).unwrap(), values[*i as usize] ); }); diff --git a/vortex-ree/src/ree.rs b/vortex-ree/src/ree.rs index e80b67d012..648c3d5296 100644 --- a/vortex-ree/src/ree.rs +++ b/vortex-ree/src/ree.rs @@ -22,7 +22,7 @@ pub struct REEMetadata { impl REEArray<'_> { pub fn try_new(ends: Array, values: Array, validity: Validity) -> VortexResult { - let length: usize = scalar_at(&ends, ends.len() - 1)?.try_into()?; + let length: usize = scalar_at(&ends, ends.len() - 1)?.as_ref().try_into()?; Self::with_offset_and_size(ends, values, validity, length, 0) } diff --git a/vortex-zigzag/src/compute.rs b/vortex-zigzag/src/compute.rs index fc43083924..024be9349c 100644 --- a/vortex-zigzag/src/compute.rs +++ b/vortex-zigzag/src/compute.rs @@ -3,7 +3,7 @@ use vortex::compute::slice::{slice, SliceFn}; use vortex::compute::ArrayCompute; use vortex::{ArrayDType, IntoArray, OwnedArray}; use vortex_error::{vortex_err, VortexResult}; -use vortex_scalar::{PScalar, Scalar}; +use vortex_scalar::Scalar; use zigzag::ZigZag as ExternalZigZag; use crate::ZigZagArray;