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