NEST main@a355080
 
Loading...
Searching...
No Matches
node_collection.h
Go to the documentation of this file.
1/*
2 * node_collection.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef NODE_COLLECTION_H
24#define NODE_COLLECTION_H
25
26// C++ includes:
27#include <memory>
28#include <ostream>
29#include <stdexcept> // out_of_range
30#include <vector>
31
32// Includes from libnestuil:
33#include "dictionary.h"
34
35// Includes from nestkernel:
36#include "exceptions.h"
37
38
39// Includes from thirdparty:
40#include "compose.hpp"
41
42namespace nest
43{
44class Node;
45class NodeCollection;
46class NodeCollectionPrimitive;
47class NodeCollectionComposite;
48class NodeCollectionMetadata;
49
50using NodeCollectionPTR = std::shared_ptr< NodeCollection >;
51using NodeCollectionMetadataPTR = std::shared_ptr< NodeCollectionMetadata >;
52
60{
61public:
63 virtual ~NodeCollectionMetadata() = default;
64
65 virtual void set_status( const Dictionary&, bool ) = 0;
66
76 virtual void get_status( Dictionary&, NodeCollection const* const ) const = 0;
77 virtual void get_status( Dictionary&, const NodeCollectionPTR ) const = 0;
78
79 virtual void set_first_node_id( size_t ) = 0;
80 virtual size_t get_first_node_id() const = 0;
81 virtual std::string get_type() const = 0;
82
83 virtual bool operator==( const NodeCollectionMetadataPTR ) const = 0;
84};
85
92{
93public:
94 size_t node_id { 0 };
95 size_t model_id { 0 };
96 size_t nc_index { 0 };
97 NodeIDTriple() = default;
98};
99
415{
418
419public:
421 enum class NCIteratorKind
422 {
423 GLOBAL,
424 RANK_LOCAL,
426 END
427 };
428
429private:
432 size_t part_idx_;
433 size_t step_;
435 const size_t rank_or_vp_;
436
439
442
451 explicit nc_const_iterator( NodeCollectionPTR collection_ptr,
452 const NodeCollectionPrimitive& collection,
453 size_t offset,
454 size_t stride,
456
466 explicit nc_const_iterator( NodeCollectionPTR collection_ptr,
467 const NodeCollectionComposite& collection,
468 size_t part,
469 size_t offset,
470 size_t stride,
472
476 size_t find_next_within_part_( size_t n ) const;
477
481 void advance_global_iter_to_new_part_( size_t n );
482
486 void advance_local_iter_to_new_part_( size_t n );
487
488public:
489 using iterator_category = std::forward_iterator_tag;
490 using difference_type = long;
494
495 nc_const_iterator( const nc_const_iterator& nci ) = default;
496 std::pair< size_t, size_t > get_part_offset() const;
497
498 NodeIDTriple operator*() const;
499 bool operator==( const nc_const_iterator& rhs ) const;
500 bool operator!=( const nc_const_iterator& rhs ) const;
501 bool operator<( const nc_const_iterator& rhs ) const;
502 bool operator<=( const nc_const_iterator& rhs ) const;
503 bool operator>( const nc_const_iterator& rhs ) const;
504 bool operator>=( const nc_const_iterator& rhs ) const;
505
507 nc_const_iterator operator++( int ); // postfix
508 nc_const_iterator& operator+=( const size_t );
509 nc_const_iterator operator+( const size_t ) const;
510
519 size_t get_step_size() const;
520};
521
522
565{
566 friend class nc_const_iterator;
567
568public:
570
571
576
577 virtual ~NodeCollection() = default;
578
587 static NodeCollectionPTR create( const size_t node_id );
588
597 static NodeCollectionPTR create( const Node* node );
598
608 static NodeCollectionPTR create( const std::vector< size_t >& node_ids );
609
616 bool valid() const;
617
624 virtual std::ostream& print_me( std::ostream& ) const = 0;
625
632 virtual size_t operator[]( size_t ) const = 0;
633
644 virtual bool operator==( NodeCollectionPTR ) const = 0;
645
652 virtual bool operator!=( NodeCollectionPTR ) const;
653
659 virtual const_iterator begin( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const = 0;
660
668
676
685 virtual const_iterator end( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const = 0;
686
694 std::vector< size_t > to_array( const std::string& selection ) const;
695
701 virtual size_t size() const = 0;
702
708 virtual size_t stride() const = 0;
709
716 virtual bool contains( const size_t node_id ) const = 0;
717
729 virtual NodeCollectionPTR slice( size_t start, size_t end, size_t stride ) const = 0;
730
736 virtual void set_metadata( NodeCollectionMetadataPTR ) = 0;
737
744
745 virtual bool is_range() const = 0;
746
752 virtual bool empty() const = 0;
753
761 virtual long get_nc_index( const size_t ) const = 0;
762
768 virtual bool has_proxies() const = 0;
769
777 virtual bool all_connect_as_neurons() const = 0;
778
786 virtual bool all_connect_as_devices() const = 0;
787
791 void get_metadata_status( Dictionary& ) const;
792
796 size_t get_first() const;
797
801 size_t get_last() const;
802
803
804private:
805 unsigned long fingerprint_;
806 static NodeCollectionPTR create_();
807 static NodeCollectionPTR create_( const std::vector< size_t >& );
808};
809
817{
818 friend class nc_const_iterator;
819
820private:
821 // Even though all members are logically const, we cannot declare them const because
822 // sorting or merging the parts_ array requires assignment.
823 size_t first_;
824 size_t last_;
825 size_t model_id_;
829
837 void assert_consistent_model_ids_( const size_t ) const;
838
839public:
849 NodeCollectionPrimitive( size_t first, size_t last, size_t model_id, NodeCollectionMetadataPTR );
850
858 NodeCollectionPrimitive( size_t first, size_t last, size_t model_id );
859
867 NodeCollectionPrimitive( size_t first, size_t last );
868
875
882
889
890 std::ostream& print_me( std::ostream& ) const override;
891 void print_primitive( std::ostream& ) const;
892
893 size_t operator[]( const size_t ) const override;
894 NodeCollectionPTR operator+( NodeCollectionPTR rhs ) const override;
895 bool operator==( const NodeCollectionPTR rhs ) const override;
896 bool operator==( const NodeCollectionPrimitive& rhs ) const;
897
898 const_iterator begin( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
901 const_iterator end( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
902
904 size_t size() const override;
905
907 size_t stride() const override;
908
909 bool contains( const size_t node_id ) const override;
910 NodeCollectionPTR slice( size_t start, size_t end, size_t stride = 1 ) const override;
911
913
915
916 bool is_range() const override;
917 bool empty() const override;
918
919 long get_nc_index( const size_t ) const override;
920
921 bool has_proxies() const override;
922 bool all_connect_as_neurons() const override;
923 bool all_connect_as_devices() const override;
924
934 bool is_contiguous_ascending( const NodeCollectionPrimitive& other ) const;
935
942 bool overlapping( const NodeCollectionPrimitive& rhs ) const;
943};
944
946
967{
968 friend class nc_const_iterator;
969
970private:
971 std::vector< NodeCollectionPrimitive > parts_;
972 size_t size_;
973 size_t stride_;
974 size_t first_part_;
975 size_t first_elem_;
976 size_t last_part_;
977 size_t last_elem_;
979 std::vector< size_t > cumul_abs_size_;
980 std::vector< size_t >
982
988 void merge_parts_( std::vector< NodeCollectionPrimitive >& parts ) const;
989
991 typedef size_t ( *gid_to_phase_fcn_ )( size_t );
992
1003 std::pair< size_t, size_t > specific_local_begin_( size_t period,
1004 size_t phase,
1005 size_t start_part,
1006 size_t start_offset,
1007 gid_to_phase_fcn_ period_first_node ) const;
1008
1012 bool valid_idx_( const size_t part_idx, const size_t element_idx ) const;
1013
1023 std::pair< size_t, size_t > find_next_part_( size_t part_idx, size_t element_idx, size_t n = 1 ) const;
1024
1026 static size_t gid_to_vp_( size_t gid );
1027
1029 static size_t gid_to_rank_( size_t gid );
1030
1031
1032public:
1048 NodeCollectionComposite( const NodeCollectionPrimitive&, size_t, size_t, size_t );
1049
1063 NodeCollectionComposite( const NodeCollectionComposite&, size_t, size_t, size_t );
1064
1073 explicit NodeCollectionComposite( const std::vector< NodeCollectionPrimitive >& );
1074
1081
1082 std::ostream& print_me( std::ostream& ) const override;
1083
1084 size_t operator[]( const size_t ) const override;
1085
1096 NodeCollectionPTR operator+( NodeCollectionPTR rhs ) const override;
1098 bool operator==( const NodeCollectionPTR rhs ) const override;
1099
1100 const_iterator begin( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
1103 const_iterator end( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
1104
1106 size_t size() const override;
1107
1109 size_t stride() const override;
1110
1111 bool contains( const size_t node_id ) const override;
1112 NodeCollectionPTR slice( size_t start, size_t end, size_t step = 1 ) const override;
1113
1114 void set_metadata( NodeCollectionMetadataPTR ) override;
1115
1116 NodeCollectionMetadataPTR get_metadata() const override;
1117
1118 bool is_range() const override;
1119 bool empty() const override;
1120
1121 long get_nc_index( const size_t ) const override;
1122
1123 bool has_proxies() const override;
1124 bool all_connect_as_neurons() const override;
1125 bool all_connect_as_devices() const override;
1126};
1127
1128inline std::ostream&
1129operator<<( std::ostream& out, const NodeCollectionPTR nc )
1130{
1131 return nc->print_me( out );
1132}
1133
1134
1135inline bool
1137{
1138 return not( *this == rhs );
1139}
1140
1141inline void
1143{
1144 throw KernelException( "Cannot set Metadata on this type of NodeCollection." );
1145}
1146
1147inline size_t
1149{
1150 return ( *begin() ).node_id;
1151}
1152
1153inline size_t
1155{
1156 assert( size() > 0 );
1157 return ( *( begin() + ( size() - 1 ) ) ).node_id;
1158}
1159
1160inline nc_const_iterator&
1162{
1163 assert( kind_ != NCIteratorKind::END );
1164
1165 if ( n == 0 )
1166 {
1167 return *this;
1168 }
1169
1170 const auto new_element_idx = find_next_within_part_( n );
1171
1172 // For a primitive collection, we either have a new element or are at the end
1173 // For a composite collection, we may need to search through further parts,
1174 // which is signalled by new_element_idx == element_idx_
1175 if ( primitive_collection_ or new_element_idx != element_idx_ )
1176 {
1177 element_idx_ = new_element_idx;
1178 }
1179 else
1180 {
1181 // We did not find a new element in the current part and have not exhausted the collection
1183 {
1185 }
1186 else
1187 {
1189 }
1190 }
1191
1192 return *this;
1193}
1194
1195inline nc_const_iterator
1196nc_const_iterator::operator+( const size_t n ) const
1197{
1198 nc_const_iterator it = *this;
1199 return it += n;
1200}
1201
1202inline nc_const_iterator&
1204{
1205 ( *this ) += 1;
1206 return *this;
1207}
1208
1209inline nc_const_iterator
1211{
1212 nc_const_iterator tmp = *this;
1213 ++( *this );
1214 return tmp;
1215}
1216
1217inline bool
1219{
1220 return part_idx_ == rhs.part_idx_ and element_idx_ == rhs.element_idx_;
1221}
1222
1223inline bool
1225{
1226 return not( *this == rhs );
1227}
1228
1229inline bool
1231{
1232 return ( part_idx_ < rhs.part_idx_ or ( part_idx_ == rhs.part_idx_ and element_idx_ < rhs.element_idx_ ) );
1233}
1234
1235inline bool
1237{
1238 return ( *this < rhs or *this == rhs );
1239}
1240
1241inline bool
1243{
1244 return not( *this <= rhs );
1245}
1246
1247inline bool
1249{
1250 return not( *this < rhs );
1251}
1252
1253inline std::pair< size_t, size_t >
1255{
1256 return { part_idx_, element_idx_ };
1257}
1258
1259inline size_t
1261{
1262 return step_;
1263}
1264
1265inline NodeCollectionPTR
1267{
1268 return lhs->operator+( rhs );
1269}
1270
1271inline size_t
1273{
1274 // throw exception if outside of NodeCollection
1275 if ( first_ + idx > last_ )
1276 {
1277 throw std::out_of_range( String::compose( "pos %1 points outside of the NodeCollection", idx ) );
1278 }
1279 return first_ + idx;
1280}
1281
1282inline bool
1284{
1285 auto const* const rhs_ptr = dynamic_cast< NodeCollectionPrimitive const* >( rhs.get() );
1286 // Checking that rhs_ptr is valid first, to avoid segfaults. If rhs is a NodeCollectionComposite,
1287 // rhs_ptr will be a null pointer.
1288 if ( not rhs_ptr )
1289 {
1290 return false;
1291 }
1292
1293 // We know we have a primitive collection, so forward
1294 return *this == *rhs_ptr;
1295}
1296
1297inline bool
1299{
1300 // Not dereferencing rhs_ptr->metadata_ in the equality comparison because we want to avoid overloading
1301 // operator==() of *metadata_, and to let it handle typechecking.
1302 const bool eq_metadata =
1303 ( not metadata_ and not rhs.metadata_ ) or ( metadata_ and rhs.metadata_ and *metadata_ == rhs.metadata_ );
1304
1305 return first_ == rhs.first_ and last_ == rhs.last_ and model_id_ == rhs.model_id_ and eq_metadata;
1306}
1307
1310{
1311 return nc_const_iterator( cp, *this, /* offset */ 0, /* stride */ 1 );
1312}
1313
1316{
1317 // The unique end() element of a primitive NC is given by (part 0, element size()) )
1318 return nc_const_iterator( cp, *this, /* offset */ size(), /* stride */ 1, nc_const_iterator::NCIteratorKind::END );
1319}
1320
1321inline size_t
1323{
1324 // empty NC has first_ == last_ == 0, need to handle that special
1325 return std::min( last_, last_ - first_ + 1 );
1326}
1327
1328inline size_t
1330{
1331 return 1;
1332}
1333
1334inline bool
1335NodeCollectionPrimitive::contains( const size_t node_id ) const
1336{
1337 return first_ <= node_id and node_id <= last_;
1338}
1339
1340inline void
1345
1348{
1349 return metadata_;
1350}
1351
1352inline bool
1354{
1355 return true;
1356}
1357
1358inline bool
1360{
1361 return last_ == 0;
1362}
1363
1364inline long
1365NodeCollectionPrimitive::get_nc_index( const size_t neuron_id ) const
1366{
1367 if ( neuron_id < first_ or last_ < neuron_id )
1368 {
1369 return -1;
1370 }
1371 else
1372 {
1373 return neuron_id - first_;
1374 }
1375}
1376
1377inline bool
1382
1383inline bool
1385{
1386 // Normal neuron nodes have proxies. Globally receiving devices, e.g. volume transmitter, don't have a local
1387 // receiver, but are connected in the same way as normal neuron nodes. Therefore they have to be treated as such
1388 // here.
1390}
1391
1392inline bool
1397
1403
1406{
1407 // The unique end() element of a composite NC is given by one past the last element
1408 // This is the (potentially non-existing) next element irrespective of stride and step
1409 return nc_const_iterator(
1410 cp, *this, last_part_, last_elem_ + 1, /* stride */ 1, nc_const_iterator::NCIteratorKind::END );
1411}
1412
1413inline size_t
1415{
1416 return size_;
1417}
1418
1419inline size_t
1421{
1422 return stride_;
1423}
1424
1425inline void
1427{
1428 for ( auto& part : parts_ )
1429 {
1430 part.set_metadata( meta );
1431 }
1432}
1433
1436{
1437 return parts_[ 0 ].get_metadata();
1438}
1439
1440inline bool
1442{
1443 return false;
1444}
1445
1446inline bool
1448{
1449 // Composite NodeCollections can never be empty.
1450 return false;
1451}
1452
1453inline bool
1454NodeCollectionComposite::contains( const size_t node_id ) const
1455{
1456 return get_nc_index( node_id ) != -1;
1457}
1458
1459inline bool
1460NodeCollectionComposite::valid_idx_( const size_t part_idx, const size_t element_idx ) const
1461{
1462 return part_idx < last_part_ or ( part_idx == last_part_ and element_idx <= last_elem_ );
1463}
1464
1465} // namespace nest
1466
1467#endif /* #ifndef NODE_COLLECTION_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Base class for all Kernel exceptions.
Definition exceptions.h:65
Subclass for the composite NodeCollection type.
Definition node_collection.h:967
bool all_connect_as_neurons() const override
Returns true if all elements connect as neurons.
Definition node_collection.cpp:1346
const_iterator rank_local_begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the beginning of the NodeCollection.
Definition node_collection.cpp:1149
static size_t gid_to_vp_(size_t gid)
helper for thread_local_begin/compsite_update_indices
Definition node_collection.cpp:1137
void merge_parts_(std::vector< NodeCollectionPrimitive > &parts) const
Goes through the vector of primitives, merging as much as possible.
Definition node_collection.cpp:1236
size_t size() const override
Returns total number of node IDs in the composite.
Definition node_collection.h:1414
NodeCollectionPTR operator+(NodeCollectionPTR rhs) const override
Addition operator.
Definition node_collection.cpp:900
NodeCollectionPTR slice(size_t start, size_t end, size_t step=1) const override
Slices the NodeCollection to the boundaries, with an optional step parameter.
Definition node_collection.cpp:1196
size_t first_part_
Primitive to start at, set when slicing.
Definition node_collection.h:974
NodeCollectionComposite(const NodeCollectionComposite &)=default
Composite copy constructor.
const_iterator end(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the end of the NodeCollection.
Definition node_collection.h:1405
size_t(* gid_to_phase_fcn_)(size_t)
Type for lambda-helper function used by {rank, thread, specific}_local_begin.
Definition node_collection.h:991
size_t size_
Total number of node IDs, takes into account slicing.
Definition node_collection.h:972
bool is_sliced_
Whether the NodeCollectionComposite is sliced.
Definition node_collection.h:978
bool has_proxies() const override
Returns whether the NodeCollection contains any nodes with proxies or not.
Definition node_collection.cpp:1339
bool valid_idx_(const size_t part_idx, const size_t element_idx) const
Return true if part_idx/element_idx pair indicates element of collection.
Definition node_collection.h:1460
long get_nc_index(const size_t) const override
Returns index of node with given node ID in NodeCollection.
Definition node_collection.cpp:1263
size_t stride_
Step length, set when slicing.
Definition node_collection.h:973
size_t last_elem_
Last entry of parts_[last_part_] belonging to sliced NC.
Definition node_collection.h:977
std::pair< size_t, size_t > specific_local_begin_(size_t period, size_t phase, size_t start_part, size_t start_offset, gid_to_phase_fcn_ period_first_node) const
Abstraction of {rank, thread}_local_begin.
Definition node_collection.cpp:1064
std::vector< size_t > first_in_part_
Local index to first element in each part when slicing is taken into account, or invalid_index.
Definition node_collection.h:981
bool contains(const size_t node_id) const override
Check if the NodeCollection contains a specified node ID.
Definition node_collection.h:1454
std::pair< size_t, size_t > find_next_part_(size_t part_idx, size_t element_idx, size_t n=1) const
Find next part and offset in it after moving beyond previous part, based on stride.
size_t last_part_
Last entry of parts_ belonging to sliced NC.
Definition node_collection.h:976
size_t stride() const override
Returns the stride between node IDs in the composite.
Definition node_collection.h:1420
NodeCollectionMetadataPTR get_metadata() const override
Gets the metadata of the NodeCollection.
Definition node_collection.h:1435
bool empty() const override
Checks if the NodeCollection has no elements.
Definition node_collection.h:1447
void set_metadata(NodeCollectionMetadataPTR) override
Sets the metadata of the NodeCollection.
Definition node_collection.h:1426
const_iterator begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the beginning of the NodeCollection.
Definition node_collection.h:1399
std::ostream & print_me(std::ostream &) const override
Print out the contents of the NodeCollection in a pretty and informative way.
Definition node_collection.cpp:1360
std::vector< size_t > cumul_abs_size_
Cumulative size of parts.
Definition node_collection.h:979
bool all_connect_as_devices() const override
Returns true if all elements connect as devices.
Definition node_collection.cpp:1353
bool is_range() const override
Definition node_collection.h:1441
std::vector< NodeCollectionPrimitive > parts_
Primitives forming composite.
Definition node_collection.h:971
size_t operator[](const size_t) const override
Get the node ID in the specified index in the NodeCollection.
Definition node_collection.cpp:1011
size_t first_elem_
Element to start at, set when slicing.
Definition node_collection.h:975
bool operator==(const NodeCollectionPTR rhs) const override
Definition node_collection.cpp:1041
static size_t gid_to_rank_(size_t gid)
helper for rank_local_begin/compsite_update_indices
Definition node_collection.cpp:1143
friend class nc_const_iterator
Definition node_collection.h:968
const_iterator thread_local_begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Return iterator stepping from first node on the thread it is called on over nodes on that thread.
Definition node_collection.cpp:1172
Class for Metadata attached to NodeCollection.
Definition node_collection.h:60
virtual void set_first_node_id(size_t)=0
virtual ~NodeCollectionMetadata()=default
virtual void set_status(const Dictionary &, bool)=0
virtual void get_status(Dictionary &, const NodeCollectionPTR) const =0
virtual void get_status(Dictionary &, NodeCollection const *const) const =0
Retrieve status information sliced according to slicing of node collection.
virtual std::string get_type() const =0
virtual size_t get_first_node_id() const =0
virtual bool operator==(const NodeCollectionMetadataPTR) const =0
Subclass for the primitive NodeCollection type.
Definition node_collection.h:817
NodeCollectionMetadataPTR get_metadata() const override
Gets the metadata of the NodeCollection.
Definition node_collection.h:1347
size_t model_id_
Model ID of the node IDs.
Definition node_collection.h:825
bool has_proxies() const override
Returns whether the NodeCollection contains any nodes with proxies or not.
Definition node_collection.h:1378
bool all_connect_as_neurons() const override
Returns true if all elements connect as neurons.
Definition node_collection.h:1384
long get_nc_index(const size_t) const override
Returns index of node with given node ID in NodeCollection.
Definition node_collection.h:1365
bool all_connect_as_devices() const override
Returns true if all elements connect as devices.
Definition node_collection.h:1393
bool is_contiguous_ascending(const NodeCollectionPrimitive &other) const
Checks if node IDs in another primitive is a continuation of node IDs in this primitive.
Definition node_collection.cpp:710
void set_metadata(NodeCollectionMetadataPTR) override
Sets the metadata of the NodeCollection.
Definition node_collection.h:1341
NodeCollectionPrimitive & operator=(const NodeCollectionPrimitive &)=default
Primitive assignment operator.
bool empty() const override
Checks if the NodeCollection has no elements.
Definition node_collection.h:1359
bool nodes_are_local_receivers_
Whether the primitive contains local receivers.
Definition node_collection.h:828
const_iterator end(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the end of the NodeCollection.
Definition node_collection.h:1315
NodeCollectionPrimitive(const NodeCollectionPrimitive &)=default
Primitive copy constructor.
size_t operator[](const size_t) const override
Get the node ID in the specified index in the NodeCollection.
Definition node_collection.h:1272
NodeCollectionPrimitive()
Create empty NodeCollection.
Definition node_collection.cpp:466
bool operator==(const NodeCollectionPTR rhs) const override
Definition node_collection.h:1283
bool nodes_have_no_proxies_
Whether the primitive contains devices or not.
Definition node_collection.h:827
void assert_consistent_model_ids_(const size_t) const
Raise an error if the model IDs of all nodes in the primitive are not the same as the expected model ...
Definition node_collection.cpp:722
const_iterator begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the beginning of the NodeCollection.
Definition node_collection.h:1309
void print_primitive(std::ostream &) const
Definition node_collection.cpp:692
NodeCollectionMetadataPTR metadata_
Pointer to the metadata of the node IDs.
Definition node_collection.h:826
bool contains(const size_t node_id) const override
Check if the NodeCollection contains a specified node ID.
Definition node_collection.h:1335
size_t stride() const override
Returns the stride between node IDs in the primitive (always 1).
Definition node_collection.h:1329
bool overlapping(const NodeCollectionPrimitive &rhs) const
Checks if node IDs of another primitive is overlapping node IDs of this primitive.
Definition node_collection.cpp:716
const_iterator thread_local_begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Return iterator stepping from first node on the thread it is called on over nodes on that thread.
Definition node_collection.cpp:622
const_iterator rank_local_begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the beginning of the NodeCollection.
Definition node_collection.cpp:603
size_t size() const override
Returns total number of node IDs in the primitive.
Definition node_collection.h:1322
NodeCollectionPTR slice(size_t start, size_t end, size_t stride=1) const override
Slices the NodeCollection to the boundaries, with an optional step parameter.
Definition node_collection.cpp:640
std::ostream & print_me(std::ostream &) const override
Print out the contents of the NodeCollection in a pretty and informative way.
Definition node_collection.cpp:673
NodeCollectionPTR operator+(NodeCollectionPTR rhs) const override
Join two NodeCollections.
Definition node_collection.cpp:533
size_t last_
The last node ID in the primitive.
Definition node_collection.h:824
friend class nc_const_iterator
Definition node_collection.h:818
size_t first_
The first node ID in the primitive.
Definition node_collection.h:823
bool is_range() const override
Definition node_collection.h:1353
Superclass for NodeCollections.
Definition node_collection.h:565
static NodeCollectionPTR create_()
Definition node_collection.cpp:345
static NodeCollectionPTR create(const size_t node_id)
Create a NodeCollection from a single node ID.
Definition node_collection.cpp:314
virtual bool is_range() const =0
virtual size_t stride() const =0
Get the step of the NodeCollection.
virtual const_iterator rank_local_begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const =0
Method to get an iterator representing the beginning of the NodeCollection.
void get_metadata_status(Dictionary &) const
Collect metadata into dictionary.
Definition node_collection.cpp:405
virtual const_iterator thread_local_begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const =0
Return iterator stepping from first node on the thread it is called on over nodes on that thread.
std::vector< size_t > to_array(const std::string &selection) const
Method that creates a vector filled with node IDs from the NodeCollection; for debugging.
Definition node_collection.cpp:477
virtual size_t operator[](size_t) const =0
Get the node ID in the specified index in the NodeCollection.
virtual bool all_connect_as_devices() const =0
Returns true if all elements connect as devices.
virtual const_iterator end(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const =0
Method to get an iterator representing the end of the NodeCollection.
virtual bool all_connect_as_neurons() const =0
Returns true if all elements connect as neurons.
virtual void set_metadata(NodeCollectionMetadataPTR)=0
Sets the metadata of the NodeCollection.
Definition node_collection.h:1142
size_t get_last() const
return the last stored ID inside the NodeCollection
Definition node_collection.h:1154
virtual bool empty() const =0
Checks if the NodeCollection has no elements.
virtual long get_nc_index(const size_t) const =0
Returns index of node with given node ID in NodeCollection.
virtual std::ostream & print_me(std::ostream &) const =0
Print out the contents of the NodeCollection in a pretty and informative way.
virtual bool contains(const size_t node_id) const =0
Check if the NodeCollection contains a specified node ID.
virtual bool operator!=(NodeCollectionPTR) const
Check if two NodeCollections are equal.
Definition node_collection.h:1136
unsigned long fingerprint_
Unique identity of the kernel that created the NodeCollection.
Definition node_collection.h:805
virtual NodeCollectionMetadataPTR get_metadata() const =0
Gets the metadata of the NodeCollection.
virtual NodeCollectionPTR slice(size_t start, size_t end, size_t stride) const =0
Slices the NodeCollection to the boundaries, with an optional step parameter.
virtual const_iterator begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const =0
Method to get an iterator representing the beginning of the NodeCollection.
size_t get_first() const
return the first stored ID (i.e, ID at index zero) inside the NodeCollection
Definition node_collection.h:1148
virtual ~NodeCollection()=default
bool valid() const
Check to see if the fingerprint of the NodeCollection matches that of the kernel.
Definition node_collection.cpp:399
virtual bool has_proxies() const =0
Returns whether the NodeCollection contains any nodes with proxies or not.
virtual NodeCollectionPTR operator+(NodeCollectionPTR) const =0
Join two NodeCollections.
virtual size_t size() const =0
Get the size of the NodeCollection.
NodeCollection()
Initializer gets current fingerprint from the kernel.
Definition node_collection.cpp:308
friend class nc_const_iterator
Definition node_collection.h:566
virtual bool operator==(NodeCollectionPTR) const =0
Represent single node entry in node collection.
Definition node_collection.h:92
NodeIDTriple()=default
size_t model_id
ID of neuron model.
Definition node_collection.h:95
size_t node_id
Global ID of neuron.
Definition node_collection.h:94
size_t nc_index
position with node collection
Definition node_collection.h:96
Base class for all NEST network objects.
Definition node.h:99
Iterator for NodeCollections.
Definition node_collection.h:415
size_t get_step_size() const
Return step size of iterator.
Definition node_collection.h:1260
std::forward_iterator_tag iterator_category
Definition node_collection.h:489
bool operator>=(const nc_const_iterator &rhs) const
Definition node_collection.h:1248
bool operator>(const nc_const_iterator &rhs) const
Definition node_collection.h:1242
NodeCollectionComposite const *const composite_collection_
Pointer to composite collection to iterate over. Zero if iterator is for primitive collection.
Definition node_collection.h:441
NodeIDTriple operator*() const
Definition node_collection.cpp:269
nc_const_iterator & operator++()
Definition node_collection.h:1203
NodeCollectionPrimitive const *const primitive_collection_
Pointer to primitive collection to iterate over. Zero if iterator is for composite collection.
Definition node_collection.h:438
bool operator<=(const nc_const_iterator &rhs) const
Definition node_collection.h:1236
bool operator==(const nc_const_iterator &rhs) const
Definition node_collection.h:1218
bool operator<(const nc_const_iterator &rhs) const
Definition node_collection.h:1230
size_t step_
internal step also accounting for stepping over rank/thread
Definition node_collection.h:433
NCIteratorKind
Markers for kind of iterator, required by composite_update_indices_().
Definition node_collection.h:422
@ GLOBAL
iterate over all elements of node collection
@ THREAD_LOCAL
iterate only over elements on owning thread
@ END
end iterator, never increase
@ RANK_LOCAL
iterate only over elements on owning rank
void advance_global_iter_to_new_part_(size_t n)
Advance composite GLOBAL iterator by n elements, taking stride into account.
Definition node_collection.cpp:158
nc_const_iterator & operator+=(const size_t)
Definition node_collection.h:1161
size_t element_idx_
index into (current) primitive node collection
Definition node_collection.h:431
long difference_type
Definition node_collection.h:490
const size_t rank_or_vp_
rank or vp iterator is bound to
Definition node_collection.h:435
size_t find_next_within_part_(size_t n) const
Return element_idx_ for next element if within part.
Definition node_collection.cpp:128
bool operator!=(const nc_const_iterator &rhs) const
Definition node_collection.h:1224
NodeCollectionPTR coll_ptr_
pointer to keep node collection alive, see note
Definition node_collection.h:430
nc_const_iterator operator+(const size_t) const
Definition node_collection.h:1196
size_t part_idx_
index into parts vector of composite collection
Definition node_collection.h:432
const NCIteratorKind kind_
whether to iterate over all elements or rank/thread specific
Definition node_collection.h:434
std::pair< size_t, size_t > get_part_offset() const
Definition node_collection.h:1254
void advance_local_iter_to_new_part_(size_t n)
Advance composite {THREAD,RANK}_LOCAL iterator by n elements, taking stride into account.
Definition node_collection.cpp:194
nc_const_iterator(const nc_const_iterator &nci)=default
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
Time operator+(const Time &t1, const Time &t2)
Definition nest_time.h:590
std::shared_ptr< NodeCollectionMetadata > NodeCollectionMetadataPTR
Definition node_collection.h:51
std::ostream & operator<<(std::ostream &out, const LoggingEvent &e)
Definition logging_event.cpp:58
std::shared_ptr< NodeCollection > NodeCollectionPTR
Definition node_collection.h:50