DL4j - Rounded floating points when converting from Java Array to INDArray

124 Views Asked by At

Converting from Java array to INDArray causes values to be rounded to nearest approximation

Actual behaviour

From Java Array - [0.0025249954778701, -0.0046458570286632, 0.0052295182831585, -0.0014667856739834, -0.0044226963073015, 0.0073519190773368, -0.0003814829979092, -0.0084274942055345, -0.0040481365285814, 0.0082860253751278]

To INDArray- [0.00, -0.00, 0.01, -0.00, -0.00, 0.01, -0.00, -0.01, -0.00, 0.01]

Expected behaviour

From Java Array - [0.0025249954778701, -0.0046458570286632, 0.0052295182831585, -0.0014667856739834, -0.0044226963073015, 0.0073519190773368, -0.0003814829979092, -0.0084274942055345, -0.0040481365285814, 0.0082860253751278]

To INDArray- [0.0025249954778701, -0.0046458570286632, 0.0052295182831585, -0.0014667856739834, -0.0044226963073015, 0.0073519190773368, -0.0003814829979092, -0.0084274942055345, -0.0040481365285814, 0.0082860253751278]

Below is the code

var (left, right) = inoc.splitAt(7840)
var bias :INDArray = Nd4j.create(right);
var weights :INDArray = Nd4j.create(left);
1

There are 1 best solutions below

2
On

The default data type is float in the latest version. This is due to memory reasons.

Please ensure you create your arrays with double precision if that's what you're desiring.