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]));
}
}
Aggregations