Skip to content

Fix dpnp.asfortranarray and dpnp.ascontiguousarray functions for not array input #1691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def ascontiguousarray(
)

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

return asarray(
Expand Down Expand Up @@ -723,7 +723,7 @@ def asfortranarray(
)

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

return asarray(
Expand Down
36 changes: 36 additions & 0 deletions tests/test_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,3 +878,39 @@ def test_logspace_axis(axis):
[2, 3], [20, 15], num=2, base=[[1, 3], [5, 7]], axis=axis
)
assert_dtype_allclose(func(dpnp), func(numpy))


@pytest.mark.parametrize(
"data", [(), 1, (2, 3), [4], numpy.array(5), numpy.array([6, 7])]
)
def test_ascontiguousarray(data):
result = dpnp.ascontiguousarray(data)
expected = numpy.ascontiguousarray(data)
assert_dtype_allclose(result, expected)
assert result.shape == expected.shape


@pytest.mark.parametrize("data", [(), 1, (2, 3), [4]])
def test_ascontiguousarray1(data):
result = dpnp.ascontiguousarray(dpnp.array(data))
expected = numpy.ascontiguousarray(numpy.array(data))
assert_dtype_allclose(result, expected)
assert result.shape == expected.shape


@pytest.mark.parametrize(
"data", [(), 1, (2, 3), [4], numpy.array(5), numpy.array([6, 7])]
)
def test_asfortranarray(data):
result = dpnp.asfortranarray(data)
expected = numpy.asfortranarray(data)
assert_dtype_allclose(result, expected)
assert result.shape == expected.shape


@pytest.mark.parametrize("data", [(), 1, (2, 3), [4]])
def test_asfortranarray1(data):
result = dpnp.asfortranarray(dpnp.array(data))
expected = numpy.asfortranarray(numpy.array(data))
assert_dtype_allclose(result, expected)
assert result.shape == expected.shape