Skip to content

Explicit shape comparison for dpnp and numpy outputs #2295

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

vtavana
Copy link
Collaborator

@vtavana vtavana commented Feb 4, 2025

In the test suite, the result arrays from dpnp and numpy were compared, but their shapes were not explicitly checked for equality. As a result, tests could pass even if the shapes differed, such as one being (1,) and the other ().

This PR adds an explicit check to ensure that the output shapes of numpy and dpnp match. Additionally, tests have been updated accordingly to pass with this new check.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you filing the PR as a draft?

@vtavana vtavana self-assigned this Feb 4, 2025
Copy link
Contributor

github-actions bot commented Feb 4, 2025

View rendered docs @ https://intelpython.github.io/dpnp/pull/2295/index.html

Copy link
Contributor

github-actions bot commented Feb 4, 2025

Array API standard conformance tests for dpnp=0.18.0dev1=py312he4f9c94_17 ran successfully.
Passed: 1222
Failed: 0
Skipped: 9

@coveralls
Copy link
Collaborator

coveralls commented Feb 4, 2025

Coverage Status

coverage: 72.271%. remained the same
when pulling b44cd2e on compare-shape
into 6a81e55 on master.

@vtavana vtavana changed the title assert the shape of result and expected array are the same Explicit shape comparison for dpnp and numpy outputs Feb 4, 2025
@vtavana vtavana marked this pull request as ready for review February 4, 2025 20:46
@vtavana vtavana requested a review from ndgrigorian as a code owner February 20, 2025 00:56
@vtavana vtavana marked this pull request as draft April 11, 2025 18:41
@vtavana vtavana force-pushed the compare-shape branch 7 times, most recently from a47ee75 to 94c792e Compare April 12, 2025 20:10
@vtavana vtavana marked this pull request as ready for review April 14, 2025 05:36
@antonwolfy antonwolfy added this to the 0.18.0 release milestone Apr 30, 2025
Comment on lines 84 to 85
We need to adjust the behavior of the multiply function when it is
used for special cases of scalar-array dots.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit unclear what kind of adjustment is implementing. To have the same dtype as numpy, i.e. dpnp.dot(a, sc).dtype == dpnp.float64, or what?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to state that change in the changelog?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the explanation and added an entry to change log. Note that in this PR, only the behavior of dpnp.outer is changed because of using this function. For other functions that fall back on _call_multiply nothing is changed in this PR.

@@ -292,7 +292,7 @@ def test_indexing_array_negative_strides(self):

slices = (slice(None), dpnp.array([0, 1, 2, 3]))
arr[slices] = 10
assert_array_equal(arr, 10.0)
assert_equal(arr, 10.0, strict=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we need strict here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is comparing an array with a scalar, if strict is True, shape comparison will fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I thought in that case we will check that dpnp has shape () and it will not raise any exception.

Copy link
Collaborator Author

@vtavana vtavana Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic that is currently used is for comparing shape of the two arrays and the exception is for a case when dpnp return a 0D array and numpy return a scalar, for which, the code validates dpnp output is indeed a 0D array.

We do not have any check-point to avoid shape comparison of a non-0D dpnp array (here the array has a shape of (4, 4)) and a scalar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants