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

Un-nested compute::arithemtics::basic #461

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/arithmetic_kernels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use criterion::Criterion;
use arrow2::array::*;
use arrow2::util::bench_util::*;
use arrow2::{
compute::arithmetics::basic::add::add, compute::arithmetics::basic::div::div_scalar,
datatypes::DataType, types::NativeType,
compute::arithmetics::basic::add, compute::arithmetics::basic::div_scalar, datatypes::DataType,
types::NativeType,
};
use num_traits::NumCast;
use std::ops::{Add, Div};
Expand Down
16 changes: 8 additions & 8 deletions src/compute/arithmetics/basic/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::add;
/// use arrow2::compute::arithmetics::basic::add;
/// use arrow2::array::PrimitiveArray;
///
/// let a = PrimitiveArray::from([None, Some(6), None, Some(6)]);
Expand All @@ -50,7 +50,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::checked_add;
/// use arrow2::compute::arithmetics::basic::checked_add;
/// use arrow2::array::PrimitiveArray;
///
/// let a = PrimitiveArray::from([Some(100i8), Some(100i8), Some(100i8)]);
Expand Down Expand Up @@ -80,7 +80,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::saturating_add;
/// use arrow2::compute::arithmetics::basic::saturating_add;
/// use arrow2::array::PrimitiveArray;
///
/// let a = PrimitiveArray::from([Some(100i8)]);
Expand Down Expand Up @@ -114,7 +114,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::overflowing_add;
/// use arrow2::compute::arithmetics::basic::overflowing_add;
/// use arrow2::array::PrimitiveArray;
///
/// let a = PrimitiveArray::from([Some(1i8), Some(100i8)]);
Expand Down Expand Up @@ -194,7 +194,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::add_scalar;
/// use arrow2::compute::arithmetics::basic::add_scalar;
/// use arrow2::array::PrimitiveArray;
///
/// let a = PrimitiveArray::from([None, Some(6), None, Some(6)]);
Expand All @@ -216,7 +216,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::checked_add_scalar;
/// use arrow2::compute::arithmetics::basic::checked_add_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[None, Some(100), None, Some(100)]);
Expand All @@ -240,7 +240,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::saturating_add_scalar;
/// use arrow2::compute::arithmetics::basic::saturating_add_scalar;
/// use arrow2::array::PrimitiveArray;
///
/// let a = PrimitiveArray::from([Some(100i8)]);
Expand All @@ -265,7 +265,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::add::overflowing_add_scalar;
/// use arrow2::compute::arithmetics::basic::overflowing_add_scalar;
/// use arrow2::array::PrimitiveArray;
///
/// let a = PrimitiveArray::from([Some(1i8), Some(100i8)]);
Expand Down
8 changes: 4 additions & 4 deletions src/compute/arithmetics/basic/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use strength_reduce::{
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::div::div;
/// use arrow2::compute::arithmetics::basic::div;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[Some(10), Some(1), Some(6)]);
Expand Down Expand Up @@ -64,7 +64,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::div::checked_div;
/// use arrow2::compute::arithmetics::basic::checked_div;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8), Some(10i8)]);
Expand Down Expand Up @@ -117,7 +117,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::div::div_scalar;
/// use arrow2::compute::arithmetics::basic::div_scalar;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
Expand Down Expand Up @@ -200,7 +200,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::div::checked_div_scalar;
/// use arrow2::compute::arithmetics::basic::checked_div_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8)]);
Expand Down
26 changes: 19 additions & 7 deletions src/compute/arithmetics/basic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
//! Defines the arithmetic kernels for `PrimitiveArrays`.
pub mod add;
pub mod div;
pub mod mul;
pub mod pow;
pub mod rem;
pub mod sub;
//! Contains arithemtic functions for [`PrimitiveArray`](crate::array::PrimitiveArray)s.
//!
//! Each operation has four variants, like the rest of Rust's ecosystem:
//! * usual, that [`panic!`]s on overflow
//! * `checked_*` that turns overflowings to `None`
//! * `overflowing_*` returning a [`Bitmap`](crate::bitmap::Bitmap) with items that overflow.
//! * `saturating_*` that saturates the result.
mod add;
pub use add::*;
mod div;
pub use div::*;
mod mul;
pub use mul::*;
mod pow;
pub use pow::*;
mod rem;
pub use rem::*;
mod sub;
pub use sub::*;
16 changes: 8 additions & 8 deletions src/compute/arithmetics/basic/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::mul;
/// use arrow2::compute::arithmetics::basic::mul;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
Expand Down Expand Up @@ -51,7 +51,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::checked_mul;
/// use arrow2::compute::arithmetics::basic::checked_mul;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(100i8), Some(100i8), Some(100i8)]);
Expand Down Expand Up @@ -81,7 +81,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::saturating_mul;
/// use arrow2::compute::arithmetics::basic::saturating_mul;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8)]);
Expand Down Expand Up @@ -115,7 +115,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::overflowing_mul;
/// use arrow2::compute::arithmetics::basic::overflowing_mul;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(1i8), Some(-100i8)]);
Expand Down Expand Up @@ -194,7 +194,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::mul_scalar;
/// use arrow2::compute::arithmetics::basic::mul_scalar;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
Expand All @@ -216,7 +216,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::checked_mul_scalar;
/// use arrow2::compute::arithmetics::basic::checked_mul_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[None, Some(100), None, Some(100)]);
Expand All @@ -240,7 +240,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::saturating_mul_scalar;
/// use arrow2::compute::arithmetics::basic::saturating_mul_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8)]);
Expand All @@ -265,7 +265,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::mul::overflowing_mul_scalar;
/// use arrow2::compute::arithmetics::basic::overflowing_mul_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(1i8), Some(100i8)]);
Expand Down
4 changes: 2 additions & 2 deletions src/compute/arithmetics/basic/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::pow::powf_scalar;
/// use arrow2::compute::arithmetics::basic::powf_scalar;
/// use arrow2::array::Float32Array;
///
/// let a = Float32Array::from(&[Some(2f32), None]);
Expand All @@ -33,7 +33,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::pow::checked_powf_scalar;
/// use arrow2::compute::arithmetics::basic::checked_powf_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(1i8), None, Some(7i8)]);
Expand Down
8 changes: 4 additions & 4 deletions src/compute/arithmetics/basic/rem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use strength_reduce::{
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::rem::rem;
/// use arrow2::compute::arithmetics::basic::rem;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[Some(10), Some(7)]);
Expand Down Expand Up @@ -49,7 +49,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::rem::checked_rem;
/// use arrow2::compute::arithmetics::basic::checked_rem;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8), Some(10i8)]);
Expand Down Expand Up @@ -100,7 +100,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::rem::rem_scalar;
/// use arrow2::compute::arithmetics::basic::rem_scalar;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[None, Some(6), None, Some(7)]);
Expand Down Expand Up @@ -184,7 +184,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::rem::checked_rem_scalar;
/// use arrow2::compute::arithmetics::basic::checked_rem_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8)]);
Expand Down
16 changes: 8 additions & 8 deletions src/compute/arithmetics/basic/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::sub;
/// use arrow2::compute::arithmetics::basic::sub;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
Expand All @@ -50,7 +50,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::checked_sub;
/// use arrow2::compute::arithmetics::basic::checked_sub;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(100i8), Some(-100i8), Some(100i8)]);
Expand Down Expand Up @@ -80,7 +80,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::saturating_sub;
/// use arrow2::compute::arithmetics::basic::saturating_sub;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8)]);
Expand Down Expand Up @@ -114,7 +114,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::overflowing_sub;
/// use arrow2::compute::arithmetics::basic::overflowing_sub;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(1i8), Some(-100i8)]);
Expand Down Expand Up @@ -194,7 +194,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::sub_scalar;
/// use arrow2::compute::arithmetics::basic::sub_scalar;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
Expand All @@ -216,7 +216,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::checked_sub_scalar;
/// use arrow2::compute::arithmetics::basic::checked_sub_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[None, Some(-100), None, Some(-100)]);
Expand All @@ -240,7 +240,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::saturating_sub_scalar;
/// use arrow2::compute::arithmetics::basic::saturating_sub_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(-100i8)]);
Expand All @@ -265,7 +265,7 @@ where
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::sub::overflowing_sub_scalar;
/// use arrow2::compute::arithmetics::basic::overflowing_sub_scalar;
/// use arrow2::array::Int8Array;
///
/// let a = Int8Array::from(&[Some(1i8), Some(-100i8)]);
Expand Down
20 changes: 10 additions & 10 deletions src/compute/arithmetics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ where
+ Rem<Output = T>,
{
match op {
Operator::Add => basic::add::add(lhs, rhs),
Operator::Subtract => basic::sub::sub(lhs, rhs),
Operator::Multiply => basic::mul::mul(lhs, rhs),
Operator::Divide => basic::div::div(lhs, rhs),
Operator::Remainder => basic::rem::rem(lhs, rhs),
Operator::Add => basic::add(lhs, rhs),
Operator::Subtract => basic::sub(lhs, rhs),
Operator::Multiply => basic::mul(lhs, rhs),
Operator::Divide => basic::div(lhs, rhs),
Operator::Remainder => basic::rem(lhs, rhs),
}
}

Expand All @@ -275,11 +275,11 @@ where
+ NumCast,
{
match op {
Operator::Add => Ok(basic::add::add_scalar(lhs, rhs)),
Operator::Subtract => Ok(basic::sub::sub_scalar(lhs, rhs)),
Operator::Multiply => Ok(basic::mul::mul_scalar(lhs, rhs)),
Operator::Divide => Ok(basic::div::div_scalar(lhs, rhs)),
Operator::Remainder => Ok(basic::rem::rem_scalar(lhs, rhs)),
Operator::Add => Ok(basic::add_scalar(lhs, rhs)),
Operator::Subtract => Ok(basic::sub_scalar(lhs, rhs)),
Operator::Multiply => Ok(basic::mul_scalar(lhs, rhs)),
Operator::Divide => Ok(basic::div_scalar(lhs, rhs)),
Operator::Remainder => Ok(basic::rem_scalar(lhs, rhs)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/it/compute/aggregate/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn test_primitive_array_sum_large_64() {
.map(|i| if i % 3 == 0 { Some(0) } else { Some(i) })
.collect();
// create an array that actually has non-zero values at the invalid indices
let c = arithmetics::basic::add::add(&a, &b).unwrap();
let c = arithmetics::basic::add(&a, &b).unwrap();
assert_eq!(
Some((1..=100).filter(|i| i % 3 == 0).sum()),
sum_primitive(&c)
Expand Down
2 changes: 1 addition & 1 deletion tests/it/compute/arithmetics/basic/add.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use arrow2::array::*;
use arrow2::bitmap::Bitmap;
use arrow2::compute::arithmetics::basic::add::*;
use arrow2::compute::arithmetics::basic::*;
use arrow2::compute::arithmetics::{
ArrayAdd, ArrayCheckedAdd, ArrayOverflowingAdd, ArraySaturatingAdd,
};
Expand Down
Loading