Java Code Examples for org.nd4j.linalg.factory.Nd4j#setDataType()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#setDataType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TSNEVisualizationExample.java    From Java-Deep-Learning-Cookbook with MIT License 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    Nd4j.setDataType(DataBuffer.Type.DOUBLE);
    List<String> cacheList = new ArrayList<>();
    File file = new File("words.txt");
    String outputFile = "tsne-standard-coords.csv";
    Pair<InMemoryLookupTable,VocabCache> vectors = WordVectorSerializer.loadTxt(file);
    VocabCache cache = vectors.getSecond();
    INDArray weights = vectors.getFirst().getSyn0();

    for(int i=0;i<cache.numWords();i++){
        cacheList.add(cache.wordAtIndex(i));
    }

    BarnesHutTsne tsne = new BarnesHutTsne.Builder()
                                            .setMaxIter(100)
                                            .theta(0.5)
                                            .normalize(false)
                                            .learningRate(500)
                                            .useAdaGrad(false)
                                            .build();

    tsne.fit(weights);
    tsne.saveAsFile(cacheList,outputFile);

}
 
Example 2
Source File: TestNativeImageLoader.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testDataTypes_1() throws Exception {
    val dtypes = new DataType[]{DataType.FLOAT, DataType.HALF, DataType.SHORT, DataType.INT};

    val dt = Nd4j.dataType();

    for (val dtype: dtypes) {
        Nd4j.setDataType(dtype);
        int w3 = 123, h3 = 77, ch3 = 3;
        val loader = new NativeImageLoader(h3, w3, ch3);
        File f3 = new ClassPathResource("datavec-data-image/testimages/class0/2.jpg").getFile();
        ImageWritable iw3 = loader.asWritable(f3);

        val array = loader.asMatrix(iw3);

        assertEquals(dtype, array.dataType());
    }

    Nd4j.setDataType(dt);
}
 
Example 3
Source File: EndlessWorkspaceTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@After
public void shutUp() throws Exception {
    Nd4j.getMemoryManager().setCurrentWorkspace(null);
    Nd4j.getWorkspaceManager().destroyAllWorkspacesForCurrentThread();
    Nd4j.setDataType(this.initialType);
    Nd4j.getMemoryManager().togglePeriodicGc(true);
}
 
Example 4
Source File: DataTypeValidationTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Testing level2 blas
 */
@Test(expected = ND4JIllegalStateException.class)
public void testBlasValidation2() {
    INDArray a = Nd4j.create(100, 10);
    INDArray x = Nd4j.create(100);

    Nd4j.setDataType(DataBuffer.Type.DOUBLE);

    INDArray y = Nd4j.create(100);

    Nd4j.getBlasWrapper().gemv(1.0, a, x, 1.0, y);
}
 
Example 5
Source File: OpValidationSuite.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void afterClass() {
    Nd4j.setDataType(initialType);

    // Log coverage information
    OpValidation.logCoverageInformation(true, true, true, true, true);
}
 
Example 6
Source File: DataTypeValidationTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Testing level1 blas
 */
@Test(expected = ND4JIllegalStateException.class)
public void testBlasValidation1() {
    INDArray x = Nd4j.create(10);

    Nd4j.setDataType(DataBuffer.Type.DOUBLE);

    INDArray y = Nd4j.create(10);

    Nd4j.getBlasWrapper().dot(x, y);
}
 
Example 7
Source File: SpecialWorkspaceTests.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@After
public void shutUp() {
    Nd4j.getMemoryManager().setCurrentWorkspace(null);
    Nd4j.getWorkspaceManager().destroyAllWorkspacesForCurrentThread();
    Nd4j.setDataType(this.initialType);
}
 
Example 8
Source File: DeepWalkGradientCheck.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Before
public void before() {
    Nd4j.setDataType(DataType.DOUBLE);
}
 
Example 9
Source File: BasicSerDeTests.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    Nd4j.setDataType(this.initialType);
}
 
Example 10
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    Nd4j.setDataType(initialType);
}
 
Example 11
Source File: TFGraphTestAllSameDiff.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
    Nd4j.setDataType(DataType.FLOAT);
    Nd4j.getExecutioner().setProfilingMode(OpExecutioner.ProfilingMode.SCOPE_PANIC);
}
 
Example 12
Source File: NativeOpExecutionerTest.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testInf() {
    Nd4j.setDataType(DataBuffer.Type.FLOAT);
    INDArray x = Nd4j.create(10, 10);
    x.minNumber();


    MatchCondition condition = new MatchCondition(x, Conditions.isInfinite());
    int match = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0);

    log.info("Matches: {}", match);

    Nd4j.getExecutioner().setProfilingMode(OpExecutioner.ProfilingMode.INF_PANIC);

    x = Nd4j.create(10, 10);
    x.minNumber();

}
 
Example 13
Source File: LapackTestsF.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    Nd4j.setDataType(DataType.DOUBLE);
}
 
Example 14
Source File: ReductionBpOpValidation.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    Nd4j.setDataType(initialType);
}
 
Example 15
Source File: ShapeTestsC.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    Nd4j.setDataType(this.initialType);
}
 
Example 16
Source File: TwoPointApproximationTest.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    Nd4j.setDataType(dtype);
    Nd4j.getExecutioner().setProfilingMode(OpExecutioner.ProfilingMode.DISABLED);
}
 
Example 17
Source File: LapackTestsF.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    Nd4j.setDataType(DataBuffer.Type.DOUBLE);
}
 
Example 18
Source File: LapackTestsF.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    Nd4j.setDataType(initialType);
}
 
Example 19
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    initialType = Nd4j.dataType();
    Nd4j.setDataType(DataType.DOUBLE);
}
 
Example 20
Source File: BasicSerDeTests.java    From nd4j with Apache License 2.0 3 votes vote down vote up
@Test
public void testBasicDataTypeSwitch1() throws Exception {
    DataBuffer.Type initialType = Nd4j.dataType();
    Nd4j.setDataType(DataBuffer.Type.FLOAT);


    INDArray array = Nd4j.create(new float[] {1, 2, 3, 4, 5, 6});

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    Nd4j.write(bos, array);


    Nd4j.setDataType(DataBuffer.Type.DOUBLE);


    INDArray restored = Nd4j.read(new ByteArrayInputStream(bos.toByteArray()));

    assertEquals(Nd4j.create(new float[] {1, 2, 3, 4, 5, 6}), restored);

    assertEquals(8, restored.data().getElementSize());
    assertEquals(8, restored.shapeInfoDataBuffer().getElementSize());



    Nd4j.setDataType(initialType);
}