Skip to content

Commit b21ac80

Browse files
committed
collect summary/show methods in show.jl
1 parent 3639b9f commit b21ac80

File tree

4 files changed

+97
-27
lines changed

4 files changed

+97
-27
lines changed

src/LinearMaps.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ include("functionmap.jl") # using a function as linear map
122122
include("blockmap.jl") # block linear maps
123123
include("kronecker.jl") # Kronecker product of linear maps
124124
include("conversion.jl") # conversion of linear maps to matrices
125+
include("show.jl") # show methods for LinearMap objects
125126

126127
"""
127128
LinearMap(A; kwargs...)

src/blockmap.jl

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -377,25 +377,6 @@ for Atype in (AbstractVector, AbstractMatrix)
377377
end
378378
end
379379

380-
############
381-
# show methods
382-
############
383-
384-
# block2string(b, s) = string(join(map(string, b), '×'), "-blocked ", Base.dims2string(s))
385-
# Base.summary(a::BlockMap) = string(block2string(nblocks(a), size(a)), " ", typeof(a))
386-
# # _show_typeof(io, a) = show(io, typeof(a))
387-
# function Base.summary(io::IO, a::AbstractBlockMap)
388-
# print(io, block2string(nblocks(a), size(a)))
389-
# print(io, ' ')
390-
# _show_typeof(io, a)
391-
# end
392-
# function _show_typeof(io::IO, a::AbstractBlockMap{T}) where {T}
393-
# Base.show_type_name(io, typeof(a).name)
394-
# print(io, '{')
395-
# show(io, T)
396-
# print(io, '}')
397-
# end
398-
399380
############
400381
# BlockDiagonalMap
401382
############

src/functionmap.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ FunctionMap{T}(f, M::Int; kwargs...) where {T} = FunctionMap{T}(f, nothi
2121
FunctionMap{T}(f, M::Int, N::Int; kwargs...) where {T} = FunctionMap{T}(f, nothing, M, N; kwargs...)
2222
FunctionMap{T}(f, fc, M::Int; kwargs...) where {T} = FunctionMap{T}(f, fc, M, M; kwargs...)
2323

24-
# show
25-
function Base.show(io::IO, A::FunctionMap{T, F, Nothing}) where {T, F}
26-
print(io, "LinearMaps.FunctionMap{$T}($(A.f), $(A.M), $(A.N); ismutating=$(A._ismutating), issymmetric=$(A._issymmetric), ishermitian=$(A._ishermitian), isposdef=$(A._isposdef))")
27-
end
28-
function Base.show(io::IO, A::FunctionMap{T}) where {T}
29-
print(io, "LinearMaps.FunctionMap{$T}($(A.f), $(A.fc), $(A.M), $(A.N); ismutating=$(A._ismutating), issymmetric=$(A._issymmetric), ishermitian=$(A._ishermitian), isposdef=$(A._isposdef))")
30-
end
31-
3224
# properties
3325
Base.size(A::FunctionMap) = (A.M, A.N)
3426
LinearAlgebra.issymmetric(A::FunctionMap) = A._issymmetric

src/show.jl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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

Comments
 (0)