Skip to content
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

control the number of digits to display in matrices via IPython's %precision magic #30755

Closed
mwageringel opened this issue Oct 11, 2020 · 16 comments

Comments

@mwageringel
Copy link

Based on #30552, this ticket adds options for customizing the number of floating point digits to display in matrices. This is particularly useful for numeric computations involving large matrices.

The option is linked to the IPython magic %precision. (The IPython magic also sets the corresponding option in NumPy.)

sage: %precision 4
'%.4f'
sage: A = matrix.random(RDF, 5); A
[-0.01337  -0.9269  -0.0893   0.1784    0.975]
[  0.2152   0.6165   0.4195   0.7558  -0.9292]
[  0.8234  -0.2305     0.83  -0.9375   0.4938]
[ -0.6378   0.7058   0.1209  -0.9081  -0.9551]
[  0.9217  -0.3054  -0.2997   0.5871  -0.5642]
sage: %precision
'%r'
sage: A
[-0.013365510514271595   -0.9268868721196306  -0.08930150422327143   0.17839999989498323    0.9750196839071508]
[  0.21517169403284941    0.6165223907365385    0.4195049240955384    0.7557760012777428   -0.9291629307331721]
[   0.8233703740645537  -0.23053733934301857    0.8299695817296515   -0.9375095363818953    0.4937640499860838]
[  -0.6378186095056861    0.7057551432596336   0.12087801033553447   -0.9080993678019631   -0.9551440194578318]
[   0.9216765622236254  -0.30541498083145413  -0.29967291645930083    0.5871367386637378   -0.5642041854379536]

CC: @slel @DavidAyotte

Component: numerical

Author: Markus Wageringel

Branch/Commit: f7cc8c9

Reviewer: David Ayotte

Issue created by migration from https://trac.sagemath.org/ticket/30755

@mwageringel mwageringel added this to the sage-9.3 milestone Oct 11, 2020
@mwageringel
Copy link
Author

Commit: 98e0926

@mwageringel
Copy link
Author

Author: Markus Wageringel

@mwageringel
Copy link
Author

New commits:

7d0b54830552: implement global options for matrices
98e092630755: implement precision for display of matrices

@mwageringel
Copy link
Author

Branch: u/gh-mwageringel/30755

@mwageringel
Copy link
Author

Dependencies: #30552

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 12, 2020

Changed commit from 98e0926 to ec5440b

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 12, 2020

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

5fe9b2c30552: reset options after examples
ec5440b30755: implement precision for display of matrices

@mkoeppe
Copy link
Contributor

mkoeppe commented Mar 15, 2021

comment:4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 Mar 15, 2021
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 8, 2021

Changed commit from ec5440b to f7cc8c9

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 8, 2021

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

f7cc8c930755: implement precision for display of matrices

@mwageringel
Copy link
Author

comment:6

Rebased on 9.3.rc5.

@mwageringel
Copy link
Author

Changed dependencies from #30552 to none

@DavidAyotte
Copy link
Member

comment:7

Hello Markus,

Thanks for this enhancement. I have reviewed it and everything is correct. However, I got two unrelated errors when testing the whole documentation:

Running doctests with ID 2021-06-28-14-01-05-7ec3f02e.
Git branch: HEAD
Using --optional=build,debian,dochtml,pip,sage,sage_spkg
Doctesting 1 file.
sage -t --long --warn-long 160.0 --random-seed=0 src/sage/modules/fg_pid/fgp_module.py
**********************************************************************
File "src/sage/modules/fg_pid/fgp_module.py", line 1274, in sage.modules.fg_pid.fgp_module.FGP_Module_class.coordinate_vector
Failed example:
    Q.coordinate_vector(Q.0 - Q.1)
Expected:
    (1, -1)
Got:
    (1, 47)
**********************************************************************
File "src/sage/modules/fg_pid/fgp_module.py", line 1294, in sage.modules.fg_pid.fgp_module.FGP_Module_class.coordinate_vector
Failed example:
    Q.coordinate_vector(x)
Expected:
    (0, -1)
Got:
    (0, 11)
**********************************************************************
1 item had failures:
   2 of  23 in sage.modules.fg_pid.fgp_module.FGP_Module_class.coordinate_vector
    [397 tests, 2 failures, 2.04 s]
----------------------------------------------------------------------
sage -t --long --warn-long 160.0 --random-seed=0 src/sage/modules/fg_pid/fgp_module.py  # 2 doctests failed
----------------------------------------------------------------------
Total time for all tests: 2.1 seconds
    cpu time: 2.0 seconds
    cumulative wall time: 2.0 seconds

I tested this module outside of your ticket (on the develop branch) and I also got the same error, so it is definitely not related with your code. Do you know if there is already a ticket about this?

EDIT: this issue is already known and is covered in ticket #32048

@DavidAyotte
Copy link
Member

Reviewer: David Ayotte

@mwageringel
Copy link
Author

comment:9

Thank you for the review, David.

@vbraun
Copy link
Member

vbraun commented Jun 29, 2021

Changed branch from u/gh-mwageringel/30755 to f7cc8c9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants