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 <cassert>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
@ -119,28 +120,28 @@ namespace amt {
|
||||||
constexpr const_reverse_iterator rbegin() const noexcept { return std::reverse_iterator(end()); }
|
constexpr const_reverse_iterator rbegin() const noexcept { return std::reverse_iterator(end()); }
|
||||||
constexpr const_reverse_iterator rend() const noexcept { return std::reverse_iterator(begin()); }
|
constexpr const_reverse_iterator rend() const noexcept { return std::reverse_iterator(begin()); }
|
||||||
|
|
||||||
constexpr auto operator()(size_type r, size_type c) noexcept -> reference {
|
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");
|
assert(index < size() && "Out of bound access");
|
||||||
return m_data[index];
|
return m_data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto operator()(size_type r, size_type c) const noexcept -> const_reference {
|
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");
|
assert(index < size() && "Out of bound access");
|
||||||
return m_data[index];
|
return m_data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto operator[](size_type r) noexcept -> View<false> {
|
constexpr auto operator[](size_type c) noexcept -> View<false> {
|
||||||
auto const base = r * m_col;
|
auto const base = c * m_row;
|
||||||
assert(r < rows() && "Out of bound access");
|
assert(c < cols() && "Out of bound access");
|
||||||
return { .data = m_data + base, .size = m_col };
|
return { .data = m_data + base, .size = m_row };
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto operator[](size_type r) const noexcept -> View<true> {
|
constexpr auto operator[](size_type c) const noexcept -> View<true> {
|
||||||
auto const base = r * m_col;
|
auto const base = c * m_row;
|
||||||
assert(r < rows() && "Out of bound access");
|
assert(c < cols() && "Out of bound access");
|
||||||
return { .data = m_data + base, .size = m_col };
|
return { .data = m_data + base, .size = m_row };
|
||||||
}
|
}
|
||||||
|
|
||||||
friend void swap(Matrix& lhs, Matrix& rhs) noexcept {
|
friend void swap(Matrix& lhs, Matrix& rhs) noexcept {
|
||||||
|
@ -158,7 +159,7 @@ namespace amt {
|
||||||
|
|
||||||
} // namespace amt
|
} // namespace amt
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include <format>
|
#include <format>
|
||||||
namespace std {
|
namespace std {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -181,4 +182,5 @@ namespace std {
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace std
|
} // namespace std
|
||||||
#endif
|
|
||||||
|
#endif // AMT_MATRIX_HPP
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue