74 template<
typename BaseIter>
81 typedef typename BaseIter::value_type::first_type KeyType;
90 const KeyType *operator -> ()
const 92 return (
const KeyType *) &(BaseIter::operator -> ( )->first);
95 const KeyType &operator * ()
const 97 return BaseIter::operator * ( ).first;
102 template<
typename BaseIter>
112 {
"gennrand_uniform", 0,
"curand_uniform_double($(rng))",
"curand_uniform($(rng))"},
113 {
"gennrand_normal", 0,
"curand_normal_double($(rng))",
"curand_normal($(rng))"},
114 {
"gennrand_exponential", 0,
"exponentialDistDouble($(rng))",
"exponentialDistFloat($(rng))"},
115 {
"gennrand_log_normal", 2,
"curand_log_normal_double($(rng), $(0), $(1))",
"curand_log_normal_float($(rng), $(0), $(1))"},
116 {
"gennrand_gamma", 1,
"gammaDistDouble($(rng), $(0))",
"gammaDistFloat($(rng), $(0))"}
123 {
"gennrand_uniform", 0,
"standardUniformDistribution($(rng))",
"standardUniformDistribution($(rng))"},
124 {
"gennrand_normal", 0,
"standardNormalDistribution($(rng))",
"standardNormalDistribution($(rng))"},
125 {
"gennrand_exponential", 0,
"standardExponentialDistribution($(rng))",
"standardExponentialDistribution($(rng))"},
126 {
"gennrand_log_normal", 2,
"std::lognormal_distribution<double>($(0), $(1))($(rng))",
"std::lognormal_distribution<float>($(0), $(1))($(rng))"},
127 {
"gennrand_gamma", 1,
"std::gamma_distribution<double>($(0), 1.0)($(rng))",
"std::gamma_distribution<float>($(0), 1.0f)($(rng))"}
133 void substitute(
string &s,
const string &trg,
const string &rep);
153 bool isInitRNGRequired(
const std::vector<NewModels::VarInit> &varInitialisers,
const std::vector<VarMode> &varModes,
168 unsigned int numParams,
const std::string &replaceFuncTemplate);
173 template<
typename NameIter>
174 inline void name_substitutions(
string &code,
const string &prefix, NameIter namesBegin, NameIter namesEnd,
const string &postfix=
"",
const string &ext =
"")
176 for (NameIter n = namesBegin; n != namesEnd; n++) {
178 "$(" + *n + ext +
")",
179 prefix + *n + postfix);
186 inline void name_substitutions(
string &code,
const string &prefix,
const vector<string> &names,
const string &postfix=
"",
const string &ext =
"")
194 template<class T, typename std::enable_if<std::is_floating_point<T>::value>
::type* =
nullptr>
198 const std::streamsize previousPrecision = os.precision();
201 os << std::scientific;
204 os << std::setprecision(std::numeric_limits<T>::max_digits10);
211 os.unsetf(std::ios_base::floatfield);
215 os << std::setprecision(previousPrecision);
221 template<class T, typename std::enable_if<std::is_floating_point<T>::value>
::type* =
nullptr>
232 template<
typename NameIter>
233 inline void value_substitutions(
string &code, NameIter namesBegin, NameIter namesEnd,
const vector<double> &values,
const string &ext =
"")
235 NameIter n = namesBegin;
236 auto v = values.cbegin();
237 for (;n != namesEnd && v != values.cend(); n++, v++) {
241 "$(" + *n + ext +
")",
242 "(" + stream.str() +
")");
249 inline void value_substitutions(
string &code,
const vector<string> &names,
const vector<double> &values,
const string &ext =
"")
258 const std::vector<FunctionTemplate> functions);
277 uint32_t
hashString(
const std::string &
string);
283 const string &offset,
284 const string &axonalDelayOffset,
285 const string &postIdx,
286 const string &devPrefix,
287 const string &preVarPrefix =
"",
288 const string &preVarSuffix =
"");
293 const string &offset,
294 const string &backPropDelayOffset,
295 const string &preIdx,
296 const string &devPrefix,
297 const string &postVarPrefix =
"",
298 const string &postVarSuffix =
"");
308 const string &preIdx,
309 const string &postIdx,
310 const string &devPrefix,
312 const string &preVarPrefix =
"",
313 const string &preVarSuffix =
"",
314 const string &postVarPrefix =
"",
315 const string &postVarSuffix =
"");
bool isInitRNGRequired(const std::vector< NewModels::VarInit > &varInitialisers, const std::vector< VarMode > &varModes, VarInit initLocation)
Does the model with the vectors of variable initialisers and modes require an RNG for the specified i...
Definition: codeGenUtils.cc:305
void functionSubstitute(std::string &code, const std::string &funcName, unsigned int numParams, const std::string &replaceFuncTemplate)
This function substitutes function calls in the form:
Definition: codeGenUtils.cc:350
const std::string doublePrecisionTemplate
The function template (for use with functionSubstitute) used when model uses double precision...
Definition: codeGenUtils.h:64
Definition: modelSpec.h:132
const std::vector< FunctionTemplate > cpuFunctions
CPU implementations of standard functions.
Definition: codeGenUtils.h:122
Definition: newModels.h:36
void postNeuronSubstitutionsInSynapticCode(string &wCode, const SynapseGroup *sg, const string &offset, const string &backPropDelayOffset, const string &preIdx, const string &devPrefix, const string &postVarPrefix="", const string &postVarSuffix="")
suffix to be used for postsynaptic variable accesses - typically combined with prefix to wrap in func...
Definition: codeGenUtils.cc:664
void name_substitutions(string &code, const string &prefix, NameIter namesBegin, NameIter namesEnd, const string &postfix="", const string &ext="")
This function performs a list of name substitutions for variables in code snippets.
Definition: codeGenUtils.h:174
type
Definition: generate_swig_interfaces.py:680
uint32_t hashString(const std::string &string)
This function returns the 32-bit hash of a string - because these are used across MPI nodes which may...
Definition: codeGenUtils.cc:586
bool isRNGRequired(const std::string &code)
Does the code string contain any functions requiring random number generator.
Definition: codeGenUtils.cc:280
PairKeyConstIter< BaseIter > GetPairKeyConstIter(BaseIter iter)
Helper function for creating a PairKeyConstIter from an iterator.
Definition: codeGenUtils.h:103
void functionSubstitutions(std::string &code, const std::string &ftype, const std::vector< FunctionTemplate > functions)
This function performs a list of function substitutions in code snipped.
Definition: codeGenUtils.cc:443
Custom iterator for iterating through the keys of containers containing pairs.
Definition: codeGenUtils.h:75
Definition: codeGenUtils.h:49
bool regexVarSubstitute(string &s, const string &trg, const string &rep)
Tool for substituting variable names in the neuron code strings or other templates using regular expr...
Definition: codeGenUtils.cc:246
void writePreciseString(std::ostream &os, T value)
This function writes a floating point value to a stream -setting the precision so no digits are lost...
Definition: codeGenUtils.h:195
PairKeyConstIter(BaseIter iter)
Definition: codeGenUtils.h:85
Definition: synapseGroup.h:19
const std::string genericName
Generic name used to refer to function in user code.
Definition: codeGenUtils.h:37
void substitute(string &s, const string &trg, const string &rep)
Tool for substituting strings in the neuron code strings or other templates.
Definition: codeGenUtils.cc:234
Definition: codeGenUtils.h:34
PairKeyConstIter()
Definition: codeGenUtils.h:84
void neuron_substitutions_in_synaptic_code(string &wCode, const SynapseGroup *sg, const string &preIdx, const string &postIdx, const string &devPrefix, double dt, const string &preVarPrefix="", const string &preVarSuffix="", const string &postVarPrefix="", const string &postVarSuffix="")
Function for performing the code and value substitutions necessary to insert neuron related variables...
Definition: codeGenUtils.cc:678
const unsigned int numArguments
Number of function arguments.
Definition: codeGenUtils.h:61
string ensureFtype(const string &oldcode, const string &type)
This function implements a parser that converts any floating point constant in a code snippet to a fl...
Definition: codeGenUtils.cc:458
const std::string singlePrecisionTemplate
The function template (for use with functionSubstitute) used when model uses single precision...
Definition: codeGenUtils.h:67
Base class for all neuron models.
Definition: newNeuronModels.h:31
void checkUnreplacedVariables(const string &code, const string &codeName)
This function checks for unknown variable definitions and returns a gennError if any are found...
Definition: codeGenUtils.cc:560
Definition: codeGenUtils.h:19
Definition: codeGenUtils.h:24
bool regexFuncSubstitute(string &s, const string &trg, const string &rep)
Tool for substituting function names in the neuron code strings or other templates using regular expr...
Definition: codeGenUtils.cc:263
const unsigned int numArguments
Number of function arguments.
Definition: codeGenUtils.h:40
const std::vector< FunctionTemplate > cudaFunctions
CUDA implementations of standard functions.
Definition: codeGenUtils.h:111
void preNeuronSubstitutionsInSynapticCode(string &wCode, const SynapseGroup *sg, const string &offset, const string &axonalDelayOffset, const string &postIdx, const string &devPrefix, const string &preVarPrefix="", const string &preVarSuffix="")
suffix to be used for presynaptic variable accesses - typically combined with prefix to wrap in funct...
Definition: codeGenUtils.cc:645
void value_substitutions(string &code, NameIter namesBegin, NameIter namesEnd, const vector< double > &values, const string &ext="")
This function performs a list of value substitutions for parameters in code snippets.
Definition: codeGenUtils.h:233
VarInit
Definition: variableMode.h:18
const std::string genericName
Generic name used to refer to function in user code.
Definition: codeGenUtils.h:58