Skip to content

Commit

Permalink
Clippy fixes (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
psvri authored Nov 16, 2023
1 parent f131267 commit 3e7401c
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 66 deletions.
4 changes: 2 additions & 2 deletions crates/arithmetic/src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ mod tests {
)]
async fn test_large_f32_array() {
let device = Arc::new(GpuDevice::new().await);
let gpu_array = Float32ArrayGPU::from_vec(
let gpu_array = Float32ArrayGPU::from_slice(
&(0..1024 * 1024 * 10)
.into_iter()
.map(|x| x as f32)
.collect::<Vec<f32>>(),
device.clone(),
);
let values_array = Float32ArrayGPU::from_vec(&vec![100.0], device);
let values_array = Float32ArrayGPU::from_slice(&vec![100.0], device);
let new_gpu_array = gpu_array.add_scalar(&values_array).await;
for (index, value) in new_gpu_array
.raw_values()
Expand Down
8 changes: 0 additions & 8 deletions crates/array/src/array/boolean_gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ impl BooleanArrayGPU {
}
}

pub fn from_optional_vec(value: &Vec<Option<bool>>, gpu_device: Arc<GpuDevice>) -> Self {
Self::from_optional_slice(&value[..], gpu_device)
}

//TODO write test case
pub fn from_slice(value: &[bool], gpu_device: Arc<GpuDevice>) -> Self {
let mut buffer = BooleanBufferBuilder::new_with_capacity(value.len());
Expand Down Expand Up @@ -91,10 +87,6 @@ impl BooleanArrayGPU {
}
}

pub fn from_bytes_vec(value: &Vec<u8>, gpu_device: Arc<GpuDevice>) -> Self {
Self::from_bytes_slice(&value[..], gpu_device)
}

pub async fn raw_values(&self) -> Option<Vec<bool>> {
let result = self.gpu_device.retrive_data(&self.data).await;
let result: Vec<u8> = bytemuck::cast_slice(&result).to_vec();
Expand Down
8 changes: 4 additions & 4 deletions crates/array/src/array/f32_gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod tests {
#[tokio::test]
async fn test_f32_sum() {
let device = Arc::new(GpuDevice::new().await);
let gpu_array = Float32ArrayGPU::from_vec(
let gpu_array = Float32ArrayGPU::from_slice(
&(0..256 * 256)
.into_iter()
.map(|_| 1.0)
Expand All @@ -111,14 +111,14 @@ mod tests {
.map(|x| x as f32)
.collect::<Vec<f32>>();
let total = (0..9_999u32).into_iter().sum::<u32>() as f32;
let gpu_array = Float32ArrayGPU::from_vec(&cvec, device);
let gpu_array = Float32ArrayGPU::from_slice(&cvec, device);
assert_eq!(gpu_array.sum().await, total);
}

#[tokio::test]
async fn test_f32_array_from_optinal_vec() {
let device = Arc::new(GpuDevice::new().await);
let gpu_array_1 = Float32ArrayGPU::from_optional_vec(
let gpu_array_1 = Float32ArrayGPU::from_optional_slice(
&vec![Some(0.0), Some(1.0), None, None, Some(4.0)],
device.clone(),
);
Expand All @@ -130,7 +130,7 @@ mod tests {
gpu_array_1.null_buffer.as_ref().unwrap().raw_values().await,
vec![0b00010011]
);
let gpu_array_2 = Float32ArrayGPU::from_optional_vec(
let gpu_array_2 = Float32ArrayGPU::from_optional_slice(
&vec![Some(1.0), Some(2.0), None, Some(4.0), None],
device,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/array/src/array/gpu_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl GpuDevice {

let mut encoder = self.create_command_encoder(None);
let dispatch_size = original_values.size() / item_size;

dbg!(dispatch_size);
let query = self.compute_pass(
&mut encoder,
None,
Expand Down
11 changes: 0 additions & 11 deletions crates/array/src/array/primitive_array_gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ impl<T: ArrowPrimitiveType> PrimitiveArrayGpu<T> {
}
}

pub fn from_optional_vec(
value: &Vec<Option<T::NativeType>>,
gpu_device: Arc<GpuDevice>,
) -> Self {
Self::from_optional_slice(&value[..], gpu_device)
}

pub fn from_slice(value: &[T::NativeType], gpu_device: Arc<GpuDevice>) -> Self {
let data = gpu_device.create_gpu_buffer_with_data(value);
let null_buffer = None;
Expand All @@ -73,10 +66,6 @@ impl<T: ArrowPrimitiveType> PrimitiveArrayGpu<T> {
}
}

pub fn from_vec(value: &Vec<T::NativeType>, gpu_device: Arc<GpuDevice>) -> Self {
Self::from_slice(&value[..], gpu_device)
}

pub async fn raw_values(&self) -> Option<Vec<T::NativeType>> {
let result = self.gpu_device.retrive_data(&self.data).await;
let result: Vec<T::NativeType> = bytemuck::cast_slice(&result).to_vec();
Expand Down
4 changes: 2 additions & 2 deletions crates/benchmarks/benches/compare_gpu_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ fn bench_gpu_f32_add(data: &Float32ArrayGPU, value: &Float32ArrayGPU) -> Float32

pub fn criterion_benchmark(c: &mut Criterion) {
let device = Arc::new(GpuDevice::new().block_on());
let mut gpu_data = Float32ArrayGPU::from_vec(
let mut gpu_data = Float32ArrayGPU::from_slice(
&(0..1024 * 1024 * 10)
.into_iter()
.map(|x| x as f32)
.collect::<Vec<f32>>(),
device.clone(),
);
let value_data = Float32ArrayGPU::from_vec(&vec![100.0], device.clone());
let value_data = Float32ArrayGPU::from_slice(&vec![100.0], device.clone());
let mut cpu_data = Float32Array::from(
(0..1024 * 1024 * 10)
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/benchmarks/benches/compare_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn bench_gpu_f32_add(data: &mut Float32ArrayGPU) -> f32 {

pub fn criterion_benchmark(c: &mut Criterion) {
let device = GpuDevice::new().block_on();
let mut gpu_data = Float32ArrayGPU::from_vec(
let mut gpu_data = Float32ArrayGPU::from_slice(
&(0..1024 * 1024 * 10)
.into_iter()
.map(|x| x as f32)
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod tests {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let data = $input;
let gpu_array = $input_ty::from_vec(&data, device);
let gpu_array = $input_ty::from_slice(&data, device);
let new_gpu_array: $output_ty =
<$input_ty as Cast<$output_ty>>::cast(&gpu_array).await;
let new_values = new_gpu_array.raw_values().await.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions crates/math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use wgpu::Buffer;

pub(crate) mod f32;

const ABS_ENTRY_POINT: &'static str = "abs_";
const SQRT_ENTRY_POINT: &'static str = "sqrt_";
const EXP_ENTRY_POINT: &'static str = "exp_";
const EXP2_ENTRY_POINT: &'static str = "exp2_";
const LOG_ENTRY_POINT: &'static str = "log_";
const LOG2_ENTRY_POINT: &'static str = "log2_";
const ABS_ENTRY_POINT: &str = "abs_";
const SQRT_ENTRY_POINT: &str = "sqrt_";
const EXP_ENTRY_POINT: &str = "exp_";
const EXP2_ENTRY_POINT: &str = "exp2_";
const LOG_ENTRY_POINT: &str = "log_";
const LOG2_ENTRY_POINT: &str = "log2_";

#[async_trait]
pub trait MathUnary {
Expand Down
12 changes: 6 additions & 6 deletions crates/routines/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ mod test {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand1_type::from_optional_vec(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_vec(&$input_2, device.clone());
let mask = BooleanArrayGPU::from_optional_vec(&$mask, device);
let gpu_array_1 = $operand1_type::from_optional_slice(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_slice(&$input_2, device.clone());
let mask = BooleanArrayGPU::from_optional_slice(&$mask, device);
let new_gpu_array = gpu_array_1.$operation(&gpu_array_2, &mask).await;
assert_eq!(new_gpu_array.values().await, $output);
}
Expand All @@ -123,9 +123,9 @@ mod test {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand1_type::from_optional_vec(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_vec(&$input_2, device.clone());
let mask = BooleanArrayGPU::from_optional_vec(&$mask, device);
let gpu_array_1 = $operand1_type::from_optional_slice(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_slice(&$input_2, device.clone());
let mask = BooleanArrayGPU::from_optional_slice(&$mask, device);
let new_gpu_array = gpu_array_1.$operation(&gpu_array_2, &mask).await;
assert_eq!(new_gpu_array.values().await, $output);

Expand Down
18 changes: 9 additions & 9 deletions crates/routines/src/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ mod tests {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand_type::from_vec(&$src, device.clone());
let mut gpu_array_2 = $operand_type::from_vec(&$dst, device.clone());
let src_index = UInt32ArrayGPU::from_vec(&$src_index, device.clone());
let dst_index = UInt32ArrayGPU::from_vec(&$dst_index, device);
let gpu_array_1 = $operand_type::from_slice(&$src, device.clone());
let mut gpu_array_2 = $operand_type::from_slice(&$dst, device.clone());
let src_index = UInt32ArrayGPU::from_slice(&$src_index, device.clone());
let dst_index = UInt32ArrayGPU::from_slice(&$dst_index, device);
gpu_array_1.$operation(&src_index, &mut gpu_array_2, &dst_index).await;
assert_eq!(gpu_array_2.raw_values().await.unwrap(), $output);
}
Expand All @@ -112,14 +112,14 @@ mod tests {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand_type::from_vec(&$src, device.clone());
let mut gpu_array_2 = $operand_type::from_vec(&$dst, device.clone());
let src_index = UInt32ArrayGPU::from_vec(&$src_index, device.clone());
let dst_index = UInt32ArrayGPU::from_vec(&$dst_index, device.clone());
let gpu_array_1 = $operand_type::from_slice(&$src, device.clone());
let mut gpu_array_2 = $operand_type::from_slice(&$dst, device.clone());
let src_index = UInt32ArrayGPU::from_slice(&$src_index, device.clone());
let dst_index = UInt32ArrayGPU::from_slice(&$dst_index, device.clone());
gpu_array_1.$operation(&src_index, &mut gpu_array_2, &dst_index).await;
assert_eq!(gpu_array_2.raw_values().await.unwrap(), $output);

let mut gpu_array_2_dyn = $operand_type::from_vec(&$dst, device.clone()).into();
let mut gpu_array_2_dyn = $operand_type::from_slice(&$dst, device.clone()).into();
$operation_dyn(&gpu_array_1.into(), &src_index, &mut gpu_array_2_dyn, &dst_index).await;

let new_values = $operand_type::try_from(gpu_array_2_dyn)
Expand Down
4 changes: 2 additions & 2 deletions crates/routines/src/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ mod tests {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand1_type::from_vec(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_vec(&$input_2, device);
let gpu_array_1 = $operand1_type::from_slice(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_slice(&$input_2, device);
let new_gpu_array = gpu_array_1.$operation(&gpu_array_2).await;
assert_eq!(new_gpu_array.raw_values().await.unwrap(), $output);
}
Expand Down
26 changes: 13 additions & 13 deletions crates/test_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ macro_rules! test_unary_op {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let data = $input;
let gpu_array = $input_ty::from_vec(&data, device);
let gpu_array = $input_ty::from_slice(&data, device);
let new_gpu_array = gpu_array.$unary_fn().await;
assert_eq!(new_gpu_array.raw_values().await.unwrap(), $output);
let new_gpu_array = $unary_fn_dyn(&gpu_array.into()).await;
Expand All @@ -24,7 +24,7 @@ macro_rules! test_unary_op {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let data = $input;
let gpu_array = $input_ty::from_vec(&data, device);
let gpu_array = $input_ty::from_slice(&data, device);
let new_gpu_array = gpu_array.$unary_fn().await;
assert_eq!(new_gpu_array.raw_values().await.unwrap(), $output);
}
Expand All @@ -39,8 +39,8 @@ macro_rules! test_scalar_op {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let data = $input;
let array = $input_ty::from_vec(&data, device.clone());
let value_array = $scalar_ty::from_vec(&vec![$scalar], device);
let array = $input_ty::from_slice(&data, device.clone());
let value_array = $scalar_ty::from_slice(&vec![$scalar], device);
let new_array = array.$scalar_fn(&value_array).await;
assert_eq!(new_array.raw_values().await.unwrap(), $output);

Expand All @@ -63,8 +63,8 @@ macro_rules! test_array_op {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand1_type::from_optional_vec(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_vec(&$input_2, device);
let gpu_array_1 = $operand1_type::from_optional_slice(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_slice(&$input_2, device);
let new_gpu_array = gpu_array_1.$operation(&gpu_array_2).await;
assert_eq!(new_gpu_array.values().await, $output);
}
Expand All @@ -75,8 +75,8 @@ macro_rules! test_array_op {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand1_type::from_optional_vec(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_vec(&$input_2, device);
let gpu_array_1 = $operand1_type::from_optional_slice(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_slice(&$input_2, device);
let new_gpu_array = gpu_array_1.$operation(&gpu_array_2).await;
assert_eq!(new_gpu_array.values().await, $output);

Expand Down Expand Up @@ -129,8 +129,8 @@ macro_rules! test_float_scalar_op {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let data = $input;
let array = $input_ty::from_vec(&data, device.clone());
let value_array = $scalar_ty::from_vec(&vec![$scalar], device);
let array = $input_ty::from_slice(&data, device.clone());
let value_array = $scalar_ty::from_slice(&vec![$scalar], device);
let new_gpu_array = array.$scalar_fn(&value_array).await;
let new_values = new_gpu_array.raw_values().await.unwrap();
for (index, new_value) in new_values.iter().enumerate() {
Expand Down Expand Up @@ -169,7 +169,7 @@ macro_rules! test_unary_op_float {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let data = $input;
let gpu_array = $input_ty::from_vec(&data, device);
let gpu_array = $input_ty::from_slice(&data, device);
let new_gpu_array = gpu_array.$unary_fn().await;
let new_values = new_gpu_array.raw_values().await.unwrap();
for (index, new_value) in new_values.iter().enumerate() {
Expand Down Expand Up @@ -206,8 +206,8 @@ macro_rules! test_float_array_op {
async fn $fn_name() {
use arrow_gpu_array::GPU_DEVICE;
let device = GPU_DEVICE.clone();
let gpu_array_1 = $operand1_type::from_optional_vec(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_vec(&$input_2, device);
let gpu_array_1 = $operand1_type::from_optional_slice(&$input_1, device.clone());
let gpu_array_2 = $operand2_type::from_optional_slice(&$input_2, device);
let new_gpu_array = gpu_array_1.$operation(&gpu_array_2).await;
let new_values = new_gpu_array.values().await;
for (index, new_value) in new_values.iter().enumerate() {
Expand Down

0 comments on commit 3e7401c

Please sign in to comment.