Class RealSparseMatrixGetSet
java.lang.Object
org.flag4j.operations.sparse.coo.real.RealSparseMatrixGetSet
This class provides methods for getting and setting elements and slices from/to a real sparse matrix.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static CooMatrix
addNotInCol
(List<Double> destEntries, List<Integer> destRowIndices, List<Integer> destColIndices, CooMatrix src, int colIdx) Adds values from a sparse matrix to specified lists if the value is not within a specified column.private static void
copyValuesNotInSlice
(CooMatrix src, List<Double> entries, List<Integer> rowIndices, List<Integer> colIndices, int[] rowRange, int[] colRange) Copies values in sparse matrix which do not fall in the specified row and column ranges.static CooVector
Gets a specified column from this sparse matrix.static CooVector
Gets a specified column range from this sparse matrix.static CooVector
Gets a specified row from this sparse matrix.static CooVector
Gets a specified row range from this sparse matrix.static CooMatrix
Gets a specified rectangular slice of a sparse matrix.private static boolean
inSlice
(int row, int col, int rowStart, int rowEnd, int colStart, int colEnd) Checks if an index is in the specified slice.static double
Gets the specified element from a sparse matrix.static CooMatrix
Sets the specified element from a sparse matrix.static CooMatrix
Sets a column of a sparse matrix to the entries of a dense array.static CooMatrix
Sets a column of a sparse matrix to the values in a sparse tensor.static CooMatrix
Sets a specified row of a real sparse matrix to the values of a dense array.static CooMatrix
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.private static CooMatrix
setSlice
(CooMatrix src, double[] values, int numRows, int numCols, int[] sliceRows, int[] sliceCols, int row, int col) Sets a slice of a sparse matrix to values given in a 1d dense array.static CooMatrix
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.static CooMatrix
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.static CooMatrix
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.static CooMatrix
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense matrix.static CooMatrix
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of another sparse matrix.
-
Constructor Details
-
RealSparseMatrixGetSet
private RealSparseMatrixGetSet()
-
-
Method Details
-
matrixGet
Gets the specified element from a sparse matrix.- Parameters:
src
- Source matrix to get value from.row
- Row index of the value to get from the sparse matrix.col
- Column index of the value to get from the sparse matrix.- Returns:
- The value in the sparse matrix at the specified indices.
-
matrixSet
Sets the specified element from a sparse matrix.- Parameters:
src
- Sparse matrix to set value in.row
- Row index of the value to set in the sparse matrix.col
- Column index of the value to set in the sparse matrix.value
- Value to set.- Returns:
- The
-
setRow
Sets a specified row of a real sparse matrix to the values of a dense array.- Parameters:
src
- Source matrix to set the row of.rowIdx
- Index of the row to set.row
- Dense array containing the entries of the row to set.- Returns:
- A copy of the
src
matrix with the specified row set to the denserow
array.
-
setCol
Sets a column of a sparse matrix to the entries of a dense array.- Parameters:
src
- Source matrix to set column of.colIdx
- The index of the column to set within thesrc
matrix.col
- The dense array containing the new column entries for thesrc
array.- Returns:
- A copy of the
src
matrix with the specified column set to the dense array. - Throws:
IllegalArgumentException
- If thecolIdx
is not within the range of the matrix.IllegalArgumentException
- If thecol
array does not have the same length as the number of rows insrc
matrix.
-
setCol
Sets a column of a sparse matrix to the values in a sparse tensor.- Parameters:
src
- Source matrix to set column of.colIdx
- Index of the column to set.col
- New entries for the specified column.- Returns:
- A copy of the
src
matrix with the specified column set to thecol
sparse vector. - Throws:
IllegalArgumentException
- If thesrc
matrix does not have the same number of rows as total entries in thecol
vector.
-
addNotInCol
private static CooMatrix addNotInCol(List<Double> destEntries, List<Integer> destRowIndices, List<Integer> destColIndices, CooMatrix src, int colIdx) Adds values from a sparse matrix to specified lists if the value is not within a specified column.- Parameters:
destEntries
- List to add non-zero entries from sparse matrix to.destRowIndices
- List to add non-zero row indices from sparse matrix to.destColIndices
- List to add non-zero column indices from sparse matrix to.src
- The sparse matrix to get non-zero values and indices from.colIdx
- Specified column to not add entries to the lists from.- Returns:
- A sparse matrix made from the resulting
destEntries, destRowIndices
anddestColIndices
lists.
-
setSlice
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of another sparse matrix.- Parameters:
src
- Source sparse matrix to copy and set values of.values
- Values of the slice to be set.row
- Starting row index of slice.col
- Starting column index of slice.- Returns:
- A copy of the
src
matrix with the specified slice set to thevalues
matrix. - Throws:
IllegalArgumentException
- If thevalues
matrix does not fit in thesrc
matrix given the row and column index.
-
setSlice
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.- Parameters:
src
- Source sparse matrix to copy and set values of.values
- Dense values of the slice to be set.row
- Starting row index of slice.col
- Starting column index of slice.- Returns:
- A copy of the
src
matrix with the specified slice set to thevalues
array. - Throws:
IllegalArgumentException
- If thevalues
array does not fit in thesrc
matrix given the row and column index.
-
setSlice
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense matrix.- Parameters:
src
- Source sparse matrix to copy and set values of.values
- Dense matrix containing values of the slice to be set.row
- Starting row index of slice.col
- Starting column index of slice.- Returns:
- A copy of the
src
matrix with the specified slice set to thevalues
array. - Throws:
IllegalArgumentException
- If thevalues
array does not fit in thesrc
matrix given the row and column index.
-
setSlice
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.- Parameters:
src
- Source sparse matrix to copy and set values of.values
- Dense values of the slice to be set.row
- Starting row index of slice.col
- Starting column index of slice.- Returns:
- A copy of the
src
matrix with the specified slice set to thevalues
array. - Throws:
IllegalArgumentException
- If thevalues
array does not fit in thesrc
matrix given the row and column index.
-
setSlice
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.- Parameters:
src
- Source sparse matrix to copy and set values of.values
- Dense values of the slice to be set.row
- Starting row index of slice.col
- Starting column index of slice.- Returns:
- A copy of the
src
matrix with the specified slice set to thevalues
array. - Throws:
IllegalArgumentException
- If thevalues
array does not fit in thesrc
matrix given the row and column index.
-
setSlice
Copies a sparse matrix and sets a slice of the sparse matrix to the entries of a dense array.- Parameters:
src
- Source sparse matrix to copy and set values of.values
- Dense values of the slice to be set.row
- Starting row index of slice.col
- Starting column index of slice.- Returns:
- A copy of the
src
matrix with the specified slice set to thevalues
array. - Throws:
IllegalArgumentException
- If thevalues
array does not fit in thesrc
matrix given the row and column index.
-
setSlice
private static CooMatrix setSlice(CooMatrix src, double[] values, int numRows, int numCols, int[] sliceRows, int[] sliceCols, int row, int col) Sets a slice of a sparse matrix to values given in a 1d dense array.- Parameters:
src
- Source sparse matrix to copy non-slice from.values
- Dense value for slice.numRows
- Number of rows in the matrix represented byvalues
.numCols
- Number of columns in the matrix represented byvalues
.sliceRows
- Row indices for slice.sliceCols
- Column indices for slice.row
- Starting row index of slice.col
- Starting column index of slice.- Returns:
- A copy of the
src
matrix with the specified slice set to the specified values.
-
getRow
-
getRow
Gets a specified row range from this sparse matrix.- Parameters:
src
- Source sparse matrix to extract row from.rowIdx
- Index of the row to extract from thesrc
matrix.start
- Staring column index of the column to be extracted (inclusive).end
- Ending column index of the column to be extracted (exclusive)- Returns:
- Returns the specified column range from this sparse matrix.
-
getCol
-
getCol
Gets a specified column range from this sparse matrix.- Parameters:
src
- Source sparse matrix to extract column from.colIdx
- Index of the column to extract from thesrc
matrix.start
- Staring row index of the column to be extracted (inclusive).end
- Ending row index of the column to be extracted (exclusive)- Returns:
- Returns the specified column range from this sparse matrix.
-
getSlice
Gets a specified rectangular slice of a sparse matrix.- Parameters:
src
- Sparse matrix to extract slice from.rowStart
- Starting row index of the slice (inclusive).rowEnd
- Ending row index of the slice (exclusive).colStart
- Staring column index of a slice (inclusive).colEnd
- Ending column index of the slice (exclusive).- Returns:
- The specified slice of the sparse matrix.
-
inSlice
private static boolean inSlice(int row, int col, int rowStart, int rowEnd, int colStart, int colEnd) Checks if an index is in the specified slice.- Parameters:
row
- Row index of value.col
- Column index of value.rowStart
- Starting row index of slice (inclusive).rowEnd
- Ending row index of slice (exclusive).colStart
- Starting column index of slice (inclusive).colEnd
- Ending column index of slice (exclusive).- Returns:
- True if the indices are in the slice. False otherwise.
-
copyValuesNotInSlice
private static void copyValuesNotInSlice(CooMatrix src, List<Double> entries, List<Integer> rowIndices, List<Integer> colIndices, int[] rowRange, int[] colRange) Copies values in sparse matrix which do not fall in the specified row and column ranges.- Parameters:
src
- Source sparse matrix to copy from.entries
- Destination list to add copied values to.rowIndices
- Destination list to add copied row indices to.colIndices
- Destination list to add copied column indices to.rowRange
- List of row indices to NOT copy from.colRange
- List of column indices to NOT copy from.
-