-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[stdlib] Add __repr__
in SIMD
#2728
Conversation
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.
Thanks, this could be a good improvement! I wonder what we should do with floating point values. We looked at this recently with @ConnorGray for numpy, but I can't remember what we concluded. Since we don't have good utilities for controlling floating point printing precision globally (the way numpy does), it might be safest to print all useful digits (the number of which depends on the float type), and use scientific notation.
Either way, please add a changelog entry.
Could you please rebase this after tomorrow's nightly? Also, I really think the implementation should be verbose here, and print all significant digits and use scientific notation. |
Sorry could you maybe give an example of the output you're expecting? |
Something like this: assert_equal(
SIMD[DType.float32, 1](1232.4).__repr__(),
"SIMD[DType.float32, 1](1.2324000e+03)", # 8 digits for float32, 16 for float64, etc
) Looking at this now, I'm not actually sure about the trailing zeros, but in repr, I would prefer scientific notation. |
Ok I'll do that thanks! |
f5d3e45
to
53ca34b
Compare
@laszlokindrat I've got the scientific notation working, hopefully you don't find the required changes too invasive. For now I haven't worried about trailing zeroes until you've made a concrete decision on that front. |
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.
Thanks for pushing this forward! The behavior with respect to trailing zeros is fine for now; we can iterate later if needed. Could you please rebase and ensure CI is happy?
Signed-off-by: Brian Grenier <grenierb96@gmail.com>
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.
Awesome, thanks!
!sync |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
Landed in ec6ecf9! Thank you for your contribution 🎉 |
[External] [stdlib] Add `__repr__` in `SIMD` Implements `__repr__` for `SIMD` --------- Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com> Closes #2728 MODULAR_ORIG_COMMIT_REV_ID: 53688198a78f892e2d4799bc8bec3f7974a538fb
Implements
__repr__
forSIMD