DepthTensor 1.11.1__tar.gz → 2.0.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 (34) hide show
  1. {depthtensor-1.11.1/src/DepthTensor.egg-info → depthtensor-2.0.0}/PKG-INFO +1 -3
  2. {depthtensor-1.11.1 → depthtensor-2.0.0}/pyproject.toml +1 -4
  3. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/__init__.py +5 -3
  4. depthtensor-2.0.0/src/DepthTensor/_core/ops/comparison.py +323 -0
  5. depthtensor-2.0.0/src/DepthTensor/_core/ops/creation.py +93 -0
  6. depthtensor-2.0.0/src/DepthTensor/_core/ops/elementwise.py +741 -0
  7. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/_core/ops/reduction.py +53 -53
  8. depthtensor-2.0.0/src/DepthTensor/_core/utils.py +226 -0
  9. depthtensor-2.0.0/src/DepthTensor/tensor.py +541 -0
  10. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/typing.py +54 -59
  11. {depthtensor-1.11.1 → depthtensor-2.0.0/src/DepthTensor.egg-info}/PKG-INFO +1 -3
  12. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor.egg-info/SOURCES.txt +1 -2
  13. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor.egg-info/requires.txt +0 -3
  14. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/example/example.py +18 -4
  15. depthtensor-2.0.0/src/example/test.py +7 -0
  16. depthtensor-1.11.1/src/DepthTensor/_core/ops/comparison.py +0 -229
  17. depthtensor-1.11.1/src/DepthTensor/_core/ops/creation.py +0 -95
  18. depthtensor-1.11.1/src/DepthTensor/_core/ops/elementwise.py +0 -541
  19. depthtensor-1.11.1/src/DepthTensor/_core/utils.py +0 -154
  20. depthtensor-1.11.1/src/DepthTensor/tensor.py +0 -887
  21. depthtensor-1.11.1/src/example/test.py +0 -12
  22. depthtensor-1.11.1/tests/test_tensor.py +0 -49
  23. {depthtensor-1.11.1 → depthtensor-2.0.0}/LICENSE +0 -0
  24. {depthtensor-1.11.1 → depthtensor-2.0.0}/README.md +0 -0
  25. {depthtensor-1.11.1 → depthtensor-2.0.0}/setup.cfg +0 -0
  26. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/_core/__init__.py +0 -0
  27. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/_core/exceptions.py +0 -0
  28. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/_core/ops/__init__.py +0 -0
  29. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/_core/ops/diff.py +0 -0
  30. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/_core/random/__init__.py +0 -0
  31. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/_core/random/generator.py +0 -0
  32. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor/autodiff.py +0 -0
  33. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
  34. {depthtensor-1.11.1 → depthtensor-2.0.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
@@ -1,11 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DepthTensor
3
- Version: 1.11.1
3
+ Version: 2.0.0
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Requires-Dist: numpy
7
- Provides-Extra: test
8
- Requires-Dist: pytest; extra == "test"
9
7
  Provides-Extra: gpu
10
8
  Requires-Dist: cupy-cuda12x; extra == "gpu"
11
9
  Dynamic: license-file
@@ -4,16 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "DepthTensor"
7
- version = "1.11.1"
7
+ version = "2.0.0"
8
8
  readme = "README.md"
9
9
  dependencies = [
10
10
  "numpy"
11
11
  ]
12
12
 
13
13
  [project.optional-dependencies]
14
- test = [
15
- "pytest"
16
- ]
17
14
  gpu = [
18
15
  "cupy-cuda12x"
19
16
  ]
@@ -1,7 +1,9 @@
1
1
  from .tensor import Tensor
2
+ from .autodiff import differentiate
2
3
  from .typing import *
3
- from ._core import random, create_2in_1out, create_1in_1out
4
+
5
+ from ._core.ops import *
4
6
  from ._core.exceptions import *
5
- from .autodiff import differentiate
7
+ from ._core import random
6
8
 
7
- __version__ = "1.11.1"
9
+ __version__ = "2.0.0"
@@ -0,0 +1,323 @@
1
+ from typing import Union, Optional, Tuple, overload
2
+
3
+ from ...typing import (
4
+ TensorLike,
5
+ DeviceLike,
6
+ NDArrayLikeBool,
7
+ Casting,
8
+ Order,
9
+ OperandLike,
10
+ )
11
+
12
+ from ..exceptions import (
13
+ CuPyNotFound,
14
+ CUPY_NOT_FOUND_MSG,
15
+ DeviceMismatch,
16
+ DEVICE_MISMATCH_MSG,
17
+ )
18
+
19
+ from ..utils import to_xp_array, get_device, get_two_operand_op_device
20
+
21
+ import numpy as np
22
+
23
+ try:
24
+ import cupy as cp
25
+ except (ImportError, ModuleNotFoundError):
26
+ cp = None
27
+
28
+ ###
29
+ ###
30
+ ###
31
+
32
+
33
+ @overload
34
+ def where(
35
+ condition: OperandLike,
36
+ /,
37
+ *,
38
+ device: DeviceLike = "cpu",
39
+ requires_grad: bool = False,
40
+ ) -> Tuple[TensorLike, ...]: ...
41
+
42
+
43
+ @overload
44
+ def where(
45
+ condition: OperandLike,
46
+ x: Optional[OperandLike],
47
+ y: Optional[OperandLike],
48
+ /,
49
+ *,
50
+ device: DeviceLike = "cpu",
51
+ requires_grad: bool = False,
52
+ ) -> TensorLike: ...
53
+
54
+
55
+ def where(
56
+ condition: OperandLike,
57
+ x: Optional[OperandLike] = None,
58
+ y: Optional[OperandLike] = None,
59
+ /,
60
+ *,
61
+ device: Optional[DeviceLike] = None,
62
+ requires_grad: bool = False,
63
+ ) -> Union[Tuple[TensorLike, ...], TensorLike]:
64
+ from ...tensor import Tensor
65
+
66
+ if device is None:
67
+ device = get_device(condition)
68
+
69
+ # * One parameter overload
70
+ if (x is None) and (y is None):
71
+ data = to_xp_array(condition, device=device)
72
+ if device == "cpu":
73
+ result = np.where(data)
74
+ else:
75
+ if cp is None:
76
+ raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
77
+ result = cp.where(data)
78
+ return tuple(
79
+ [
80
+ Tensor(array, device=device, requires_grad=requires_grad)
81
+ for array in result
82
+ ]
83
+ )
84
+ # * Two parameters overload
85
+ elif x is not None and y is not None:
86
+ if (
87
+ not (get_device(x) == get_device(y) == device)
88
+ and not isinstance(x, (int, float, list, tuple))
89
+ and not isinstance(y, (int, float, list, tuple))
90
+ ):
91
+ raise DeviceMismatch(DEVICE_MISMATCH_MSG)
92
+
93
+ data = to_xp_array(condition, device=device)
94
+ x_data = to_xp_array(x, device=device)
95
+ y_data = to_xp_array(y, device=device)
96
+ if device == "cpu":
97
+ result = np.where(data, x_data, y_data)
98
+ else:
99
+ if cp is None:
100
+ raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
101
+ result = cp.where(data, x_data, y_data)
102
+ return Tensor(result, device=device, requires_grad=requires_grad)
103
+ else:
104
+ raise ValueError("Both x and y parameters must be given.")
105
+
106
+
107
+ ###
108
+ ###
109
+ ###
110
+
111
+
112
+ def wrapper_2in_1out(
113
+ x1: OperandLike,
114
+ x2: OperandLike,
115
+ /,
116
+ out: Optional[NDArrayLikeBool] = None,
117
+ *,
118
+ func_name: str,
119
+ device: Optional[DeviceLike] = None,
120
+ where: Union[bool, NDArrayLikeBool] = True,
121
+ casting: Casting = "same_kind",
122
+ order: Order = "K",
123
+ dtype: None = None,
124
+ subok: bool = True,
125
+ ) -> TensorLike:
126
+ from ...tensor import Tensor
127
+
128
+ op_device = get_two_operand_op_device(x1, x2, device)
129
+
130
+ x1, x2 = to_xp_array(x1, device=op_device), to_xp_array(x2, device=op_device)
131
+ if op_device == "cpu":
132
+ y = getattr(np, func_name)(
133
+ x1,
134
+ x2,
135
+ out=out,
136
+ dtype=dtype,
137
+ where=where,
138
+ casting=casting,
139
+ order=order,
140
+ subok=subok,
141
+ )
142
+ else:
143
+ if cp is None:
144
+ raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
145
+ y = getattr(cp, func_name)(x1, x2, out=out, dtype=dtype, casting=casting)
146
+ return Tensor(y, device=op_device)
147
+
148
+
149
+ def equal(
150
+ x1: OperandLike,
151
+ x2: OperandLike,
152
+ /,
153
+ out: Optional[NDArrayLikeBool] = None,
154
+ *,
155
+ device: Optional[DeviceLike] = None,
156
+ where: Union[bool, NDArrayLikeBool] = True,
157
+ casting: Casting = "same_kind",
158
+ order: Order = "K",
159
+ dtype: None = None,
160
+ subok: bool = True,
161
+ ) -> TensorLike:
162
+ return wrapper_2in_1out(
163
+ x1,
164
+ x2,
165
+ out=out,
166
+ func_name="equal",
167
+ device=device,
168
+ where=where,
169
+ casting=casting,
170
+ order=order,
171
+ dtype=dtype,
172
+ subok=subok,
173
+ )
174
+
175
+
176
+ def not_equal(
177
+ x1: OperandLike,
178
+ x2: OperandLike,
179
+ /,
180
+ out: Optional[NDArrayLikeBool] = None,
181
+ *,
182
+ device: Optional[DeviceLike] = None,
183
+ where: Union[bool, NDArrayLikeBool] = True,
184
+ casting: Casting = "same_kind",
185
+ order: Order = "K",
186
+ dtype: None = None,
187
+ subok: bool = True,
188
+ ) -> TensorLike:
189
+ return wrapper_2in_1out(
190
+ x1,
191
+ x2,
192
+ out=out,
193
+ func_name="not_equal",
194
+ device=device,
195
+ where=where,
196
+ casting=casting,
197
+ order=order,
198
+ dtype=dtype,
199
+ subok=subok,
200
+ )
201
+
202
+
203
+ def greater(
204
+ x1: OperandLike,
205
+ x2: OperandLike,
206
+ /,
207
+ out: Optional[NDArrayLikeBool] = None,
208
+ *,
209
+ device: Optional[DeviceLike] = None,
210
+ where: Union[bool, NDArrayLikeBool] = True,
211
+ casting: Casting = "same_kind",
212
+ order: Order = "K",
213
+ dtype: None = None,
214
+ subok: bool = True,
215
+ ) -> TensorLike:
216
+ return wrapper_2in_1out(
217
+ x1,
218
+ x2,
219
+ out=out,
220
+ func_name="greater",
221
+ device=device,
222
+ where=where,
223
+ casting=casting,
224
+ order=order,
225
+ dtype=dtype,
226
+ subok=subok,
227
+ )
228
+
229
+
230
+ def greater_equal(
231
+ x1: OperandLike,
232
+ x2: OperandLike,
233
+ /,
234
+ out: Optional[NDArrayLikeBool] = None,
235
+ *,
236
+ device: Optional[DeviceLike] = None,
237
+ where: Union[bool, NDArrayLikeBool] = True,
238
+ casting: Casting = "same_kind",
239
+ order: Order = "K",
240
+ dtype: None = None,
241
+ subok: bool = True,
242
+ ) -> TensorLike:
243
+ return wrapper_2in_1out(
244
+ x1,
245
+ x2,
246
+ out=out,
247
+ func_name="greater_equal",
248
+ device=device,
249
+ where=where,
250
+ casting=casting,
251
+ order=order,
252
+ dtype=dtype,
253
+ subok=subok,
254
+ )
255
+
256
+
257
+ def less(
258
+ x1: OperandLike,
259
+ x2: OperandLike,
260
+ /,
261
+ out: Optional[NDArrayLikeBool] = None,
262
+ *,
263
+ device: Optional[DeviceLike] = None,
264
+ where: Union[bool, NDArrayLikeBool] = True,
265
+ casting: Casting = "same_kind",
266
+ order: Order = "K",
267
+ dtype: None = None,
268
+ subok: bool = True,
269
+ ) -> TensorLike:
270
+ return wrapper_2in_1out(
271
+ x1,
272
+ x2,
273
+ out=out,
274
+ func_name="less",
275
+ device=device,
276
+ where=where,
277
+ casting=casting,
278
+ order=order,
279
+ dtype=dtype,
280
+ subok=subok,
281
+ )
282
+
283
+
284
+ def less_equal(
285
+ x1: OperandLike,
286
+ x2: OperandLike,
287
+ /,
288
+ out: Optional[NDArrayLikeBool] = None,
289
+ *,
290
+ device: Optional[DeviceLike] = None,
291
+ where: Union[bool, NDArrayLikeBool] = True,
292
+ casting: Casting = "same_kind",
293
+ order: Order = "K",
294
+ dtype: None = None,
295
+ subok: bool = True,
296
+ ) -> TensorLike:
297
+ return wrapper_2in_1out(
298
+ x1,
299
+ x2,
300
+ out=out,
301
+ func_name="less_equal",
302
+ device=device,
303
+ where=where,
304
+ casting=casting,
305
+ order=order,
306
+ dtype=dtype,
307
+ subok=subok,
308
+ )
309
+
310
+
311
+ ###
312
+ ###
313
+ ###
314
+
315
+ __all__ = [
316
+ "where",
317
+ "equal",
318
+ "not_equal",
319
+ "greater",
320
+ "greater_equal",
321
+ "less",
322
+ "less_equal",
323
+ ]
@@ -0,0 +1,93 @@
1
+ from typing import Optional
2
+
3
+ from ...typing import TensorLike, DTypeLike, Order, AxisLike, OperandLike, DeviceLike
4
+
5
+ from ..exceptions import CuPyNotFound, CUPY_NOT_FOUND_MSG
6
+
7
+ from ..utils import to_xp_array, get_device
8
+
9
+ import numpy as np
10
+
11
+ try:
12
+ import cupy as cp
13
+ except (ImportError, ModuleNotFoundError):
14
+ cp = None
15
+
16
+ ###
17
+ ###
18
+ ###
19
+
20
+
21
+ def zeros_like(
22
+ a: OperandLike,
23
+ /,
24
+ *,
25
+ device: Optional[DeviceLike] = None,
26
+ requires_grad: bool = False,
27
+ dtype: Optional[DTypeLike] = None,
28
+ order: Order = "K",
29
+ subok: bool = True,
30
+ shape: Optional[AxisLike] = None,
31
+ ) -> TensorLike:
32
+ from ...tensor import Tensor
33
+
34
+ if device is None:
35
+ device_op = get_device(a)
36
+ else:
37
+ device_op = device
38
+ a = to_xp_array(a)
39
+ if device_op == "cpu":
40
+ return Tensor(
41
+ np.zeros_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
42
+ device=device_op,
43
+ requires_grad=requires_grad,
44
+ )
45
+ else:
46
+ if cp is None:
47
+ raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
48
+ return Tensor(
49
+ cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
50
+ device=device_op,
51
+ requires_grad=requires_grad,
52
+ )
53
+
54
+
55
+ def ones_like(
56
+ a: OperandLike,
57
+ /,
58
+ *,
59
+ device: Optional[DeviceLike] = None,
60
+ requires_grad: bool = False,
61
+ dtype: Optional[DTypeLike] = None,
62
+ order: Order = "K",
63
+ subok: bool = True,
64
+ shape: Optional[AxisLike] = None,
65
+ ) -> TensorLike:
66
+ from ...tensor import Tensor
67
+
68
+ if device is None:
69
+ device_op = get_device(a)
70
+ else:
71
+ device_op = device
72
+ a = to_xp_array(a)
73
+ if device_op == "cpu":
74
+ return Tensor(
75
+ np.ones_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
76
+ device=device_op,
77
+ requires_grad=requires_grad,
78
+ )
79
+ else:
80
+ if cp is None:
81
+ raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
82
+ return Tensor(
83
+ cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
84
+ device=device_op,
85
+ requires_grad=requires_grad,
86
+ )
87
+
88
+
89
+ ###
90
+ ###
91
+ ###
92
+
93
+ __all__ = ["zeros_like", "ones_like"]