Python square brackets between function name and arguments: func[...](...)
<p>I was learning how to accelerate python computations on GPU from <a href="https://nbviewer.jupyter.org/gist/harrism/f5707335f40af9463c43" rel="nofollow">this notebook</a>, where one line confuses me:</p>

<pre><code>mandel_kernel[griddim, blockdim](-2.0, 1.0, -1.0, 1.0, d_image, 20)
</code></pre>

<p>Here, <code>mandel_kernel</code> is a decorated (by <code>cuda.jit</code>) function, <code>griddim</code> and <code>blockdim</code> are tuples of length 2: <code>griddim=(32,16)</code>, <code>blockdim=(32,8)</code>.</p>

<p>Is this square brackets in between function name and argument list part of python syntax, or something specific to the <code>cuda.jit</code> decoration?</p>

<p>This is valid python syntax, i'll try to break it down for you:</p>

<p><code>mandel_kernel</code> is a dict, whose keys are 2-tuples (griddim, blockdim) and values are method (which is valid since methods are objects in python)</p>

<p><code>mandel_kernel[griddim, blockdim]</code> therefore 'returns' (or evaluates to) a method</p>

<p><code>mandel_kernel[griddim, blockdim](-2.0, 1.0, -1.0, 1.0, d_image, 20)</code> therefore calls that method with whatever arguments are inside the parenthesis.</p>

<p>This one line could be rewritten in three lines like so:</p>

<pre><code>key = tuple(griddim, blockdim)
method = mandel_kernel[key]
method(-2.0, 1.0, -1.0, 1.0, d_image, 20)
</code></pre>

python python-decorators numba numba-pro