NEST main@caf0ae8
 
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
773 void get_metadata_status( Dictionary& ) const;
774
778 size_t get_first() const;
779
783 size_t get_last() const;
784
785
786private:
787 unsigned long fingerprint_;
788 static NodeCollectionPTR create_();
789 static NodeCollectionPTR create_( const std::vector< size_t >& );
790};
791
799{
800 friend class nc_const_iterator;
801
802private:
803 // Even though all members are logically const, we cannot declare them const because
804 // sorting or merging the parts_ array requires assignment.
805 size_t first_;
806 size_t last_;
807 size_t model_id_;
810
818 void assert_consistent_model_ids_( const size_t ) const;
819
820public:
830 NodeCollectionPrimitive( size_t first, size_t last, size_t model_id, NodeCollectionMetadataPTR );
831
839 NodeCollectionPrimitive( size_t first, size_t last, size_t model_id );
840
848 NodeCollectionPrimitive( size_t first, size_t last );
849
856
863
870
871 std::ostream& print_me( std::ostream& ) const override;
872 void print_primitive( std::ostream& ) const;
873
874 size_t operator[]( const size_t ) const override;
875 NodeCollectionPTR operator+( NodeCollectionPTR rhs ) const override;
876 bool operator==( const NodeCollectionPTR rhs ) const override;
877 bool operator==( const NodeCollectionPrimitive& rhs ) const;
878
879 const_iterator begin( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
882 const_iterator end( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
883
885 size_t size() const override;
886
888 size_t stride() const override;
889
890 bool contains( const size_t node_id ) const override;
891 NodeCollectionPTR slice( size_t start, size_t end, size_t stride = 1 ) const override;
892
894
896
897 bool is_range() const override;
898 bool empty() const override;
899
900 long get_nc_index( const size_t ) const override;
901
902 bool has_proxies() const override;
903
913 bool is_contiguous_ascending( const NodeCollectionPrimitive& other ) const;
914
921 bool overlapping( const NodeCollectionPrimitive& rhs ) const;
922};
923
925
946{
947 friend class nc_const_iterator;
948
949private:
950 std::vector< NodeCollectionPrimitive > parts_;
951 size_t size_;
952 size_t stride_;
953 size_t first_part_;
954 size_t first_elem_;
955 size_t last_part_;
956 size_t last_elem_;
958 std::vector< size_t > cumul_abs_size_;
959 std::vector< size_t >
961
967 void merge_parts_( std::vector< NodeCollectionPrimitive >& parts ) const;
968
970 typedef size_t ( *gid_to_phase_fcn_ )( size_t );
971
982 std::pair< size_t, size_t > specific_local_begin_( size_t period,
983 size_t phase,
984 size_t start_part,
985 size_t start_offset,
986 gid_to_phase_fcn_ period_first_node ) const;
987
991 bool valid_idx_( const size_t part_idx, const size_t element_idx ) const;
992
1002 std::pair< size_t, size_t > find_next_part_( size_t part_idx, size_t element_idx, size_t n = 1 ) const;
1003
1005 static size_t gid_to_vp_( size_t gid );
1006
1008 static size_t gid_to_rank_( size_t gid );
1009
1010
1011public:
1027 NodeCollectionComposite( const NodeCollectionPrimitive&, size_t, size_t, size_t );
1028
1042 NodeCollectionComposite( const NodeCollectionComposite&, size_t, size_t, size_t );
1043
1052 explicit NodeCollectionComposite( const std::vector< NodeCollectionPrimitive >& );
1053
1060
1061 std::ostream& print_me( std::ostream& ) const override;
1062
1063 size_t operator[]( const size_t ) const override;
1064
1075 NodeCollectionPTR operator+( NodeCollectionPTR rhs ) const override;
1077 bool operator==( const NodeCollectionPTR rhs ) const override;
1078
1079 const_iterator begin( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
1082 const_iterator end( NodeCollectionPTR = NodeCollectionPTR( nullptr ) ) const override;
1083
1085 size_t size() const override;
1086
1088 size_t stride() const override;
1089
1090 bool contains( const size_t node_id ) const override;
1091 NodeCollectionPTR slice( size_t start, size_t end, size_t step = 1 ) const override;
1092
1093 void set_metadata( NodeCollectionMetadataPTR ) override;
1094
1095 NodeCollectionMetadataPTR get_metadata() const override;
1096
1097 bool is_range() const override;
1098 bool empty() const override;
1099
1100 long get_nc_index( const size_t ) const override;
1101
1102 bool has_proxies() const override;
1103};
1104
1105inline std::ostream&
1106operator<<( std::ostream& out, const NodeCollectionPTR nc )
1107{
1108 return nc->print_me( out );
1109}
1110
1111
1112inline bool
1114{
1115 return not( *this == rhs );
1116}
1117
1118inline void
1120{
1121 throw KernelException( "Cannot set Metadata on this type of NodeCollection." );
1122}
1123
1124inline size_t
1126{
1127 return ( *begin() ).node_id;
1128}
1129
1130inline size_t
1132{
1133 assert( size() > 0 );
1134 return ( *( begin() + ( size() - 1 ) ) ).node_id;
1135}
1136
1137inline nc_const_iterator&
1139{
1140 assert( kind_ != NCIteratorKind::END );
1141
1142 if ( n == 0 )
1143 {
1144 return *this;
1145 }
1146
1147 const auto new_element_idx = find_next_within_part_( n );
1148
1149 // For a primitive collection, we either have a new element or are at the end
1150 // For a composite collection, we may need to search through further parts,
1151 // which is signalled by new_element_idx == element_idx_
1152 if ( primitive_collection_ or new_element_idx != element_idx_ )
1153 {
1154 element_idx_ = new_element_idx;
1155 }
1156 else
1157 {
1158 // We did not find a new element in the current part and have not exhausted the collection
1160 {
1162 }
1163 else
1164 {
1166 }
1167 }
1168
1169 return *this;
1170}
1171
1172inline nc_const_iterator
1173nc_const_iterator::operator+( const size_t n ) const
1174{
1175 nc_const_iterator it = *this;
1176 return it += n;
1177}
1178
1179inline nc_const_iterator&
1181{
1182 ( *this ) += 1;
1183 return *this;
1184}
1185
1186inline nc_const_iterator
1188{
1189 nc_const_iterator tmp = *this;
1190 ++( *this );
1191 return tmp;
1192}
1193
1194inline bool
1196{
1197 return part_idx_ == rhs.part_idx_ and element_idx_ == rhs.element_idx_;
1198}
1199
1200inline bool
1202{
1203 return not( *this == rhs );
1204}
1205
1206inline bool
1208{
1209 return ( part_idx_ < rhs.part_idx_ or ( part_idx_ == rhs.part_idx_ and element_idx_ < rhs.element_idx_ ) );
1210}
1211
1212inline bool
1214{
1215 return ( *this < rhs or *this == rhs );
1216}
1217
1218inline bool
1220{
1221 return not( *this <= rhs );
1222}
1223
1224inline bool
1226{
1227 return not( *this < rhs );
1228}
1229
1230inline std::pair< size_t, size_t >
1232{
1233 return { part_idx_, element_idx_ };
1234}
1235
1236inline size_t
1238{
1239 return step_;
1240}
1241
1242inline NodeCollectionPTR
1244{
1245 return lhs->operator+( rhs );
1246}
1247
1248inline size_t
1250{
1251 // throw exception if outside of NodeCollection
1252 if ( first_ + idx > last_ )
1253 {
1254 throw std::out_of_range( String::compose( "pos %1 points outside of the NodeCollection", idx ) );
1255 }
1256 return first_ + idx;
1257}
1258
1259inline bool
1261{
1262 auto const* const rhs_ptr = dynamic_cast< NodeCollectionPrimitive const* >( rhs.get() );
1263 // Checking that rhs_ptr is valid first, to avoid segfaults. If rhs is a NodeCollectionComposite,
1264 // rhs_ptr will be a null pointer.
1265 if ( not rhs_ptr )
1266 {
1267 return false;
1268 }
1269
1270 // We know we have a primitive collection, so forward
1271 return *this == *rhs_ptr;
1272}
1273
1274inline bool
1276{
1277 // Not dereferencing rhs_ptr->metadata_ in the equality comparison because we want to avoid overloading
1278 // operator==() of *metadata_, and to let it handle typechecking.
1279 const bool eq_metadata =
1280 ( not metadata_ and not rhs.metadata_ ) or ( metadata_ and rhs.metadata_ and *metadata_ == rhs.metadata_ );
1281
1282 return first_ == rhs.first_ and last_ == rhs.last_ and model_id_ == rhs.model_id_ and eq_metadata;
1283}
1284
1287{
1288 return nc_const_iterator( cp, *this, /* offset */ 0, /* stride */ 1 );
1289}
1290
1293{
1294 // The unique end() element of a primitive NC is given by (part 0, element size()) )
1295 return nc_const_iterator( cp, *this, /* offset */ size(), /* stride */ 1, nc_const_iterator::NCIteratorKind::END );
1296}
1297
1298inline size_t
1300{
1301 // empty NC has first_ == last_ == 0, need to handle that special
1302 return std::min( last_, last_ - first_ + 1 );
1303}
1304
1305inline size_t
1307{
1308 return 1;
1309}
1310
1311inline bool
1312NodeCollectionPrimitive::contains( const size_t node_id ) const
1313{
1314 return first_ <= node_id and node_id <= last_;
1315}
1316
1317inline void
1322
1325{
1326 return metadata_;
1327}
1328
1329inline bool
1331{
1332 return true;
1333}
1334
1335inline bool
1337{
1338 return last_ == 0;
1339}
1340
1341inline long
1342NodeCollectionPrimitive::get_nc_index( const size_t neuron_id ) const
1343{
1344 if ( neuron_id < first_ or last_ < neuron_id )
1345 {
1346 return -1;
1347 }
1348 else
1349 {
1350 return neuron_id - first_;
1351 }
1352}
1353
1354inline bool
1359
1365
1368{
1369 // The unique end() element of a composite NC is given by one past the last element
1370 // This is the (potentially non-existing) next element irrespective of stride and step
1371 return nc_const_iterator(
1372 cp, *this, last_part_, last_elem_ + 1, /* stride */ 1, nc_const_iterator::NCIteratorKind::END );
1373}
1374
1375inline size_t
1377{
1378 return size_;
1379}
1380
1381inline size_t
1383{
1384 return stride_;
1385}
1386
1387inline void
1389{
1390 for ( auto& part : parts_ )
1391 {
1392 part.set_metadata( meta );
1393 }
1394}
1395
1398{
1399 return parts_[ 0 ].get_metadata();
1400}
1401
1402inline bool
1404{
1405 return false;
1406}
1407
1408inline bool
1410{
1411 // Composite NodeCollections can never be empty.
1412 return false;
1413}
1414
1415inline bool
1416NodeCollectionComposite::contains( const size_t node_id ) const
1417{
1418 return get_nc_index( node_id ) != -1;
1419}
1420
1421inline bool
1422NodeCollectionComposite::valid_idx_( const size_t part_idx, const size_t element_idx ) const
1423{
1424 return part_idx < last_part_ or ( part_idx == last_part_ and element_idx <= last_elem_ );
1425}
1426
1427} // namespace nest
1428
1429#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:946
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:1144
static size_t gid_to_vp_(size_t gid)
helper for thread_local_begin/compsite_update_indices
Definition node_collection.cpp:1132
void merge_parts_(std::vector< NodeCollectionPrimitive > &parts) const
Goes through the vector of primitives, merging as much as possible.
Definition node_collection.cpp:1231
size_t size() const override
Returns total number of node IDs in the composite.
Definition node_collection.h:1376
NodeCollectionPTR operator+(NodeCollectionPTR rhs) const override
Addition operator.
Definition node_collection.cpp:895
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:1191
size_t first_part_
Primitive to start at, set when slicing.
Definition node_collection.h:953
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:1367
size_t(* gid_to_phase_fcn_)(size_t)
Type for lambda-helper function used by {rank, thread, specific}_local_begin.
Definition node_collection.h:970
size_t size_
Total number of node IDs, takes into account slicing.
Definition node_collection.h:951
bool is_sliced_
Whether the NodeCollectionComposite is sliced.
Definition node_collection.h:957
bool has_proxies() const override
Returns whether the NodeCollection contains any nodes with proxies or not.
Definition node_collection.cpp:1334
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:1422
long get_nc_index(const size_t) const override
Returns index of node with given node ID in NodeCollection.
Definition node_collection.cpp:1258
size_t stride_
Step length, set when slicing.
Definition node_collection.h:952
size_t last_elem_
Last entry of parts_[last_part_] belonging to sliced NC.
Definition node_collection.h:956
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:1059
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:960
bool contains(const size_t node_id) const override
Check if the NodeCollection contains a specified node ID.
Definition node_collection.h:1416
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:955
size_t stride() const override
Returns the stride between node IDs in the composite.
Definition node_collection.h:1382
NodeCollectionMetadataPTR get_metadata() const override
Gets the metadata of the NodeCollection.
Definition node_collection.h:1397
bool empty() const override
Checks if the NodeCollection has no elements.
Definition node_collection.h:1409
void set_metadata(NodeCollectionMetadataPTR) override
Sets the metadata of the NodeCollection.
Definition node_collection.h:1388
const_iterator begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the beginning of the NodeCollection.
Definition node_collection.h:1361
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:1341
std::vector< size_t > cumul_abs_size_
Cumulative size of parts.
Definition node_collection.h:958
bool is_range() const override
Definition node_collection.h:1403
std::vector< NodeCollectionPrimitive > parts_
Primitives forming composite.
Definition node_collection.h:950
size_t operator[](const size_t) const override
Get the node ID in the specified index in the NodeCollection.
Definition node_collection.cpp:1006
size_t first_elem_
Element to start at, set when slicing.
Definition node_collection.h:954
bool operator==(const NodeCollectionPTR rhs) const override
Definition node_collection.cpp:1036
static size_t gid_to_rank_(size_t gid)
helper for rank_local_begin/compsite_update_indices
Definition node_collection.cpp:1138
friend class nc_const_iterator
Definition node_collection.h:947
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:1167
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:799
NodeCollectionMetadataPTR get_metadata() const override
Gets the metadata of the NodeCollection.
Definition node_collection.h:1324
size_t model_id_
Model ID of the node IDs.
Definition node_collection.h:807
bool has_proxies() const override
Returns whether the NodeCollection contains any nodes with proxies or not.
Definition node_collection.h:1355
long get_nc_index(const size_t) const override
Returns index of node with given node ID in NodeCollection.
Definition node_collection.h:1342
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:705
void set_metadata(NodeCollectionMetadataPTR) override
Sets the metadata of the NodeCollection.
Definition node_collection.h:1318
NodeCollectionPrimitive & operator=(const NodeCollectionPrimitive &)=default
Primitive assignment operator.
bool empty() const override
Checks if the NodeCollection has no elements.
Definition node_collection.h:1336
const_iterator end(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the end of the NodeCollection.
Definition node_collection.h:1292
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:1249
NodeCollectionPrimitive()
Create empty NodeCollection.
Definition node_collection.cpp:462
bool operator==(const NodeCollectionPTR rhs) const override
Definition node_collection.h:1260
bool nodes_have_no_proxies_
Whether the primitive contains devices or not.
Definition node_collection.h:809
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:717
const_iterator begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
Method to get an iterator representing the beginning of the NodeCollection.
Definition node_collection.h:1286
void print_primitive(std::ostream &) const
Definition node_collection.cpp:687
NodeCollectionMetadataPTR metadata_
Pointer to the metadata of the node IDs.
Definition node_collection.h:808
bool contains(const size_t node_id) const override
Check if the NodeCollection contains a specified node ID.
Definition node_collection.h:1312
size_t stride() const override
Returns the stride between node IDs in the primitive (always 1).
Definition node_collection.h:1306
bool overlapping(const NodeCollectionPrimitive &rhs) const
Checks if node IDs of another primitive is overlapping node IDs of this primitive.
Definition node_collection.cpp:711
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:617
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:598
size_t size() const override
Returns total number of node IDs in the primitive.
Definition node_collection.h:1299
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:635
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:668
NodeCollectionPTR operator+(NodeCollectionPTR rhs) const override
Join two NodeCollections.
Definition node_collection.cpp:528
size_t last_
The last node ID in the primitive.
Definition node_collection.h:806
friend class nc_const_iterator
Definition node_collection.h:800
size_t first_
The first node ID in the primitive.
Definition node_collection.h:805
bool is_range() const override
Definition node_collection.h:1330
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:472
virtual size_t operator[](size_t) const =0
Get the node ID in the specified index in the NodeCollection.
virtual const_iterator end(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const =0
Method to get an iterator representing the end of the NodeCollection.
virtual void set_metadata(NodeCollectionMetadataPTR)=0
Sets the metadata of the NodeCollection.
Definition node_collection.h:1119
size_t get_last() const
return the last stored ID inside the NodeCollection
Definition node_collection.h:1131
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:1113
unsigned long fingerprint_
Unique identity of the kernel that created the NodeCollection.
Definition node_collection.h:787
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:1125
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:1237
std::forward_iterator_tag iterator_category
Definition node_collection.h:489
bool operator>=(const nc_const_iterator &rhs) const
Definition node_collection.h:1225
bool operator>(const nc_const_iterator &rhs) const
Definition node_collection.h:1219
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:1180
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:1213
bool operator==(const nc_const_iterator &rhs) const
Definition node_collection.h:1195
bool operator<(const nc_const_iterator &rhs) const
Definition node_collection.h:1207
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:1138
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:1201
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:1173
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:1231
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