sarah-ek / faer-rs

Linear algebra foundation for the Rust programming language
https://faer-rs.github.io
MIT License
1.8k stars 58 forks source link

Matrix Addition and Subtraction using `+` and `-` Operators #41

Closed geo-ant closed 11 months ago

geo-ant commented 1 year ago

Is your feature request related to a problem? Please describe.

Hey, this might be an embarrassingly dumb question, but I cannot see a way to add two matrices using + (or subtract using -). The official website does mention that the addition and subtraction operators should work as expected, but when I write a+b for e.g. two Mat<f64> instances, it won't compile. Looking at the faer_core crate I cannot find an implementation of core::ops::Add. What am I missing?

Describe the solution you'd like

It would be great if the + operator would just work for two suitable Mat<E> instances as well as one Mat<E> and the as a suitable MatRef instance. I can elaborate on what I mean by suitable, but roughly I mean if the entities can be added, then the matrix should be addable (given that the matrix dimensions match).

Describe alternatives you've considered I could of course do element wise additions manually, but that would feel so much less ergonomic than having an Add trait implemented. Same for AddAssign.

Additional context

If I missed an obvious way to add matrices, I'd really appreciate a hint. If the Add and AddAssign, Sub, and SubAssign traits are indeed not implemented I'd be very happy to file a PR because this crate is really awesome. Please let me know and thanks for your work :)

sarah-ek commented 1 year ago

ah, yeah. it used to be possible to add two matrices. but i forgot to add it back since i refactored the code a while ago. i'll put it on my todo list

geo-ant commented 1 year ago

ah, yeah. it used to be possible to add two matrices. but i forgot to add it back since i refactored the code a while ago. i'll put it on my todo list

Hey, if you want I'll file a PR. You can give me a rough sketch of where you want the code to be and if there are special things I need to pay attention to. I'm happy to help :)