Java Code Examples for org.nd4j.linalg.api.rng.Random#nextInt()

The following examples show how to use org.nd4j.linalg.api.rng.Random#nextInt() . 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: RandomTests.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaSide2() throws Exception {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[1000];
    int array2[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt();
        array2[e] = random2.nextInt();

        assertEquals(array1[e], array2[e]);
        assertTrue(array1[e] >= 0);
    }

    assertArrayEquals(array1, array2);
}
 
Example 2
Source File: RandomTests.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaSide3() throws Exception {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[10000];
    int array2[] = new int[10000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt(9823);
        array2[e] = random2.nextInt(9823);

        assertTrue(array1[e] >= 0);
        assertTrue(array1[e] < 9823);
    }

    assertArrayEquals(array1, array2);
}
 
Example 3
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaSide2() {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[1000];
    int array2[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt();
        array2[e] = random2.nextInt();

        assertEquals(array1[e], array2[e]);
        assertTrue(array1[e] >= 0);
    }

    assertArrayEquals(array1, array2);
}
 
Example 4
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaSide3() {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[10000];
    int array2[] = new int[10000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt(9823);
        array2[e] = random2.nextInt(9823);

        assertTrue(array1[e] >= 0);
        assertTrue(array1[e] < 9823);
    }

    assertArrayEquals(array1, array2);
}
 
Example 5
Source File: RandomTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks reSeed mechanics for native side
 *
 * @throws Exception
 */

@Test
public void testJavaSide4() throws Exception {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[1000];
    int array2[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt();
        array2[e] = random2.nextInt();

        assertEquals(array1[e], array2[e]);
        assertTrue(array1[e] >= 0);
    }

    assertArrayEquals(array1, array2);

    random1.reSeed();
    random1.reSeed();

    int array3[] = new int[1000];
    int array4[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array3[e] = random1.nextInt();
        array4[e] = random2.nextInt();

        assertNotEquals(array3[e], array4[e]);
        assertTrue(array1[e] >= 0);
    }
}
 
Example 6
Source File: RandomTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testDeallocation1() throws Exception {

    while (true) {
        Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
        random1.nextInt();

        System.gc();
        Thread.sleep(50);
    }
}
 
Example 7
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks reSeed mechanics for native side
 *
 * @throws Exception
 */

@Test
public void testJavaSide4() {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[1000];
    int array2[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt();
        array2[e] = random2.nextInt();

        assertEquals(array1[e], array2[e]);
        assertTrue(array1[e] >= 0);
    }

    assertArrayEquals(array1, array2);

    random1.reSeed();
    random1.reSeed();

    int array3[] = new int[1000];
    int array4[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array3[e] = random1.nextInt();
        array4[e] = random2.nextInt();

        assertNotEquals(array3[e], array4[e]);
        assertTrue(array1[e] >= 0);
    }
}
 
Example 8
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testDeallocation1() throws Exception {

    while (true) {
        Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
        random1.nextInt();

        System.gc();
        Thread.sleep(50);
    }
}