18 #define DECLARE_MODEL(TYPE, NUM_PARAMS, NUM_VARS) \ 19 DECLARE_SNIPPET(TYPE, NUM_PARAMS) \ 20 typedef NewModels::VarInitContainerBase<NUM_VARS> VarValues; \ 21 typedef NewModels::VarInitContainerBase<0> PreVarValues; \ 22 typedef NewModels::VarInitContainerBase<0> PostVarValues; 24 #define IMPLEMENT_MODEL(TYPE) IMPLEMENT_SNIPPET(TYPE) 26 #define SET_VARS(...) virtual StringPairVec getVars() const override{ return __VA_ARGS__; } 55 template<
size_t NumVars>
62 typedef std::vector<VarInit> InitialiserArray;
67 template<
typename... T>
68 VarInitContainerBase(T&&... initialisers) : m_Initialisers(InitialiserArray{{std::forward<const VarInit>(initialisers)...}})
70 static_assert(
sizeof...(initialisers) == NumVars,
"Wrong number of initialisers");
79 return m_Initialisers;
87 return m_Initialisers[pos];
94 InitialiserArray m_Initialisers;
108 template<
typename... T>
111 static_assert(
sizeof...(initialisers) == 0,
"Wrong number of initialisers");
147 return getVarIndex(varName, getVars());
156 auto varIter = std::find_if(vars.begin(), vars.end(),
157 [varName](
const StringPairVec::value_type &v){
return (v.first == varName); });
158 assert(varIter != vars.end());
161 return distance(vars.begin(), varIter);
169 template<
typename ModelBase,
typename LegacyModelType, const std::vector<LegacyModelType> &ModelArray>
173 typedef typename ModelBase::DerivedParamFunc DerivedParamFunc;
174 typedef typename ModelBase::StringVec StringVec;
175 typedef typename ModelBase::StringPairVec StringPairVec;
176 typedef typename ModelBase::DerivedParamVec DerivedParamVec;
179 LegacyWrapper(
unsigned int legacyTypeIndex) : m_LegacyTypeIndex(legacyTypeIndex)
189 const auto &nm = ModelArray[m_LegacyTypeIndex];
197 const auto &
m = ModelArray[m_LegacyTypeIndex];
200 DerivedParamVec derivedParams;
201 derivedParams.reserve(
m.dpNames.size());
204 for(
size_t p = 0; p <
m.dpNames.size(); p++)
208 derivedParams.push_back(std::make_pair(
210 [
this, p](
const std::vector<double> &pars,
double dt)
212 return ModelArray[m_LegacyTypeIndex].dps->calculateDerivedParameter(p, pars, dt);
217 return derivedParams;
223 const auto &nm = ModelArray[m_LegacyTypeIndex];
224 return zipStringVectors(nm.varNames, nm.varTypes);
233 assert(a.size() == b.size());
237 zip.reserve(a.size());
240 for(
size_t v = 0; v < a.size(); v++)
242 zip.push_back(std::make_pair(a[v], b[v]));
const unsigned int m_LegacyTypeIndex
Index into the array of legacy models.
Definition: newModels.h:252
VarInit(double constant)
Definition: newModels.h:44
virtual StringPairVec getVars() const
Gets names and types (as strings) of model variables.
Definition: newModels.h:221
virtual DerivedParamVec getDerivedParams() const
Definition: newModels.h:195
VarInitContainerBase(T &&... initialisers)
Definition: newModels.h:68
Definition: snippet.h:139
Definition: newModels.h:36
Init(const InitVarSnippet::Base *snippet, const std::vector< double > ¶ms)
Definition: snippet.h:142
Wrapper around old-style models stored in global arrays and referenced by index.
Definition: newModels.h:170
VarInitContainerBase(const Snippet::ValueBase< 0 > &)
Definition: newModels.h:114
LegacyWrapper(unsigned int legacyTypeIndex)
Definition: newModels.h:179
Definition: initVarSnippet.h:17
Definition: newModels.h:56
Base class for all models - in addition to the parameters snippets have, models can have state variab...
Definition: newModels.h:132
static StringPairVec zipStringVectors(const StringVec &a, const StringVec &b)
Definition: newModels.h:231
virtual StringPairVec getVars() const
Gets names and types (as strings) of model variables.
Definition: newModels.h:139
const std::vector< VarInit > & getInitialisers() const
Gets initialisers as a vector of Values.
Definition: newModels.h:77
Base class for all value initialisation snippets.
Definition: initVarSnippet.h:15
static size_t getVarIndex(const std::string &varName, const StringPairVec &vars)
Definition: newModels.h:154
VarInitContainerBase(T &&... initialisers)
Definition: newModels.h:109
Base class for all code snippets.
Definition: snippet.h:105
std::vector< VarInit > getInitialisers() const
Gets initialisers as a vector of Values.
Definition: newModels.h:122
VarInit(const InitVarSnippet::Base *snippet, const std::vector< double > ¶ms)
Definition: newModels.h:39
std::vector< std::pair< std::string, std::string > > StringPairVec
Definition: snippet.h:117
Definition: codeGenUtils.h:24
size_t getVarIndex(const std::string &varName) const
Find the index of a named variable.
Definition: newModels.h:145
virtual StringVec getParamNames() const
Gets names of of (independent) model parameters.
Definition: newModels.h:187
m
Definition: build/lib.linux-x86_64-3.6/pygenn/genn_model.py:76
const VarInit & operator[](size_t pos) const
Definition: newModels.h:85