@@ -605,7 +605,7 @@ function dot(x::AbstractVector{T1}, A::AbstractSparseMatrixCSC{T2}, y::AbstractV
605605 end
606606 return s
607607end
608- function dot (x:: SparseVector , A:: AbstractSparseMatrixCSC , y:: SparseVector )
608+ function dot (x:: AbstractSparseVector , A:: AbstractSparseMatrixCSC , y:: AbstractSparseVector )
609609 m, n = size (A)
610610 length (x) == m && n == length (y) ||
611611 throw (DimensionMismatch (" x has length $(length (x)) , A has size ($m , $n ), y has length $(length (y)) " ))
@@ -723,6 +723,71 @@ function dot(x::AbstractSparseVector, D::Diagonal, y::AbstractSparseVector)
723723 return s
724724end
725725
726+ function dot (
727+ a:: AbstractSparseVector ,
728+ Q:: Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,<:DenseMatrixUnion}} ,
729+ b:: AbstractSparseVector ,
730+ )
731+ return _dot_quadratic_form (a, Q, b)
732+ end
733+
734+ function dot (
735+ a:: AbstractSparseVector ,
736+ Q:: LinearAlgebra.Transpose{<:Real,<:DenseMatrixUnion} ,
737+ b:: AbstractSparseVector ,
738+ )
739+ return _dot_quadratic_form (a, Q, b)
740+ end
741+
742+ function dot (
743+ a:: AbstractSparseVector ,
744+ Q:: LinearAlgebra.Transpose{<:Real,<:WrapperMatrixTypes{<:Real,<:DenseMatrixUnion}} ,
745+ b:: AbstractSparseVector ,
746+ )
747+ return _dot_quadratic_form (a, Q, b)
748+ end
749+
750+ function dot (
751+ a:: AbstractSparseVector ,
752+ Q:: LinearAlgebra.RealHermSymComplexHerm{<:Real,<:DenseMatrixUnion} ,
753+ b:: AbstractSparseVector )
754+ return _dot_quadratic_form (a, Q, b)
755+ end
756+
757+ function dot (
758+ a:: AbstractSparseVector ,
759+ Q:: Union {
760+ LinearAlgebra. Hermitian{<: Real ,<: DenseMatrixUnion }, LinearAlgebra. Symmetric{<: Real ,<: DenseMatrixUnion }
761+ },
762+ b:: AbstractSparseVector )
763+ return _dot_quadratic_form (a, Q, b)
764+ end
765+
766+ # actual function implementation called by the method dispatch
767+ function _dot_quadratic_form (a, Q, b)
768+ n = length (a)
769+ m = length (b)
770+ if size (Q) != (n, m)
771+ throw (DimensionMismatch (" Matrix has a size $(size (Q)) but vectors have length $n , $m " ))
772+ end
773+ anzind = nonzeroinds (a)
774+ bnzind = nonzeroinds (b)
775+ anzval = nonzeros (a)
776+ bnzval = nonzeros (b)
777+ s = zero (Base. promote_eltype (a, Q, b))
778+ if isempty (anzind) || isempty (bnzind)
779+ return s
780+ end
781+ @inbounds for a_idx in eachindex (anzind)
782+ for b_idx in eachindex (bnzind)
783+ ia = anzind[a_idx]
784+ ib = bnzind[b_idx]
785+ s += dot (anzval[a_idx], Q[ia, ib], bnzval[b_idx])
786+ end
787+ end
788+ return s
789+ end
790+
726791# # triangular sparse handling
727792# # triangular multiplication
728793function LinearAlgebra. generic_trimatmul! (C:: StridedVecOrMat , uploc, isunitc, tfun:: Function , A:: SparseMatrixCSCUnion , B:: AbstractVecOrMat )
0 commit comments