forked from Tensor-Array/Tensor-Array-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator.py
More file actions
80 lines (73 loc) · 2.97 KB
/
operator.py
File metadata and controls
80 lines (73 loc) · 2.97 KB
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
"""
# src/tensor_array/core/operator.py
# This module provides various mathematical operations for tensors, including addition, division, multiplication, power, matrix multiplication, and conditional selection.
# Each operation is implemented as a function that takes two tensors as input and returns a new tensor representing the result of the operation.
"""
from .tensor import Tensor
def add(value_1 : Tensor, value_2 : Tensor) -> Tensor:
"""
Adds two tensors element-wise.
Args:
value_1 (Tensor): The first tensor.
value_2 (Tensor): The second tensor.
Returns:
Tensor: A tensor that is the element-wise sum of value_1 and value_2
"""
from ..tensor2 import add as _add
return _add(value_1, value_2)
def divide(value_1 : Tensor, value_2 : Tensor) -> Tensor:
"""
Divides two tensors element-wise.
Args:
value_1 (Tensor): The first tensor.
value_2 (Tensor): The second tensor.
Returns:
Tensor: A tensor that is the element-wise division of value_1 by value_2
"""
from ..tensor2 import divide as _divide
return _divide(value_1, value_2)
def multiply(value_1 : Tensor, value_2 : Tensor) -> Tensor:
"""
Multiplies two tensors element-wise.
Args:
value_1 (Tensor): The first tensor.
value_2 (Tensor): The second tensor.
Returns:
Tensor: A tensor that is the element-wise product of value_1 and value_2
"""
from ..tensor2 import multiply as _multiply
return _multiply(value_1, value_2)
def power(value_1 : Tensor, value_2 : Tensor) -> Tensor:
"""
Raises the first tensor to the power of the second tensor element-wise.
Args:
value_1 (Tensor): The base tensor.
value_2 (Tensor): The exponent tensor.
Returns:
Tensor: A tensor that is the element-wise result of value_1 raised to the power of value_2
"""
from ..tensor2 import power as _power
return _power(value_1, value_2)
def matmul(value_1 : Tensor, value_2 : Tensor) -> Tensor:
"""
Performs matrix multiplication between two tensors.
Args:
value_1 (Tensor): The first tensor.
value_2 (Tensor): The second tensor.
Returns:
Tensor: A tensor that is the result of matrix multiplication between value_1 and value_2
"""
from ..tensor2 import matmul as _matmul
return _matmul(value_1, value_2)
def condition(condition_value : Tensor, value_if_true : Tensor, value_if_false : Tensor) -> Tensor:
"""
Chooses between two tensors based on a condition tensor.
Args:
condition_value (Tensor): The condition tensor.
value_if_true (Tensor): The tensor to return if the condition is true.
value_if_false (Tensor): The tensor to return if the condition is false.
Returns:
Tensor: A tensor that is either value_if_true or value_if_false, depending on the condition.
"""
from ..tensor2 import condition as _condition
return _condition(condition_value, value_if_true, value_if_false)