23#ifndef NODE_COLLECTION_H
24#define NODE_COLLECTION_H
46class NodeCollectionPrimitive;
47class NodeCollectionComposite;
48class NodeCollectionMetadata;
624 virtual std::ostream&
print_me( std::ostream& )
const = 0;
694 std::vector< size_t >
to_array(
const std::string& selection )
const;
701 virtual size_t size()
const = 0;
716 virtual bool contains(
const size_t node_id )
const = 0;
871 std::ostream&
print_me( std::ostream& )
const override;
874 size_t operator[](
const size_t )
const override;
885 size_t size()
const override;
888 size_t stride()
const override;
890 bool contains(
const size_t node_id )
const override;
898 bool empty()
const override;
950 std::vector< NodeCollectionPrimitive >
parts_;
959 std::vector< size_t >
967 void merge_parts_( std::vector< NodeCollectionPrimitive >& parts )
const;
991 bool valid_idx_(
const size_t part_idx,
const size_t element_idx )
const;
1002 std::pair< size_t, size_t >
find_next_part_(
size_t part_idx,
size_t element_idx,
size_t n = 1 )
const;
1061 std::ostream&
print_me( std::ostream& )
const override;
1063 size_t operator[](
const size_t )
const override;
1085 size_t size()
const override;
1088 size_t stride()
const override;
1090 bool contains(
const size_t node_id )
const override;
1098 bool empty()
const override;
1108 return nc->print_me( out );
1115 return not( *
this == rhs );
1121 throw KernelException(
"Cannot set Metadata on this type of NodeCollection." );
1127 return ( *
begin() ).node_id;
1133 assert(
size() > 0 );
1134 return ( *(
begin() + (
size() - 1 ) ) ).node_id;
1203 return not( *
this == rhs );
1215 return ( *
this < rhs or *
this == rhs );
1221 return not( *
this <= rhs );
1227 return not( *
this < rhs );
1230inline std::pair< size_t, size_t >
1245 return lhs->operator+( rhs );
1254 throw std::out_of_range( String::compose(
"pos %1 points outside of the NodeCollection", idx ) );
1271 return *
this == *rhs_ptr;
1279 const bool eq_metadata =
1350 return neuron_id -
first_;
1390 for (
auto& part :
parts_ )
1392 part.set_metadata( meta );
1399 return parts_[ 0 ].get_metadata();
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
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
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