1#ifndef RAIIGRAPH_MATRIX_HPP
2#define RAIIGRAPH_MATRIX_HPP
31 void setup(igraph_int_t nr, igraph_int_t nc) {
120 check_code(Ns_::copy(&my_matrix, &(other.my_matrix)));
128 if (
this != &other) {
130 check_code(Ns_::update(&my_matrix, &(other.my_matrix)));
141 std::swap(my_matrix, other.my_matrix);
149 if (
this != &other) {
150 std::swap(my_matrix, other.my_matrix);
159 Ns_::destroy(&my_matrix);
167 return Ns_::empty(&my_matrix);
174 return Ns_::size(&my_matrix);
181 return my_matrix.nrow;
188 return my_matrix.ncol;
200 return my_matrix.data.stor_end - my_matrix.data.stor_begin;
221 auto old_size = this->
size();
223 auto new_size = this->
size();
224 if (old_size < new_size) {
225 std::fill_n(
begin() + old_size, new_size - old_size, val);
233 Ns_::shrink_to_fit(&my_matrix);
242 return *(
begin() + i);
250 return *(
begin() + i);
259 return *(
begin() + r + c * my_matrix.nrow);
268 return *(
begin() + r + c * my_matrix.nrow);
304 return my_matrix.data.stor_begin;
311 return my_matrix.data.stor_end;
332 return my_matrix.data.stor_begin;
339 return my_matrix.data.stor_end;
346 return my_matrix.data.stor_begin;
353 return my_matrix.data.stor_begin;
360 return std::reverse_iterator(
end());
367 return std::reverse_iterator(
begin());
374 return std::reverse_iterator(
end());
381 return std::reverse_iterator(
begin());
388 return std::reverse_iterator(
cend());
395 return std::reverse_iterator(
cbegin());
409 template<
typename BaseIterator,
typename BaseReference>
415 View(BaseIterator start,
size_type step_size,
size_type max_steps) : start(start), step_size(step_size), max_steps(max_steps) {}
429 return max_steps == 0;
444 return *(start + i * step_size);
451 return (*
this)[max_steps - 1];
483 using iterator_category = std::random_access_iterator_tag;
485 typedef decltype(&std::declval<BaseReference>()) pointer;
491 start(std::move(start)), step_size(step_size), offset(position * step_size) {}
497 bool operator==(
const Iterator& other)
const {
500 return offset == other.offset;
503 bool operator!=(
const Iterator& other)
const {
504 return offset != other.offset;
507 bool operator<(
const Iterator& other)
const {
508 return offset < other.offset;
511 bool operator>(
const Iterator& other)
const {
512 return offset > other.offset;
515 bool operator<=(
const Iterator& other)
const {
516 return offset <= other.offset;
519 bool operator>=(
const Iterator& other)
const {
520 return offset >= other.offset;
524 BaseReference operator*()
const {
525 return *(start + offset);
529 return *(start + offset + step_size * i);
557 copy.offset += step_size * n;
562 offset += step_size * n;
567 it.offset += it.step_size * n;
573 copy.offset -= step_size * n;
578 offset -= step_size * n;
583 if (other.offset > offset) {
587 return (offset - other.offset) / step_size;
599 return Iterator(start, step_size, 0);
606 return Iterator(start, step_size, max_steps);
626 std::reverse_iterator<Iterator>
rbegin()
const {
627 return std::reverse_iterator(
end());
633 std::reverse_iterator<Iterator>
rend()
const {
634 return std::reverse_iterator(
begin());
640 std::reverse_iterator<Iterator>
crbegin()
const {
641 return std::reverse_iterator(
cend());
647 std::reverse_iterator<Iterator>
crend()
const {
648 return std::reverse_iterator(
cbegin());
674 check_code(Ns_::get_row(&my_matrix, output.get(), r));
700 check_code(Ns_::get_col(&my_matrix, output.get(), c));
745 std::swap(my_matrix, other.my_matrix);
755namespace matrix_internal {
758 typedef igraph_int_t value_type;
759 typedef igraph_matrix_int_t igraph_type;
760 typedef IntVector vector_type;
762#define RAIIGRAPH_MATRIX_SUFFIX _int
763#include "fragments/matrix.hpp"
764#undef RAIIGRAPH_MATRIX_SUFFIX
768 typedef igraph_real_t value_type;
769 typedef igraph_matrix_t igraph_type;
772#define RAIIGRAPH_MATRIX_SUFFIX
773#include "fragments/matrix.hpp"
774#undef RAIIGRAPH_MATRIX_SUFFIX
778 typedef igraph_bool_t value_type;
779 typedef igraph_matrix_bool_t igraph_type;
782#define RAIIGRAPH_MATRIX_SUFFIX _bool
783#include "fragments/matrix.hpp"
784#undef RAIIGRAPH_MATRIX_SUFFIX
Wrapper around igraph_vector_*_t objects with RAII behavior.
View into a row/column of the matrix.
Definition Matrix.hpp:410
std::reverse_iterator< Iterator > crbegin() const
Definition Matrix.hpp:640
bool empty() const
Definition Matrix.hpp:428
size_type size() const
Definition Matrix.hpp:435
BaseReference operator[](size_type i) const
Definition Matrix.hpp:443
Iterator end() const
Definition Matrix.hpp:605
std::reverse_iterator< Iterator > rbegin() const
Definition Matrix.hpp:626
std::reverse_iterator< Iterator > rend() const
Definition Matrix.hpp:633
BaseReference front() const
Definition Matrix.hpp:457
std::reverse_iterator< Iterator > crend() const
Definition Matrix.hpp:647
BaseReference back() const
Definition Matrix.hpp:450
Iterator begin() const
Definition Matrix.hpp:598
Iterator cend() const
Definition Matrix.hpp:619
Iterator cbegin() const
Definition Matrix.hpp:612
Wrapper around igraph_matrix_*_t objects with RAII behavior.
Definition Matrix.hpp:29
vector_type column_copy(size_type c) const
Definition Matrix.hpp:698
const_reference operator()(size_type r, size_type c) const
Definition Matrix.hpp:267
reverse_const_iterator crbegin() const
Definition Matrix.hpp:387
void clear()
Definition Matrix.hpp:207
Matrix(const Matrix< Ns_ > &other)
Definition Matrix.hpp:119
Ns_::value_type value_type
Definition Matrix.hpp:44
Ns_::igraph_type igraph_type
Definition Matrix.hpp:39
igraph_int_t size_type
Definition Matrix.hpp:59
Matrix()
Definition Matrix.hpp:95
igraph_bool_t empty() const
Definition Matrix.hpp:166
View< iterator, reference > column(size_type c)
Definition Matrix.hpp:682
constexpr size_type max_size() const
Definition Matrix.hpp:194
std::reverse_iterator< iterator > reverse_iterator
Definition Matrix.hpp:79
const_reference back() const
Definition Matrix.hpp:281
const igraph_type * get() const
Definition Matrix.hpp:733
const_reference front() const
Definition Matrix.hpp:295
reverse_const_iterator crend() const
Definition Matrix.hpp:394
const_reference operator[](size_type i) const
Definition Matrix.hpp:249
View< const_iterator, const_reference > row(size_type r) const
Definition Matrix.hpp:664
View< const_iterator, const_reference > column(size_type c) const
Definition Matrix.hpp:690
void shrink_to_fit()
Definition Matrix.hpp:232
vector_type row_copy(size_type r) const
Definition Matrix.hpp:672
const value_type * data() const
Definition Matrix.hpp:352
~Matrix()
Definition Matrix.hpp:158
reference back()
Definition Matrix.hpp:274
value_type & reference
Definition Matrix.hpp:49
igraph_type * get()
Definition Matrix.hpp:725
void resize(size_type nr, size_type nc, value_type val=value_type())
Definition Matrix.hpp:220
size_type size() const
Definition Matrix.hpp:173
const_iterator begin() const
Definition Matrix.hpp:317
size_type ncol() const
Definition Matrix.hpp:187
const value_type * const_iterator
Definition Matrix.hpp:74
reverse_const_iterator rbegin() const
Definition Matrix.hpp:373
reverse_const_iterator rend() const
Definition Matrix.hpp:380
Matrix & operator=(Matrix< Ns_ > &&other)
Definition Matrix.hpp:148
View< iterator, reference > row(size_type r)
Definition Matrix.hpp:656
const_iterator cbegin() const
Definition Matrix.hpp:331
iterator end()
Definition Matrix.hpp:310
size_type nrow() const
Definition Matrix.hpp:180
value_type * iterator
Definition Matrix.hpp:69
reference operator()(size_type r, size_type c)
Definition Matrix.hpp:258
Ns_::vector_type vector_type
Definition Matrix.hpp:89
iterator begin()
Definition Matrix.hpp:303
void swap(Matrix< Ns_ > &other)
Definition Matrix.hpp:742
reference operator[](size_type i)
Definition Matrix.hpp:241
Matrix(igraph_type &&matrix)
Definition Matrix.hpp:112
Matrix(size_type nr, size_type nc, const value_type &val=value_type())
Definition Matrix.hpp:102
Matrix(Matrix< Ns_ > &&other)
Definition Matrix.hpp:139
igraph_int_t difference_type
Definition Matrix.hpp:64
const_iterator end() const
Definition Matrix.hpp:324
const_iterator cend() const
Definition Matrix.hpp:338
std::reverse_iterator< const_iterator > reverse_const_iterator
Definition Matrix.hpp:84
reverse_iterator rend()
Definition Matrix.hpp:366
reference front()
Definition Matrix.hpp:288
reverse_iterator rbegin()
Definition Matrix.hpp:359
Matrix< Ns_ > & operator=(const Matrix< Ns_ > &other)
Definition Matrix.hpp:127
size_type capacity() const
Definition Matrix.hpp:199
value_type * data()
Definition Matrix.hpp:345
const value_type & const_reference
Definition Matrix.hpp:54
Error handling for raiigraph.
Utilities for manipulating igraph data structures in C++.
Definition error.hpp:11
Matrix< matrix_internal::Bool > BoolMatrix
Definition Matrix.hpp:814
Matrix< matrix_internal::Integer > IntMatrix
Definition Matrix.hpp:795
Vector< internal::Real > RealVector
Definition Vector.hpp:580
void check_code(igraph_error_t code)
Definition error.hpp:39
Matrix< matrix_internal::Real > RealMatrix
Definition Matrix.hpp:809
Vector< internal::Bool > BoolVector
Definition Vector.hpp:585
Random-access iterator through the view.
Definition Matrix.hpp:465