/** * 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 matrix elements as a group of parameters values. The number of parameters depends * on the matrix size. Only matrix elements different from their default value will be included * in this group. * * @param matrix The matrix to returns as a group of parameters. * @return A copy of the parameter values for this math transform. */ static ParameterValueGroup getParameterValues(final Matrix matrix) { final MatrixParameters values; values = (MatrixParameters) ProviderAffine.PARAMETERS.createValue(); values.setMatrix(matrix); return values; }
/** * Creates a new instance of {@linkplain MatrixParameters parameter values} with elements * initialized to the 1 on the diagonal, and 0 everywere else. The returned parameter group is * extensible, i.e. the number of elements will depends upon the value associated to the {@link * #numRow} and {@link #numCol numCol} parameters. * * @return A new parameter initialized to the default value. */ @Override public ParameterValueGroup createValue() { return new MatrixParameters(this); }
/** 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()); } } }
ensureNonNull("name", name); name = name.trim(); final MatrixParameterDescriptors descriptor = 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;
/** * Writes the content of this parameter to the specified table. * * @param table The table where to format the parameter value. * @throws IOException if an error occurs during output operation. */ @Override protected void write(final TableWriter table) throws IOException { table.write(getName(descriptor)); table.nextColumn(); table.write('='); table.nextColumn(); table.write(getMatrix().toString()); table.nextLine(); } }
if (parameters instanceof MatrixParameters) { return ((MatrixParameters) parameters).getMatrix();
/** * 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()); }
/** 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; }