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

Commit

Permalink
Simplified trait in compute. (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Nov 4, 2021
1 parent 2fb2995 commit 0dda942
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 65 deletions.
24 changes: 12 additions & 12 deletions src/compute/arithmetics/basic/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
bitmap::Bitmap,
compute::{
arithmetics::{
ArrayAdd, ArrayCheckedAdd, ArrayOverflowingAdd, ArraySaturatingAdd, NotI128,
ArrayAdd, ArrayCheckedAdd, ArrayOverflowingAdd, ArraySaturatingAdd, NativeArithmetics,
},
arity::{
binary, binary_checked, binary_with_bitmap, unary, unary_checked, unary_with_bitmap,
Expand Down Expand Up @@ -87,7 +87,7 @@ where
/// ```
pub fn checked_add<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
where
T: NativeType + CheckedAdd<Output = T> + Zero,
T: NativeType + CheckedAdd<Output = T>,
{
check_same_type(lhs, rhs)?;

Expand Down Expand Up @@ -158,7 +158,7 @@ where
// Implementation of ArrayAdd trait for PrimitiveArrays
impl<T> ArrayAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + Add<Output = T> + NotI128,
T: NativeArithmetics + Add<Output = T>,
{
type Output = Self;

Expand All @@ -169,7 +169,7 @@ where

impl<T> ArrayWrappingAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + WrappingAdd<Output = T> + NotI128,
T: NativeArithmetics + WrappingAdd<Output = T>,
{
type Output = Self;

Expand All @@ -181,7 +181,7 @@ where
// Implementation of ArrayCheckedAdd trait for PrimitiveArrays
impl<T> ArrayCheckedAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + CheckedAdd<Output = T> + Zero + NotI128,
T: NativeArithmetics + CheckedAdd<Output = T>,
{
type Output = Self;

Expand All @@ -193,7 +193,7 @@ where
// Implementation of ArraySaturatingAdd trait for PrimitiveArrays
impl<T> ArraySaturatingAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + SaturatingAdd<Output = T> + NotI128,
T: NativeArithmetics + SaturatingAdd<Output = T>,
{
type Output = Self;

Expand All @@ -205,7 +205,7 @@ where
// Implementation of ArraySaturatingAdd trait for PrimitiveArrays
impl<T> ArrayOverflowingAdd<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + OverflowingAdd<Output = T> + NotI128,
T: NativeArithmetics + OverflowingAdd<Output = T>,
{
type Output = Self;

Expand Down Expand Up @@ -271,7 +271,7 @@ where
/// ```
pub fn checked_add_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
T: NativeType + CheckedAdd<Output = T> + Zero,
T: NativeType + CheckedAdd<Output = T>,
{
let rhs = *rhs;
let op = move |a: T| a.checked_add(&rhs);
Expand Down Expand Up @@ -331,7 +331,7 @@ where
// Implementation of ArrayAdd trait for PrimitiveArrays with a scalar
impl<T> ArrayAdd<T> for PrimitiveArray<T>
where
T: NativeType + Add<Output = T> + NotI128,
T: NativeArithmetics + Add<Output = T>,
{
type Output = Self;

Expand All @@ -343,7 +343,7 @@ where
// Implementation of ArrayCheckedAdd trait for PrimitiveArrays with a scalar
impl<T> ArrayCheckedAdd<T> for PrimitiveArray<T>
where
T: NativeType + CheckedAdd<Output = T> + Zero + NotI128,
T: NativeArithmetics + CheckedAdd<Output = T> + Zero,
{
type Output = Self;

Expand All @@ -355,7 +355,7 @@ where
// Implementation of ArraySaturatingAdd trait for PrimitiveArrays with a scalar
impl<T> ArraySaturatingAdd<T> for PrimitiveArray<T>
where
T: NativeType + SaturatingAdd<Output = T> + NotI128,
T: NativeArithmetics + SaturatingAdd<Output = T>,
{
type Output = Self;

Expand All @@ -367,7 +367,7 @@ where
// Implementation of ArraySaturatingAdd trait for PrimitiveArrays with a scalar
impl<T> ArrayOverflowingAdd<T> for PrimitiveArray<T>
where
T: NativeType + OverflowingAdd<Output = T> + NotI128,
T: NativeArithmetics + OverflowingAdd<Output = T>,
{
type Output = Self;

Expand Down
12 changes: 6 additions & 6 deletions src/compute/arithmetics/basic/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::datatypes::DataType;
use crate::{
array::{Array, PrimitiveArray},
compute::{
arithmetics::{ArrayCheckedDiv, ArrayDiv, NotI128},
arithmetics::{ArrayCheckedDiv, ArrayDiv, NativeArithmetics},
arity::{binary, binary_checked, unary, unary_checked},
},
error::Result,
Expand Down Expand Up @@ -68,7 +68,7 @@ where
/// ```
pub fn checked_div<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
where
T: NativeType + CheckedDiv<Output = T> + Zero,
T: NativeArithmetics + CheckedDiv<Output = T>,
{
check_same_type(lhs, rhs)?;

Expand All @@ -80,7 +80,7 @@ where
// Implementation of ArrayDiv trait for PrimitiveArrays
impl<T> ArrayDiv<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + Div<Output = T> + NotI128,
T: NativeArithmetics + Div<Output = T>,
{
type Output = Self;

Expand All @@ -92,7 +92,7 @@ where
// Implementation of ArrayCheckedDiv trait for PrimitiveArrays
impl<T> ArrayCheckedDiv<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + CheckedDiv<Output = T> + Zero + NotI128,
T: NativeArithmetics + CheckedDiv<Output = T>,
{
type Output = Self;

Expand Down Expand Up @@ -210,7 +210,7 @@ where
// Implementation of ArrayDiv trait for PrimitiveArrays with a scalar
impl<T> ArrayDiv<T> for PrimitiveArray<T>
where
T: NativeType + Div<Output = T> + NotI128 + NumCast,
T: NativeType + Div<Output = T> + NativeArithmetics + NumCast,
{
type Output = Self;

Expand All @@ -222,7 +222,7 @@ where
// Implementation of ArrayCheckedDiv trait for PrimitiveArrays with a scalar
impl<T> ArrayCheckedDiv<T> for PrimitiveArray<T>
where
T: NativeType + CheckedDiv<Output = T> + Zero + NotI128,
T: NativeType + CheckedDiv<Output = T> + Zero + NativeArithmetics,
{
type Output = Self;

Expand Down
26 changes: 13 additions & 13 deletions src/compute/arithmetics/basic/mul.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Definition of basic mul operations with primitive arrays
use std::ops::Mul;

use num_traits::{ops::overflowing::OverflowingMul, CheckedMul, SaturatingMul, WrappingMul, Zero};
use num_traits::{ops::overflowing::OverflowingMul, CheckedMul, SaturatingMul, WrappingMul};

use crate::compute::arithmetics::basic::check_same_type;
use crate::compute::arithmetics::ArrayWrappingMul;
Expand All @@ -10,7 +10,7 @@ use crate::{
bitmap::Bitmap,
compute::{
arithmetics::{
ArrayCheckedMul, ArrayMul, ArrayOverflowingMul, ArraySaturatingMul, NotI128,
ArrayCheckedMul, ArrayMul, ArrayOverflowingMul, ArraySaturatingMul, NativeArithmetics,
},
arity::{
binary, binary_checked, binary_with_bitmap, unary, unary_checked, unary_with_bitmap,
Expand Down Expand Up @@ -88,7 +88,7 @@ where
/// ```
pub fn checked_mul<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
where
T: NativeType + CheckedMul<Output = T> + Zero,
T: NativeType + CheckedMul<Output = T>,
{
check_same_type(lhs, rhs)?;

Expand Down Expand Up @@ -159,7 +159,7 @@ where
// Implementation of ArrayMul trait for PrimitiveArrays
impl<T> ArrayMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + Mul<Output = T> + NotI128,
T: NativeArithmetics + Mul<Output = T>,
{
type Output = Self;

Expand All @@ -170,7 +170,7 @@ where

impl<T> ArrayWrappingMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + WrappingMul<Output = T> + NotI128,
T: NativeArithmetics + WrappingMul<Output = T>,
{
type Output = Self;

Expand All @@ -182,7 +182,7 @@ where
// Implementation of ArrayCheckedMul trait for PrimitiveArrays
impl<T> ArrayCheckedMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + CheckedMul<Output = T> + Zero + NotI128,
T: NativeArithmetics + CheckedMul<Output = T>,
{
type Output = Self;

Expand All @@ -194,7 +194,7 @@ where
// Implementation of ArraySaturatingMul trait for PrimitiveArrays
impl<T> ArraySaturatingMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + SaturatingMul<Output = T> + NotI128,
T: NativeArithmetics + SaturatingMul<Output = T>,
{
type Output = Self;

Expand All @@ -206,7 +206,7 @@ where
// Implementation of ArraySaturatingMul trait for PrimitiveArrays
impl<T> ArrayOverflowingMul<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + OverflowingMul<Output = T> + NotI128,
T: NativeArithmetics + OverflowingMul<Output = T>,
{
type Output = Self;

Expand Down Expand Up @@ -271,7 +271,7 @@ where
/// ```
pub fn checked_mul_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
T: NativeType + CheckedMul<Output = T> + Zero,
T: NativeType + CheckedMul<Output = T>,
{
let rhs = *rhs;
let op = move |a: T| a.checked_mul(&rhs);
Expand Down Expand Up @@ -331,7 +331,7 @@ where
// Implementation of ArrayMul trait for PrimitiveArrays with a scalar
impl<T> ArrayMul<T> for PrimitiveArray<T>
where
T: NativeType + Mul<Output = T> + NotI128,
T: NativeType + Mul<Output = T> + NativeArithmetics,
{
type Output = Self;

Expand All @@ -343,7 +343,7 @@ where
// Implementation of ArrayCheckedMul trait for PrimitiveArrays with a scalar
impl<T> ArrayCheckedMul<T> for PrimitiveArray<T>
where
T: NativeType + CheckedMul<Output = T> + Zero + NotI128,
T: NativeArithmetics + CheckedMul<Output = T>,
{
type Output = Self;

Expand All @@ -355,7 +355,7 @@ where
// Implementation of ArraySaturatingMul trait for PrimitiveArrays with a scalar
impl<T> ArraySaturatingMul<T> for PrimitiveArray<T>
where
T: NativeType + SaturatingMul<Output = T> + NotI128,
T: NativeArithmetics + SaturatingMul<Output = T>,
{
type Output = Self;

Expand All @@ -367,7 +367,7 @@ where
// Implementation of ArraySaturatingMul trait for PrimitiveArrays with a scalar
impl<T> ArrayOverflowingMul<T> for PrimitiveArray<T>
where
T: NativeType + OverflowingMul<Output = T> + NotI128,
T: NativeArithmetics + OverflowingMul<Output = T>,
{
type Output = Self;

Expand Down
16 changes: 8 additions & 8 deletions src/compute/arithmetics/basic/rem.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::ops::Rem;

use num_traits::{CheckedRem, NumCast, Zero};
use num_traits::{CheckedRem, NumCast};

use crate::compute::arithmetics::basic::check_same_type;
use crate::datatypes::DataType;
use crate::{
array::{Array, PrimitiveArray},
compute::{
arithmetics::{ArrayCheckedRem, ArrayRem, NotI128},
arithmetics::{ArrayCheckedRem, ArrayRem, NativeArithmetics},
arity::{binary, binary_checked, unary, unary_checked},
},
error::Result,
Expand Down Expand Up @@ -57,7 +57,7 @@ where
/// ```
pub fn checked_rem<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
where
T: NativeType + CheckedRem<Output = T> + Zero,
T: NativeType + CheckedRem<Output = T>,
{
check_same_type(lhs, rhs)?;

Expand All @@ -68,7 +68,7 @@ where

impl<T> ArrayRem<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + Rem<Output = T> + NotI128,
T: NativeArithmetics + Rem<Output = T>,
{
type Output = Self;

Expand All @@ -79,7 +79,7 @@ where

impl<T> ArrayCheckedRem<PrimitiveArray<T>> for PrimitiveArray<T>
where
T: NativeType + CheckedRem<Output = T> + Zero + NotI128,
T: NativeArithmetics + CheckedRem<Output = T>,
{
type Output = Self;

Expand Down Expand Up @@ -187,7 +187,7 @@ where
/// ```
pub fn checked_rem_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
T: NativeType + CheckedRem<Output = T> + Zero,
T: NativeType + CheckedRem<Output = T>,
{
let rhs = *rhs;
let op = move |a: T| a.checked_rem(&rhs);
Expand All @@ -197,7 +197,7 @@ where

impl<T> ArrayRem<T> for PrimitiveArray<T>
where
T: NativeType + Rem<Output = T> + NotI128 + NumCast,
T: NativeArithmetics + Rem<Output = T> + NumCast,
{
type Output = Self;

Expand All @@ -208,7 +208,7 @@ where

impl<T> ArrayCheckedRem<T> for PrimitiveArray<T>
where
T: NativeType + CheckedRem<Output = T> + Zero + NotI128,
T: NativeArithmetics + CheckedRem<Output = T>,
{
type Output = Self;

Expand Down
Loading

0 comments on commit 0dda942

Please sign in to comment.