DepthTensor 1.3.1__tar.gz → 1.5.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.3.1/src/DepthTensor.egg-info → depthtensor-1.5.0}/PKG-INFO +1 -1
- {depthtensor-1.3.1 → depthtensor-1.5.0}/pyproject.toml +1 -1
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/__init__.py +1 -1
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/ops/diff.py +53 -2
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/ops/elementwise.py +18 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/tensor.py +126 -14
- {depthtensor-1.3.1 → depthtensor-1.5.0/src/DepthTensor.egg-info}/PKG-INFO +1 -1
- depthtensor-1.5.0/src/example/example.py +5 -0
- depthtensor-1.3.1/src/example/example.py +0 -4
- {depthtensor-1.3.1 → depthtensor-1.5.0}/LICENSE +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/README.md +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/setup.cfg +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/__init__.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/exceptions.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/ops/__init__.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/ops/comparison.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/ops/creation.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/ops/reduction.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/random/__init__.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/random/generator.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/_core/utils.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/autodiff.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor/typing.py +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor.egg-info/SOURCES.txt +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor.egg-info/requires.txt +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
- {depthtensor-1.3.1 → depthtensor-1.5.0}/tests/test_tensor.py +0 -0
|
@@ -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
|
]
|
|
@@ -199,6 +199,23 @@ def divide(
|
|
|
199
199
|
) -> TensorLike:
|
|
200
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)
|
|
201
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
|
+
|
|
202
219
|
def negative(
|
|
203
220
|
x: OperandLike,
|
|
204
221
|
/,
|
|
@@ -354,6 +371,7 @@ __all__ = [
|
|
|
354
371
|
'multiply',
|
|
355
372
|
'matmul',
|
|
356
373
|
'divide',
|
|
374
|
+
'power',
|
|
357
375
|
'negative',
|
|
358
376
|
'sign',
|
|
359
377
|
'abs',
|
|
@@ -5,7 +5,8 @@ from typing import (
|
|
|
5
5
|
Any,
|
|
6
6
|
Tuple,
|
|
7
7
|
Callable,
|
|
8
|
-
overload
|
|
8
|
+
overload,
|
|
9
|
+
Iterator
|
|
9
10
|
)
|
|
10
11
|
|
|
11
12
|
from .typing import (
|
|
@@ -22,27 +23,60 @@ from .typing import (
|
|
|
22
23
|
|
|
23
24
|
from ._core import (
|
|
24
25
|
xp_array_to_device,
|
|
25
|
-
CuPyNotFound,
|
|
26
|
+
CuPyNotFound,
|
|
27
|
+
CUPY_NOT_FOUND_MSG,
|
|
26
28
|
|
|
27
29
|
#* creation
|
|
28
|
-
zeros_like,
|
|
30
|
+
zeros_like,
|
|
31
|
+
ones_like,
|
|
29
32
|
|
|
30
33
|
#* elementwise
|
|
31
|
-
add,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
add,
|
|
35
|
+
subtract,
|
|
36
|
+
multiply,
|
|
37
|
+
matmul,
|
|
38
|
+
divide,
|
|
39
|
+
negative,
|
|
40
|
+
power,
|
|
41
|
+
clip,
|
|
42
|
+
sign,
|
|
43
|
+
abs,
|
|
44
|
+
#* elementwise (exponents/logarithm)
|
|
45
|
+
exp,
|
|
46
|
+
sqrt,
|
|
47
|
+
log,
|
|
48
|
+
square,
|
|
49
|
+
|
|
50
|
+
#* diff (elementwise)
|
|
51
|
+
add_diff,
|
|
52
|
+
subtract_diff,
|
|
53
|
+
multiply_diff,
|
|
54
|
+
matmul_diff,
|
|
55
|
+
divide_diff,
|
|
56
|
+
power_diff,
|
|
57
|
+
negative_diff,
|
|
58
|
+
sign_diff,
|
|
59
|
+
abs_diff,
|
|
60
|
+
#* diff (exponents/logarithm)
|
|
61
|
+
exp_diff,
|
|
62
|
+
sqrt_diff,
|
|
63
|
+
log_diff,
|
|
64
|
+
square_diff,
|
|
65
|
+
|
|
40
66
|
|
|
41
67
|
#* comparison
|
|
42
|
-
where,
|
|
68
|
+
where,
|
|
69
|
+
equal,
|
|
70
|
+
not_equal,
|
|
71
|
+
greater,
|
|
72
|
+
greater_equal,
|
|
73
|
+
less,
|
|
74
|
+
less_equal,
|
|
43
75
|
|
|
44
76
|
#* reduction
|
|
45
|
-
max,
|
|
77
|
+
max,
|
|
78
|
+
maximum,
|
|
79
|
+
sum
|
|
46
80
|
)
|
|
47
81
|
|
|
48
82
|
import numpy as np
|
|
@@ -302,6 +336,28 @@ class Tensor():
|
|
|
302
336
|
divide_diff, x1, x2, record_op
|
|
303
337
|
)
|
|
304
338
|
|
|
339
|
+
@staticmethod
|
|
340
|
+
def power(
|
|
341
|
+
x1: OperandLike,
|
|
342
|
+
x2: OperandLike,
|
|
343
|
+
/,
|
|
344
|
+
out: Optional[Union[np.ndarray, Any]] = None,
|
|
345
|
+
*,
|
|
346
|
+
device: DeviceLike = "cpu",
|
|
347
|
+
in_place: bool = False,
|
|
348
|
+
record_op: bool = True,
|
|
349
|
+
|
|
350
|
+
where: Union[ArrayLikeBool, bool] = True,
|
|
351
|
+
casting: Casting = 'same_kind',
|
|
352
|
+
order: Order = 'K',
|
|
353
|
+
dtype: Optional[DTypeLike] = None,
|
|
354
|
+
subok: bool = True
|
|
355
|
+
) -> Tensor:
|
|
356
|
+
return _wrapper_2in_1out(
|
|
357
|
+
power(x1, x2, out=out, device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok),
|
|
358
|
+
power_diff, x1, x2, record_op
|
|
359
|
+
)
|
|
360
|
+
|
|
305
361
|
@staticmethod
|
|
306
362
|
def negative(
|
|
307
363
|
x: OperandLike,
|
|
@@ -428,6 +484,48 @@ class Tensor():
|
|
|
428
484
|
sqrt_diff, x, record_op
|
|
429
485
|
)
|
|
430
486
|
|
|
487
|
+
@staticmethod
|
|
488
|
+
def log(
|
|
489
|
+
x: OperandLike,
|
|
490
|
+
/,
|
|
491
|
+
out: Optional[Union[np.ndarray, Any]] = None,
|
|
492
|
+
*,
|
|
493
|
+
device: DeviceLike = "cpu",
|
|
494
|
+
in_place: bool = False,
|
|
495
|
+
record_op: bool = True,
|
|
496
|
+
|
|
497
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
498
|
+
casting: Casting = 'same_kind',
|
|
499
|
+
order: Order = 'K',
|
|
500
|
+
dtype: Optional[DTypeLike] = None,
|
|
501
|
+
subok: bool = True
|
|
502
|
+
) -> Tensor:
|
|
503
|
+
return _wrapper_1in_1out(
|
|
504
|
+
log(x, out=out, device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok),
|
|
505
|
+
log_diff, x, record_op
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
@staticmethod
|
|
509
|
+
def square(
|
|
510
|
+
x: OperandLike,
|
|
511
|
+
/,
|
|
512
|
+
out: Optional[Union[np.ndarray, Any]] = None,
|
|
513
|
+
*,
|
|
514
|
+
device: DeviceLike = "cpu",
|
|
515
|
+
in_place: bool = False,
|
|
516
|
+
record_op: bool = True,
|
|
517
|
+
|
|
518
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
519
|
+
casting: Casting = 'same_kind',
|
|
520
|
+
order: Order = 'K',
|
|
521
|
+
dtype: Optional[DTypeLike] = None,
|
|
522
|
+
subok: bool = True
|
|
523
|
+
) -> Tensor:
|
|
524
|
+
return _wrapper_1in_1out(
|
|
525
|
+
square(x, out=out, device=device, in_place=in_place, where=where, casting=casting, order=order, dtype=dtype, subok=subok),
|
|
526
|
+
square_diff, x, record_op
|
|
527
|
+
)
|
|
528
|
+
|
|
431
529
|
###
|
|
432
530
|
### Comparison
|
|
433
531
|
###
|
|
@@ -655,6 +753,11 @@ class Tensor():
|
|
|
655
753
|
return Tensor.divide(t, self)
|
|
656
754
|
def __itruediv__(self, t: OperandLike) -> Tensor:
|
|
657
755
|
return Tensor.divide(self, t, in_place=True)
|
|
756
|
+
|
|
757
|
+
def __pow__(self, t: OperandLike) -> Tensor:
|
|
758
|
+
return Tensor.power(self, t)
|
|
759
|
+
def __ipow__(self, t: OperandLike) -> Tensor:
|
|
760
|
+
return Tensor.power(self, t, in_place=True)
|
|
658
761
|
|
|
659
762
|
###
|
|
660
763
|
### Unary
|
|
@@ -685,6 +788,15 @@ class Tensor():
|
|
|
685
788
|
### Misc dunder
|
|
686
789
|
###
|
|
687
790
|
|
|
791
|
+
def __getitem__(self, index) -> Any:
|
|
792
|
+
return self.data[index]
|
|
793
|
+
|
|
794
|
+
def __setitem__(self, index, value) -> Any:
|
|
795
|
+
self.data[index] = value
|
|
796
|
+
|
|
797
|
+
def __iter__(self) -> Iterator:
|
|
798
|
+
return iter(self.data)
|
|
799
|
+
|
|
688
800
|
def __repr__(self) -> str:
|
|
689
801
|
return f'Tensor({self.data}, device={self.device})'
|
|
690
802
|
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|