Skip to content

Commit

Permalink
Merge branch 'master' into reductions
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/genn/genn/currentSource.h
#	include/genn/genn/neuronGroup.h
  • Loading branch information
neworderofjamie committed Aug 11, 2021
2 parents b45882f + 78faf0d commit 8bd66ac
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 26 deletions.
4 changes: 2 additions & 2 deletions include/genn/genn/customUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class GENN_EXPORT CustomUpdateBase
m_Batched(false)
{
// Validate names
Utils::validateVarPopName(name, "Custom update");
Utils::validateVarPopName(updateGroupName, "Custom update group name");
Utils::validatePopName(name, "Custom update");
Utils::validatePopName(updateGroupName, "Custom update group name");
getCustomUpdateModel()->validate();
}

Expand Down
11 changes: 8 additions & 3 deletions include/genn/genn/gennUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ GENN_EXPORT bool isTypeFloatingPoint(const std::string &type);
GENN_EXPORT std::string getUnderlyingType(const std::string &type);

//--------------------------------------------------------------------------
//! \brief Is the variable/population name valid? GeNN variables and population names must obey C variable naming rules
//! \brief Is the variable name valid? GeNN variable names must obey C variable naming rules
//--------------------------------------------------------------------------
GENN_EXPORT void validateVarPopName(const std::string &name, const std::string &description);
GENN_EXPORT void validateVarName(const std::string &name, const std::string &description);

//--------------------------------------------------------------------------
//! \brief Is the population name valid? GeNN population names obey C variable naming rules but can start with a number
//--------------------------------------------------------------------------
GENN_EXPORT void validatePopName(const std::string &name, const std::string &description);

