public static < S extends Matrix , D extends Matrix > LinearSolver < S , D > safe ( LinearSolver < S , D > solver ) { if ( solver . modifiesA ( ) || solver . modifiesB ( ) ) { if ( solver instanceof LinearSolverDense ) { return new LinearSolverSafe ( ( LinearSolverDense ) solver ) ; } else if ( solver instanceof LinearSolverSparse ) { return new LinearSolverSparseSafe ( ( LinearSolverSparse ) solver ) ; } else { throw new IllegalArgumentException ( "Unknown solver type" ) ; } } else { return solver ; } }
Wraps a linear solver of any type with a safe solver the ensures inputs are not modified