Skip to content
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

Forward chainerx::MakeArray in some case #8296

Merged
merged 5 commits into from
Oct 30, 2019

Conversation

take-cheeze
Copy link
Member

@take-cheeze take-cheeze commented Oct 15, 2019

Spin-offed from: #8262

In non-copy mode of more C++ like MakeArray if device and dtype matches the source array so python like API should follow the behavior too:

if (!copy && a.dtype() == dtype_ && &a.device() == &device) {
return MoveArrayBody(std::move(a));
}

TODO:

@niboshi
Copy link
Member

niboshi commented Oct 15, 2019

Could you explain a bit more? For what case this fix is needed?
Please add unit tests if applicable.

@emcastillo emcastillo self-assigned this Oct 16, 2019
@take-cheeze
Copy link
Member Author

Updated the PR comment

if (!copy && py::isinstance<ArrayBody>(object)) {
ArrayBodyPtr body = py::cast<ArrayBodyPtr>(object);
if ((device.is_none() || &dev == &body->device()) && (dtype.is_none() || *dtype_ == body->dtype())) {
return std::move(body);
Copy link
Member

Choose a reason for hiding this comment

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

I think you don't have to move the return value.

@@ -259,10 +259,14 @@ def test_array_from_chainerx_array_with_device(

dst_device = chainerx.get_device(dst_device_spec)

if not copy and src_dtype == dst_dtype and device is dst_device:
if not copy and \
Copy link
Member

Choose a reason for hiding this comment

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

Let's follow the recommendation in PEP-8.

  • Use parentheses instead of \.
  • Place and after line breaks.

@niboshi
Copy link
Member

niboshi commented Oct 17, 2019

I think array should always return a "copy" unlike asarray, to which this check is applicable.

@niboshi
Copy link
Member

niboshi commented Oct 17, 2019

Sorry never mind, the above comment only assumed the default copy=True.
But how about adding the same check to asarray?

Copy link
Member

@emcastillo emcastillo left a comment

Choose a reason for hiding this comment

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

LGTM

@emcastillo
Copy link
Member

Jenkins, test this please

@chainer-ci
Copy link
Member

Jenkins CI test (for commit d5a9a6b, target branch master) failed with status FAILURE.

@emcastillo
Copy link
Member

Jenkins, test this please

@emcastillo emcastillo added this to the v7.0.0 milestone Oct 28, 2019
@emcastillo emcastillo added cat:enhancement Implementation that does not break interfaces. st:test-and-merge State indicating that pull request is approved by a reviewer and can be merged after CI passes. labels Oct 28, 2019
@chainer-ci
Copy link
Member

Jenkins CI test (for commit d5a9a6b, target branch master) succeeded!

@niboshi
Copy link
Member

niboshi commented Oct 30, 2019

LGTM @emcastillo

@mergify mergify bot merged commit 6d37d9b into chainer:master Oct 30, 2019
@take-cheeze take-cheeze deleted the reduce_makearray_cop branch October 30, 2019 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:enhancement Implementation that does not break interfaces. ChainerX Related to ChainerX. st:test-and-merge State indicating that pull request is approved by a reviewer and can be merged after CI passes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants