Adds radians and degrees (#1011)

This commit is contained in:
Aneesh Shetty
2024-04-22 13:17:49 -05:00
committed by GitHub
parent 3d405fb3b1
commit d0dbfe0b97
7 changed files with 120 additions and 1 deletions

View File

@@ -2192,6 +2192,16 @@ array arctanh(const array& a, StreamOrDevice s /* = {} */) {
a.shape(), dtype, std::make_shared<ArcTanh>(to_stream(s)), {input});
}
array degrees(const array& a, StreamOrDevice s /* = {} */) {
auto dtype = at_least_float(a.dtype());
return multiply(a, array(180.0 / M_PI, dtype), s);
}
array radians(const array& a, StreamOrDevice s /* = {} */) {
auto dtype = at_least_float(a.dtype());
return multiply(a, array(M_PI / 180.0, dtype), s);
}
array log(const array& a, StreamOrDevice s /* = {} */) {
auto dtype = at_least_float(a.dtype());
auto input = astype(a, dtype, s);

View File

@@ -851,6 +851,12 @@ array arccosh(const array& a, StreamOrDevice s = {});
/** Inverse Hyperbolic Tangent of the elements of an array */
array arctanh(const array& a, StreamOrDevice s = {});
/** Convert the elements of an array from Radians to Degrees **/
array degrees(const array& a, StreamOrDevice s = {});
/** Convert the elements of an array from Degrees to Radians **/
array radians(const array& a, StreamOrDevice s = {});
/** Natural logarithm of the elements of an array. */
array log(const array& a, StreamOrDevice s = {});