Skip to content

Commit 6e22482

Browse files
committed
Changed tests for tril() and triu() functions.
1 parent 76dafc1 commit 6e22482

File tree

7 files changed

+36
-38
lines changed

7 files changed

+36
-38
lines changed

dpnp/dpnp_container.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
from dpnp.dpnp_array import dpnp_array
4141
import dpnp
42-
import operator
4342

4443

4544
__all__ = [
@@ -204,19 +203,15 @@ def ones(shape,
204203

205204

206205
def tril(x1, /, *, k=0):
207-
k = operator.index(k)
208-
order = "F" if (x1.flags.f_contiguous) else "C"
209206
""""Creates `dpnp_array` as lower triangular part of an input array."""
210207
array_obj = dpt.tril(x1.get_array() if isinstance(x1, dpnp_array) else x1, k)
211-
return dpnp_array(array_obj.shape, buffer=array_obj, order=order)
208+
return dpnp_array(array_obj.shape, buffer=array_obj, order="K")
212209

213210

214211
def triu(x1, /, *, k=0):
215-
k = operator.index(k)
216-
order = "F" if (x1.flags.f_contiguous) else "C"
217212
""""Creates `dpnp_array` as upper triangular part of an input array."""
218213
array_obj = dpt.triu(x1.get_array() if isinstance(x1, dpnp_array) else x1, k)
219-
return dpnp_array(array_obj.shape, buffer=array_obj, order=order)
214+
return dpnp_array(array_obj.shape, buffer=array_obj, order="K")
220215

221216

222217
def zeros(shape,

dpnp/dpnp_iface_arraycreation.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import numpy
4444
import dpnp
45+
import operator
4546

4647
import dpnp.config as config
4748
from dpnp.dpnp_algo import *
@@ -1357,15 +1358,20 @@ def tril(x1, /, *, k=0):
13571358
13581359
"""
13591360

1361+
_k = None
1362+
try:
1363+
_k = operator.index(k)
1364+
except TypeError:
1365+
pass
1366+
13601367
if not isinstance(x1, (dpnp.ndarray, dpt.usm_ndarray)):
13611368
pass
13621369
elif x1.ndim < 2:
13631370
pass
1364-
elif not isinstance(k, int):
1365-
if not (isinstance(k, (dpnp.ndarray, dpt.usm_ndarray)) and numpy.issubdtype(k.dtype, int)):
1366-
pass
1371+
elif _k is None:
1372+
pass
13671373
else:
1368-
return dpnp_container.tril(x1, k=k)
1374+
return dpnp_container.tril(x1, k=_k)
13691375

13701376
return call_origin(numpy.tril, x1, k)
13711377

@@ -1396,15 +1402,20 @@ def triu(x1, /, *, k=0):
13961402
13971403
"""
13981404

1405+
_k = None
1406+
try:
1407+
_k = operator.index(k)
1408+
except TypeError:
1409+
pass
1410+
13991411
if not isinstance(x1, (dpnp.ndarray, dpt.usm_ndarray)):
14001412
pass
14011413
elif x1.ndim < 2:
14021414
pass
1403-
elif not isinstance(k, int):
1404-
if not (isinstance(k, (dpnp.ndarray, dpt.usm_ndarray)) and numpy.issubdtype(k.dtype, int)):
1405-
pass
1415+
elif _k is None:
1416+
pass
14061417
else:
1407-
return dpnp_container.triu(x1, k=k)
1418+
return dpnp_container.triu(x1, k=_k)
14081419

14091420
return call_origin(numpy.triu, x1, k)
14101421

tests/skipped_tests.tbl

-6
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,6 @@ tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_
430430
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_mixed_start_stop
431431
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_mixed_start_stop2
432432
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_start_stop_list
433-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_tril
434-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_tril_nega
435-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_tril_posi
436-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_triu
437-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_triu_nega
438-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_triu_posi
439433
tests/third_party/cupy/indexing_tests/test_generate.py::TestAxisConcatenator::test_AxisConcatenator_init1
440434
tests/third_party/cupy/indexing_tests/test_generate.py::TestAxisConcatenator::test_len
441435
tests/third_party/cupy/indexing_tests/test_generate.py::TestC_::test_c_1

tests/skipped_tests_gpu.tbl

-6
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_cons
190190
tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_construction_from_tuple
191191
tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_extraction_from_nested_list
192192
tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_extraction_from_nested_tuple
193-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_tril
194-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_tril_nega
195-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_tril_posi
196-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_triu
197-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_triu_nega
198-
tests/third_party/cupy/creation_tests/test_matrix.py::TestTriLowerAndUpper_param_0_{shape=(2,)}::test_triu_posi
199193

200194
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_4_{shape=(3, 3), val=(2,), wrap=True}::test_1darray
201195
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_4_{shape=(3, 3), val=(2,), wrap=True}::test_fill_diagonal

tests/test_arraycreation.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616

1717
import tempfile
18+
import operator
1819

1920

2021
@pytest.mark.parametrize("start",
@@ -258,8 +259,10 @@ def test_tri_default_dtype():
258259

259260

260261
@pytest.mark.parametrize("k",
261-
[-3, -2, -1, 0, 1, 2, 3, 4, 5],
262-
ids=['-3', '-2', '-1', '0', '1', '2', '3', '4', '5'])
262+
[-3, -2, -1, 0, 1, 2, 3, 4, 5,
263+
numpy.array(1), dpnp.array(2), dpt.asarray(3)],
264+
ids=['-3', '-2', '-1', '0', '1', '2', '3', '4', '5',
265+
'np.array(1)', 'dpnp.array(2)', 'dpt.asarray(3)'])
263266
@pytest.mark.parametrize("m",
264267
[[[0, 0], [0, 0]],
265268
[[1, 2], [1, 2]],
@@ -275,14 +278,16 @@ def test_tri_default_dtype():
275278
def test_tril(m, k, dtype):
276279
a = numpy.array(m, dtype=dtype)
277280
ia = dpnp.array(a)
278-
expected = numpy.tril(a, k=k)
281+
expected = numpy.tril(a, k=operator.index(k))
279282
result = dpnp.tril(ia, k=k)
280283
assert_array_equal(expected, result)
281284

282285

283286
@pytest.mark.parametrize("k",
284-
[-3, -2, -1, 0, 1, 2, 3, 4, 5],
285-
ids=['-3', '-2', '-1', '0', '1', '2', '3', '4', '5'])
287+
[-3, -2, -1, 0, 1, 2, 3, 4, 5,
288+
numpy.array(1), dpnp.array(2), dpt.asarray(3)],
289+
ids=['-3', '-2', '-1', '0', '1', '2', '3', '4', '5',
290+
'np.array(1)', 'dpnp.array(2)', 'dpt.asarray(3)'])
286291
@pytest.mark.parametrize("m",
287292
[[[1, 2], [3, 4]],
288293
[[0, 1, 2], [3, 4, 5], [6, 7, 8]],
@@ -294,7 +299,7 @@ def test_tril(m, k, dtype):
294299
def test_triu(m, k, dtype):
295300
a = numpy.array(m, dtype=dtype)
296301
ia = dpnp.array(a)
297-
expected = numpy.triu(a, k=k)
302+
expected = numpy.triu(a, k=operator.index(k))
298303
result = dpnp.triu(ia, k=k)
299304
assert_array_equal(expected, result)
300305

@@ -305,8 +310,8 @@ def test_triu(m, k, dtype):
305310
def test_triu_size_null(k):
306311
a = numpy.ones(shape=(1, 2, 0))
307312
ia = dpnp.array(a)
308-
expected = numpy.triu(a, k)
309-
result = dpnp.triu(ia, k)
313+
expected = numpy.triu(a, k=k)
314+
result = dpnp.triu(ia, k=k)
310315
assert_array_equal(expected, result)
311316

312317

tests/test_sycl_queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_array_creation_like(func, kwargs, device_x, device_y):
168168
def test_tril_triu(func, device):
169169
x0 = dpnp.ones((3,3), device=device)
170170
x = getattr(dpnp, func)(x0)
171-
assert x.sycl_device == device
171+
assert_sycl_queue_equal(x.sycl_queue, x0.sycl_queue)
172172

173173

174174
@pytest.mark.usefixtures("allow_fall_back_on_numpy")

tests/third_party/cupy/creation_tests/test_matrix.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def test_tri_posi(self, xp, dtype):
140140
{'shape': (2, 3, 4)},
141141
)
142142
@testing.gpu
143+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
143144
class TestTriLowerAndUpper(unittest.TestCase):
144145

145146
@testing.for_all_dtypes(no_complex=True)
@@ -148,7 +149,6 @@ def test_tril(self, xp, dtype):
148149
m = testing.shaped_arange(self.shape, xp, dtype)
149150
return xp.tril(m)
150151

151-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
152152
@testing.numpy_cupy_array_equal()
153153
def test_tril_array_like(self, xp):
154154
return xp.tril([[1, 2], [3, 4]])
@@ -171,7 +171,6 @@ def test_triu(self, xp, dtype):
171171
m = testing.shaped_arange(self.shape, xp, dtype)
172172
return xp.triu(m)
173173

174-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
175174
@testing.numpy_cupy_array_equal()
176175
def test_triu_array_like(self, xp):
177176
return xp.triu([[1, 2], [3, 4]])

0 commit comments

Comments
 (0)