Skip to content

Commit c95be55

Browse files
chore[fastlanes]: remove FoR unsigned transmute (#4252)
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 7a89e7f commit c95be55

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

docs/quickstart/python.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Use :func:`~vortex.compress` to compress the Vortex array and check the relative
3737

3838
>>> cvtx = vx.compress(vtx)
3939
>>> cvtx.nbytes
40-
14297
40+
14298
4141
>>> cvtx.nbytes / vtx.nbytes
4242
0.10...
4343

encodings/fastlanes/src/for/compress.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ impl FoRArray {
2020
.ok_or_else(|| vortex_err!("Min stat not found"))?;
2121

2222
let encoded = match_each_integer_ptype!(array.ptype(), |T| {
23-
let unsigned_ptype = array.ptype().to_unsigned();
24-
compress_primitive::<T>(array, T::try_from(&min)?)?
25-
.reinterpret_cast(unsigned_ptype)
26-
.into_array()
23+
compress_primitive::<T>(array, T::try_from(&min)?)?.into_array()
2724
});
2825
FoRArray::try_new(encoded, min)
2926
}
@@ -49,7 +46,7 @@ pub fn decompress(array: &FoRArray) -> VortexResult<PrimitiveArray> {
4946
let ptype = array.ptype();
5047

5148
// TODO(ngates): do we need this to be into_encoded() somehow?
52-
let encoded = array.encoded().to_primitive()?.reinterpret_cast(ptype);
49+
let encoded = array.encoded().to_primitive()?;
5350
let validity = encoded.validity().clone();
5451

5552
Ok(match_each_integer_ptype!(ptype, |T| {
@@ -82,6 +79,7 @@ mod test {
8279
use vortex_array::ToCanonical;
8380
use vortex_array::validity::Validity;
8481
use vortex_buffer::buffer;
82+
use vortex_dtype::PType;
8583
use vortex_scalar::Scalar;
8684

8785
use super::*;
@@ -109,10 +107,10 @@ mod test {
109107
let compressed = FoRArray::encode(array).unwrap();
110108
assert_eq!(compressed.dtype(), &dtype);
111109
assert!(compressed.dtype().is_signed_int());
112-
assert!(compressed.encoded().dtype().is_unsigned_int());
110+
assert!(compressed.encoded().dtype().is_signed_int());
113111

114112
let constant = compressed.encoded().as_constant().unwrap();
115-
assert_eq!(constant, Scalar::from(0u32));
113+
assert_eq!(constant, Scalar::from(0i32));
116114
}
117115

118116
#[test]
@@ -137,7 +135,11 @@ mod test {
137135
.unwrap()
138136
);
139137

140-
let encoded = compressed.encoded().to_primitive().unwrap();
138+
let encoded = compressed
139+
.encoded()
140+
.to_primitive()
141+
.unwrap()
142+
.reinterpret_cast(PType::U8);
141143
let encoded_bytes: &[u8] = encoded.as_slice::<u8>();
142144
let unsigned: Vec<u8> = (0..=u8::MAX).collect_vec();
143145
assert_eq!(encoded_bytes, unsigned.as_slice());

encodings/fastlanes/src/for/compute/compare.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868

6969
// Wrap up the RHS into a scalar and cast to the encoded DType (this will be the equivalent
7070
// unsigned integer type).
71-
let rhs = Scalar::primitive(rhs, nullability).reinterpret_cast(T::PTYPE.to_unsigned());
71+
let rhs = Scalar::primitive(rhs, nullability);
7272

7373
compare(
7474
lhs.encoded(),
@@ -94,7 +94,7 @@ mod tests {
9494
let reference = Scalar::from(10);
9595
// 10, 30, 12
9696
let lhs = FoRArray::try_new(
97-
PrimitiveArray::new(buffer!(0u32, 20, 2), Validity::AllValid).into_array(),
97+
PrimitiveArray::new(buffer!(0i32, 20, 2), Validity::AllValid).into_array(),
9898
reference,
9999
)
100100
.unwrap();
@@ -121,7 +121,7 @@ mod tests {
121121
let reference = Scalar::from(0);
122122
// 10, 30, 12
123123
let lhs = FoRArray::try_new(
124-
PrimitiveArray::new(buffer!(0u32, 20, 2), Validity::NonNullable).into_array(),
124+
PrimitiveArray::new(buffer!(0i32, 20, 2), Validity::NonNullable).into_array(),
125125
reference,
126126
)
127127
.unwrap();
@@ -147,7 +147,7 @@ mod tests {
147147
let reference = Scalar::from(10);
148148
// 10, 30, 12
149149
let lhs = FoRArray::try_new(
150-
PrimitiveArray::new(buffer!(0u32, 10, 1), Validity::AllValid).into_array(),
150+
PrimitiveArray::new(buffer!(0i32, 10, 1), Validity::AllValid).into_array(),
151151
reference,
152152
)
153153
.unwrap();
@@ -165,9 +165,13 @@ mod tests {
165165
#[test]
166166
fn compare_large_constant() {
167167
let reference = Scalar::from(-9219218377546224477i64);
168+
#[allow(clippy::cast_possible_truncation)]
168169
let lhs = FoRArray::try_new(
169-
PrimitiveArray::new(buffer![0u64, 9654309310445864926], Validity::AllValid)
170-
.into_array(),
170+
PrimitiveArray::new(
171+
buffer![0i64, 9654309310445864926u64 as i64],
172+
Validity::AllValid,
173+
)
174+
.into_array(),
171175
reference,
172176
)
173177
.unwrap();
@@ -176,7 +180,7 @@ mod tests {
176180
compare_constant(
177181
&lhs,
178182
435090932899640449i64,
179-
Nullability::NonNullable,
183+
Nullability::Nullable,
180184
Operator::Eq,
181185
),
182186
[false, true],
@@ -185,7 +189,7 @@ mod tests {
185189
compare_constant(
186190
&lhs,
187191
435090932899640449i64,
188-
Nullability::NonNullable,
192+
Nullability::Nullable,
189193
Operator::NotEq,
190194
),
191195
[true, false],

encodings/fastlanes/src/for/ops.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ impl OperationsVTable<FoRVTable> for FoRVTable {
1919
}
2020

2121
fn scalar_at(array: &FoRArray, index: usize) -> VortexResult<Scalar> {
22-
let encoded_pvalue = array
23-
.encoded()
24-
.scalar_at(index)?
25-
.reinterpret_cast(array.ptype());
22+
let encoded_pvalue = array.encoded().scalar_at(index)?;
2623
let encoded_pvalue = encoded_pvalue.as_primitive();
2724
let reference = array.reference_scalar();
2825
let reference = reference.as_primitive();

encodings/fastlanes/src/for/serde.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use vortex_array::{
99
ArrayBufferVisitor, ArrayChildVisitor, Canonical, DeserializeMetadata, SerializeMetadata,
1010
};
1111
use vortex_buffer::ByteBuffer;
12-
use vortex_dtype::{DType, PType};
12+
use vortex_dtype::DType;
1313
use vortex_error::{VortexResult, vortex_bail};
1414
use vortex_scalar::{Scalar, ScalarValue};
1515

@@ -40,10 +40,7 @@ impl SerdeVTable<FoRVTable> for FoRVTable {
4040
)
4141
}
4242

43-
let ptype = PType::try_from(dtype)?;
44-
let encoded_dtype = DType::Primitive(ptype.to_unsigned(), dtype.nullability());
45-
let encoded = children.get(0, &encoded_dtype, len)?;
46-
43+
let encoded = children.get(0, dtype, len)?;
4744
let reference = Scalar::new(dtype.clone(), metadata.clone());
4845

4946
FoRArray::try_new(encoded, reference)

0 commit comments

Comments
 (0)