Skip to content

Commit 134eb58

Browse files
authored
Merge pull request nest#759 from pnbabu/vectors_bug
Fix bug in vectors when there is a single vector state variable
2 parents 9729af7 + 085d1b6 commit 134eb58

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

pynestml/codegeneration/resources_nest/point_neuron/directives/DynamicStateElement.jinja2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ inline double get_state_element(size_t elem)
1515
else if
1616
{%- endif %}
1717

18-
{%- if loop.index != len %}
18+
{%- if len == 1 or loop.index < len %}
1919
{%- if variable.has_vector_parameter() %}
2020
{%- set size = variable.get_vector_parameter() %}
2121
{%- if size|int == 0 %}
2222
{%- set size = printer.print_vector_size_parameter(variable) %}
2323
{%- endif -%}
2424
(elem >= State_::{{names.name(variable).upper()}} && elem < State_::{{names.name(variable).upper()}} + {{size}})
2525
{
26-
return S_.{{names.name(variable)}}[ elem - State_::{{names.name(variable).upper()}}];
26+
return S_.{{names.name(variable)}}[ elem - State_::{{names.name(variable).upper()}} ];
2727
}
2828
{%- else %}
2929
(elem == State_::{{names.name(variable).upper()}})
@@ -34,7 +34,7 @@ inline double get_state_element(size_t elem)
3434
{%- else %}
3535
{%- if variable.has_vector_parameter() %}
3636
{
37-
return S_.{{names.name(variable)}}[ elem - State_::{{names.name(variable).upper()}}];
37+
return S_.{{names.name(variable)}}[ elem - State_::{{names.name(variable).upper()}} ];
3838
}
3939
{%- else %}
4040
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
3+
SimpleVectorsModel.nestml
4+
#########################
5+
6+
Copyright statement
7+
+++++++++++++++++++
8+
9+
This file is part of NEST.
10+
11+
Copyright (C) 2004 The NEST Initiative
12+
13+
NEST is free software: you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation, either version 2 of the License, or
16+
(at your option) any later version.
17+
18+
NEST is distributed in the hope that it will be useful,
19+
but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
GNU General Public License for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with NEST. If not, see <http://www.gnu.org/licenses/>.
25+
26+
"""
27+
28+
neuron simple_vectors_model:
29+
state:
30+
g_ex [20] real = 1.2
31+
end
32+
33+
update:
34+
g_ex[2] = 10.5
35+
end
36+
end

tests/vector_code_generator_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import unittest
2323

2424
from pynestml.codegeneration.nest_code_generator import NESTCodeGenerator
25+
from pynestml.frontend.pynestml_frontend import generate_nest_target
2526

2627
from pynestml.utils.model_parser import ModelParser
2728

@@ -72,6 +73,13 @@ def test_vector_code_generation(self):
7273
nestCodeGenerator = NESTCodeGenerator()
7374
nestCodeGenerator.generate_code(compilation_unit.get_neuron_list())
7475

76+
def test_vector_code_generation_and_build(self):
77+
input_path = str(os.path.realpath(os.path.join(os.path.dirname(__file__), "resources",
78+
"SimpleVectorsModel.nestml")))
79+
generate_nest_target(input_path=input_path,
80+
target_path=self.target_path,
81+
logging_level="INFO")
82+
7583
def tearDown(self) -> None:
7684
import shutil
7785
shutil.rmtree(self.target_path)

0 commit comments

Comments
 (0)