final int row, final int column, final int numRow, final int numCol) throws IndexOutOfBoundsException { MatrixParameterDescriptors.checkIndice("row", row, numRow); MatrixParameterDescriptors.checkIndice("column", column, numCol); if (matrixValues == null) { matrixValues = new ParameterValue[numRow][]; new FloatParameter( ((MatrixParameterDescriptors) descriptor) .descriptor(row, column, numRow, numCol));
/** * Returns the parameters in this group. The number or elements is inferred from the {@linkplain * ParameterDescriptor#getDefaultValue default values} given to the {@link #numRow} and {@link * #numCol} parameters. * * @return The matrix parameters, including all elements. */ @Override public final List<GeneralParameterDescriptor> descriptors() { return descriptors( this.numRow.getDefaultValue().intValue(), this.numCol.getDefaultValue().intValue()); }
ensureNonNull("name", name); name = name.trim(); RuntimeException cause = null; final int row = Integer.parseInt(name.substring(prefix.length(), split)); final int col = Integer.parseInt(name.substring(split + 1)); return descriptor(row, col, numRow, numCol); } catch (NumberFormatException exception) { cause = exception;
/** * Implementation of the {@link #descriptors()} method. Returns the parameters in this group for * a matrix of the specified size. * * @param numRow The number of rows. * @param numCol The number of columns. * @return The matrix parameters, including all elements. */ final List<GeneralParameterDescriptor> descriptors(final int numRow, final int numCol) { final GeneralParameterDescriptor[] parameters = new GeneralParameterDescriptor[numRow * numCol + 2]; int k = 0; parameters[k++] = this.numRow; parameters[k++] = this.numCol; for (int j = 0; j < numRow; j++) { for (int i = 0; i < numCol; i++) { parameters[k++] = descriptor(j, i, numRow, numCol); } } assert k == parameters.length : k; return UnmodifiableArrayList.wrap(parameters); }
/** 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()); } } }
final int row, final int column, final int numRow, final int numCol) throws IndexOutOfBoundsException { checkIndice("row", row, numRow); checkIndice("column", column, numCol); int index = -1; ParameterDescriptor<Double> param;
/** * Constructs a parameter group. The properties map is given unchanged to the {@linkplain * AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}. The {@code * parameters} array should contains parameters <strong>other</strong> than matrix elements. The * first parameter is assumed to be the number of rows, and the second parameter the number of * columns. All extra parameters are ignored. * * @param properties Set of properties. Should contains at least {@code "name"}. * @param parameters The {@code "num_row"} and {@code "num_col"} parameters. * @param prefix The prefix to insert in front of parameter name for each matrix elements. * @param separator The separator between the row and the column index in parameter names. */ public MatrixParameterDescriptors( final Map<String, ?> properties, ParameterDescriptor<?>[] parameters, final String prefix, final char separator) { super(properties, parameters); if (parameters.length < 2) { // TODO: provide a localized message throw new IllegalArgumentException(); } numRow = Parameters.cast(parameters[0], Integer.class); numCol = Parameters.cast(parameters[1], Integer.class); ensureNonNull("prefix", prefix); this.prefix = prefix; this.separator = separator; }
/** * Creates a projective transform from the specified group of parameter values. * * @param values The group of parameter values. * @return The created math transform. * @throws ParameterNotFoundException if a required parameter was not found. */ protected MathTransform createMathTransform(final ParameterValueGroup values) throws ParameterNotFoundException { final MathTransform transform; transform = create(((MatrixParameterDescriptors) getParameters()).getMatrix(values)); return new Delegate( transform, getProvider(transform.getSourceDimensions(), transform.getTargetDimensions())); }
/** * Returns the parameter in this group for the specified name. The name can be a matrix element * if it uses the following syntax: <code>"elt_<var>row</var>_<var>col</var>"</code> where * {@code "elt_"} is the {@linkplain #prefix} for all matrix elements, and <var>row</var> and * <var>col</var> are row and column indices respectively. For example {@code "elt_2_1"} is the * element name for the value at line 2 and row 1. The row and column index are 0 based. * * @param name The case insensitive name of the parameter to search for. * @return The parameter for the given name. * @throws ParameterNotFoundException if there is no parameter for the given name. */ @Override @SuppressWarnings("unchecked") public final GeneralParameterDescriptor descriptor(final String name) throws ParameterNotFoundException { return descriptor( name, ((Number) numRow.getMaximumValue()).intValue(), ((Number) numCol.getMaximumValue()).intValue()); }
/** * Returns the parameter in this group for a matrix element at the specified index. row and * column indices are 0 based. Indices must be lower that the {@linkplain * ParameterDescriptor#getMaximumValue maximum values} given to the {@link #numRow} and {@link * #numCol} parameters. * * @param row The row indice. * @param column The column indice * @return The parameter descriptor for the specified matrix element. * @throws IndexOutOfBoundsException if {@code row} or {@code column} is out of bounds. */ @SuppressWarnings("unchecked") public final ParameterDescriptor<Double> descriptor(final int row, final int column) throws IndexOutOfBoundsException { return descriptor( row, column, ((Number) numRow.getMaximumValue()).intValue(), ((Number) numCol.getMaximumValue()).intValue()); }
/** * Returns the parameters descriptors in this group. The amount of parameters depends on the * value of <code>"num_row"</code> and <code>"num_col"</code> parameters. */ public List<GeneralParameterDescriptor> descriptors() { return ((MatrixParameterDescriptors) descriptor) .descriptors(numRow.intValue(), numCol.intValue()); }
/** * Returns the parameter in this group for the specified name. The name can be a matrix element * if it uses the following syntax: <code>"elt_<var>row</var>_<var>col</var>"</code> where * <code>"elt_"</code> is the {@linkplain MatrixParameterDescriptors#prefix prefix} for all * matrix elements, and <var>row</var> and <var>col</var> are row and column indices * respectively. For example <code>"elt_2_1"</code> is the element name for the value at line 2 * and row 1. The row and column index are 0 based. * * @param name The case insensitive name of the parameter to search for. * @return The parameter for the given name. * @throws ParameterNotFoundException if there is no parameter for the given name. */ public GeneralParameterDescriptor descriptor(final String name) throws ParameterNotFoundException { return ((MatrixParameterDescriptors) descriptor) .descriptor(name, numRow.intValue(), numCol.intValue()); }
for (int col = 0; col < numCol; col++) { final double element = matrix.getElement(row, col); ParameterDescriptor<Double> descriptor = matrixDescriptor.descriptor(row, col); final double value = descriptor.getDefaultValue(); if (Double.doubleToLongBits(element) == Double.doubleToLongBits(value)) {