blob: 52228548cbf339dc684c8c7bf169f1bf4f8ec234 (
plain) (
blame)
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
82
83
84
|
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* pmatrix2d.h
*
* NxM regular matrix
*
*/
#ifndef PMATRIX2D_H_
#define PMATRIX2D_H_
#include "palloc.h"
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <type_traits>
#include <vector>
namespace plib
{
template<typename T, typename A = std::allocator<T>>
class pmatrix2d
{
public:
using value_type = T;
static constexpr const std::size_t align_size = align_traits<A>::align_size;
static constexpr const std::size_t stride_size = align_traits<A>::stride_size;
pmatrix2d()
: m_N(0), m_M(0), m_stride(8)
{
}
pmatrix2d(std::size_t N, std::size_t M)
: m_N(N), m_M(M)
{
m_stride = ((M + stride_size-1) / stride_size) * stride_size;
m_v.resize(N * m_stride);
}
void resize(std::size_t N, std::size_t 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[] (std::size_t row) noexcept
{
return assume_aligned_ptr<T, align_size>(&m_v[m_stride * row]);
}
constexpr const T * operator[] (std::size_t row) const noexcept
{
return assume_aligned_ptr<T, align_size>(&m_v[m_stride * row]);
}
T & operator()(std::size_t r, std::size_t c) noexcept
{
return (*this)[r][c];
}
const T & operator()(std::size_t r, std::size_t c) const noexcept
{
return (*this)[r][c];
}
private:
std::size_t m_N;
std::size_t m_M;
std::size_t m_stride;
std::vector<T, A> m_v;
};
} // namespace plib
#endif /* MAT_CR_H_ */
|