Skip to content

Fix power #500

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 5 commits into from
Jan 21, 2021
Merged

Fix power #500

merged 5 commits into from
Jan 21, 2021

Conversation

Rubtsowa
Copy link
Contributor

No description provided.

res_type = x1.dtype
if isinstance(x2, float) and (res_type == dpnp.int64 or res_type == dpnp.int32):
res_type = dpnp.float64
result = dparray(x1.size, dtype=res_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
result = dparray(x1.size, dtype=res_type)
result = dparray(x1.shape, dtype=res_type)

to avoid reshape in further

return call_fptr_2in_1out(DPNP_FN_POWER, x1, x2, x1.shape)
cpdef dparray dpnp_power(dparray x1, x2):
cdef dparray result
if dpnp.isscalar(x2):
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 have any test that covers the branch?

cdef dparray result
if dpnp.isscalar(x2):
res_type = x1.dtype
if isinstance(x2, float) and (res_type == dpnp.int64 or res_type == dpnp.int32):
Copy link
Contributor

Choose a reason for hiding this comment

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

E.g. such approach

types_map = {
(dpnp.int32, dpnp.int32): dpnp.int32,
(dpnp.int32, dpnp.int64): dpnp.int64,
(dpnp.int64, dpnp.int32): dpnp.int64,
(dpnp.int64, dpnp.int64): dpnp.int64,
(dpnp.float32, dpnp.float32): dpnp.float32,
}
res_type = types_map.get((x1.dtype, x2.dtype), dpnp.float64)
looks more readable.

@Rubtsowa Rubtsowa added the in progress Please do not merge. Work is in progress. label Jan 19, 2021
@Rubtsowa Rubtsowa removed the in progress Please do not merge. Work is in progress. label Jan 20, 2021
x2_ = dpnp.array([x2])

types_map = {
(dpnp.dtype(dpnp.int32), dpnp.dtype(dpnp.float64)): dpnp.float64,
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like it needs to be adjusted to the same things as you did in other PR

cpdef dparray dpnp_power(dparray x1, x2):
cdef dparray result
if dpnp.isscalar(x2):
x2_ = dpnp.array([x2])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to avoid creating one-element array?

@shssf shssf merged commit af49a9f into IntelPython:master Jan 21, 2021
@Rubtsowa Rubtsowa deleted the fix_power branch January 26, 2021 07:14
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