DepthTensor 1.0.0__tar.gz → 1.2.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 (33) hide show
  1. {depthtensor-1.0.0 → depthtensor-1.2.0}/LICENSE +20 -20
  2. {depthtensor-1.0.0/src/DepthTensor.egg-info → depthtensor-1.2.0}/PKG-INFO +26 -26
  3. {depthtensor-1.0.0 → depthtensor-1.2.0}/README.md +13 -13
  4. {depthtensor-1.0.0 → depthtensor-1.2.0}/pyproject.toml +21 -21
  5. {depthtensor-1.0.0 → depthtensor-1.2.0}/setup.cfg +4 -4
  6. depthtensor-1.2.0/src/DepthTensor/__init__.py +6 -0
  7. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor/_core/__init__.py +3 -3
  8. depthtensor-1.2.0/src/DepthTensor/_core/exceptions.py +16 -0
  9. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor/_core/ops/__init__.py +5 -5
  10. depthtensor-1.2.0/src/DepthTensor/_core/ops/comparison.py +226 -0
  11. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor/_core/ops/creation.py +94 -76
  12. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor/_core/ops/diff.py +112 -87
  13. depthtensor-1.2.0/src/DepthTensor/_core/ops/elementwise.py +362 -0
  14. depthtensor-1.2.0/src/DepthTensor/_core/ops/reduction.py +136 -0
  15. depthtensor-1.2.0/src/DepthTensor/_core/random/__init__.py +1 -0
  16. depthtensor-1.2.0/src/DepthTensor/_core/random/generator.py +110 -0
  17. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor/_core/utils.py +127 -90
  18. depthtensor-1.2.0/src/DepthTensor/autodiff.py +45 -0
  19. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor/tensor.py +704 -449
  20. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor/typing.py +40 -39
  21. {depthtensor-1.0.0 → depthtensor-1.2.0/src/DepthTensor.egg-info}/PKG-INFO +26 -26
  22. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor.egg-info/SOURCES.txt +3 -0
  23. depthtensor-1.2.0/src/example/example.py +4 -0
  24. {depthtensor-1.0.0 → depthtensor-1.2.0}/tests/test_tensor.py +48 -48
  25. depthtensor-1.0.0/src/DepthTensor/__init__.py +0 -4
  26. depthtensor-1.0.0/src/DepthTensor/_core/exceptions.py +0 -8
  27. depthtensor-1.0.0/src/DepthTensor/_core/ops/comparison.py +0 -109
  28. depthtensor-1.0.0/src/DepthTensor/_core/ops/elementwise.py +0 -206
  29. depthtensor-1.0.0/src/DepthTensor/_core/ops/reduction.py +0 -76
  30. depthtensor-1.0.0/src/example/example.py +0 -10
  31. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
  32. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor.egg-info/requires.txt +0 -0
  33. {depthtensor-1.0.0 → depthtensor-1.2.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Lê Hồng Hà
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Lê Hồng Hà
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
@@ -1,26 +1,26 @@
1
- Metadata-Version: 2.4
2
- Name: DepthTensor
3
- Version: 1.0.0
4
- Description-Content-Type: text/markdown
5
- License-File: LICENSE
6
- Requires-Dist: numpy
7
- Provides-Extra: test
8
- Requires-Dist: pytest; extra == "test"
9
- Provides-Extra: gpu
10
- Requires-Dist: cupy-cuda12x; extra == "gpu"
11
- Dynamic: license-file
12
-
13
- # DepthTensor
14
- This is a NumPy/CuPy wrapper module designed for tensor computations. DepthTensor was created to operate in tandem with another library called Depth, a deep-learning library.
15
-
16
- # Functionalities
17
-
18
- * NumPy functionalities (N-dimensional array, broadcasting, etc.)
19
-
20
- * Auto-differentiation
21
-
22
- # Installation
23
-
24
- ```bash
25
- pip install DepthTensor
26
- ```
1
+ Metadata-Version: 2.4
2
+ Name: DepthTensor
3
+ Version: 1.2.0
4
+ Description-Content-Type: text/markdown
5
+ License-File: LICENSE
6
+ Requires-Dist: numpy
7
+ Provides-Extra: test
8
+ Requires-Dist: pytest; extra == "test"
9
+ Provides-Extra: gpu
10
+ Requires-Dist: cupy-cuda12x; extra == "gpu"
11
+ Dynamic: license-file
12
+
13
+ # DepthTensor
14
+ This is a NumPy/CuPy wrapper module designed for tensor computations. DepthTensor was created to operate in tandem with another library called Depth, a deep-learning library.
15
+
16
+ # Functionalities
17
+
18
+ * NumPy functionalities (N-dimensional array, broadcasting, etc.)
19
+
20
+ * Auto-differentiation
21
+
22
+ # Installation
23
+
24
+ ```bash
25
+ pip install DepthTensor
26
+ ```
@@ -1,14 +1,14 @@
1
- # DepthTensor
2
- This is a NumPy/CuPy wrapper module designed for tensor computations. DepthTensor was created to operate in tandem with another library called Depth, a deep-learning library.
3
-
4
- # Functionalities
5
-
6
- * NumPy functionalities (N-dimensional array, broadcasting, etc.)
7
-
8
- * Auto-differentiation
9
-
10
- # Installation
11
-
12
- ```bash
13
- pip install DepthTensor
1
+ # DepthTensor
2
+ This is a NumPy/CuPy wrapper module designed for tensor computations. DepthTensor was created to operate in tandem with another library called Depth, a deep-learning library.
3
+
4
+ # Functionalities
5
+
6
+ * NumPy functionalities (N-dimensional array, broadcasting, etc.)
7
+
8
+ * Auto-differentiation
9
+
10
+ # Installation
11
+
12
+ ```bash
13
+ pip install DepthTensor
14
14
  ```
@@ -1,22 +1,22 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0.0"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "DepthTensor"
7
- version = "1.0.0"
8
- readme = "README.md"
9
- dependencies = [
10
- "numpy"
11
- ]
12
-
13
- [project.optional-dependencies]
14
- test = [
15
- "pytest"
16
- ]
17
- gpu = [
18
- "cupy-cuda12x"
19
- ]
20
-
21
- [tool.setuptools.packages.find]
1
+ [build-system]
2
+ requires = ["setuptools>=61.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "DepthTensor"
7
+ version = "1.2.0"
8
+ readme = "README.md"
9
+ dependencies = [
10
+ "numpy"
11
+ ]
12
+
13
+ [project.optional-dependencies]
14
+ test = [
15
+ "pytest"
16
+ ]
17
+ gpu = [
18
+ "cupy-cuda12x"
19
+ ]
20
+
21
+ [tool.setuptools.packages.find]
22
22
  where = ["src"]
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from .tensor import Tensor
2
+ from .typing import *
3
+ from ._core import random
4
+ from .autodiff import differentiate
5
+
6
+ __version__ = "1.2.0"
@@ -1,4 +1,4 @@
1
- from .utils import *
2
- from .exceptions import *
3
-
1
+ from .utils import *
2
+ from .exceptions import *
3
+
4
4
  from .ops import *
@@ -0,0 +1,16 @@
1
+ CUPY_NOT_FOUND_MSG = "Module CuPy not found or installed. Please install CuPy."
2
+ DEVICE_MISMATCH_MSG = "There is a mismatch in device between two objects."
3
+ OPERAND_MISMATCH_MSG = "There is a mismatch in the type between two operands."
4
+ GRADIENT_COMPUTATION_ERROR = "An error in gradient computation has occurred."
5
+
6
+ class CuPyNotFound(RuntimeError):
7
+ ...
8
+
9
+ class DeviceMismatch(RuntimeError):
10
+ ...
11
+
12
+ class OperandMismatch(RuntimeError):
13
+ ...
14
+
15
+ class GradientComputationError(RuntimeError):
16
+ ...
@@ -1,6 +1,6 @@
1
- from .creation import *
2
- from .elementwise import *
3
- from .comparison import *
4
- from .reduction import *
5
-
1
+ from .creation import *
2
+ from .elementwise import *
3
+ from .comparison import *
4
+ from .reduction import *
5
+
6
6
  from .diff import *
@@ -0,0 +1,226 @@
1
+ from typing import (
2
+ Union,
3
+ Optional,
4
+ Tuple,
5
+ overload
6
+ )
7
+
8
+ from ...typing import (
9
+ ArrayLike,
10
+ TensorLike,
11
+ DeviceLike,
12
+ ArrayLikeBool,
13
+ Casting,
14
+ Order,
15
+ OperandLike
16
+ )
17
+
18
+ from ..exceptions import (
19
+ CuPyNotFound, CUPY_NOT_FOUND_MSG,
20
+ DeviceMismatch, DEVICE_MISMATCH_MSG,
21
+ OperandMismatch, OPERAND_MISMATCH_MSG
22
+ )
23
+
24
+ from ..utils import to_xp_array
25
+
26
+ import numpy as np
27
+ try:
28
+ import cupy as cp
29
+ except (ImportError, ModuleNotFoundError):
30
+ cp = None
31
+
32
+ ###
33
+ ###
34
+ ###
35
+
36
+ @overload
37
+ def where(
38
+ condition: OperandLike,
39
+ /,
40
+ *,
41
+ device: DeviceLike = "cpu"
42
+ ) -> Tuple[TensorLike, ...]: ...
43
+
44
+ @overload
45
+ def where(
46
+ condition: OperandLike,
47
+ x: Optional[OperandLike],
48
+ y: Optional[OperandLike],
49
+ /,
50
+ *,
51
+ device: DeviceLike = "cpu"
52
+ ) -> TensorLike: ...
53
+
54
+ def where(
55
+ condition: OperandLike,
56
+ x: Optional[OperandLike] = None,
57
+ y: Optional[OperandLike] = None,
58
+ /,
59
+ *,
60
+ device: DeviceLike = "cpu"
61
+ ) -> Union[Tuple[TensorLike, ...], TensorLike]:
62
+ from ...tensor import Tensor
63
+ #* One parameter overload
64
+ if (x is None) and (y is None):
65
+ data = to_xp_array(condition, device=device)
66
+ if device == "cpu":
67
+ result = np.where(data)
68
+ else:
69
+ if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
70
+ result = cp.where(data)
71
+ return tuple([Tensor(array, device=device) for array in result])
72
+ elif x is not None and y is not None:
73
+ data = to_xp_array(condition, device=device)
74
+ x_data = to_xp_array(x, device=device)
75
+ y_data = to_xp_array(y, device=device)
76
+ if device == "cpu":
77
+ result = np.where(data, x_data, y_data)
78
+ else:
79
+ if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
80
+ result = cp.where(data, x_data, y_data)
81
+ return Tensor(result, device=device)
82
+ else:
83
+ raise ValueError("Both x and y parameters must be given.")
84
+
85
+ ###
86
+ ###
87
+ ###
88
+
89
+ def wrapper_2in_1out(
90
+ x1: OperandLike,
91
+ x2: OperandLike,
92
+ /,
93
+ out: Optional[ArrayLikeBool] = None,
94
+ *,
95
+ func_name: str,
96
+ device: DeviceLike = "cpu",
97
+ where: Union[bool, ArrayLikeBool] = True,
98
+ casting: Casting = 'same_kind',
99
+ order: Order = 'K',
100
+ dtype: None = None,
101
+ subok: bool = True
102
+ ) -> TensorLike:
103
+ from ...tensor import Tensor
104
+ if isinstance(x1, Tensor) and isinstance(x2, Tensor):
105
+ if not x1.is_device(x2.device):
106
+ raise DeviceMismatch(DEVICE_MISMATCH_MSG)
107
+ else:
108
+ 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
+ #* Either tensor-tensor op or array-array op.
114
+
115
+ #* If its tensor-tensor op, device is decided by x1.device, else, its by the device argument.
116
+ if is_tensor_op and isinstance(x1, Tensor):
117
+ device_op = x1.device
118
+ else:
119
+ device_op = device
120
+
121
+ x1, x2 = to_xp_array(x1, device=device_op), to_xp_array(x2, device=device_op)
122
+ if device_op == "cpu":
123
+ y = getattr(np, func_name)(x1, x2, out=out, dtype=dtype, where=where, casting=casting, order=order, subok=subok)
124
+ else:
125
+ if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
126
+ y = getattr(cp, func_name)(x1, x2, out=out, dtype=dtype, casting=casting)
127
+ return Tensor(y, device=device_op)
128
+
129
+ def equal(
130
+ x1: OperandLike,
131
+ x2: OperandLike,
132
+ /,
133
+ out: Optional[ArrayLikeBool] = None,
134
+ *,
135
+ device: DeviceLike = "cpu",
136
+ where: Union[bool, ArrayLikeBool] = True,
137
+ casting: Casting = 'same_kind',
138
+ order: Order = 'K',
139
+ dtype: None = None,
140
+ subok: bool = True
141
+ ) -> TensorLike:
142
+ return wrapper_2in_1out(x1, x2, out=out, func_name="equal", device=device, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
143
+
144
+ def not_equal(
145
+ x1: OperandLike,
146
+ x2: OperandLike,
147
+ /,
148
+ out: Optional[ArrayLikeBool] = None,
149
+ *,
150
+ device: DeviceLike = "cpu",
151
+ where: Union[bool, ArrayLikeBool] = True,
152
+ casting: Casting = 'same_kind',
153
+ order: Order = 'K',
154
+ dtype: None = None,
155
+ subok: bool = True
156
+ ) -> TensorLike:
157
+ return wrapper_2in_1out(x1, x2, out=out, func_name="not_equal", device=device, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
158
+
159
+ def greater(
160
+ x1: OperandLike,
161
+ x2: OperandLike,
162
+ /,
163
+ out: Optional[ArrayLikeBool] = None,
164
+ *,
165
+ device: DeviceLike = "cpu",
166
+ where: Union[bool, ArrayLikeBool] = True,
167
+ casting: Casting = 'same_kind',
168
+ order: Order = 'K',
169
+ dtype: None = None,
170
+ subok: bool = True
171
+ ) -> TensorLike:
172
+ return wrapper_2in_1out(x1, x2, out=out, func_name="greater", device=device, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
173
+
174
+ def greater_equal(
175
+ x1: OperandLike,
176
+ x2: OperandLike,
177
+ /,
178
+ out: Optional[ArrayLikeBool] = None,
179
+ *,
180
+ device: DeviceLike = "cpu",
181
+ where: Union[bool, ArrayLikeBool] = True,
182
+ casting: Casting = 'same_kind',
183
+ order: Order = 'K',
184
+ dtype: None = None,
185
+ subok: bool = True
186
+ ) -> TensorLike:
187
+ return wrapper_2in_1out(x1, x2, out=out, func_name="greater_equal", device=device, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
188
+
189
+ def less(
190
+ x1: OperandLike,
191
+ x2: OperandLike,
192
+ /,
193
+ out: Optional[ArrayLikeBool] = None,
194
+ *,
195
+ device: DeviceLike = "cpu",
196
+ where: Union[bool, ArrayLikeBool] = True,
197
+ casting: Casting = 'same_kind',
198
+ order: Order = 'K',
199
+ dtype: None = None,
200
+ subok: bool = True
201
+ ) -> TensorLike:
202
+ return wrapper_2in_1out(x1, x2, out=out, func_name="less", device=device, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
203
+
204
+ def less_equal(
205
+ x1: OperandLike,
206
+ x2: OperandLike,
207
+ /,
208
+ out: Optional[ArrayLikeBool] = None,
209
+ *,
210
+ device: DeviceLike = "cpu",
211
+ where: Union[bool, ArrayLikeBool] = True,
212
+ casting: Casting = 'same_kind',
213
+ order: Order = 'K',
214
+ dtype: None = None,
215
+ subok: bool = True
216
+ ) -> TensorLike:
217
+ return wrapper_2in_1out(x1, x2, out=out, func_name="less_equal", device=device, where=where, casting=casting, order=order, dtype=dtype, subok=subok)
218
+
219
+ ###
220
+ ###
221
+ ###
222
+
223
+ __all__ = [
224
+ 'where',
225
+ 'equal', 'not_equal', 'greater', 'greater_equal', 'less', 'less_equal'
226
+ ]
@@ -1,77 +1,95 @@
1
- from typing import (
2
- Optional
3
- )
4
-
5
- from ...typing import (
6
- TensorLike, DTypeLike, Order,
7
- AxisShapeLike
8
- )
9
-
10
- from ..exceptions import (
11
- CuPyNotFound, CUPY_NOT_FOUND_MSG
12
- )
13
-
14
- import numpy as np
15
- try:
16
- import cupy as cp
17
- except (ImportError, ModuleNotFoundError):
18
- cp = None
19
-
20
- ###
21
- ###
22
- ###
23
-
24
- def zeros_like(
25
- a: TensorLike,
26
- /,
27
- *,
28
- dtype: Optional[DTypeLike] = None,
29
- order: Order = 'K',
30
- subok: bool = True,
31
- shape: Optional[AxisShapeLike] = None
32
- ) -> TensorLike:
33
- from ...tensor import Tensor
34
- if a.device == "cpu":
35
- return Tensor(
36
- a.zeros_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
37
- device=a.device
38
- )
39
- else:
40
- if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
41
- return Tensor(
42
- #! As of the time writing this, CuPy does not support subok.
43
- cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
44
- device=a.device
45
- )
46
-
47
- def ones_like(
48
- a: TensorLike,
49
- /,
50
- *,
51
- dtype: Optional[DTypeLike] = None,
52
- order: Order = 'K',
53
- subok: bool = True,
54
- shape: Optional[AxisShapeLike] = None
55
- ) -> TensorLike:
56
- from ...tensor import Tensor
57
- if a.is_cpu():
58
- return Tensor(
59
- np.ones_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
60
- device=a.device
61
- )
62
- else:
63
- if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
64
- return Tensor(
65
- #! As of the time writing this, CuPy does not support subok.
66
- cp.ones_like(a, dtype=dtype, order=order, subok=None, shape=shape),
67
- device=a.device
68
- )
69
-
70
- ###
71
- ###
72
- ###
73
-
74
- __all__ = [
75
- 'zeros_like',
76
- 'ones_like'
1
+ from typing import (
2
+ Optional
3
+ )
4
+
5
+ from ...typing import (
6
+ TensorLike,
7
+ DTypeLike,
8
+ Order,
9
+ AxisShapeLike,
10
+ OperandLike,
11
+ DeviceLike
12
+ )
13
+
14
+ from ..exceptions import (
15
+ CuPyNotFound, CUPY_NOT_FOUND_MSG
16
+ )
17
+
18
+ from ..utils import to_xp_array
19
+
20
+ import numpy as np
21
+ try:
22
+ import cupy as cp
23
+ except (ImportError, ModuleNotFoundError):
24
+ cp = None
25
+
26
+ ###
27
+ ###
28
+ ###
29
+
30
+ def zeros_like(
31
+ a: OperandLike,
32
+ /,
33
+ *,
34
+ device: DeviceLike = "cpu",
35
+ dtype: Optional[DTypeLike] = None,
36
+ order: Order = 'K',
37
+ subok: bool = True,
38
+ shape: Optional[AxisShapeLike] = None
39
+ ) -> TensorLike:
40
+ from ...tensor import Tensor
41
+ if isinstance(a, Tensor):
42
+ device_op = a.device
43
+ else:
44
+ device_op = device
45
+ a = to_xp_array(a)
46
+ if device_op == "cpu":
47
+ return Tensor(
48
+ np.zeros_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
49
+ device=device_op
50
+ )
51
+ else:
52
+ if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
53
+ return Tensor(
54
+ #! As of the time writing this, CuPy does not support subok.
55
+ cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
56
+ device=device_op
57
+ )
58
+
59
+ def ones_like(
60
+ a: OperandLike,
61
+ /,
62
+ *,
63
+ device: DeviceLike = "cpu",
64
+ dtype: Optional[DTypeLike] = None,
65
+ order: Order = 'K',
66
+ subok: bool = True,
67
+ shape: Optional[AxisShapeLike] = None
68
+ ) -> TensorLike:
69
+ from ...tensor import Tensor
70
+ if isinstance(a, Tensor):
71
+ device_op = a.device
72
+ else:
73
+ device_op = device
74
+ a = to_xp_array(a)
75
+ if device_op == "cpu":
76
+ return Tensor(
77
+ np.ones_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
78
+ device=device_op
79
+ )
80
+ else:
81
+ if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
82
+ return Tensor(
83
+ #! As of the time writing this, CuPy does not support subok.
84
+ cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
85
+ device=device_op
86
+ )
87
+
88
+ ###
89
+ ###
90
+ ###
91
+
92
+ __all__ = [
93
+ 'zeros_like',
94
+ 'ones_like'
77
95
  ]