9#include <dr/detail/index.hpp>
10#include <dr/detail/iterator_adaptor.hpp>
11#include <dr/detail/matrix_entry.hpp>
12#include <dr/sp/views/dense_column_view.hpp>
13#include <dr/sp/views/dense_matrix_iterator.hpp>
14#include <dr/sp/views/dense_row_view.hpp>
18template <
typename T,
typename Allocator = std::allocator<T>>
21 using size_type = std::size_t;
22 using difference_type = std::ptrdiff_t;
24 using allocator_type = Allocator;
26 using scalar_pointer =
typename std::allocator_traits<Allocator>::pointer;
28 using scalar_reference = std::iter_reference_t<scalar_pointer>;
37 : allocator_(Allocator()), shape_(shape), ld_(shape[1]) {
38 data_ = allocator_.allocate(shape_[0] * shape_[1]);
42 requires(std::is_default_constructible_v<Allocator>)
43 : allocator_(Allocator()), shape_(shape), ld_(ld) {
44 data_ = allocator_.allocate(shape_[0] * ld_);
48 : allocator_(alloc), shape_(shape), ld_(ld) {
49 data_ = allocator_.allocate(shape_[0] * ld_);
53 : allocator_(other.allocator_), data_(other.data_), shape_(other.shape_),
59 deallocate_storage_();
60 allocator_ = other.allocator_;
62 shape_ = other.shape_;
73 key_type shape()
const noexcept {
return shape_; }
75 size_type size()
const noexcept {
return shape()[0] * shape()[1]; }
77 scalar_reference operator[](
key_type idx)
const {
78 return data_[idx[0] * ld_ + idx[1]];
89 auto row(size_type row_index)
const {
92 auto row_elements = rng::views::iota(size_type(0), size_type(shape()[1]));
93 scalar_pointer data = data_ + row_index * ld_;
95 return row_elements | rng::views::transform([=](
auto column_index) {
101 auto column(size_type column_index)
const {
104 auto column_elements =
105 rng::views::iota(size_type(0), size_type(shape()[0]));
106 scalar_pointer data = data_ + column_index;
109 return column_elements | rng::views::transform([=](
auto row_index) {
111 data[row_index * ld]);
115 scalar_pointer data()
const {
return data_; }
117 size_type ld()
const {
return ld_; }
125 void deallocate_storage_() {
126 if (data_ !=
nullptr) {
127 allocator_.deallocate(data_, shape_[0] * ld_);
137 allocator_type allocator_;
138 scalar_pointer data_;
Definition: iterator_adaptor.hpp:23
Definition: matrix_entry.hpp:115
Definition: dense_matrix.hpp:19