-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
Multiply matrix by vector row-wise #1358
Comments
Can you elaborate on how you want this operation to work? The example you've given doesn't seem quite correct, as far as I can tell; m.row_iter_mut().zip(v.iter()).for_each(|(row, component)| {
row *= component;
}) should likely do roughly the same thing execution-wise as a built-in method would do; do you have a use-case for this for which this approach benchmarks poorly? Can you elaborate on the use-case for this per-row componentwise multiplication? This could be a built-in method on |
I have a 3x3 transformation matrix I agree with both your points:
I was just asking if it's a good idea. However, now that I think about it more. There's no need to add a method. This operation could use the |
The |
If I understand @nilgoyette correctly, I think this is mathematically best expressed by the multiplication of a diagonal matrix and a matrix, i.e. I don't think we want to mimic numpy's unintuitive implicit broadcasting features. EDIT: I think I got the order reversed, it's a ambiguous from @nilgoyette original example, since they're using the identity matrix for |
Is there still discussion on what that would look like? Would you accept a PR for it? Something like |
We should probably flesh this out in a separate issue, but I'll give you some starting points. However, I think @sebcrozet has been skeptical to adding it in the past, because of the combinatorial explosion in adding more types that need to interact with matrices (and references, mutable references ...). However, I'm personally in favor of at least exploring this option, because I find myself missing diagonal matrices in every project I work on. I think we might consider something like a wrapper around a vector storage, so it might look like: pub struct DiagonalMatrix<T, N, S> {
data: Vector<T, N, S>
} and then on I think a small prototype around this idea shouldn't be too much work, and could help us figure out the trade-offs and design considerations better. If you want, feel free to join us on our Discord server for some casual discussion. |
How can I multiply a matrix and a vector "row-wise" in nalgebra? Like I would do in numpy
I understand that I can convert my vector into a square matrix, then use
*
(ordot
) or code a generic function that does this task but multiplying each row with a number will be faster.I thought there would be be a method/operator that does it, so I asked this question on the r/rust "simple question" post and on SO. It seems that such a method doesn't exist. Can you please confirm?
Moreover, if this is right, should we add this method, and what would be its name?
The text was updated successfully, but these errors were encountered: