Skip to main content

Module numeric

Module numeric 

Source
Expand description

Defines numeric arithmetic kernels on [PrimitiveArray], such as add

Re-exportsΒ§

use std::cmp::Ordering; πŸ”’
use std::collections::TryReserveError; πŸ”’
use std::convert::Infallible; πŸ”’
use std::fmt::Formatter; πŸ”’
use std::sync::Arc; πŸ”’
use arrow_array::cast::AsArray; πŸ”’
use arrow_array::temporal_conversions::NANOSECONDS; πŸ”’
use arrow_array::temporal_conversions::SECONDS_IN_DAY; πŸ”’
use arrow_array::timezone::Tz; πŸ”’
use arrow_buffer::ArrowNativeType; πŸ”’
use arrow_buffer::BooleanBuffer; πŸ”’
use arrow_buffer::DivisorI32; πŸ”’
use arrow_buffer::DivisorI64; πŸ”’
use arrow_buffer::DivisorU32; πŸ”’
use arrow_buffer::DivisorU64; πŸ”’
use arrow_buffer::IntervalDayTime; πŸ”’
use arrow_buffer::IntervalMonthDayNano; πŸ”’
use arrow_buffer::NullBuffer; πŸ”’
use arrow_buffer::i256; πŸ”’
use arrow_schema::ArrowError; πŸ”’
use arrow_schema::DataType; πŸ”’
use arrow_schema::IntervalUnit; πŸ”’
use arrow_schema::TimeUnit; πŸ”’
use num_traits::CheckedMul; πŸ”’
use num_traits::ToPrimitive; πŸ”’
use crate::arity::binary; πŸ”’
use crate::arity::try_binary; πŸ”’
use arrow_array::types::*; πŸ”’
use arrow_array::*; πŸ”’

MacrosΒ§

date πŸ”’
divisor_op πŸ”’
Defines $fn, which computes / or % of an array by a scalar with a precomputed divisor. It returns None for an op other than / and %, when the scalar is null, or when a value could fail to divide by it (zero, or $fallible for /), so that integer_op returns an error only for a valid value that fails. Otherwise no value can fail, and unary divides every slot, null or not, unless the array has more than $max_nulls nulls, where dividing only the valid values with try_unary costs less
neg_checked πŸ”’
neg_wrapping πŸ”’
op πŸ”’
Perform an infallible binary operation on potentially scalar inputs
op_ref πŸ”’
Same as op but with a type hint for the returned array
signed_mul_overflowing πŸ”’
The wrapping product of two signed integers and whether it overflowed.
signed_overflowing_op πŸ”’
timestamp πŸ”’
try_op πŸ”’
Perform a fallible binary operation on potentially scalar inputs
try_op_ref πŸ”’
Same as try_op but with a type hint for the returned array
unsigned_overflowing_op πŸ”’

EnumsΒ§

Op πŸ”’
An enumeration of arithmetic operations

TraitsΒ§

DateOp πŸ”’
Arithmetic trait for date arrays
IntervalOp πŸ”’
Arithmetic trait for interval arrays
OverflowingOp πŸ”’
Wrapping +, - and * that also report whether they overflowed, written so that LLVM vectorizes a loop over them.
TimestampOp πŸ”’
Arithmetic trait for timestamp arrays

FunctionsΒ§

abs_checked πŸ”’
add
Perform lhs + rhs, returning an error on overflow
add_wrapping
Perform lhs + rhs, wrapping on overflow for [DataType::is_integer]
any_valid πŸ”’
Whether any valid row of nulls is set in overflowed
arithmetic_op πŸ”’
Dispatch the given op to the appropriate specialized kernel
collect_overflowing πŸ”’
Collects the values of iter, and whether any was flagged as overflowed.
date_op πŸ”’
Perform arithmetic operation on a date array
decimal_op πŸ”’
Perform arithmetic operation on decimal arrays
div
Perform lhs / rhs
divisor_op_i32 πŸ”’
divisor_op_i64 πŸ”’
divisor_op_u32 πŸ”’
divisor_op_u64 πŸ”’
duration_op πŸ”’
float_op πŸ”’
Perform an arithmetic operation on floats
integer_op πŸ”’
Perform an arithmetic operation on integers
interval_f64_op πŸ”’
interval_mul_f64 πŸ”’
Multiplies an IntervalMonthDayNano by an f64, mirroring DuckDB’s interval_t layout of months, days, and a sub-day component (nanoseconds in Arrow, microseconds in DuckDB). https://github.com/duckdb/duckdb/blob/21aca0424f1faf78b593b1e6fbfdd4846624c987/src/include/duckdb/common/types/interval.hpp#L24-L27
interval_mul_op πŸ”’
interval_op πŸ”’
Perform arithmetic operation on an interval array
memory_error πŸ”’
Converts an allocation failure in collect_overflowing.
mul
Perform lhs * rhs, returning an error on overflow
mul_checked_cold πŸ”’
[ArrowNativeTypeOp::mul_checked] out of line, for closures that call it only after checked_mul overflows, so that building the error doesn’t stop them from being inlined
mul_i32_i64 πŸ”’
mul_wrapping
Perform lhs * rhs, wrapping on overflow for [DataType::is_integer]
neg
Negates each element of array, returning an error on overflow
neg_wrapping
Negates each element of array, wrapping on overflow for [DataType::is_integer]
overflowing_op πŸ”’
Applies op to every slot of l and r, including null slots, without branching on overflow.
rem
Perform lhs % rhs
rescale_left πŸ”’
Multiplies l by mul, then applies op, reporting whether either step overflowed. With unequal scales only the operand with the smaller scale is multiplied, because the other multiplier is one.
rescale_right πŸ”’
Like rescale_left, but multiplies r by mul.
rescale_scalar πŸ”’
Multiplies the value of the decimal scalar array by mul, so that the kernel doesn’t rescale it on every row.
scalar_divisor πŸ”’
Returns the scalar divisor r scaled by r_mul, when l is an array and dividing any value by it can’t fail. That needs r to be valid and the product to fit and be neither 0 nor -1.
scaled_div πŸ”’
Divides l * 10^mul_pow by r a digit at a time, without forming the scaled numerator. Used when scaling l would overflow T::Native, which it does well before the quotient does.
sub
Perform lhs - rhs, returning an error on overflow
sub_wrapping
Perform lhs - rhs, wrapping on overflow for [DataType::is_integer]
timestamp_op πŸ”’
Perform arithmetic operation on a timestamp array
unless_valid_overflow πŸ”’
Builds the array from the output of collect_overflowing, or returns None if a valid row overflowed.