Skip to content

usm_ndarray.real and usm_ndarray.imag now set flags correctly #1355

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 1 commit into from
Aug 20, 2023

Conversation

ndgrigorian
Copy link
Collaborator

The real and imag properties of usm_ndarray were setting the flags of the returned view incorrectly.

In most cases, the output was not contiguous, but the input was, which caused most functions to behave incorrectly on views into the real or imaginary parts of complex arrays.

This PR corrects that, and also allows real and imag to work on 0-dimensional arrays.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an 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 opening the PR as a draft?

- these functions were setting the flags of the output to the flags of the input, which is incorrect, as the output is almost never contiguous
- added tests for this behavior
@github-actions
Copy link

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 85.584%. remained the same when pulling 72775fc on flags-real-imag-views into 96293fd on master.

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.6dev4=py310ha25a700_2 ran successfully.
Passed: 913
Failed: 87
Skipped: 119

Copy link
Contributor

@oleksandr-pavlyk oleksandr-pavlyk left a comment

Choose a reason for hiding this comment

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

Good catch, @ndgrigorian !

It is reminds me that it is possible to set up real/imag values of complex arrays:

import dpctl.tensor as dpt

sp_vals = dpt.asarray([dpt.nan, -dpt.nan, dpt.inf, -dpt.inf, -1.0, -0.0, 0.0, 1.0], dtype="f4")
x = dpt.empty((sp_vals.shape[0], sp_vals.shape[0]), dtype="c8")
x.real[...] = sp_vals[:, dpt.newaxis]
x.imag[...] = sp_vals[dpt.newaxis, :]

@ndgrigorian ndgrigorian merged commit abc8c80 into master Aug 20, 2023
@ndgrigorian ndgrigorian deleted the flags-real-imag-views branch August 20, 2023 05:09
@github-actions
Copy link

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.6dev4=py310ha25a700_2 ran successfully.
Passed: 916
Failed: 84
Skipped: 119

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