我已经编写了一个简单的类,并在main()中手动测试它,并按预期工作:
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();
}
}但是尝试用JUnit 4对这个类进行单元测试是在抛出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());
}
}事实上,使用ND4J的更复杂的类在main()中运行良好,在测试中也遇到了类似的问题。我的pom文件有以下本机依赖项: javacpp,nd4j-jblas,ND4J -ND4J-platform,nd4j-native。
谢谢
发布于 2018-07-27 03:10:14
我没有使用ND4J get started页面上提到的前提条件,而是按照下面的说明让它正常工作:https://github.com/deeplearning4j/dl4j-examples/blob/master/standalone-sample-project/pom.xml
https://stackoverflow.com/questions/51522773
复制相似问题