Skip to content

Commit

Permalink
Move fkeep! docstring to the right function (#503)
Browse files Browse the repository at this point in the history
* Move `fkeep!` docstring to the right function

* Add docstring test
  • Loading branch information
lgoettgens authored Feb 8, 2024
1 parent 1aa6431 commit 1748989
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1763,35 +1763,6 @@ end

## fkeep! and children tril!, triu!, droptol!, dropzeros[!]

"""
fkeep!(f, A::AbstractSparseArray)
Keep elements of `A` for which test `f` returns `true`. `f`'s signature should be
f(i::Integer, [j::Integer,] x) -> Bool
where `i` and `j` are an element's row and column indices and `x` is the element's
value. This method makes a single sweep
through `A`, requiring `O(size(A, 2), nnz(A))`-time for matrices and `O(nnz(A))`-time for vectors
and no space beyond that passed in.
# Examples
```jldoctest
julia> A = sparse(Diagonal([1, 2, 3, 4]))
4×4 SparseMatrixCSC{Int64, Int64} with 4 stored entries:
1 ⋅ ⋅ ⋅
⋅ 2 ⋅ ⋅
⋅ ⋅ 3 ⋅
⋅ ⋅ ⋅ 4
julia> SparseArrays.fkeep!((i, j, v) -> isodd(v), A)
4×4 SparseMatrixCSC{Int64, Int64} with 2 stored entries:
1 ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅
⋅ ⋅ 3 ⋅
⋅ ⋅ ⋅ ⋅
```
"""
function _fkeep!(f::F, A::AbstractSparseMatrixCSC) where F<:Function
An = size(A, 2)
Acolptr = getcolptr(A)
Expand Down Expand Up @@ -1839,6 +1810,35 @@ function _fkeep!_fixed(f::F, A::AbstractSparseMatrixCSC) where F<:Function
return A
end

"""
fkeep!(f, A::AbstractSparseArray)
Keep elements of `A` for which test `f` returns `true`. `f`'s signature should be
f(i::Integer, [j::Integer,] x) -> Bool
where `i` and `j` are an element's row and column indices and `x` is the element's
value. This method makes a single sweep
through `A`, requiring `O(size(A, 2), nnz(A))`-time for matrices and `O(nnz(A))`-time for vectors
and no space beyond that passed in.
# Examples
```jldoctest
julia> A = sparse(Diagonal([1, 2, 3, 4]))
4×4 SparseMatrixCSC{Int64, Int64} with 4 stored entries:
1 ⋅ ⋅ ⋅
⋅ 2 ⋅ ⋅
⋅ ⋅ 3 ⋅
⋅ ⋅ ⋅ 4
julia> SparseArrays.fkeep!((i, j, v) -> isodd(v), A)
4×4 SparseMatrixCSC{Int64, Int64} with 2 stored entries:
1 ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅
⋅ ⋅ 3 ⋅
⋅ ⋅ ⋅ ⋅
```
"""
fkeep!(f::F, A::AbstractSparseMatrixCSC) where F<:Function = _is_fixed(A) ? _fkeep!_fixed(f, A) : _fkeep!(f, A)

# deprecated syntax
Expand Down
6 changes: 6 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ end
@test s[3] === -0.0
end

if isdefined(Docs, :undocumented_names) # new in Julia 1.11
@testset "docstrings (issue julia#52725)" begin
@test isempty(Docs.undocumented_names(SparseArrays))
end
end

# As part of the migration of SparseArrays.jl into its own repo,
# these tests have been moved from other files in julia tests to
# the SparseArrays.jl repo
Expand Down

0 comments on commit 1748989

Please sign in to comment.