Opened 12 years ago
Closed 12 years ago
#8707 closed defect (fixed)
view(x) calls x._latex_() 5 times!
Reported by: | Nicolas M. Thiéry | Owned by: | Alex Ghitza |
---|---|---|---|
Priority: | major | Milestone: | sage-4.4 |
Component: | misc | Keywords: | latex |
Cc: | Sage Combinat CC user | Merged in: | sage-4.4.alpha1 |
Authors: | Nicolas M. Thiéry | Reviewers: | Andrey Novoseltsev |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
latex(x) calls x._latex_() twice, and view(x) 5 times!!!
For small objects, that's fine, but when x is a graph, and latex'ing it requires calling graphviz, dot2tex, ... it is not reasonable!
sage: class blah(): ....: def _latex_(x): ....: print "coucou" ....: return "x" ....: sage: latex(blah()) coucou coucou x sage: view(blah()) coucou coucou coucou coucou coucou
Analysis:
- latex makes use of has_latex_expr which makes a call to _latex_ but discards the result
- latex_file does not reuse its calls to latex(x)
Attachments (1)
Change History (6)
Changed 12 years ago by
Attachment: | trac_8707-5x_faster_latex-nt.patch added |
---|
comment:1 Changed 12 years ago by
Authors: | → Nicolas M. Thiéry |
---|---|
Cc: | Sage Combinat CC user added |
Component: | algebra → misc |
Status: | new → needs_review |
comment:2 Changed 12 years ago by
Reviewers: | → Andrey Novoseltsev |
---|---|
Status: | needs_review → positive_review |
Looks good, passes all doctests!
comment:3 Changed 12 years ago by
Do we know for sure that types are the only sorts of objects which have this problem (that is, which seem to inherit a _latex_
method according to hasattr, but which actually don't when you try to call it)?
comment:4 Changed 12 years ago by
I thought about it, but it seems to me that such objects should be "special" rather than "usual". Then it makes sense to check if x is in one of the special classes and hope that everything is good otherwise, i.e. return True. If it will turn out that there are other special cases, we can add tests for them and document them!
comment:5 Changed 12 years ago by
Merged in: | → sage-4.4.alpha1 |
---|---|
Resolution: | → fixed |
Status: | positive_review → closed |
Merged into 4.4.alpha1.
Now, e.g.
takes 6 seconds instead of .5 minutes, which makes it finally usable!