Repository: brian-team/brian2 (language: python)

Issue:
A bug in the Synapse.connect documentation
Python version: 3.8. Platform: windows 10. Brian2 version: 2.5.1
In the documentation of [Synapses class](https://brian2.readthedocs.io/en/2.5.1/reference/brian2.synapses.synapses.Synapses.html?highlight=connect#brian2.synapses.synapses.Synapses.connect), there is an example of `connect` usage
```python
S.connect(j='i+(-1)**k for k in range(2) if i>0 and i<N_pre-1') # connect neuron i to its neighbours if it has both neighbours
```
I ran it myself, but was given the following error:
```python
Error compiling Cython file:
------------------------------------------------------------
...
        for k in range(_iter_low, _iter_high, _iter_step):

                        
            _pre_idx = _raw_pre_idx
            i = _i
            _j = i + ((- 1) ** k)
                   ^
------------------------------------------------------------

C:\Users\13372\.cython\brian_extensions\_cython_magic_16a1c724b1adb9773451a3d083b2c890.pyx:190:19: Cannot assign type 'double' to 'int32_t'
```
It seems that `i` is `int32_t` while (-1)**k is double, and these two cannot summed directly. So I cast the latter into `int32_t` manually:
```python
S.connect(j='i+int((-1)**k) for k in range(2) if i>0 and i<N_pre-1')
```
And now it works. Hope this will be revised in future.


Discussion / hints:
Dear @Jasmine969, many thanks for the report. I did not yet look into it in detail, but from what you state it rather looks like a bug in the Cython code generation (`(-1)**k` should stay an int), than a bug in the documentation. I think it has to do with a change in semantics between Cython 0.29 (our minimal dependency) and Cython 3.0 (the latest version). We can probably/hopefully fix it quite easily with a [`cpow` compiler directive](https://cython.readthedocs.io/en/stable/src/userguide/source_files_and_compilation.html#compiler-directives) – could you maybe quickly confirm that you  are using Cython 3.x? Thanks!
> Dear @Jasmine969, many thanks for the report. I did not yet look into it in detail, but from what you state it rather looks like a bug in the Cython code generation (`(-1)**k` should stay an int), than a bug in the documentation. I think it has to do with a change in semantics between Cython 0.29 (our minimal dependency) and Cython 3.0 (the latest version). We can probably/hopefully fix it quite easily with a [`cpow` compiler directive](https://cython.readthedocs.io/en/stable/src/userguide/source_files_and_compilation.html#compiler-directives) – could you maybe quickly confirm that you are using Cython 3.x? Thanks!

it is cython 3.0.8

Fix patch:
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 %}
 


Test patch:
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_