DepthTensor 1.10.0__tar.gz → 1.11.1__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 (29) hide show
  1. {depthtensor-1.10.0/src/DepthTensor.egg-info → depthtensor-1.11.1}/PKG-INFO +1 -1
  2. {depthtensor-1.10.0 → depthtensor-1.11.1}/pyproject.toml +1 -1
  3. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/__init__.py +1 -1
  4. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/ops/comparison.py +15 -15
  5. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/ops/creation.py +3 -5
  6. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/ops/diff.py +5 -2
  7. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/ops/elementwise.py +100 -64
  8. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/ops/reduction.py +13 -11
  9. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/utils.py +21 -5
  10. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/tensor.py +115 -68
  11. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/typing.py +24 -24
  12. {depthtensor-1.10.0 → depthtensor-1.11.1/src/DepthTensor.egg-info}/PKG-INFO +1 -1
  13. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor.egg-info/SOURCES.txt +1 -0
  14. depthtensor-1.11.1/src/example/example.py +25 -0
  15. depthtensor-1.11.1/src/example/test.py +12 -0
  16. depthtensor-1.10.0/src/example/example.py +0 -26
  17. {depthtensor-1.10.0 → depthtensor-1.11.1}/LICENSE +0 -0
  18. {depthtensor-1.10.0 → depthtensor-1.11.1}/README.md +0 -0
  19. {depthtensor-1.10.0 → depthtensor-1.11.1}/setup.cfg +0 -0
  20. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/__init__.py +0 -0
  21. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/exceptions.py +0 -0
  22. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/ops/__init__.py +0 -0
  23. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/random/__init__.py +0 -0
  24. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/_core/random/generator.py +0 -0
  25. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor/autodiff.py +0 -0
  26. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor.egg-info/dependency_links.txt +0 -0
  27. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor.egg-info/requires.txt +0 -0
  28. {depthtensor-1.10.0 → depthtensor-1.11.1}/src/DepthTensor.egg-info/top_level.txt +0 -0
  29. {depthtensor-1.10.0 → depthtensor-1.11.1}/tests/test_tensor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DepthTensor
3
- Version: 1.10.0
3
+ Version: 1.11.1
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.10.0"
7
+ version = "1.11.1"
8
8
  readme = "README.md"
