DepthTensor 1.2.1__tar.gz → 1.4.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.2.1/src/DepthTensor.egg-info → depthtensor-1.4.0}/PKG-INFO +1 -1
- {depthtensor-1.2.1 → depthtensor-1.4.0}/pyproject.toml +1 -1
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/__init__.py +1 -1
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/comparison.py +7 -7
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/diff.py +53 -2
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/elementwise.py +35 -17
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/reduction.py +19 -16
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/random/generator.py +5 -4
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/autodiff.py +0 -1
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/tensor.py +175 -85
- {depthtensor-1.2.1 → depthtensor-1.4.0/src/DepthTensor.egg-info}/PKG-INFO +1 -1
- depthtensor-1.4.0/src/example/example.py +4 -0
- depthtensor-1.2.1/src/example/example.py +0 -4
- {depthtensor-1.2.1 → depthtensor-1.4.0}/LICENSE +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/README.md +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/setup.cfg +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/__init__.py +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/exceptions.py +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/__init__.py +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/creation.py +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/random/__init__.py +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/_core/utils.py +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor/typing.py +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/SOURCES.txt +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/requires.txt +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
- {depthtensor-1.2.1 → depthtensor-1.4.0}/tests/test_tensor.py +0 -0
|
@@ -6,7 +6,6 @@ from typing import (
|
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
from ...typing import (
|
|
9
|
-
ArrayLike,
|
|
10
9
|
TensorLike,
|
|
11
10
|
DeviceLike,
|
|
12
11
|
ArrayLikeBool,
|
|
@@ -18,7 +17,6 @@ from ...typing import (
|
|
|
18
17
|
from ..exceptions import (
|
|
19
18
|
CuPyNotFound, CUPY_NOT_FOUND_MSG,
|
|
20
19
|
DeviceMismatch, DEVICE_MISMATCH_MSG,
|
|
21
|
-
OperandMismatch, OPERAND_MISMATCH_MSG
|
|
22
20
|
)
|
|
23
21
|
|
|
24
22
|
from ..utils import to_xp_array
|
|
@@ -101,15 +99,12 @@ def wrapper_2in_1out(
|
|
|
101
99
|
subok: bool = True
|
|
102
100
|
) -> TensorLike:
|
|
103
101
|
from ...tensor import Tensor
|
|
102
|
+
is_tensor_op = False
|
|
104
103
|
if isinstance(x1, Tensor) and isinstance(x2, Tensor):
|
|
105
104
|
if not x1.is_device(x2.device):
|
|
106
105
|
raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
107
106
|
else:
|
|
108
107
|
is_tensor_op = True
|
|
109
|
-
else:
|
|
110
|
-
if isinstance(x1, Tensor) or isinstance(x2, Tensor):
|
|
111
|
-
raise OperandMismatch(OPERAND_MISMATCH_MSG)
|
|
112
|
-
is_tensor_op = False
|
|
113
108
|
#* Either tensor-tensor op or array-array op.
|
|
114
109
|
|
|
115
110
|
#* If its tensor-tensor op, device is decided by x1.device, else, its by the device argument.
|
|
@@ -222,5 +217,10 @@ def less_equal(
|
|
|
222
217
|
|
|
223
218
|
__all__ = [
|
|
224
219
|
'where',
|
|
225
|
-
'equal',
|
|
220
|
+
'equal',
|
|
221
|
+
'not_equal',
|
|
222
|
+
'greater',
|
|
223
|
+
'greater_equal',
|
|
224
|
+
'less',
|
|
225
|
+
'less_equal'
|
|
226
226
|
]
|
|
@@ -3,6 +3,15 @@ from ...typing import (
|
|
|
3
3
|
)
|
|
4
4
|
|
|
5
5
|
from ..utils import sum_to_shape
|
|
6
|
+
from ..exceptions import (
|
|
7
|
+
CuPyNotFound, CUPY_NOT_FOUND_MSG
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
try:
|
|
12
|
+
import cupy as cp
|
|
13
|
+
except (ImportError, ModuleNotFoundError):
|
|
14
|
+
cp = None
|
|
6
15
|
|
|
7
16
|
###
|
|
8
17
|
### Arithmetics
|
|
@@ -58,6 +67,20 @@ def divide_diff(result: TensorLike, x1: TensorLike, x2: TensorLike) -> TensorLik
|
|
|
58
67
|
result.backward = backward
|
|
59
68
|
return result
|
|
60
69
|
|
|
70
|
+
def power_diff(result: TensorLike, x1: TensorLike, x2: TensorLike) -> TensorLike:
|
|
71
|
+
if not result.requires_grad: return result
|
|
72
|
+
def backward() -> None:
|
|
73
|
+
if x1.requires_grad:
|
|
74
|
+
x1.grad += sum_to_shape(result.grad * x2.data*x1.data**(x2.data-1), x1.shape, x1.device)
|
|
75
|
+
if x2.requires_grad:
|
|
76
|
+
if x2.device == "cpu":
|
|
77
|
+
x2.grad += sum_to_shape(result.grad * np.log(x1.data)*x1.data**x2.data, x2.shape, x2.device)
|
|
78
|
+
else:
|
|
79
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
80
|
+
x2.grad += sum_to_shape(result.grad * cp.log(x1.data)*x1.data**x2.data, x2.shape, x2.device)
|
|
81
|
+
result.backward = backward
|
|
82
|
+
return result
|
|
83
|
+
|
|
61
84
|
def negative_diff(result: TensorLike, x: TensorLike) -> TensorLike:
|
|
62
85
|
if not result.requires_grad: return result
|
|
63
86
|
def backward() -> None:
|
|
@@ -103,11 +126,39 @@ def sqrt_diff(result: TensorLike, x: TensorLike) -> TensorLike:
|
|
|
103
126
|
result.backward = backward
|
|
104
127
|
return result
|
|
105
128
|
|
|
129
|
+
def log_diff(result: TensorLike, x: TensorLike) -> TensorLike:
|
|
130
|
+
if not result.requires_grad: return result
|
|
131
|
+
def backward() -> None:
|
|
132
|
+
if x.requires_grad:
|
|
133
|
+
x.grad += sum_to_shape(result.grad / x.data, x.shape, x.device)
|
|
134
|
+
result.backward = backward
|
|
135
|
+
return result
|
|
136
|
+
|
|
137
|
+
def square_diff(result: TensorLike, x: TensorLike) -> TensorLike:
|
|
138
|
+
if not result.requires_grad: return result
|
|
139
|
+
def backward() -> None:
|
|
140
|
+
if x.requires_grad:
|
|
141
|
+
x.grad += sum_to_shape(result.grad * 2, x.shape, x.device)
|
|
142
|
+
result.backward = backward
|
|
143
|
+
return result
|
|
144
|
+
|
|
106
145
|
###
|
|
107
146
|
###
|
|
108
147
|
###
|
|
109
148
|
|
|
110
149
|
__all__ = [
|
|
111
|
-
'add_diff',
|
|
112
|
-
'
|
|
150
|
+
'add_diff',
|
|
151
|
+
'subtract_diff',
|
|
152
|
+
'multiply_diff',
|
|
153
|
+
'matmul_diff',
|
|
154
|
+
'divide_diff',
|
|
155
|
+
'power_diff',
|
|
156
|
+
'negative_diff',
|
|
157
|
+
'sign_diff',
|
|
158
|
+
'abs_diff',
|
|
159
|
+
|
|
160
|
+
'exp_diff',
|
|
161
|
+
'sqrt_diff',
|
|
162
|
+
'log_diff',
|
|
163
|
+
'square_diff'
|
|
113
164
|
]
|
|
@@ -17,8 +17,7 @@ from ...typing import (
|
|
|
17
17
|
|
|
18
18
|
from ..exceptions import (
|
|
19
19
|
DeviceMismatch, DEVICE_MISMATCH_MSG,
|
|
20
|
-
CuPyNotFound, CUPY_NOT_FOUND_MSG
|
|
21
|
-
OperandMismatch, OPERAND_MISMATCH_MSG
|
|
20
|
+
CuPyNotFound, CUPY_NOT_FOUND_MSG
|
|
22
21
|
)
|
|
23
22
|
|
|
24
23
|
from ..utils import (
|
|
@@ -51,15 +50,12 @@ def wrapper_2in_1out(
|
|
|
51
50
|
subok: bool = True
|
|
52
51
|
) -> TensorLike:
|
|
53
52
|
from ...tensor import Tensor
|
|
53
|
+
is_tensor_op = False
|
|
54
54
|
if isinstance(x1, Tensor) and isinstance(x2, Tensor):
|
|
55
55
|
if not x1.is_device(x2.device):
|
|
56
56
|
raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
57
57
|
else:
|
|
58
|
-
is_tensor_op = True
|
|
59
|
-
else:
|
|
60
|
-
if isinstance(x1, Tensor) or isinstance(x2, Tensor):
|
|
61
|
-
raise OperandMismatch(OPERAND_MISMATCH_MSG)
|
|
62
|
-
is_tensor_op = False
|
|
58
|
+
is_tensor_op = True
|
|
63
59
|
#* Either tensor-tensor op or array-array op.
|
|
64
60
|
|
|
65
61
|
#* If its tensor-tensor op, device is decided by x1.device, else, its by the device argument.
|
|
@@ -203,6 +199,23 @@ def divide(
|
|
|
203
199
|
) -> TensorLike:
|
|
204
200
|
return wrapper_2in_1out(x1, x2, out=out, func_name="divide", device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
205
201
|
|
|
202
|
+
def power(
|
|
203
|
+
x1: OperandLike,
|
|
204
|
+
x2: OperandLike,
|
|
205
|
+
/,
|
|
206
|
+
out: Optional[Union[np.ndarray, Any]] = None,
|
|
207
|
+
*,
|
|
208
|
+
device: DeviceLike = "cpu",
|
|
209
|
+
in_place: bool = False,
|
|
210
|
+
where: Union[ArrayLikeBool, bool] = True,
|
|
211
|
+
casting: Casting = 'same_kind',
|
|
212
|
+
order: Order = 'K',
|
|
213
|
+
dtype: Optional[DTypeLike] = None,
|
|
214
|
+
subok: bool = True
|
|
215
|
+
) -> TensorLike:
|
|
216
|
+
return wrapper_2in_1out(x1, x2, out=out, func_name="power", device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
217
|
+
|
|
218
|
+
|
|
206
219
|
def negative(
|
|
207
220
|
x: OperandLike,
|
|
208
221
|
/,
|
|
@@ -263,14 +276,11 @@ def clip(
|
|
|
263
276
|
subok: bool = True
|
|
264
277
|
) -> TensorLike:
|
|
265
278
|
from ...tensor import Tensor
|
|
279
|
+
is_tensor_op = False
|
|
266
280
|
if isinstance(a, Tensor) and isinstance(a_min, Tensor) and isinstance(a_max, Tensor):
|
|
267
281
|
if not (a.device == a_min.device == a_max.device): raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
268
282
|
is_tensor_op = True
|
|
269
|
-
|
|
270
|
-
if isinstance(a, Tensor) or isinstance(a_min, Tensor) or isinstance(a_max, Tensor):
|
|
271
|
-
raise OperandMismatch(OPERAND_MISMATCH_MSG)
|
|
272
|
-
is_tensor_op = False
|
|
273
|
-
|
|
283
|
+
|
|
274
284
|
if is_tensor_op and isinstance(a, Tensor):
|
|
275
285
|
device_op = a.device
|
|
276
286
|
else:
|
|
@@ -356,10 +366,18 @@ def square(
|
|
|
356
366
|
###
|
|
357
367
|
|
|
358
368
|
__all__ = [
|
|
359
|
-
'add',
|
|
360
|
-
'
|
|
361
|
-
|
|
362
|
-
'
|
|
363
|
-
|
|
369
|
+
'add',
|
|
370
|
+
'subtract',
|
|
371
|
+
'multiply',
|
|
372
|
+
'matmul',
|
|
373
|
+
'divide',
|
|
374
|
+
'power',
|
|
375
|
+
'negative',
|
|
376
|
+
'sign',
|
|
377
|
+
'abs',
|
|
378
|
+
'exp',
|
|
379
|
+
'sqrt',
|
|
380
|
+
'log',
|
|
381
|
+
'square',
|
|
364
382
|
'clip'
|
|
365
383
|
]
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from typing import (
|
|
2
2
|
Optional,
|
|
3
3
|
Union,
|
|
4
|
-
Any
|
|
5
|
-
TypeVar
|
|
4
|
+
Any
|
|
6
5
|
)
|
|
7
6
|
|
|
8
7
|
from ...typing import (
|
|
@@ -14,14 +13,12 @@ from ...typing import (
|
|
|
14
13
|
DTypeLike,
|
|
15
14
|
AxisShapeLike,
|
|
16
15
|
OperandLike,
|
|
17
|
-
DeviceLike
|
|
18
|
-
ArrayLike
|
|
16
|
+
DeviceLike
|
|
19
17
|
)
|
|
20
18
|
|
|
21
19
|
from ..exceptions import (
|
|
22
20
|
CuPyNotFound, CUPY_NOT_FOUND_MSG,
|
|
23
|
-
DeviceMismatch, DEVICE_MISMATCH_MSG
|
|
24
|
-
OperandMismatch, OPERAND_MISMATCH_MSG
|
|
21
|
+
DeviceMismatch, DEVICE_MISMATCH_MSG
|
|
25
22
|
)
|
|
26
23
|
|
|
27
24
|
from ..utils import (
|
|
@@ -59,10 +56,17 @@ def sum(
|
|
|
59
56
|
|
|
60
57
|
arr = to_xp_array(a, device=device_op)
|
|
61
58
|
if device_op == "cpu":
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
kwds = {
|
|
60
|
+
'axis': axis,
|
|
61
|
+
'dtype': dtype,
|
|
62
|
+
'keepdims': keepdims,
|
|
63
|
+
'where': where
|
|
64
|
+
}
|
|
65
|
+
if not isinstance(initial, type(_NoValue)):
|
|
66
|
+
kwds['initial'] = initial
|
|
67
|
+
if out is not None:
|
|
68
|
+
kwds['out'] = out
|
|
69
|
+
y = np.sum(arr, **kwds)
|
|
66
70
|
else:
|
|
67
71
|
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
68
72
|
y = cp.sum(arr, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
|
|
@@ -107,14 +111,11 @@ def maximum(
|
|
|
107
111
|
subok: bool = True
|
|
108
112
|
) -> TensorLike:
|
|
109
113
|
from ...tensor import Tensor
|
|
114
|
+
is_tensor_op = False
|
|
110
115
|
if isinstance(x1, Tensor) and isinstance(x2, Tensor):
|
|
111
116
|
if not x1.is_device(x2.device): raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
112
117
|
is_tensor_op = True
|
|
113
|
-
|
|
114
|
-
if isinstance(x1, Tensor) or isinstance(x2, Tensor):
|
|
115
|
-
raise OperandMismatch(OPERAND_MISMATCH_MSG)
|
|
116
|
-
is_tensor_op = False
|
|
117
|
-
|
|
118
|
+
|
|
118
119
|
if is_tensor_op and isinstance(x1, Tensor):
|
|
119
120
|
device_op = x1.device
|
|
120
121
|
else:
|
|
@@ -132,5 +133,7 @@ def maximum(
|
|
|
132
133
|
###
|
|
133
134
|
|
|
134
135
|
__all__ = [
|
|
135
|
-
'max',
|
|
136
|
+
'max',
|
|
137
|
+
'maximum',
|
|
138
|
+
'sum'
|
|
136
139
|
]
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from typing import (
|
|
2
2
|
Optional,
|
|
3
3
|
overload,
|
|
4
|
-
Any
|
|
5
|
-
Type
|
|
4
|
+
Any
|
|
6
5
|
)
|
|
7
6
|
|
|
8
7
|
from numpy import random
|
|
@@ -19,7 +18,6 @@ from ..exceptions import (
|
|
|
19
18
|
CuPyNotFound, CUPY_NOT_FOUND_MSG
|
|
20
19
|
)
|
|
21
20
|
|
|
22
|
-
import numpy as np
|
|
23
21
|
try:
|
|
24
22
|
import cupy as cp
|
|
25
23
|
except (ImportError, ModuleNotFoundError):
|
|
@@ -106,5 +104,8 @@ def uniform(
|
|
|
106
104
|
###
|
|
107
105
|
|
|
108
106
|
__all__ = [
|
|
109
|
-
'rand',
|
|
107
|
+
'rand',
|
|
108
|
+
'randn',
|
|
109
|
+
'randint',
|
|
110
|
+
'uniform'
|
|
110
111
|
]
|
|
@@ -22,27 +22,60 @@ from .typing import (
|
|
|
22
22
|
|
|
23
23
|
from ._core import (
|
|
24
24
|
xp_array_to_device,
|
|
25
|
-
CuPyNotFound,
|
|
25
|
+
CuPyNotFound,
|
|
26
|
+
CUPY_NOT_FOUND_MSG,
|
|
26
27
|
|
|
27
28
|
#* creation
|
|
28
|
-
zeros_like,
|
|
29
|
+
zeros_like,
|
|
30
|
+
ones_like,
|
|
29
31
|
|
|
30
32
|
#* elementwise
|
|
31
|
-
add,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
add,
|
|
34
|
+
subtract,
|
|
35
|
+
multiply,
|
|
36
|
+
matmul,
|
|
37
|
+
divide,
|
|
38
|
+
negative,
|
|
39
|
+
power,
|
|
40
|
+
clip,
|
|
41
|
+
sign,
|
|
42
|
+
abs,
|
|
43
|
+
#* elementwise (exponents/logarithm)
|
|
44
|
+
exp,
|
|
45
|
+
sqrt,
|
|
46
|
+
log,
|
|
47
|
+
square,
|
|
48
|
+
|
|
49
|
+
#* diff (elementwise)
|
|
50
|
+
add_diff,
|
|
51
|
+
subtract_diff,
|
|
52
|
+
multiply_diff,
|
|
53
|
+
matmul_diff,
|
|
54
|
+
divide_diff,
|
|
55
|
+
power_diff,
|
|
56
|
+
negative_diff,
|
|
57
|
+
sign_diff,
|
|
58
|
+
abs_diff,
|
|
59
|
+
#* diff (exponents/logarithm)
|
|
60
|
+
exp_diff,
|
|
61
|
+
sqrt_diff,
|
|
62
|
+
log_diff,
|
|
63
|
+
square_diff,
|
|
64
|
+
|
|
40
65
|
|
|
41
66
|
#* comparison
|
|
42
|
-
where,
|
|
67
|
+
where,
|
|
68
|
+
equal,
|
|
69
|
+
not_equal,
|
|
70
|
+
greater,
|
|
71
|
+
greater_equal,
|
|
72
|
+
less,
|
|
73
|
+
less_equal,
|
|
43
74
|
|
|
44
75
|
#* reduction
|
|
45
|
-
max,
|
|
76
|
+
max,
|
|
77
|
+
maximum,
|
|
78
|
+
sum
|
|
46
79
|
)
|
|
47
80
|
|
|
48
81
|
import numpy as np
|
|
@@ -217,8 +250,8 @@ class Tensor():
|
|
|
217
250
|
|
|
218
251
|
@staticmethod
|
|
219
252
|
def subtract(
|
|
220
|
-
x1:
|
|
221
|
-
x2:
|
|
253
|
+
x1: OperandLike,
|
|
254
|
+
x2: OperandLike,
|
|
222
255
|
/,
|
|
223
256
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
224
257
|
*,
|
|
@@ -239,8 +272,8 @@ class Tensor():
|
|
|
239
272
|
|
|
240
273
|
@staticmethod
|
|
241
274
|
def multiply(
|
|
242
|
-
x1:
|
|
243
|
-
x2:
|
|
275
|
+
x1: OperandLike,
|
|
276
|
+
x2: OperandLike,
|
|
244
277
|
/,
|
|
245
278
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
246
279
|
*,
|
|
@@ -261,8 +294,8 @@ class Tensor():
|
|
|
261
294
|
|
|
262
295
|
@staticmethod
|
|
263
296
|
def matmul(
|
|
264
|
-
x1:
|
|
265
|
-
x2:
|
|
297
|
+
x1: OperandLike,
|
|
298
|
+
x2: OperandLike,
|
|
266
299
|
/,
|
|
267
300
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
268
301
|
*,
|
|
@@ -282,8 +315,8 @@ class Tensor():
|
|
|
282
315
|
|
|
283
316
|
@staticmethod
|
|
284
317
|
def divide(
|
|
285
|
-
x1:
|
|
286
|
-
x2:
|
|
318
|
+
x1: OperandLike,
|
|
319
|
+
x2: OperandLike,
|
|
287
320
|
/,
|
|
288
321
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
289
322
|
*,
|
|
@@ -302,9 +335,31 @@ class Tensor():
|
|
|
302
335
|
divide_diff, x1, x2, record_op
|
|
303
336
|
)
|
|
304
337
|
|
|
338
|
+
@staticmethod
|
|
339
|
+
def power(
|
|
340
|
+
x1: OperandLike,
|
|
341
|
+
x2: OperandLike,
|
|
342
|
+
/,
|
|
343
|
+
out: Optional[Union[np.ndarray, Any]] = None,
|
|
344
|
+
*,
|
|
345
|
+
device: DeviceLike = "cpu",
|
|
346
|
+
in_place: bool = False,
|
|
347
|
+
record_op: bool = True,
|
|
348
|
+
|
|
349
|
+
where: Union[ArrayLikeBool, bool] = True,
|
|
350
|
+
casting: Casting = 'same_kind',
|
|
351
|
+
order: Order = 'K',
|
|
352
|
+
dtype: Optional[DTypeLike] = None,
|
|
353
|
+
subok: bool = True
|
|
354
|
+
) -> Tensor:
|
|
355
|
+
return _wrapper_2in_1out(
|
|
356
|
+
power(x1, x2, out=out, device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok),
|
|
357
|
+
power_diff, x1, x2, record_op
|
|
358
|
+
)
|
|
359
|
+
|
|
305
360
|
@staticmethod
|
|
306
361
|
def negative(
|
|
307
|
-
x:
|
|
362
|
+
x: OperandLike,
|
|
308
363
|
/,
|
|
309
364
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
310
365
|
*,
|
|
@@ -325,9 +380,9 @@ class Tensor():
|
|
|
325
380
|
|
|
326
381
|
@staticmethod
|
|
327
382
|
def clip(
|
|
328
|
-
a:
|
|
329
|
-
a_min:
|
|
330
|
-
a_max:
|
|
383
|
+
a: OperandLike,
|
|
384
|
+
a_min: OperandLike,
|
|
385
|
+
a_max: OperandLike,
|
|
331
386
|
/,
|
|
332
387
|
out: Optional[ArrayLike] = None,
|
|
333
388
|
*,
|
|
@@ -342,7 +397,7 @@ class Tensor():
|
|
|
342
397
|
|
|
343
398
|
@staticmethod
|
|
344
399
|
def sign(
|
|
345
|
-
x:
|
|
400
|
+
x: OperandLike,
|
|
346
401
|
/,
|
|
347
402
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
348
403
|
*,
|
|
@@ -363,7 +418,7 @@ class Tensor():
|
|
|
363
418
|
|
|
364
419
|
@staticmethod
|
|
365
420
|
def abs(
|
|
366
|
-
x:
|
|
421
|
+
x: OperandLike,
|
|
367
422
|
/,
|
|
368
423
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
369
424
|
*,
|
|
@@ -388,7 +443,7 @@ class Tensor():
|
|
|
388
443
|
|
|
389
444
|
@staticmethod
|
|
390
445
|
def exp(
|
|
391
|
-
x:
|
|
446
|
+
x: OperandLike,
|
|
392
447
|
/,
|
|
393
448
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
394
449
|
*,
|
|
@@ -409,7 +464,7 @@ class Tensor():
|
|
|
409
464
|
|
|
410
465
|
@staticmethod
|
|
411
466
|
def sqrt(
|
|
412
|
-
x:
|
|
467
|
+
x: OperandLike,
|
|
413
468
|
/,
|
|
414
469
|
out: Optional[Union[np.ndarray, Any]] = None,
|
|
415
470
|
*,
|
|
@@ -428,6 +483,48 @@ class Tensor():
|
|
|
428
483
|
sqrt_diff, x, record_op
|
|
429
484
|
)
|
|
430
485
|
|
|
486
|
+
@staticmethod
|
|
487
|
+
def log(
|
|
488
|
+
x: OperandLike,
|
|
489
|
+
/,
|
|
490
|
+
out: Optional[Union[np.ndarray, Any]] = None,
|
|
491
|
+
*,
|
|
492
|
+
device: DeviceLike = "cpu",
|
|
493
|
+
in_place: bool = False,
|
|
494
|
+
record_op: bool = True,
|
|
495
|
+
|
|
496
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
497
|
+
casting: Casting = 'same_kind',
|
|
498
|
+
order: Order = 'K',
|
|
499
|
+
dtype: Optional[DTypeLike] = None,
|
|
500
|
+
subok: bool = True
|
|
501
|
+
) -> Tensor:
|
|
502
|
+
return _wrapper_1in_1out(
|
|
503
|
+
log(x, out=out, device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok),
|
|
504
|
+
log_diff, x, record_op
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
@staticmethod
|
|
508
|
+
def square(
|
|
509
|
+
x: OperandLike,
|
|
510
|
+
/,
|
|
511
|
+
out: Optional[Union[np.ndarray, Any]] = None,
|
|
512
|
+
*,
|
|
513
|
+
device: DeviceLike = "cpu",
|
|
514
|
+
in_place: bool = False,
|
|
515
|
+
record_op: bool = True,
|
|
516
|
+
|
|
517
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
518
|
+
casting: Casting = 'same_kind',
|
|
519
|
+
order: Order = 'K',
|
|
520
|
+
dtype: Optional[DTypeLike] = None,
|
|
521
|
+
subok: bool = True
|
|
522
|
+
) -> Tensor:
|
|
523
|
+
return _wrapper_1in_1out(
|
|
524
|
+
square(x, out=out, device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok),
|
|
525
|
+
square_diff, x, record_op
|
|
526
|
+
)
|
|
527
|
+
|
|
431
528
|
###
|
|
432
529
|
### Comparison
|
|
433
530
|
###
|
|
@@ -435,7 +532,7 @@ class Tensor():
|
|
|
435
532
|
@staticmethod
|
|
436
533
|
@overload
|
|
437
534
|
def where(
|
|
438
|
-
condition:
|
|
535
|
+
condition: OperandLike,
|
|
439
536
|
/,
|
|
440
537
|
*,
|
|
441
538
|
device: DeviceLike = "cpu",
|
|
@@ -444,9 +541,9 @@ class Tensor():
|
|
|
444
541
|
@staticmethod
|
|
445
542
|
@overload
|
|
446
543
|
def where(
|
|
447
|
-
condition:
|
|
448
|
-
x: Optional[
|
|
449
|
-
y: Optional[
|
|
544
|
+
condition: OperandLike,
|
|
545
|
+
x: Optional[OperandLike],
|
|
546
|
+
y: Optional[OperandLike],
|
|
450
547
|
/,
|
|
451
548
|
*,
|
|
452
549
|
device: DeviceLike = "cpu",
|
|
@@ -454,9 +551,9 @@ class Tensor():
|
|
|
454
551
|
|
|
455
552
|
@staticmethod
|
|
456
553
|
def where(
|
|
457
|
-
condition:
|
|
458
|
-
x: Optional[
|
|
459
|
-
y: Optional[
|
|
554
|
+
condition: OperandLike,
|
|
555
|
+
x: Optional[OperandLike] = None,
|
|
556
|
+
y: Optional[OperandLike] = None,
|
|
460
557
|
/,
|
|
461
558
|
*,
|
|
462
559
|
device: DeviceLike = "cpu",
|
|
@@ -474,8 +571,8 @@ class Tensor():
|
|
|
474
571
|
|
|
475
572
|
@staticmethod
|
|
476
573
|
def equal(
|
|
477
|
-
x1:
|
|
478
|
-
x2:
|
|
574
|
+
x1: OperandLike,
|
|
575
|
+
x2: OperandLike,
|
|
479
576
|
/,
|
|
480
577
|
out: Optional[ArrayLikeBool] = None,
|
|
481
578
|
*,
|
|
@@ -490,8 +587,8 @@ class Tensor():
|
|
|
490
587
|
|
|
491
588
|
@staticmethod
|
|
492
589
|
def not_equal(
|
|
493
|
-
x1:
|
|
494
|
-
x2:
|
|
590
|
+
x1: OperandLike,
|
|
591
|
+
x2: OperandLike,
|
|
495
592
|
/,
|
|
496
593
|
out: Optional[ArrayLikeBool] = None,
|
|
497
594
|
*,
|
|
@@ -506,8 +603,8 @@ class Tensor():
|
|
|
506
603
|
|
|
507
604
|
@staticmethod
|
|
508
605
|
def greater(
|
|
509
|
-
x1:
|
|
510
|
-
x2:
|
|
606
|
+
x1: OperandLike,
|
|
607
|
+
x2: OperandLike,
|
|
511
608
|
/,
|
|
512
609
|
out: Optional[ArrayLikeBool] = None,
|
|
513
610
|
*,
|
|
@@ -522,8 +619,8 @@ class Tensor():
|
|
|
522
619
|
|
|
523
620
|
@staticmethod
|
|
524
621
|
def greater_equal(
|
|
525
|
-
x1:
|
|
526
|
-
x2:
|
|
622
|
+
x1: OperandLike,
|
|
623
|
+
x2: OperandLike,
|
|
527
624
|
/,
|
|
528
625
|
out: Optional[ArrayLikeBool] = None,
|
|
529
626
|
*,
|
|
@@ -538,8 +635,8 @@ class Tensor():
|
|
|
538
635
|
|
|
539
636
|
@staticmethod
|
|
540
637
|
def less(
|
|
541
|
-
x1:
|
|
542
|
-
x2:
|
|
638
|
+
x1: OperandLike,
|
|
639
|
+
x2: OperandLike,
|
|
543
640
|
/,
|
|
544
641
|
out: Optional[ArrayLikeBool] = None,
|
|
545
642
|
*,
|
|
@@ -554,8 +651,8 @@ class Tensor():
|
|
|
554
651
|
|
|
555
652
|
@staticmethod
|
|
556
653
|
def less_equal(
|
|
557
|
-
x1:
|
|
558
|
-
x2:
|
|
654
|
+
x1: OperandLike,
|
|
655
|
+
x2: OperandLike,
|
|
559
656
|
/,
|
|
560
657
|
out: Optional[ArrayLikeBool] = None,
|
|
561
658
|
*,
|
|
@@ -574,7 +671,7 @@ class Tensor():
|
|
|
574
671
|
|
|
575
672
|
@staticmethod
|
|
576
673
|
def sum(
|
|
577
|
-
a:
|
|
674
|
+
a: OperandLike,
|
|
578
675
|
/,
|
|
579
676
|
*,
|
|
580
677
|
device: DeviceLike = "cpu",
|
|
@@ -589,7 +686,7 @@ class Tensor():
|
|
|
589
686
|
|
|
590
687
|
@staticmethod
|
|
591
688
|
def max(
|
|
592
|
-
a:
|
|
689
|
+
a: OperandLike,
|
|
593
690
|
/,
|
|
594
691
|
*,
|
|
595
692
|
device: DeviceLike = "cpu",
|
|
@@ -603,8 +700,8 @@ class Tensor():
|
|
|
603
700
|
|
|
604
701
|
@staticmethod
|
|
605
702
|
def maximum(
|
|
606
|
-
x1:
|
|
607
|
-
x2:
|
|
703
|
+
x1: OperandLike,
|
|
704
|
+
x2: OperandLike,
|
|
608
705
|
/,
|
|
609
706
|
out: Optional[np.ndarray] = None,
|
|
610
707
|
*,
|
|
@@ -621,73 +718,66 @@ class Tensor():
|
|
|
621
718
|
### Dunder Operations
|
|
622
719
|
###
|
|
623
720
|
|
|
624
|
-
def __add__(self, t:
|
|
721
|
+
def __add__(self, t: OperandLike) -> Tensor:
|
|
625
722
|
return Tensor.add(self, t)
|
|
626
|
-
def __radd__(self, t:
|
|
723
|
+
def __radd__(self, t: OperandLike) -> Tensor:
|
|
627
724
|
return Tensor.add(t, self)
|
|
628
|
-
def __iadd__(self, t:
|
|
725
|
+
def __iadd__(self, t: OperandLike) -> Tensor:
|
|
629
726
|
return Tensor.add(self, t, in_place=True)
|
|
630
727
|
|
|
631
|
-
def __sub__(self, t:
|
|
728
|
+
def __sub__(self, t: OperandLike) -> Tensor:
|
|
632
729
|
return Tensor.subtract(self, t)
|
|
633
|
-
def __rsub__(self, t:
|
|
730
|
+
def __rsub__(self, t: OperandLike) -> Tensor:
|
|
634
731
|
return Tensor.subtract(t, self)
|
|
635
|
-
def __isub__(self, t:
|
|
732
|
+
def __isub__(self, t: OperandLike) -> Tensor:
|
|
636
733
|
return Tensor.subtract(self, t, in_place=True)
|
|
637
734
|
|
|
638
|
-
def __mul__(self, t:
|
|
735
|
+
def __mul__(self, t: OperandLike) -> Tensor:
|
|
639
736
|
return Tensor.multiply(self, t)
|
|
640
|
-
def __rmul__(self, t:
|
|
737
|
+
def __rmul__(self, t: OperandLike) -> Tensor:
|
|
641
738
|
return Tensor.multiply(t, self)
|
|
642
|
-
def __imul__(self, t:
|
|
739
|
+
def __imul__(self, t: OperandLike) -> Tensor:
|
|
643
740
|
return Tensor.multiply(self, t, in_place=True)
|
|
644
741
|
|
|
645
|
-
def __matmul__(self, t:
|
|
742
|
+
def __matmul__(self, t: OperandLike) -> Tensor:
|
|
646
743
|
return Tensor.matmul(self, t)
|
|
647
|
-
def __rmatmul__(self, t:
|
|
744
|
+
def __rmatmul__(self, t: OperandLike) -> Tensor:
|
|
648
745
|
return Tensor.matmul(t, self)
|
|
649
|
-
def __imatmul__(self, t:
|
|
746
|
+
def __imatmul__(self, t: OperandLike) -> Tensor:
|
|
650
747
|
return Tensor.matmul(self, t, in_place=True)
|
|
651
748
|
|
|
652
|
-
def __truediv__(self, t:
|
|
749
|
+
def __truediv__(self, t: OperandLike) -> Tensor:
|
|
653
750
|
return Tensor.divide(self, t)
|
|
654
|
-
def __rtruediv__(self, t:
|
|
751
|
+
def __rtruediv__(self, t: OperandLike) -> Tensor:
|
|
655
752
|
return Tensor.divide(t, self)
|
|
656
|
-
def __itruediv__(self, t:
|
|
753
|
+
def __itruediv__(self, t: OperandLike) -> Tensor:
|
|
657
754
|
return Tensor.divide(self, t, in_place=True)
|
|
755
|
+
|
|
756
|
+
def __pow__(self, t: OperandLike) -> Tensor:
|
|
757
|
+
return Tensor.power(self, t)
|
|
758
|
+
def __ipow__(self, t: OperandLike) -> Tensor:
|
|
759
|
+
return Tensor.power(self, t, in_place=True)
|
|
658
760
|
|
|
659
761
|
###
|
|
660
762
|
### Unary
|
|
661
763
|
###
|
|
662
764
|
|
|
663
|
-
def __eq__(self, value: Any) ->
|
|
664
|
-
if not isinstance(value, Tensor):
|
|
665
|
-
return NotImplemented
|
|
765
|
+
def __eq__(self, value: Any) -> Tensor: # type: ignore[override]
|
|
666
766
|
return equal(self, value)
|
|
667
767
|
|
|
668
|
-
def __ne__(self, value: Any) ->
|
|
669
|
-
if not isinstance(value, Tensor):
|
|
670
|
-
return NotImplemented
|
|
768
|
+
def __ne__(self, value: Any) -> Tensor: # type: ignore[override]
|
|
671
769
|
return not_equal(self, value)
|
|
672
770
|
|
|
673
|
-
def __gt__(self, value: Any) ->
|
|
674
|
-
if not isinstance(value, Tensor):
|
|
675
|
-
return NotImplemented
|
|
771
|
+
def __gt__(self, value: Any) -> Tensor: # type: ignore[override]
|
|
676
772
|
return greater(self, value)
|
|
677
773
|
|
|
678
|
-
def __ge__(self, value: Any) ->
|
|
679
|
-
if not isinstance(value, Tensor):
|
|
680
|
-
return NotImplemented
|
|
774
|
+
def __ge__(self, value: Any) -> Tensor: # type: ignore[override]
|
|
681
775
|
return greater_equal(self, value)
|
|
682
776
|
|
|
683
|
-
def __lt__(self, value: Any) ->
|
|
684
|
-
if not isinstance(value, Tensor):
|
|
685
|
-
return NotImplemented
|
|
777
|
+
def __lt__(self, value: Any) -> Tensor: # type: ignore[override]
|
|
686
778
|
return less(self, value)
|
|
687
779
|
|
|
688
|
-
def __le__(self, value: Any) ->
|
|
689
|
-
if not isinstance(value, Tensor):
|
|
690
|
-
return NotImplemented
|
|
780
|
+
def __le__(self, value: Any) -> Tensor: # type: ignore[override]
|
|
691
781
|
return less_equal(self, value)
|
|
692
782
|
|
|
693
783
|
def __neg__(self) -> Tensor:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|