Skip to content

Commit

Permalink
fix error in last sparse reductions change
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Apr 15, 2014
1 parent 6cf7ca3 commit eeb6ab1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,17 @@ end

function maximum{T}(A::SparseMatrixCSC{T})
isempty(A) && throw(ArgumentError("argument must not be empty"))
max(maximum(A.nzval), zero(T))
m = maximum(A.nzval)
nfilled(A)!=length(A) ? max(m,zero(T)) : m
end

maximum{T}(A::SparseMatrixCSC{T}, region) =
isempty(A) ? similar(A, reduced_dims0(A,region)) : reducedim(Base.scalarmax,A,region,typemin(T))

function minimum{T}(A::SparseMatrixCSC{T})
isempty(A) && throw(ArgumentError("argument must not be empty"))
min(minimum(A.nzval), zero(T))
m = minimum(A.nzval)
nfilled(A)!=length(A) ? min(m,zero(T)) : m
end

minimum{T}(A::SparseMatrixCSC{T}, region) =
Expand Down
3 changes: 3 additions & 0 deletions test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,6 @@ end
@test maximum(P, (1,)) == [1.0 2.0 3.0]
@test maximum(P, (2,)) == reshape([1.0,2.0,3.0],3,1)
@test maximum(P, (1,2)) == reshape([3.0],1,1)

@test maximum(sparse(-ones(3,3))) == -1
@test minimum(sparse(ones(3,3))) == 1

0 comments on commit eeb6ab1

Please sign in to comment.