9
9
  dependencies = [
10
10
  "numpy"
@@ -4,4 +4,4 @@ from ._core import random, create_2in_1out, create_1in_1out
4
4
  from ._core.exceptions import *
5
5
  from .autodiff import differentiate
6
6
 
7
- __version__ = "1.10.0"
7
+ __version__ = "1.11.1"
@@ -8,7 +8,7 @@ from typing import (
8
8
  from ...typing import (
9
9
  TensorLike,
10
10
  DeviceLike,
11
- ArrayLikeBool,
11
+ NDArrayLikeBool,
12
12
  Casting,
13
13
  Order,
14
14
  OperandLike
@@ -91,11 +91,11 @@ def wrapper_2in_1out(
91
91
  x1: OperandLike,
92
92
  x2: OperandLike,
93
93
  /,
94
- out: Optional[ArrayLikeBool] = None,
94
+ out: Optional[NDArrayLikeBool] = None,
95
95
  *,
96
96
  func_name: str,
97
97
  device: DeviceLike = "cpu",
98
- where: Union[bool, ArrayLikeBool] = True,
98
+ where: Union[bool, NDArrayLikeBool] = True,
99
99
  casting: Casting = 'same_kind',
100
100
  order: Order = 'K',
101
101
  dtype: None = None,
@@ -128,10 +128,10 @@ def equal(
128
128
  x1: OperandLike,
129
129
  x2: OperandLike,
130
130
  /,
131
- out: Optional[ArrayLikeBool] = None,
131
+ out: Optional[NDArrayLikeBool] = None,
132
132
  *,
133
133
  device: DeviceLike = "cpu",
134
- where: Union[bool, ArrayLikeBool] = True,
134
+ where: Union[bool, NDArrayLikeBool] = True,
135
135
  casting: Casting = 'same_kind',
136
136
  order: Order = 'K',
137
137
  dtype: None = None,
@@ -143,10 +143,10 @@ def not_equal(
143
143
  x1: OperandLike,
144
144
  x2: OperandLike,
145
145
  /,
146
- out: Optional[ArrayLikeBool] = None,
146
+ out: Optional[NDArrayLikeBool] = None,
147
147
  *,
148
148
  device: DeviceLike = "cpu",
149
- where: Union[bool, ArrayLikeBool] = True,
149
+ where: Union[bool, NDArrayLikeBool] = True,
150
150
  casting: Casting = 'same_kind',
151
151
  order: Order = 'K',
152
152
  dtype: None = None,
@@ -158,10 +158,10 @@ def greater(
158
158
  x1: OperandLike,
159
159
  x2: OperandLike,
160
160
  /,
161
- out: Optional[ArrayLikeBool] = None,
161
+ out: Optional[NDArrayLikeBool] = None,
162
162
  *,
163
163
  device: DeviceLike = "cpu",
164
- where: Union[bool, ArrayLikeBool] = True,
164
+ where: Union[bool, NDArrayLikeBool] = True,
165
165
  casting: Casting = 'same_kind',
166
166
  order: Order = 'K',
167
167
  dtype: None = None,
@@ -173,10 +173,10 @@ def greater_equal(
173
173
  x1: OperandLike,
174
174
  x2: OperandLike,
175
175
  /,
176
- out: Optional[ArrayLikeBool] = None,
176
+ out: Optional[NDArrayLikeBool] = None,
177
177
  *,
178
178
  device: DeviceLike = "cpu",
179
- where: Union[bool, ArrayLikeBool] = True,
179
+ where: Union[bool, NDArrayLikeBool] = True,
180
180
  casting: Casting = 'same_kind',
181
181
  order: Order = 'K',
182
182
  dtype: None = None,
@@ -188,10 +188,10 @@ def less(
188
188
  x1: OperandLike,
189
189
  x2: OperandLike,
190
190
  /,
191
- out: Optional[ArrayLikeBool] = None,
191
+ out: Optional[NDArrayLikeBool] = None,
192
192
  *,
193
193
  device: DeviceLike = "cpu",
194
- where: Union[bool, ArrayLikeBool] = True,
194
+ where: Union[bool, NDArrayLikeBool] = True,
195
195
  casting: Casting = 'same_kind',
196
196
  order: Order = 'K',
197
197
  dtype: None = None,
@@ -203,10 +203,10 @@ def less_equal(
203
203
  x1: OperandLike,
204
204
  x2: OperandLike,
205
205
  /,
206
- out: Optional[ArrayLikeBool] = None,
206
+ out: Optional[NDArrayLikeBool] = None,
207
207
  *,
208
208
  device: DeviceLike = "cpu",
209
- where: Union[bool, ArrayLikeBool] = True,
209
+ where: Union[bool, NDArrayLikeBool] = True,
210
210
  casting: Casting = 'same_kind',
211
211
  order: Order = 'K',
212
212
  dtype: None = None,
@@ -6,7 +6,7 @@ from ...typing import (
6
6
  TensorLike,
7
7
  DTypeLike,
8
8
  Order,
9
- AxisShapeLike,
9
+ AxisLike,
10
10
  OperandLike,
11
11
  DeviceLike
12
12
  )
@@ -36,7 +36,7 @@ def zeros_like(
36
36
  dtype: Optional[DTypeLike] = None,
37
37
  order: Order = 'K',
38
38
  subok: bool = True,
39
- shape: Optional[AxisShapeLike] = None
39
+ shape: Optional[AxisLike] = None
40
40
  ) -> TensorLike:
41
41
  from ...tensor import Tensor
42
42
  if isinstance(a, Tensor):
@@ -52,7 +52,6 @@ def zeros_like(
52
52
  else:
53
53
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
54
54
  return Tensor(
55
- #! As of the time writing this, CuPy does not support subok.
56
55
  cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
57
56
  device=device_op, requires_grad=requires_grad
58
57
  )
@@ -66,7 +65,7 @@ def ones_like(
66
65
  dtype: Optional[DTypeLike] = None,
67
66
  order: Order = 'K',
68
67
  subok: bool = True,
69
- shape: Optional[AxisShapeLike] = None
68
+ shape: Optional[AxisLike] = None
70
69
  ) -> TensorLike:
71
70
  from ...tensor import Tensor
72
71
  if isinstance(a, Tensor):
@@ -82,7 +81,6 @@ def ones_like(
82
81
  else:
83
82
  if cp is None: raise CuPyNotFound(CUPY_NOT_FOUND_MSG)
84
83
  return Tensor(
85
- #! As of the time writing this, CuPy does not support subok.
86
84
  cp.zeros_like(a, dtype=dtype, order=order, subok=None, shape=shape),
87
85
  device=device_op, requires_grad=requires_grad
88
86
  )
@@ -19,7 +19,7 @@ except (ImportError, ModuleNotFoundError):
19
19
  cp = None
20
20
 
21
21
  ###
22
- ### Arithmetics
22
+ ###
23
23
  ###
24
24
 
25
25
  def wrapper_2in_diff(result: TensorLike, x1: OperandLike, x2: OperandLike, callback_x1: Callable, callback_x2: Callable) -> TensorLike:
@@ -44,6 +44,10 @@ def wrapper_1in_diff(result: TensorLike, x: OperandLike, callback_x1: Callable)
44
44
  result.backward = backward
45
45
  return result
46
46
 
47
+ ###
48
+ ### Arithmetics
49
+ ###
50
+
47
51
  def add_diff(result: TensorLike, x1: OperandLike, x2: OperandLike) -> TensorLike:
48
52
  def callback_x1(shape, device, _x1, _x2):
49
53
  return sum_to_shape(result.grad, shape, device)
@@ -143,7 +147,6 @@ __all__ = [
143
147
  'negative_diff',
144
148
  'sign_diff',
145
149
  'abs_diff',
146
-
147
150
  'exp_diff',
148
151
  'sqrt_diff',
149
152
  'log_diff',
@@ -10,8 +10,8 @@ from ...typing import (
10
10
  DTypeLike,
11
11
  Casting,
12
12
  Order,
13
- ArrayLikeBool,
14
- ArrayLike,
13
+ NDArrayLikeBool,
14
+ NDArrayLike,
15
15
  OperandLike,
16
16
  DeviceLike,
17
17
  Op_2in_1out_Protocol,
@@ -28,7 +28,8 @@ from ..exceptions import (
28
28
  )
29
29
 
30
30
  from ..utils import (
31
- to_xp_array
31
+ to_xp_array,
32
+ get_device
32
33
  )
33
34
 
34
35
  import numpy as np
@@ -49,7 +50,7 @@ def create_2in_1out(
49
50
  x1: OperandLike,
50
51
  x2: OperandLike,
51
52
  *,
52
- device: DeviceLike = "cpu",
53
+ device: Optional[DeviceLike] = None,
53
54
  in_place: bool = False,
54
55
  requires_grad: bool = True,
55
56
  **kwds: Any
@@ -65,14 +66,24 @@ def create_2in_1out(
65
66
  if is_tensor_op and isinstance(x1, Tensor):
66
67
  device_op = x1.device
67
68
  else:
68
- device_op = device
69
+ if device is None:
70
+ _x1_device = get_device(x1)
71
+ if _x1_device != get_device(x2):
72
+ raise DeviceMismatch(DEVICE_MISMATCH_MSG)
73
+ device_op = _x1_device
74
+ else:
75
+ device_op = device
69
76
 
70
77
  a1, a2 = to_xp_array(x1, device=device_op), to_xp_array(x2, device=device_op)
71
- y = op(a1, a2, device=device, **kwds)
72
-
78
+ y = op(a1, a2, device=device_op, **kwds)
79
+
73
80
  if is_tensor_op and in_place and isinstance(x1, Tensor):
74
- x1.data = y
75
- return x1
81
+ if isinstance(y, Tensor):
82
+ x1.data = y.data
83
+ return x1
84
+ else:
85
+ x1.data = y
86
+ return x1
76
87
 
77
88
  y_requires_grad = False
78
89
  prev = ()
@@ -86,7 +97,13 @@ def create_2in_1out(
86
97
  else:
87
98
  prev = (x2,)
88
99
 
89
- y = Tensor(y, device=device_op, prev=prev, requires_grad=y_requires_grad and requires_grad)
100
+ if isinstance(y, Tensor):
101
+ y.to_device(device_op, in_place=True)
102
+ y.prev = prev
103
+ if y_requires_grad and requires_grad:
104
+ y.make_differentiable()
105
+ else:
106
+ y = Tensor(y, device=device_op, prev=prev, requires_grad=y_requires_grad and requires_grad)
90
107
  if diff is None:
91
108
  return y
92
109
  else:
@@ -108,7 +125,7 @@ def create_1in_1out(
108
125
  def func(
109
126
  x: OperandLike,
110
127
  *,
111
- device: DeviceLike = "cpu",
128
+ device: Optional[DeviceLike] = None,
112
129
  in_place: bool = False,
113
130
  requires_grad: bool = True,
114
131
  **kwds: Any
@@ -117,11 +134,14 @@ def create_1in_1out(
117
134
  if isinstance(x, Tensor):
118
135
  device_op = x.device
119
136
  else:
120
- device_op = device
137
+ if device is None:
138
+ device_op = get_device(x)
139
+ else:
140
+ device_op = device
121
141
 
122
142
  a = to_xp_array(x, device=device_op)
123
- y = op(a, device=device, **kwds)
124
-
143
+ y = op(a, device=device_op, **kwds)
144
+
125
145
  y_requires_grad = False
126
146
  if isinstance(x, Tensor):
127
147
  if in_place:
@@ -129,7 +149,13 @@ def create_1in_1out(
129
149
  return x
130
150
  y_requires_grad = x.requires_grad
131
151
 
132
- y = Tensor(y, device=device_op, prev=(x,), requires_grad=y_requires_grad and requires_grad)
152
+ if isinstance(y, Tensor):
153
+ y.to_device(device_op)
154
+ y.prev = (x,)
155
+ if y_requires_grad and requires_grad:
156
+ y.make_differentiable()
157
+ else:
158
+ y = Tensor(y, device=device_op, prev=(x,), requires_grad=y_requires_grad and requires_grad)
133
159
  if diff is None:
134
160
  return y
135
161
  else:
@@ -146,12 +172,12 @@ def wrapper_2in_1out(
146
172
  x1: OperandLike,
147
173
  x2: OperandLike,
148
174
  /,
149
- out: Optional[Union[np.ndarray, Any]] = None,
175
+ out: Optional[NDArrayLike] = None,
150
176
  *,
151
177
  func_name: str,
152
- device: DeviceLike = "cpu",
178
+ device: Optional[DeviceLike] = None,
153
179
  in_place: bool = False,
154
- where: Union[ArrayLikeBool, bool] = True,
180
+ where: Union[NDArrayLikeBool, bool] = True,
155
181
  casting: Casting = 'same_kind',
156
182
  order: Order = 'K',
157
183
  dtype: Optional[DTypeLike] = None,
@@ -170,7 +196,14 @@ def wrapper_2in_1out(
170
196
  if is_tensor_op and isinstance(x1, Tensor):
171
197
  device_op = x1.device
172
198
  else:
173
- device_op = device
199
+ if device is None:
200
+ _x1_device = get_device(x1)
201
+ if _x1_device != get_device(x2):
202
+ raise DeviceMismatch(DEVICE_MISMATCH_MSG)
203
+ else:
204
+ device_op = _x1_device
205
+ else:
206
+ device_op = device
174
207
 
175
208
  a1, a2 = to_xp_array(x1, device=device_op), to_xp_array(x2, device=device_op)
176
209
  if device_op == "cpu":
@@ -203,12 +236,12 @@ def wrapper_2in_1out(
203
236
  def wrapper_1in_1out(
204
237
  x: OperandLike,
205
238
  /,
206
- out: Optional[Union[np.ndarray, Any]] = None,
239
+ out: Optional[NDArrayLike] = None,
207
240
  *,
208
241
  func_name: str,
209
- device: DeviceLike = "cpu",
242
+ device: Optional[DeviceLike] = None,
210
243
  in_place: bool = False,
211
- where: Union[ArrayLikeBool, bool] = True,
244
+ where: Union[NDArrayLikeBool, bool] = True,
212
245
  casting: Casting = 'same_kind',
213
246
  order: Order = 'K',
214
247
  dtype: Optional[DTypeLike] = None,
@@ -218,7 +251,10 @@ def wrapper_1in_1out(
218
251
  if isinstance(x, Tensor):
219
252
  device_op = x.device
220
253
  else:
221
- device_op = device
254
+ if device is None:
255
+ device_op = get_device(device)
256
+ else:
257
+ device_op = device
222
258
 
223
259
  a = to_xp_array(x, device=device_op)
224
260
  if device_op:
@@ -243,11 +279,11 @@ def add(
243
279
  x1: OperandLike,
244
280
  x2: OperandLike,
245
281
  /,
246
- out: Optional[Union[np.ndarray, Any]] = None,
282
+ out: Optional[NDArrayLike] = None,
247
283
  *,
248
- device: DeviceLike = "cpu",
284
+ device: Optional[DeviceLike] = None,
249
285
  in_place: bool = False,
250
- where: Union[ArrayLikeBool, bool] = True,
286
+ where: Union[NDArrayLikeBool, bool] = True,
251
287
  casting: Casting = 'same_kind',
252
288
  order: Order = 'K',
253
289
  dtype: Optional[DTypeLike] = None,
@@ -259,11 +295,11 @@ def subtract(
259
295
  x1: OperandLike,
260
296
  x2: OperandLike,
261
297
  /,
262
- out: Optional[Union[np.ndarray, Any]] = None,
298
+ out: Optional[NDArrayLike] = None,
263
299
  *,
264
- device: DeviceLike = "cpu",
300
+ device: Optional[DeviceLike] = None,
265
301
  in_place: bool = False,
266
- where: Union[ArrayLikeBool, bool] = True,
302
+ where: Union[NDArrayLikeBool, bool] = True,
267
303
  casting: Casting = 'same_kind',
268
304
  order: Order = 'K',
269
305
  dtype: Optional[DTypeLike] = None,
@@ -275,11 +311,11 @@ def multiply(
275
311
  x1: OperandLike,
276
312
  x2: OperandLike,
277
313
  /,
278
- out: Optional[Union[np.ndarray, Any]] = None,
314
+ out: Optional[NDArrayLike] = None,
279
315
  *,
280
- device: DeviceLike = "cpu",
316
+ device: Optional[DeviceLike] = None,
281
317
  in_place: bool = False,
282
- where: Union[ArrayLikeBool, bool] = True,
318
+ where: Union[NDArrayLikeBool, bool] = True,
283
319
  casting: Casting = 'same_kind',
284
320
  order: Order = 'K',
285
321
  dtype: Optional[DTypeLike] = None,
@@ -291,9 +327,9 @@ def matmul(
291
327
  x1: OperandLike,
292
328
  x2: OperandLike,
293
329
  /,
294
- out: Optional[Union[np.ndarray, Any]] = None,
330
+ out: Optional[NDArrayLike] = None,
295
331
  *,
296
- device: DeviceLike = "cpu",
332
+ device: Optional[DeviceLike] = None,
297
333
  in_place: bool = False,
298
334
  casting: Casting = 'same_kind',
299
335
  order: Order = 'K',
@@ -306,11 +342,11 @@ def divide(
306
342
  x1: OperandLike,
307
343
  x2: OperandLike,
308
344
  /,
309
- out: Optional[Union[np.ndarray, Any]] = None,
345
+ out: Optional[NDArrayLike] = None,
310
346
  *,
311
- device: DeviceLike = "cpu",
347
+ device: Optional[DeviceLike] = None,
312
348
  in_place: bool = False,
313
- where: Union[ArrayLikeBool, bool] = True,
349
+ where: Union[NDArrayLikeBool, bool] = True,
314
350
  casting: Casting = 'same_kind',
315
351
  order: Order = 'K',
316
352
  dtype: Optional[DTypeLike] = None,
@@ -322,11 +358,11 @@ def power(
322
358
  x1: OperandLike,
323
359
  x2: OperandLike,
324
360
  /,
325
- out: Optional[Union[np.ndarray, Any]] = None,
361
+ out: Optional[NDArrayLike] = None,
326
362
  *,
327
- device: DeviceLike = "cpu",
363
+ device: Optional[DeviceLike] = None,
328
364
  in_place: bool = False,
329
- where: Union[ArrayLikeBool, bool] = True,
365
+ where: Union[NDArrayLikeBool, bool] = True,
330
366
  casting: Casting = 'same_kind',
331
367
  order: Order = 'K',
332
368
  dtype: Optional[DTypeLike] = None,
@@ -338,11 +374,11 @@ def power(
338
374
  def negative(
339
375
  x: OperandLike,
340
376
  /,
341
- out: Optional[Union[np.ndarray, Any]] = None,
377
+ out: Optional[NDArrayLike] = None,
342
378
  *,
343
- device: DeviceLike = "cpu",
379
+ device: Optional[DeviceLike] = None,
344
380
  in_place: bool = False,
345
- where: Union[ArrayLikeBool, bool] = True,
381
+ where: Union[NDArrayLikeBool, bool] = True,
346
382
  casting: Casting = 'same_kind',
347
383
  order: Order = 'K',
348
384
  dtype: Optional[DTypeLike] = None,
@@ -353,11 +389,11 @@ def negative(
353
389
  def sign(
354
390
  x: OperandLike,
355
391
  /,
356
- out: Optional[Union[np.ndarray, Any]] = None,
392
+ out: Optional[NDArrayLike] = None,
357
393
  *,
358
- device: DeviceLike = "cpu",
394
+ device: Optional[DeviceLike] = None,
359
395
  in_place: bool = False,
360
- where: Union[ArrayLikeBool, bool] = True,
396
+ where: Union[NDArrayLikeBool, bool] = True,
361
397
  casting: Casting = 'same_kind',
362
398
  order: Order = 'K',
363
399
  dtype: Optional[DTypeLike] = None,
@@ -368,11 +404,11 @@ def sign(
368
404
  def abs(
369
405
  x: OperandLike,
370
406
  /,
371
- out: Optional[Union[np.ndarray, Any]] = None,
407
+ out: Optional[NDArrayLike] = None,
372
408
  *,
373
- device: DeviceLike = "cpu",
409
+ device: Optional[DeviceLike] = None,
374
410
  in_place: bool = False,
375
- where: Union[ArrayLikeBool, bool] = True,
411
+ where: Union[NDArrayLikeBool, bool] = True,
376
412
  casting: Casting = 'same_kind',
377
413
  order: Order = 'K',
378
414
  dtype: Optional[DTypeLike] = None,
@@ -385,11 +421,11 @@ def clip(
385
421
  a_min: OperandLike,
386
422
  a_max: OperandLike,
387
423
  /,
388
- out: Optional[ArrayLike] = None,
424
+ out: Optional[NDArrayLike] = None,
389
425
  *,
390
426
  requires_grad: bool = False,
391
- device: DeviceLike = "cpu",
392
- where: Union[bool, ArrayLikeBool] = True,
427
+ device: Optional[DeviceLike] = None,
428
+ where: Union[bool, NDArrayLikeBool] = True,
393
429
  casting: Casting = 'same_kind',
394
430
  order: Order = 'K',
395
431
  dtype: Optional[DTypeLike] = None,
@@ -424,11 +460,11 @@ def clip(
424
460
  def exp(
425
461
  x: OperandLike,
426
462
  /,
427
- out: Optional[Union[np.ndarray, Any]] = None,
463
+ out: Optional[NDArrayLike] = None,
428
464
  *,
429
- device: DeviceLike = "cpu",
465
+ device: Optional[DeviceLike] = None,
430
466
  in_place: bool = False,
431
- where: Union[bool, ArrayLikeBool] = True,
467
+ where: Union[bool, NDArrayLikeBool] = True,
432
468
  casting: Casting = 'same_kind',
433
469
  order: Order = 'K',
434
470
  dtype: Optional[DTypeLike] = None,
@@ -439,11 +475,11 @@ def exp(
439
475
  def sqrt(
440
476
  x: OperandLike,
441
477
  /,
442
- out: Optional[Union[np.ndarray, Any]] = None,
478
+ out: Optional[NDArrayLike] = None,
443
479
  *,
444
- device: DeviceLike = "cpu",
480
+ device: Optional[DeviceLike] = None,
445
481
  in_place: bool = False,
446
- where: Union[bool, ArrayLikeBool] = True,
482
+ where: Union[bool, NDArrayLikeBool] = True,
447
483
  casting: Casting = 'same_kind',
448
484
  order: Order = 'K',
449
485
  dtype: Optional[DTypeLike] = None,
@@ -454,11 +490,11 @@ def sqrt(
454
490
  def log(
455
491
  x: OperandLike,
456
492
  /,
457
- out: Optional[Union[np.ndarray, Any]] = None,
493
+ out: Optional[NDArrayLike] = None,
458
494
  *,
459
- device: DeviceLike = "cpu",
495
+ device: Optional[DeviceLike] = None,
460
496
  in_place: bool = False,
461
- where: Union[bool, ArrayLikeBool] = True,
497
+ where: Union[bool, NDArrayLikeBool] = True,
462
498
  casting: Casting = 'same_kind',
463
499
  order: Order = 'K',
464
500
  dtype: Optional[DTypeLike] = None,
@@ -469,11 +505,11 @@ def log(
469
505
  def square(
470
506
  x: OperandLike,
471
507
  /,
472
- out: Optional[Union[np.ndarray, Any]] = None,
508
+ out: Optional[NDArrayLike] = None,
473
509
  *,
474
- device: DeviceLike = "cpu",
510
+ device: Optional[DeviceLike] = None,
475
511
  in_place: bool = False,
476
- where: Union[bool, ArrayLikeBool] = True,
512
+ where: Union[bool, NDArrayLikeBool] = True,
477
513
  casting: Casting = 'same_kind',
478
514
  order: Order = 'K',
479
515
  dtype: Optional[DTypeLike] = None,
@@ -6,12 +6,12 @@ from typing import (
6
6
 
7
7
  from ...typing import (
8
8
  TensorLike,
9
- ShapeLike,
10
- ArrayLikeBool,
9
+ NDArrayLike,
10
+ NDArrayLikeBool,
11
11
  Casting,
12
12
  Order,
13
13
  DTypeLike,
14
- AxisShapeLike,
14
+ AxisLike,
15
15
  OperandLike,
16
16
  DeviceLike
17
17
  )
@@ -42,12 +42,12 @@ def sum(
42
42
  *,
43
43
  device: DeviceLike = "cpu",
44
44
  requires_grad: bool = False,
45
- axis: Optional[AxisShapeLike] = None,
45
+ axis: Optional[AxisLike] = None,
46
46
  dtype: Optional[DTypeLike] = None,
47
47
  out: Optional[Union[np.ndarray, Any]] = None,
48
48
  keepdims: bool = True,
49
49
  initial: Any = _NoValue,
50
- where: Union[bool, ArrayLikeBool] = True
50
+ where: Union[bool, NDArrayLikeBool] = True
51
51
  ) -> TensorLike:
52
52
  from ...tensor import Tensor
53
53
  if isinstance(a, Tensor):
@@ -79,11 +79,11 @@ def max(
79
79
  *,
80
80
  device: DeviceLike = "cpu",
81
81
  requires_grad: bool = False,
82
- axis: Optional[ShapeLike] = None,
82
+ axis: Optional[AxisLike] = None,
83
83
  out: Optional[Union[np.ndarray, Any]] = None,
84
84
  keepdims: bool = False,
85
85
  initial: Any = _NoValue,
86
- where: Union[bool, ArrayLikeBool] = True
86
+ where: Union[bool, NDArrayLikeBool] = True
87
87
  ) -> TensorLike:
88
88
  from ...tensor import Tensor
89
89
  if isinstance(a, Tensor):
@@ -107,7 +107,7 @@ def maximum(
107
107
  *,
108
108
  device: DeviceLike = "cpu",
109
109
  requires_grad: bool = False,
110
- where: Union[bool, ArrayLikeBool] = True,
110
+ where: Union[bool, NDArrayLikeBool] = True,
111
111
  casting: Casting = 'same_kind',
112
112
  order: Order = 'K',
113
113
  dtype: Optional[DTypeLike] = None,
@@ -124,11 +124,13 @@ def maximum(
124
124
  else:
125
125
  device_op = device
126
126
 
127
- x1, x2 = to_xp_array(x1, device=device_op), to_xp_array(x2, device=device_op)
127
+ _x1: NDArrayLike = to_xp_array(x1, device=device_op)
128
+ _x2: NDArrayLike = to_xp_array(x2, device=device_op)
129
+
128
130
  if device_op == "cpu":
129
- y = np.maximum(x1, x2, out=out, dtype=dtype, where=where, casting=casting, order=order, subok=subok)
131
+ y = np.maximum(_x1, _x2, out=out, dtype=dtype, where=where, casting=casting, order=order, subok=subok)
130
132
  else:
131
- y = np.maximum(x1, x2, out=out, dtype=dtype, casting=casting)
133
+ y = np.maximum(_x1, _x2, out=out, dtype=dtype, casting=casting)
132
134
  return Tensor(y, device=device_op, requires_grad=requires_grad)
133
135
 
134
136
  ###