|
1 | 1 | # summary
|
2 |
| -function Base.summary(io::IO, A::LinearMap) |
3 |
| - print(io, Base.dims2string(size(A))) |
4 |
| - print(io, ' ') |
5 |
| - _show_typeof(io, A) |
| 2 | +Base.summary(io::IO, A::LinearMap) = print(io, map_summary(A)) |
| 3 | +function map_summary(A::LinearMap) |
| 4 | + Base.dims2string(size(A)) * ' ' * _show_typeof(A) |
6 | 5 | end
|
7 | 6 |
|
8 | 7 | # show
|
9 |
| -Base.show(io::IO, A::LinearMap) = (summary(io, A); _show(io, A)) |
10 |
| -_show(io::IO, ::LinearMap) = nothing |
11 |
| -function _show(io::IO, A::FunctionMap{T,F,Nothing}) where {T,F} |
12 |
| - print(io, "($(A.f); ismutating=$(A._ismutating), issymmetric=$(A._issymmetric), ishermitian=$(A._ishermitian), isposdef=$(A._isposdef))") |
| 8 | +Base.show(io::IO, A::LinearMap) = print(io, map_show(io, A, 0)) |
| 9 | + |
| 10 | +map_show(io::IO, A::LinearMap, i) = " "^i * map_summary(A) * _show(io, A, i) |
| 11 | +map_show(io::IO, A::AbstractMatrix, i) = " "^i * string(typeof(A)) |
| 12 | +_show(io::IO, ::LinearMap, _) = "" |
| 13 | +function _show(io::IO, A::FunctionMap{T,F,Nothing}, _) where {T,F} |
| 14 | + "($(A.f); ismutating=$(A._ismutating), issymmetric=$(A._issymmetric), ishermitian=$(A._ishermitian), isposdef=$(A._isposdef))" |
13 | 15 | end
|
14 |
| -function _show(io::IO, A::FunctionMap) |
15 |
| - print(io, "($(A.f), $(A.fc); ismutating=$(A._ismutating), issymmetric=$(A._issymmetric), ishermitian=$(A._ishermitian), isposdef=$(A._isposdef))") |
| 16 | +function _show(io::IO, A::FunctionMap, _) |
| 17 | + "($(A.f), $(A.fc); ismutating=$(A._ismutating), issymmetric=$(A._issymmetric), ishermitian=$(A._ishermitian), isposdef=$(A._isposdef))" |
16 | 18 | end
|
17 |
| -function _show(io::IO, A::Union{CompositeMap,LinearCombination,KroneckerMap,KroneckerSumMap}) |
| 19 | +function _show(io::IO, A::Union{CompositeMap,LinearCombination,KroneckerMap,KroneckerSumMap}, i) |
18 | 20 | n = length(A.maps)
|
19 |
| - println(io, " with $n map", n>1 ? "s" : "", ":") |
20 |
| - print_maps(io, A.maps) |
| 21 | + " with $n map" * (n>1 ? "s" : "") * ":\n" * print_maps(io, A.maps, i+2) |
21 | 22 | end
|
22 |
| -function _show(io::IO, A::Union{AdjointMap,TransposeMap,WrappedMap}) |
23 |
| - print(io, " of ") |
24 |
| - L = A.lmap |
25 |
| - if A isa MatrixMap |
26 |
| - # summary(io, L) |
27 |
| - # println(io, ":") |
28 |
| - # Base.print_matrix(io, L) |
29 |
| - print(io, typeof(L)) |
30 |
| - else |
31 |
| - show(io, L) |
32 |
| - end |
| 23 | +function _show(io::IO, A::Union{AdjointMap,TransposeMap,WrappedMap}, i) |
| 24 | + " of\n" * map_show(io, parent(A), i+2) |
33 | 25 | end
|
34 |
| -function _show(io::IO, A::BlockMap) |
| 26 | +function _show(io::IO, A::BlockMap, i) |
35 | 27 | nrows = length(A.rows)
|
36 | 28 | n = length(A.maps)
|
37 |
| - println(io, " with $n block map", n>1 ? "s" : "", " in $nrows block row", nrows>1 ? "s" : "") |
38 |
| - print_maps(io, A.maps) |
| 29 | + " with $n block map" * (n>1 ? "s" : "") * " in $nrows block row" * (nrows>1 ? "s" : "") * |
| 30 | + "\n" * print_maps(io, A.maps, i+2) |
39 | 31 | end
|
40 |
| -function _show(io::IO, A::BlockDiagonalMap) |
| 32 | +function _show(io::IO, A::BlockDiagonalMap, i) |
41 | 33 | n = length(A.maps)
|
42 |
| - println(io, " with $n diagonal block map", n>1 ? "s" : "") |
43 |
| - print_maps(io, A.maps) |
| 34 | + " with $n diagonal block map" * (n>1 ? "s" : "") * ":\n" * print_maps(io, A.maps, i+2) |
44 | 35 | end
|
45 |
| -function _show(io::IO, J::UniformScalingMap) |
46 |
| - s = "$(J.λ)" |
47 |
| - print(io, " with scaling factor: $s") |
| 36 | +function _show(io::IO, J::UniformScalingMap, _) |
| 37 | + " with scaling factor: $(J.λ)" |
48 | 38 | end
|
49 |
| -function _show(io::IO, A::ScaledMap{T}) where {T} |
50 |
| - println(io, " with scale: $(A.λ) of") |
51 |
| - show(io, A.lmap) |
| 39 | +function _show(io::IO, A::ScaledMap{T}, i) where {T} |
| 40 | + " with scale: $(A.λ) of\n" * map_show(io, A.lmap, i+2) |
52 | 41 | end
|
53 | 42 |
|
54 | 43 | # helper functions
|
55 |
| -function _show_typeof(io::IO, A::LinearMap{T}) where {T} |
56 |
| - Base.show_type_name(io, typeof(A).name) |
57 |
| - print(io, '{') |
58 |
| - show(io, T) |
59 |
| - print(io, '}') |
| 44 | +function _show_typeof(A::LinearMap{T}) where {T} |
| 45 | + split(string(typeof(A)), '{')[1] * '{' * string(T) * '}' |
60 | 46 | end
|
61 | 47 |
|
62 |
| -function print_maps(io::IO, maps::Tuple{Vararg{LinearMap}}) |
| 48 | +function print_maps(io::IO, maps::Tuple{Vararg{LinearMap}}, k) |
63 | 49 | n = length(maps)
|
| 50 | + str = "" |
64 | 51 | if get(io, :limit, true) && n > 10
|
65 | 52 | s = 1:5
|
66 | 53 | e = n-5:n
|
67 | 54 | if e[1] - s[end] > 1
|
68 | 55 | for i in s
|
69 |
| - # print(io, ' ') |
70 |
| - show(io, maps[i]) |
71 |
| - println(io, "") |
| 56 | + str *= map_show(io, maps[i], k) * "\n" |
72 | 57 | end
|
73 |
| - print(io, "⋮") |
| 58 | + str *= " "^k * "⋮" |
74 | 59 | for i in e
|
75 |
| - println(io, "") |
76 |
| - show(io, maps[i]) |
| 60 | + str *= "\n" * map_show(io, maps[i], k) |
77 | 61 | end
|
78 | 62 | else
|
79 | 63 | for i in 1:n-1
|
80 |
| - # print(io, ' ') |
81 |
| - show(io, maps[i]) |
82 |
| - println(io, "") |
| 64 | + str *= map_show(io, maps[i], k) * "\n" |
83 | 65 | end
|
84 |
| - # print(io, ' ') |
85 |
| - show(io, last(maps)) |
| 66 | + str *= map_show(io, last(maps), k) |
86 | 67 | end
|
87 | 68 | else
|
88 | 69 | for i in 1:n-1
|
89 |
| - # print(io, ' ') |
90 |
| - show(io, maps[i]) |
91 |
| - println(io, "") |
| 70 | + str *= map_show(io, maps[i], k) * "\n" |
92 | 71 | end
|
93 |
| - # print(io, ' ') |
94 |
| - show(io, last(maps)) |
| 72 | + str *= map_show(io, last(maps), k) |
95 | 73 | end
|
| 74 | + return str |
96 | 75 | end
|
0 commit comments