DepthTensor 1.5.0__tar.gz → 1.7.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.5.0/src/DepthTensor.egg-info → depthtensor-1.7.0}/PKG-INFO +1 -1
  2. {depthtensor-1.5.0 → depthtensor-1.7.0}/pyproject.toml +1 -1
  3. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/__init__.py +1 -1
  4. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/ops/creation.py +6 -4
  5. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/ops/reduction.py +6 -3
  6. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/random/generator.py +18 -12
  7. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/tensor.py +37 -5
  8. {depthtensor-1.5.0 → depthtensor-1.7.0/src/DepthTensor.egg-info}/PKG-INFO +1 -1
  9. {depthtensor-1.5.0 → depthtensor-1.7.0}/LICENSE +0 -0
  10. {depthtensor-1.5.0 → depthtensor-1.7.0}/README.md +0 -0
  11. {depthtensor-1.5.0 → depthtensor-1.7.0}/setup.cfg +0 -0
  12. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/__init__.py +0 -0
  13. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/exceptions.py +0 -0
  14. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/ops/__init__.py +0 -0
  15. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/ops/comparison.py +0 -0
  16. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/ops/diff.py +0 -0
  17. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/ops/elementwise.py +0 -0
  18. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/random/__init__.py +0 -0
  19. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/_core/utils.py +0 -0
  20. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/autodiff.py +0 -0
  21. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor/typing.py +0 -0
  22. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor.egg-info/SOURCES.txt +0 -0
  23. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
  24. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor.egg-info/requires.txt +0 -0
  25. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
  26. {depthtensor-1.5.0 → depthtensor-1.7.0}/src/example/example.py +0 -0
  27. {depthtensor-1.5.0 → depthtensor-1.7.0}/tests/test_tensor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DepthTensor
