1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// license:GPL-2.0+
// copyright-holders:Couriersud
#ifndef PMATRIX2D_H_
#define PMATRIX2D_H_
///
/// \file pmatrix2d.h
///
#include "palloc.h"
#include <algorithm>
#include <type_traits>
#include <vector>
namespace plib
{
template<typename T, typename A = aligned_allocator<T>>
class pmatrix2d
{
public:
using size_type = std::size_t;
using value_type = T;
using allocator_type = A;
static constexpr const size_type align_size = align_traits<A>::align_size;
static constexpr const size_type stride_size = align_traits<A>::stride_size;
pmatrix2d() noexcept
: m_N(0), m_M(0), m_stride(8), m_v()
{
}
pmatrix2d(size_type N, size_type M)
: m_N(N), m_M(M), m_v()
{
m_stride = ((M + stride_size-1) / stride_size) * stride_size;
m_v.resize(N * m_stride);
}
void resize(size_type N, size_type M)
{
m_N = N;
m_M = M;
m_stride = ((M + stride_size-1) / stride_size) * stride_size;
m_v.resize(N * m_stride);
}
C14CONSTEXPR T * operator[] (size_type row) noexcept
{
return assume_aligned_ptr<T, align_size>(&m_v[m_stride * row]);
}
constexpr const T * operator[] (size_type row) const noexcept
{
return assume_aligned_ptr<T, align_size>(&m_v[m_stride * row]);
}
T & operator()(size_type r, size_type c) noexcept
{
return (*this)[r][c];
}
const T & operator()(size_type r, size_type c) const noexcept
{
return (*this)[r][c];
}
private:
size_type m_N;
size_type m_M;
size_type m_stride;
std::vector<T, A> m_v;
};
} // namespace plib
#endif // PMATRIX2D_H_
|