Bring in a row major version of Amit's matrix.
This commit is contained in:
parent
5e63272f24
commit
d47f6f996d
1 changed files with 19 additions and 17 deletions
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#ifndef AMT_MATRIX_HPP
|
||||
#define AMT_MATRIX_HPP
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
@ -120,27 +121,27 @@ namespace amt {
|
|||
constexpr const_reverse_iterator rend() const noexcept { return std::reverse_iterator(begin()); }
|
||||
|
||||
constexpr auto operator()(size_type r, size_type c) noexcept -> reference {
|
||||
auto const index = r * m_col + c; // column-major;
|
||||
auto const index = r + c * m_row; // row-major;
|
||||
assert(index < size() && "Out of bound access");
|
||||
return m_data[index];
|
||||
}
|
||||
|
||||
constexpr auto operator()(size_type r, size_type c) const noexcept -> const_reference {
|
||||
auto const index = r * m_col + c; // column-major;
|
||||
auto const index = r + c * m_row; // row-major;
|
||||
assert(index < size() && "Out of bound access");
|
||||
return m_data[index];
|
||||
}
|
||||
|
||||
constexpr auto operator[](size_type r) noexcept -> View<false> {
|
||||
auto const base = r * m_col;
|
||||
assert(r < rows() && "Out of bound access");
|
||||
return { .data = m_data + base, .size = m_col };
|
||||
constexpr auto operator[](size_type c) noexcept -> View<false> {
|
||||
auto const base = c * m_row;
|
||||
assert(c < cols() && "Out of bound access");
|
||||
return { .data = m_data + base, .size = m_row };
|
||||
}
|
||||
|
||||
constexpr auto operator[](size_type r) const noexcept -> View<true> {
|
||||
auto const base = r * m_col;
|
||||
assert(r < rows() && "Out of bound access");
|
||||
return { .data = m_data + base, .size = m_col };
|
||||
constexpr auto operator[](size_type c) const noexcept -> View<true> {
|
||||
auto const base = c * m_row;
|
||||
assert(c < cols() && "Out of bound access");
|
||||
return { .data = m_data + base, .size = m_row };
|
||||
}
|
||||
|
||||
friend void swap(Matrix& lhs, Matrix& rhs) noexcept {
|
||||
|
@ -158,7 +159,7 @@ namespace amt {
|
|||
|
||||
} // namespace amt
|
||||
|
||||
#if 0
|
||||
|
||||
#include <format>
|
||||
namespace std {
|
||||
template <typename T>
|
||||
|
@ -181,4 +182,5 @@ namespace std {
|
|||
};
|
||||
|
||||
} // namespace std
|
||||
#endif
|
||||
|
||||
#endif // AMT_MATRIX_HPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue