-
Notifications
You must be signed in to change notification settings - Fork 308
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
Allow &a @ &b to have different lifetimes #103
Conversation
How did you run into this? If you have two & from different scopes rust should infer their intersection lifetime automatically. |
Really? I wasn't expecting it to. I just put up the commit that creates this problem for me, on rustc 1.8.0-nightly (d5558825b 2016-02-28). It is daniel-vainsencher/online_weighted_stats@8f9cf03 BTW, I have found porting that code to ndarray quite pleasant, other than the issue we are discussing. The scalar support worked well. I don't enjoy the iadd style, but it is a good compromise until @= are widely available. I think I'll be porting a much bigger project soon. |
Thank you for sharing the code (I did compile it). This surprises me. Anyway, the primitive types do the same thing (different lifetime parameters) http://doc.rust-lang.org/nightly/std/primitive.f64.html so it seems like the right thing to do! For future reference, rebased PRs are preferable to merge (when possible). Great to hear your feedback. @= is stable in Rust 1.8 (it was just decided), so it's only 6 weeks left! 😄 I am continuously tweaking some details related to trait bounds on array elements and scalars for arithmetic operators. We can't really get everything we want, there's two reasons.
|
Allow &a @ &b to have different lifetimes
By the way, we want to make it easier to do multiple arithmetic operations without needing to create a temporary array like happens here. Like the issue #88 points out, it's already possible manually to use Even this could be possible: |
I think the lifetime behavior + error msg that commit gets in rustc was certainly confusing. What should I file a bug against? |
Yes |
There seem to be two natural types of interpretation for the same The other to my understanding, is creating expression trees that compose. This raises some issues:
|
Sorry, just realized you probably don't mean anything as complicated as I was referring to. Anyway, a question. In commit [1], in addition to working around the lifetime issue, I also added some to_owned's in a test, to comply with the signature I chose for next_value. What type/trait bound should I give data and/or self.mean in order to work with any reasonable kind of ndarray? I only read their content, so I really don't care whether I get an owned, shared, view or whatever storage strategy. This is a common case for me at least. |
How to design it in Rust an open ended question, so any complicated scheme is on topc. It may even be a major thing enough that it is best explored outside of ndarray. Rust has a pretty advanced type system too, but I don't know how well expression templates work out. About the question. Note that The simplest way to work with any array is to accept an array view (requires caller to convert to a view if needed). Apart from that, I'm not sure what to recommend, this is not fully fleshed out in the library. Accepting different array types right now requires using the |
I this requiring callers to convert into views is not great, ergonomically, Maybe we can use something like Deref? if you squint, any *Array points at On Wed, Mar 2, 2016 at 8:46 AM, bluss notifications@github.com wrote:
Daniel Vainsencher |
We should create an issue for that. We can't Deref directly to Introducing views was still a huge boon to the library. We can now do sensible things like mutable subviews, a mutable diagonal view, etc. Maybe it's possible to deref to something, or we can declare a new trait for all arrays, and we will also consider the |
Rust 1.22 fixes the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008 and rust-lang/rust#45435 for the issue and fix in Rust.)
Rust 1.23 fixes the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008 and rust-lang/rust#45435 for the issue and fix in Rust.)
Rust 1.23 fixed the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008 and rust-lang/rust#45435 for the issue and fix in Rust.)
Rust 1.23 fixed the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008, rust-lang/rust#45425, and rust-lang/rust#45435 for the relevant Rust issues/PRs.)
Rust 1.23 fixed the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008, rust-lang/rust#45425, and rust-lang/rust#45435 for the relevant Rust issues/PRs.)
Like it says, an about 5 character diff. Logic is that both operands are being read only, so there is no need on any lifetime constraint, in particular they do not need have the same lifetime.