# Class Matrix1

Object
MatrixSIS
Matrix1

All Implemented Interfaces:
  `Serializable, Cloneable, LenientComparable, Matrix`

public class Matrix1 extends MatrixSIS
A matrix of fixed 1×1 size, typically resulting from `MathTransform1D` derivative computation. The matrix member is:

>      ┌     ┐
>     │ m00 │
>     └     ┘

Since:
  0.4
See Also:
  - `Matrix2`
  - `Matrix3`
  - `Matrix4`
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `double`
  `m00`
  The only element in this matrix.
  `static final int`
  `SIZE`
  The matrix size, which is 1.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Matrix1()`
  Creates a new identity matrix.
  `Matrix1(double m00)`
  Creates a new matrix initialized to the specified value.
  `Matrix1(double[] elements)`
  Creates a new matrix initialized to the specified values.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Matrix1`
  `castOrCopy(Matrix matrix)`
  Casts or copies the given matrix to a `Matrix1` implementation.
  `Matrix1`
  `clone()`
  Returns a clone of this matrix.
  `boolean`
  `equals(Object object)`
  Returns `true` if the specified object is of type `Matrix1` and all of the data members are equal to the corresponding data members in this matrix.
  `final double`
  `getElement(int row, int column)`
  Retrieves the value at the specified row and column of this matrix.
  `final double[]`
  `getElements()`
  Returns all matrix elements in a flat, row-major (column indices vary fastest) array.
  `final int`
  `getNumCol()`
  Returns the number of columns in this matrix, which is always 1 in this implementation.
  `final int`
  `getNumRow()`
  Returns the number of rows in this matrix, which is always 1 in this implementation.
  `int`
  `hashCode()`
  Returns a hash code value based on the data values in this object.
  `MatrixSIS`
  `inverse()`
  Returns the inverse of this matrix.
  `final boolean`
  `isAffine()`
  Returns `true` if this matrix represents an affine transform.
  `final boolean`
  `isIdentity()`
  Returns `true` if this matrix is an identity matrix.
  `double[]`
  `multiply(double[] vector)`
  Returns a new vector which is the result of multiplying this matrix with the specified vector.
  `MatrixSIS`
  `normalizeColumns()`
  Normalizes all columns in-place.
  `final void`
  `setElement(int row, int column, double value)`
  Modifies the value at the specified row and column of this matrix.
  `final void`
  `setElements(double[] elements)`
  Sets all matrix elements from a flat, row-major (column indices vary fastest) array.
  `void`
  `transpose()`
  For a 1×1 matrix, this method does nothing.

  ### Methods inherited from class MatrixSIS

  `convertAfter, convertBefore, equals, equals, getNumber, multiply, removeColumns, removeRows, setMatrix, setNumber, solve, toString, translate`

  ### Methods inherited from class Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### SIZE

    public static final int SIZE
    The matrix size, which is 1.
    See Also:
      - Constant Field Values

  - ### m00

    public double m00
    The only element in this matrix.

- ## Constructor Details

  - ### Matrix1

    public Matrix1()
    Creates a new identity matrix.

  - ### Matrix1

    public Matrix1(double m00)
    Creates a new matrix initialized to the specified value.
    Parameters:
      `m00` - The element in this matrix.

  - ### Matrix1

    public Matrix1(double[] elements) throws IllegalArgumentException
    Creates a new matrix initialized to the specified values. The length of the given array must be 1.
    Parameters:
      `elements` - elements of the matrix.
    Throws:
      `IllegalArgumentException` - if the given array does not have the expected length.
    See Also:
      - `setElements(double[])`
      - `Matrices​.create(int, int, double[])`

