1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
use crate::{
core::prelude::*,
errors::prelude::*,
numeric::prelude::*,
};
/// ArrayTrait - Array Hyperbolic functions
pub trait ArrayHyperbolic<N: Numeric> where Self: Sized + Clone {
/// Compute the hyperbolic sine of array elements
///
/// # Examples
///
/// ```
/// use arr_rs::prelude::*;
///
/// let arr = Array::flat(vec![-1., 0., 1.]).unwrap();
/// assert_eq!(Array::flat(vec![-1.1752011936438014, 0., 1.1752011936438014]), arr.sinh());
/// ```
fn sinh(&self) -> Result<Array<N>, ArrayError>;
/// Compute the hyperbolic cosine of array elements
///
/// # Examples
///
/// ```
/// use arr_rs::prelude::*;
///
/// let arr = Array::flat(vec![-1., 0., 1.]).unwrap();
/// assert_eq!(Array::flat(vec![1.5430806348152437, 1., 1.5430806348152437]), arr.cosh());
/// ```
fn cosh(&self) -> Result<Array<N>, ArrayError>;
/// Compute the hyperbolic tangent of array elements
///
/// # Examples
///
/// ```
/// use arr_rs::prelude::*;
///
/// let arr = Array::flat(vec![-1., 0., 1.]).unwrap();
/// assert_eq!(Array::flat(vec![-0.7615941559557649, 0., 0.7615941559557649]), arr.tanh());
/// ```
fn tanh(&self) -> Result<Array<N>, ArrayError>;
/// Compute the inverse hyperbolic sine of array elements
///
/// # Examples
///
/// ```
/// use arr_rs::prelude::*;
///
/// let arr = Array::flat(vec![-1., 0., 1.]).unwrap();
/// assert_eq!(Array::flat(vec![-0.881373587019543, 0., 0.881373587019543]), arr.asinh());
/// ```
fn asinh(&self) -> Result<Array<N>, ArrayError>;
/// Compute the inverse hyperbolic cosine of array elements
///
/// # Examples
///
/// ```
/// use arr_rs::prelude::*;
///
/// let arr = Array::flat(vec![1., 2., 3.]).unwrap();
/// assert_eq!(Array::flat(vec![0., 1.3169578969248166, 1.762747174039086]), arr.acosh());
/// ```
fn acosh(&self) -> Result<Array<N>, ArrayError>;
/// Compute the inverse hyperbolic tangent of array elements
///
/// # Examples
///
/// ```
/// use arr_rs::prelude::*;
///
/// let arr = Array::flat(vec![-1., 0., 1.]).unwrap();
/// assert_eq!(Array::flat(vec![-f64::INFINITY, 0., f64::INFINITY]), arr.atanh());
/// ```
fn atanh(&self) -> Result<Array<N>, ArrayError>;
}
impl <N: Numeric> ArrayHyperbolic<N> for Array<N> {
fn sinh(&self) -> Result<Array<N>, ArrayError> {
self.map(|i| N::from(i.to_f64().sinh()))
}
fn cosh(&self) -> Result<Array<N>, ArrayError> {
self.map(|i| N::from(i.to_f64().cosh()))
}
fn tanh(&self) -> Result<Array<N>, ArrayError> {
self.map(|i| N::from(i.to_f64().tanh()))
}
fn asinh(&self) -> Result<Array<N>, ArrayError> {
self.map(|i| N::from(i.to_f64().asinh()))
}
fn acosh(&self) -> Result<Array<N>, ArrayError> {
self.map(|i| N::from(i.to_f64().acosh()))
}
fn atanh(&self) -> Result<Array<N>, ArrayError> {
self.map(|i| N::from(i.to_f64().atanh()))
}
}
impl <N: Numeric> ArrayHyperbolic<N> for Result<Array<N>, ArrayError> {
fn sinh(&self) -> Result<Array<N>, ArrayError> {
self.clone()?.sinh()
}
fn cosh(&self) -> Result<Array<N>, ArrayError> {
self.clone()?.cosh()
}
fn tanh(&self) -> Result<Array<N>, ArrayError> {
self.clone()?.tanh()
}
fn asinh(&self) -> Result<Array<N>, ArrayError> {
self.clone()?.asinh()
}
fn acosh(&self) -> Result<Array<N>, ArrayError> {
self.clone()?.acosh()
}
fn atanh(&self) -> Result<Array<N>, ArrayError> {
self.clone()?.atanh()
}
}