Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • pystencils pystencils
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 18
    • Issues 18
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pycodegen
  • pystencilspystencils
  • Merge requests
  • !282

Fix RoundOff problems

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Markus Holzer requested to merge holzer/pystencils:RoundOffError into master Dec 20, 2021
  • Overview 0
  • Commits 2
  • Pipelines 2
  • Changes 3

When printing Rationals with pystencils at the moment the number of digits which will be printed is only 15. This is not enough for DP and thus Error is introduced in the printed code...

The reason for this is the following line: str(expr.evalf().num)

Here it is important to know what is happening. First of all the Rational is evaluated with Sympy with 15 digits, because SymPy defaults to 15 digits when using evalf: https://docs.sympy.org/latest/modules/evalf.html

but the story continues: .num is not a SymPy function !!!! This comes from mpmath so the Rational is converted to an sp.Float and then to a mpmath.ctx_mp_python.mpf. And yet again mpmath provides also a notion of precision. This could be set with mpmath.mp.dps = 30 for example. However, why should this be done in that way here anyway?

In this MR the .num function is removed and all evalf functions in pystencils are set to evalf(17). Note here that the SymPy printer on the other hand knows very well which precision it needs to provide. Thus when using a float inside the Assignment SymPy prints this correctly.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: RoundOffError