-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce specific show methods, add Base.parent overload #87
Conversation
Codecov Report
@@ Coverage Diff @@
## master #87 +/- ##
=========================================
Coverage ? 99.08%
=========================================
Files ? 13
Lines ? 988
Branches ? 0
=========================================
Hits ? 979
Misses ? 9
Partials ? 0
Continue to review full report at Codecov.
|
Alright, this needs certainly tests, but meanwhile I'd like to solicit some feedback/opinions/suggestions. So please, be invited to checkout this branch and test it in your current workflow. I see two "issues" here: (a) how to display matrices nicely; I'm not very well familiar with matrix plotting, but currently sparse matrices are displayed like dense ones; and (b) how to represent the hierarchy; ideally, I'd like to shift display blocks by two spaces or so, but I have no idea how to shift the matrix display, for instance. |
I also have little experience with My first suggestion for now would be to put the scalar of |
As another suggestion, I have omitted printing of matrices. After all, one could print matrices by explicitly asking for julia> A = LinearMap(rand(10, 10))
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
julia> B = LinearMap(rand(10, 10))
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
julia> A + B
10×10 LinearMaps.LinearCombination{Float64} with 2 maps:
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
julia> A*B
10×10 LinearMaps.CompositeMap{Float64} with 2 maps:
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
julia> A'
10×10 LinearMaps.WrappedMap{Float64} of
Adjoint{Float64,Array{Float64,2}}
julia> transpose(B)
10×10 LinearMaps.WrappedMap{Float64} of
Transpose{Float64,Array{Float64,2}}
julia> [A A; B B]
20×20 LinearMaps.BlockMap{Float64} with 4 block maps in 2 block rows
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
10×10 LinearMaps.WrappedMap{Float64} of
Array{Float64,2}
julia> N = 100
100
julia> function myft(v::AbstractVector)
# not so fast fourier transform
N = length(v)
w = zeros(complex(eltype(v)), N)
for k = 1:N
kappa = (2*(k-1)/N)*pi
for n = 1:N
w[k] += v[n]*exp(kappa*(n-1)*im)
end
end
return w
end
myft (generic function with 1 method)
julia> MyFT = LinearMap{ComplexF64}(myft, N)
100×100 LinearMaps.FunctionMap{Complex{Float64}}(myft; ismutating=false, issymmetric=false, ishermitian=false, isposdef=false)
julia> MyFT'
100×100 LinearMaps.AdjointMap{Complex{Float64}} of
100×100 LinearMaps.FunctionMap{Complex{Float64}}(myft; ismutating=false, issymmetric=false, ishermitian=false, isposdef=false)
julia> J = LinearMap(3I, 100)
100×100 LinearMaps.UniformScalingMap{Int64} with scaling factor: 3
julia> 2MyFT + J
100×100 LinearMaps.LinearCombination{Complex{Float64}} with 2 maps:
100×100 LinearMaps.ScaledMap{Complex{Float64}} with scale: 2 of
100×100 LinearMaps.FunctionMap{Complex{Float64}}(myft; ismutating=false, issymmetric=false, ishermitian=false, isposdef=false)
100×100 LinearMaps.UniformScalingMap{Int64} with scaling factor: 3 It would be nice if one could have indentation, but this could be tackled in the future. How do you like this everyone? |
I believe this is an improvement in any case. The main question is whether we want to display matrices or not. I don't plan to work on any other aspect (like indention) soon, so it would be great to receive a few votes. Maybe @chriscoey or @jagot? Personally, I have a slight preference towards not displaying them, but if anyone has a strong preference and a good reason, that would be helpful to know. |
I think it is fine not to print them, you can always investigate them manually by |
Maybe we should provide a |
Yes, that's cool. julia> get_map(LinearMap(rand(2,3)))
2×3 Array{Float64,2}:
0.765154 0.334224 0.702233
0.887921 0.189611 0.18073 This is hard to use in an automated fashion, because it may return very different types in general, but for interactive usage and quick exploration, that should be helpful. |
Actually, let's call it help?> parent
search: parent parentmodule parentindices
parent(A)
Return the underlying "parent array”. This parent array of objects of types SubArray, ReshapedArray or LinearAlgebra.Transpose is what was passed as an
argument to view, reshape, transpose, etc. during object creation. If the input is not a wrapped object, return the input itself. |
I'd like to add my vote of support for not showing the matrices and keeping the default |
I was very inspired by the
show
methods in #84, so I went ahead and introduced consistent such methods for allLinearMap
subtypes. This is the current output:I would like to give an idea of the hierarchy by adding indention to lower-order maps, but I don't know yet how to do that (across several lines, with potentially increasing width).
Of course, the details are up for discussion, now that we have something to start from. Needless to say that I can't help but finding it beautiful. 🤣