|
2 | 2 |
|
3 | 3 | #[cfg(feature = "std")]
|
4 | 4 | use num_traits::Float;
|
| 5 | +use std::borrow::Borrow; |
5 | 6 |
|
6 | 7 | use crate::imp_prelude::*;
|
| 8 | +use crate::IntoNdProducer; |
7 | 9 |
|
8 | 10 | #[cfg(feature = "std")]
|
9 | 11 | macro_rules! boolean_ops {
|
@@ -50,6 +52,18 @@ macro_rules! binary_ops {
|
50 | 52 | };
|
51 | 53 | }
|
52 | 54 |
|
| 55 | +#[cfg(feature = "std")] |
| 56 | +macro_rules! binary_ops_array { |
| 57 | + ($($(#[$meta:meta])* fn $fn_use:ident($ty:ty) as $fn_name:ident)+) => { |
| 58 | + $($(#[$meta])* |
| 59 | + #[must_use = "method returns a new array and does not mutate the original value"] |
| 60 | + pub fn $fn_name<P>(&self, rhs: P) -> Array<A, D> |
| 61 | + where P: IntoNdProducer<Dim = D, Item: Borrow<$ty>> { |
| 62 | + $crate::Zip::from(self).and(rhs).map_collect(|a, b| A::$fn_use(*a, *b.borrow())) |
| 63 | + })+ |
| 64 | + }; |
| 65 | +} |
| 66 | + |
53 | 67 | /// # Element-wise methods for float arrays
|
54 | 68 | ///
|
55 | 69 | /// Element-wise math functions for any array type that contains float number.
|
@@ -157,6 +171,22 @@ where
|
157 | 171 | fn abs_sub(A)
|
158 | 172 | /// Length of the hypotenuse of a right-angle triangle of each element
|
159 | 173 | fn hypot(A)
|
| 174 | + /// Four quadrant arctangent of each element in radians. |
| 175 | + fn atan2(A) |
| 176 | + } |
| 177 | + binary_ops_array! { |
| 178 | + /// Integer power of each element. |
| 179 | + fn powi(i32) as powi_all |
| 180 | + /// Float power of each element. |
| 181 | + fn powf(A) as powf_all |
| 182 | + /// Logarithm of each element with respect to an arbitrary base. |
| 183 | + fn log(A) as log_all |
| 184 | + /// The positive difference between given number and each element. |
| 185 | + fn abs_sub(A) as abs_sub_all |
| 186 | + /// Length of the hypotenuse of a right-angle triangle of each element |
| 187 | + fn hypot(A) as hypot_all |
| 188 | + /// Four quadrant arctangent of each element in radians. |
| 189 | + fn atan2(A) as atan2_all |
160 | 190 | }
|
161 | 191 |
|
162 | 192 | /// Square (two powers) of each element.
|
|
0 commit comments