diff options
author | 2019-03-25 22:44:58 +0100 | |
---|---|---|
committer | 2019-03-25 22:44:58 +0100 | |
commit | c24473ddff715ecec2e258a6eb38960cf8c8e98e (patch) | |
tree | 8ea44b6396a6129913c0aac13859b5de9965e972 /src/lib/netlist/plib/pmatrix2d.h | |
parent | 009cba4fb8102102168ef32870892438327f3705 (diff) | |
parent | 598cd5227223c3b04ca31f0dbc1981256d9ea3ff (diff) |
conflict resolution (nw)
Diffstat (limited to 'src/lib/netlist/plib/pmatrix2d.h')
-rw-r--r-- | src/lib/netlist/plib/pmatrix2d.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/lib/netlist/plib/pmatrix2d.h b/src/lib/netlist/plib/pmatrix2d.h new file mode 100644 index 00000000000..eab533688d7 --- /dev/null +++ b/src/lib/netlist/plib/pmatrix2d.h @@ -0,0 +1,85 @@ +// 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 = aligned_allocator<T>> + class pmatrix2d + { + public: + using value_type = T; + using allocator_type = A; + + 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), m_v() + { + } + + pmatrix2d(std::size_t N, std::size_t 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(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_ */ |