From 59a4cb0d41af5eeec91b9d25cfcdb0ea2ac6391b Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Mon, 5 Feb 2024 16:23:44 +0100 Subject: [PATCH] Use cpow=True in Python Avoids that x**y becomes a float for two integers, leading to compilation errors cpow=True has been the default in Cython, but it changed to cpow=False with Cython 3.0 Fixes #1500 --- .../cython_rt/templates/common_group.pyx | 1 + brian2/tests/test_functions.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/brian2/codegen/runtime/cython_rt/templates/common_group.pyx b/brian2/codegen/runtime/cython_rt/templates/common_group.pyx index 881fc74f9..0b24c5a3c 100644 --- a/brian2/codegen/runtime/cython_rt/templates/common_group.pyx +++ b/brian2/codegen/runtime/cython_rt/templates/common_group.pyx @@ -3,6 +3,7 @@ #cython: boundscheck=False #cython: wraparound=False #cython: cdivision=False +#cython: cpow=True #cython: infer_types=True {% endmacro %} diff --git a/brian2/tests/test_functions.py b/brian2/tests/test_functions.py index 811b58d8c..5d1683943 100644 --- a/brian2/tests/test_functions.py +++ b/brian2/tests/test_functions.py @@ -187,6 +187,24 @@ def test_bool_to_int(): assert_equal(s_mon.intexpr2.flatten(), [1, 0]) +@pytest.mark.standalone_compatible +def test_integer_power(): + # See github issue #1500 + G = NeuronGroup( + 3, + """ + intval1 : integer + intval2 : integer + k : integer (constant) + """, + ) + G.k = [0, 1, 2] + G.run_regularly("intval1 = 2**k; intval2 = (-1)**k") + run(defaultclock.dt) + assert_equal(G.intval1[:], [1, 2, 4]) + assert_equal(G.intval2[:], [1, -1, 1]) + + @pytest.mark.codegen_independent def test_timestep_function(): dt = defaultclock.dt_