pub fn rem_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
    T: NativeArithmetics + Rem<Output = T> + NumCast,
{
    let rhs = *rhs;

    match T::PRIMITIVE {
        PrimitiveType::UInt64 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u64>>().unwrap();
            let rhs = rhs.to_u64().unwrap();

            let reduced_rem = StrengthReducedU64::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u64>` which means that
            // T = u64
            unsafe {
                std::mem::transmute::<PrimitiveArray<u64>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        PrimitiveType::UInt32 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u32>>().unwrap();
            let rhs = rhs.to_u32().unwrap();

            let reduced_rem = StrengthReducedU32::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u32>` which means that
            // T = u32
            unsafe {
                std::mem::transmute::<PrimitiveArray<u32>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        PrimitiveType::UInt16 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u16>>().unwrap();
            let rhs = rhs.to_u16().unwrap();

            let reduced_rem = StrengthReducedU16::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u16>` which means that
            // T = u16
            unsafe {
                std::mem::transmute::<PrimitiveArray<u16>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        PrimitiveType::UInt8 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u8>>().unwrap();
            let rhs = rhs.to_u8().unwrap();

            let reduced_rem = StrengthReducedU8::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u8>` which means that
            // T = u8
            unsafe {
                std::mem::transmute::<PrimitiveArray<u8>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        _ => unary(lhs, |a| a % rhs, lhs.data_type().clone()),
    }
}
/// Remainder a primitive array of type T by a scalar T.
/// Panics if the divisor is zero.
///
/// # Examples
/// ```
/// use arrow2::compute::arithmetics::basic::rem_scalar;
/// use arrow2::array::Int32Array;
///
/// let a = Int32Array::from(&[None, Some(6), None, Some(7)]);
/// let result = rem_scalar(&a, &2i32);
/// let expected = Int32Array::from(&[None, Some(0), None, Some(1)]);
/// assert_eq!(result, expected)
/// ```
Remainder a primitive array of type T by a scalar T.
Panics if the divisor is zero.
Remainder a primitive array of type T by a scalar T . Panics if the divisor is zero .
pub fn rem_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
    T: NativeArithmetics + Rem<Output = T> + NumCast,
{
    let rhs = *rhs;
    match T::PRIMITIVE {
        PrimitiveType::UInt64 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u64>>().unwrap();
            let rhs = rhs.to_u64().unwrap();
            let reduced_rem = StrengthReducedU64::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u64>` which means that
            // T = u64
            unsafe {
                std::mem::transmute::<PrimitiveArray<u64>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        PrimitiveType::UInt32 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u32>>().unwrap();
            let rhs = rhs.to_u32().unwrap();
            let reduced_rem = StrengthReducedU32::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u32>` which means that
            // T = u32
            unsafe {
                std::mem::transmute::<PrimitiveArray<u32>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        PrimitiveType::UInt16 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u16>>().unwrap();
            let rhs = rhs.to_u16().unwrap();
            let reduced_rem = StrengthReducedU16::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u16>` which means that
            // T = u16
            unsafe {
                std::mem::transmute::<PrimitiveArray<u16>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        PrimitiveType::UInt8 => {
            let lhs = lhs.as_any().downcast_ref::<PrimitiveArray<u8>>().unwrap();
            let rhs = rhs.to_u8().unwrap();
            let reduced_rem = StrengthReducedU8::new(rhs);
            // Safety: we just proved that `lhs` is `PrimitiveArray<u8>` which means that
            // T = u8
            unsafe {
                std::mem::transmute::<PrimitiveArray<u8>, PrimitiveArray<T>>(unary(
                    lhs,
                    |a| a % reduced_rem,
                    lhs.data_type().clone(),
                ))
            }
        }
        _ => unary(lhs, |a| a % rhs, lhs.data_type().clone()),
    }
}
pub fn rem_scalar < T > ( lhs : & PrimitiveArray < T > , rhs : & T ) -> PrimitiveArray < T > where T : NativeArithmetics + Rem < Output = T > + NumCast , { let rhs = * rhs ; match T :: PRIMITIVE { PrimitiveType :: UInt64 => { let lhs = lhs . as_any ( ) . downcast_ref :: < PrimitiveArray < u64 > > ( ) . unwrap ( ) ; let rhs = rhs . to_u64 ( ) . unwrap ( ) ; let reduced_rem = StrengthReducedU64 :: new ( rhs ) ; // Safety: we just proved that `lhs` is `PrimitiveArray<u64>` which means that // T = u64 unsafe { std :: mem :: transmute :: < PrimitiveArray < u64 > , PrimitiveArray < T > > ( unary ( lhs , | a | a % reduced_rem , lhs . data_type ( ) . clone ( ) , ) ) } } PrimitiveType :: UInt32 => { let lhs = lhs . as_any ( ) . downcast_ref :: < PrimitiveArray < u32 > > ( ) . unwrap ( ) ; let rhs = rhs . to_u32 ( ) . unwrap ( ) ; let reduced_rem = StrengthReducedU32 :: new ( rhs ) ; // Safety: we just proved that `lhs` is `PrimitiveArray<u32>` which means that // T = u32 unsafe { std :: mem :: transmute :: < PrimitiveArray < u32 > , PrimitiveArray < T > > ( unary ( lhs , | a | a % reduced_rem , lhs . data_type ( ) . clone ( ) , ) ) } } PrimitiveType :: UInt16 => { let lhs = lhs . as_any ( ) . downcast_ref :: < PrimitiveArray < u16 > > ( ) . unwrap ( ) ; let rhs = rhs . to_u16 ( ) . unwrap ( ) ; let reduced_rem = StrengthReducedU16 :: new ( rhs ) ; // Safety: we just proved that `lhs` is `PrimitiveArray<u16>` which means that // T = u16 unsafe { std :: mem :: transmute :: < PrimitiveArray < u16 > , PrimitiveArray < T > > ( unary ( lhs , | a | a % reduced_rem , lhs . data_type ( ) . clone ( ) , ) ) } } PrimitiveType :: UInt8 => { let lhs = lhs . as_any ( ) . downcast_ref :: < PrimitiveArray < u8 > > ( ) . unwrap ( ) ; let rhs = rhs . to_u8 ( ) . unwrap ( ) ; let reduced_rem = StrengthReducedU8 :: new ( rhs ) ; // Safety: we just proved that `lhs` is `PrimitiveArray<u8>` which means that // T = u8 unsafe { std :: mem :: transmute :: < PrimitiveArray < u8 > , PrimitiveArray < T > > ( unary ( lhs , | a | a % reduced_rem , lhs . data_type ( ) . clone ( ) , ) ) } } _ => unary ( lhs , | a | a % rhs , lhs . data_type ( ) . clone ( ) ) , } }
Remainder a primitive array of type T by a scalar T.
Panics if the divisor is zero.
Remainder a primitive array of type T by a scalar T . Panics if the divisor is zero .
lhs
&PrimitiveArray<T>
rhs
&T
lhs
&PrimitiveArray<T>
rhs
&T
examples
```
use arrow2::compute::arithmetics::basic::rem_scalar;
use arrow2::array::Int32Array.

let a = Int32Array::from(&[None, Some(6), None, Some(7)]);
let result = rem_scalar(&a, &2i32);
let expected = Int32Array::from(&[None, Some(0), None, Some(1)]);
assert_eq!(result, expected)
```
` ` ` use arrow2 :: compute :: arithmetics :: basic :: rem_scalar ; use arrow2 :: array :: Int32Array . let a = Int32Array :: from ( & [ None Some ( 6 ) None Some ( 7 ) ] ) ; let result = rem_scalar ( &a &2i32 ) ; let expected = Int32Array :: from ( & [ None Some ( 0 ) None Some ( 1 ) ] ) ; assert_eq! ( result expected ) ` ` `