1#ifndef RAIIGRAPH_MATRIX_HPP
2#define RAIIGRAPH_MATRIX_HPP
28 void setup(igraph_integer_t nr, igraph_integer_t nc) {
29 if (Ns_::init(&my_matrix, nr, nc)) {
30 throw std::runtime_error(
"failed to initialize igraph matrix of dimensions " + std::to_string(nr) +
" x " + std::to_string(nc));
119 if (Ns_::copy(&my_matrix, &(
other.my_matrix))) {
120 throw std::runtime_error(
"failed to copy-construct integer igraph matrix");
129 if (
this != &
other) {
130 if (Ns_::update(&my_matrix, &(
other.my_matrix))) {
131 throw std::runtime_error(
"failed to copy-assign integer igraph matrix");
143 std::swap(my_matrix,
other.my_matrix);
151 if (
this != &
other) {
152 std::swap(my_matrix,
other.my_matrix);
161 Ns_::destroy(&my_matrix);
169 return Ns_::empty(&my_matrix);
176 return Ns_::size(&my_matrix);
183 return my_matrix.nrow;
190 return my_matrix.ncol;
202 return my_matrix.data.stor_end - my_matrix.data.stor_begin;
235 Ns_::shrink_to_fit(&my_matrix);
261 return *(
begin() +
r +
c * my_matrix.nrow);
270 return *(
begin() +
r +
c * my_matrix.nrow);
306 return my_matrix.data.stor_begin;
313 return my_matrix.data.stor_end;
334 return my_matrix.data.stor_begin;
341 return my_matrix.data.stor_end;
348 return my_matrix.data.stor_begin;
355 return my_matrix.data.stor_begin;
362 return std::reverse_iterator(
end());
369 return std::reverse_iterator(
begin());
376 return std::reverse_iterator(
end());
383 return std::reverse_iterator(
begin());
390 return std::reverse_iterator(
cend());
397 return std::reverse_iterator(
cbegin());
411 template<
typename BaseIterator,
typename BaseReference>
446 return *(start +
i * step_size);
487 typedef decltype(&std::declval<BaseReference>())
pointer;
493 start(std::move(start)), step_size(step_size), offset(
position * step_size) {}
502 return offset ==
other.offset;
506 return offset !=
other.offset;
510 return offset <
other.offset;
514 return offset >
other.offset;
518 return offset <=
other.offset;
522 return offset >=
other.offset;
527 return *(start + offset);
531 return *(start + offset + step_size *
i);
559 copy.offset += step_size *
n;
564 offset += step_size *
n;
569 it.offset +=
it.step_size *
n;
575 copy.offset -= step_size *
n;
580 offset -= step_size *
n;
585 if (
other.offset > offset) {
589 return (offset -
other.offset) / step_size;
601 return Iterator(start, step_size, 0);
628 std::reverse_iterator<Iterator>
rbegin()
const {
629 return std::reverse_iterator(
end());
635 std::reverse_iterator<Iterator>
rend()
const {
636 return std::reverse_iterator(
begin());
642 std::reverse_iterator<Iterator>
crbegin()
const {
643 return std::reverse_iterator(
cend());
649 std::reverse_iterator<Iterator>
crend()
const {
650 return std::reverse_iterator(
cbegin());
747 std::swap(my_matrix,
other.my_matrix);
757namespace matrix_internal {
760 typedef igraph_integer_t value_type;
761 typedef igraph_matrix_int_t igraph_type;
762 typedef IntVector vector_type;
764#define RAIIGRAPH_MATRIX_SUFFIX _int
765#include "fragments/matrix.hpp"
766#undef RAIIGRAPH_MATRIX_SUFFIX
770 typedef igraph_real_t value_type;
771 typedef igraph_matrix_t igraph_type;
774#define RAIIGRAPH_MATRIX_SUFFIX
775#include "fragments/matrix.hpp"
776#undef RAIIGRAPH_MATRIX_SUFFIX
780 typedef igraph_bool_t value_type;
781 typedef igraph_matrix_bool_t igraph_type;
784#define RAIIGRAPH_MATRIX_SUFFIX _bool
785#include "fragments/matrix.hpp"
786#undef RAIIGRAPH_MATRIX_SUFFIX
Wrapper around igraph_vector_*_t objects with RAII behavior.
View into a row/column of the matrix.
Definition Matrix.hpp:412
std::reverse_iterator< Iterator > crbegin() const
Definition Matrix.hpp:642
bool empty() const
Definition Matrix.hpp:430
size_type size() const
Definition Matrix.hpp:437
BaseReference operator[](size_type i) const
Definition Matrix.hpp:445
Iterator end() const
Definition Matrix.hpp:607
std::reverse_iterator< Iterator > rbegin() const
Definition Matrix.hpp:628
std::reverse_iterator< Iterator > rend() const
Definition Matrix.hpp:635
BaseReference front() const
Definition Matrix.hpp:459
std::reverse_iterator< Iterator > crend() const
Definition Matrix.hpp:649
BaseReference back() const
Definition Matrix.hpp:452
Iterator begin() const
Definition Matrix.hpp:600
Iterator cend() const
Definition Matrix.hpp:621
Iterator cbegin() const
Definition Matrix.hpp:614
Wrapper around igraph_matrix_*_t objects with RAII behavior.
Definition Matrix.hpp:26
vector_type column_copy(size_type c) const
Definition Matrix.hpp:700
std::reverse_iterator< const_iterator > reverse_const_iterator
Definition Matrix.hpp:83
const_reference operator()(size_type r, size_type c) const
Definition Matrix.hpp:269
reverse_const_iterator crbegin() const
Definition Matrix.hpp:389
void clear()
Definition Matrix.hpp:209
Matrix(const Matrix< Ns_ > &other)
Definition Matrix.hpp:118
Ns_::igraph_type igraph_type
Definition Matrix.hpp:38
value_type * iterator
Definition Matrix.hpp:68
Matrix()
Definition Matrix.hpp:94
igraph_bool_t empty() const
Definition Matrix.hpp:168
View< iterator, reference > column(size_type c)
Definition Matrix.hpp:684
constexpr size_type max_size() const
Definition Matrix.hpp:196
Ns_::value_type value_type
Definition Matrix.hpp:43
const_reference back() const
Definition Matrix.hpp:283
const igraph_type * get() const
Definition Matrix.hpp:735
const_reference front() const
Definition Matrix.hpp:297
reverse_const_iterator crend() const
Definition Matrix.hpp:396
const_reference operator[](size_type i) const
Definition Matrix.hpp:251
View< const_iterator, const_reference > row(size_type r) const
Definition Matrix.hpp:666
View< const_iterator, const_reference > column(size_type c) const
Definition Matrix.hpp:692
void shrink_to_fit()
Definition Matrix.hpp:234
vector_type row_copy(size_type r) const
Definition Matrix.hpp:674
const value_type * data() const
Definition Matrix.hpp:354
value_type & reference
Definition Matrix.hpp:48
~Matrix()
Definition Matrix.hpp:160
reference back()
Definition Matrix.hpp:276
igraph_type * get()
Definition Matrix.hpp:727
void resize(size_type nr, size_type nc, value_type val=value_type())
Definition Matrix.hpp:222
Ns_::vector_type vector_type
Definition Matrix.hpp:88
size_type size() const
Definition Matrix.hpp:175
const value_type * const_iterator
Definition Matrix.hpp:73
const_iterator begin() const
Definition Matrix.hpp:319
size_type ncol() const
Definition Matrix.hpp:189
reverse_const_iterator rbegin() const
Definition Matrix.hpp:375
reverse_const_iterator rend() const
Definition Matrix.hpp:382
Matrix & operator=(Matrix< Ns_ > &&other)
Definition Matrix.hpp:150
View< iterator, reference > row(size_type r)
Definition Matrix.hpp:658
const_iterator cbegin() const
Definition Matrix.hpp:333
const value_type & const_reference
Definition Matrix.hpp:53
iterator end()
Definition Matrix.hpp:312
igraph_integer_t size_type
Definition Matrix.hpp:58
size_type nrow() const
Definition Matrix.hpp:182
reference operator()(size_type r, size_type c)
Definition Matrix.hpp:260
iterator begin()
Definition Matrix.hpp:305
void swap(Matrix< Ns_ > &other)
Definition Matrix.hpp:744
reference operator[](size_type i)
Definition Matrix.hpp:243
Matrix(igraph_type &&matrix)
Definition Matrix.hpp:111
Matrix(size_type nr, size_type nc, const value_type &val=value_type())
Definition Matrix.hpp:101
Matrix(Matrix< Ns_ > &&other)
Definition Matrix.hpp:141
const_iterator end() const
Definition Matrix.hpp:326
const_iterator cend() const
Definition Matrix.hpp:340
igraph_integer_t difference_type
Definition Matrix.hpp:63
reverse_iterator rend()
Definition Matrix.hpp:368
reference front()
Definition Matrix.hpp:290
reverse_iterator rbegin()
Definition Matrix.hpp:361
std::reverse_iterator< iterator > reverse_iterator
Definition Matrix.hpp:78
Matrix< Ns_ > & operator=(const Matrix< Ns_ > &other)
Definition Matrix.hpp:128
size_type capacity() const
Definition Matrix.hpp:201
value_type * data()
Definition Matrix.hpp:347
Error handling for raiigraph.
Utilities for manipulating igraph data structures in C++.
Definition error.hpp:11
Matrix< matrix_internal::Bool > BoolMatrix
Definition Matrix.hpp:816
Matrix< matrix_internal::Integer > IntMatrix
Definition Matrix.hpp:797
Vector< internal::Real > RealVector
Definition Vector.hpp:582
void check_code(igraph_error_t code)
Definition error.hpp:34
Matrix< matrix_internal::Real > RealMatrix
Definition Matrix.hpp:811
Vector< internal::Bool > BoolVector
Definition Vector.hpp:587
Random-access iterator through the view.
Definition Matrix.hpp:467