Facing warning while dividing two integer values using "/"

Description of problem

I want to run one of the samples in Brian2 documentation which has the following term :

exc_neurons.x = '(i / N_rows)*grid_dist - N_rows/2.0*grid_dist'
exc_neurons.y = '(i % N_rows)*grid_dist - N_cols/2.0*grid_dist'

I get this warning :

WARNING The expression “i / N_rows” divides two integer values. In previous versions of Brian, this would have used either an integer (“flooring”) or a floating point division, depending on the Python version and the code generation target. In the current version, it always uses a floating point division. Explicitly ask for an integer division ("//"), or turn one of the operands into a floating point value (e.g. replace “1/2” by “1.0/2”) to no longer receive this warning. [brian2.parsing.bast.floating_point_division]

How can I solve it ?

Hi @Rihana . The idea of this code is to us an integer division. With N_rows = 56, it should give 0 for i = 0, 1, 2, 3, ... 55, then 1 for i = 56, 57, ... and so on. It should therefore use (i // N_rows) instead of (i / N_rows). You are probably looking at an older version of the documentation, in the current version it is already corrected: Example: example_6_COBA_with_astro — Brian 2 2.5.0.1 documentation

1 Like