Class MatrixCell

java.lang.Object
jline.util.matrix.MatrixCell
All Implemented Interfaces:
Serializable

public class MatrixCell extends Object implements Serializable
An ordered collection of Matrix objects that provides indexing and manipulation operations.

MatrixCell serves as a container for multiple Matrix instances, allowing them to be stored, retrieved, and operated upon as a group. This is particularly useful in scenarios where multiple related matrices need to be managed together, such as in matrix decompositions or iterative algorithms.

Key features:

  • Integer-indexed access to matrices
  • Support for matrix operations across all contained matrices
  • Automatic cloning for deep copy operations
  • Null-safe operations and cleanup utilities
Since:
1.0
Author:
QORE Lab, Imperial College London
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty MatrixCell with no initial capacity constraints.
    MatrixCell(int K)
    Creates an empty MatrixCell with a specified initial capacity.
    Creates a MatrixCell from an array of matrices.
    Creates a deep copy of another MatrixCell.
    Creates a MatrixCell containing exactly two matrices.
  • Method Summary

    Modifier and Type
    Method
    Description
    Computes the element-wise sum of all matrices in this cell.
    double
    cellsum(int row, int col)
    Computes the sum of elements at a specific position across all matrices in the cell.
    get(int i)
    Retrieves the matrix stored at the specified index.
    boolean
    Checks whether this MatrixCell contains any matrices.
    void
    Prints all matrices in the collection to the standard output.
    void
    remove(int i)
    Removes the matrix at the specified index.
    void
    Removes all null matrices from the collection.
    set(int i, Matrix D)
    Stores a matrix at the specified index.
    int
    Returns the number of matrices currently stored in this MatrixCell.
    Creates a copy of the internal mapping from indices to matrices.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MatrixCell

      public MatrixCell()
      Creates an empty MatrixCell with no initial capacity constraints.
    • MatrixCell

      public MatrixCell(MatrixCell x)
      Creates a deep copy of another MatrixCell. All matrices in the source MatrixCell are cloned to ensure independence.
      Parameters:
      x - the MatrixCell to copy
    • MatrixCell

      public MatrixCell(Matrix[] x)
      Creates a MatrixCell from an array of matrices. The matrices are stored with indices 0, 1, 2, ... corresponding to their array positions.
      Parameters:
      x - the array of matrices to store
    • MatrixCell

      public MatrixCell(int K)
      Creates an empty MatrixCell with a specified initial capacity.
      Parameters:
      K - the initial capacity for the underlying storage
    • MatrixCell

      public MatrixCell(Matrix D0, Matrix D1)
      Creates a MatrixCell containing exactly two matrices. This is a convenience constructor for the common case of matrix pairs.
      Parameters:
      D0 - the first matrix (stored at index 0)
      D1 - the second matrix (stored at index 1)
  • Method Details

    • cellsum

      public double cellsum(int row, int col)
      Computes the sum of elements at a specific position across all matrices in the cell. This operation is useful for aggregating corresponding elements from multiple matrices.
      Parameters:
      row - the row index
      col - the column index
      Returns:
      the sum of elements at position (row, col) across all matrices
    • cellsum

      public Matrix cellsum()
      Computes the element-wise sum of all matrices in this cell. Each matrix must have the same dimensions. The matrices are summed in the order of their integer keys (0 to N-1). The result is accumulated in-place for efficiency.
      Returns:
      A Matrix representing the element-wise sum of all matrices in the cell
      Throws:
      RuntimeException - if the cell is empty or if any matrices have incompatible dimensions
    • get

      public Matrix get(int i)
      Retrieves the matrix stored at the specified index.
      Parameters:
      i - the index of the matrix to retrieve
      Returns:
      the matrix at the specified index, or null if no matrix exists at that index
    • isEmpty

      public boolean isEmpty()
      Checks whether this MatrixCell contains any matrices.
      Returns:
      true if the MatrixCell is empty, false otherwise
    • print

      public void print()
      Prints all matrices in the collection to the standard output. Each matrix is printed using its own print() method.
    • remove

      public void remove(int i)
      Removes the matrix at the specified index.
      Parameters:
      i - the index of the matrix to remove
    • removeNull

      public void removeNull()
      Removes all null matrices from the collection. This method iterates backwards through the indices to safely remove entries without affecting the iteration process.
    • set

      public Matrix set(int i, Matrix D)
      Stores a matrix at the specified index. If a matrix already exists at that index, it is replaced.
      Parameters:
      i - the index at which to store the matrix
      D - the matrix to store
      Returns:
      the previous matrix at this index, or null if none existed
    • size

      public int size()
      Returns the number of matrices currently stored in this MatrixCell.
      Returns:
      the number of matrices in the collection
    • toMap

      public Map<Integer,Matrix> toMap()
      Creates a copy of the internal mapping from indices to matrices. This method provides access to the underlying data structure while maintaining encapsulation.
      Returns:
      a new Map containing copies of the index-to-matrix mappings