Skip to main content

ferray_ufunc/
lib.rs

1// ferray-ufunc: Universal functions and SIMD-accelerated elementwise operations
2//
3// This crate provides 100+ NumPy-equivalent ufunc functions for the ferray
4// N-dimensional array library. All functions are generic over element type
5// and dimensionality, preserving the input array's rank.
6//
7// Features:
8// - Trigonometric, exponential, logarithmic, rounding, arithmetic functions
9// - Cumulative operations (cumsum, cumprod, diff, gradient)
10// - Convolution and interpolation
11// - Float intrinsics (isnan, clip, nan_to_num, etc.)
12// - Complex number operations
13// - Bitwise and logical operations
14// - Comparison functions (allclose, isclose, etc.)
15// - Special functions (sinc, i0)
16// - SIMD dispatch via pulp (REQ-17)
17// - Rayon parallelism for large arrays (REQ-21)
18// - Operator overloads (+, -, *, /, %, &, |, ^, !, <<, >>)
19
20pub mod cr_math;
21pub mod dispatch;
22pub mod fast_exp;
23pub mod helpers;
24pub mod kernels;
25pub mod operator_overloads;
26pub mod ops;
27pub mod parallel;
28
29// ---------------------------------------------------------------------------
30// Public re-exports — flat namespace for ergonomic use
31// ---------------------------------------------------------------------------
32
33// Trigonometric
34pub use ops::trig::{
35    arccos, arccosh, arcsin, arcsinh, arctan, arctan2, arctanh, cos, cosh, deg2rad, degrees, hypot,
36    rad2deg, radians, sin, sinh, tan, tanh, unwrap,
37};
38
39// Exponential and logarithmic
40pub use ops::explog::{exp, exp_fast, exp2, expm1, log, log1p, log2, log10, logaddexp, logaddexp2};
41
42// Rounding
43pub use ops::rounding::{around, ceil, fix, floor, rint, round, trunc};
44
45// Arithmetic
46pub use ops::arithmetic::{
47    absolute, add, add_accumulate, add_broadcast, add_reduce, cbrt, cross, cumprod, cumsum, diff,
48    divide, divide_broadcast, divmod, ediff1d, fabs, floor_divide, fmod, gcd, gradient, heaviside,
49    lcm, mod_, multiply, multiply_broadcast, multiply_outer, nancumprod, nancumsum, negative,
50    positive, power, reciprocal, remainder, sign, sqrt, square, subtract, subtract_broadcast,
51    trapezoid, true_divide,
52};
53
54// Float intrinsics
55pub use ops::floatintrinsic::{
56    clip, copysign, float_power, fmax, fmin, frexp, isfinite, isinf, isnan, isneginf, isposinf,
57    ldexp, maximum, minimum, nan_to_num, nextafter, signbit, spacing,
58};
59
60// Complex
61pub use ops::complex::{abs, angle, conj, conjugate, imag, real};
62
63// Bitwise
64pub use ops::bitwise::{
65    BitwiseOps, ShiftOps, bitwise_and, bitwise_not, bitwise_or, bitwise_xor, invert, left_shift,
66    right_shift,
67};
68
69// Comparison
70pub use ops::comparison::{
71    allclose, array_equal, array_equiv, equal, greater, greater_equal, isclose, less, less_equal,
72    not_equal,
73};
74
75// Logical
76pub use ops::logical::{Logical, all, any, logical_and, logical_not, logical_or, logical_xor};
77
78// Special
79pub use ops::special::{i0, sinc};
80
81// Convolution
82pub use ops::convolution::{ConvolveMode, convolve};
83
84// Interpolation
85pub use ops::interpolation::{interp, interp_one};
86
87// f16 variants (feature-gated)
88#[cfg(feature = "f16")]
89pub use ops::arithmetic::{
90    absolute_f16, add_f16, cbrt_f16, divide_f16, floor_divide_f16, multiply_f16, negative_f16,
91    power_f16, reciprocal_f16, remainder_f16, sign_f16, sqrt_f16, square_f16, subtract_f16,
92};
93#[cfg(feature = "f16")]
94pub use ops::explog::{exp_f16, exp2_f16, expm1_f16, log_f16, log1p_f16, log2_f16, log10_f16};
95#[cfg(feature = "f16")]
96pub use ops::floatintrinsic::{
97    clip_f16, isfinite_f16, isinf_f16, isnan_f16, maximum_f16, minimum_f16, nan_to_num_f16,
98};
99#[cfg(feature = "f16")]
100pub use ops::rounding::{ceil_f16, floor_f16, round_f16, trunc_f16};
101#[cfg(feature = "f16")]
102pub use ops::special::sinc_f16;
103#[cfg(feature = "f16")]
104pub use ops::trig::{
105    arccos_f16, arccosh_f16, arcsin_f16, arcsinh_f16, arctan_f16, arctan2_f16, arctanh_f16,
106    cos_f16, cosh_f16, degrees_f16, hypot_f16, radians_f16, sin_f16, sinh_f16, tan_f16, tanh_f16,
107};
108
109// Operator-style convenience functions
110pub use operator_overloads::{
111    array_add, array_bitand, array_bitnot, array_bitor, array_bitxor, array_div, array_mul,
112    array_neg, array_rem, array_shl, array_shr, array_sub,
113};