Skip to content

Commit b456400

Browse files
committed
extend docs
1 parent 0e1b627 commit b456400

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

docs/src/custom.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mul!(ones(3,3), A, reshape(collect(1:9), 3, 3), 2, 2)
7373
using BenchmarkTools
7474

7575
@benchmark mul!($(zeros(3)), $A, $x)
76-
76+
7777
#-
7878

7979
@benchmark mul!($(zeros(3)), $A, $x, $(rand()), $(rand()))
@@ -241,6 +241,9 @@ mul!(similar(x)', x', A)
241241
F = MyFillMap(5, (100,100))
242242
M = Matrix{eltype(F)}(undef, size(F))
243243
@benchmark Matrix($F)
244+
245+
#-
246+
244247
@benchmark LinearMaps._unsafe_mul!($(Matrix{Int}(undef, (100,100))), $(MyFillMap(5, (100,100))), true)
245248

246249
# If a more performant implementation exists, it is recommended to overwrite this method,
@@ -249,6 +252,9 @@ M = Matrix{eltype(F)}(undef, size(F))
249252

250253
LinearMaps._unsafe_mul!(M::AbstractMatrix, A::MyFillMap, s::Number) = fill!(M, A.λ*s)
251254
@benchmark Matrix($F)
255+
256+
#-
257+
252258
@benchmark LinearMaps._unsafe_mul!($(Matrix{Int}(undef, (100,100))), $(MyFillMap(5, (100,100))), true)
253259

254260
# As one can see, the above runtimes are dominated by the allocation of the output matrix,
@@ -259,16 +265,18 @@ LinearMaps._unsafe_mul!(M::AbstractMatrix, A::MyFillMap, s::Number) = fill!(M, A
259265

260266
# As usual, generic fallbacks for `LinearMap` slicing exist and are handled by the following
261267
# method hierarchy, where at least one of `I` and `J` has to be a `Colon`:
262-
#
268+
#
263269
# Base.getindex(::LinearMap, I, J)
264270
# -> LinearMaps._getindex(::LinearMap, I, J)
265-
#
271+
#
266272
# The method `Base.getindex` checks the validity of the the requested indices and calls
267273
# `LinearMaps._getindex`, which should be overloaded for custom `LinearMap`s subtypes.
268274
# For instance:
269275

270276
@benchmark F[1,:]
271277

278+
#-
279+
272280
LinearMaps._getindex(A::MyFillMap, ::Integer, J::Base.Slice) = fill(A.λ, axes(J))
273281
@benchmark F[1,:]
274282

docs/src/types.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,13 @@ as in the usual matrix case: `transpose(A) * x` and `mul!(y, A', x)`, for instan
143143
purposes or if you want to have the explicit sparse matrix representation of
144144
a linear map for which you only have a function definition (e.g. to be able
145145
to use its `transpose` or `adjoint`).
146+
147+
### Slicing methods
148+
149+
Complete slicing, i.e., `A[:,j]`, `A[:,J]`, `A[i,:]`, `A[I,:]` and `A[:,:]` for `i`, `j`
150+
`Integer` and `I,J` `AbstractVector{<:Integer}` is generically available for any
151+
`A::LinearMap` subtype via application of `A` (or `A'` for (predominantly) horizontal
152+
slicing) to standard unit vectors of appropriate length. By complete slicing we refer
153+
two-dimensional Cartesian indexing where at least one of the "indices" is a colon. This is
154+
facilitated by overloads of `Base.getindex`. Partial slicing à la `A[I,J]` and scalar or
155+
linear indexing are _not_ supported for performance reasons.

0 commit comments

Comments
 (0)