Skip to content

implement dot for higher-dimensional arrays with Ix2#1602

Open
EbrahimEldesoky wants to merge 2 commits into
rust-ndarray:masterfrom
EbrahimEldesoky:nd-dot-ix2
Open

implement dot for higher-dimensional arrays with Ix2#1602
EbrahimEldesoky wants to merge 2 commits into
rust-ndarray:masterfrom
EbrahimEldesoky:nd-dot-ix2

Conversation

@EbrahimEldesoky

Copy link
Copy Markdown
Contributor

closes #1587

right now calling .dot() on anything above Ix2 doesn't work, so if you have a 3-D or 5-D array and want to multiply it by a matrix you have to manually reshape, dot, then reshape back.

this adds Dot<ArrayRef<A, Ix2>> for Ix3, Ix4, Ix5, Ix6, and IxDyn. the implementation flattens all axes except the last into a single "rows" dimension, delegates to the existing 2-D dot (which already handles BLAS), then reshapes the result back to the correct output shape.

for example:

use ndarray::prelude::*;
use ndarray::linalg::Dot;

let x = Array5::<f64>::zeros((3, 2, 5, 9, 12));
let y = Array2::<f64>::zeros((12, 13));
let z = x.dot(&y); // shape: (3, 2, 5, 9, 13)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] ArrayRef<A, Ix2>.dot() for axis greater than Ix2

1 participant