Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Simplified code. (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Nov 13, 2021
1 parent a667ad7 commit 73ee16d
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 218 deletions.
16 changes: 16 additions & 0 deletions src/compute/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ use crate::{
bitmap::Bitmap,
};

/// Trait describing a type describing multiple lanes with an order relationship
/// consistent with the same order of `T`.
pub trait SimdOrd<T> {
/// The minimum value
const MIN: T;
/// The maximum value
const MAX: T;
/// reduce itself to the minimum
fn max_element(self) -> T;
/// reduce itself to the maximum
fn min_element(self) -> T;
/// lane-wise maximum between two instances
fn max(self, x: Self) -> Self;
/// lane-wise minimum between two instances
fn min(self, x: Self) -> Self;
/// returns a new instance with all lanes equal to `MIN`
fn new_min() -> Self;
/// returns a new instance with all lanes equal to `MAX`
fn new_max() -> Self;
}

Expand Down Expand Up @@ -350,6 +360,9 @@ macro_rules! dyn_generic {
}};
}

/// Returns the maximum of [`Array`]. The scalar is null when all elements are null.
/// # Error
/// Errors iff the type does not support this operation.
pub fn max(array: &dyn Array) -> Result<Box<dyn Scalar>> {
Ok(match array.data_type() {
DataType::Boolean => dyn_generic!(BooleanArray, BooleanScalar, array, max_boolean),
Expand Down Expand Up @@ -388,6 +401,9 @@ pub fn max(array: &dyn Array) -> Result<Box<dyn Scalar>> {
})
}

/// Returns the minimum of [`Array`]. The scalar is null when all elements are null.
/// # Error
/// Errors iff the type does not support this operation.
pub fn min(array: &dyn Array) -> Result<Box<dyn Scalar>> {
Ok(match array.data_type() {
DataType::Boolean => dyn_generic!(BooleanArray, BooleanScalar, array, min_boolean),
Expand Down
36 changes: 9 additions & 27 deletions src/compute/arithmetics/basic/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ impl<T> ArrayAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + Add<Output = T>,
{
type Output = Self;

fn add(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn add(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
add(self, rhs)
}
}
Expand All @@ -171,9 +169,7 @@ impl<T> ArrayWrappingAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + WrappingAdd<Output = T>,
{
type Output = Self;

fn wrapping_add(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn wrapping_add(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
wrapping_add(self, rhs)
}
}
Expand All @@ -183,9 +179,7 @@ impl<T> ArrayCheckedAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + CheckedAdd<Output = T>,
{
type Output = Self;

fn checked_add(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn checked_add(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
checked_add(self, rhs)
}
}
Expand All @@ -195,9 +189,7 @@ impl<T> ArraySaturatingAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + SaturatingAdd<Output = T>,
{
type Output = Self;

fn saturating_add(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn saturating_add(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
saturating_add(self, rhs)
}
}
Expand All @@ -207,9 +199,7 @@ impl<T> ArrayOverflowingAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + OverflowingAdd<Output = T>,
{
type Output = Self;

fn overflowing_add(&self, rhs: &PrimitiveArray<T>) -> Result<(Self::Output, Bitmap)> {
fn overflowing_add(&self, rhs: &PrimitiveArray<T>) -> Result<(Self, Bitmap)> {
overflowing_add(self, rhs)
}
}
Expand Down Expand Up @@ -333,9 +323,7 @@ impl<T> ArrayAdd<T> for PrimitiveArray<T>
where
T: NativeArithmetics + Add<Output = T>,
{
type Output = Self;

fn add(&self, rhs: &T) -> Result<Self::Output> {
fn add(&self, rhs: &T) -> Result<Self> {
Ok(add_scalar(self, rhs))
}
}
Expand All @@ -345,9 +333,7 @@ impl<T> ArrayCheckedAdd<T> for PrimitiveArray<T>
where
T: NativeArithmetics + CheckedAdd<Output = T> + Zero,
{
type Output = Self;

fn checked_add(&self, rhs: &T) -> Result<Self::Output> {
fn checked_add(&self, rhs: &T) -> Result<Self> {
Ok(checked_add_scalar(self, rhs))
}
}
Expand All @@ -357,9 +343,7 @@ impl<T> ArraySaturatingAdd<T> for PrimitiveArray<T>
where
T: NativeArithmetics + SaturatingAdd<Output = T>,
{
type Output = Self;

fn saturating_add(&self, rhs: &T) -> Result<Self::Output> {
fn saturating_add(&self, rhs: &T) -> Result<Self> {
Ok(saturating_add_scalar(self, rhs))
}
}
Expand All @@ -369,9 +353,7 @@ impl<T> ArrayOverflowingAdd<T> for PrimitiveArray<T>
where
T: NativeArithmetics + OverflowingAdd<Output = T>,
{
type Output = Self;

fn overflowing_add(&self, rhs: &T) -> Result<(Self::Output, Bitmap)> {
fn overflowing_add(&self, rhs: &T) -> Result<(Self, Bitmap)> {
Ok(overflowing_add_scalar(self, rhs))
}
}
16 changes: 4 additions & 12 deletions src/compute/arithmetics/basic/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ impl<T> ArrayDiv<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + Div<Output = T>,
{
type Output = Self;

fn div(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn div(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
div(self, rhs)
}
}
Expand All @@ -94,9 +92,7 @@ impl<T> ArrayCheckedDiv<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + CheckedDiv<Output = T>,
{
type Output = Self;

fn checked_div(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn checked_div(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
checked_div(self, rhs)
}
}
Expand Down Expand Up @@ -212,9 +208,7 @@ impl<T> ArrayDiv<T> for PrimitiveArray<T>
where
T: NativeType + Div<Output = T> + NativeArithmetics + NumCast,
{
type Output = Self;

fn div(&self, rhs: &T) -> Result<Self::Output> {
fn div(&self, rhs: &T) -> Result<Self> {
Ok(div_scalar(self, rhs))
}
}
Expand All @@ -224,9 +218,7 @@ impl<T> ArrayCheckedDiv<T> for PrimitiveArray<T>
where
T: NativeType + CheckedDiv<Output = T> + Zero + NativeArithmetics,
{
type Output = Self;

fn checked_div(&self, rhs: &T) -> Result<Self::Output> {
fn checked_div(&self, rhs: &T) -> Result<Self> {
Ok(checked_div_scalar(self, rhs))
}
}
36 changes: 9 additions & 27 deletions src/compute/arithmetics/basic/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ impl<T> ArrayMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + Mul<Output = T>,
{
type Output = Self;

fn mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
mul(self, rhs)
}
}
Expand All @@ -172,9 +170,7 @@ impl<T> ArrayWrappingMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + WrappingMul<Output = T>,
{
type Output = Self;

fn wrapping_mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn wrapping_mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
wrapping_mul(self, rhs)
}
}
Expand All @@ -184,9 +180,7 @@ impl<T> ArrayCheckedMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + CheckedMul<Output = T>,
{
type Output = Self;

fn checked_mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn checked_mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
checked_mul(self, rhs)
}
}
Expand All @@ -196,9 +190,7 @@ impl<T> ArraySaturatingMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + SaturatingMul<Output = T>,
{
type Output = Self;

fn saturating_mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn saturating_mul(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
saturating_mul(self, rhs)
}
}
Expand All @@ -208,9 +200,7 @@ impl<T> ArrayOverflowingMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + OverflowingMul<Output = T>,
{
type Output = Self;

fn overflowing_mul(&self, rhs: &PrimitiveArray<T>) -> Result<(Self::Output, Bitmap)> {
fn overflowing_mul(&self, rhs: &PrimitiveArray<T>) -> Result<(Self, Bitmap)> {
overflowing_mul(self, rhs)
}
}
Expand Down Expand Up @@ -333,9 +323,7 @@ impl<T> ArrayMul<T> for PrimitiveArray<T>
where
T: NativeType + Mul<Output = T> + NativeArithmetics,
{
type Output = Self;

fn mul(&self, rhs: &T) -> Result<Self::Output> {
fn mul(&self, rhs: &T) -> Result<Self> {
Ok(mul_scalar(self, rhs))
}
}
Expand All @@ -345,9 +333,7 @@ impl<T> ArrayCheckedMul<T> for PrimitiveArray<T>
where
T: NativeArithmetics + CheckedMul<Output = T>,
{
type Output = Self;

fn checked_mul(&self, rhs: &T) -> Result<Self::Output> {
fn checked_mul(&self, rhs: &T) -> Result<Self> {
Ok(checked_mul_scalar(self, rhs))
}
}
Expand All @@ -357,9 +343,7 @@ impl<T> ArraySaturatingMul<T> for PrimitiveArray<T>
where
T: NativeArithmetics + SaturatingMul<Output = T>,
{
type Output = Self;

fn saturating_mul(&self, rhs: &T) -> Result<Self::Output> {
fn saturating_mul(&self, rhs: &T) -> Result<Self> {
Ok(saturating_mul_scalar(self, rhs))
}
}
Expand All @@ -369,9 +353,7 @@ impl<T> ArrayOverflowingMul<T> for PrimitiveArray<T>
where
T: NativeArithmetics + OverflowingMul<Output = T>,
{
type Output = Self;

fn overflowing_mul(&self, rhs: &T) -> Result<(Self::Output, Bitmap)> {
fn overflowing_mul(&self, rhs: &T) -> Result<(Self, Bitmap)> {
Ok(overflowing_mul_scalar(self, rhs))
}
}
16 changes: 4 additions & 12 deletions src/compute/arithmetics/basic/rem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ impl<T> ArrayRem<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + Rem<Output = T>,
{
type Output = Self;

fn rem(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn rem(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
rem(self, rhs)
}
}
Expand All @@ -81,9 +79,7 @@ impl<T> ArrayCheckedRem<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeArithmetics + CheckedRem<Output = T>,
{
type Output = Self;

fn checked_rem(&self, rhs: &PrimitiveArray<T>) -> Result<Self::Output> {
fn checked_rem(&self, rhs: &PrimitiveArray<T>) -> Result<Self> {
checked_rem(self, rhs)
}
}
Expand Down Expand Up @@ -199,9 +195,7 @@ impl<T> ArrayRem<T> for PrimitiveArray<T>
where
T: NativeArithmetics + Rem<Output = T> + NumCast,
{
type Output = Self;

fn rem(&self, rhs: &T) -> Result<Self::Output> {
fn rem(&self, rhs: &T) -> Result<Self> {
Ok(rem_scalar(self, rhs))
}
}
Expand All @@ -210,9 +204,7 @@ impl<T> ArrayCheckedRem<T> for PrimitiveArray<T>
where
T: NativeArithmetics + CheckedRem<Output = T>,
{
type Output = Self;

fn checked_rem(&self, rhs: &T) -> Result<Self::Output> {
fn checked_rem(&self, rhs: &T) -> Result<Self> {
Ok(checked_rem_scalar(self, rhs))
}
}
Loading

0 comments on commit 73ee16d

Please sign in to comment.