|
| 1 | +use intel_mkl_sys::*; |
| 2 | + |
| 3 | +trait VecMath: Sized { |
| 4 | + /* Arthmetic */ |
| 5 | + fn add(a: &[Self], b: &[Self], out: &mut [Self]); |
| 6 | + fn sub(a: &[Self], b: &[Self], out: &mut [Self]); |
| 7 | + fn mul(a: &[Self], b: &[Self], out: &mut [Self]); |
| 8 | + fn abs(in_: &[Self], out: &mut [Self]); |
| 9 | + |
| 10 | + /* Power and Root */ |
| 11 | + fn div(a: &[Self], b: &[Self], out: &mut [Self]); |
| 12 | + fn sqrt(in_: &[Self], out: &mut [Self]); |
| 13 | + fn pow(a: &[Self], b: &[Self], out: &mut [Self]); |
| 14 | + fn powx(a: &[Self], b: Self, out: &mut [Self]); |
| 15 | + |
| 16 | + /* Exponential and Logarithmic */ |
| 17 | + fn exp(in_: &[Self], out: &mut [Self]); |
| 18 | + fn ln(in_: &[Self], out: &mut [Self]); |
| 19 | + fn log10(in_: &[Self], out: &mut [Self]); |
| 20 | + |
| 21 | + /* Trigonometric */ |
| 22 | + fn cos(in_: &[Self], out: &mut [Self]); |
| 23 | + fn sin(in_: &[Self], out: &mut [Self]); |
| 24 | + fn tan(in_: &[Self], out: &mut [Self]); |
| 25 | + fn acos(in_: &[Self], out: &mut [Self]); |
| 26 | + fn asin(in_: &[Self], out: &mut [Self]); |
| 27 | + fn atan(in_: &[Self], out: &mut [Self]); |
| 28 | + |
| 29 | + /* Hyperbolic */ |
| 30 | + fn cosh(in_: &[Self], out: &mut [Self]); |
| 31 | + fn sinh(in_: &[Self], out: &mut [Self]); |
| 32 | + fn tanh(in_: &[Self], out: &mut [Self]); |
| 33 | + fn acosh(in_: &[Self], out: &mut [Self]); |
| 34 | + fn asinh(in_: &[Self], out: &mut [Self]); |
| 35 | + fn atanh(in_: &[Self], out: &mut [Self]); |
| 36 | +} |
| 37 | + |
| 38 | +trait VecMathReal: Sized { |
| 39 | + /* Arthmetic */ |
| 40 | + fn sqr(in_: &[Self], out: &mut [Self]); |
| 41 | + fn linear_frac(in_: &[Self], out: &mut [Self]); |
| 42 | + fn fmod(in_: &[Self], out: &mut [Self]); |
| 43 | + fn remainder(in_: &[Self], out: &mut [Self]); |
| 44 | + |
| 45 | + /* Power and Root */ |
| 46 | + fn inv(in_: &[Self], out: &mut [Self]); |
| 47 | + fn inv_sqrt(in_: &[Self], out: &mut [Self]); |
| 48 | + fn cbrt(in_: &[Self], out: &mut [Self]); |
| 49 | + fn inv_cbrt(in_: &[Self], out: &mut [Self]); |
| 50 | + fn pow2o3(in_: &[Self], out: &mut [Self]); |
| 51 | + fn pow3o2(in_: &[Self], out: &mut [Self]); |
| 52 | + fn powr(in_: &[Self], out: &mut [Self]); |
| 53 | + fn hypot(in_: &[Self], out: &mut [Self]); |
| 54 | + |
| 55 | + /* Exponential and Logarithmic */ |
| 56 | + fn exp2(in_: &[Self], out: &mut [Self]); |
| 57 | + fn exp10(in_: &[Self], out: &mut [Self]); |
| 58 | + fn expm1(in_: &[Self], out: &mut [Self]); |
| 59 | + fn log2(in_: &[Self], out: &mut [Self]); |
| 60 | + fn log1p(in_: &[Self], out: &mut [Self]); |
| 61 | + fn logb(in_: &[Self], out: &mut [Self]); |
| 62 | + |
| 63 | + /* Trigonometric */ |
| 64 | + fn sin_cos(in_: &[Self], out: &mut [Self]); |
| 65 | + fn atan2(in_: &[Self], out: &mut [Self]); |
| 66 | + |
| 67 | + /* Special */ |
| 68 | + fn erf(in_: &[Self], out: &mut [Self]); |
| 69 | + fn erfc(in_: &[Self], out: &mut [Self]); |
| 70 | + fn cdf_normal(in_: &[Self], out: &mut [Self]); |
| 71 | + fn erf_inv(in_: &[Self], out: &mut [Self]); |
| 72 | + fn erfc_inv(in_: &[Self], out: &mut [Self]); |
| 73 | + fn cdf_normal_inv(in_: &[Self], out: &mut [Self]); |
| 74 | + fn ln_gamma(in_: &[Self], out: &mut [Self]); |
| 75 | + fn gamma(in_: &[Self], out: &mut [Self]); |
| 76 | + fn exp_integral(in_: &[Self], out: &mut [Self]); |
| 77 | + |
| 78 | + /* Rounding */ |
| 79 | + fn floor(in_: &[Self], out: &mut [Self]); |
| 80 | + fn ceil(in_: &[Self], out: &mut [Self]); |
| 81 | + fn trunc(in_: &[Self], out: &mut [Self]); |
| 82 | + fn round(in_: &[Self], out: &mut [Self]); |
| 83 | + fn near_by_int(in_: &[Self], out: &mut [Self]); |
| 84 | + fn rint(in_: &[Self], out: &mut [Self]); |
| 85 | + fn modf(in_: &[Self], out: &mut [Self]); |
| 86 | + fn frac(in_: &[Self], out: &mut [Self]); |
| 87 | + |
| 88 | + /* Miscellaneous */ |
| 89 | + fn copy_sign(in_: &[Self], out: &mut [Self]); |
| 90 | + fn next_after(in_: &[Self], out: &mut [Self]); |
| 91 | + fn fdim(in_: &[Self], out: &mut [Self]); |
| 92 | + fn fmax(in_: &[Self], out: &mut [Self]); |
| 93 | + fn fmin(in_: &[Self], out: &mut [Self]); |
| 94 | + fn maxmag(in_: &[Self], out: &mut [Self]); |
| 95 | + fn minmag(in_: &[Self], out: &mut [Self]); |
| 96 | +} |
| 97 | + |
| 98 | +trait VecMathComplex: Sized { |
| 99 | + /* Arthmetic */ |
| 100 | + fn mulbyconj(in_: &[Self], out: &mut [Self]); |
| 101 | + fn conj(in_: &[Self], out: &mut [Self]); |
| 102 | + fn arg(in_: &[Self], out: &mut [Self]); |
| 103 | + |
| 104 | + /* Trigonometric */ |
| 105 | + fn cis(in_: &[Self], out: &mut [Self]); |
| 106 | +} |
| 107 | + |
| 108 | +macro_rules! impl_unary { |
| 109 | + ($scalar:ty, $name:ident, $impl_name:ident) => { |
| 110 | + fn $name(in_: &[$scalar], out: &mut [$scalar]) { |
| 111 | + assert_eq!(in_.len(), out.len()); |
| 112 | + let n = in_.len() as i32; |
| 113 | + unsafe { $impl_name(n, in_.as_ptr(), out.as_mut_ptr()) } |
| 114 | + } |
| 115 | + }; |
| 116 | +} |
| 117 | + |
| 118 | +macro_rules! impl_binary { |
| 119 | + ($scalar:ty, $name:ident, $impl_name:ident) => { |
| 120 | + fn $name(a: &[$scalar], b: &[$scalar], out: &mut [$scalar]) { |
| 121 | + assert_eq!(a.len(), out.len()); |
| 122 | + assert_eq!(b.len(), out.len()); |
| 123 | + let n = out.len() as i32; |
| 124 | + unsafe { $impl_name(n, a.as_ptr(), b.as_ptr(), out.as_mut_ptr()) } |
| 125 | + } |
| 126 | + }; |
| 127 | +} |
| 128 | + |
| 129 | +macro_rules! impl_binary_scalar { |
| 130 | + ($scalar:ty, $name:ident, $impl_name:ident) => { |
| 131 | + fn $name(a: &[$scalar], b: $scalar, out: &mut [$scalar]) { |
| 132 | + assert_eq!(a.len(), out.len()); |
| 133 | + let n = out.len() as i32; |
| 134 | + unsafe { $impl_name(n, a.as_ptr(), b, out.as_mut_ptr()) } |
| 135 | + } |
| 136 | + }; |
| 137 | +} |
| 138 | + |
| 139 | +impl VecMath for f32 { |
| 140 | + impl_binary!(f32, add, vsAdd); |
| 141 | + impl_binary!(f32, sub, vsSub); |
| 142 | + impl_binary!(f32, mul, vsMul); |
| 143 | + impl_unary!(f32, abs, vsAbs); |
| 144 | + |
| 145 | + impl_binary!(f32, div, vsDiv); |
| 146 | + impl_unary!(f32, sqrt, vsSqrt); |
| 147 | + impl_binary!(f32, pow, vsPow); |
| 148 | + impl_binary_scalar!(f32, powx, vsPowx); |
| 149 | + |
| 150 | + impl_unary!(f32, exp, vsExp); |
| 151 | + impl_unary!(f32, ln, vsLn); |
| 152 | + impl_unary!(f32, log10, vsLog10); |
| 153 | + |
| 154 | + impl_unary!(f32, cos, vsCos); |
| 155 | + impl_unary!(f32, sin, vsSin); |
| 156 | + impl_unary!(f32, tan, vsTan); |
| 157 | + impl_unary!(f32, acos, vsAcos); |
| 158 | + impl_unary!(f32, asin, vsAsin); |
| 159 | + impl_unary!(f32, atan, vsAtan); |
| 160 | + |
| 161 | + impl_unary!(f32, cosh, vsCosh); |
| 162 | + impl_unary!(f32, sinh, vsSinh); |
| 163 | + impl_unary!(f32, tanh, vsTanh); |
| 164 | + impl_unary!(f32, acosh, vsAcosh); |
| 165 | + impl_unary!(f32, asinh, vsAsinh); |
| 166 | + impl_unary!(f32, atanh, vsAtanh); |
| 167 | +} |
| 168 | + |
| 169 | +impl VecMath for f64 { |
| 170 | + impl_binary!(f64, add, vdAdd); |
| 171 | + impl_binary!(f64, sub, vdSub); |
| 172 | + impl_binary!(f64, mul, vdMul); |
| 173 | + impl_unary!(f64, abs, vdAbs); |
| 174 | + |
| 175 | + impl_binary!(f64, div, vdDiv); |
| 176 | + impl_unary!(f64, sqrt, vdSqrt); |
| 177 | + impl_binary!(f64, pow, vdPow); |
| 178 | + impl_binary_scalar!(f64, powx, vdPowx); |
| 179 | + |
| 180 | + impl_unary!(f64, exp, vdExp); |
| 181 | + impl_unary!(f64, ln, vdLn); |
| 182 | + impl_unary!(f64, log10, vdLog10); |
| 183 | + |
| 184 | + impl_unary!(f64, cos, vdCos); |
| 185 | + impl_unary!(f64, sin, vdSin); |
| 186 | + impl_unary!(f64, tan, vdTan); |
| 187 | + impl_unary!(f64, acos, vdAcos); |
| 188 | + impl_unary!(f64, asin, vdAsin); |
| 189 | + impl_unary!(f64, atan, vdAtan); |
| 190 | + |
| 191 | + impl_unary!(f64, cosh, vdCosh); |
| 192 | + impl_unary!(f64, sinh, vdSinh); |
| 193 | + impl_unary!(f64, tanh, vdTanh); |
| 194 | + impl_unary!(f64, acosh, vdAcosh); |
| 195 | + impl_unary!(f64, asinh, vdAsinh); |
| 196 | + impl_unary!(f64, atanh, vdAtanh); |
| 197 | +} |
0 commit comments