Skip to content

Add printoptions - #3333

Merged
angeloskath merged 13 commits into
ml-explore:mainfrom
ChristophePRAT:feat/print_options
Apr 2, 2026
Merged

angeloskath merged 13 commits into
ml-explore:mainfrom
ChristophePRAT:feat/print_options

Conversation

@ChristophePRAT

Copy link
Copy Markdown
Contributor

Proposed changes

Add minimal print options similar to numpy's set_printoptions.

This PR should fix #471.

Quick example

import mlx.core as mx

a = mx.array([0.3668831623])

print(a) # 0.3668831623

with mx.printoptions(precision=2):
    print(a) # 0.37

print(a) # 0.3668831623

mx.set_printoptions(precision=4)
print(a) # 0.3669
print(a) # 0.3669

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Comment thread mlx/utils.h Outdated
Comment thread python/src/array.cpp Outdated
Comment thread python/src/array.cpp Outdated
Comment thread docs/src/python/printoptions.rst Outdated
@ChristophePRAT

Copy link
Copy Markdown
Contributor Author

Thank you very much for your feedback. I have incorporated all of the changes that you mentioned in the previous commits. Let me know if I missed something.

@zcbenz

zcbenz commented Apr 1, 2026

Copy link
Copy Markdown
Member

Can you rebase this PR on latest main branch and exclude unrelated commits?
Screenshot 2026-04-01 at 11 25 48

@ChristophePRAT

Copy link
Copy Markdown
Contributor Author

Sorry for the git mistakes. This should be solved.

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@ChristophePRAT

Copy link
Copy Markdown
Contributor Author

Thank you very much for the review and the feedback, really appreciate your time!

@angeloskath
angeloskath merged commit befe42d into ml-explore:main Apr 2, 2026
16 checks passed
@BrewTestBot BrewTestBot mentioned this pull request Apr 22, 2026
1 task done
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.

API for array printing options

3 participants