Skip to content

Commit

Permalink
Update _math_tensor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed Jun 9, 2024
1 parent 8a82054 commit 4419c79
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/tensortrax/math/_math_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ def array(object, dtype=None, like=None, shape=None):


def trace(A):
"Return the sum along diagonals of the array."
return einsum("ii...->...", A)


def transpose(A):
"Returns an array with axes transposed."
return einsum("ij...->ji...", A)


def sum(A, axis=0):
"Sum of array elements over a given axis."
if isinstance(A, Tensor):
return Tensor(
x=np.sum(f(A), axis=axis),
Expand All @@ -62,6 +65,7 @@ def sum(A, axis=0):


def sign(A):
"Returns an element-wise indication of the sign of a number."
if isinstance(A, Tensor):
return Tensor(
x=np.sign(f(A)),
Expand All @@ -75,6 +79,7 @@ def sign(A):


def abs(A):
"Calculate the absolute value element-wise."
if isinstance(A, Tensor):
return Tensor(
x=np.abs(f(A)),
Expand All @@ -95,6 +100,7 @@ def sqrt(A):


def sin(A):
"Trigonometric sine, element-wise."
if isinstance(A, Tensor):
return Tensor(
x=np.sin(f(A)),
Expand All @@ -108,6 +114,7 @@ def sin(A):


def cos(A):
"Cosine element-wise."
if isinstance(A, Tensor):
return Tensor(
x=np.cos(f(A)),
Expand All @@ -121,6 +128,7 @@ def cos(A):


def tan(A):
"Compute tangent element-wise."
if isinstance(A, Tensor):
return Tensor(
x=np.tan(f(A)),
Expand All @@ -135,6 +143,7 @@ def tan(A):


def sinh(A):
"Hyperbolic sine, element-wise."
if isinstance(A, Tensor):
return Tensor(
x=np.sinh(f(A)),
Expand All @@ -148,6 +157,7 @@ def sinh(A):


def cosh(A):
"Hyperbolic cosine, element-wise."
if isinstance(A, Tensor):
return Tensor(
x=np.cosh(f(A)),
Expand All @@ -161,6 +171,7 @@ def cosh(A):


def tanh(A):
"Compute hyperbolic tangent element-wise."
if isinstance(A, Tensor):
x = np.tanh(f(A))
return Tensor(
Expand All @@ -175,6 +186,7 @@ def tanh(A):


def exp(A):
"Calculate the exponential of all elements in the input array."
if isinstance(A, Tensor):
x = np.exp(f(A))
return Tensor(
Expand All @@ -189,6 +201,7 @@ def exp(A):


def log(A):
"Natural logarithm, element-wise."
if isinstance(A, Tensor):
x = np.log(f(A))
return Tensor(
Expand All @@ -203,6 +216,7 @@ def log(A):


def log10(A):
"Return the base 10 logarithm of the input array, element-wise."
if isinstance(A, Tensor):
x = np.log10(f(A))
return Tensor(
Expand Down

0 comments on commit 4419c79

Please sign in to comment.