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

The assignment problem about NDArray #9976

Closed
wkcn opened this issue Mar 3, 2018 · 2 comments · Fixed by #9981
Closed

The assignment problem about NDArray #9976

wkcn opened this issue Mar 3, 2018 · 2 comments · Fixed by #9981
Labels

Comments

@wkcn
Copy link
Member

wkcn commented Mar 3, 2018

Description

If a is a multi-dims array, it is not available to use a[0] = a[1] to assign a row.
However, it's available to use a[0, :] = a[1] or a[0]=a[1].asnumpy()

Environment info (Required)

The latest pre-built MXNet has the same problem.

----------Python Info----------
Version      : 3.6.4
Compiler     : GCC 7.2.1 20171224
Build        : ('default', 'Jan  5 2018 02:35:40')
Arch         : ('64bit', '')
------------Pip Info-----------
Version      : 9.0.1
Directory    : /usr/lib/python3.6/site-packages/pip
----------MXNet Info-----------
Version      : 1.2.0
Directory    : /home/wkcn/proj/mxnet/python/mxnet
Hashtag not found. Not installed from pre-built package.
----------System Info----------
Platform     : Linux-4.15.5-1-ARCH-x86_64-with-arch
system       : Linux
node         : MiraiM
release      : 4.15.5-1-ARCH
version      : #1 SMP PREEMPT Thu Feb 22 22:15:20 UTC 2018

Package used (Python/R/Scala/Julia):
Python

Build info (Required if built from source)

Compiler (gcc/clang/mingw/visual studio): gcc 7.2.1

MXNet commit hash:
17a9c6a

Build config:
make -j4 USE_OPENCV=1 USE_BLAS=openblas

Minimum reproducible example

>>> import mxnet as mx
>>> import numpy as np

>>> a = mx.nd.array(np.arange(12).reshape((3,4)))
>>> a

[[ 0.  1.  2.  3.]
 [ 4.  5.  6.  7.]
 [ 8.  9. 10. 11.]]
<NDArray 3x4 @cpu(0)>
>>> a[0]=a[1]     #   HERE
>>> a

[[ 0.  1.  2.  3.]
 [ 4.  5.  6.  7.]
 [ 8.  9. 10. 11.]]
<NDArray 3x4 @cpu(0)>
>>> a[0]=[10,11,12,13]
>>> a

[[10. 11. 12. 13.]
 [ 4.  5.  6.  7.]
 [ 8.  9. 10. 11.]]
<NDArray 3x4 @cpu(0)>
>>> a[0]=a[1].asnumpy()
>>> a

[[ 4.  5.  6.  7.]
 [ 4.  5.  6.  7.]
 [ 8.  9. 10. 11.]]
<NDArray 3x4 @cpu(0)>
>>> a[1,:]=a[2]
>>> a

[[ 4.  5.  6.  7.]
 [ 8.  9. 10. 11.]
 [ 8.  9. 10. 11.]]
<NDArray 3x4 @cpu(0)>
@reminisce
Copy link
Contributor

This is a bug of CopyFromTo function. a[0] and a[1] share the same var and thus the copy is skipped.
https://github.com/apache/incubator-mxnet/blob/master/src/ndarray/ndarray.cc#L1131

@reminisce reminisce added the Bug label Mar 3, 2018
@wkcn
Copy link
Member Author

wkcn commented Mar 3, 2018

@reminisce Thank you! I will try to fix it.

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

Successfully merging a pull request may close this issue.

2 participants