- ## Method Details

  - ### castOrCopy

    public static Matrix1 castOrCopy(Matrix matrix) throws MismatchedMatrixSizeException
    Casts or copies the given matrix to a `Matrix1` implementation. If the given `matrix` is already an instance of `Matrix1`, then it is returned unchanged. Otherwise this method verifies the matrix size, then copies the element in a new `Matrix1` object.
    Parameters:
      `matrix` - the matrix to cast or copy, or `null`.
    Returns:
      the matrix argument if it can be safely cast (including `null` argument), or a copy of the given matrix otherwise.
    Throws:
      `MismatchedMatrixSizeException` - if the size of the given matrix is not 1×1.

  - ### getNumRow

    public final int getNumRow()
    Returns the number of rows in this matrix, which is always 1 in this implementation.
    Returns:
      always 1.

  - ### getNumCol

    public final int getNumCol()
    Returns the number of columns in this matrix, which is always 1 in this implementation.
    Returns:
      always 1.

  - ### getElement

    public final double getElement(int row, int column)
    Retrieves the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance of `Matrix1`, then the `m00` field can be read directly for efficiency.
    Parameters:
      `row` - the row index, which can only be 0.
      `column` - the column index, which can only be 0.
    Returns:
      the current value.

  - ### setElement

    public final void setElement(int row, int column, double value)
    Modifies the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance of `Matrix1`, then the `m00` field can be set directly for efficiency.
    Parameters:
      `row` - the row index, which can only be 0.
      `column` - the column index, which can only be 0.
      `value` - the new value to set.

  - ### getElements

    public final double[] getElements()
    Returns all matrix elements in a flat, row-major (column indices vary fastest) array. The array length is 1.
    Overrides:
      `getElements` in class `MatrixSIS`
    Returns:
      a copy of all current matrix elements in a row-major array.

  - ### setElements

    public final void setElements(double[] elements)
    Sets all matrix elements from a flat, row-major (column indices vary fastest) array. The array length shall be 1.
    Overrides:
      `setElements` in class `MatrixSIS`
    Parameters:
      `elements` - The new matrix elements in a row-major array.
    See Also:
      - `Matrices​.create(int, int, double[])`

  - ### isAffine

    public final boolean isAffine()
    Returns `true` if this matrix represents an affine transform. A transform is affine if the matrix is square and its last row contains only zeros, except in the last column which contains 1.
    Overrides:
      `isAffine` in class `MatrixSIS`
    Returns:
      `true` if this matrix represents an affine transform.
    See Also:
      - `Matrices​.isAffine(Matrix)`
      - `LinearTransform​.isAffine()`

  - ### isIdentity

    public final boolean isIdentity()
    Returns `true` if this matrix is an identity matrix. This method is equivalent to the following code, except that it is potentially more efficient:

        return Matrices.isIdentity(this, 0.0);

    Specified by:
      `isIdentity` in interface `Matrix`
    Specified by:
      `isIdentity` in class `MatrixSIS`
    Returns:
      `true` if this matrix is an identity matrix.
    See Also:
      - `Matrices​.isIdentity(Matrix, double)`
      - `AffineTransform​.isIdentity()`

  - ### transpose

    public void transpose()
    For a 1×1 matrix, this method does nothing.
    Specified by:
      `transpose` in class `MatrixSIS`

  - ### multiply

    public double[] multiply(double[] vector)
    Returns a new vector which is the result of multiplying this matrix with the specified vector. In other words, returns `this` × `vector`. The length of the given vector must be equal to the number of columns in this matrix, and the length of the returned vector will be equal to the number of rows in this matrix.

    #### Relationship with coordinate operations

    In the context of coordinate operations, `Matrix​.multiply(vector)` is related to `AffineTransform​.transform(…)` except that the last `vector` number is implicitly 1 in `AffineTransform` operations. While this `multiply(double[])` method could be used for coordinate transformation, it is not its purpose. This method is designed for occasional uses when accuracy is more important than performance.
    Overrides:
      `multiply` in class `MatrixSIS`
    Parameters:
      `vector` - the vector to multiply to this matrix.
    Returns:
      the result of `this` × `vector`.
    Since:
      1.5

  - ### inverse

    public MatrixSIS inverse() throws NoninvertibleMatrixException
    Returns the inverse of this matrix.
    Overrides:
      `inverse` in class `MatrixSIS`
    Returns:
      the inverse of this matrix.
    Throws:
      `NoninvertibleMatrixException` - if this matrix is not invertible.
    See Also:
      - `AffineTransform​.createInverse()`

  - ### normalizeColumns

    public MatrixSIS normalizeColumns()
    Normalizes all columns in-place. For a 1×1 matrix with non-NaN value, this method sets the `m00` value to +1, -1 or 0 with the same sign as the original value.
    Overrides:
      `normalizeColumns` in class `MatrixSIS`
    Returns:
      the magnitude of the column, which is the absolute value of `m00`.

  - ### clone

    public Matrix1 clone()
    Returns a clone of this matrix.
    Specified by:
      `clone` in interface `Matrix`
    Overrides:
      `clone` in class `MatrixSIS`
    Returns:
      a new matrix of the same class and with the same values as this matrix.
    See Also:
      - `Matrices​.copy(Matrix)`

  - ### equals

    public boolean equals(Object object)
    Returns `true` if the specified object is of type `Matrix1` and all of the data members are equal to the corresponding data members in this matrix.
    Specified by:
      `equals` in interface `LenientComparable`
    Overrides:
      `equals` in class `MatrixSIS`
    Parameters:
      `object` - the object to compare with this matrix for equality.
    Returns:
      `true` if the given object is equal to this matrix.
    See Also:
      - `ComparisonMode​.STRICT`

  - ### hashCode

    public int hashCode()
    Returns a hash code value based on the data values in this object.
    Overrides:
      `hashCode` in class `MatrixSIS`
    Returns:
      a hash code value for this matrix.