Skip to content

Commit 96eb94e

Browse files
committed
Weird changes needed...
_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.
1 parent 1313e20 commit 96eb94e

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

mathics/builtin/drawing/plot.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ def eval(self, points, evaluation: Evaluation, options: dict):
301301

302302
class_name = self.__class__.__name__
303303

304+
# Scale point values down by Log 10. Tick mark values will be adjusted to be 10^n in GraphicsBox.
305+
if self.use_log_scale:
306+
points = ListExpression(
307+
*(
308+
Expression(SymbolLog10, point).evaluate(evaluation)
309+
for point in points
310+
)
311+
)
312+
313+
points = points.evaluate(evaluation)
304314
if not isinstance(points, ListExpression):
305315
evaluation.message(class_name, "lpn", points)
306316
return
@@ -315,15 +325,6 @@ def eval(self, points, evaluation: Evaluation, options: dict):
315325
evaluation.message(class_name, "lpn", points)
316326
return
317327

318-
# Scale point values down by Log 10. Tick mark values will be adjusted to be 10^n in GraphicsBox.
319-
if self.use_log_scale:
320-
points = ListExpression(
321-
*(
322-
Expression(SymbolLog10, point).evaluate(evaluation)
323-
for point in points
324-
)
325-
)
326-
327328
# If "points" is a literal value with a Python representation,
328329
# it has a ".value" attribute with a non-None value. So here,
329330
# we don't have to eval_N().to_python().

mathics/core/expression.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,12 @@ def rules():
14101410
if not isinstance(result, EvalMixin):
14111411
return result, False
14121412
if result.sameQ(new):
1413-
new._timestamp_cache(evaluation)
1414-
return new, False
1413+
# Even though result and new may be the same,
1414+
# new can be a Expression[SymbolConstant: System`List...]
1415+
# while "result' might be ListExpression!?
1416+
# So make sure to use "result", not "new".
1417+
result._timestamp_cache(evaluation)
1418+
return result, False
14151419
else:
14161420
return result, True
14171421

mathics/eval/drawing/plot.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ def eval_ListPlot(
201201
[xx for xx, yy in plot_groups], [xx for xx, yy in plot_groups], x_range
202202
)
203203
plot_groups = [plot_groups]
204-
elif all(isinstance(line, list) for line in plot_groups):
205-
if not all(isinstance(line, list) for line in plot_groups):
204+
elif all(isinstance(line, (list, tuple)) for line in plot_groups):
205+
if not all(isinstance(line, (list, tuple)) for line in plot_groups):
206206
return
207207

208208
# He have a list of plot groups
209209
if all(
210-
isinstance(point, list) and len(point) == 2
211-
for plot_group in plot_groups
210+
isinstance(point, (list, tuple)) and len(point) == 2
211+
for _ in plot_groups
212212
for point in plot_groups
213213
):
214214
pass

0 commit comments

Comments
 (0)