Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

custom op full_like #16778

Closed
wants to merge 1 commit into from
Closed

Conversation

Alicia1529
Copy link
Contributor

Description

Add numpy operator full_like

def forward(self, is_train, req, in_data, out_data, aux):
np_version = np.version.version
if np_version == '1.17.0':
out = np.full_like(in_data[0].asnumpy(), self._fill_value, dtype=self._dtype, order=self._order,
Copy link
Member

Choose a reason for hiding this comment

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

It will be faster to use mx.nd.full(shape, fill_value)

@hgt312
Copy link
Contributor

hgt312 commented Nov 12, 2019

@mxnet-label-bot add [Numpy]

def hybrid_forward(self, F, x, *args, **kwargs):
return F.np.full_like(x, self._fill_value, self._dtype)

if StrictVersion(platform.python_version()) < StrictVersion('3.0.0'):
Copy link
Contributor

Choose a reason for hiding this comment

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

You can decorate the test function with this condition as the following.

@unittest.skipIf(StrictVersion(platform.python_version()) < StrictVersion('3.0.0'), "reason to skip")
def test_np_full_like():
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

@sxjscience
Copy link
Member

I suggest not use the customop for full_like, which is very similar to ones_like

@sxjscience
Copy link
Member

@Alicia1529
Copy link
Contributor Author

@Alicia1529, You can refer to the implementation of ones_like and zeros_like:

https://github.com/apache/incubator-mxnet/blob/61c8bafdcfee129e4f7a491438a2402e6762ddd9/src/operator/numpy/np_init_op.cc#L100-L134

Thanks for the suggestions!

In pr #16804 a c++ version of full_like is implemented. Zeros_like and ones_like are also rewritten by calling full_like with different fill_value in the front-end to fix the type inference bug in issue #16646

But I am still fixing some problems in python2 test, so it has not been merged. This pr is older and should be closed.

@sxjscience
Copy link
Member

sxjscience commented Nov 21, 2019

@Alicia1529 Is it safe to close this PR?

@Alicia1529
Copy link
Contributor Author

@sxjscience Yeah, thanks

@sxjscience sxjscience closed this Nov 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants