DepthTensor 1.9.0__tar.gz → 1.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {depthtensor-1.9.0/src/DepthTensor.egg-info → depthtensor-1.11.0}/PKG-INFO +1 -1
- {depthtensor-1.9.0 → depthtensor-1.11.0}/pyproject.toml +1 -1
- depthtensor-1.11.0/src/DepthTensor/__init__.py +7 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/ops/comparison.py +15 -15
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/ops/creation.py +4 -6
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/ops/diff.py +5 -2
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/ops/elementwise.py +206 -56
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/ops/reduction.py +13 -11
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/utils.py +22 -6
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/tensor.py +115 -68
- depthtensor-1.11.0/src/DepthTensor/typing.py +125 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0/src/DepthTensor.egg-info}/PKG-INFO +1 -1
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor.egg-info/SOURCES.txt +1 -0
- depthtensor-1.11.0/src/example/example.py +25 -0
- depthtensor-1.11.0/src/example/test.py +12 -0
- depthtensor-1.9.0/src/DepthTensor/__init__.py +0 -6
- depthtensor-1.9.0/src/DepthTensor/typing.py +0 -41
- depthtensor-1.9.0/src/example/example.py +0 -9
- {depthtensor-1.9.0 → depthtensor-1.11.0}/LICENSE +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/README.md +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/setup.cfg +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/__init__.py +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/exceptions.py +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/ops/__init__.py +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/random/__init__.py +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/_core/random/generator.py +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor/autodiff.py +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor.egg-info/requires.txt +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
- {depthtensor-1.9.0 → depthtensor-1.11.0}/tests/test_tensor.py +0 -0
|
@@ -8,7 +8,7 @@ from typing import (
|
|
|
8
8
|
from ...typing import (
|
|
9
9
|
TensorLike,
|
|
10
10
|
DeviceLike,
|
|
11
|
-
|
|
11
|
+
NDArrayLikeBool,
|
|
12
12
|
Casting,
|
|
13
13
|
Order,
|
|
14
14
|
OperandLike
|
|
@@ -91,11 +91,11 @@ def wrapper_2in_1out(
|
|
|
91
91
|
x1: OperandLike,
|
|
92
92
|
x2: OperandLike,
|
|
93
93
|
/,
|
|
94
|
-
out: Optional[
|
|
94
|
+
out: Optional[NDArrayLikeBool] = None,
|
|
95
95
|
*,
|
|
96
96
|
func_name: str,
|
|
97
97
|
device: DeviceLike = "cpu",
|
|
98
|
-
where: Union[bool,
|
|
98
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
99
99
|
casting: Casting = 'same_kind',
|
|
100
100
|
order: Order = 'K',
|
|
101
101
|
dtype: None = None,
|
|
@@ -128,10 +128,10 @@ def equal(
|
|
|
128
128
|
x1: OperandLike,
|
|
129
129
|
x2: OperandLike,
|
|
130
130
|
/,
|
|
131
|
-
out: Optional[
|
|
131
|
+
out: Optional[NDArrayLikeBool] = None,
|
|
132
132
|
*,
|
|
133
133
|
device: DeviceLike = "cpu",
|
|
134
|
-
where: Union[bool,
|
|
134
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
135
135
|
casting: Casting = 'same_kind',
|
|
136
136
|
order: Order = 'K',
|
|
137
137
|
dtype: None = None,
|
|
@@ -143,10 +143,10 @@ def not_equal(
|
|
|
143
143
|
x1: OperandLike,
|
|
144
144
|
x2: OperandLike,
|
|
145
145
|
/,
|
|
146
|
-
out: Optional[
|
|
146
|
+
out: Optional[NDArrayLikeBool] = None,
|
|
147
147
|
*,
|
|
148
148
|
device: DeviceLike = "cpu",
|
|
149
|
-
where: Union[bool,
|
|
149
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
150
150
|
casting: Casting = 'same_kind',
|
|
151
151
|
order: Order = 'K',
|
|
152
152
|
dtype: None = None,
|
|
@@ -158,10 +158,10 @@ def greater(
|
|
|
158
158
|
x1: OperandLike,
|
|
159
159
|
x2: OperandLike,
|
|
160
160
|
/,
|
|
161
|
-
out: Optional[
|
|
161
|
+
out: Optional[NDArrayLikeBool] = None,
|
|
162
162
|
*,
|
|
163
163
|
device: DeviceLike = "cpu",
|
|
164
|
-
where: Union[bool,
|
|
164
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
165
165
|
casting: Casting = 'same_kind',
|
|
166
166
|
order: Order = 'K',
|
|
167
167
|
dtype: None = None,
|
|
@@ -173,10 +173,10 @@ def greater_equal(
|
|
|
173
173
|
x1: OperandLike,
|
|
174
174
|
x2: OperandLike,
|
|
175
175
|
/,
|
|
176
|
-
out: Optional[
|
|
176
|
+
out: Optional[NDArrayLikeBool] = None,
|
|
177
177
|
*,
|
|
178
178
|
device: DeviceLike = "cpu",
|
|
179
|
-
where: Union[bool,
|
|
179
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
180
180
|
casting: Casting = 'same_kind',
|
|
181
181
|
order: Order = 'K',
|
|
182
182
|
dtype: None = None,
|
|
@@ -188,10 +188,10 @@ def less(
|
|
|
188
188
|
x1: OperandLike,
|
|
189
189
|
x2: OperandLike,
|
|
190
190
|
/,
|
|
191
|
-
out: Optional[
|
|
191
|
+
out: Optional[NDArrayLikeBool] = None,
|
|
192
192
|
*,
|
|
193
193
|
device: DeviceLike = "cpu",
|
|
194
|
-
where: Union[bool,
|
|
194
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
195
195
|
casting: Casting = 'same_kind',
|
|
196
196
|
order: Order = 'K',
|
|
197
197
|
dtype: None = None,
|
|
@@ -203,10 +203,10 @@ def less_equal(
|
|
|
203
203
|
x1: OperandLike,
|
|
204
204
|
x2: OperandLike,
|
|
205
205
|
/,
|
|
206
|
-
out: Optional[
|
|
206
|
+
out: Optional[NDArrayLikeBool] = None,
|
|
207
207
|
*,
|
|
208
208
|
device: DeviceLike = "cpu",
|
|
209
|
-
where: Union[bool,
|
|
209
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
210
210
|
casting: Casting = 'same_kind',
|
|
211
211
|
order: Order = 'K',
|
|
212
212
|
dtype: None = None,
|
|
@@ -6,7 +6,7 @@ from ...typing import (
|
|
|
6
6
|
TensorLike,
|
|
7
7
|
DTypeLike,
|
|
8
8
|
Order,
|
|
9
|
-
|
|
9
|
+
AxisLike,
|
|
10
10
|
OperandLike,
|
|
11
11
|
DeviceLike
|
|
12
12
|
)
|
|
@@ -36,7 +36,7 @@ def zeros_like(
|
|
|
36
36
|
dtype: Optional[DTypeLike] = None,
|
|
37
37
|
order: Order = 'K',
|
|
38
38
|
subok: bool = True,
|
|
39
|
-
shape: Optional[
|
|
39
|
+
shape: Optional[AxisLike] = None
|
|
40
40
|
) -> TensorLike:
|
|
41
41
|
from ...tensor import Tensor
|
|
42
42
|
if isinstance(a, Tensor):
|
|
@@ -52,7 +52,6 @@ def zeros_like(
|
|
|
52
52
|
else:
|
|
53
53
|
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
54
54
|
return Tensor(
|
|
55
|
-
#! As of the time writing this, CuPy does not support subok.
|
|
56
55
|
cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
|
|
57
56
|
device=device_op, requires_grad=requires_grad
|
|
58
57
|
)
|
|
@@ -66,7 +65,7 @@ def ones_like(
|
|
|
66
65
|
dtype: Optional[DTypeLike] = None,
|
|
67
66
|
order: Order = 'K',
|
|
68
67
|
subok: bool = True,
|
|
69
|
-
shape: Optional[
|
|
68
|
+
shape: Optional[AxisLike] = None
|
|
70
69
|
) -> TensorLike:
|
|
71
70
|
from ...tensor import Tensor
|
|
72
71
|
if isinstance(a, Tensor):
|
|
@@ -82,11 +81,10 @@ def ones_like(
|
|
|
82
81
|
else:
|
|
83
82
|
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
84
83
|
return Tensor(
|
|
85
|
-
#! As of the time writing this, CuPy does not support subok.
|
|
86
84
|
cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
|
|
87
85
|
device=device_op, requires_grad=requires_grad
|
|
88
86
|
)
|
|
89
|
-
|
|
87
|
+
|
|
90
88
|
###
|
|
91
89
|
###
|
|
92
90
|
###
|
|
@@ -19,7 +19,7 @@ except (ImportError, ModuleNotFoundError):
|
|
|
19
19
|
cp = None
|
|
20
20
|
|
|
21
21
|
###
|
|
22
|
-
###
|
|
22
|
+
###
|
|
23
23
|
###
|
|
24
24
|
|
|
25
25
|
def wrapper_2in_diff(result: TensorLike, x1: OperandLike, x2: OperandLike, callback_x1: Callable, callback_x2: Callable) -> TensorLike:
|
|
@@ -44,6 +44,10 @@ def wrapper_1in_diff(result: TensorLike, x: OperandLike, callback_x1: Callable)
|
|
|
44
44
|
result.backward = backward
|
|
45
45
|
return result
|
|
46
46
|
|
|
47
|
+
###
|
|
48
|
+
### Arithmetics
|
|
49
|
+
###
|
|
50
|
+
|
|
47
51
|
def add_diff(result: TensorLike, x1: OperandLike, x2: OperandLike) -> TensorLike:
|
|
48
52
|
def callback_x1(shape, device, _x1, _x2):
|
|
49
53
|
return sum_to_shape(result.grad, shape, device)
|
|
@@ -143,7 +147,6 @@ __all__ = [
|
|
|
143
147
|
'negative_diff',
|
|
144
148
|
'sign_diff',
|
|
145
149
|
'abs_diff',
|
|
146
|
-
|
|
147
150
|
'exp_diff',
|
|
148
151
|
'sqrt_diff',
|
|
149
152
|
'log_diff',
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from typing import (
|
|
2
2
|
Optional,
|
|
3
3
|
Union,
|
|
4
|
-
Any
|
|
4
|
+
Any,
|
|
5
|
+
Callable
|
|
5
6
|
)
|
|
6
7
|
|
|
7
8
|
from ...typing import (
|
|
@@ -9,10 +10,16 @@ from ...typing import (
|
|
|
9
10
|
DTypeLike,
|
|
10
11
|
Casting,
|
|
11
12
|
Order,
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
NDArrayLikeBool,
|
|
14
|
+
NDArrayLike,
|
|
14
15
|
OperandLike,
|
|
15
|
-
DeviceLike
|
|
16
|
+
DeviceLike,
|
|
17
|
+
Op_2in_1out_Protocol,
|
|
18
|
+
Diff_2in_1out_Protocol,
|
|
19
|
+
Func_2in_1out_Protocol,
|
|
20
|
+
Op_1in_1out_Protocol,
|
|
21
|
+
Diff_1in_1out_Protocol,
|
|
22
|
+
Func_1in_1out_Protocol
|
|
16
23
|
)
|
|
17
24
|
|
|
18
25
|
from ..exceptions import (
|
|
@@ -21,7 +28,8 @@ from ..exceptions import (
|
|
|
21
28
|
)
|
|
22
29
|
|
|
23
30
|
from ..utils import (
|
|
24
|
-
to_xp_array
|
|
31
|
+
to_xp_array,
|
|
32
|
+
get_device
|
|
25
33
|
)
|
|
26
34
|
|
|
27
35
|
import numpy as np
|
|
@@ -31,19 +39,145 @@ except (ImportError, ModuleNotFoundError):
|
|
|
31
39
|
cp = None
|
|
32
40
|
|
|
33
41
|
###
|
|
34
|
-
### Arithmetics
|
|
35
42
|
###
|
|
43
|
+
###
|
|
44
|
+
|
|
45
|
+
def create_2in_1out(
|
|
46
|
+
op: Op_2in_1out_Protocol,
|
|
47
|
+
diff: Optional[Diff_2in_1out_Protocol]
|
|
48
|
+
) -> Func_2in_1out_Protocol:
|
|
49
|
+
def func(
|
|
50
|
+
x1: OperandLike,
|
|
51
|
+
x2: OperandLike,
|
|
52
|
+
*,
|
|
53
|
+
device: Optional[DeviceLike] = None,
|
|
54
|
+
in_place: bool = False,
|
|
55
|
+
requires_grad: bool = True,
|
|
56
|
+
**kwds: Any
|
|
57
|
+
) -> TensorLike:
|
|
58
|
+
from ...tensor import Tensor
|
|
59
|
+
is_tensor_op = False
|
|
60
|
+
if isinstance(x1, Tensor) and isinstance(x2, Tensor):
|
|
61
|
+
if not x1.is_device(x2.device):
|
|
62
|
+
raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
63
|
+
else:
|
|
64
|
+
is_tensor_op = True
|
|
65
|
+
|
|
66
|
+
if is_tensor_op and isinstance(x1, Tensor):
|
|
67
|
+
device_op = x1.device
|
|
68
|
+
else:
|
|
69
|
+
if device is None:
|
|
70
|
+
_x1_device = get_device(x1)
|
|
71
|
+
if _x1_device != get_device(x2):
|
|
72
|
+
raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
73
|
+
device_op = _x1_device
|
|
74
|
+
else:
|
|
75
|
+
device_op = device
|
|
76
|
+
|
|
77
|
+
a1, a2 = to_xp_array(x1, device=device_op), to_xp_array(x2, device=device_op)
|
|
78
|
+
y = op(a1, a2, device=device_op, **kwds)
|
|
79
|
+
|
|
80
|
+
if is_tensor_op and in_place and isinstance(x1, Tensor):
|
|
81
|
+
if isinstance(y, Tensor):
|
|
82
|
+
x1.data = y.data
|
|
83
|
+
return x1
|
|
84
|
+
else:
|
|
85
|
+
x1.data = y
|
|
86
|
+
return x1
|
|
87
|
+
|
|
88
|
+
y_requires_grad = False
|
|
89
|
+
prev = ()
|
|
90
|
+
if isinstance(x1, Tensor):
|
|
91
|
+
y_requires_grad = x1.requires_grad
|
|
92
|
+
prev = (x1,)
|
|
93
|
+
if isinstance(x2, Tensor):
|
|
94
|
+
y_requires_grad = y_requires_grad or x2.requires_grad
|
|
95
|
+
if len(prev) == 1:
|
|
96
|
+
prev = (x1, x2)
|
|
97
|
+
else:
|
|
98
|
+
prev = (x2,)
|
|
99
|
+
|
|
100
|
+
if isinstance(y, Tensor):
|
|
101
|
+
y.to_device(device_op, in_place=True)
|
|
102
|
+
y.prev = prev
|
|
103
|
+
if y_requires_grad and requires_grad:
|
|
104
|
+
y.make_differentiable()
|
|
105
|
+
else:
|
|
106
|
+
y = Tensor(y, device=device_op, prev=prev, requires_grad=y_requires_grad and requires_grad)
|
|
107
|
+
if diff is None:
|
|
108
|
+
return y
|
|
109
|
+
else:
|
|
110
|
+
if y.requires_grad:
|
|
111
|
+
dx1, dx2 = diff(y, a1, a2)
|
|
112
|
+
def backward() -> None:
|
|
113
|
+
if isinstance(x1, Tensor) and x1.requires_grad:
|
|
114
|
+
x1.grad += y.grad * dx1()
|
|
115
|
+
if isinstance(x2, Tensor) and x2.requires_grad:
|
|
116
|
+
x2.grad += y.grad * dx2()
|
|
117
|
+
y.backward = backward
|
|
118
|
+
return y
|
|
119
|
+
return func
|
|
120
|
+
|
|
121
|
+
def create_1in_1out(
|
|
122
|
+
op: Op_1in_1out_Protocol,
|
|
123
|
+
diff: Optional[Diff_1in_1out_Protocol]
|
|
124
|
+
) -> Func_1in_1out_Protocol:
|
|
125
|
+
def func(
|
|
126
|
+
x: OperandLike,
|
|
127
|
+
*,
|
|
128
|
+
device: Optional[DeviceLike] = None,
|
|
129
|
+
in_place: bool = False,
|
|
130
|
+
requires_grad: bool = True,
|
|
131
|
+
**kwds: Any
|
|
132
|
+
) -> TensorLike:
|
|
133
|
+
from ...tensor import Tensor
|
|
134
|
+
if isinstance(x, Tensor):
|
|
135
|
+
device_op = x.device
|
|
136
|
+
else:
|
|
137
|
+
if device is None:
|
|
138
|
+
device_op = get_device(x)
|
|
139
|
+
else:
|
|
140
|
+
device_op = device
|
|
141
|
+
|
|
142
|
+
a = to_xp_array(x, device=device_op)
|
|
143
|
+
y = op(a, device=device_op, **kwds)
|
|
144
|
+
|
|
145
|
+
y_requires_grad = False
|
|
146
|
+
if isinstance(x, Tensor):
|
|
147
|
+
if in_place:
|
|
148
|
+
x.data = y
|
|
149
|
+
return x
|
|
150
|
+
y_requires_grad = x.requires_grad
|
|
151
|
+
|
|
152
|
+
if isinstance(y, Tensor):
|
|
153
|
+
y.to_device(device_op)
|
|
154
|
+
y.prev = (x,)
|
|
155
|
+
if y_requires_grad and requires_grad:
|
|
156
|
+
y.make_differentiable()
|
|
157
|
+
else:
|
|
158
|
+
y = Tensor(y, device=device_op, prev=(x,), requires_grad=y_requires_grad and requires_grad)
|
|
159
|
+
if diff is None:
|
|
160
|
+
return y
|
|
161
|
+
else:
|
|
162
|
+
if y.requires_grad:
|
|
163
|
+
dx = diff(y, a)
|
|
164
|
+
def backward() -> None:
|
|
165
|
+
if isinstance(x, Tensor) and x.requires_grad:
|
|
166
|
+
x.grad += y.grad * dx()
|
|
167
|
+
y.backward = backward
|
|
168
|
+
return y
|
|
169
|
+
return func
|
|
36
170
|
|
|
37
171
|
def wrapper_2in_1out(
|
|
38
172
|
x1: OperandLike,
|
|
39
173
|
x2: OperandLike,
|
|
40
174
|
/,
|
|
41
|
-
out: Optional[
|
|
175
|
+
out: Optional[NDArrayLike] = None,
|
|
42
176
|
*,
|
|
43
177
|
func_name: str,
|
|
44
|
-
device: DeviceLike =
|
|
178
|
+
device: Optional[DeviceLike] = None,
|
|
45
179
|
in_place: bool = False,
|
|
46
|
-
where: Union[
|
|
180
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
47
181
|
casting: Casting = 'same_kind',
|
|
48
182
|
order: Order = 'K',
|
|
49
183
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -62,7 +196,14 @@ def wrapper_2in_1out(
|
|
|
62
196
|
if is_tensor_op and isinstance(x1, Tensor):
|
|
63
197
|
device_op = x1.device
|
|
64
198
|
else:
|
|
65
|
-
|
|
199
|
+
if device is None:
|
|
200
|
+
_x1_device = get_device(x1)
|
|
201
|
+
if _x1_device != get_device(x2):
|
|
202
|
+
raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
203
|
+
else:
|
|
204
|
+
device_op = _x1_device
|
|
205
|
+
else:
|
|
206
|
+
device_op = device
|
|
66
207
|
|
|
67
208
|
a1, a2 = to_xp_array(x1, device=device_op), to_xp_array(x2, device=device_op)
|
|
68
209
|
if device_op == "cpu":
|
|
@@ -95,12 +236,12 @@ def wrapper_2in_1out(
|
|
|
95
236
|
def wrapper_1in_1out(
|
|
96
237
|
x: OperandLike,
|
|
97
238
|
/,
|
|
98
|
-
out: Optional[
|
|
239
|
+
out: Optional[NDArrayLike] = None,
|
|
99
240
|
*,
|
|
100
241
|
func_name: str,
|
|
101
|
-
device: DeviceLike =
|
|
242
|
+
device: Optional[DeviceLike] = None,
|
|
102
243
|
in_place: bool = False,
|
|
103
|
-
where: Union[
|
|
244
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
104
245
|
casting: Casting = 'same_kind',
|
|
105
246
|
order: Order = 'K',
|
|
106
247
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -110,7 +251,10 @@ def wrapper_1in_1out(
|
|
|
110
251
|
if isinstance(x, Tensor):
|
|
111
252
|
device_op = x.device
|
|
112
253
|
else:
|
|
113
|
-
|
|
254
|
+
if device is None:
|
|
255
|
+
device_op = get_device(device)
|
|
256
|
+
else:
|
|
257
|
+
device_op = device
|
|
114
258
|
|
|
115
259
|
a = to_xp_array(x, device=device_op)
|
|
116
260
|
if device_op:
|
|
@@ -127,15 +271,19 @@ def wrapper_1in_1out(
|
|
|
127
271
|
requires_grad = x.requires_grad
|
|
128
272
|
return Tensor(y, device=device_op, prev=(x,), requires_grad=requires_grad)
|
|
129
273
|
|
|
274
|
+
###
|
|
275
|
+
### Arithmetics
|
|
276
|
+
###
|
|
277
|
+
|
|
130
278
|
def add(
|
|
131
279
|
x1: OperandLike,
|
|
132
280
|
x2: OperandLike,
|
|
133
281
|
/,
|
|
134
|
-
out: Optional[
|
|
282
|
+
out: Optional[NDArrayLike] = None,
|
|
135
283
|
*,
|
|
136
|
-
device: DeviceLike =
|
|
284
|
+
device: Optional[DeviceLike] = None,
|
|
137
285
|
in_place: bool = False,
|
|
138
|
-
where: Union[
|
|
286
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
139
287
|
casting: Casting = 'same_kind',
|
|
140
288
|
order: Order = 'K',
|
|
141
289
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -147,11 +295,11 @@ def subtract(
|
|
|
147
295
|
x1: OperandLike,
|
|
148
296
|
x2: OperandLike,
|
|
149
297
|
/,
|
|
150
|
-
out: Optional[
|
|
298
|
+
out: Optional[NDArrayLike] = None,
|
|
151
299
|
*,
|
|
152
|
-
device: DeviceLike =
|
|
300
|
+
device: Optional[DeviceLike] = None,
|
|
153
301
|
in_place: bool = False,
|
|
154
|
-
where: Union[
|
|
302
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
155
303
|
casting: Casting = 'same_kind',
|
|
156
304
|
order: Order = 'K',
|
|
157
305
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -163,11 +311,11 @@ def multiply(
|
|
|
163
311
|
x1: OperandLike,
|
|
164
312
|
x2: OperandLike,
|
|
165
313
|
/,
|
|
166
|
-
out: Optional[
|
|
314
|
+
out: Optional[NDArrayLike] = None,
|
|
167
315
|
*,
|
|
168
|
-
device: DeviceLike =
|
|
316
|
+
device: Optional[DeviceLike] = None,
|
|
169
317
|
in_place: bool = False,
|
|
170
|
-
where: Union[
|
|
318
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
171
319
|
casting: Casting = 'same_kind',
|
|
172
320
|
order: Order = 'K',
|
|
173
321
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -179,9 +327,9 @@ def matmul(
|
|
|
179
327
|
x1: OperandLike,
|
|
180
328
|
x2: OperandLike,
|
|
181
329
|
/,
|
|
182
|
-
out: Optional[
|
|
330
|
+
out: Optional[NDArrayLike] = None,
|
|
183
331
|
*,
|
|
184
|
-
device: DeviceLike =
|
|
332
|
+
device: Optional[DeviceLike] = None,
|
|
185
333
|
in_place: bool = False,
|
|
186
334
|
casting: Casting = 'same_kind',
|
|
187
335
|
order: Order = 'K',
|
|
@@ -194,11 +342,11 @@ def divide(
|
|
|
194
342
|
x1: OperandLike,
|
|
195
343
|
x2: OperandLike,
|
|
196
344
|
/,
|
|
197
|
-
out: Optional[
|
|
345
|
+
out: Optional[NDArrayLike] = None,
|
|
198
346
|
*,
|
|
199
|
-
device: DeviceLike =
|
|
347
|
+
device: Optional[DeviceLike] = None,
|
|
200
348
|
in_place: bool = False,
|
|
201
|
-
where: Union[
|
|
349
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
202
350
|
casting: Casting = 'same_kind',
|
|
203
351
|
order: Order = 'K',
|
|
204
352
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -210,11 +358,11 @@ def power(
|
|
|
210
358
|
x1: OperandLike,
|
|
211
359
|
x2: OperandLike,
|
|
212
360
|
/,
|
|
213
|
-
out: Optional[
|
|
361
|
+
out: Optional[NDArrayLike] = None,
|
|
214
362
|
*,
|
|
215
|
-
device: DeviceLike =
|
|
363
|
+
device: Optional[DeviceLike] = None,
|
|
216
364
|
in_place: bool = False,
|
|
217
|
-
where: Union[
|
|
365
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
218
366
|
casting: Casting = 'same_kind',
|
|
219
367
|
order: Order = 'K',
|
|
220
368
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -226,11 +374,11 @@ def power(
|
|
|
226
374
|
def negative(
|
|
227
375
|
x: OperandLike,
|
|
228
376
|
/,
|
|
229
|
-
out: Optional[
|
|
377
|
+
out: Optional[NDArrayLike] = None,
|
|
230
378
|
*,
|
|
231
|
-
device: DeviceLike =
|
|
379
|
+
device: Optional[DeviceLike] = None,
|
|
232
380
|
in_place: bool = False,
|
|
233
|
-
where: Union[
|
|
381
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
234
382
|
casting: Casting = 'same_kind',
|
|
235
383
|
order: Order = 'K',
|
|
236
384
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -241,11 +389,11 @@ def negative(
|
|
|
241
389
|
def sign(
|
|
242
390
|
x: OperandLike,
|
|
243
391
|
/,
|
|
244
|
-
out: Optional[
|
|
392
|
+
out: Optional[NDArrayLike] = None,
|
|
245
393
|
*,
|
|
246
|
-
device: DeviceLike =
|
|
394
|
+
device: Optional[DeviceLike] = None,
|
|
247
395
|
in_place: bool = False,
|
|
248
|
-
where: Union[
|
|
396
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
249
397
|
casting: Casting = 'same_kind',
|
|
250
398
|
order: Order = 'K',
|
|
251
399
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -256,11 +404,11 @@ def sign(
|
|
|
256
404
|
def abs(
|
|
257
405
|
x: OperandLike,
|
|
258
406
|
/,
|
|
259
|
-
out: Optional[
|
|
407
|
+
out: Optional[NDArrayLike] = None,
|
|
260
408
|
*,
|
|
261
|
-
device: DeviceLike =
|
|
409
|
+
device: Optional[DeviceLike] = None,
|
|
262
410
|
in_place: bool = False,
|
|
263
|
-
where: Union[
|
|
411
|
+
where: Union[NDArrayLikeBool, bool] = True,
|
|
264
412
|
casting: Casting = 'same_kind',
|
|
265
413
|
order: Order = 'K',
|
|
266
414
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -273,11 +421,11 @@ def clip(
|
|
|
273
421
|
a_min: OperandLike,
|
|
274
422
|
a_max: OperandLike,
|
|
275
423
|
/,
|
|
276
|
-
out: Optional[
|
|
424
|
+
out: Optional[NDArrayLike] = None,
|
|
277
425
|
*,
|
|
278
426
|
requires_grad: bool = False,
|
|
279
|
-
device: DeviceLike =
|
|
280
|
-
where: Union[bool,
|
|
427
|
+
device: Optional[DeviceLike] = None,
|
|
428
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
281
429
|
casting: Casting = 'same_kind',
|
|
282
430
|
order: Order = 'K',
|
|
283
431
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -312,11 +460,11 @@ def clip(
|
|
|
312
460
|
def exp(
|
|
313
461
|
x: OperandLike,
|
|
314
462
|
/,
|
|
315
|
-
out: Optional[
|
|
463
|
+
out: Optional[NDArrayLike] = None,
|
|
316
464
|
*,
|
|
317
|
-
device: DeviceLike =
|
|
465
|
+
device: Optional[DeviceLike] = None,
|
|
318
466
|
in_place: bool = False,
|
|
319
|
-
where: Union[bool,
|
|
467
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
320
468
|
casting: Casting = 'same_kind',
|
|
321
469
|
order: Order = 'K',
|
|
322
470
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -327,11 +475,11 @@ def exp(
|
|
|
327
475
|
def sqrt(
|
|
328
476
|
x: OperandLike,
|
|
329
477
|
/,
|
|
330
|
-
out: Optional[
|
|
478
|
+
out: Optional[NDArrayLike] = None,
|
|
331
479
|
*,
|
|
332
|
-
device: DeviceLike =
|
|
480
|
+
device: Optional[DeviceLike] = None,
|
|
333
481
|
in_place: bool = False,
|
|
334
|
-
where: Union[bool,
|
|
482
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
335
483
|
casting: Casting = 'same_kind',
|
|
336
484
|
order: Order = 'K',
|
|
337
485
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -342,11 +490,11 @@ def sqrt(
|
|
|
342
490
|
def log(
|
|
343
491
|
x: OperandLike,
|
|
344
492
|
/,
|
|
345
|
-
out: Optional[
|
|
493
|
+
out: Optional[NDArrayLike] = None,
|
|
346
494
|
*,
|
|
347
|
-
device: DeviceLike =
|
|
495
|
+
device: Optional[DeviceLike] = None,
|
|
348
496
|
in_place: bool = False,
|
|
349
|
-
where: Union[bool,
|
|
497
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
350
498
|
casting: Casting = 'same_kind',
|
|
351
499
|
order: Order = 'K',
|
|
352
500
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -357,11 +505,11 @@ def log(
|
|
|
357
505
|
def square(
|
|
358
506
|
x: OperandLike,
|
|
359
507
|
/,
|
|
360
|
-
out: Optional[
|
|
508
|
+
out: Optional[NDArrayLike] = None,
|
|
361
509
|
*,
|
|
362
|
-
device: DeviceLike =
|
|
510
|
+
device: Optional[DeviceLike] = None,
|
|
363
511
|
in_place: bool = False,
|
|
364
|
-
where: Union[bool,
|
|
512
|
+
where: Union[bool, NDArrayLikeBool] = True,
|
|
365
513
|
casting: Casting = 'same_kind',
|
|
366
514
|
order: Order = 'K',
|
|
367
515
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -387,5 +535,7 @@ __all__ = [
|
|
|
387
535
|
'sqrt',
|
|
388
536
|
'log',
|
|
389
537
|
'square',
|
|
390
|
-
'clip'
|
|
538
|
+
'clip',
|
|
539
|
+
'create_2in_1out',
|
|
540
|
+
'create_1in_1out'
|
|
391
541
|
]
|