-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Improved stack! implementation, tests #1375
Conversation
I just remembered that I wanted to change the default prefix used for the macro. I'll also do a review of the PR myself before assigning a reviewer. |
ac4860a
to
7940bd5
Compare
Note that this PR introduces some minor breaking changes by providing new trait methods with default impls:
Since they have default impls, they're very unlikely to break anyone's code (but it's possible in rare circumstances). Technically, it would be possible to implement I think in order to avoid breakage with the dimension traits, we should seal all of them. I have yet to see a legitimate use case for implementing any of the dim traits ( |
Assigning you for review due to your prior involvement in #1080, @tpdickso. Please let me know if you're not able to. Because I refactored some code in |
Just realized I hadn't tested any other built-ins than a single integer type. Added some basic sanity tests to ensure that stuff works as expected for the types we might care about (and by extension, it ought to work for any other arbitrary types). |
Nice! Looking forward to this addition! One comment for posterity that might be useful when discussing terminology and/or adding documentation. I was confused about stacking vs concatenation as a new numpy user, coming from matlab. I can foresee the same confusing arising here as well. Matlab use Numpy (and other python nd-array manipulation libs) use Julia also allows nd-arrays, with a generic Since nalgebra only have two-dimensional objects (vectors are matrices as well!) this means that the semantics are like in Matlab. But while the semantics are concatenations, the term chosen is PS. I personally don't care about the chosen term, as long as I manage to find it and use it. |
Thanks for the useful comparison with other libs/languages @el-hult! Based on your summary, I think discoverability is key. I think updating the user guide with a chapter on block matrix construction / concatenation will hopefully go a long way towards that. Here are the reasons I/we went with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic! The code, docs, and tests are great. No issues, just a formatting nit.
tests/macros/stack.rs
Outdated
assert_eq!( | ||
stack![a, 0; | ||
0, b], | ||
matrix![1, 2; | ||
3, 4; | ||
0, 0; | ||
0, 0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt
might have done something odd here, putting the first row of entries on a newline from the opening bracket might fix it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Thanks for the review @tpdickso. I fixed the formatting issue you pointed out. As I opened the code, the I think with this we're ready to merge. We don't yet have a clear routine for when to merge what (e.g. if the next release is a patch or a minor version bump etc.), so we'll have to figure out the plan for the next release(s) first. |
Cargo conventions leave it up to project discretion as to whether defaulted trait items are breaking. Given that people aren't going to be implementing the traits noted in #1375 (comment) on their own types, or calling those methods, very often themselves, I think it's reasonable to judge this non-breaking, if there's nothing else. |
Completely agree. I think a more useful label here would be |
By testing matrix!, stack! macros etc. in nalgebra, we ensure that these macros are used in the same way that users will be using them.
This improves error messages upon dimension mismatch, among other things. I've also tried to make the implementation easier to understand, adding some comments to help the reader understand the individual steps.
This gives more accurate compiler errors if matrix dimensions are mismatched.
This ensures that the expected generated code in tests is the actual generated code when used in the wild.
pedantic seems to be mostly intent on wasting the programmer's time
This PR improves upon #1080 with improved docs, extensive tests, and better UX through more accurate macro spans. The implementation of the
stack!
macro itself is hopefully also now a little bit easier to grok. The additional tests also uncovered an issue with the macro for accepting more complex expressions, which has now been fixed.Big thanks to @birktj for the initial implementation, which was really clever. His commits are of course preserved in this PR.
I'm excited to hopefully soon land this feature, it's been a long while in the making. Once again my apologies in leaving you waiting for so long @birktj.
Once this PR is merged, we should also update the user guide to include guidance on constructing block matrices with
stack!
. I also want to create an additional issue that proposes to extend thestack!
macro so that it can support diagonal concatenation and dynamic stacking by enabling slices of matrices to be valid inputs, in line with some of the ideas initially discussed in #446.