-
Notifications
You must be signed in to change notification settings - Fork 311
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
Zip and azip! behavior related to inputted NdProducers #453
Comments
The key thing here is that When zipping together producers with extern crate ndarray;
use ndarray::prelude::*;
use ndarray::{NdProducer, arr3};
fn main() {
let a = arr3(&[[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]);
let inner0 = a.lanes(Axis(0));
println!("shape of inner0 = {:?}", inner0.raw_dim());
for item in inner0 {
println!("item = {}", item);
}
let trial = arr1(&[0, 0, 0, 0, 0, 0]);
let tr_iter = trial.axis_iter(Axis(0));
println!("shape of tr_iter = {:?}", tr_iter.raw_dim());
for item in tr_iter {
println!("item = {}", item);
}
} which prints
If you expand the Zip::from(inner0).and(tr_iter).apply(|output, trial| {
println!("{:?}, {:?}", output, trial);
}); the first compilation error is a bit clearer:
It's an error to try to add Note that although for (output, trial) in inner0.into_iter().zip(tr_iter) {
println!("{:?}, {:?}", output, trial);
} which prints
Your second example works because
Why is #[macro_use]
extern crate ndarray;
fn main() {
let a = array![[1, 2, 3], [4, 5, 6]];
let b = array![[1, 2], [3, 4], [5, 6]];
azip!(a, b in {
println!("{} {}", a, b);
});
} How should the elements of More discussion about I do think the docs could be improved to make this clearer. For example, the docs for |
I think actually including examples that fail in the documentation wouldn't be a bad idea. By doing it this way, you can highlight what you mean by if any of the producers are not of the same shape. Also, I will say that thinking about how Another method that might be useful would work kinda similar to the above, but it would allow one to create an iterator that merges multiple outer axes together reducing the dimensionality of the array, and then iterating over a specified axis. Edit: I guess the above method could also work as long as the axes are next to each other as well. In my mind it would have a behavior something like:
The equivalent code using Ndarray today.
It would then print the same stuff we saw in your comment for either |
I'd like to work on this issue. Is there anything specific that I need to be aware of ? |
Oh man looking back on this issue after 3 years, I definitely would not have had time to work on a prototype of the functions I'd envisioned between finishing grad school and starting a new job hahaha. So, the maintainers might have some thoughts on this, but I would probably start with Arrays without custom strides initially just to keep things easy. It's been a while since I've normally worked with Rust, since my day to day job has me working with c++, so I would take that into consideration when reading my initial thoughts on this issue. For the |
This issue needs more design, potentially. For rcarson3's 2018 example #453 (comment) it looks good to to just use to_shape/into_shape with Order::F here when they arrive in smarter versions #390 #982? |
Ok, so then current So apart from the shaping, what remains in this issue seems to be:
|
Based on trying to help in Issue #452 , I found some interesting behavior regarding either
Zip
orazip!
. I've given examples down belowThe compiler returns the following error:
However, if I were to roll what inner0 outputs directly, I can get it to work no problem as seen below:
I feel that either method should work, since we contain the same number of "items" to iterate over in each version. So, I was curious if this is simply an error/bug in the code or is there a design choice behind one method failing to compile and the other one working.
The text was updated successfully, but these errors were encountered: