-
Notifications
You must be signed in to change notification settings - Fork 47
Refactor to allow partial views #245
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
Conversation
As suggested by @mulimoen (#244 (comment)), it's doable to have a concrete type abstracting the classic indptr case with the first element at 0, and the sliced matrix case, by simply performing the subtraction everywhere.
This API will be useful to interface with C APIs, where we need to pass a proper indptr.
This way iterating over indices and data should become ergonomic (though we'll have to clone the range).
@vbarrielle I really like this addition! The methods for iterating are really quite nice, maybe we should implement The only problem is of course the breaking change introduced. I'll go through some of the crates using
which makes the comparisons in I'll fixup the serde failures shortly to see what |
de568ac
to
a78aafd
Compare
@mulimoen thanks for the serde fixes. I've fixed the other crates in the workspace as well. Your PartialEq implementation looks nice, I'm on mobile now so I cannot see easily the impact on triplet.rs or dependent crates though. I'll look into it tomorrow (except if you'd rather submit another pr against this branch of course). I do hope there's not too much breakage in dependent crates, I think it affects most code that wanted to deal with the inner workings of the sparse structure, which should not be that common. We'll see. |
8b187ce
to
d46afb7
Compare
I had a look at which crates would be affected by these changes. The dependent crates listed at
|
add a PartialEq for indptr and slices
Thanks @mulimoen for your impact investigations. Looks like Edit: I'm a bit sleepy right now, but I think |
Apparently formatting has changed a tiny bit...
I've added 51606cf which makes it easier to pass a sparse matrix to C interfaces. I think I think this PR is mostly done, what do you think @mulimoen ? Do you see something missing? If not, do your prefer #237 to be merged before this one? |
I believe 51606cf is a bit unfortunate, any changes made to the returned I would prefer to fixup #237 after this, I'm missing an |
Why not put the warning on |
Ok I've thought about it again, and you're right: there's nothing gained by using Now I'm wondering if there's a way to prevent this kind of issue, eg using |
You would end up with the same problem if you used |
c81ed9e
to
95fea34
Compare
I removed |
95fea34
to
64cacaf
Compare
This API is safer than the previously introduced IndPtrBase::to_proper_ffi, which could very easily lead to use after free in unsafe code, as pointed out by @mulimoen. This new API still can be misused, but that's a common pitfall for methods returning Cow. The documentation thus warns against this pitfall, and illustrates the proper usage.
64cacaf
to
6f563e9
Compare
This is a refactoring that should fix #244. This is very much WIP, but the basic test suite is passing. @mulimoen I'd be very interested in your feedback.
This introduces lots of breaking changes, for instance lots of iterators are now using an
impl Iterator
pattern instead of an explicit type.There are still a few rough edges, which may not be addressed in this PR but should be addressed before 0.10 is released:
middle_outer_views
is cumbersome to use, it probably should take a start and end parameter (or a range) to be more convenient and less error prone.IndPtr
type is not used to build owned indptr types, but it could be interesting to use it to enforce good patterns. As it would not be practical to have runtime checks, this would be a crate-only APICsMatViewI
in its API. I probably should change that before 0.10.