-
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 slicing functionality #165
Conversation
7e4d6e2
to
a3b8c34
Compare
Codecov Report
@@ Coverage Diff @@
## master #165 +/- ##
==========================================
+ Coverage 99.63% 99.65% +0.02%
==========================================
Files 14 15 +1
Lines 1089 1167 +78
==========================================
+ Hits 1085 1163 +78
Misses 4 4
Continue to review full report at Codecov.
|
176ef4f
to
7b70fc8
Compare
Codecov Report
@@ Coverage Diff @@
## master #165 +/- ##
==========================================
+ Coverage 98.54% 98.61% +0.06%
==========================================
Files 15 16 +1
Lines 1307 1372 +65
==========================================
+ Hits 1288 1353 +65
Misses 19 19
Continue to review full report at Codecov.
|
abc5e38
to
ef2867f
Compare
Anyone interested in indexing and slicing @JeffFessler: if I forward indexing If this looks good, we could get this in v3.7 soon, otherwise I'd go and make a release with the other currently merged PRs. |
Very much so! With this, could we do |
I'll comment on that in the other issue. For the time being, I'd be interested in getting feedback on the implementation. ;-) |
Ok ;-) |
Wow, this is a very comprehensive implementation with several features I didn't know about like I'm not exactly sure how to test this independently. When you say "forward indexing" do you mean something like this? |
Exactly. |
I think I agree, as long as "scalar" means |
Yes, that's what I meant.
I fully agree.
Absolutely - that's an efficient operation, after all. My inuition would be (with scalar indices
|
The latest commit largely implements the suggestions (thanks for the clear roadmap!). What I currently have errors on |
Thanks a lot for doing all of this!
Oh, that's a nice approach I think!
My intuition was that code which iterates over
Yes, I think so too. I was assuming that the user code wouldn't want to have the actual matrix in hand, necessarily. Maybe it would in fact be best if Maybe it's best if we disallow |
Yes, I guess that's much better than first allow it and then handle potential "Why is XYZ so slow?" issues... or even disallow it later. I think the main point that the user needs to understand is that these cases do correspond to first compute entire slices and then slice again. If users will have to write that out they will naturally want to think twice if that's really what they want, or whether they were writing it just out of convenience. |
Makes sense. |
Ha, that will make a fantastic PR: basically add a whole bunch of methods that throw! Progress! Yippieh! 🤣 |
I think |
I guess that is in the eye of the beholder. If |
Yes, that's what I mean - it scales proportionally to the number of outputs that you want to produce, both for I would put it like this: |
For higher-dimensional arrays, I guess it is not completely uncommon to put colons in two dimensions. For "matrices", who would construct a (deep) copy via BTW, |
It's not quite the same in general, because for normal arrays My argument for allowing |
Ok, the rationale of allowing "any complete slicing" (as opposed to partial slicing, which requires more allocations than just the unavoidable unit vector and the result) sounds convincing to me. As I said, it's borderline and a matter of taste: from the point of view of matrix construction it's clear that this is expensive (and could deserve a warning), from the point of view of slicing it is "expectedly expensive" (and could therefore be allowed). I'll see if I need to adjust the announcement. Perhaps, there should also be a section in the |
Uff, I think I finally understood the macro stuff! 🎉 What shall we do then? Allow slicing in general without interference of macros and allow scalar indexing/partial slicing upon a macro signal, or allow any slicing/indexing only upon macro signal? Having two macros, one for slicing and one for indexing and partial slicing is perhaps overkill. |
From a user perspective, I'd be happy with |
Ok, then you should be happy with the current state, I hope. We could release this as is and then take some time to work out how to allow things that are currently forbidden. That would be "a new feature" and non-breaking, as opposed to first allowing something and later require a macro to do that. I'll wait for @JeffFessler's thumb. |
Sounds great - again, thanks a lot! |
src/getindex.jl
Outdated
Base.lastindex(A::LinearMap) = last(eachindex(IndexLinear(), A)) | ||
Base.firstindex(A::LinearMap) = first(eachindex(IndexLinear(), A)) |
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.
I noticed that codecov complains about these two lines. I wonder if they should be commented out because we are not supporting A[1]
and A[end]
at this point in time, right?
return x | ||
end | ||
|
||
function _fillbyrows!(dest, A, I, J) |
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.
should these be commented out since A[I,J]
is not supported?
the codecov warning is what caught my eye here.
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.
The tests were not variable enough. This method is needed in general.
this is also fine with me. thumbs up other than a couple questions i asked about commenting out possibly unused code which i leave to you to decide. |
Thanks again! |
This is an alternative approach to #145, without adding yet another
LinearMap
subtype. As it stands now, there is no switch for turning on/off indexing/slicing. I was hoping one could have a submodule and "hide" it from the user, unless s/he asks forusing LinearMaps.GetIndex
, but that doesn't seem to work as easy as I was hoping for. OTOH, we might as well trust our users that they are cautious about indexing/slicing and not put additional stones in their way.This may require a few more tests to keep coverage high, some announcement in the docs and some information on how to extend that functionality to own map types.
Closes #145, closes #38.