| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public void changeSize(int newRows, int newCols) |
| 247 | { |
| 248 | if(newRows <= 0) |
| 249 | throw new ArithmeticException("Matrix must have a positive number of rows"); |
| 250 | if(newCols <= 0) |
| 251 | throw new ArithmeticException("Matrix must have a positive number of columns"); |
| 252 | final int oldRow = matrix.length; |
| 253 | //first, did the cols change? That forces a lot of allocation. |
| 254 | if(newCols != cols()) |
| 255 | { |
| 256 | for(int i = 0; i < matrix.length; i++) |
| 257 | matrix[i] = Arrays.copyOf(matrix[i], newCols); |
| 258 | } |
| 259 | //now cols are equal, need to add or remove rows |
| 260 | matrix = Arrays.copyOf(matrix, newRows); |
| 261 | for(int i = oldRow; i < newRows; i++) |
| 262 | matrix[i] = new double[cols()]; |
| 263 | } |
| 264 | |
| 265 | private class BlockMultRun implements Runnable |
| 266 | { |