Class MatrixCell

  • All Implemented Interfaces:
    java.io.Serializable

    
    public class MatrixCell
     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

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      MatrixCell() Creates an empty MatrixCell with no initial capacity constraints.
      MatrixCell(MatrixCell x) Creates a deep copy of another MatrixCell.
      MatrixCell(Array<Matrix> x) Creates a MatrixCell from an array of matrices.
      MatrixCell(int K) Creates an empty MatrixCell with a specified initial capacity.
      MatrixCell(Matrix D0, Matrix D1) Creates a MatrixCell containing exactly two matrices.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      double cellsum(int row, int col) Computes the sum of elements at a specific position across all matrices in the cell.
      Matrix cellsum() Computes the element-wise sum of all matrices in this cell.
      Matrix get(int i) Retrieves the matrix stored at the specified index.
      boolean isEmpty() Checks whether this MatrixCell contains any matrices.
      void print() Prints all matrices in the collection to the standard output.
      void remove(int i) Removes the matrix at the specified index.
      void removeNull() Removes all null matrices from the collection.
      Matrix set(int i, Matrix D) Stores a matrix at the specified index.
      int size() Returns the number of matrices currently stored in this MatrixCell.
      Map<Integer, Matrix> toMap() 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 Detail

      • MatrixCell

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

        MatrixCell(MatrixCell x)
        Creates a deep copy of another MatrixCell.
        Parameters:
        x - the MatrixCell to copy
      • MatrixCell

        MatrixCell(Array<Matrix> x)
        Creates a MatrixCell from an array of matrices.
        Parameters:
        x - the array of matrices to store
      • MatrixCell

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

        MatrixCell(Matrix D0, Matrix D1)
        Creates a MatrixCell containing exactly two matrices.
        Parameters:
        D0 - the first matrix (stored at index 0)
        D1 - the second matrix (stored at index 1)
    • Method Detail

      • cellsum

         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

         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

      • get

         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

         boolean isEmpty()

        Checks whether this MatrixCell contains any matrices.

        Returns:

        true if the MatrixCell is empty, false otherwise

      • print

         void print()

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

      • remove

         void remove(int i)

        Removes the matrix at the specified index.

        Parameters:
        i - the index of the matrix to remove
      • removeNull

         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

         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

         int size()

        Returns the number of matrices currently stored in this MatrixCell.

        Returns:

        the number of matrices in the collection

      • toMap

         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