[DAPHNE-#811] Extension of EwBinaryMat and EwUnaryMat Kernels to Support Sparse and Dense Matrix Addition #812
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This draft pull request introduces an extension to the
EwBinaryMat
andEwUnaryMat
kernels to support efficient operations for matrix addition between dense and sparse matrices (see issue #811). The following kernels have been added:EwBinaryMat Kernels:
DenseMatrix <- CSRMatrix, DenseMatrix
DenseMatrix <- DenseMatrix, CSRMatrix
CSRMatrix <- CSRMatrix, DenseMatrix
EwUnaryMat Kernels:
CSRMatrix <- CSRMatrix
Implementation Details
As part of this implementation, a
resize
method was added to theCSRMatrix
class to dynamically handle the reallocation of memory when the number of non-zero elements exceeds the initially allocated space.Questions Regarding
resize
Method ImplementationThe
resize
method is essential for managing dynamic memory allocation within sparse matrices, especially when the number of non-zero elements increases during operations.Comparison with Dense Matrices: In some scenarios, the memory usage of a CSR matrix may approach or even exceed that of a dense matrix, particularly when the matrix is nearly dense or when the overhead from storing indices becomes significant. Is it advisable to dynamically adjust the size of the CSR matrix in these cases, considering that the most efficient representation should have already been chosen in a previous compiler pass?
Alternative Approaches: Are there alternative methods that could offer more efficiency in handling dynamic resizing, especially in the context of sparse matrices?