//--------------------------------------------------------------------------
//! \brief Are all the parameter names in vector valid? GeNN variables and population names must obey C variable naming rules
Expand All @@ -76,7 +81,7 @@ template<typename T>
void validateVecNames(const std::vector<T> &vec, const std::string &description)
{
for(const auto &v : vec) {
validateVarPopName(v.name, description);
validateVarName(v.name, description);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/genn/genn/currentSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CurrentSource::CurrentSource(const std::string &name, const CurrentSourceModels:
m_ExtraGlobalParamLocation(currentSourceModel->getExtraGlobalParams().size(), defaultExtraGlobalParamLocation)
{
// Validate names
Utils::validateVarPopName(name, "Current source");
Utils::validatePopName(name, "Current source");
getCurrentSourceModel()->validate();
}
//----------------------------------------------------------------------------
Expand Down
19 changes: 17 additions & 2 deletions src/genn/genn/gennUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ std::string getUnderlyingType(const std::string &type)
}
}
//--------------------------------------------------------------------------
void validateVarPopName(const std::string &name, const std::string &description)
void validateVarName(const std::string &name, const std::string &description)
{
// Empty names aren't valid
if(name.empty()) {
Expand All @@ -120,10 +120,25 @@ void validateVarPopName(const std::string &name, const std::string &description)
}
}
//--------------------------------------------------------------------------
void validatePopName(const std::string &name, const std::string &description)
{
// Empty names aren't valid
if(name.empty()) {
throw std::runtime_error(description + " name invalid: cannot be empty");
}

// If any characters aren't underscores or alphanumeric, name isn't valud
if(std::any_of(name.cbegin(), name.cend(),
[](char c) { return (c != '_') && !std::isalnum(c); }))
{
throw std::runtime_error(description + " name invalid: '" + name + "' contains an illegal character");
}
}
//--------------------------------------------------------------------------
void validateParamNames(const std::vector<std::string> &paramNames)
{
for(const std::string &p : paramNames) {
validateVarPopName(p, "Parameter");
validateVarName(p, "Parameter");
}
}
} // namespace utils
2 changes: 1 addition & 1 deletion src/genn/genn/neuronGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ NeuronGroup::NeuronGroup(const std::string &name, int numNeurons, const NeuronMo
m_SpikeRecordingEnabled(false), m_SpikeEventRecordingEnabled(false)
{
// Validate names
Utils::validateVarPopName(name, "Neuron group");
Utils::validatePopName(name, "Neuron group");
getNeuronModel()->validate();
}
//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/genn/genn/synapseGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ SynapseGroup::SynapseGroup(const std::string &name, SynapseMatrixType matrixType
m_ConnectivityExtraGlobalParamLocation(connectivityInitialiser.getSnippet()->getExtraGlobalParams().size(), defaultExtraGlobalParamLocation), m_PSModelTargetName(name)
{
// Validate names
Utils::validateVarPopName(name, "Synapse group");
Utils::validatePopName(name, "Synapse group");
getWUModel()->validate();
getPSModel()->validate();

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/currentSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TEST(CurrentSource, InvalidName)
auto *pop = model.addNeuronPopulation<NeuronModels::Izhikevich>("Pop", 10, paramVals, varVals);

try {
model.addCurrentSource<CurrentSourceModels::DC>("6CS", "Pop", {1.0}, {});
model.addCurrentSource<CurrentSourceModels::DC>("CS-2", "Pop", {1.0}, {});
FAIL();
}
catch(const std::runtime_error &) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/customUpdate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ TEST(CustomUpdates, InvalidName)
Sum::VarReferences sumVarReferences1(createVarRef(ng1, "V"), createVarRef(ng1, "U"));

try {
model.addCustomUpdate<Sum>("1Sum", "CustomUpdate",
model.addCustomUpdate<Sum>("Sum-1", "CustomUpdate",
{}, sumVarValues, sumVarReferences1);
FAIL();
}
Expand All @@ -646,7 +646,7 @@ TEST(CustomUpdates, InvalidUpdateGroupName)
Sum::VarReferences sumVarReferences1(createVarRef(ng1, "V"), createVarRef(ng1, "U"));

try {
model.addCustomUpdate<Sum>("Sum", "1CustomUpdate",
model.addCustomUpdate<Sum>("Sum", "CustomUpdate-1",
{}, sumVarValues, sumVarReferences1);
FAIL();
}
Expand Down
42 changes: 31 additions & 11 deletions tests/unit/gennUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
//--------------------------------------------------------------------------
namespace
{
void validateVarPopNameDeathTest(const std::string &name)
void validatePopNameDeathTest(const std::string &name)
{
try {
Utils::validateVarPopName(name, "test");
Utils::validatePopName(name, "test");
FAIL();
}

catch(const std::runtime_error &) {
}
}
void validateVarNameDeathTest(const std::string &name)
{
try {
Utils::validateVarName(name, "test");
FAIL();
}

Expand All @@ -27,16 +37,26 @@ void validateVarPopNameDeathTest(const std::string &name)
//--------------------------------------------------------------------------
TEST(GeNNUtils, ValidateVarPopName)
{
Utils::validateVarPopName("test", "test");
Utils::validateVarPopName("Test", "test");
Utils::validateVarPopName("test123", "test");
Utils::validateVarPopName("test_123", "test");
Utils::validateVarPopName("_test_123", "test");
Utils::validateVarName("test", "test");
Utils::validateVarName("Test", "test");
Utils::validateVarName("test123", "test");
Utils::validateVarName("test_123", "test");
Utils::validateVarName("_test_123", "test");

Utils::validatePopName("test", "test");
Utils::validatePopName("Test", "test");
Utils::validatePopName("test123", "test");
Utils::validatePopName("test_123", "test");
Utils::validatePopName("_test_123", "test");
Utils::validatePopName("1test", "test");

validateVarPopNameDeathTest("");
validateVarPopNameDeathTest("1test");
validateVarPopNameDeathTest("test.test");
validateVarPopNameDeathTest("test-test");
validateVarNameDeathTest("");
validateVarNameDeathTest("1test");
validateVarNameDeathTest("test.test");
validateVarNameDeathTest("test-test");
validatePopNameDeathTest("");
validatePopNameDeathTest("test.test");
validatePopNameDeathTest("test-test");
}
//--------------------------------------------------------------------------
TEST(GeNNUtils, ValidateParamNames)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/neuronGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TEST(NeuronGroup, InvalidName)
{
ModelSpec model;
try {
model.addNeuronPopulation<NeuronModels::SpikeSource>("0Neurons", 10, {}, {});
model.addNeuronPopulation<NeuronModels::SpikeSource>("Neurons-0", 10, {}, {});
FAIL();
}
catch(const std::runtime_error &) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/synapseGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ TEST(SynapseGroup, InvalidName)
auto *post = model.addNeuronPopulation<NeuronModels::Izhikevich>("Post", 10, paramVals, varVals);
try {
model.addSynapsePopulation<WeightUpdateModels::StaticPulse, PostsynapticModels::DeltaCurr>(
"6Syn", SynapseMatrixType::DENSE_GLOBALG, NO_DELAY,
"Syn-6", SynapseMatrixType::DENSE_GLOBALG, NO_DELAY,
"Pre", "Post",
{}, {1.0},
{}, {});
Expand Down

0 comments on commit 8bd66ac

Please sign in to comment.