Skip to content

Commit c54d7bf

Browse files
authored
Make LinearMaps callable (#128)
1 parent ef64037 commit c54d7bf

File tree

8 files changed

+33
-6
lines changed

8 files changed

+33
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LinearMaps"
22
uuid = "7a12625a-238d-50fd-b39a-03d52299707e"
3-
version = "3.0.1"
3+
version = "3.1.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ The only requirement for a `LinearMap` is that it can act on a vector (by multip
77

88
| **Documentation** | **Build Status** |
99
|:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:|
10-
| [![][docs-stable-img]][docs-stable-url] [![][docs-dev-img]][docs-dev-url] | [![][build-img]][build-url] [![][codecov-img]][codecov-url] [![][license-img]][license-url] |
11-
10+
| [![stable docs][docs-stable-img]][docs-stable-url] [![dev docs][docs-dev-img]][docs-dev-url] | [![build status][build-img]][build-url] [![coverage][codecov-img]][codecov-url] [![license][license-img]][license-url] |
1211

1312
## Installation
1413

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
77

88
[compat]
99
BenchmarkTools = "0.4, 0.5"
10-
Documenter = "0.25"
10+
Documenter = "0.25, 0.26"
1111
Literate = "2"

docs/src/history.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Version history
22

3+
## What's new in v3.1
4+
5+
* In Julia v1.3 and above, `LinearMap`-typed objects are callable on `AbstractVector`s:
6+
For `L::LinearMap` and `x::AbstractVector`, `L(x) = L*x`.
7+
38
## What's new in v3.0
49

510
* BREAKING change: Internally, any dependence on former `A*_mul_B!` methods is abandonned.

docs/src/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ Arpack.eigs(Δ; nev=3, which=:LR)
8787
KrylovKit.eigsolve(x -> Δ*x, size(Δ, 1), 3, :LR)
8888
```
8989

90+
In Julia v1.3 and above, the last line can be simplified to
91+
92+
```julia
93+
KrylovKit.eigsolve(Δ, size(Δ, 1), 3, :LR)
94+
````
95+
96+
leveraging the fact that objects of type `L <: LinearMap` are callable.
97+
9098
## Philosophy
9199

92100
Several iterative linear algebra methods such as linear solvers or eigensolvers

src/LinearMaps.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,20 @@ convert_to_lmaps(A) = (convert_to_lmaps_(A),)
9090
9191
Compute the action of the linear map `A` on the vector `x`.
9292
93+
!!! compat "Julia 1.3"
94+
In Julia versions v1.3 and above, objects `L` of any subtype of `LinearMap`
95+
are callable in the sense that `L(x) = L*x` for `x::AbstractVector`.
96+
9397
## Examples
9498
```jldoctest; setup=(using LinearAlgebra, LinearMaps)
9599
julia> A=LinearMap([1.0 2.0; 3.0 4.0]); x=[1.0, 1.0];
96100
97101
julia> A*x
102+
2-element Array{Float64,1}:
103+
3.0
104+
7.0
105+
106+
julia> A(x)
98107
2-element Array{Float64,1}:
99108
3.0
100109
7.0
@@ -104,6 +113,9 @@ function Base.:(*)(A::LinearMap, x::AbstractVector)
104113
check_dim_mul(A, x)
105114
return mul!(similar(x, promote_type(eltype(A), eltype(x)), size(A, 1)), A, x)
106115
end
116+
if VERSION v"1.3"
117+
(L::LinearMap)(x::AbstractVector) = L*x
118+
end
107119

108120
"""
109121
mul!(Y::AbstractVecOrMat, A::LinearMap, B::AbstractVector) -> Y

src/kronecker.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ holds. Upon vector multiplication, this rule is checked for applicability.
3030
# Examples
3131
```jldoctest; setup=(using LinearAlgebra, SparseArrays, LinearMaps)
3232
julia> J = LinearMap(I, 2) # 2×2 identity map
33-
LinearMaps.UniformScalingMap{Bool}(true, 2)
33+
2×2 LinearMaps.UniformScalingMap{Bool} with scaling factor: true
3434
3535
julia> E = spdiagm(-1 => trues(1)); D = E + E' - 2I;
3636
@@ -228,7 +228,7 @@ For convenience, one can also use `A ⊕ B` or `⊕(A, B, Cs...)` (typed as
228228
# Examples
229229
```jldoctest; setup=(using LinearAlgebra, SparseArrays, LinearMaps)
230230
julia> J = LinearMap(I, 2) # 2×2 identity map
231-
LinearMaps.UniformScalingMap{Bool}(true, 2)
231+
2×2 LinearMaps.UniformScalingMap{Bool} with scaling factor: true
232232
233233
julia> E = spdiagm(-1 => trues(1)); D = LinearMap(E + E' - 2I);
234234

test/linearmaps.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
6161
α = rand(ComplexF64); β = rand(ComplexF64)
6262
v = rand(ComplexF64, 10); V = rand(ComplexF64, 10, 3)
6363
w = rand(ComplexF64, 10); W = rand(ComplexF64, 10, 3)
64+
if VERSION v"1.3"
65+
F(v) == F*v
66+
end
6467
@test mul!(w, F, v) === w == F * v
6568
@test_throws ErrorException F' * v
6669
@test_throws ErrorException transpose(F) * v

0 commit comments

Comments
 (0)