jvx.numeric

## Class PnSparseMatrix

- java.lang.Object
- - jv.object.PsObject
  - - jvx.numeric.PnSparseMatrix

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, PsUpdateIf, PdMatrixIf
  Direct Known Subclasses:
    PnStiffMatrix

      public class PnSparseMatrix
      extends PsObject
      implements PdMatrixIf

  Sparse matrix representation.

  Class was extracted from earlier code in jvx.numeric.PnStiffMatrix.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `USE_LARGER_BUFFER` Flag, whether the buffer should enlarged dynamically.

    - ### Fields inherited from class jv.object.PsObject

      `HAS_BOUNDARY_PANEL, HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_LABEL_PANEL, HAS_MATERIAL_PANEL, HAS_TEXTURE_PANEL, HAS_VECTOR_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_FOCUSSED, IS_PICKED, IS_SELECTED, IS_USED, NUM_TAGS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PnSparseMatrix()` Constructor.
    `PnSparseMatrix(int iSize, int jSize)` Constructor with initial matrix sizes.
    `PnSparseMatrix(int iSize, int jSize, int bufferSize)` Constructor with initial matrix sizes and buffer size.
    `PnSparseMatrix(PdMatrix m)` Create a sparse Matrix from a PdMatrix.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(PnSparseMatrix m)` Add another sparse matrix to this matrix.
    `void` | `add(PnSparseMatrix m1, PnSparseMatrix m2)` Set this = m1+m2.
    `void` | `addDiagonal(double d)` Add the given value to every diagonal element of the matrix.
    `void` | `addDiagonal(PdVector diag)` Add a given diagonal matrix to this.
    `void` | `addEntry(int i, int j, double value)` Add value to the entry (i, j) of this matrix.
    `static PnSparseMatrix` | `addNew(PnSparseMatrix A, PnSparseMatrix B)` Return a new matrix that is the sum of A and B.
    `void` | `appendEntry(int i, int j, double value)` Appends an entry to row i.
    `void` | `clear()` Set all elements of the matrix to 0.
    `void` | `clearRow(int rowInd)` Set all entries in specified row to 0.
    `void` | `compress()` Compress this stiff matrix that only values not equal zero remain.
    `void` | `concatMatrices(PnSparseMatrix ma, PnSparseMatrix mb, PnSparseMatrix mc, PnSparseMatrix md)` Concatenates 4 matrices to a bigger one of the form this = ((ma, mb), (mc, md)).
    `void` | `copy(PnSparseMatrix A)` Copy the sparse matrix A into this.
    `static PnSparseMatrix` | `copyNew(PnSparseMatrix A)` Return a copy of the argument matrix A.
    `void` | `deleteColumn(int col)` Delete the col-th row from the sparse matrix.
    `void` | `deleteRow(int i)` Delete the i-th row from the sparse matrix.
    `int` | `getColIndex(int i, int j)` Get the index of the column for the j.th entry in the i.th row.
    `PiVector[]` | `getColIndices()` Get an array with the column indices of the entries in the matrix.
    `PiVector` | `getColIndices(int i)` Get the column indices of the i.th row of the matrix.
    `int` | `getDiagIndex(int n)` Get the index of the n-th diagonal element.
    `PdVector[]` | `getEntries()` Get the array with all non-zero entries of the matrix.
    `PdVector` | `getEntries(int i)` Get the i.th row of the matrix.
    `double` | `getEntry(int i, int j)` Get the (i,j) entry of the matrix.
    `double` | `getEntrySparse(int i, int jInd)` Get the entry in row i at position jInd in the stiffness array.
    `int` | `getIndex(int aLine, int anIndex)` For given component s[aLine][aColumn] of the full matrix s this method finds the position in the index vector m_sindx[aLine] of the row aLine which refers to the full matrix component.
    `int` | `getNumCols()` Get number of columns of full matrix.
    `PiVector` | `getNumEntries()` Get the number of non-zero entries for all rows.
    `int` | `getNumEntries(int i)` Get the number of non-zero entries in the i.th row.
    `int` | `getNumRows()` Get number of rows of full matrix.
    `boolean` | `isSquare()` Whether numRows == numColumns.
    `PdVector` | `leftMultMatrix(PdVector out, PdVector in)` Multiply this matrix with vector and fill output vector, `out = this*in.`
    `PdVector` | `leftMultVector(PdVector in, PdVector out)` Deprecated.
    `PdVector` | `leftMultVector(PdVector in, PdVector out, int dim)` Compute out=in*smat.
    `static PdVector` | `leftMultVector(PnSparseMatrix smat, PdVector in, PdVector out)` Compute out=in*smat.
    `static PdVector` | `leftMultVector(PnSparseMatrix smat, PdVector in, PdVector out, int dim)` Compute out=in*smat.
    `static PnSparseMatrix` | `multMatrices(PnSparseMatrix left, PnSparseMatrix right, PnSparseMatrix out)` Multiply two sparse matrices, out = left.right.
    `double` | `multQuadratic(PdVector left, PdVector right)` Compute left^T*this*right.
    `void` | `multScalar(double scalar)` Multiply the matrix by a scalar value.
    `static PnSparseMatrix` | `multScalar(PnSparseMatrix smat, double scalar)` Multiply each entry of the matrix by a scalar value.
    `void` | `removeZeros(double eps)` Remove entries which are 0 up to a given tolerance.
    `PdVector` | `rightMultMatrix(PdVector out, PdVector in)` Multiply this matrix with vector and fill output vector, `out = in*this.`
    `PdVector` | `rightMultVector(PdVector in, PdVector out)` Deprecated.
    `PdVector` | `rightMultVector(PdVector in, PdVector out, int dim)` Compute out=smat*in.
    `static PdVector` | `rightMultVector(PnSparseMatrix smat, PdVector in, PdVector out)` Compute out=smat*in.
    `static PdVector` | `rightMultVector(PnSparseMatrix smat, PdVector in, PdVector out, int dim)` Compute out=smat*in.
    `void` | `setEntry(int i, int j, double value)` Set the entry (i, j) to a specific value.
    `void` | `setEntrySparse(int i, int jInd, double value)` Set the entry in row i at position jInd in the stiffness array.
    `void` | `setNumEntries(int i, int numEntries)` Set number of non-zero entries in row i.
    `void` | `setRow(int rowInd, int numEntries, PiVector colIndex, PdVector stiff)` Set a row of the matrix.
    `void` | `setSize(int size)` Set number of rows and number of columns to size.
    `void` | `setSize(int iSize, int jSize)` Set size of the matrix.
    `void` | `setSize(int numRows, int numCols, int bufferSize)` Set size and buffer of the matrix.
    `void` | `sortEntries()` Sort the sparse arrays (representing the rows) by their column indices.
    `void` | `sub(PnSparseMatrix m)` Subtract another sparse matrix from this matrix.
    `static PnSparseMatrix` | `subNew(PnSparseMatrix A, PnSparseMatrix B)` Return a new matrix A-B.
    `PdMatrix` | `toPdMatrix()` Convert the sparse matrix into a dense PdMatrix.
    `java.lang.String` | `toShortString()` Create a full matrix and print all components in a short multi-line string representation.
    `java.lang.String` | `toString()` Create a full matrix and print all components in a multi-line string representation.
    `void` | `transpose()` Transpose this sparse matrix.
    `void` | `transpose(PnSparseMatrix transpose)` Transpose a sparse matrix.
    `PnSparseMatrix` | `transposeNew()` Transpose a sparse matrix.
    `static PnSparseMatrix` | `transposeNew(PnSparseMatrix pm)` Transpose the sparse matrix.
    `void` | `validate()` Ensures, that the matrix is in a valid state.

    - ### Methods inherited from class jv.object.PsObject

      `addInspector, addUpdateListener, assureInspector, clearTag, clone, clone, clone, copy, getFather, getInfoPanel, getInspector, getName, getNumObjects, getSymbol, hasInspector, hasTag, hasUpdateListener, init, instanceOf, instanceOf, newInspector, newInspector, removeInspector, removeInspector, removeUpdateListener, setName, setParent, setSymbol, setTag, update, updatePanels`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### USE_LARGER_BUFFER

          public static final boolean USE_LARGER_BUFFER

      Flag, whether the buffer should enlarged dynamically.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PnSparseMatrix

          public PnSparseMatrix()

      Constructor.

    - #### PnSparseMatrix

          public PnSparseMatrix(int iSize,
                        int jSize)

      Constructor with initial matrix sizes.

    - #### PnSparseMatrix

          public PnSparseMatrix(int iSize,
                        int jSize,
                        int bufferSize)

      Constructor with initial matrix sizes and buffer size. Each row is assured to have at least bufferSize entries (some of them are possibly invisible from outside). The methods appendEntry() and addEntry() use these virtual entries for not reallocate memory each time.

    - #### PnSparseMatrix

          public PnSparseMatrix(PdMatrix m)

      Create a sparse Matrix from a PdMatrix. Only values greater than PuMath.EPS are used.

  - ### Method Detail

    - #### getNumRows

          public int getNumRows()

      Get number of rows of full matrix.
      Specified by:
        `getNumRows` in interface `PdMatrixIf`

    - #### getNumCols

          public int getNumCols()

      Get number of columns of full matrix.
      Specified by:
        `getNumCols` in interface `PdMatrixIf`

    - #### setSize

          public void setSize(int iSize,
                     int jSize)

      Set size of the matrix.

    - #### setSize

          public void setSize(int numRows,
                     int numCols,
                     int bufferSize)

      Set size and buffer of the matrix. This method assures that each row has at least bufferSize entries (some of them are possibly invisible from outside). The methods appendEntry() and addEntry() use these virtual entries for not reallocate memory each time.

    - #### setSize

          public void setSize(int size)

      Set number of rows and number of columns to size.

    - #### setNumEntries

          public void setNumEntries(int i,
                           int numEntries)

      Set number of non-zero entries in row i.

    - #### getEntries

          public PdVector[] getEntries()

      Get the array with all non-zero entries of the matrix.

    - #### getEntries

          public PdVector getEntries(int i)

      Get the i.th row of the matrix.

    - #### getEntrySparse

          public double getEntrySparse(int i,
                              int jInd)

      Get the entry in row i at position jInd in the stiffness array. The column position of this entry can be obtained by getColIndices(i).

    - #### getEntry

          public double getEntry(int i,
                        int j)

      Get the (i,j) entry of the matrix.
      Specified by:
        `getEntry` in interface `PdMatrixIf`

    - #### getNumEntries

          public PiVector getNumEntries()

      Get the number of non-zero entries for all rows.

    - #### getNumEntries

          public int getNumEntries(int i)

      Get the number of non-zero entries in the i.th row.

    - #### getColIndices

          public PiVector[] getColIndices()

      Get an array with the column indices of the entries in the matrix.

    - #### getColIndices

          public PiVector getColIndices(int i)

      Get the column indices of the i.th row of the matrix.

    - #### getColIndex

          public int getColIndex(int i,
                        int j)

      Get the index of the column for the j.th entry in the i.th row.

    - #### setRow

          public void setRow(int rowInd,
                    int numEntries,
                    PiVector colIndex,
                    PdVector stiff)

      Set a row of the matrix.

    - #### isSquare

          public boolean isSquare()

      Whether numRows == numColumns.
      Specified by:
        `isSquare` in interface `PdMatrixIf`

    - #### setEntry

          public void setEntry(int i,
                      int j,
                      double value)

      Set the entry (i, j) to a specific value.
      Note: This methods do a linear search through the matrix row i. If no entry (i, j) was found, then a new entry will be appended to row i. The entries in this row are then not necessarily sorted by their column index. Call validate() to ensure a valid state of the matrix.
      Specified by:
        `setEntry` in interface `PdMatrixIf`

    - #### setEntrySparse

          public void setEntrySparse(int i,
                            int jInd,
                            double value)

      Set the entry in row i at position jInd in the stiffness array. The column position of this entry can be obtained by getColIndices(i).

    - #### addEntry

          public void addEntry(int i,
                      int j,
                      double value)

      Add value to the entry (i, j) of this matrix.
      The matrix rows are possibly not sorted after a call of this method. Call validate() to ensure a valid state of the matrix.
      Specified by:
        `addEntry` in interface `PdMatrixIf`

    - #### copy

          public void copy(PnSparseMatrix A)

      Copy the sparse matrix A into this.
      Parameters:
        `A` -

    - #### copyNew

          public static PnSparseMatrix copyNew(PnSparseMatrix A)

      Return a copy of the argument matrix A.
      Returns:
        A copy of the argument matrix A.

    - #### addNew

          public static PnSparseMatrix addNew(PnSparseMatrix A,
                              PnSparseMatrix B)

      Return a new matrix that is the sum of A and B. Both matrices (A and B) must be valid.
      Returns:
        A new matrix that is the sum of A and B.

    - #### subNew

          public static PnSparseMatrix subNew(PnSparseMatrix A,
                              PnSparseMatrix B)

      Return a new matrix A-B. Both matrices (A and B) must be valid.
      Returns:
        A new matrix M = A - B.

    - #### compress

          public void compress()

      Compress this stiff matrix that only values not equal zero remain.

    - #### toPdMatrix

          public PdMatrix toPdMatrix()

      Convert the sparse matrix into a dense PdMatrix.
      Returns:
        PdMatrix of the sparse matrix

    - #### getIndex

          public int getIndex(int aLine,
                     int anIndex)

      For given component s[aLine][aColumn] of the full matrix s this method finds the position in the index vector m_sindx[aLine] of the row aLine which refers to the full matrix component. If position is not found, then the component is added to the index vector by appending the value aColumn.

      This method is the central method for handling the sparse matrix representation.

      The matrix rows are possibly not sorted after a call of this method. Call validate() to ensure a valid state of the matrix.

    - #### appendEntry

          public void appendEntry(int i,
                         int j,
                         double value)

      Appends an entry to row i.
      Note: This method will not check if there is already an entry j in row i. Furthermore, row i will not be sorted by column indices. Call validate() to ensure a valid state of the matrix.

    - #### toString

          public java.lang.String toString()

      Create a full matrix and print all components in a multi-line string representation.
      Overrides:
        `toString` in class `PsObject`

    - #### toShortString

          public java.lang.String toShortString()

      Create a full matrix and print all components in a short multi-line string representation.

    - #### rightMultVector

          public PdVector rightMultVector(PdVector in,
                                 PdVector out,
                                 int dim)

      Compute out=smat*in. The arrays in and out must have length = dim*(dim of smat). The array in usually contains the position of vertices, listing all coordinates of one vertex before the next. Setting dim = dim of vertices allows to multiply each coordinate of the vertices with smat.

      If the vector out is null, a new vector is created.

    - #### rightMultVector

          public PdVector rightMultVector(PdVector in,
                                 PdVector out)

      Deprecated.
      Compute out=smat*in. If the vector out is null, a new vector is created.

    - #### leftMultMatrix

          public PdVector leftMultMatrix(PdVector out,
                                PdVector in)

      Description copied from interface: `PdMatrixIf`
      Multiply this matrix with vector and fill output vector, `out = this*in.`. Matrix need not be square. Input vector must have same size as number of columns of this matrix. Method modifies size of output vector to number of rows of this matrix. If output vector is null then it is created.
      Specified by:
        `leftMultMatrix` in interface `PdMatrixIf`

    - #### rightMultVector

          public static PdVector rightMultVector(PnSparseMatrix smat,
                                 PdVector in,
                                 PdVector out,
                                 int dim)

      Compute out=smat*in. If the vector out is null, a new vector is created.

    - #### rightMultVector

          public static PdVector rightMultVector(PnSparseMatrix smat,
                                 PdVector in,
                                 PdVector out)

      Compute out=smat*in. If the vector out is null, a new vector is created.

    - #### leftMultVector

          public static PdVector leftMultVector(PnSparseMatrix smat,
                                PdVector in,
                                PdVector out,
                                int dim)

      Compute out=in*smat. The arrays in and out must have length >= dim*(dim of smat). The array in usually contains the position of vertices, listing all coordinates of one vertex before the next. Setting dim equal to dim of vertices allows to multiply each coordinate of the vertices with smat.

      If the vector out is null, a new vector is created.

    - #### leftMultVector

          public PdVector leftMultVector(PdVector in,
                                PdVector out,
                                int dim)

      Compute out=in*smat. If the vector out is null, a new vector is created.

    - #### leftMultVector

          public PdVector leftMultVector(PdVector in,
                                PdVector out)

      Deprecated.
      Compute out=in*smat. If the vector out is null, a new vector is created.

    - #### rightMultMatrix

          public PdVector rightMultMatrix(PdVector out,
                                 PdVector in)

      Description copied from interface: `PdMatrixIf`
      Multiply this matrix with vector and fill output vector, `out = in*this.`. Matrix need not be square. Input vector must have same size as number of rows of this matrix. Method modifies size of output vector to number of columns of this matrix. If output vector is null then it is created.
      Specified by:
        `rightMultMatrix` in interface `PdMatrixIf`

    - #### leftMultVector

          public static PdVector leftMultVector(PnSparseMatrix smat,
                                PdVector in,
                                PdVector out)

      Compute out=in*smat. If the vector out is null, a new vector is created.

    - #### getDiagIndex

          public int getDiagIndex(int n)

      Get the index of the n-th diagonal element.
      Parameters:
        `n` -
      Returns:
        index

    - #### transposeNew

          public PnSparseMatrix transposeNew()

      Transpose a sparse matrix.
      Returns:
        a new PnSparseMatrix instance, which is transpose of the actual matrix.

    - #### transpose

          public void transpose(PnSparseMatrix transpose)

      Transpose a sparse matrix. The given matrix "transpose" is transposed and stored in this.
      Parameters:
        `transpose` - Matrix to be transposed.

    - #### transpose

          public void transpose()

      Transpose this sparse matrix.
      Specified by:
        `transpose` in interface `PdMatrixIf`

    - #### multMatrices

          public static PnSparseMatrix multMatrices(PnSparseMatrix left,
                                    PnSparseMatrix right,
                                    PnSparseMatrix out)

      Multiply two sparse matrices, out = left.right.
      Returns:
        the matrix out is returned

    - #### validate

          public void validate()

      Ensures, that the matrix is in a valid state. I.e. for each row, the entries are sorted by their column index. Entries with the same column index will be summed up. Entries with a ColIndex out of range will be removed.

    - #### removeZeros

          public void removeZeros(double eps)

      Remove entries which are 0 up to a given tolerance.

    - #### transposeNew

          public static PnSparseMatrix transposeNew(PnSparseMatrix pm)

      Transpose the sparse matrix.
      Parameters:
        `pm` - the sparse matrix to transpose
      Returns:
        a new PnSparseMatrix instace of the transpose matrix

    - #### add

          public void add(PnSparseMatrix m)

      Add another sparse matrix to this matrix. Both matrices (this and m) have to be valid. Call validate() before.

    - #### sub

          public void sub(PnSparseMatrix m)

      Subtract another sparse matrix from this matrix. Both matrices (this and m) have to be valid.

    - #### add

          public void add(PnSparseMatrix m1,
                 PnSparseMatrix m2)

      Set this = m1+m2. Both matrices (m1 and m2) have to be valid. Call validate() before.

    - #### addDiagonal

          public void addDiagonal(double d)

      Add the given value to every diagonal element of the matrix. Works only for square matrices.

    - #### addDiagonal

          public void addDiagonal(PdVector diag)

      Add a given diagonal matrix to this. Works only for square matrices.
      Parameters:
        `diag` - Diagonal entries of the matrix.

    - #### multScalar

          public void multScalar(double scalar)

      Multiply the matrix by a scalar value.
      Specified by:
        `multScalar` in interface `PdMatrixIf`

    - #### clear

          public void clear()

      Set all elements of the matrix to 0.
      Specified by:
        `clear` in interface `PdMatrixIf`

    - #### concatMatrices

          public void concatMatrices(PnSparseMatrix ma,
                            PnSparseMatrix mb,
                            PnSparseMatrix mc,
                            PnSparseMatrix md)

      Concatenates 4 matrices to a bigger one of the form this = ((ma, mb), (mc, md)).

      The matrices (mb, md) or (mc, md) may be null if only two matrices should be concatenated.

    - #### deleteRow

          public void deleteRow(int i)

      Delete the i-th row from the sparse matrix.
      Parameters:
        `i` - Row index.

    - #### deleteColumn

          public void deleteColumn(int col)

      Delete the col-th row from the sparse matrix.
      Parameters:
        `col` - Row index.

    - #### multQuadratic

          public double multQuadratic(PdVector left,
                             PdVector right)

      Compute left^T*this*right. The matrix is interpreted as a quadratic form.
      Specified by:
        `multQuadratic` in interface `PdMatrixIf`
      Parameters:
        `left` - The left argument.
        `right` - The right argument.
      Returns:
        left^T*this*right.

    - #### multScalar

          public static PnSparseMatrix multScalar(PnSparseMatrix smat,
                                  double scalar)

      Multiply each entry of the matrix by a scalar value.
      Returns:
        the given matrix smat is returned.

    - #### sortEntries

          public void sortEntries()

      Sort the sparse arrays (representing the rows) by their column indices.

    - #### clearRow

          public void clearRow(int rowInd)

      Set all entries in specified row to 0.

"

The software JavaView? is copyright protected. All Rights Reserved.
"