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

a.assign(b) unexpected results when a.shape() = b.transpose.shape() #6545

Closed
treo opened this issue Oct 7, 2018 · 2 comments · Fixed by #6546

Comments

@treo
Copy link

commented Oct 7, 2018

I ran into the issue where I've been using a.assign(b), and while debugging I noticed that as long as a and b have the same overall length, there will be no exception.

For vectors that works just fine, so if a has the shape [1, x] and b has the shape [x, 1] they are written as expected - just transposed.

For matrices this behavior however doesn't work. This examples shows what happens:

        final INDArray target = Nd4j.zeros(7, 2);

        final INDArray source = Nd4j.linspace(1, 14, 14).reshape(2, 7);
        System.out.println(source);
/*
[[    1,0000,    2,0000,    3,0000,    4,0000,    5,0000,    6,0000,    7,0000], 
 [    8,0000,    9,0000,   10,0000,   11,0000,   12,0000,   13,0000,   14,0000]]
*/
        target.assign(source);
        System.out.println(target);
/*
[[    1,0000,    2,0000], 
 [    3,0000,    4,0000], 
 [    5,0000,    6,0000], 
 [    7,0000,    8,0000], 
 [    9,0000,   10,0000], 
 [   11,0000,   12,0000], 
 [   13,0000,   14,0000]]
*/

This allows for some very subtle and hard to find bugs - I've questioned my sanity several times before I notices what was going on there. So I think this case should also throw an exception.

@AlexDBlack

This comment has been minimized.

Copy link
Contributor

commented Oct 8, 2018

I think this was originally intended behaviour, but on reflection I'm in favor of making it explicit (as you've found out, it's a source of unintended silent errors).

I'll add validation to allow the both scalar and both vector cases, but otherwise the shapes must be equal. Users can reshape manually for the other cases.

AlexDBlack added a commit that referenced this issue Oct 10, 2018
DL4J/ND4J Fixes (#6546)
* #6539 Handle 0 gradient case for gradient normalization

* #6521 Nd4j.gemm validation

* #6543 View/order checks for BaseNDArray.mmuli()

* #6542 mmuli shape validation

* #6545 Require scalars, vectors, or same shape for INDArray.assign()

* #6520 Fix setLearningRate(double) for the no updater state (SGD, etc) case

* #6490 Fix StackVertex NPE with some masking cases

* Cnn3DLossLayer. Typo in RecordReaderMultiDataSetIteratorTest.

* Small fix

* Cnn3DLossLayer gradient checks (not yet passing)

* Cnn3dLossLayer masking + test fixes

* Extra tests, CNN3D tweaks

* Fix Conv3d layer support for NDHWC data format

* Fix Cnn3DLossLayer

* Allow size 1 dimensions in assign shape check

* Minor test fixes

* Fix RollAxis; other tweaks
@lock

This comment has been minimized.

Copy link

commented Nov 9, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Nov 9, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants
You can’t perform that action at this time.