Skip to content

Commit

Permalink
Merge pull request #49 from heplesser/jstap-eprop
Browse files Browse the repository at this point in the history
Tidying up
  • Loading branch information
akorgor authored Dec 14, 2023
2 parents 2cc2758 + aab1f57 commit c2547d8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 54 deletions.
55 changes: 2 additions & 53 deletions build_support/generate_modelsmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"""

import argparse
import itertools
import os
import sys
from pathlib import Path
Expand Down Expand Up @@ -229,8 +230,7 @@ def generate_modelsmodule():
1. the copyright header.
2. a list of generic NEST includes
3. the list of includes for the models to build into NEST
4. some boilerplate function implementations needed to fulfill the
Module interface
4. if required template specialization for eprop_synapse
5. the list of model registration lines for the models to build
into NEST
Expand All @@ -253,9 +253,6 @@ def generate_modelsmodule():
"""
#include "models.h"
// Includes from nestkernel
#include "target_identifier.h"
// Generated includes
#include "config.h"
"""
Expand All @@ -270,54 +267,6 @@ def generate_modelsmodule():
file.write(f'#include "{fname}"\n')
file.write(end_guard(guards))

file.write(
dedent(
"""
namespace nest
{
template <>
void
Connector< eprop_synapse< TargetIdentifierPtrRport > >::disable_connection( const size_t lcid )
{
assert( not C_[ lcid ].is_disabled() );
C_[ lcid ].disable();
C_[ lcid ].delete_optimizer();
}
template <>
void
Connector< eprop_synapse< TargetIdentifierIndex > >::disable_connection( const size_t lcid )
{
assert( not C_[ lcid ].is_disabled() );
C_[ lcid ].disable();
C_[ lcid ].delete_optimizer();
}
template <>
Connector< eprop_synapse< TargetIdentifierPtrRport > >::~Connector()
{
for ( auto& c : C_ )
{
c.delete_optimizer();
}
C_.clear();
}
template <>
Connector< eprop_synapse< TargetIdentifierIndex > >::~Connector()
{
for ( auto& c : C_ )
{
c.delete_optimizer();
}
C_.clear();
}
}
"""
)
)

file.write("\nvoid nest::register_models()\n{")

for model_type, guards_mnames in models.items():
Expand Down
41 changes: 40 additions & 1 deletion models/eprop_synapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
// nestkernel
#include "nest_impl.h"


namespace nest
{

Expand Down Expand Up @@ -107,4 +106,44 @@ EpropCommonProperties::set_status( const DictionaryDatum& d, ConnectorModel& cm
}
}

template <>
void
Connector< eprop_synapse< TargetIdentifierPtrRport > >::disable_connection( const size_t lcid )
{
assert( not C_[ lcid ].is_disabled() );
C_[ lcid ].disable();
C_[ lcid ].delete_optimizer();
}

template <>
void
Connector< eprop_synapse< TargetIdentifierIndex > >::disable_connection( const size_t lcid )
{
assert( not C_[ lcid ].is_disabled() );
C_[ lcid ].disable();
C_[ lcid ].delete_optimizer();
}


template <>
Connector< eprop_synapse< TargetIdentifierPtrRport > >::~Connector()
{
for ( auto& c : C_ )
{
c.delete_optimizer();
}
C_.clear();
}

template <>
Connector< eprop_synapse< TargetIdentifierIndex > >::~Connector()
{
for ( auto& c : C_ )
{
c.delete_optimizer();
}
C_.clear();
}


} // namespace nest
15 changes: 15 additions & 0 deletions models/eprop_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

// nestkernel
#include "connection.h"
#include "connector_base.h"
#include "eprop_archiving_node.h"
#include "target_identifier.h"
#include "weight_optimizer.h"
Expand Down Expand Up @@ -357,6 +358,20 @@ class eprop_synapse : public Connection< targetidentifierT >
template < typename targetidentifierT >
constexpr ConnectionModelProperties eprop_synapse< targetidentifierT >::properties;

// Explicitly declare specializations of Connector methods that need to do special things for eprop_synapse
template <>
void Connector< eprop_synapse< TargetIdentifierPtrRport > >::disable_connection( const size_t lcid );

template <>
void Connector< eprop_synapse< TargetIdentifierIndex > >::disable_connection( const size_t lcid );

template <>
Connector< eprop_synapse< TargetIdentifierPtrRport > >::~Connector();

template <>
Connector< eprop_synapse< TargetIdentifierIndex > >::~Connector();


template < typename targetidentifierT >
eprop_synapse< targetidentifierT >::eprop_synapse()
: ConnectionBase()
Expand Down
4 changes: 4 additions & 0 deletions nestkernel/connector_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ namespace nest
/**
* Base class to allow storing Connectors for different synapse types
* in vectors. We define the interface here to avoid casting.
*
* @note If any member functions need to do something special for a given connection type,
* declare specializations in the corresponding header file and define them in the corresponding
* source file. For an example, see `eprop_synapse`.
*/
class ConnectorBase
{
Expand Down

0 comments on commit c2547d8

Please sign in to comment.