6
6
7
7
` LinearMaps.jl ` is a registered package and can be installed via
8
8
9
- pkg> add LinearMaps
9
+ ``` julia
10
+ pkg> add LinearMaps
11
+ ```
10
12
11
13
in package mode, to be entered by typing ` ] ` in the Julia REPL.
12
14
13
15
## Examples
14
16
15
17
Let
16
18
17
- A = LinearMap(rand(10, 10))
18
- B = LinearMap(cumsum, reverse∘cumsum∘reverse, 10)
19
+ ``` julia
20
+ A = LinearMap (rand (10 , 10 ))
21
+ B = LinearMap (cumsum, reverse∘ cumsum∘ reverse, 10 )
22
+ ```
19
23
20
24
be a matrix- and function-based linear map, respectively. Then the following code just works,
21
25
indistinguishably from the case when ` A ` and ` B ` are both ` AbstractMatrix ` -typed objects.
22
26
23
- 3.0A + 2B
24
- A + I
25
- A*B'
26
- [A B; B A]
27
- kron(A, B)
27
+ ``` julia
28
+ 3.0 A + 2 B
29
+ A + I
30
+ A* B'
31
+ [A B; B A]
32
+ kron (A, B)
33
+ ```
28
34
29
35
The ` LinearMap ` type and corresponding methods combine well with the following packages:
30
36
37
+ * [ ArnoldiMethods.jl] ( https://github.com/haampie/ArnoldiMethod.jl )
31
38
* [ Arpack.jl] ( https://github.com/JuliaLinearAlgebra/Arpack.jl ) : iterative eigensolver
32
39
` eigs ` and SVD ` svds ` ;
33
40
* [ IterativeSolvers.jl] ( https://github.com/JuliaMath/IterativeSolvers.jl ) : iterative
@@ -38,7 +45,7 @@ The `LinearMap` type and corresponding methods combine well with the following p
38
45
39
46
``` julia
40
47
using LinearMaps
41
- import Arpack, IterativeSolvers, KrylovKit, TSVD
48
+ import Arpack, IterativeSolvers, KrylovKit, TSVD, ArnoldiMethod
42
49
43
50
# Example 1, 1-dimensional Laplacian with periodic boundary conditions
44
51
function leftdiff! (y:: AbstractVector , x:: AbstractVector ) # left difference assuming periodic boundary conditions
@@ -64,11 +71,15 @@ D = LinearMap(leftdiff!, mrightdiff!, 100; ismutating=true) # by default has elt
64
71
Arpack. eigs (D' D; nev= 3 , which= :SR ) # note that D'D is recognized as symmetric => real eigenfact
65
72
Arpack. svds (D; nsv= 3 )
66
73
74
+ ArnoldiMethod. partialschur (D' D; nev= 3 , which= ArnoldiMethod. SR ())
75
+
76
+ KrylovKit. eigsolve (D' D, 100 , 3 , :SR )
77
+
67
78
Σ, L = IterativeSolvers. svdl (D; nsv= 3 )
68
79
69
80
TSVD. tsvd (D, 3 )
70
81
71
- # Example 2, 1-dimensional Laplacian
82
+ # Example 2, 3 smallest eigenvalues of 1-dimensional Laplacian
72
83
A = LinearMap (100 ; issymmetric= true , ismutating= true ) do C, B
73
84
C[1 ] = - 2 B[1 ] + B[2 ]
74
85
for i in 2 : length (B)- 1
80
91
81
92
Arpack. eigs (- A; nev= 3 , which= :SR )
82
93
94
+ ArnoldiMethod. partialschur (- A; nev= 3 , which= ArnoldiMethod. SR ())
95
+
96
+ KrylovKit. eigsolve (- A, size (A, 1 ), 3 , :SR )
97
+
83
98
# Example 3, 2-dimensional Laplacian
84
99
Δ = kronsum (A, A)
85
100
86
101
Arpack. eigs (Δ; nev= 3 , which= :LR )
102
+ ArnoldiMethod. partialeigen (ArnoldiMethod. partialschur (Δ; nev= 3 , which= ArnoldiMethod. LR ())[1 ])
87
103
KrylovKit. eigsolve (x -> Δ* x, size (Δ, 1 ), 3 , :LR )
88
104
```
89
105
0 commit comments