Skip to content

Commit

Permalink
Fix a bug in the doubletranspose method for non-square matrices (#8316).
Browse files Browse the repository at this point in the history
Add tests for sparse matrix multiplication that exercise both,
the sortcols and the doubletranspose method.
  • Loading branch information
ViralBShah committed Oct 26, 2014
1 parent b718cbc commit 98c882f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,8 @@ end
# sortSparseMatrixCSC!(A, sortindices = :doubletranspose) # Sort with a double transpose
function sortSparseMatrixCSC!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}; sortindices::Symbol = :sortcols)
if sortindices == :doubletranspose
B = similar(A)
nB, mB = size(A)
B = SparseMatrixCSC(mB, nB, Array(Ti, nB+1), similar(A.rowval), similar(A.nzval))
transpose!(A, B)
transpose!(B, A)
return A
Expand Down
4 changes: 3 additions & 1 deletion test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ end
# matrix multiplication and kron
for i = 1:5
a = sprand(10, 5, 0.7)
b = sprand(5, 10, 0.3)
b = sprand(5, 15, 0.3)
@test maximum(abs(a*b - full(a)*full(b))) < 100*eps()
@test maximum(abs(Base.LinAlg.spmatmul(a,b,sortindices=:sortcols) - full(a)*full(b))) < 100*eps()
@test maximum(abs(Base.LinAlg.spmatmul(a,b,sortindices=:doubletranspose) - full(a)*full(b))) < 100*eps()
@test full(kron(a,b)) == kron(full(a), full(b))
end

Expand Down

0 comments on commit 98c882f

Please sign in to comment.