Skip to content

Commit

Permalink
Merge pull request #11685 from KristofferC/kc/functs_triu_etc
Browse files Browse the repository at this point in the history
Performance improvements for sparse triu!, tril!, dropzeros!, droptol!
  • Loading branch information
ViralBShah committed Jun 14, 2015
2 parents d8e5d6f + 4a49c16 commit 0497967
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions base/sparse/csparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,19 @@ function fkeep!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, f, other)
A
end

droptol!(A::SparseMatrixCSC, tol) = fkeep!(A, (i,j,x,other)->abs(x)>other, tol)
dropzeros!(A::SparseMatrixCSC) = fkeep!(A, (i,j,x,other)->x!=0, nothing)
triu!(A::SparseMatrixCSC) = fkeep!(A, (i,j,x,other)->(j>=i), nothing)

immutable DropTolFun <: Func{4} end
call(::DropTolFun, i,j,x,other) = abs(x)>other
immutable DropZerosFun <: Func{4} end
call(::DropZerosFun, i,j,x,other) = x!=0
immutable TriuFun <: Func{4} end
call(::TriuFun, i,j,x,other) = j>=i
immutable TrilFun <: Func{4} end
call(::TrilFun, i,j,x,other) = i>=j

droptol!(A::SparseMatrixCSC, tol) = fkeep!(A, DropTolFun(), tol)
dropzeros!(A::SparseMatrixCSC) = fkeep!(A, DropZerosFun(), nothing)
triu!(A::SparseMatrixCSC) = fkeep!(A, TriuFun(), nothing)
triu(A::SparseMatrixCSC) = triu!(copy(A))
tril!(A::SparseMatrixCSC) = fkeep!(A, (i,j,x,other)->(i>=j), nothing)
tril!(A::SparseMatrixCSC) = fkeep!(A, TrilFun(), nothing)
tril(A::SparseMatrixCSC) = tril!(copy(A))

0 comments on commit 0497967

Please sign in to comment.