Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

Adds support for sparse + dense matrix addition, returning a dense matrix consistent with standard Julia SparseArrays behavior.

Implementation

  • Core interface (src/core.jl): Generic +(A::AbstractDeviceSparseMatrix, B::DenseMatrix) with commutative variant, including dimension and backend compatibility checks

  • Format-specific kernels: Backend-agnostic kernels for CSC, CSR, and COO formats that efficiently iterate only over sparse elements:

    • kernel_add_sparse_to_dense_csc! - column-wise iteration
    • kernel_add_sparse_to_dense_csr! - row-wise iteration
    • kernel_add_sparse_to_dense_coo! - element-wise iteration
  • Helper functions: _add_sparse_to_dense! for each sparse format dispatches to appropriate kernel

  • Tests: 54 tests covering all formats (CSC, CSR, COO) and backends (Array, JLArray), including commutativity and dimension validation

  • Benchmarks: Added benchmark_sparse_dense_add! function to measure performance across all sparse formats (CSC, CSR, COO) and backends (Array, JLArray) with N×N matrices at 1% density (default N=10000)

Usage

using DeviceSparseArrays, SparseArrays

A = DeviceSparseMatrixCSC(sprand(100, 80, 0.1))
B = rand(100, 80)

C = A + B  # Returns dense Matrix{Float64}
C = B + A  # Commutative

Works identically across all sparse formats and backends (CPU, GPU, accelerators).

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement sum between AbstractDeviceSparseMatrix and DenseMatrix</issue_title>
<issue_description>Implement the method +(A::AbstractDeviceSparseMatrix, B::DenseMatrix) efficiently.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 11, 2025 23:59
Co-authored-by: albertomercurio <61953577+albertomercurio@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement sum method for AbstractDeviceSparseMatrix and DenseMatrix Implement addition between AbstractDeviceSparseMatrix and DenseMatrix Nov 12, 2025
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 72.50000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.09%. Comparing base (83f15ad) to head (93496de).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/matrix_csc/matrix_csc_kernels.jl 20.00% 4 Missing ⚠️
src/matrix_csr/matrix_csr_kernels.jl 20.00% 4 Missing ⚠️
src/matrix_coo/matrix_coo_kernels.jl 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #21      +/-   ##
==========================================
- Coverage   85.92%   85.09%   -0.84%     
==========================================
  Files          11       11              
  Lines         604      644      +40     
==========================================
+ Hits          519      548      +29     
- Misses         85       96      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@albertomercurio albertomercurio marked this pull request as ready for review November 12, 2025 07:41
@albertomercurio
Copy link
Owner

@copilot could you add also the benchmarks, following the same structure of the existing ones?

Co-authored-by: albertomercurio <61953577+albertomercurio@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 12, 2025

@copilot could you add also the benchmarks, following the same structure of the existing ones?

Added benchmarks in commit 93496de. The implementation follows the existing benchmark structure:

  • benchmark_sparse_dense_add! function in benchmarks/matrix_benchmarks.jl
  • Benchmarks all three sparse formats (CSC, CSR, COO)
  • Tests both Array and JLArray backends
  • Uses N×N matrices with 1% density (default N=10000)
  • Integrated into benchmarks/runbenchmarks.jl for both backends

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pkg.julialang.org
    • Triggering command: julia --project=benchmarks -e using Pkg; Pkg.instantiate() (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@albertomercurio albertomercurio merged commit 3344d6f into main Nov 12, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement sum between AbstractDeviceSparseMatrix and DenseMatrix

2 participants