1

I have written a simple class and test it manually in main() and works as expected:

import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;

public class ND4J {
    public static void main(String[] args) {
        ND4J actualObject = new ND4J(Nd4j.zeros(2,2).add(4.0));
        INDArray testObject = Nd4j.create(new double[][]{{4.0,4.0}, {4.0,4.0}});
        if(testObject.equals(actualObject.getMatrix())){
            System.out.println("OK"); // prints “OK”
        }
    }
    private INDArray matrix;
    public ND4J (INDArray matrix){
        this.matrix = matrix;
    }
    public INDArray getMatrix(){
        return this.matrix;
    }
    public String toString(){
        return this.getMatrix().toString();
    }
}

But trying to unit test this class with JUnit 4 is throwing java.lang.AbstractMethodError:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import static org.junit.Assert.*;
public class ND4JTest {
    @Test
    public void print() {
        ND4J actualObject = new ND4J(Nd4j.zeros(2,2).add(4.0));
        //above statement throws this error
        //java.lang.AbstractMethodError: org.nd4j.linalg.factory.Nd4jBackend.getConfigurationResource()Lorg/springframework/core/io/Resource;
        INDArray testObject = Nd4j.create(new double[][]{{4.0,4.0}, {4.0,4.0}});
        assertEquals(testObject, actualObject.getMatrix());
    }
}

In fact more complex classes classes using ND4J that run fine from main() are having similar problems in testing. My pom file has the following ND4J dependencies: javacpp, nd4j-jblas, nd4j-native-platform, nd4j-native.

Thanks

shanlodh
  • 1,015
  • 2
  • 11
  • 30

1 Answers1

0

Rather than the prerequisites mentioned on the ND4J get started page I got it working by following instructions from here: https://github.com/deeplearning4j/dl4j-examples/blob/master/standalone-sample-project/pom.xml

shanlodh
  • 1,015
  • 2
  • 11
  • 30