File: group_variable_get_conditional.pyx

package info (click to toggle)
brian 2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,872 kB
  • sloc: python: 51,820; cpp: 2,033; makefile: 108; sh: 72
file content (30 lines) | stat: -rw-r--r-- 806 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{# USES_VARIABLES { N } #}
{% extends 'common_group.pyx' %}

{% block maincode %}

    {%set c_type = cpp_dtype(variables['_variable'].dtype) %}
    {%set np_type = numpy_dtype(variables['_variable'].dtype) %}

    _vectorisation_idx = 1

    cdef size_t _N = {{constant_or_scalar('N', variables['N'])}}
    cdef size_t _num_elements = 0
    cdef _numpy.ndarray[{{c_type}}, ndim=1, mode='c'] _elements = _numpy.zeros(_N, dtype=_numpy.{{np_type}})
    cdef {{c_type}}[:] _elements_view = _elements


    {{scalar_code|autoindent}}

    for _idx in range(_N):
        _vectorisation_idx = _idx
        
        {{vector_code|autoindent}}
        
        if _cond:
            _elements_view[_num_elements] = _variable
            _num_elements += 1
    
    return _elements[:_num_elements]

{% endblock %}