DepthTensor 2.1.0__tar.gz → 2.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.
- {depthtensor-2.1.0/src/DepthTensor.egg-info → depthtensor-2.2.0}/PKG-INFO +1 -1
- {depthtensor-2.1.0 → depthtensor-2.2.0}/pyproject.toml +1 -1
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/__init__.py +1 -1
- depthtensor-2.2.0/src/DepthTensor/_core/ops/creation.py +126 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/tensor.py +9 -1
- {depthtensor-2.1.0 → depthtensor-2.2.0/src/DepthTensor.egg-info}/PKG-INFO +1 -1
- depthtensor-2.1.0/src/DepthTensor/_core/ops/creation.py +0 -89
- {depthtensor-2.1.0 → depthtensor-2.2.0}/LICENSE +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/README.md +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/setup.cfg +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/__init__.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/exceptions.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/ops/__init__.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/ops/comparison.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/ops/diff.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/ops/elementwise.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/ops/reduction.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/random/__init__.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/random/generator.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/_core/utils.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/autodiff.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor/typing.py +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor.egg-info/SOURCES.txt +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor.egg-info/requires.txt +0 -0
- {depthtensor-2.1.0 → depthtensor-2.2.0}/src/DepthTensor.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from typing import Optional, Literal, Union
|
|
2
|
+
|
|
3
|
+
from ...typing import (
|
|
4
|
+
TensorLike,
|
|
5
|
+
DTypeLike,
|
|
6
|
+
Order,
|
|
7
|
+
AxisLike,
|
|
8
|
+
OperandLike,
|
|
9
|
+
DeviceLike,
|
|
10
|
+
ShapeLike,
|
|
11
|
+
NDArrayLike,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from ..exceptions import CuPyNotFound, CUPY_NOT_FOUND_MSG
|
|
15
|
+
|
|
16
|
+
from ..utils import to_xp_array, get_device
|
|
17
|
+
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
import cupy as cp
|
|
22
|
+
except (ImportError, ModuleNotFoundError):
|
|
23
|
+
cp = None
|
|
24
|
+
|
|
25
|
+
###
|
|
26
|
+
###
|
|
27
|
+
###
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def zeros_like(
|
|
31
|
+
a: OperandLike,
|
|
32
|
+
/,
|
|
33
|
+
*,
|
|
34
|
+
device: Optional[DeviceLike] = None,
|
|
35
|
+
requires_grad: bool = False,
|
|
36
|
+
dtype: Optional[DTypeLike] = None,
|
|
37
|
+
order: Order = "K",
|
|
38
|
+
subok: bool = True,
|
|
39
|
+
shape: Optional[AxisLike] = None,
|
|
40
|
+
) -> TensorLike:
|
|
41
|
+
from ...tensor import Tensor
|
|
42
|
+
|
|
43
|
+
if device is None:
|
|
44
|
+
device_op = get_device(a)
|
|
45
|
+
else:
|
|
46
|
+
device_op = device
|
|
47
|
+
a = to_xp_array(a)
|
|
48
|
+
if device_op == "cpu":
|
|
49
|
+
y = np.zeros_like(a, dtype=dtype, order=order, subok=subok, shape=shape)
|
|
50
|
+
else:
|
|
51
|
+
if cp is None:
|
|
52
|
+
raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
53
|
+
y = cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape)
|
|
54
|
+
return Tensor(y, requires_grad=requires_grad)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def ones_like(
|
|
58
|
+
a: OperandLike,
|
|
59
|
+
/,
|
|
60
|
+
*,
|
|
61
|
+
device: Optional[DeviceLike] = None,
|
|
62
|
+
requires_grad: bool = False,
|
|
63
|
+
dtype: Optional[DTypeLike] = None,
|
|
64
|
+
order: Order = "K",
|
|
65
|
+
subok: bool = True,
|
|
66
|
+
shape: Optional[AxisLike] = None,
|
|
67
|
+
) -> TensorLike:
|
|
68
|
+
from ...tensor import Tensor
|
|
69
|
+
|
|
70
|
+
if device is None:
|
|
71
|
+
device_op = get_device(a)
|
|
72
|
+
else:
|
|
73
|
+
device_op = device
|
|
74
|
+
a = to_xp_array(a)
|
|
75
|
+
if device_op == "cpu":
|
|
76
|
+
y = np.ones_like(a, dtype=dtype, order=order, subok=subok, shape=shape)
|
|
77
|
+
else:
|
|
78
|
+
if cp is None:
|
|
79
|
+
raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
80
|
+
y = cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape)
|
|
81
|
+
return Tensor(y, requires_grad=requires_grad)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def zeros(
|
|
85
|
+
shape: ShapeLike,
|
|
86
|
+
dtype: DTypeLike = float,
|
|
87
|
+
order: Literal["C", "F"] = "C",
|
|
88
|
+
*,
|
|
89
|
+
device: DeviceLike = "cpu",
|
|
90
|
+
requires_grad: bool = False,
|
|
91
|
+
) -> TensorLike:
|
|
92
|
+
from ...tensor import Tensor
|
|
93
|
+
|
|
94
|
+
if device == "cpu":
|
|
95
|
+
y = np.zeros(shape=shape, dtype=dtype, order=order)
|
|
96
|
+
else:
|
|
97
|
+
if cp is None:
|
|
98
|
+
raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
99
|
+
y = cp.zeros(shape=shape, dtype=dtype, order=order)
|
|
100
|
+
return Tensor(y, requires_grad=requires_grad)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def ones(
|
|
104
|
+
shape: ShapeLike,
|
|
105
|
+
dtype: DTypeLike = float,
|
|
106
|
+
order: Literal["C", "F"] = "C",
|
|
107
|
+
*,
|
|
108
|
+
device: DeviceLike = "cpu",
|
|
109
|
+
requires_grad: bool = False,
|
|
110
|
+
) -> TensorLike:
|
|
111
|
+
from ...tensor import Tensor
|
|
112
|
+
|
|
113
|
+
if device == "cpu":
|
|
114
|
+
y = np.ones(shape=shape, dtype=dtype, order=order)
|
|
115
|
+
else:
|
|
116
|
+
if cp is None:
|
|
117
|
+
raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
118
|
+
y = cp.ones(shape=shape, dtype=dtype, order=order)
|
|
119
|
+
return Tensor(y, requires_grad=requires_grad)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
###
|
|
123
|
+
###
|
|
124
|
+
###
|
|
125
|
+
|
|
126
|
+
__all__ = ["zeros_like", "ones_like", "zeros", "ones"]
|
|
@@ -92,6 +92,12 @@ allowed_dtype_kind = "uifb"
|
|
|
92
92
|
###
|
|
93
93
|
|
|
94
94
|
|
|
95
|
+
def is_list_of_type(list_obj, type_obj) -> bool:
|
|
96
|
+
if not isinstance(list_obj, list):
|
|
97
|
+
return False
|
|
98
|
+
return all(isinstance(x, type_obj) for x in list_obj)
|
|
99
|
+
|
|
100
|
+
|
|
95
101
|
class Tensor:
|
|
96
102
|
data: NDArrayLike
|
|
97
103
|
device: DeviceLike
|
|
@@ -100,7 +106,7 @@ class Tensor:
|
|
|
100
106
|
|
|
101
107
|
def __init__(
|
|
102
108
|
self,
|
|
103
|
-
obj: OperandLike,
|
|
109
|
+
obj: Union[OperandLike, List[NDArrayLike]],
|
|
104
110
|
/,
|
|
105
111
|
*,
|
|
106
112
|
dtype: Optional[DTypeLike] = None,
|
|
@@ -131,6 +137,8 @@ class Tensor:
|
|
|
131
137
|
raise TypeError("Expected a numerical CuPy array.")
|
|
132
138
|
elif isinstance(obj, Tensor):
|
|
133
139
|
self.data = xp_array_to_device(obj.data, self.device)
|
|
140
|
+
elif is_list_of_type(obj, Tensor):
|
|
141
|
+
self.data = [xp_array_to_device(t) for t in obj] # type: ignore
|
|
134
142
|
else:
|
|
135
143
|
self.data = xp_array_to_device(
|
|
136
144
|
to_xp_array(obj, self.device), self.device
|
|
@@ -1,89 +0,0 @@
|
|
|
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
|
-
requires_grad=requires_grad,
|
|
43
|
-
)
|
|
44
|
-
else:
|
|
45
|
-
if cp is None:
|
|
46
|
-
raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
47
|
-
return Tensor(
|
|
48
|
-
cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
|
|
49
|
-
requires_grad=requires_grad,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def ones_like(
|
|
54
|
-
a: OperandLike,
|
|
55
|
-
/,
|
|
56
|
-
*,
|
|
57
|
-
device: Optional[DeviceLike] = None,
|
|
58
|
-
requires_grad: bool = False,
|
|
59
|
-
dtype: Optional[DTypeLike] = None,
|
|
60
|
-
order: Order = "K",
|
|
61
|
-
subok: bool = True,
|
|
62
|
-
shape: Optional[AxisLike] = None,
|
|
63
|
-
) -> TensorLike:
|
|
64
|
-
from ...tensor import Tensor
|
|
65
|
-
|
|
66
|
-
if device is None:
|
|
67
|
-
device_op = get_device(a)
|
|
68
|
-
else:
|
|
69
|
-
device_op = device
|
|
70
|
-
a = to_xp_array(a)
|
|
71
|
-
if device_op == "cpu":
|
|
72
|
-
return Tensor(
|
|
73
|
-
np.ones_like(a, dtype=dtype, order=order, subok=subok, shape=shape),
|
|
74
|
-
requires_grad=requires_grad,
|
|
75
|
-
)
|
|
76
|
-
else:
|
|
77
|
-
if cp is None:
|
|
78
|
-
raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
|
|
79
|
-
return Tensor(
|
|
80
|
-
cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
|
|
81
|
-
requires_grad=requires_grad,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
###
|
|
86
|
-
###
|
|
87
|
-
###
|
|
88
|
-
|
|
89
|
-
__all__ = ["zeros_like", "ones_like"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|