Skip to content

Commit 0987f19

Browse files
authored
Fix dpnp.asfortranarray and dpnp.ascontiguousarray functions for not array input (#1691)
* Fix dpnp.asfortranarray and dpnp.ascontiguousarray functions for not array input * Fix tests
1 parent f324c3f commit 0987f19

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

dpnp/dpnp_iface_arraycreation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def ascontiguousarray(
612612
)
613613

614614
# at least 1-d array has to be returned
615-
if a.ndim == 0:
615+
if dpnp.isscalar(a) or hasattr(a, "ndim") and a.ndim == 0:
616616
a = [a]
617617

618618
return asarray(
@@ -723,7 +723,7 @@ def asfortranarray(
723723
)
724724

725725
# at least 1-d array has to be returned
726-
if a.ndim == 0:
726+
if dpnp.isscalar(a) or hasattr(a, "ndim") and a.ndim == 0:
727727
a = [a]
728728

729729
return asarray(

tests/test_arraycreation.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,3 +878,39 @@ def test_logspace_axis(axis):
878878
[2, 3], [20, 15], num=2, base=[[1, 3], [5, 7]], axis=axis
879879
)
880880
assert_dtype_allclose(func(dpnp), func(numpy))
881+
882+
883+
@pytest.mark.parametrize(
884+
"data", [(), 1, (2, 3), [4], numpy.array(5), numpy.array([6, 7])]
885+
)
886+
def test_ascontiguousarray(data):
887+
result = dpnp.ascontiguousarray(data)
888+
expected = numpy.ascontiguousarray(data)
889+
assert_dtype_allclose(result, expected)
890+
assert result.shape == expected.shape
891+
892+
893+
@pytest.mark.parametrize("data", [(), 1, (2, 3), [4]])
894+
def test_ascontiguousarray1(data):
895+
result = dpnp.ascontiguousarray(dpnp.array(data))
896+
expected = numpy.ascontiguousarray(numpy.array(data))
897+
assert_dtype_allclose(result, expected)
898+
assert result.shape == expected.shape
899+
900+
901+
@pytest.mark.parametrize(
902+
"data", [(), 1, (2, 3), [4], numpy.array(5), numpy.array([6, 7])]
903+
)
904+
def test_asfortranarray(data):
905+
result = dpnp.asfortranarray(data)
906+
expected = numpy.asfortranarray(data)
907+
assert_dtype_allclose(result, expected)
908+
assert result.shape == expected.shape
909+
910+
911+
@pytest.mark.parametrize("data", [(), 1, (2, 3), [4]])
912+
def test_asfortranarray1(data):
913+
result = dpnp.asfortranarray(dpnp.array(data))
914+
expected = numpy.asfortranarray(numpy.array(data))
915+
assert_dtype_allclose(result, expected)
916+
assert result.shape == expected.shape

0 commit comments

Comments
 (0)