Skip to content

Commit

Permalink
Nework: Template the Nework class also on the weight type
Browse files Browse the repository at this point in the history
Straight forward and may be useful in the future. Default type is double

Co-authored-by: Amrita Goswami <[email protected]>
  • Loading branch information
MSallermann and amritagos committed Mar 15, 2024
1 parent 7919342 commit 5ba966e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Seldon
Note: switch is equivalent to toggle + transpose, but much cheaper!
*/
template<typename AgentType>
template<typename AgentType, typename WeightType = double>
class Network
{
public:
Expand All @@ -37,7 +37,7 @@ class Network
Outgoing
};

using WeightT = double;
using WeightT = WeightType;
using AgentT = AgentType;
// @TODO: Make this private later
std::vector<AgentT> agents{}; // List of agents of type AgentType
Expand Down Expand Up @@ -106,6 +106,7 @@ class Network
{
return std::span( neighbour_list[agent_idx].data(), neighbour_list[agent_idx].size() );
}

[[nodiscard]] std::span<size_t> get_neighbours( std::size_t agent_idx )
{
return std::span( neighbour_list[agent_idx].data(), neighbour_list[agent_idx].size() );
Expand All @@ -118,6 +119,7 @@ class Network
{
return std::span<const WeightT>( weight_list[agent_idx].data(), weight_list[agent_idx].size() );
}

[[nodiscard]] std::span<WeightT> get_weights( std::size_t agent_idx )
{
return std::span<WeightT>( weight_list[agent_idx].data(), weight_list[agent_idx].size() );
Expand Down Expand Up @@ -145,6 +147,7 @@ class Network
weight_list[agent_idx].resize( buffer_neighbours.size() );
std::fill( weight_list[agent_idx].begin(), weight_list[agent_idx].end(), weight );
}

/*
Sets the neighbour indices and weights at agent_idx
*/
Expand Down

0 comments on commit 5ba966e

Please sign in to comment.