/** * Constructs default values for the specified {@linkplain MatrixParameterDescriptors matrix * parameter descriptors}. * * @param descriptor The descriptor for this group of parameters. */ public MatrixParameters(final MatrixParameterDescriptors descriptor) { super(descriptor); numRow = Parameters.cast((ParameterValue) parameter(0), Integer.class); numCol = Parameters.cast((ParameterValue) parameter(1), Integer.class); }
/** * Returns the value in this group for a matrix element at the specified index. Row and column * index are 0 based. * * @param row The row indice. * @param column The column indice * @return The parameter value for the specified matrix element (never {@code null}). * @throws IndexOutOfBoundsException if {@code row} or {@code column} is out of bounds. */ public final ParameterValue<Double> parameter(final int row, final int column) throws IndexOutOfBoundsException { return parameter(row, column, numRow.intValue(), numCol.intValue()); }
final int row = Integer.parseInt(name.substring(prefix.length(), split)); final int col = Integer.parseInt(name.substring(split + 1)); return parameter(row, col); } catch (NumberFormatException exception) { cause = exception;
/** Returns a clone of this parameter group. */ @Override @SuppressWarnings("unchecked") public MatrixParameters clone() { final MatrixParameters copy = (MatrixParameters) super.clone(); if (copy.matrixValues != null) { copy.numRow = (ParameterValue) copy.parameter(0); copy.numCol = (ParameterValue) copy.parameter(1); copy.matrixValues = copy.matrixValues.clone(); for (int j = 0; j < copy.matrixValues.length; j++) { ParameterValue[] array = copy.matrixValues[j]; if (array != null) { copy.matrixValues[j] = array = array.clone(); for (int i = 0; i < array.length; i++) { if (array[i] != null) { array[i] = array[i].clone(); } } } } } return copy; }
/** Compare this object with the specified one for equality. */ @Override public boolean equals(final Object object) { if (object == this) { return true; // Slight optimization. } if (super.equals(object)) { final MatrixParameters that = (MatrixParameters) object; final int numRow = this.numRow.intValue(); final int numCol = this.numCol.intValue(); for (int j = 0; j < numRow; j++) { for (int i = 0; i < numCol; i++) { if (!Utilities.equals( this.parameter(j, i, numRow, numCol), that.parameter(j, i, numRow, numCol))) { return false; } } } return true; } return false; }
/** Tests the storage of matrix parameters. */ @Test public void testMatrixEdit() { final int size = 8; final Random random = new Random(47821365); final GeneralMatrix matrix = new GeneralMatrix(size); for (int j = 0; j < size; j++) { for (int i = 0; i < size; i++) { matrix.setElement(j, i, 200 * random.nextDouble() - 100); } } final MatrixParameterDescriptors descriptor = new MatrixParameterDescriptors(Collections.singletonMap("name", "Test")); for (int height = 2; height <= size; height++) { for (int width = 2; width <= size; width++) { MatrixParameters parameters = (MatrixParameters) descriptor.createValue(); GeneralMatrix copy = matrix.clone(); copy.setSize(height, width); parameters.setMatrix(copy); assertEquals( "height", height, ((Parameter) parameters.parameter("num_row")).intValue()); assertEquals( "width", width, ((Parameter) parameters.parameter("num_col")).intValue()); assertTrue("equals", copy.equals(parameters.getMatrix(), 0)); assertEquals("equals", parameters, parameters.clone()); } } }