I have a question about using the oj algo library,
I would like to know if there is an easy and efficient way to take a row out of a Primitive64Matrix, sort it, and then replace it in the matrix, Or alternatively to sort each row of a Primitive64Matrix (but even then I would still like to know how to fill a row of a matrix efficiently)
Here is what I'm doing now :
final double[][] tab = {
{
1, 3, 4, 2 },
{
0, 4, 3, 1 } };
Primitive64Matrix matrix = Primitive64Matrix.FACTORY.rows(tab);
for (int iRow = 0; iRow < matrix.countRows(); iRow++) {
final double[] rowSorted = matrix.row(iRow).toRawCopy1D();
Arrays.sort(rowSorted);
final Primitive64Matrix.DenseReceiver receiver = matrix.copy();
receiver.fillRow(iRow, Primitive64Matrix.FACTORY.rows(rowSorted));
matrix = receiver.get();
}
I think it's ugly and surely they must be other more efficient ways to do that (especially the .copy is awful)
Primitive64Matrixis immutable. Maybe you'll find it more natural to work with the various classes in theorg.ojalgo.matrix.storepackage. Further,Primitive64Matrixhas been renamedMatrixR064in newer versions.Here something you can do, that is close to what you're currently doing:
If you use
Primitive64Store(not yet renamed) instead ofMatrixR064you can avoid copying the matrix, but still do essentially the same thing as above.