Skip to content

Commit 68e1ae5

Browse files
authored
Fix vectorized contour plot bugs and add tests (#1545)
1 parent 73cbe0a commit 68e1ae5

File tree

6 files changed

+4993
-3626
lines changed

6 files changed

+4993
-3626
lines changed

mathics/eval/drawing/plot3d_vectorized.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def eval_ContourPlot(
225225
# convert fs of the form a==b to a-b, inplicit contour level 0
226226
plot_options.functions = list(plot_options.functions) # so we can modify it
227227
for i, f in enumerate(plot_options.functions):
228-
if f.head == SymbolEqual:
228+
if hasattr(f, "head") and f.head == SymbolEqual:
229229
f = Expression(SymbolSubtract, *f.elements[0:2])
230230
plot_options.functions[i] = f
231231
contour_levels = [0]
@@ -264,7 +264,7 @@ def emit(graphics, i, xyzs, quads):
264264
for level in levels:
265265
# find contours and add lines
266266
with Timer("contours"):
267-
zgrid = zs.reshape((nx, ny)) # find_contours needs it as an array
267+
zgrid = zs.reshape((nx, ny)).T # find_contours needs it as an array
268268
contours = skimage.measure.find_contours(zgrid, level)
269269

270270
# add lines

test/builtin/drawing/test_plot_detail.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@
129129
print(f"ref_dir {ref_dir}")
130130

131131

132-
doc_tests_fn = pathlib.Path(__file__).resolve().parent / "doc_tests.yaml"
133-
with open(doc_tests_fn) as r:
134-
doc_tests = yaml.safe_load(r)
135-
136-
137132
def one_test(name, str_expr, vec, opt, act_dir="/tmp"):
138133
# update name and set use_vectorized_plot depending on
139134
# whether vectorized test
@@ -190,6 +185,30 @@ def one_test(name, str_expr, vec, opt, act_dir="/tmp"):
190185
plot.use_vectorized_plot = False
191186

192187

188+
def yaml_tests(fn, act_dir, vec):
189+
"""run a set of tests from yaml file fn"""
190+
191+
# read the yaml file
192+
fn = pathlib.Path(__file__).resolve().parent / fn
193+
with open(fn) as r:
194+
tests = yaml.safe_load(r)
195+
196+
# switch to appropriate mode
197+
plot.use_vectorized_plot = vec
198+
199+
for name, info in tests.items():
200+
skip = info.get("skip", False)
201+
if isinstance(skip, str):
202+
skip = {
203+
"pyodide": pyodide, # skip if on pyodide
204+
"skimage": not skimage, # skip if no skimage
205+
}[skip]
206+
if not skip:
207+
one_test(name, info["expr"], vec, ..., act_dir)
208+
else:
209+
print(f"skipping {name}")
210+
211+
193212
def test_all(act_dir="/tmp", opt=None):
194213
# run twice, once without and once with options
195214
for use_opt in [False, True]:
@@ -211,17 +230,8 @@ def test_all(act_dir="/tmp", opt=None):
211230
# the tests above seem so far to be ok on pyodide, but generally they are
212231
# simpler than these doc_tests
213232
if not pyodide:
214-
for name, info in doc_tests.items():
215-
skip = info.get("skip", False)
216-
if isinstance(skip, str):
217-
skip = {
218-
"pyodide": pyodide, # skip if on pyodide
219-
"skimage": not skimage, # skip if no skimage
220-
}[skip]
221-
if not skip:
222-
one_test(name, info["expr"], False, ..., act_dir)
223-
else:
224-
print(f"skipping {name}")
233+
yaml_tests("doc_tests.yaml", act_dir, vec=False)
234+
yaml_tests("vec_tests.yaml", act_dir, vec=True)
225235

226236

227237
# reference files can be generated by pointing saved actual

0 commit comments

Comments
 (0)