Feature suggestion: impl Default for Zip, and add Zip::with_shape() constructor
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by reviewing the existing Zip::from, Zip::and, and and_broadcast entry points and how they handle shapes and broadcasting. Compare the proposed Default and Zip::with_shape APIs with the motivating example; done means the API direction and resulting behavior are clearly agreed and validated.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Motivating example: I'm computing 3D positions on a unit sphere from a uniform grid of (longitude, latitude) pairs. This is what it looks like now:
const SHAPE: (usize, usize) = (HEIGHT, WIDTH);
let cell_size_lon = TAU / WIDTH as f32;
let cell_size_lat = PI / HEIGHT as f32;
let lon = Array1::linspace(cell_size_lon, TAU - cell_size_lon, WIDTH)
.into_shape((1, WIDTH)).unwrap();
let lat = Array1::linspace(-FRAC_PI_2 + cell_size_lat, FRAC_PI_2 - cell_size_lat, HEIGHT)
.into_shape((HEIGHT, 1)).unwrap();
let pos = Zip::from(lat.mapv(f32::cos).broadcast(SHAPE).unwrap())
.and(lat.mapv(f32::sin).broadcast(SHAPE).unwrap())
.and(lon.mapv(f32::cos).broadcast(SHAPE).unwrap())
.and(lon.mapv(f32::sin).broadcast(SHAPE).unwrap())
.par_map_collect(|&cos_lat, &sin_lat, &cos_lon, &sin_lon| {
Vec3::new(cos_lat * sin_lon, sin_lat, cos_lat * cos_lon)
});
I know about azip! and par_azip! but I don't think the small reduction in character count outweighs the additional "magic" syntax, so I don't use them.
Notice the distinction between Zip::from and Zip::and even though these both serve the same purpose: add another producer to the Zip.
This lopsided distinction could be eliminated if Zip implemented Default (and/or had the customary zero-args new() constructor):
let pos = Zip::default()
.and(lat.mapv(f32::cos).broadcast(SHAPE).unwrap())
.and(lat.mapv(f32::sin).broadcast(SHAPE).unwrap())
.and(lon.mapv(f32::cos).broadcast(SHAPE).unwrap())
.and(lon.mapv(f32::sin).broadcast(SHAPE).unwrap())
.par_map_collect(|&cos_lat, &sin_lat, &cos_lon, &sin_lon| {
Vec3::new(cos_lat * sin_lon, sin_lat, cos_lat * cos_lon)
});
Even nicer (for this use case) would be if we could specify the shape once up front in the constructor, so we could use and_broadcast on all producers (not just the 2nd-4th):
let pos = Zip::with_shape(SHAPE)
.and_broadcast(lat.mapv(f32::cos))
.and_broadcast(lat.mapv(f32::sin))
.and_broadcast(lon.mapv(f32::cos))
.and_broadcast(lon.mapv(f32::sin))
.par_map_collect(|&cos_lat, &sin_lat, &cos_lon, &sin_lon| {
Vec3::new(cos_lat * sin_lon, sin_lat, cos_lat * cos_lon)
});
I can't tell whether this is at all feasible or desirable, just throwing it out there for your consideration, and so that other users with similar needs can chime in.
- Ngôn ngữ chính
- Rust
- Star
- 4.3k
- Fork
- 391
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-ndarray/ndarray
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rust-ndarray/ndarray#1612 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
rust-ndarray/ndarray#1617 · 1 bình luận ·
-
Stack overflow in `triu` Đang mởbug good first issue
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
rust-ndarray/ndarray#1615 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
rust-ndarray/ndarray#1610 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
rust-ndarray/ndarray#1609 ·
Tất cả issue của rust-ndarray/ndarray
Issue tương tự
-
risk:low runtime status:in-progress type:test
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
EricSpencer00/Resilient#4835 · 1 bình luận ·
-
agent:ready documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
cesarferreira/stax#890 ·
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100