Package jline.util.matrix
Class MatrixCell
java.lang.Object
jline.util.matrix.MatrixCell
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionCreates an empty MatrixCell with no initial capacity constraints.MatrixCell(int K) Creates an empty MatrixCell with a specified initial capacity.MatrixCell(Matrix[] x) Creates a MatrixCell from an array of matrices.Creates a deep copy of another MatrixCell.MatrixCell(Matrix D0, Matrix D1) Creates a MatrixCell containing exactly two matrices. -
Method Summary
Modifier and TypeMethodDescriptioncellsum()Computes the element-wise sum of all matrices in this cell.doublecellsum(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.booleanisEmpty()Checks whether this MatrixCell contains any matrices.voidprint()Prints all matrices in the collection to the standard output.voidremove(int i) Removes the matrix at the specified index.voidRemoves all null matrices from the collection.Stores a matrix at the specified index.intsize()Returns the number of matrices currently stored in this MatrixCell.toMap()Creates a copy of the internal mapping from indices to matrices.
-
Constructor Details
-
MatrixCell
public MatrixCell()Creates an empty MatrixCell with no initial capacity constraints. -
MatrixCell
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
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
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 indexcol- the column index- Returns:
- the sum of elements at position (row, col) across all matrices
-
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
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
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 matrixD- 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
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
-