Search in sources :

Example 6 with Pair

use of org.nd4j.linalg.primitives.Pair in project nd4j by deeplearning4j.

the class NDArrayCreationUtil method getAll5dTestArraysWithShape.

public static List<Pair<INDArray, String>> getAll5dTestArraysWithShape(int seed, int... shape) {
    if (shape.length != 5)
        throw new IllegalArgumentException("Shape is not length 5");
    List<Pair<INDArray, String>> list = new ArrayList<>();
    String baseMsg = "getAll5dTestArraysWithShape(" + seed + "," + Arrays.toString(shape) + ").get(";
    // Basic 5d in C and F orders:
    Nd4j.getRandom().setSeed(seed);
    INDArray stdC = Nd4j.rand(shape, 'c');
    INDArray stdF = Nd4j.rand(shape, 'f');
    list.add(new Pair<>(stdC, baseMsg + "0)/Nd4j.rand(" + Arrays.toString(shape) + ",'c')"));
    list.add(new Pair<>(stdF, baseMsg + "1)/Nd4j.rand(" + Arrays.toString(shape) + ",'f')"));
    // Various sub arrays:
    list.addAll(get5dSubArraysWithShape(seed, shape));
    // TAD
    list.addAll(get5dTensorAlongDimensionWithShape(seed, shape));
    // Permuted
    list.addAll(get5dPermutedWithShape(seed, shape));
    // Reshaped
    list.addAll(get5dReshapedWithShape(seed, shape));
    return list;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Pair(org.nd4j.linalg.primitives.Pair)

Example 7 with Pair

use of org.nd4j.linalg.primitives.Pair in project nd4j by deeplearning4j.

the class NDArrayCreationUtil method get5dTensorAlongDimensionWithShape.

public static List<Pair<INDArray, String>> get5dTensorAlongDimensionWithShape(int seed, int... shape) {
    List<Pair<INDArray, String>> list = new ArrayList<>();
    String baseMsg = "get5dTensorAlongDimensionWithShape(" + seed + "," + Arrays.toString(shape) + ")";
    // Create some 6d arrays and get subsets using 5d TAD on them
    // This is not an exhausive list of possible 5d arrays from 6d via TAD
    Nd4j.getRandom().setSeed(seed);
    int[] shape4d1 = { 3, shape[0], shape[1], shape[2], shape[3], shape[4] };
    INDArray orig1a = Nd4j.rand(shape4d1);
    INDArray tad1a = orig1a.javaTensorAlongDimension(0, 1, 2, 3, 4, 5);
    INDArray orig1b = Nd4j.rand(shape4d1);
    INDArray tad1b = orig1b.javaTensorAlongDimension(2, 1, 2, 3, 4, 5);
    list.add(new Pair<>(tad1a, baseMsg + ".get(0)"));
    list.add(new Pair<>(tad1b, baseMsg + ".get(1)"));
    int[] shape4d2 = { 3, shape[0], shape[1], shape[2], shape[3], shape[4] };
    INDArray orig2 = Nd4j.rand(shape4d2);
    INDArray tad2 = orig2.javaTensorAlongDimension(1, 3, 5, 4, 2, 1);
    list.add(new Pair<>(tad2, baseMsg + ".get(2)"));
    int[] shape4d3 = { shape[0], shape[1], shape[2], shape[3], shape[4], 2 };
    INDArray orig3 = Nd4j.rand(shape4d3);
    INDArray tad3 = orig3.javaTensorAlongDimension(1, 4, 1, 3, 2, 0);
    list.add(new Pair<>(tad3, baseMsg + ".get(3)"));
    int[] shape4d4 = { shape[0], shape[1], shape[2], shape[3], 3, shape[4] };
    INDArray orig4 = Nd4j.rand(shape4d4);
    INDArray tad4 = orig4.javaTensorAlongDimension(1, 5, 2, 0, 3, 1);
    list.add(new Pair<>(tad4, baseMsg + ".get(4)"));
    return list;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Pair(org.nd4j.linalg.primitives.Pair)

Example 8 with Pair

use of org.nd4j.linalg.primitives.Pair in project nd4j by deeplearning4j.

the class NDArrayCreationUtil method get3dTensorAlongDimensionWithShape.

public static List<Pair<INDArray, String>> get3dTensorAlongDimensionWithShape(int seed, int... shape) {
    List<Pair<INDArray, String>> list = new ArrayList<>();
    String baseMsg = "get3dTensorAlongDimensionWithShape(" + seed + "," + Arrays.toString(shape) + ")";
    // Create some 4d arrays and get subsets using 3d TAD on them
    // This is not an exhaustive list of possible 3d arrays from 4d via TAD
    Nd4j.getRandom().setSeed(seed);
    // int[] shape4d1 = {shape[2],shape[1],shape[0],3};
    int[] shape4d1 = { shape[0], shape[1], shape[2], 3 };
    int lenshape4d1 = ArrayUtil.prod(shape4d1);
    INDArray orig1a = Nd4j.linspace(1, lenshape4d1, lenshape4d1).reshape(shape4d1);
    INDArray tad1a = orig1a.javaTensorAlongDimension(0, 0, 1, 2);
    INDArray orig1b = Nd4j.linspace(1, lenshape4d1, lenshape4d1).reshape(shape4d1);
    INDArray tad1b = orig1b.javaTensorAlongDimension(1, 0, 1, 2);
    list.add(new Pair<>(tad1a, baseMsg + ".get(0)"));
    list.add(new Pair<>(tad1b, baseMsg + ".get(1)"));
    int[] shape4d2 = { 3, shape[0], shape[1], shape[2] };
    int lenshape4d2 = ArrayUtil.prod(shape4d2);
    INDArray orig2 = Nd4j.linspace(1, lenshape4d2, lenshape4d2).reshape(shape4d2);
    INDArray tad2 = orig2.javaTensorAlongDimension(1, 1, 2, 3);
    list.add(new Pair<>(tad2, baseMsg + ".get(2)"));
    int[] shape4d3 = { shape[0], shape[1], 3, shape[2] };
    int lenshape4d3 = ArrayUtil.prod(shape4d3);
    INDArray orig3 = Nd4j.linspace(1, lenshape4d3, lenshape4d3).reshape(shape4d3);
    INDArray tad3 = orig3.javaTensorAlongDimension(1, 1, 3, 0);
    list.add(new Pair<>(tad3, baseMsg + ".get(3)"));
    int[] shape4d4 = { shape[0], 3, shape[1], shape[2] };
    int lenshape4d4 = ArrayUtil.prod(shape4d4);
    INDArray orig4 = Nd4j.linspace(1, lenshape4d4, lenshape4d4).reshape(shape4d4);
    INDArray tad4 = orig4.javaTensorAlongDimension(1, 2, 0, 3);
    list.add(new Pair<>(tad4, baseMsg + ".get(4)"));
    return list;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Pair(org.nd4j.linalg.primitives.Pair)

Example 9 with Pair

use of org.nd4j.linalg.primitives.Pair in project nd4j by deeplearning4j.

the class NDArrayCreationUtil method getTransposedMatrixWithShape.

public static Pair<INDArray, String> getTransposedMatrixWithShape(char ordering, int rows, int cols, int seed) {
    Nd4j.getRandom().setSeed(seed);
    INDArray out = Nd4j.linspace(1, rows * cols, rows * cols).reshape(ordering, cols, rows);
    return new Pair<>(out.transpose(), "getTransposedMatrixWithShape(" + rows + "," + cols + "," + seed + ")");
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Pair(org.nd4j.linalg.primitives.Pair)

Example 10 with Pair

use of org.nd4j.linalg.primitives.Pair in project nd4j by deeplearning4j.

the class NDArrayCreationUtil method getTransposedMatrixWithShape.

public static Pair<INDArray, String> getTransposedMatrixWithShape(int rows, int cols, int seed) {
    Nd4j.getRandom().setSeed(seed);
    INDArray out = Nd4j.linspace(1, rows * cols, rows * cols).reshape(cols, rows);
    return new Pair<>(out.transpose(), "getTransposedMatrixWithShape(" + rows + "," + cols + "," + seed + ")");
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Pair(org.nd4j.linalg.primitives.Pair)

Aggregations

Pair (org.nd4j.linalg.primitives.Pair)66 INDArray (org.nd4j.linalg.api.ndarray.INDArray)63 Test (org.junit.Test)24 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)9 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)5 ArrayList (java.util.ArrayList)4 DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)4 Ignore (org.junit.Ignore)3 List (java.util.List)2 RealMatrix (org.apache.commons.math3.linear.RealMatrix)2 IntPointer (org.bytedeco.javacpp.IntPointer)2 Pointer (org.bytedeco.javacpp.Pointer)2 OpExecutionerUtil (org.nd4j.linalg.api.ops.executioner.OpExecutionerUtil)2 LongPointerWrapper (org.nd4j.nativeblas.LongPointerWrapper)2 IntBuffer (java.nio.IntBuffer)1 Random (java.util.Random)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)1 BlockRealMatrix (org.apache.commons.math3.linear.BlockRealMatrix)1 LUDecomposition (org.apache.commons.math3.linear.LUDecomposition)1