module Narray::Math
Overview
Exponential and logarithmic functions module
Defined in:
narray/math/exponential.crnarray/math/hyperbolic.cr
narray/math/trig.cr
Class Method Summary
-
.acos(arr : Array(T)) : Array(Float64) forall T
Computes the arc cosine (inverse cosine) of each element in the array.
-
.acos!(arr : Array(T)) : Array(T) forall T
Computes the arc cosine (inverse cosine) of each element in the array in-place.
-
.asin(arr : Array(T)) : Array(Float64) forall T
Computes the arc sine (inverse sine) of each element in the array.
-
.asin!(arr : Array(T)) : Array(T) forall T
Computes the arc sine (inverse sine) of each element in the array in-place.
-
.atan(arr : Array(T)) : Array(Float64) forall T
Computes the arc tangent (inverse tangent) of each element in the array.
-
.atan!(arr : Array(T)) : Array(T) forall T
Computes the arc tangent (inverse tangent) of each element in the array in-place.
-
.cos(arr : Array(T)) : Array(Float64) forall T
Computes the cosine of each element in the array.
-
.cos!(arr : Array(T)) : Array(T) forall T
Computes the cosine of each element in the array in-place.
-
.cosh(arr : Array(T)) : Array(Float64) forall T
Computes the hyperbolic cosine of each element in the array.
-
.cosh!(arr : Array(T)) : Array(T) forall T
Computes the hyperbolic cosine of each element in the array in-place.
-
.exp(arr : Array(T)) : Array(Float64) forall T
Computes the exponential of each element in the array.
-
.exp!(arr : Array(T)) : Array(T) forall T
Computes the exponential of each element in the array in-place.
-
.log(arr : Array(T)) : Array(Float64) forall T
Computes the natural logarithm of each element in the array.
-
.log!(arr : Array(T)) : Array(T) forall T
Computes the natural logarithm of each element in the array in-place.
-
.log10(arr : Array(T)) : Array(Float64) forall T
Computes the base-10 logarithm of each element in the array.
-
.log10!(arr : Array(T)) : Array(T) forall T
Computes the base-10 logarithm of each element in the array in-place.
-
.pow(arr : Array(T), power : Number) : Array(Float64) forall T
Raises each element of the array to the specified power.
-
.pow!(arr : Array(T), power : Number) : Array(T) forall T
Raises each element of the array to the specified power in-place.
-
.sin(arr : Array(T)) : Array(Float64) forall T
Computes the sine of each element in the array.
-
.sin!(arr : Array(T)) : Array(T) forall T
Computes the sine of each element in the array in-place.
-
.sinh(arr : Array(T)) : Array(Float64) forall T
Computes the hyperbolic sine of each element in the array.
-
.sinh!(arr : Array(T)) : Array(T) forall T
Computes the hyperbolic sine of each element in the array in-place.
-
.sqrt(arr : Array(T)) : Array(Float64) forall T
Computes the square root of each element in the array.
-
.sqrt!(arr : Array(T)) : Array(T) forall T
Computes the square root of each element in the array in-place.
-
.tan(arr : Array(T)) : Array(Float64) forall T
Computes the tangent of each element in the array.
-
.tan!(arr : Array(T)) : Array(T) forall T
Computes the tangent of each element in the array in-place.
-
.tanh(arr : Array(T)) : Array(Float64) forall T
Computes the hyperbolic tangent of each element in the array.
-
.tanh!(arr : Array(T)) : Array(T) forall T
Computes the hyperbolic tangent of each element in the array in-place.
Class Method Detail
Computes the arc cosine (inverse cosine) of each element in the array.
a = Narray.array([2, 2], [1.0, 0.7071, 0.5, 0.0])
b = Narray::Math.acos(a)
b.shape # => [2, 2]
b.data # => [0.0, 0.7854, 1.0472, 1.5708] (approximately)
Computes the arc cosine (inverse cosine) of each element in the array in-place.
a = Narray.array([2, 2], [1.0, 0.7071, 0.5, 0.0])
Narray::Math.acos!(a)
a.data # => [0.0, 0.7854, 1.0472, 1.5708] (approximately)
Computes the arc sine (inverse sine) of each element in the array.
a = Narray.array([2, 2], [0.0, 0.5, 0.7071, 1.0])
b = Narray::Math.asin(a)
b.shape # => [2, 2]
b.data # => [0.0, 0.5236, 0.7854, 1.5708] (approximately)
Computes the arc sine (inverse sine) of each element in the array in-place.
a = Narray.array([2, 2], [0.0, 0.5, 0.7071, 1.0])
Narray::Math.asin!(a)
a.data # => [0.0, 0.5236, 0.7854, 1.5708] (approximately)
Computes the arc tangent (inverse tangent) of each element in the array.
a = Narray.array([2, 2], [0.0, 1.0, 1.7321, 10.0])
b = Narray::Math.atan(a)
b.shape # => [2, 2]
b.data # => [0.0, 0.7854, 1.0472, 1.4711] (approximately)
Computes the arc tangent (inverse tangent) of each element in the array in-place.
a = Narray.array([2, 2], [0.0, 1.0, 1.7321, 10.0])
Narray::Math.atan!(a)
a.data # => [0.0, 0.7854, 1.0472, 1.4711] (approximately)
Computes the cosine of each element in the array.
a = Narray.array([2, 2], [0.0, Math::PI/2, Math::PI, 3*Math::PI/2])
b = Narray::Math.cos(a)
b.shape # => [2, 2]
b.data # => [1.0, 0.0, -1.0, 0.0] (approximately)
Computes the cosine of each element in the array in-place.
a = Narray.array([2, 2], [0.0, Math::PI/2, Math::PI, 3*Math::PI/2])
Narray::Math.cos!(a)
a.data # => [1.0, 0.0, -1.0, 0.0] (approximately)
Computes the hyperbolic cosine of each element in the array.
a = Narray.array([2, 2], [0.0, 0.5, 1.0, 2.0])
b = Narray::Math.cosh(a)
b.shape # => [2, 2]
b.data # => [1.0, 1.1276, 1.5431, 3.7622] (approximately)
Computes the hyperbolic cosine of each element in the array in-place.
a = Narray.array([2, 2], [0.0, 0.5, 1.0, 2.0])
Narray::Math.cosh!(a)
a.data # => [1.0, 1.1276, 1.5431, 3.7622] (approximately)
Computes the exponential of each element in the array.
a = Narray.array([2, 2], [0.0, 1.0, 2.0, 3.0])
b = Narray::Math.exp(a)
b.shape # => [2, 2]
b.data # => [1.0, 2.7183, 7.3891, 20.0855] (approximately)
Computes the exponential of each element in the array in-place.
a = Narray.array([2, 2], [0.0, 1.0, 2.0, 3.0])
Narray::Math.exp!(a)
a.data # => [1.0, 2.7183, 7.3891, 20.0855] (approximately)
Computes the natural logarithm of each element in the array.
a = Narray.array([2, 2], [1.0, 2.0, 5.0, 10.0])
b = Narray::Math.log(a)
b.shape # => [2, 2]
b.data # => [0.0, 0.6931, 1.6094, 2.3026] (approximately)
Computes the natural logarithm of each element in the array in-place.
a = Narray.array([2, 2], [1.0, 2.0, 5.0, 10.0])
Narray::Math.log!(a)
a.data # => [0.0, 0.6931, 1.6094, 2.3026] (approximately)
Computes the base-10 logarithm of each element in the array.
a = Narray.array([2, 2], [1.0, 10.0, 100.0, 1000.0])
b = Narray::Math.log10(a)
b.shape # => [2, 2]
b.data # => [0.0, 1.0, 2.0, 3.0]
Computes the base-10 logarithm of each element in the array in-place.
a = Narray.array([2, 2], [1.0, 10.0, 100.0, 1000.0])
Narray::Math.log10!(a)
a.data # => [0.0, 1.0, 2.0, 3.0]
Raises each element of the array to the specified power.
a = Narray.array([2, 2], [1.0, 2.0, 3.0, 4.0])
b = Narray::Math.pow(a, 2)
b.shape # => [2, 2]
b.data # => [1.0, 4.0, 9.0, 16.0]
Raises each element of the array to the specified power in-place.
a = Narray.array([2, 2], [1.0, 2.0, 3.0, 4.0])
Narray::Math.pow!(a, 2)
a.data # => [1.0, 4.0, 9.0, 16.0]
Computes the sine of each element in the array.
a = Narray.array([2, 2], [0.0, Math::PI/2, Math::PI, 3*Math::PI/2])
b = Narray::Math.sin(a)
b.shape # => [2, 2]
b.data # => [0.0, 1.0, 0.0, -1.0] (approximately)
Computes the sine of each element in the array in-place.
a = Narray.array([2, 2], [0.0, Math::PI/2, Math::PI, 3*Math::PI/2])
Narray::Math.sin!(a)
a.data # => [0.0, 1.0, 0.0, -1.0] (approximately)
Computes the hyperbolic sine of each element in the array.
a = Narray.array([2, 2], [0.0, 0.5, 1.0, 2.0])
b = Narray::Math.sinh(a)
b.shape # => [2, 2]
b.data # => [0.0, 0.5211, 1.1752, 3.6269] (approximately)
Computes the hyperbolic sine of each element in the array in-place.
a = Narray.array([2, 2], [0.0, 0.5, 1.0, 2.0])
Narray::Math.sinh!(a)
a.data # => [0.0, 0.5211, 1.1752, 3.6269] (approximately)
Computes the square root of each element in the array.
a = Narray.array([2, 2], [1.0, 4.0, 9.0, 16.0])
b = Narray::Math.sqrt(a)
b.shape # => [2, 2]
b.data # => [1.0, 2.0, 3.0, 4.0]
Computes the square root of each element in the array in-place.
a = Narray.array([2, 2], [1.0, 4.0, 9.0, 16.0])
Narray::Math.sqrt!(a)
a.data # => [1.0, 2.0, 3.0, 4.0]
Computes the tangent of each element in the array.
a = Narray.array([2, 2], [0.0, Math::PI/4, Math::PI/2 - 0.01, Math::PI])
b = Narray::Math.tan(a)
b.shape # => [2, 2]
b.data # => [0.0, 1.0, very large value, 0.0] (approximately)
Computes the tangent of each element in the array in-place.
a = Narray.array([2, 2], [0.0, Math::PI/4, Math::PI/2 - 0.01, Math::PI])
Narray::Math.tan!(a)
a.data # => [0.0, 1.0, very large value, 0.0] (approximately)
Computes the hyperbolic tangent of each element in the array.
a = Narray.array([2, 2], [0.0, 0.5, 1.0, 2.0])
b = Narray::Math.tanh(a)
b.shape # => [2, 2]
b.data # => [0.0, 0.4621, 0.7616, 0.9640] (approximately)
Computes the hyperbolic tangent of each element in the array in-place.
a = Narray.array([2, 2], [0.0, 0.5, 1.0, 2.0])
Narray::Math.tanh!(a)
a.data # => [0.0, 0.4621, 0.7616, 0.9640] (approximately)