File existence validation for Nd4j.createFromNpyFile()

Signed-off-by: raver119 <raver119@gmail.com>
master
raver119 2019-07-17 14:53:24 +03:00 committed by AlexDBlack
parent 91a8fb0d90
commit c9e867b2e8
2 changed files with 9 additions and 0 deletions

View File

@ -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);
}

View File

@ -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';