MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / changeSize

Method changeSize

JSAT/src/jsat/linear/DenseMatrix.java:245–263  ·  view source on GitHub ↗
(int newRows, int newCols)

Source from the content-addressed store, hash-verified

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 {

Callers 1

testChangeSizeMethod · 0.95

Calls 2

colsMethod · 0.95
copyOfMethod · 0.80

Tested by 1

testChangeSizeMethod · 0.76