diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java index 73d70086c..eda5c7319 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java @@ -6916,6 +6916,9 @@ public class Nd4j { * @return the created ndarray */ public static INDArray createFromNpyFile(File file) { + if (!file.exists()) + throw new IllegalArgumentException("File [" + file.getAbsolutePath() + "] doesn't exist"); + return INSTANCE.createFromNpyFile(file); } diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/serde/NumpyFormatTests.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/serde/NumpyFormatTests.java index 06a0b62fb..217f9780f 100644 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/serde/NumpyFormatTests.java +++ b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/serde/NumpyFormatTests.java @@ -304,6 +304,12 @@ public class NumpyFormatTests extends BaseNd4jTest { boolean eq = exp.equals(probablyShouldntLoad); //And is actually equal content } + @Test(expected = IllegalArgumentException.class) + public void testAbsentNumpyFile_1() throws Exception { + val f = new File("pew-pew-zomg.some_extension_that_wont_exist"); + INDArray act1 = Nd4j.createFromNpyFile(f); + } + @Override public char ordering() { return 'c';