diff --git a/doc/notebooks/01_tutorial_getting_started.ipynb b/doc/notebooks/01_tutorial_getting_started.ipynb index 97ff73da1cf3bb63e19fa6fac122499120d71cee..8ae0745ee5523b794078c22fa840e497a00a9d26 100644 --- a/doc/notebooks/01_tutorial_getting_started.ipynb +++ b/doc/notebooks/01_tutorial_getting_started.ipynb @@ -932,14 +932,18 @@ } ], "source": [ - "import requests\n", - "import imageio\n", - "from io import BytesIO\n", + "try:\n", + " import requests\n", + " import imageio\n", + " from io import BytesIO\n", "\n", - "response = requests.get(\"https://www.python.org/static/img/python-logo.png\")\n", - "img = imageio.imread(BytesIO(response.content)).astype(np.double)\n", - "img /= img.max()\n", - "plt.imshow(img);" + " response = requests.get(\"https://www.python.org/static/img/python-logo.png\")\n", + " img = imageio.imread(BytesIO(response.content)).astype(np.double)\n", + " img /= img.max()\n", + " plt.imshow(img);\n", + "except ImportError:\n", + " print(\"No requests installed\")\n", + " img = None" ] }, { @@ -961,10 +965,11 @@ } ], "source": [ - "filtered_image = np.zeros_like(img[..., 0])\n", - "# here we call the compiled stencil function\n", - "compiled_kernel(img=img, dst=filtered_image, w_2=0.5)\n", - "plt.imshow(filtered_image, cmap='gray');" + "if img:\n", + " filtered_image = np.zeros_like(img[..., 0])\n", + " # here we call the compiled stencil function\n", + " compiled_kernel(img=img, dst=filtered_image, w_2=0.5)\n", + " plt.imshow(filtered_image, cmap='gray');" ] }, { diff --git a/doc/notebooks/demo_wave_equation.ipynb b/doc/notebooks/demo_wave_equation.ipynb index a4d5a9ff7c1cf5df33b83d3d48c3272f214a4d39..007e9a7b5dedb1cd07e6b8d7536bc4fc9d244a18 100644 --- a/doc/notebooks/demo_wave_equation.ipynb +++ b/doc/notebooks/demo_wave_equation.ipynb @@ -8,7 +8,9 @@ }, "outputs": [], "source": [ - "from pystencils.session import *" + "from pystencils.session import *\n", + "\n", + "import shutil" ] }, { @@ -397,8 +399,11 @@ } ], "source": [ - "ani = plt.surface_plot_animation(run, zlim=(-1, 1))\n", - "ps.jupyter.display_as_html_video(ani)" + "if shutil.which(\"ffmpeg\") is not None:\n", + " ani = plt.surface_plot_animation(run, zlim=(-1, 1))\n", + " ps.jupyter.display_as_html_video(ani)\n", + "else:\n", + " print(\"No ffmpeg installed\")" ] }, { diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py index 1c7c722cbe273329bc2a15521fbc933b00f56606..c00d6028b8fc066358c05013ec2e24f2ffd3419e 100644 --- a/pystencils/backends/cbackend.py +++ b/pystencils/backends/cbackend.py @@ -389,7 +389,7 @@ class CustomSympyPrinter(CCodePrinter): elif isinstance(expr, sp.Abs): return "abs({})".format(self._print(expr.args[0])) elif isinstance(expr, sp.Mod): - if expr.is_integer: + if expr.args[0].is_integer and expr.args[1].is_integer: return "({} % {})".format(self._print(expr.args[0]), self._print(expr.args[1])) else: return "fmod({}, {})".format(self._print(expr.args[0]), self._print(expr.args[1])) diff --git a/pystencils_tests/test_loop_cutting.py b/pystencils_tests/test_loop_cutting.py index cd89f37f6f365b4223e1463db68874f50e81c46d..0291074b87c051bcf381883e474078c663274ac1 100644 --- a/pystencils_tests/test_loop_cutting.py +++ b/pystencils_tests/test_loop_cutting.py @@ -1,6 +1,8 @@ import numpy as np import sympy as sp +import pytest + import pystencils as ps import pystencils.astnodes as ast from pystencils.field import Field, FieldType @@ -57,6 +59,7 @@ def test_staggered_iteration(): sum(f[o] for o in offsets_in_plane(d, -1, dim))) assignments = [ps.Assignment(s.staggered_access(d), expressions[i]) for i, d in enumerate(s.staggered_stencil)] func_optimized = create_staggered_kernel(assignments).compile() + pytest.importorskip('islpy') assert not func_optimized.ast.atoms(Conditional), "Loop cutting optimization did not work" func(f=f_arr, s=s_arr_ref) @@ -99,6 +102,7 @@ def test_staggered_iteration_manual(): move_constants_before_loop(kernel_ast.body) cleanup_blocks(kernel_ast.body) + pytest.importorskip('islpy') assert not kernel_ast.atoms(Conditional), "Loop cutting optimization did not work" func_optimized = make_python_function(kernel_ast) diff --git a/pystencils_tests/test_plot.py b/pystencils_tests/test_plot.py index 6234334bb91352c80c643c474c76c15b968ce1c7..4c9207216266e48d4f2b0b14db1a5e160732c5cb 100644 --- a/pystencils_tests/test_plot.py +++ b/pystencils_tests/test_plot.py @@ -1,5 +1,8 @@ import os from tempfile import TemporaryDirectory +import shutil + +import pytest import numpy as np @@ -20,6 +23,7 @@ def example_vector_field(t=0, shape=(40, 40)): return result +@pytest.mark.skipif(shutil.which('ffmpeg') is None, reason="ffmpeg not available") def test_animation(): t = 0 diff --git a/pystencils_tests/test_staggered_kernel.py b/pystencils_tests/test_staggered_kernel.py index 310220d21442dc1d1a24b0e74e50f3e068374b67..c4f491393d2b4d08fbb9b4c99356abdc7e7199b6 100644 --- a/pystencils_tests/test_staggered_kernel.py +++ b/pystencils_tests/test_staggered_kernel.py @@ -1,6 +1,8 @@ import numpy as np import sympy as sp +import pytest + import pystencils as ps @@ -88,6 +90,7 @@ def test_staggered_subexpressions(): def test_staggered_loop_cutting(): + pytest.importorskip('islpy') dh = ps.create_data_handling((4, 4), periodicity=True, default_target='cpu') j = dh.add_array('j', values_per_cell=4, field_type=ps.FieldType.STAGGERED) assignments = [ps.Assignment(j.staggered_access("SW"), 1)]