Search in sources :

Example 6 with BlockRealMatrix

use of org.apache.commons.math3.linear.BlockRealMatrix in project gatk-protected by broadinstitute.

the class Nd4jApacheAdapterUtils method convertINDArrayToApacheMatrix.

/**
     * INDArray to Apache
     *
     * @param matrix rank-2 INDArray
     * @return Apache matrix
     */
public static RealMatrix convertINDArrayToApacheMatrix(@Nonnull final INDArray matrix) {
    Utils.validateArg(matrix.rank() == 2, "Input rank is not 2 (not matrix)");
    final int[] shape = matrix.shape();
    final INDArray concreteMatrix = matrix.isView() ? matrix.dup() : matrix;
    final double[] data = concreteMatrix.data().asDouble();
    final char ordering = concreteMatrix.ordering();
    if (ordering == 'c') {
        return new BlockRealMatrix(monoToBiDiArrayRowMajor(data, shape[0], shape[1]));
    } else {
        /* ordering == 'f' */
        return new BlockRealMatrix(monoToBiDiArrayColumnMajor(data, shape[0], shape[1]));
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) BlockRealMatrix(org.apache.commons.math3.linear.BlockRealMatrix)

Aggregations

BlockRealMatrix (org.apache.commons.math3.linear.BlockRealMatrix)6 RealMatrix (org.apache.commons.math3.linear.RealMatrix)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 INDArray (org.nd4j.linalg.api.ndarray.INDArray)2 Test (org.testng.annotations.Test)2