Opened 11 years ago

Last modified 11 years ago

#11885 closed defect

call function in sage.libs.mpmath.utils doesn't handle parent=parent(float) — at Version 4

Reported by: benjaminfjones Owned by: burcin
Priority: major Milestone: sage-4.8
Component: symbolics Keywords: mpmath call parent precision
Cc: burcin Merged in:
Authors: Benjamin Jones Reviewers: Burcin Erocal
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by benjaminfjones)

In multiple places in the Sage library the function is called and inputs are passed along with their parents. If the parent of the input doesn't have a prec method, an AttributeError is raised:

sage: import sage.libs.mpmath.all as a
sage: z = float(4)
sage:, z)
sage:, z, parent=parent(z))
AttributeError                            Traceback (most recent call last)

/Users/jonesbe/sage/sage-4.7.2.alpha2/devel/sage-test/sage/<ipython console> in <module>()

/Users/jonesbe/sage/latest/local/lib/python2.6/site-packages/sage/libs/mpmath/ in (sage/libs/mpmath/utils.c:5277)()

AttributeError: type object 'float' has no attribute 'prec'

This can be fixed with a simple check in in the call code in sage/libs/mpmath/utils.pyx.

Apply trac_11885_v2.patch to the Sage library.

Change History (6)

Changed 11 years ago by benjaminfjones

adds check that parent has attribute 'prec' before calling

comment:1 Changed 11 years ago by leif

  • Authors set to Benjamin Jones
  • Description modified (diff)
  • Keywords precision added
  • Status changed from new to needs_review

comment:2 Changed 11 years ago by burcin

  • Reviewers set to Burcin Erocal
  • Status changed from needs_review to needs_work

Thanks for the patch. It looks good, though I have minor suggestions:

  • this needs to be doctested
  • using
        prec = parent.prec()
    except AttributeError:

might be faster than performing a test with hasattr() first, then looking up the prec() method again.

Changed 11 years ago by benjaminfjones

adds an exception check in call()

comment:3 Changed 11 years ago by benjaminfjones

  • Status changed from needs_work to needs_review

Good point! I made the change and added a doctest to call() to illustrate that the bug is fixed.

The change does give a speedup. The best case I found was running

sage: timeit(', 1.0r, parent=float)')

Before the old patch, I was getting about 87 micro seconds. With the new patch, the best time I got was about 60 micro seconds.

comment:4 Changed 11 years ago by benjaminfjones

  • Description modified (diff)
Note: See TracTickets for help on using tickets.