E
- The type of tensor element values.public class TensorParameters<E> extends Object implements Serializable
Each group of parameters contains the following elements:
"num_row"
in WKT 1)."num_col"
in WKT 1).num_row
× num_col
× … optional parameters for the matrix or tensor element values.
Parameter names depend on the formatting convention.Parameters are not an efficient storage format for large tensors.
Parameters are used only for small matrices/tensors to be specified in coordinate operations or processing libraries.
In particular, those parameters integrate well in Well Known Text (WKT) format.
For a more efficient matrix storage, see MatrixSIS
.
Those groups are extensible, i.e. the number ofParameter["num_row", 3], Parameter["num_col", 3], Parameter["elt_0_0", <value>], Parameter["elt_0_1", <value>], ... Parameter["elt_0_<num_col-1>", <value>], Parameter["elt_1_0", <value>], Parameter["elt_1_1", <value>], ... Parameter["elt_<num_row-1>_<num_col-1>", <value>]
"elt_row_col"
parameters
depends on the "num_row"
and "num_col"
parameter values. For this reason, the descriptor of
matrix or tensor parameters is not immutable.
WKT1
naming conventions,
on can use the following code:
Map<String,?> properties = Collections.singletonMap("name", "My operation"); ParameterValueGroup p = TensorParameters.WKT1.createValueGroup(properties);
Defined in the sis-referencing
module
Modifier and Type | Field and Description |
---|---|
protected String |
prefix
The prefix of parameter names for tensor elements.
|
protected String |
separator
The separator between row and column in parameter names for tensor elements.
|
static TensorParameters<Double> |
WKT1
Parses and creates parameters names for matrices matching the
Well Known Text
version 1 (WKT 1) convention.
|
Constructor and Description |
---|
TensorParameters(Class<E> elementType,
String prefix,
String separator,
ParameterDescriptor<Integer>... dimensions)
Constructs a descriptors provider.
|
Modifier and Type | Method and Description |
---|---|
protected ParameterDescriptor<E> |
createElementDescriptor(int[] indices)
Creates a new parameter descriptor for a matrix or tensor element at the given indices.
|
ParameterValueGroup |
createValueGroup(Map<String,?> properties)
Creates a new instance of parameter group with default values of 1 on the diagonal, and 0 everywhere else.
|
ParameterValueGroup |
createValueGroup(Map<String,?> properties,
Matrix matrix)
Creates a new instance of parameter group initialized to the given matrix.
|
boolean |
equals(Object other)
Compares this object with the given object for equality.
|
ParameterDescriptor<Integer> |
getDimensionDescriptor(int i)
Returns the parameter descriptor for the dimension at the given index.
|
ParameterDescriptor<E> |
getElementDescriptor(int... indices)
Returns the parameter descriptor for a matrix or tensor element at the given indices.
|
Class<E> |
getElementType()
Returns the type of tensor element values.
|
int |
hashCode()
Returns a hash code value for this object.
|
protected String |
indicesToName(int[] indices)
Returns the parameter descriptor name of a matrix or tensor element at the given indices.
|
protected int[] |
nameToIndices(String name)
Returns the indices of matrix element for the given parameter name, or
null if none. |
int |
rank()
Returns the rank of the tensor objects for which this instance will create parameters.
|
Matrix |
toMatrix(ParameterValueGroup parameters)
Constructs a matrix from a group of parameters.
|
public static final TensorParameters<Double> WKT1
"num_row"
."num_col"
."elt_row_col"
."elt_2_1"
is the element name for the value at line 2 and row 1.protected final String prefix
"elt_"
in WKT 1.protected final String separator
"_"
in WKT 1.public TensorParameters(Class<E> elementType, String prefix, String separator, ParameterDescriptor<Integer>... dimensions)
elementType
- The type of tensor element values.prefix
- The prefix to insert in front of parameter name for each tensor elements.separator
- The separator between dimension (row, column, …) indices in parameter names.dimensions
- The parameter for the size of each dimension, usually in an array of length 2.
Length may be different if the caller wants to generalize usage of this class to tensors.public final Class<E> getElementType()
public final int rank()
Rank | Type |
---|---|
0 | scalar |
1 | vector |
2 | matrix |
k | rank k tensor |
public final ParameterDescriptor<Integer> getDimensionDescriptor(int i)
i
- The dimension index, from 0 inclusive to rank()
exclusive.public final ParameterDescriptor<E> getElementDescriptor(int... indices)
indices
array shall be equals to the rank.
That length is usually 2, where indices[0]
is the row index and indices[1]
is the column index.indices
- The indices of the tensor element for which to get the descriptor.IllegalArgumentException
- If the given array does not have the expected length or have illegal value.protected ParameterDescriptor<E> createElementDescriptor(int[] indices) throws IllegalArgumentException
getElementDescriptor(int[])
when a new descriptor needs
to be created.
indicesToName(int[])
method, then creates a descriptor for an optional parameter
of that name.
indices
- The indices of the tensor element for which to create a parameter.IllegalArgumentException
- If the given array does not have the expected length or have illegal value.indicesToName(int[])
,
nameToIndices(String)
protected String indicesToName(int[] indices) throws IllegalArgumentException
nameToIndices(String)
method.
indices
array having a length equals to the rank. That length is usually 2, where indices[0]
is the row index and indices[1]
is
the column index. Then this method builds a name with the “prefix
+ row +
separator
+ column + …” pattern (e.g. "elt_0_0"
).
nameToIndices(String)
for parsing those names.indices
- The indices of the tensor element for which to create a parameter name.IllegalArgumentException
- If the given array does not have the expected length or have illegal value.protected int[] nameToIndices(String name) throws IllegalArgumentException
null
if none.
This method is the converse of indicesToName(int[])
.
prefix
+ row + separator
+
column + …” pattern and returns an array containing the row, column and other
indices, in that order.name
- The parameter name to parse.null
if the name is not recognized.IllegalArgumentException
- If the name has been recognized but an error occurred while parsing it
(e.g. an NumberFormatException
, which is an IllegalArgumentException
subclass).public ParameterValueGroup createValueGroup(Map<String,?> properties)
The properties map is given unchanged to the identified object constructor. The following table is a reminder of main (not all) properties:
Property name | Value type | Returned by |
---|---|---|
"name" | ReferenceIdentifier or String |
AbstractIdentifiedObject.getName() |
"alias" | GenericName or CharSequence (optionally as array) |
AbstractIdentifiedObject.getAlias() |
"identifiers" | ReferenceIdentifier (optionally as array) |
AbstractIdentifiedObject.getIdentifiers() |
"remarks" | InternationalString or String |
AbstractIdentifiedObject.getRemarks() |
properties
- The properties to be given to the identified object.public ParameterValueGroup createValueGroup(Map<String,?> properties, Matrix matrix)
properties
- The properties to be given to the identified object.matrix
- The matrix to copy in the new parameter group.public Matrix toMatrix(ParameterValueGroup parameters) throws InvalidParameterNameException
parameters
- The group of parameters.InvalidParameterNameException
- if a parameter name was not recognized.public int hashCode()
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.