[Feature request] `ArrayRef<A, Ix2>.dot()` for axis greater than `Ix2`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start from the ndarray dot() entry point and inspect how dimensions are currently constrained. Compare the requested behavior with the provided Ix3-by-Ix2 example, then verify that higher-rank left-hand arrays produce the expected NumPy-compatible shape while preserving existing Ix2 behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In NumPy, the left-hand side of a matrix multiplication can have as many axes as desired, as long as it has more than 2 axes and the last axis's dimension matches that of the 0th axis of the right-hand side, e.g.:
import numpy as np
x = np.random.random((3, 2, 5, 9, 12))
y = np.random.random((12, 13))
(x @ y).shape
# (3, 2, 5, 9, 13)
In ndarray, you can't do this directly:
// Doesn't compile:
use ndarray::prelude::*;
use ndarray_rand::RandomExt;
use ndarray_rand::rand_distr::Uniform;
fn main() {
let x: Array<f64, Ix3> = Array::random(
(12, 4, 3),
Uniform::new(0., 1.).unwrap()
);
let y: Array<f64, Ix2> = Array::random(
(3, 2),
Uniform::new(0., 1.).unwrap()
);
let x_y = x.dot(&y);
println!("{}", x_y);
}
Compiler Output
$ cargo run
Compiling playground v0.1.0 (/home/connor/RustroverProjects/playground)
error[E0275]: overflow evaluating the requirement `&ArrayBase<_, _, _>: Not`
--> src/main.rs:15:17
|
15 | let x_y = x.dot(&y);
| ^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`playground`)
= note: required for `&ArrayBase<_, _, _>` to implement `Not`
= note: 127 redundant requirements hidden
= note: required for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>, f64>` to implement `Not`
For more information about this error, try `rustc --explain E0275`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Emulating the behavior in the previous NumPy example requires a non-trivial amount of work, e.g. for x with 3 axes:
use ndarray::prelude::*;
use ndarray_rand::RandomExt;
use ndarray_rand::rand_distr::Uniform;
fn main() {
let x: Array<f64, Ix3> = Array::random((12, 4, 3), Uniform::new(0., 1.).unwrap());
let y = Array::random((3, 2), Uniform::new(0., 1.).unwrap());
let (a, b, c) = (x.len_of(Axis(0)), x.len_of(Axis(1)), x.len_of(Axis(2)));
let d = y.len_of(Axis(1));
let x_y: Array3<f64> = x
.to_shape((a * b, c)).unwrap()
.dot(&y)
.to_shape((a, b, d)).unwrap()
.to_owned();
println!("{:?}", x_y);
}
Therefore, I think it would be nice to have dot() be implemented for axis numbers greater than Ix2
- 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ự
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
n0-computer/iroh#4550 ·
-
impl detach for native Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
paritytech/zombienet-sdk#591 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
farion1231/cc-switch#7638 · 1 bình luận ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100