7#include <dr/detail/matrix_entry.hpp>
15template <
typename T,
typename I,
typename Allocator = std::allocator<T>>
19 using scalar_type = T;
21 using size_type = std::size_t;
22 using difference_type = std::ptrdiff_t;
24 using allocator_type = Allocator;
29 using backend_allocator_type =
typename std::allocator_traits<
30 allocator_type>::template rebind_alloc<value_type>;
31 using backend_type = std::vector<value_type, backend_allocator_type>;
33 using iterator =
typename backend_type::iterator;
34 using const_iterator =
typename backend_type::const_iterator;
39 using scalar_reference = T &;
45 size_type size()
const noexcept {
return tuples_.size(); }
47 void reserve(size_type new_cap) { tuples_.reserve(new_cap); }
49 iterator begin()
noexcept {
return tuples_.begin(); }
51 const_iterator begin()
const noexcept {
return tuples_.begin(); }
53 iterator end()
noexcept {
return tuples_.end(); }
55 const_iterator end()
const noexcept {
return tuples_.end(); }
57 template <
typename InputIt>
void insert(InputIt first, InputIt last) {
58 for (
auto iter = first; iter != last; ++iter) {
63 template <
typename InputIt>
void push_back(InputIt first, InputIt last) {
64 for (
auto iter = first; iter != last; ++iter) {
69 void push_back(
const value_type &value) { tuples_.push_back(value); }
71 template <
typename InputIt>
void assign_tuples(InputIt first, InputIt last) {
72 tuples_.assign(first, last);
75 std::pair<iterator, bool> insert(
value_type &&value) {
76 auto &&[insert_index, insert_value] = value;
77 for (
auto iter = begin(); iter != end(); ++iter) {
78 auto &&[
index, v] = *iter;
79 if (
index == insert_index) {
83 tuples_.push_back(value);
84 return {--tuples_.end(),
true};
87 std::pair<iterator, bool> insert(
const value_type &value) {
88 auto &&[insert_index, insert_value] = value;
89 for (
auto iter = begin(); iter != end(); ++iter) {
90 auto &&[
index, v] = *iter;
91 if (
index == insert_index) {
95 tuples_.push_back(value);
96 return {--tuples_.end(),
true};
100 std::pair<iterator, bool> insert_or_assign(
key_type k, M &&obj) {
101 for (
auto iter = begin(); iter != end(); ++iter) {
102 auto &&[
index, v] = *iter;
104 v = std::forward<M>(obj);
105 return {iter,
false};
108 tuples_.push_back({k, std::forward<M>(obj)});
109 return {--tuples_.end(),
true};
112 iterator find(
key_type key)
noexcept {
113 return std::ranges::find_if(begin(), end(), [&](
auto &&v) {
119 const_iterator find(
key_type key)
const noexcept {
120 return std::ranges::find_if(begin(), end(), [&](
auto &&v) {
127 bool all_inside =
true;
128 for (
auto &&[
index, v] : *
this) {
129 auto &&[i, j] =
index;
130 if (!(i < shape[0] && j < shape[1])) {
141 for (
auto &&[
index, v] : *
this) {
142 auto &&[i, j] =
index;
143 if (i < shape[0] && j < shape[1]) {
144 new_tuples.insert({
index, v});
148 assign_tuples(new_tuples.begin(), new_tuples.end());
159 std::size_t nbytes()
const noexcept {
165 backend_type tuples_;
Definition: coo_matrix.hpp:16
Definition: matrix_entry.hpp:20
Definition: matrix_entry.hpp:115