From 4a49c160b6aa646766aba089fd3bd5eb415ab81e Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Fri, 12 Jun 2015 17:57:27 +0200 Subject: [PATCH] Add functors for triu, tril, droptol, dropzeros --- base/sparse/csparse.jl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/base/sparse/csparse.jl b/base/sparse/csparse.jl index d56d7b36f0ad3..433d2160841a6 100644 --- a/base/sparse/csparse.jl +++ b/base/sparse/csparse.jl @@ -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))