2 #include <doctest/doctest.h> 14 template <
int dim,
typename Tindices = std::array<
int, dim>>
struct RowMajorOffset 22 inline int operator()(
const Tindices& N,
const Tindices& n)
25 for (
int i = 0; i < dim; i++) {
27 for (
int j = i + 1; j < dim; j++) {
30 offset += prod * n[i];
37 template <
typename T,
typename Tindices = std::array<
int, 2>>
class DynamicArray2D 43 void resize(
const Tindices& dimensions)
46 data.resize(dim[0] * dim[1],
T());
49 inline size_t index(
const Tindices& i) {
return i[1] + dim[1] * i[0]; }
51 inline T&
operator()(
const Tindices& i) {
return i[1] + dim[1] * i[0]; }
53 inline const T&
operator()(
const Tindices& i)
const {
return i[1] + dim[1] * i[0]; }
57 template <
typename T,
typename Tindices = std::array<
int, 3>>
class DynamicArray3D 63 void resize(
const Tindices& dimensions)
66 data.resize(dim[0] * dim[1] * dim[2],
T());
69 inline size_t index(
const Tindices& i) {
return i[2] + dim[2] * (i[1] + dim[1] * i[0]); }
71 inline T&
operator()(
const Tindices& i) {
return data[i[2] + dim[2] * (i[1] + dim[1] * i[0])]; }
75 return data[i[2] + dim[2] * (i[1] + dim[1] * i[0])];
79 TEST_CASE(
"[Faunus] RowMajor3DMatrix")
82 Eigen::Vector3i dim = {4, 10, 2};
83 Eigen::Vector3i one = {1, 1, 1};
85 matrix({2, 3, 1}) = 0.1;
86 CHECK_EQ(matrix.data[matrix.index({2, 3, 1})], 0.1);
87 CHECK_EQ(&matrix({0, 0, 0}), &matrix.data.front());
88 CHECK_EQ(&matrix(dim - one), &matrix.data.back());
91 CHECK_EQ(matrix.index(dim - one), matrix.data.size() - 1);
92 CHECK_EQ(matrix.index(dim - one), offset(dim, dim - one));
93 CHECK_EQ(matrix.index(dim), offset(dim, dim));
95 for (
int k = 0; k < dim[0]; k++) {
96 for (
int l = 0; l < dim[1]; l++) {
97 for (
int m = 0; m < dim[2]; m++) {
102 CHECK_EQ(cnt, matrix.data.size());
Definition: multimatrix.h:37
int operator()(const Tindices &N, const Tindices &n)
memory offset
Definition: multimatrix.h:22
double T
floating point size
Definition: units.h:73
memory offset for arbitrary dimensions, row-major layout
Definition: multimatrix.h:14
Definition: multimatrix.h:57
Cell list class templates.
Definition: actions.cpp:11