Skip to content

Commit

Permalink
Filter testviews output
Browse files Browse the repository at this point in the history
  • Loading branch information
lindstro committed Sep 18, 2024
1 parent 3b6eb55 commit b621b47
Showing 1 changed file with 58 additions and 11 deletions.
69 changes: 58 additions & 11 deletions tests/testviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ verify(double f, double g)
}
}

// filter output; returns true for first head and last tail calls
static bool
filter_output(size_t head = 0, size_t tail = 0, size_t size = 0)
{
static size_t i = 0;
static size_t h = 0;
static size_t t = 0;
static size_t n = 0;

if (size) {
i = 0;
h = head;
t = tail;
n = size;
return false;
}

bool display = !(h <= i && i + t < n);
if (!display && i == h)
std::cout << "..." << std::endl;
i++;

return display;
}

static int
usage()
{
Expand Down Expand Up @@ -98,30 +123,36 @@ int main(int argc, char* argv[])
// rectangular view into a
std::cout << std::endl << "3D view" << std::endl;
zfp::array3<double>::view v(&a, x0, y0, z0, mx, my, mz);
filter_output(v.size_x() + 2, 3, v.size());
for (size_t z = 0; z < v.size_z(); z++)
for (size_t y = 0; y < v.size_y(); y++)
for (size_t x = 0; x < v.size_x(); x++) {
std::cout << x << " " << y << " " << z << ": " << a(x0 + x, y0 + y, z0 + z) << " " << v(x, y, z) << std::endl;
if (filter_output())
std::cout << x << " " << y << " " << z << ": " << a(x0 + x, y0 + y, z0 + z) << " " << v(x, y, z) << std::endl;
verify(a(x0 + x, y0 + y, z0 + z), v(x, y, z));
}

// flat view of all of a
std::cout << std::endl << "3D flat view" << std::endl;
zfp::array3<double>::flat_view fv(&a);
filter_output(fv.size_x() + 2, 3, fv.size());
for (size_t z = 0; z < fv.size_z(); z++)
for (size_t y = 0; y < fv.size_y(); y++)
for (size_t x = 0; x < fv.size_x(); x++) {
std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << fv[fv.index(x, y, z)] << std::endl;
if (filter_output())
std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << fv[fv.index(x, y, z)] << std::endl;
verify(a(x, y, z), fv[fv.index(x, y, z)]);
}

// nested view of all of a
std::cout << std::endl << "3D nested view" << std::endl;
zfp::array3<double>::nested_view nv(&a);
filter_output(nv.size_x() + 2, 3, nv.size());
for (size_t z = 0; z < nv.size_z(); z++)
for (size_t y = 0; y < nv.size_y(); y++)
for (size_t x = 0; x < nv.size_x(); x++) {
std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << nv[z][y][x] << std::endl;
if (filter_output())
std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << nv[z][y][x] << std::endl;
verify(a(x, y, z), nv[z][y][x]);
}

Expand All @@ -130,12 +161,13 @@ int main(int argc, char* argv[])
zfp::array3<double>::view::const_reference vr = v(0, 0, 0);
zfp::array3<double>::view::const_pointer p = &vr;
p = &v(0, 0, 0);
filter_output(v.size_x() + 2, 3, v.size());
for (zfp::array3<double>::view::const_iterator it = v.begin(); it != v.end(); it++) {
size_t x = it.i();
size_t y = it.j();
size_t z = it.k();
std::cout << x << " " << y << " " << z << std::endl;
std::cout << mx << " " << my << " " << std::endl;
if (filter_output())
std::cout << x << " " << y << " " << z << ": " << *it << " " << p[x + mx * (y + my * z)] << std::endl;
verify(*it, p[x + mx * (y + my * z)]);
}

Expand All @@ -144,29 +176,36 @@ std::cout << mx << " " << my << " " << std::endl;
zfp::array3<double>::flat_view::const_reference fvr = fv[0];
zfp::array3<double>::flat_view::const_pointer fp = &fvr;
fp = &fv(0, 0, 0);
filter_output(fv.size_x() + 2, 3, fv.size());
for (zfp::array3<double>::flat_view::const_iterator it = fv.begin(); it != fv.end(); it++) {
size_t x = it.i();
size_t y = it.j();
size_t z = it.k();
if (filter_output())
std::cout << x << " " << y << " " << z << ": " << *it << " " << fp[x + nx * (y + ny * z)] << std::endl;
verify(*it, fp[x + nx * (y + ny * z)]);
}

// 2D slice of a
std::cout << std::endl << "2D slice" << std::endl;
size_t z = rand(0, nv.size_z() - 1);
zfp::array3<double>::nested_view2 slice2(nv[z]);
filter_output(slice2.size_x() + 2, 3, slice2.size());
for (size_t y = 0; y < slice2.size_y(); y++)
for (size_t x = 0; x < slice2.size_x(); x++) {
std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << slice2[y][x] << std::endl;
if (filter_output())
std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << slice2[y][x] << std::endl;
verify(a(x, y, z), slice2[y][x]);
}

// 2D array constructed from 2D slice (exercises deep copy via iterator)
std::cout << std::endl << "2D array from 2D slice" << std::endl;
zfp::array2<double> b(slice2);
filter_output(b.size_x() + 2, 3, b.size());
for (size_t y = 0; y < b.size_y(); y++)
for (size_t x = 0; x < b.size_x(); x++) {
std::cout << x << " " << y << ": " << b(x, y) << " " << slice2[y][x] << std::endl;
if (filter_output())
std::cout << x << " " << y << ": " << b(x, y) << " " << slice2[y][x] << std::endl;
verify(b(x, y), slice2[y][x]);
}

Expand All @@ -182,18 +221,22 @@ std::cout << mx << " " << my << " " << std::endl;
// 2D array constructed from 2D slice of 3D array (exercises deep copy via iterator)
std::cout << std::endl << "2D array from 2D slice of 3D array" << std::endl;
zfp::array2<double> c(slice2);
filter_output(c.size_x() + 2, 3, c.size());
for (size_t y = 0; y < c.size_y(); y++)
for (size_t x = 0; x < c.size_x(); x++) {
std::cout << x << " " << y << ": " << c(x, y) << " " << slice2[y][x] << std::endl;
if (filter_output())
std::cout << x << " " << y << ": " << c(x, y) << " " << slice2[y][x] << std::endl;
verify(c(x, y), slice2[y][x]);
}

// 2D thread-safe read-only view of c
std::cout << std::endl << "2D private read-only view" << std::endl;
zfp::array2<double>::private_const_view d(&c);
filter_output(c.size_x() + 2, 3, c.size());
for (size_t y = 0; y < c.size_y(); y++)
for (size_t x = 0; x < c.size_x(); x++) {
std::cout << x << " " << y << ": " << c(x, y) << " " << d(x, y) << std::endl;
if (filter_output())
std::cout << x << " " << y << ": " << c(x, y) << " " << d(x, y) << std::endl;
verify(c(x, y), d(x, y));
}

Expand All @@ -206,10 +249,12 @@ std::cout << mx << " " << my << " " << std::endl;
{
// make a thread-local view into c
zfp::array2<double>::private_const_view d(&c);
if (omp_get_thread_num() == 0)
filter_output(d.size_x() + 2, 3, d.size());
for (size_t y = 0; y < d.size_y(); y++)
for (size_t x = 0; x < d.size_x(); x++) {
double val = data[x + nx * y];
if (omp_get_thread_num() == 0)
if (omp_get_thread_num() == 0 && filter_output())
std::cout << x << " " << y << ": " << val << " " << d(x, y) << std::endl;
verify(val, d(x, y));
}
Expand All @@ -221,13 +266,15 @@ std::cout << mx << " " << my << " " << std::endl;
// partition c into disjoint views
zfp::array2<double>::private_view d(&c);
d.partition(omp_get_thread_num(), omp_get_num_threads());
if (omp_get_thread_num() == 0)
filter_output(d.size_x() + 2, 3, d.size());
for (size_t j = 0; j < d.size_y(); j++)
for (size_t i = 0; i < d.size_x(); i++) {
d(i, j) += 1;
size_t x = d.global_x(i);
size_t y = d.global_y(j);
double val = data[x + nx * y] + 1;
if (omp_get_thread_num() == 0)
if (omp_get_thread_num() == 0 && filter_output())
std::cout << x << " " << y << ": " << val << " " << d(i, j) << std::endl;
verify(val, d(i, j));
}
Expand Down

0 comments on commit b621b47

Please sign in to comment.