Skip to content

Commit

Permalink
Merge 74019fd into 1307970
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Apr 21, 2015
2 parents 1307970 + 74019fd commit 6b10eee
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
33 changes: 30 additions & 3 deletions brian2/devices/cpp_standalone/device.py
Expand Up @@ -186,6 +186,32 @@ def get_array_name(self, var, access_data=True):
raise TypeError(('Do not have a name for variable of type '
'%s') % type(var))

def get_array_filename(self, var, basedir='results'):
'''
Return a file name for a variable.
Parameters
----------
var : `ArrayVariable`
The variable to get a filename for.
basedir : str
The base directory for the filename, defaults to ``'results'``.
Returns
-------
filename : str
A filename of the form
``'results/'+varname+'_'+str(hash(varname))``, where varname is the
name returned by `get_array_name`.
Notes
-----
The reason that the filename is not simply ``'results/' + varname`` is
that this could lead to file names that are not unique in file systems
that are not case sensitive (e.g. on Windows).
'''
varname = self.get_array_name(var, access_data=False)
return os.path.join(basedir, varname + '_' + str(hash(varname)))

def add_array(self, var):
# Note that a dynamic array variable is added to both the arrays and
# the _dynamic_array dictionary
Expand Down Expand Up @@ -317,8 +343,8 @@ def get_value(self, var, access_data=True):
# disk
if self.has_been_run:
dtype = var.dtype
fname = os.path.join(self.project_dir, 'results',
array_name)
fname = os.path.join(self.project_dir,
self.get_array_filename(var))
with open(fname, 'rb') as f:
data = np.fromfile(f, dtype=dtype)
# This is a bit of an heuristic, but our 2d dynamic arrays are
Expand Down Expand Up @@ -403,7 +429,8 @@ def generate_objects_source(self, writer, arange_arrays, synapses, static_array_
synapses=synapses,
clocks=self.clocks,
static_array_specs=static_array_specs,
networks=networks)
networks=networks,
get_array_filename=self.get_array_filename)
writer.write('objects.*', arr_tmp)

def generate_main_source(self, writer, main_includes):
Expand Down
6 changes: 3 additions & 3 deletions brian2/devices/cpp_standalone/templates/objects.cpp
Expand Up @@ -113,7 +113,7 @@ void _write_arrays()
{% for var, varname in array_specs | dictsort(by='value') %}
{% if not (var in dynamic_array_specs or var in dynamic_array_2d_specs) %}
ofstream outfile_{{varname}};
outfile_{{varname}}.open("results/{{varname}}", ios::binary | ios::out);
outfile_{{varname}}.open("{{get_array_filename(var)}}", ios::binary | ios::out);
if(outfile_{{varname}}.is_open())
{
outfile_{{varname}}.write(reinterpret_cast<char*>({{varname}}), {{var.size}}*sizeof({{varname}}[0]));
Expand All @@ -127,7 +127,7 @@ void _write_arrays()

{% for var, varname in dynamic_array_specs | dictsort(by='value') %}
ofstream outfile_{{varname}};
outfile_{{varname}}.open("results/{{varname}}", ios::binary | ios::out);
outfile_{{varname}}.open("{{get_array_filename(var)}}", ios::binary | ios::out);
if(outfile_{{varname}}.is_open())
{
outfile_{{varname}}.write(reinterpret_cast<char*>(&{{varname}}[0]), {{varname}}.size()*sizeof({{varname}}[0]));
Expand All @@ -140,7 +140,7 @@ void _write_arrays()

{% for var, varname in dynamic_array_2d_specs | dictsort(by='value') %}
ofstream outfile_{{varname}};
outfile_{{varname}}.open("results/{{varname}}", ios::binary | ios::out);
outfile_{{varname}}.open("{{get_array_filename(var)}}", ios::binary | ios::out);
if(outfile_{{varname}}.is_open())
{
for (int n=0; n<{{varname}}.n; n++)
Expand Down
12 changes: 6 additions & 6 deletions brian2/tests/__init__.py
Expand Up @@ -62,10 +62,9 @@ def run(codegen_targets=None, long_tests=False, test_codegen_independent=True,
sys.stderr.write('Running tests in "%s" ' % dirname)
if codegen_targets:
sys.stderr.write('for targets %s' % (', '.join(codegen_targets)))
ex_in = 'including' if long_tests else 'excluding'
sys.stderr.write(' (%s long tests)\n' % ex_in)
else:
sys.stderr.write('\n')
ex_in = 'including' if long_tests else 'excluding'
sys.stderr.write(' (%s long tests)\n' % ex_in)

if test_standalone:
if not isinstance(test_standalone, basestring):
raise ValueError('test_standalone argument has to be the name of a '
Expand Down Expand Up @@ -128,13 +127,14 @@ def run(codegen_targets=None, long_tests=False, test_codegen_independent=True,
set_device(test_standalone + '_simple')
sys.stderr.write('Testing standalone device "%s"\n' % test_standalone)
sys.stderr.write('Running standalone-compatible standard tests\n')
exclude_str = ',!long' if not long_tests else ''
success.append(nose.run(argv=['', dirname,
'-c=', # no config file loading
'-I', '^hears\.py$',
'-I', '^\.',
'-I', '^_',
# Only run standalone tests
'-a', 'standalone-compatible',
'-a', 'standalone-compatible'+exclude_str,
'--nologcapture',
'--exe']))
set_device(previous_device)
Expand All @@ -145,7 +145,7 @@ def run(codegen_targets=None, long_tests=False, test_codegen_independent=True,
'-I', '^\.',
'-I', '^_',
# Only run standalone tests
'-a', test_standalone,
'-a', test_standalone+exclude_str,
'--nologcapture',
'--exe']))
all_success = all(success)
Expand Down

0 comments on commit 6b10eee

Please sign in to comment.