Skip to content

Commit 0ad35ca

Browse files
author
Will Kimmerer
committed
select and map docstring improvements
1 parent 214b015 commit 0ad35ca

File tree

2 files changed

+31
-36
lines changed

2 files changed

+31
-36
lines changed

src/operations/map.jl

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ function Base.map(
7777
return map!(op, similar(A, t), x, A; mask, accum, desc)
7878
end
7979

80+
"""
81+
map(op::Union{Function, AbstractUnaryOp}, A::GBArray; kwargs...)::GBArray
82+
map(op::Union{Function, AbstractBinaryOp}, A::GBArray, x; kwargs...)::GBArray
83+
map(op::Union{Function, AbstractBinaryOp}, x, A::GBArray, kwargs...)::GBArray
84+
85+
Transform a GBArray by applying `op` to each element.
86+
87+
UnaryOps and single argument functions apply elementwise in the usual fashion.
88+
BinaryOps and two argument functions require the additional argument `x` which is
89+
substituted as the first or second operand of `op` depending on its position.
90+
91+
# Arguments
92+
- `op::Union{Function, AbstractUnaryOp, AbstractBinaryOp}`
93+
- `A::GBArray`
94+
- `x`: Position dependent argument to binary operators.
95+
96+
# Keywords
97+
- `mask::Union{Nothing, GBVecOrMat} = nothing`: optional mask.
98+
- `accum::Union{Nothing, AbstractBinaryOp} = nothing`: binary accumulator operation
99+
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
100+
- `desc::Union{Nothing, Descriptor} = nothing`
101+
"""
80102
function Base.map(
81103
op, x, A::GBArray;
82104
mask = nothing, accum = nothing, desc = nothing
@@ -148,34 +170,6 @@ Base.:-(u::GBArray, x::valid_union; mask = nothing, accum = nothing, desc = noth
148170
map(BinaryOps.MINUS, u, x; mask, accum, desc)
149171

150172
Base.:-(u::GBArray) = map(UnaryOps.AINV, u)
151-
"""
152-
map(op::UnaryOp, A::GBArray; kwargs...)::GBArray
153-
map(op::BinaryOp, A::GBArray, x; kwargs...)::GBArray
154-
map(op::BinaryOp, x, A::GBArray, kwargs...)::GBArray
155-
156-
Transform a GBArray by applying `op` to each element.
157-
158-
UnaryOps apply elementwise in the usual fashion.
159-
BinaryOps require the additional argument `x` which is substituted as the first or second
160-
argument of `op` depending on its position.
161-
162-
# Arguments
163-
- `op::MonoidBinaryOrRig = BinaryOps.PLUS`: the binary operation which is applied such that
164-
`C[i,j] = op(A[i,j], B[i,j])` for all `i,j` present in either `A` and/or `B`.
165-
- `A::GBArray`: `GBVector` or optionally transposed `GBMatrix`.
166-
- `x`: Position dependent argument to binary operators.
167-
168-
# Keywords
169-
- `mask::Union{Nothing, GBMatrix} = nothing`: optional mask.
170-
- `accum::Union{Nothing, AbstractBinaryOp} = nothing`: binary accumulator operation
171-
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
172-
- `desc = nothing`
173-
"""
174-
function Base.map(
175-
op::AbstractOp, A::GBArray, x = nothing;
176-
mask = nothing, accum = nothing, desc = nothing
177-
)
178-
end
179173

180174
"""
181175
mask!(C::GBArray, A::GBArray, mask::GBArray)

src/operations/select.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ function select!(
3030
)
3131
return select!(SelectOp(op), C, A, thunk; mask, accum, desc)
3232
end
33+
3334
"""
34-
select(op::SelectUnion, A::GBArray; kwargs...)::GBArray
35-
select(op::SelectUnion, A::GBArray, thunk; kwargs...)::GBArray
35+
select(op::Union{Function, SelectUnion}, A::GBArray; kwargs...)::GBArray
36+
select(op::Union{Function, SelectUnion}, A::GBArray, thunk; kwargs...)::GBArray
3637
3738
Return a `GBArray` whose elements satisfy the predicate defined by `op`.
38-
Some SelectOps may require an additional argument `thunk`, for use in comparison operations
39-
such as `C[i,j] = A[i,j] >= thunk ? A[i,j] : nothing`, which maps to
40-
`select(GT, A, thunk)`.
39+
Some SelectOps or functions may require an additional argument `thunk`, for use in
40+
comparison operations such as `C[i,j] = A[i,j] >= thunk ? A[i,j] : nothing`, which is
41+
performed by `select(>, A, thunk)`.
4142
4243
# Arguments
43-
- `op::SelectUnion`: A select operator from the SelectOps submodule.
44-
- `A::GBArray`: GBVector or optionally transposed GBMatrix.
44+
- `op::Union{Function, SelectUnion}`: A select operator from the SelectOps submodule.
45+
- `A::GBArray`
4546
- `thunk::Union{GBScalar, nothing, valid_union}`: Optional value used to evaluate `op`.
4647
4748
# Keywords
@@ -52,7 +53,7 @@ such as `C[i,j] = A[i,j] >= thunk ? A[i,j] : nothing`, which maps to
5253
- `desc = nothing`
5354
5455
# Returns
55-
- `GBArray`: The output matrix whose `eltype` is determined by `A`.
56+
- `GBArray`: The output matrix whose `eltype` is determined by `A` and `op`.
5657
"""
5758
function select(
5859
op::SelectUnion,

0 commit comments

Comments
 (0)