DepthTensor 1.3.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.
Files changed (27) hide show
  1. {depthtensor-1.3.1/src/DepthTensor.egg-info → depthtensor-1.4.0}/PKG-INFO +1 -1
  2. {depthtensor-1.3.1 → depthtensor-1.4.0}/pyproject.toml +1 -1
  3. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/__init__.py +1 -1
  4. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/diff.py +53 -2
  5. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/elementwise.py +18 -0
  6. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/tensor.py +115 -13
  7. {depthtensor-1.3.1 → depthtensor-1.4.0/src/DepthTensor.egg-info}/PKG-INFO +1 -1
  8. {depthtensor-1.3.1 → depthtensor-1.4.0}/LICENSE +0 -0
  9. {depthtensor-1.3.1 → depthtensor-1.4.0}/README.md +0 -0
  10. {depthtensor-1.3.1 → depthtensor-1.4.0}/setup.cfg +0 -0
  11. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/__init__.py +0 -0
  12. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/exceptions.py +0 -0
  13. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/__init__.py +0 -0
  14. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/comparison.py +0 -0
  15. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/creation.py +0 -0
  16. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/ops/reduction.py +0 -0
  17. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/random/__init__.py +0 -0
  18. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/random/generator.py +0 -0
  19. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/_core/utils.py +0 -0
  20. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/autodiff.py +0 -0
  21. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor/typing.py +0 -0
  22. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/SOURCES.txt +0 -0
  23. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
  24. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/requires.txt +0 -0
  25. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
  26. {depthtensor-1.3.1 → depthtensor-1.4.0}/src/example/example.py +0 -0
  27. {depthtensor-1.3.1 → depthtensor-1.4.0}/tests/test_tensor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DepthTensor
3
- Version: 1.3.1
3
+ Version: 1.4.0
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Requires-Dist: numpy
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "DepthTensor"
7
- version = "1.3.1"
7
+ version = "1.4.0"
8
8
  readme = "README.md"
9
9
  dependencies = [
10
10
  "numpy"
@@ -3,4 +3,4 @@ from .typing import *
3
3
  from ._core import random
4
4
  from .autodiff import differentiate
5
5
 
6
- __version__ = "1.3.1"
6
+ __version__ = "1.4.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', 'subtract_diff', 'multiply_diff', 'matmul_diff', 'divide_diff',
112
- 'negative_diff', 'exp_diff', 'sqrt_diff', 'sign_diff', 'abs_diff'
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',
@@ -22,27 +22,60 @@ from .typing import (
22
22
 
23
23
  from ._core import (
24
24
  xp_array_to_device,
25
- CuPyNotFound, CUPY_NOT_FOUND_MSG,
25
+ CuPyNotFound,
26
+ CUPY_NOT_FOUND_MSG,
26
27
 
27
28
  #* creation
28
- zeros_like, ones_like,
29
+ zeros_like,
30
+ ones_like,
29
31
 
30
32
  #* elementwise
31
- add, subtract, multiply, matmul, divide,
32
- negative, clip, sign, abs,
33
-
34
- #* exponents/logarithm
35
- exp, sqrt,
36
-
37
- #* diff
38
- add_diff, subtract_diff, multiply_diff, matmul_diff, divide_diff,
39
- negative_diff, exp_diff, sqrt_diff, sign_diff, abs_diff,
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, equal, not_equal, greater, greater_equal, less, less_equal,
67
+ where,
68
+ equal,
69
+ not_equal,
70
+ greater,
71
+ greater_equal,
72
+ less,
73
+ less_equal,
43
74
 
44
75
  #* reduction
45
- max, maximum, sum
76
+ max,
77
+ maximum,
78
+ sum
46
79
  )
47
80
 
48
81
  import numpy as np
@@ -302,6 +335,28 @@ 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
362
  x: OperandLike,
@@ -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
  ###
@@ -655,6 +752,11 @@ class Tensor():
655
752
  return Tensor.divide(t, self)
656
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DepthTensor
3
- Version: 1.3.1
3
+ Version: 1.4.0
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Requires-Dist: numpy
File without changes
File without changes
File without changes