3
- Version: 1.5.0
3
+ Version: 1.7.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.5.0"
7
+ version = "1.7.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.5.0"
6
+ __version__ = "1.7.0"
@@ -32,6 +32,7 @@ def zeros_like(
32
32
  /,
33
33
  *,
34
34
  device: DeviceLike = "cpu",
35
+ requires_grad: bool = False,
35
36
  dtype: Optional[DTypeLike] = None,
36
37
  order: Order = 'K',
37
38
  subok: bool = True,
@@ -46,14 +47,14 @@ def zeros_like(
46
47
  if device_op == "cpu":
47
48
  return Tensor(
48
49
  np.zeros_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
49
- device=device_op
50
+ device=device_op, requires_grad=requires_grad
50
51
  )
51
52
  else:
52
53
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
53
54
  return Tensor(
54
55
  #! As of the time writing this, CuPy does not support subok.
55
56
  cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
56
- device=device_op
57
+ device=device_op, requires_grad=requires_grad
57
58
  )
58
59
 
59
60
  def ones_like(
@@ -61,6 +62,7 @@ def ones_like(
61
62
  /,
62
63
  *,
63
64
  device: DeviceLike = "cpu",
65
+ requires_grad: bool = False,
64
66
  dtype: Optional[DTypeLike] = None,
65
67
  order: Order = 'K',
66
68
  subok: bool = True,
@@ -75,14 +77,14 @@ def ones_like(
75
77
  if device_op == "cpu":
76
78
  return Tensor(
77
79
  np.ones_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
78
- device=device_op
80
+ device=device_op, requires_grad=requires_grad
79
81
  )
80
82
  else:
81
83
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
82
84
  return Tensor(
83
85
  #! As of the time writing this, CuPy does not support subok.
84
86
  cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
85
- device=device_op
87
+ device=device_op, requires_grad=requires_grad
86
88
  )
87
89
 
88
90
  ###
@@ -41,6 +41,7 @@ def sum(
41
41
  /,
42
42
  *,
43
43
  device: DeviceLike = "cpu",
44
+ requires_grad: bool = False,
44
45
  axis: Optional[AxisShapeLike] = None,
45
46
  dtype: Optional[DTypeLike] = None,
46
47
  out: Optional[Union[np.ndarray, Any]] = None,
@@ -70,13 +71,14 @@ def sum(
70
71
  else:
71
72
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
72
73
  y = cp.sum(arr, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
73
- return Tensor(y, device=device_op)
74
+ return Tensor(y, device=device_op, requires_grad=requires_grad)
74
75
 
75
76
  def max(
76
77
  a: OperandLike,
77
78
  /,
78
79
  *,
79
80
  device: DeviceLike = "cpu",
81
+ requires_grad: bool = False,
80
82
  axis: Optional[ShapeLike] = None,
81
83
  out: Optional[Union[np.ndarray, Any]] = None,
82
84
  keepdims: bool = False,
@@ -95,7 +97,7 @@ def max(
95
97
  else:
96
98
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
97
99
  y = cp.max(arr, axis=axis, out=out, keepdims=keepdims)
98
- return Tensor(y, device=device_op)
100
+ return Tensor(y, device=device_op, requires_grad=requires_grad)
99
101
 
100
102
  def maximum(
101
103
  x1: OperandLike,
@@ -104,6 +106,7 @@ def maximum(
104
106
  out: Optional[np.ndarray] = None,
105
107
  *,
106
108
  device: DeviceLike = "cpu",
109
+ requires_grad: bool = False,
107
110
  where: Union[bool, ArrayLikeBool] = True,
108
111
  casting: Casting = 'same_kind',
109
112
  order: Order = 'K',
@@ -126,7 +129,7 @@ def maximum(
126
129
  y = np.maximum(x1, x2, out=out, dtype=dtype, where=where, casting=casting, order=order, subok=subok)
127
130
  else:
128
131
  y = np.maximum(x1, x2, out=out, dtype=dtype, casting=casting)
129
- return Tensor(y, device=device_op)
132
+ return Tensor(y, device=device_op, requires_grad=requires_grad)
130
133
 
131
134
  ###
132
135
  ###
@@ -28,17 +28,19 @@ except (ImportError, ModuleNotFoundError):
28
28
  ###
29
29
 
30
30
  @overload
31
- def rand(*, device: DeviceLike = "cpu") -> TensorLike: ...
31
+ def rand(*, device: DeviceLike = "cpu", requires_grad: bool = False) -> TensorLike: ...
32
32
  @overload
33
33
  def rand(
34
34
  *d: int,
35
35
  dtype: Optional[DTypeLike] = None,
36
- device: DeviceLike = "cpu"
36
+ device: DeviceLike = "cpu",
37
+ requires_grad: bool = False
37
38
  ) -> TensorLike: ...
38
39
  def rand(
39
40
  *d: int,
40
41
  dtype: Optional[DTypeLike] = None,
41
- device: DeviceLike = "cpu"
42
+ device: DeviceLike = "cpu",
43
+ requires_grad: bool = False
42
44
  ) -> TensorLike:
43
45
  from ...tensor import Tensor
44
46
  if device == "cpu":
@@ -46,20 +48,22 @@ def rand(
46
48
  else:
47
49
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
48
50
  y = cp.random.rand(*d, dtype=dtype)
49
- return Tensor(y, dtype=dtype)
51
+ return Tensor(y, dtype=dtype, requires_grad=requires_grad)
50
52
 
51
53
  @overload
52
- def randn(*, device: DeviceLike = "cpu") -> TensorLike: ...
54
+ def randn(*, device: DeviceLike = "cpu", requires_grad: bool = False) -> TensorLike: ...
53
55
  @overload
54
56
  def randn(
55
57
  *d: int,
56
58
  dtype: Optional[DTypeLike] = None,
57
- device: DeviceLike = "cpu"
59
+ device: DeviceLike = "cpu",
60
+ requires_grad: bool = False
58
61
  ) -> TensorLike: ...
59
62
  def randn(
60
63
  *d: int,
61
64
  dtype: Optional[DTypeLike] = None,
62
- device: DeviceLike = "cpu"
65
+ device: DeviceLike = "cpu",
66
+ requires_grad: bool = False
63
67
  ) -> TensorLike:
64
68
  from ...tensor import Tensor
65
69
  if device == "cpu":
@@ -67,14 +71,15 @@ def randn(
67
71
  else:
68
72
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
69
73
  y = cp.random.randn(*d, dtype=dtype)
70
- return Tensor(y, dtype=dtype)
74
+ return Tensor(y, dtype=dtype, requires_grad=requires_grad)
71
75
 
72
76
  def randint(
73
77
  low: int,
74
78
  high: Optional[int] = None,
75
79
  size: Optional[AxisLike] = None,
76
80
  dtype: Any = int64,
77
- device: DeviceLike = "cpu"
81
+ device: DeviceLike = "cpu",
82
+ requires_grad: bool = False
78
83
  ) -> TensorLike:
79
84
  from ...tensor import Tensor
80
85
  if device == "cpu":
@@ -82,14 +87,15 @@ def randint(
82
87
  else:
83
88
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
84
89
  y = cp.random.randint(low=low, high=high, size=size, dtype=dtype)
85
- return Tensor(y)
90
+ return Tensor(y, requires_grad=requires_grad)
86
91
 
87
92
  def uniform(
88
93
  low: float = 0.0,
89
94
  high: float = 1.0,
90
95
  size: Optional[AxisLike] = None,
91
96
  *,
92
- device: DeviceLike = "cpu"
97
+ device: DeviceLike = "cpu",
98
+ requires_grad: bool = False
93
99
  ):
94
100
  from ...tensor import Tensor
95
101
  if device == "cpu":
@@ -97,7 +103,7 @@ def uniform(
97
103
  else:
98
104
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
99
105
  y = cp.random.uniform(low=low, high=high, size=size)
100
- return Tensor(y)
106
+ return Tensor(y, requires_grad=requires_grad)
101
107
 
102
108
  ###
103
109
  ###
@@ -164,6 +164,33 @@ class Tensor():
164
164
  ###
165
165
  ###
166
166
 
167
+ def copy(
168
+ self,
169
+ *,
170
+ order: Order = "K",
171
+ dtype: Optional[DTypeLike] = None,
172
+ device: Optional[DeviceLike] = None,
173
+ copy_prev: bool = False,
174
+ copy_requires_grad: bool = False,
175
+ copy_grad: bool = False
176
+ ) -> Tensor:
177
+ t = Tensor(
178
+ self.data.copy(order=order),
179
+ dtype=self.dtype if dtype is None else dtype,
180
+ device=self.device if device is None else device,
181
+ prev=self.prev if copy_prev else (),
182
+ requires_grad=self.requires_grad if copy_requires_grad else False
183
+ )
184
+ if copy_grad:
185
+ t.grad = self.grad
186
+ return t
187
+
188
+ def to_device(self, device: DeviceLike) -> Tensor:
189
+ if device == self.device:
190
+ return self.copy()
191
+ else:
192
+ return self.copy(device=device)
193
+
167
194
  def get_device(self) -> DeviceLike:
168
195
  return self.device
169
196
  def is_device(self, device: DeviceLike) -> bool:
@@ -203,12 +230,13 @@ class Tensor():
203
230
  /,
204
231
  *,
205
232
  device: DeviceLike = "cpu",
233
+ requires_grad: bool = False,
206
234
  dtype: Optional[DTypeLike] = None,
207
235
  order: Order = 'K',
208
236
  subok: bool = True,
209
237
  shape: Optional[AxisShapeLike] = None
210
238
  ) -> Tensor:
211
- return zeros_like(a, device=device, dtype=dtype, order=order, subok=subok, shape=shape)
239
+ return zeros_like(a, device=device, requires_grad=requires_grad, dtype=dtype, order=order, subok=subok, shape=shape)
212
240
 
213
241
  @staticmethod
214
242
  def ones_like(
@@ -216,12 +244,13 @@ class Tensor():
216
244
  /,
217
245
  *,
218
246
  device: DeviceLike = "cpu",
247
+ requires_grad: bool = False,
219
248
  dtype: Optional[DTypeLike] = None,
220
249
  order: Order = 'K',
221
250
  subok: bool = True,
222
251
  shape: Optional[AxisShapeLike] = None
223
252
  ) -> Tensor:
224
- return ones_like(a, device=device, dtype=dtype, order=order, subok=subok, shape=shape)
253
+ return ones_like(a, device=device, requires_grad=requires_grad, dtype=dtype, order=order, subok=subok, shape=shape)
225
254
 
226
255
  ###
227
256
  ### Element-wise
@@ -676,6 +705,7 @@ class Tensor():
676
705
  /,
677
706
  *,
678
707
  device: DeviceLike = "cpu",
708
+ requires_grad: bool = False,
679
709
  axis: Optional[AxisShapeLike] = None,
680
710
  dtype: Optional[DTypeLike] = None,
681
711
  out: Optional[Union[np.ndarray, Any]] = None,
@@ -683,7 +713,7 @@ class Tensor():
683
713
  initial: Any = _NoValue,
684
714
  where: Union[bool, ArrayLikeBool] = True
685
715
  ) -> Tensor:
686
- return sum(a, axis=axis, device=device, dtype=dtype, out=out, keepdims=keepdims, initial=initial, where=where)
716
+ return sum(a, axis=axis, device=device, requires_grad=requires_grad, dtype=dtype, out=out, keepdims=keepdims, initial=initial, where=where)
687
717
 
688
718
  @staticmethod
689
719
  def max(
@@ -691,13 +721,14 @@ class Tensor():
691
721
  /,
692
722
  *,
693
723
  device: DeviceLike = "cpu",
724
+ requires_grad: bool = False,
694
725
  axis: Optional[ShapeLike] = None,
695
726
  out: Optional[Union[np.ndarray, Any]] = None,
696
727
  keepdims: bool = False,
697
728
  initial: Any = _NoValue,
698
729
  where: Union[bool, ArrayLikeBool] = True
699
730
  ) -> Tensor:
700
- return max(a, axis=axis, device=device, out=out, keepdims=keepdims, initial=initial, where=where)
731
+ return max(a, axis=axis, device=device, requires_grad=requires_grad, out=out, keepdims=keepdims, initial=initial, where=where)
701
732
 
702
733
  @staticmethod
703
734
  def maximum(
@@ -707,13 +738,14 @@ class Tensor():
707
738
  out: Optional[np.ndarray] = None,
708
739
  *,
709
740
  device: DeviceLike = "cpu",
741
+ requires_grad: bool = False,
710
742
  where: Union[bool, ArrayLikeBool] = True,
711
743
  casting: Casting = 'same_kind',
712
744
  order: Order = 'K',
713
745
  dtype: Optional[DTypeLike] = None,
714
746
  subok: bool = True
715
747
  ) -> Tensor:
716
- return maximum(x1, x2, out=out, device=device, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
748
+ return maximum(x1, x2, out=out, device=device, requires_grad=requires_grad, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
717
749
 
718
750
  ###
719
751
  ### Dunder Operations
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DepthTensor
3
- Version: 1.5.0
3
+ Version: 1.7.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