Skip to content

Commit

Permalink
change vecdot for sparse matrices to dot
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Jun 19, 2018
1 parent 9b24aee commit e5127f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions stdlib/SparseArrays/src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ function spmatmul(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti};
return C
end

# Frobenius inner product: trace(A'B)
function vecdot(A::SparseMatrixCSC{T1,S1},B::SparseMatrixCSC{T2,S2}) where {T1,T2,S1,S2}
# Frobenius dot/inner product: trace(A'B)
function dot(A::SparseMatrixCSC{T1,S1},B::SparseMatrixCSC{T2,S2}) where {T1,T2,S1,S2}
m, n = size(A)
size(B) == (m,n) || throw(DimensionMismatch("matrices must have the same dimensions"))
r = vecdot(zero(T1), zero(T2))
r = dot(zero(T1), zero(T2))
@inbounds for j = 1:n
ia = A.colptr[j]; ia_nxt = A.colptr[j+1]
ib = B.colptr[j]; ib_nxt = B.colptr[j+1]
Expand All @@ -223,7 +223,7 @@ function vecdot(A::SparseMatrixCSC{T1,S1},B::SparseMatrixCSC{T2,S2}) where {T1,T
ib < ib_nxt || break
rb = B.rowval[ib]
else # ra == rb
r += vecdot(A.nzval[ia], B.nzval[ib])
r += dot(A.nzval[ia], B.nzval[ib])
ia += oneunit(S1); ib += oneunit(S2)
ia < ia_nxt && ib < ib_nxt || break
ra = A.rowval[ia]; rb = B.rowval[ib]
Expand Down
6 changes: 3 additions & 3 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ end
end
end

@testset "sparse Frobenius inner product" begin
@testset "sparse Frobenius dot/inner product" begin
for i = 1:5
A = sprand(ComplexF64,10,15,0.4)
B = sprand(ComplexF64,10,15,0.5)
@test vecdot(A,B) vecdot(Matrix(A),Matrix(B))
@test dot(A,B) dot(Matrix(A),Matrix(B))
end
@test_throws DimensionMismatch vecdot(sprand(5,5,0.2),sprand(5,6,0.2))
@test_throws DimensionMismatch dot(sprand(5,5,0.2),sprand(5,6,0.2))
end

sA = sprandn(3, 7, 0.5)
Expand Down

0 comments on commit e5127f8

Please sign in to comment.