Skip to content

Commit

Permalink
Weird changes needed...
Browse files Browse the repository at this point in the history
_ListPlot[] needs to evaluate its arguements in order to check them!
There is this weird place in caching where we were caching the
Expression form of a ListExpression. This is something that has been
plaguing our code. Finding and fixing these simplifies coding speeds up
execution.
  • Loading branch information
rocky committed Dec 25, 2024
1 parent 1313e20 commit 96eb94e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
19 changes: 10 additions & 9 deletions mathics/builtin/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ def eval(self, points, evaluation: Evaluation, options: dict):

class_name = self.__class__.__name__

# Scale point values down by Log 10. Tick mark values will be adjusted to be 10^n in GraphicsBox.
if self.use_log_scale:
points = ListExpression(
*(
Expression(SymbolLog10, point).evaluate(evaluation)
for point in points
)
)

points = points.evaluate(evaluation)
if not isinstance(points, ListExpression):
evaluation.message(class_name, "lpn", points)
return
Expand All @@ -315,15 +325,6 @@ def eval(self, points, evaluation: Evaluation, options: dict):
evaluation.message(class_name, "lpn", points)
return

# Scale point values down by Log 10. Tick mark values will be adjusted to be 10^n in GraphicsBox.
if self.use_log_scale:
points = ListExpression(
*(
Expression(SymbolLog10, point).evaluate(evaluation)
for point in points
)
)

# If "points" is a literal value with a Python representation,
# it has a ".value" attribute with a non-None value. So here,
# we don't have to eval_N().to_python().
Expand Down
8 changes: 6 additions & 2 deletions mathics/core/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,12 @@ def rules():
if not isinstance(result, EvalMixin):
return result, False
if result.sameQ(new):
new._timestamp_cache(evaluation)
return new, False
# Even though result and new may be the same,
# new can be a Expression[SymbolConstant: System`List...]
# while "result' might be ListExpression!?
# So make sure to use "result", not "new".
result._timestamp_cache(evaluation)
return result, False
else:
return result, True

Expand Down
8 changes: 4 additions & 4 deletions mathics/eval/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ def eval_ListPlot(
[xx for xx, yy in plot_groups], [xx for xx, yy in plot_groups], x_range
)
plot_groups = [plot_groups]
elif all(isinstance(line, list) for line in plot_groups):
if not all(isinstance(line, list) for line in plot_groups):
elif all(isinstance(line, (list, tuple)) for line in plot_groups):
if not all(isinstance(line, (list, tuple)) for line in plot_groups):
return

# He have a list of plot groups
if all(
isinstance(point, list) and len(point) == 2
for plot_group in plot_groups
isinstance(point, (list, tuple)) and len(point) == 2
for _ in plot_groups
for point in plot_groups
):
pass
Expand Down

0 comments on commit 96eb94e

Please sign in to comment.