Skip to content

Conversation

matbesancon
Copy link
Contributor

@matbesancon matbesancon commented Aug 8, 2025

This was missing from the specializations and thus still slow.
This is a port from the same PR on FW.jl: ZIB-IOL/FrankWolfe.jl#607

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doubly layered case (transpose of wrapper of dense) begs the question if that really occurs, and if yes, then what about the adjoint of wrappers of dense? Conversely, would it be too generic to have

function dot(a::AbstractSparseVector, Q::AbstractMatrix, b::AbstractSparseVector)
    return _dot_quadratic_form(a, Q, b)
end

ADD: It would actually correspond nicely to the existing

function dot(x::AbstractVector{T1}, A::AbstractSparseMatrixCSC{T2}, y::AbstractVector{T3}) where {T1,T2,T3}

Copy link

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 80.64516% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.00%. Comparing base (34ece87) to head (4c71b6b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/linalg.jl 80.64% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #640      +/-   ##
==========================================
- Coverage   84.01%   84.00%   -0.02%     
==========================================
  Files          12       12              
  Lines        9258     9288      +30     
==========================================
+ Hits         7778     7802      +24     
- Misses       1480     1486       +6     

☔ 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.

@matbesancon
Copy link
Contributor Author

begs the question if that really occurs

that's the problem with method ambiguities, there is no way to prove Aqua that this is never the case

@matbesancon
Copy link
Contributor Author

About the suggestion of

dot(a::AbstractSparseVector, Q::AbstractMatrix, b::AbstractSparseVector)

The issue is precisely
dot(x::AbstractVector{T1}, A::AbstractSparseMatrixCSC{T2}, y::AbstractVector{T3}) where {T1,T2,T3}

because this needs to be disambiguated again

@dkarrasch
Copy link
Member

dkarrasch commented Aug 8, 2025

But we have

function dot(x::SparseVector, A::AbstractSparseMatrixCSC, y::SparseVector)

If you change it to

function dot(x::AbstractSparseVector, A::AbstractSparseMatrixCSC, y::AbstractSparseVector)

that would be the disambiguating method, wouldn't it?

@matbesancon
Copy link
Contributor Author

Making it general was making a whole lot of ambiguities pop:
https://github.com/JuliaSparse/SparseArrays.jl/actions/runs/16826540584/job/47664254978?pr=640#step:6:118

@matbesancon
Copy link
Contributor Author

Generalizing SparseVector to AbstractSparse in the other method worked though :)

@matbesancon
Copy link
Contributor Author

ok all settled on my end, @dkarrasch can you take a look to see if things are all good for you?

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need these. The other use case is actually wrong. I'll need to fix it, and then backport the fix. Could you perhaps double check for one of the examples that we actually call the right method?

Co-authored-by: Daniel Karrasch <[email protected]>
@matbesancon
Copy link
Contributor Author

OK something interesting, there is an incorrect behavior somewhere:

using SparseArrays, LinearAlgebra, Random

Random.seed!(42)
A = sprand(ComplexF64, 10, 15, 0.4)
Av = view(A, :, :)
x = sprand(ComplexF64, 10, 0.5)
y = sprand(ComplexF64, 15, 0.5)
@test dot(y, Symmetric(collect(A)' * collect(A)), y)  dot(y, Symmetric(A' * A), y)

fails on the current SparseArrays default (on 1.11)

@matbesancon
Copy link
Contributor Author

@matbesancon
Copy link
Contributor Author

The test will fail if we haven't overwritten the function

@dkarrasch
Copy link
Member

Hm, this is another bug in the method signature:

dot(x::SparseVector, A::RealHermSymComplexHerm{<:Any,<:AbstractSparseMatrixCSC}, y::SparseVector)

needs to have <:Real instead of <:Any. This way, the function won't apply to sparse complex symmetric matrices. One could fix the complex symmetric case, but I don't think this is actually needed.

@dkarrasch
Copy link
Member

A fix is coming in #643. Let's merge that one first, then update here and make sure we don't end up with ambiguities.

@matbesancon
Copy link
Contributor Author

The tests are passing, good to merge I'd say

@dkarrasch dkarrasch merged commit bb5ecc0 into main Aug 10, 2025
8 of 10 checks passed
@dkarrasch dkarrasch deleted the added-fast-quadratic-form branch August 10, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants