You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/04/15 16:21:52 UTC
[GitHub] [incubator-mxnet] ZheyuYe opened a new issue #18068: [Numpy] Failed
for Boolean type
ZheyuYe opened a new issue #18068: [Numpy] Failed for Boolean type
URL: https://github.com/apache/incubator-mxnet/issues/18068
## Description
Many operations are unreliable in numpy interface but works well in `mx.nd.ndarray`, such as an example showcased in the reproducible code snippet. The reasons for the above problems can be boiled down to the incompatibility of **Boolean type** which is the return type of `mx.np.equal'. Unlike the `mx.np.equal` operation, `mx.nd.equal` takes float32 as the resulting data type and works fine in this case.
## To Reproduce
```
import mxnet as mx
inputs = mx.np.array([1,1,1])
fake_data = mx.np.array([1,1,0])
1 - mx.np.equal(fake_data, inputs)
inputs = mx.nd.array([1,1,1])
fake_data = mx.nd.array([1,1,0])
1 - mx.nd.equal(fake_data, inputs)
```
### Error Message
```
MXNetError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/IPython/core/formatters.py in __call__(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
/usr/local/lib/python3.6/dist-packages/IPython/lib/pretty.py in pretty(self, obj)
400 if cls is not object \
401 and callable(cls.__dict__.get('__repr__')):
--> 402 return _repr_pprint(obj, self, cycle)
403
404 return _default_pprint(obj, self, cycle)
/usr/local/lib/python3.6/dist-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
695 """A pprint that just redirects to the normal repr function."""
696 # Find newlines and replace them with p.break_()
--> 697 output = repr(obj)
698 for idx,output_line in enumerate(output.splitlines()):
699 if idx:
~/mxnet/python/mxnet/numpy/multiarray.py in __repr__(self)
1163 [0.84426576 0.60276335 0.85794562]] @gpu(0)
1164 """
-> 1165 array_str = self.asnumpy().__repr__()
1166 dtype = self.dtype
1167 if 'dtype=' in array_str:
~/mxnet/python/mxnet/ndarray/ndarray.py in asnumpy(self)
2564 self.handle,
2565 data.ctypes.data_as(ctypes.c_void_p),
-> 2566 ctypes.c_size_t(data.size)))
2567 return data
2568
~/mxnet/python/mxnet/base.py in check_call(ret)
244 """
245 if ret != 0:
--> 246 raise get_last_ffi_error()
247
248
MXNetError: Traceback (most recent call last):
File "../src/operator/numpy/./../tensor/elemwise_binary_scalar_op.h", line 244
MXNetError: Unknown type enum 7
```
## Comments
@sxjscience
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] sxjscience commented on issue #18068: [Numpy]
Failed for Boolean type
Posted by GitBox <gi...@apache.org>.
sxjscience commented on issue #18068: [Numpy] Failed for Boolean type
URL: https://github.com/apache/incubator-mxnet/issues/18068#issuecomment-614146311
@haojin2 @yzhliu @reminisce @szha
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] ZheyuYe commented on issue #18068: [Numpy] Failed
for Boolean type
Posted by GitBox <gi...@apache.org>.
ZheyuYe commented on issue #18068: [Numpy] Failed for Boolean type
URL: https://github.com/apache/incubator-mxnet/issues/18068#issuecomment-614144542
```python
import mxnet as mx
inputs = mx.np.array([1,1,1])
fake_data = mx.np.array([1,1,0])
labels = mx.np.ones_like(inputs) - mx.np.equal(fake_data, inputs)
```
It works well.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] sxjscience commented on issue #18068: [Numpy]
Failed for Boolean type
Posted by GitBox <gi...@apache.org>.
sxjscience commented on issue #18068: [Numpy] Failed for Boolean type
URL: https://github.com/apache/incubator-mxnet/issues/18068#issuecomment-614146108
We should enhance the support of `boolean` type. The current problem is that operators like `np.equal(a, b)`, `a == b` will return a array with boolean type. However, this array will usually be updated with operations like `1 - mask`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] yzhliu commented on issue #18068: [Numpy] Failed for Boolean type
Posted by GitBox <gi...@apache.org>.
yzhliu commented on issue #18068:
URL: https://github.com/apache/incubator-mxnet/issues/18068#issuecomment-632842398
closed by #18277
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-mxnet] xidulu commented on issue #18068: [Numpy] Failed for Boolean type
Posted by GitBox <gi...@apache.org>.
xidulu commented on issue #18068:
URL: https://github.com/apache/incubator-mxnet/issues/18068#issuecomment-629089392
Thanks for your issue,
This is indeed a very interesting use case.
I noticed that this problem also occurred in PyTorch:
```python
>>> inputs = torch.tensor([1,1,1])
>>> fake_data = torch.tensor([1,1,0])
>>> 1 - (inputs == fake_data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/torch/tensor.py", line 394, in __rsub__
return _C._VariableFunctions.rsub(self, other)
RuntimeError: Subtraction, the `-` operator, with a bool tensor is not supported. If you are trying to invert a mask, use the `~` or `logical_not()` operator instead.
>>>
```
If we are capable of providing a solution to this case, that would be a huge advantage over PyTorch.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-mxnet] yzhliu commented on issue #18068: [Numpy] Failed for Boolean type
Posted by GitBox <gi...@apache.org>.
yzhliu commented on issue #18068:
URL: https://github.com/apache/incubator-mxnet/issues/18068#issuecomment-621513662
Assignee: @CassiniXu
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-mxnet] yzhliu closed issue #18068: [Numpy] Failed for Boolean type
Posted by GitBox <gi...@apache.org>.
yzhliu closed issue #18068:
URL: https://github.com/apache/incubator-mxnet/issues/18068
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org