-
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
Add IndexableMap #145
Add IndexableMap #145
Conversation
Codecov Report
@@ Coverage Diff @@
## master #145 +/- ##
==========================================
- Coverage 99.80% 96.64% -3.17%
==========================================
Files 14 15 +1
Lines 1042 1072 +30
==========================================
- Hits 1040 1036 -4
- Misses 2 36 +34
Continue to review full report at Codecov.
|
@@ -293,7 +294,9 @@ For the function-based constructor, there is one more keyword argument: | |||
The default value is guessed by looking at the number of arguments of the first | |||
occurrence of `f` in the method table. | |||
""" | |||
LinearMap(A::MapOrVecOrMat; kwargs...) = WrappedMap(A; kwargs...) | |||
LinearMap(A::MapOrVecOrMat; getind=nothing, kwargs...) = _LinearMap(getind, A; kwargs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LinearMap(A::MapOrVecOrMat; getind=nothing, kwargs...) = _LinearMap(getind, A; kwargs...) | |
LinearMap(A::MapOrVecOrMat; getind=Base.getindex, kwargs...) = _LinearMap(getind, A; kwargs...) |
For a WrappedMap
could the default getind
simply be Base.getindex
because presumably that is the expected behavior for a matrix or even for any AbstractArray
that already has a getindex
method.
Base.transpose(A::IndexableMap) = IndexableMap(transpose(A.lmap), (i,j) -> transpose(A.getind(j,i))) | ||
# rewrapping preserves indexability but redefines, e.g., symmetry properties | ||
LinearMap(A::IndexableMap; getind=nothing, kwargs...) = IndexableMap(LinearMap(A.lmap; kwargs...), getind) | ||
# addition/subtraction/scalar multiplication preserve indexability |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
I wish I had a suggestion for how to handle a CompositeMap
...
I won't have time to review this before next week, but I just thought of another possible approach. We could support a general |
# UniformScalingMap(λ, M) : error("UniformScalingMap needs to be square")) | ||
# UniformScalingMap(λ::T, sz::Dims{2}) where {T} = | ||
# (sz[1] == sz[2] ? | ||
# UniformScalingMap(λ, sz[1]) : error("UniformScalingMap needs to be square")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base.getindex(A::UniformScalingMap, args...) = A.λ * A.lmap.getind(args...) |
Seems like something like this should be the natural default for this type.
I was going to suggest something similar to what @Jutho said, i.e., some way of letting users "opt in" to the natural default. It could be a switch or an exported convenience routine that could be passed back in like I put in a couple other suggestions. |
This adds a type for indexable LinearMaps. Construction is via a keyword argument
getind
, naming can be discussed, of course.Closes #38.