Skip to content

Commit

Permalink
Merge pull request #24204 from Sacha0/fixvecnorm
Browse files Browse the repository at this point in the history
fix vecnorm for sparse matrices
  • Loading branch information
Sacha0 authored Oct 19, 2017
2 parents 40ee27a + bdff18b commit 99ef868
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ end
diff(a::SparseMatrixCSC, dim::Integer)= dim==1 ? sparse_diff1(a) : sparse_diff2(a)

## norm and rank
vecnorm(A::SparseMatrixCSC, p::Real=2) = vecnorm(A.nzval, p)
vecnorm(A::SparseMatrixCSC, p::Real=2) = vecnorm(view(A.nzval, 1:nnz(A)), p)

function norm(A::SparseMatrixCSC,p::Real=2)
m, n = size(A)
Expand Down
7 changes: 7 additions & 0 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,13 @@ end
@test norm(Ai,1) norm(Array(Ai),1)
@test norm(Ai,Inf) norm(Array(Ai),Inf)
@test vecnorm(Ai) vecnorm(Array(Ai))
# make certain entries in nzval beyond
# the range specified in colptr do not
# impact vecnorm of a sparse matrix
foo = speye(4)
resize!(foo.nzval, 5)
setindex!(foo.nzval, NaN, 5)
@test vecnorm(foo) == 2.0
end

@testset "sparse matrix cond" begin
Expand Down

0 comments on commit 99ef868

Please sign in to comment.