Skip to content

implement dot for higher-dimensional arrays with Ix2#1602

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

implement dot for higher-dimensional arrays with Ix2#1602
EbrahimEldesoky wants to merge 3 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)

@EbrahimEldesoky

Copy link
Copy Markdown
Contributor Author

hi @akern40 please when you have time check this pr

@nilgoyette

Copy link
Copy Markdown
Collaborator

One thing you could do before someone checks your PR is remove the formatting changes. It's hard[er] to know what you actually modified. We should probably format the whole project with a specific rule but it hasn't been done yet.

@EbrahimEldesoky

Copy link
Copy Markdown
Contributor Author

One thing you could do before someone checks your PR is remove the formatting changes. It's hard[er] to know what you actually modified. We should probably format the whole project with a specific rule but it hasn't been done yet.

One thing you could do before someone checks your PR is remove the formatting changes. It's hard[er] to know what you actually modified. We should probably format the whole project with a specific rule but it hasn't been done yet.

Thank you @nilgoyette, Please take a look.

@nilgoyette

Copy link
Copy Markdown
Collaborator

I don't know how common this operation is used (I never had to use it). If it is common, then yes we should add this feature to ndarray. Is it the same behavior as numpy dot?

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

2 participants