19 #define DECLARE_SNIPPET(TYPE, NUM_PARAMS) \ 21 GENN_EXPORT static TYPE *s_Instance; \ 23 static const TYPE *getInstance() \ 25 if(s_Instance == NULL) \ 27 s_Instance = new TYPE; \ 31 typedef Snippet::ValueBase<NUM_PARAMS> ParamValues \ 34 #define IMPLEMENT_SNIPPET(TYPE) TYPE *TYPE::s_Instance = NULL 36 #define SET_PARAM_NAMES(...) virtual StringVec getParamNames() const override{ return __VA_ARGS__; } 37 #define SET_DERIVED_PARAMS(...) virtual DerivedParamVec getDerivedParams() const override{ return __VA_ARGS__; } 38 #define SET_EXTRA_GLOBAL_PARAMS(...) virtual EGPVec getExtraGlobalParams() const override{ return __VA_ARGS__; } 47 template<
typename V,
size_t NumVars>
53 template<
typename... T>
56 static_assert(
sizeof...(vals) == NumVars,
"Wrong number of values");
80 std::vector<V> m_Values;
94 template<
typename... T>
97 static_assert(
sizeof...(vals) == 0,
"Wrong number of values");
113 template<
size_t NumVars>
133 bool operator == (
const EGP &other)
const 135 return ((name == other.
name) && (type == other.
type));
145 ParamVal(
const std::string &n,
const std::string &t,
const std::string &v) : name(n), type(t), value(v)
154 return ((name == other.
name) && (type == other.
type) && (value == other.
value));
167 return (name == other.
name);
171 std::function<double(const std::vector<double> &, double)> func;
203 return getNamedVecIndex(paramName, getExtraGlobalParams());
231 auto iter = std::find_if(vec.begin(), vec.end(),
232 [name](
const T &v){
return (v.name == name); });
234 if(iter == vec.end()) {
235 throw std::runtime_error(
"Cannot find variable '" + name +
"'");
239 return distance(vec.begin(), iter);
249 template<
typename SnippetBase>
253 Init(
const SnippetBase *snippet,
const std::vector<double> ¶ms)
254 : m_Snippet(snippet), m_Params(params)
257 getSnippet()->validate();
264 const std::vector<double> &
getParams()
const{
return m_Params; }
269 auto derivedParams = m_Snippet->getDerivedParams();
272 m_DerivedParams.reserve(derivedParams.size());
275 for(
const auto &d : derivedParams) {
276 m_DerivedParams.push_back(d.func(m_Params, dt));
282 return getSnippet()->getHashDigest();
289 const SnippetBase *m_Snippet;
290 std::vector<double> m_Params;
291 std::vector<double> m_DerivedParams;
ParamVal()
Definition: snippet.h:149
std::vector< V > getInitialisers() const
Gets values as a vector of doubles.
Definition: snippet.h:104
std::string type
Definition: snippet.h:158
std::string name
Definition: snippet.h:170
ParamVal(const std::string &n, const std::string &t, double v)
Definition: snippet.h:147
std::string name
Definition: snippet.h:157
#define GENN_EXPORT
Definition: gennExport.h:13
ParamVal(const std::string &n, const std::string &t, const std::string &v)
Definition: snippet.h:145
Definition: snippet.h:250
Init(const SnippetBase *snippet, const std::vector< double > ¶ms)
Definition: snippet.h:253
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: gennUtils.h:92
size_t getExtraGlobalParamIndex(const std::string ¶mName) const
Find the index of a named extra global parameter.
Definition: snippet.h:201
std::string value
Definition: snippet.h:159
boost::uuids::detail::sha1::digest_type getHashDigest() const
Definition: snippet.h:280
void updateHash(const T &value, boost::uuids::detail::sha1 &hash)
Hash arithmetic types and enums.
Definition: gennUtils.h:128
A derived parameter has a name and a function for obtaining its value.
Definition: snippet.h:163
void updateHash(boost::uuids::detail::sha1 &hash) const
Definition: snippet.h:210
std::string type
Definition: snippet.h:139
void initDerivedParams(double dt)
Definition: snippet.h:267
virtual ~Base()
Definition: snippet.h:123
const std::vector< V > & getInitialisers() const
Gets values as a vector.
Definition: snippet.h:63
virtual StringVec getParamNames() const
Gets names of of (independent) model parameters.
Definition: snippet.h:187
const SnippetBase * getSnippet() const
Definition: snippet.h:263
const V & operator[](size_t pos) const
Definition: snippet.h:71
const std::vector< double > & getParams() const
Definition: snippet.h:264
std::vector< DerivedParam > DerivedParamVec
Definition: snippet.h:181
void updateHash(const Base::EGP &e, boost::uuids::detail::sha1 &hash)
Definition: snippet.h:297
std::vector< std::string > StringVec
Definition: snippet.h:178
virtual EGPVec getExtraGlobalParams() const
Definition: snippet.h:195
InitialiserContainerBase(T &&... vals)
Definition: snippet.h:54
An extra global parameter has a name and a type.
Definition: snippet.h:131
Base class for all code snippets.
Definition: snippet.h:120
Additional input variables, row state variables and other things have a name, a type and an initial v...
Definition: snippet.h:143
Definition: gennUtils.h:30
static size_t getNamedVecIndex(const std::string &name, const std::vector< T > &vec)
Definition: snippet.h:229
InitialiserContainerBase(T &&... vals)
Definition: snippet.h:95
void validate() const
Validate names of parameters etc.
Definition: snippet.h:218
virtual DerivedParamVec getDerivedParams() const
Definition: snippet.h:191
void validateVecNames(const std::vector< T > &vec, const std::string &description)
Are the 'name' fields of all structs in vector valid? GeNN variables and population names must obey C...
Definition: gennUtils.h:81
std::string name
Definition: snippet.h:138
GENN_EXPORT void validateParamNames(const std::vector< std::string > ¶mNames)
Are all the parameter names in vector valid? GeNN variables and population names must obey C variable...
Definition: gennUtils.cc:142
const std::vector< double > & getDerivedParams() const
Definition: snippet.h:265
std::vector< ParamVal > ParamValVec
Definition: snippet.h:180
std::vector< EGP > EGPVec
Definition: snippet.h:179