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

[Numpy] Boolean array bug #16658

Closed
sxjscience opened this issue Oct 28, 2019 · 8 comments
Closed

[Numpy] Boolean array bug #16658

sxjscience opened this issue Oct 28, 2019 · 8 comments

Comments

@sxjscience
Copy link
Member

sxjscience commented Oct 28, 2019

import mxnet as mx
import numpy as np
from mxnet.gluon import HybridBlock
mx.npx.set_np()

class CastBlock(HybridBlock):
	def hybrid_forward(F, x):
		return x.astype(np.float32)

f_cast = CastBlock()
f_cast.hybridize()
out = f_cast(mx.np.ones((10,)) > 0)
print(out)
MXNetError: [09:43:24] src/operator/tensor/elemwise_unary_op.h:461: Unknown type enum 7
@sxjscience
Copy link
Member Author

The problem only occurs after I called hybridize.

@sxjscience
Copy link
Member Author

@reminisce
Copy link
Contributor

boolean ndarrays are only supported in a few ops right now. We need to enable them gradually in more ops. Thanks for reporting this.

@sxjscience
Copy link
Member Author

@reminisce I agree. At least we should fix cast, otherwise we cannot use >, <.

@reminisce
Copy link
Contributor

@sxjscience astype should be working with boolean ndarrays. I think using cast is not as pythonic as using astype.

@sxjscience
Copy link
Member Author

@reminisce In this case, .astype will not trigger the error if the block is not hybridized. However, once it's hybridized, it will report the error message.

@reminisce
Copy link
Contributor

reminisce commented Oct 28, 2019

@sxjscience Sorry didn't notice your earlier comments. I will investigate to see why there is a such difference.

@reminisce
Copy link
Contributor

In imperative mode, astype used copy operator which has fully supported boolean ndarrays, while in symbolic mode, astype calls cast, which has not been fully enabled to support boolean ndarrays.

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

No branches or pull requests

2 participants