DepthTensor 1.0.0__tar.gz → 1.1.2__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.0.0 → depthtensor-1.1.2}/LICENSE +20 -20
- {depthtensor-1.0.0/src/DepthTensor.egg-info → depthtensor-1.1.2}/PKG-INFO +26 -26
- {depthtensor-1.0.0 → depthtensor-1.1.2}/README.md +13 -13
- {depthtensor-1.0.0 → depthtensor-1.1.2}/pyproject.toml +21 -21
- {depthtensor-1.0.0 → depthtensor-1.1.2}/setup.cfg +4 -4
- depthtensor-1.1.2/src/DepthTensor/__init__.py +6 -0
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/__init__.py +3 -3
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/exceptions.py +11 -7
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/ops/__init__.py +5 -5
- depthtensor-1.1.2/src/DepthTensor/_core/ops/comparison.py +225 -0
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/ops/creation.py +76 -76
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/ops/diff.py +112 -87
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/ops/elementwise.py +355 -205
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/ops/reduction.py +95 -75
- depthtensor-1.1.2/src/DepthTensor/_core/random/__init__.py +1 -0
- depthtensor-1.1.2/src/DepthTensor/_core/random/generator.py +117 -0
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/_core/utils.py +90 -90
- depthtensor-1.1.2/src/DepthTensor/autodiff.py +45 -0
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/tensor.py +675 -449
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor/typing.py +39 -39
- {depthtensor-1.0.0 → depthtensor-1.1.2/src/DepthTensor.egg-info}/PKG-INFO +26 -26
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor.egg-info/SOURCES.txt +3 -0
- depthtensor-1.1.2/src/example/example.py +7 -0
- {depthtensor-1.0.0 → depthtensor-1.1.2}/tests/test_tensor.py +48 -48
- depthtensor-1.0.0/src/DepthTensor/__init__.py +0 -4
- depthtensor-1.0.0/src/DepthTensor/_core/ops/comparison.py +0 -109
- depthtensor-1.0.0/src/example/example.py +0 -10
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
- {depthtensor-1.0.0 → depthtensor-1.1.2}/src/DepthTensor.egg-info/requires.txt +0 -0
- {depthtensor-1.0.0 → depthtensor-1.1.2}/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.
|
|
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.1.2
|
|
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.
|
|
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.1.2"
|
|
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
|
+
|
|
@@ -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 *
|
|
@@ -1,8 +1,12 @@
|
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
GRADIENT_COMPUTATION_ERROR = "An error in gradient computation has occurred."
|
|
4
|
+
|
|
5
|
+
class CuPyNotFound(RuntimeError):
|
|
6
|
+
...
|
|
7
|
+
|
|
8
|
+
class DeviceMismatch(RuntimeError):
|
|
9
|
+
...
|
|
10
|
+
|
|
11
|
+
class GradientComputationError(RuntimeError):
|
|
8
12
|
...
|
|
@@ -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,225 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
Union,
|
|
3
|
+
Optional,
|
|
4
|
+
Tuple,
|
|
5
|
+
overload,
|
|
6
|
+
Callable
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
from ...typing import (
|
|
10
|
+
ArrayLike,
|
|
11
|
+
TensorLike,
|
|
12
|
+
DeviceLike,
|
|
13
|
+
ArrayLikeBool,
|
|
14
|
+
Casting,
|
|
15
|
+
Order
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
from ..exceptions import (
|
|
19
|
+
CuPyNotFound, CUPY_NOT_FOUND_MSG,
|
|
20
|
+
DeviceMismatch, DEVICE_MISMATCH_MSG
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
import numpy as np
|
|
24
|
+
try:
|
|
25
|
+
import cupy as cp
|
|
26
|
+
except (ImportError, ModuleNotFoundError):
|
|
27
|
+
cp = None
|
|
28
|
+
|
|
29
|
+
###
|
|
30
|
+
###
|
|
31
|
+
###
|
|
32
|
+
|
|
33
|
+
@overload
|
|
34
|
+
def where(
|
|
35
|
+
condition: Union[ArrayLike, TensorLike],
|
|
36
|
+
/
|
|
37
|
+
) -> Tuple[TensorLike, ...]: ...
|
|
38
|
+
|
|
39
|
+
@overload
|
|
40
|
+
def where(
|
|
41
|
+
condition: Union[ArrayLike, TensorLike],
|
|
42
|
+
x: Optional[Union[ArrayLike, TensorLike]],
|
|
43
|
+
y: Optional[Union[ArrayLike, TensorLike]],
|
|
44
|
+
/,
|
|
45
|
+
*,
|
|
46
|
+
device: DeviceLike = "cpu"
|
|
47
|
+
) -> TensorLike: ...
|
|
48
|
+
|
|
49
|
+
def where(
|
|
50
|
+
condition: Union[ArrayLike, TensorLike],
|
|
51
|
+
x: Optional[Union[ArrayLike, TensorLike]] = None,
|
|
52
|
+
y: Optional[Union[ArrayLike, TensorLike]] = None,
|
|
53
|
+
/,
|
|
54
|
+
*,
|
|
55
|
+
device: DeviceLike = "cpu"
|
|
56
|
+
) -> Union[Tuple[TensorLike, ...], TensorLike]:
|
|
57
|
+
from ...tensor import Tensor
|
|
58
|
+
#* One parameter overload
|
|
59
|
+
if x is None and y is None:
|
|
60
|
+
if isinstance(condition, TensorLike):
|
|
61
|
+
data = condition.data
|
|
62
|
+
else:
|
|
63
|
+
if device == "cpu":
|
|
64
|
+
data = np.asarray(condition)
|
|
65
|
+
else:
|
|
66
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
67
|
+
data = cp.asarray(condition)
|
|
68
|
+
if device == "cpu":
|
|
69
|
+
result = np.where(data)
|
|
70
|
+
else:
|
|
71
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
72
|
+
result = cp.where(data)
|
|
73
|
+
return tuple([Tensor(array, device=device) for array in result])
|
|
74
|
+
elif x is not None and y is not None:
|
|
75
|
+
if isinstance(condition, TensorLike):
|
|
76
|
+
data = condition.data
|
|
77
|
+
else:
|
|
78
|
+
if device == "cpu":
|
|
79
|
+
data = np.asarray(condition)
|
|
80
|
+
else:
|
|
81
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
82
|
+
data = cp.asarray(condition)
|
|
83
|
+
if isinstance(x, TensorLike):
|
|
84
|
+
x_data = x.data
|
|
85
|
+
else:
|
|
86
|
+
if device == "cpu":
|
|
87
|
+
x_data = np.asarray(x)
|
|
88
|
+
else:
|
|
89
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
90
|
+
x_data = cp.asarray(x)
|
|
91
|
+
if isinstance(y, TensorLike):
|
|
92
|
+
y_data = y.data
|
|
93
|
+
else:
|
|
94
|
+
if device == "cpu":
|
|
95
|
+
y_data = np.asarray(y)
|
|
96
|
+
else:
|
|
97
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
98
|
+
y_data = cp.asarray(y)
|
|
99
|
+
if device == "cpu":
|
|
100
|
+
result = np.where(data, x_data, y_data)
|
|
101
|
+
else:
|
|
102
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
103
|
+
result = cp.where(data, x_data, y_data)
|
|
104
|
+
return Tensor(result, device=device)
|
|
105
|
+
else:
|
|
106
|
+
raise ValueError("Both x and y parameters must be given.")
|
|
107
|
+
|
|
108
|
+
###
|
|
109
|
+
###
|
|
110
|
+
###
|
|
111
|
+
|
|
112
|
+
def comparison_ufunc(
|
|
113
|
+
x1: TensorLike,
|
|
114
|
+
x2: TensorLike,
|
|
115
|
+
/,
|
|
116
|
+
out: Optional[ArrayLikeBool] = None,
|
|
117
|
+
*,
|
|
118
|
+
func_name: str,
|
|
119
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
120
|
+
casting: Casting = 'same_kind',
|
|
121
|
+
order: Order = 'K',
|
|
122
|
+
dtype: None = None,
|
|
123
|
+
subok: bool = True
|
|
124
|
+
) -> TensorLike:
|
|
125
|
+
from ...tensor import Tensor
|
|
126
|
+
if not x1.is_device(x2.device): raise DeviceMismatch(DEVICE_MISMATCH_MSG)
|
|
127
|
+
if x1.is_cpu():
|
|
128
|
+
y = getattr(np, func_name)(x1.data, x2.data, out=out, dtype=dtype, where=where, casting=casting, order=order, subok=subok)
|
|
129
|
+
else:
|
|
130
|
+
if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
131
|
+
y = getattr(cp, func_name)(x1.data, x2.data, out=out, dtype=dtype, casting=casting)
|
|
132
|
+
return Tensor(y, device=x1.device)
|
|
133
|
+
|
|
134
|
+
def equal(
|
|
135
|
+
x1: TensorLike,
|
|
136
|
+
x2: TensorLike,
|
|
137
|
+
/,
|
|
138
|
+
out: Optional[ArrayLikeBool] = None,
|
|
139
|
+
*,
|
|
140
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
141
|
+
casting: Casting = 'same_kind',
|
|
142
|
+
order: Order = 'K',
|
|
143
|
+
dtype: None = None,
|
|
144
|
+
subok: bool = True
|
|
145
|
+
) -> TensorLike:
|
|
146
|
+
return comparison_ufunc(x1, x2, out=out, func_name="equal", where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
147
|
+
|
|
148
|
+
def not_equal(
|
|
149
|
+
x1: TensorLike,
|
|
150
|
+
x2: TensorLike,
|
|
151
|
+
/,
|
|
152
|
+
out: Optional[ArrayLikeBool] = None,
|
|
153
|
+
*,
|
|
154
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
155
|
+
casting: Casting = 'same_kind',
|
|
156
|
+
order: Order = 'K',
|
|
157
|
+
dtype: None = None,
|
|
158
|
+
subok: bool = True
|
|
159
|
+
) -> TensorLike:
|
|
160
|
+
return comparison_ufunc(x1, x2, out=out, func_name="not_equal", where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
161
|
+
|
|
162
|
+
def greater(
|
|
163
|
+
x1: TensorLike,
|
|
164
|
+
x2: TensorLike,
|
|
165
|
+
/,
|
|
166
|
+
out: Optional[ArrayLikeBool] = None,
|
|
167
|
+
*,
|
|
168
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
169
|
+
casting: Casting = 'same_kind',
|
|
170
|
+
order: Order = 'K',
|
|
171
|
+
dtype: None = None,
|
|
172
|
+
subok: bool = True
|
|
173
|
+
) -> TensorLike:
|
|
174
|
+
return comparison_ufunc(x1, x2, out=out, func_name="greater", where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
175
|
+
|
|
176
|
+
def greater_equal(
|
|
177
|
+
x1: TensorLike,
|
|
178
|
+
x2: TensorLike,
|
|
179
|
+
/,
|
|
180
|
+
out: Optional[ArrayLikeBool] = None,
|
|
181
|
+
*,
|
|
182
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
183
|
+
casting: Casting = 'same_kind',
|
|
184
|
+
order: Order = 'K',
|
|
185
|
+
dtype: None = None,
|
|
186
|
+
subok: bool = True
|
|
187
|
+
) -> TensorLike:
|
|
188
|
+
return comparison_ufunc(x1, x2, out=out, func_name="greater_equal", where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
189
|
+
|
|
190
|
+
def less(
|
|
191
|
+
x1: TensorLike,
|
|
192
|
+
x2: TensorLike,
|
|
193
|
+
/,
|
|
194
|
+
out: Optional[ArrayLikeBool] = None,
|
|
195
|
+
*,
|
|
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 comparison_ufunc(x1, x2, out=out, func_name="less", where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
203
|
+
|
|
204
|
+
def less_equal(
|
|
205
|
+
x1: TensorLike,
|
|
206
|
+
x2: TensorLike,
|
|
207
|
+
/,
|
|
208
|
+
out: Optional[ArrayLikeBool] = None,
|
|
209
|
+
*,
|
|
210
|
+
where: Union[bool, ArrayLikeBool] = True,
|
|
211
|
+
casting: Casting = 'same_kind',
|
|
212
|
+
order: Order = 'K',
|
|
213
|
+
dtype: None = None,
|
|
214
|
+
subok: bool = True
|
|
215
|
+
) -> TensorLike:
|
|
216
|
+
return comparison_ufunc(x1, x2, out=out, func_name="less_equal", where=where, casting=casting, order=order, dtype=dtype, subok=subok)
|
|
217
|
+
|
|
218
|
+
###
|
|
219
|
+
###
|
|
220
|
+
###
|
|
221
|
+
|
|
222
|
+
__all__ = [
|
|
223
|
+
'where',
|
|
224
|
+
'equal', 'not_equal', 'greater', 'greater_equal', 'less', 'less_equal'
|
|
225
|
+
]
|
|
@@ -1,77 +1,77 @@
|
|
|
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, 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'
|
|
77
77
|
]
|