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.mmuli(b, result) produces wrong results in result is a view on an f ordered array #6543

Closed
treo opened this issue Oct 6, 2018 · 1 comment · Fixed by #6546

Comments

@treo
Copy link

commented Oct 6, 2018

I ran into this issue first when the view was on the whole array like in the following code:

        final INDArray activations = Nd4j.createUninitialized(new long[]{1, 3, 1}, 'f');
        final INDArray z = activations.tensorAlongDimension(0, 1, 2);

        final INDArray a = Nd4j.rand(3, 4);
        final INDArray b = Nd4j.rand(4, 1);
        System.out.println(a.mmuli(b, z));
/*
[1,8806, 
 2,4756, 
 1,2774]
*/
        System.out.println(a.mmul(b));
/*
[1,2774, 
 2,4756, 
 1,8806]
*/
        System.out.println(activations);
/*
[[1,8806, 
  2,4756, 
  1,2774]]
*/

First it looked like it would only happen if the view was on the whole array, but while collecting information for this issue I've got even worse results:

        final INDArray activations = Nd4j.createUninitialized(new long[]{2, 3, 1}, 'f');
        final INDArray z = activations.tensorAlongDimension(0, 1, 2);

        final INDArray a = Nd4j.rand(3, 4);
        final INDArray b = Nd4j.rand(4, 1);
        System.out.println(a.mmuli(b, z));
/*
[0,8462, 
 1,6749e65, 
 1,7817]
*/
        System.out.println(a.mmul(b));
/*
[0,8462, 
 1,7817, 
 1,7691]
*/
        System.out.println(activations);
/*
[[0,8462, 
  1,7817, 
  1,7691], 

 [1,6749e65, 
  1,1927e180, 
  1,2964e219]]
*/

So it looks like the correct result is written to the holding array, but then the view itself contains wrong data.

This appears to work as intended when the last dimension is not 1 even if the view spans the whole array:

        final INDArray activations = Nd4j.createUninitialized(new long[]{1, 3, 2}, 'f');
        final INDArray z = activations.tensorAlongDimension(0, 1, 2);

        final INDArray a = Nd4j.rand(3, 4);
        final INDArray b = Nd4j.rand(4, 2);
        System.out.println(a.mmuli(b, z));
/*
[[    0,3508,    0,9562], 
 [    0,4043,    0,9546], 
 [    0,2221,    0,6694]]
*/
        System.out.println(a.mmul(b));
/*
[[    0,3508,    0,9562], 
 [    0,4043,    0,9546], 
 [    0,2221,    0,6694]]
*/
        System.out.println(activations);
/*
[[[    0,3508,    0,9562], 
  [    0,4043,    0,9546], 
  [    0,2221,    0,6694]]]
*/

However if the target is larger than the required place, the results again get put upside down:

        final INDArray activations = Nd4j.createUninitialized(new long[]{1, 3, 2}, 'f');
        final INDArray z = activations.tensorAlongDimension(0, 1, 2);

        final INDArray a = Nd4j.rand(3, 4);
        final INDArray b = Nd4j.rand(4, 1);
        System.out.println(a.mmuli(b, z));
/*
[[    1,1066,1,1927e180], 
 [    0,7974,2,8534e242], 
 [    0,8920,-1,1968e-248]]
*/
        System.out.println(a.mmul(b));
/*
[0,8920, 
 0,7974, 
 1,1066]
*/
        System.out.println(activations);
/*
[[[    1,1066,1,1927e180], 
  [    0,7974,2,8534e242], 
  [    0,8920,-1,1968e-248]]]
*/

@AlexDBlack AlexDBlack self-assigned this Oct 8, 2018

AlexDBlack added a commit that referenced this issue Oct 8, 2018
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.