public static DoubleMatrix permutationDoubleMatrixFromPivotIndices(int size, int[] ipiv) {
        int n = ipiv.length;
        //System.out.printf("size = %d n = %d\n", size, n);
        int indices[] = new int[size];
        for (int i = 0; i < size; i++)
            indices[i] = i;

        //for (int i = 0; i < n; i++)
        //    System.out.printf("ipiv[%d] = %d\n", i, ipiv[i]);

        for (int i = 0; i < n; i++) {
            int j = ipiv[i] - 1;
            int t = indices[i];
            indices[i] = indices[j];
            indices[j] = t;
        }
        DoubleMatrix result = new DoubleMatrix(size, size);
        for (int i = 0; i < size; i++)
            result.put(indices[i], i, 1.0);
        return result;
    }
public static DoubleMatrix permutationDoubleMatrixFromPivotIndices ( int size , int [ ] ipiv ) { int n = ipiv . length ; int indices [ ] = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) indices [ i ] = i ; for ( int i = 0 ; i < n ; i ++ ) { int j = ipiv [ i ] - 1 ; int t = indices [ i ] ; indices [ i ] = indices [ j ] ; indices [ j ] = t ; } DoubleMatrix result = new DoubleMatrix ( size , size ) ; for ( int i = 0 ; i < size ; i ++ ) result . put ( indices [ i ] , i , 1.0 ) ; return result ; }
Create a permutation matrix from a LAPACK-style 'ipiv' vector.

@param ipiv row i was interchanged with row ipiv[i]