Skip to content

Commit

Permalink
Fix vecnorm(A::SparseMatrixCSC, ...).
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Oct 19, 2017
1 parent 01fc2dd commit 42c2963
Show file tree
Hide file tree
Showing 2 changed files with 5 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
4 changes: 4 additions & 0 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,10 @@ 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
@test (foo = speye(4); resize!(foo.nzval, 5)[5] = NaN; vecnorm(foo) == 2.0)
end

@testset "sparse matrix cond" begin
Expand Down

0 comments on commit 42c2963

Please sign in to comment.