From 98c5c37bb3fd9c58b98c38d601b8beffa85c205f Mon Sep 17 00:00:00 2001 From: Tom de Geus Date: Wed, 6 Dec 2023 16:23:26 +0100 Subject: [PATCH] Discontinuing C++ example: rounding in C++/Python may differ slightly. Please add helper function if needed --- docs/examples/W2c.cpp | 74 ------------------------------------------- docs/theory_W2.rst | 7 ---- 2 files changed, 81 deletions(-) delete mode 100644 docs/examples/W2c.cpp diff --git a/docs/examples/W2c.cpp b/docs/examples/W2c.cpp deleted file mode 100644 index f56edcc1..00000000 --- a/docs/examples/W2c.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include - -#define MYASSERT(expr) MYASSERT_IMPL(expr, __FILE__, __LINE__) -#define MYASSERT_IMPL(expr, file, line) \ - if (!(expr)) { \ - throw std::runtime_error( \ - std::string(file) + ':' + std::to_string(line) + \ - ": assertion failed (" #expr ") \n\t"); \ - } - -int main() -{ - // square grid of circles - size_t N = 15; - size_t M = 500; - auto row = xt::linspace(0, M, N); - auto col = xt::linspace(0, M, N); - xt::xarray rowmat; - xt::xarray colmat; - std::tie(rowmat, colmat) = xt::meshgrid(row, col); - rowmat = xt::ravel(rowmat); - colmat = xt::ravel(colmat); - xt::xtensor r = (double)(M) / (double)(N) / 4.0 * xt::ones({N * N}); - - // random perturbation - prrng::pcg32 rng(0); - rowmat += rng.normal({N * N}, 0.0, (double)(M) / (double)(N)); - colmat += rng.normal({N * N}, 0.0, (double)(M) / (double)(N)); - auto dr = rng.random({N * N}) * 2.0 + 0.1; - r = r * dr; - - // generate image - auto I = GooseEYE::dummy_circles({M, M}, xt::round(rowmat), xt::round(colmat), xt::round(r)); - - // create 'damage' -> right of inclusion - colmat += 1.1 * r; - r *= 0.4; - auto W = GooseEYE::dummy_circles({M, M}, xt::round(rowmat), xt::round(colmat), xt::round(r)); - W = xt::where(xt::equal(I, 1), 0, W); - - // compute individual damage clusters and their centers - auto labels = GooseEYE::clusters(W); - auto names = xt::unique(labels); - auto cpos = GooseEYE::labels_centers(labels, names); - auto centers = xt::zeros_like(labels); - int m = static_cast(labels.shape(0)); - int n = static_cast(labels.shape(1)); - for (size_t i = 0; i < names.size(); ++i) { - auto row = (int)round(cpos(i, 0)); - auto col = (int)round(cpos(i, 1)); - row = row < 0 ? 0 : (row >= m ? m - 1 : row); - col = col < 0 ? 0 : (col >= n ? n - 1 : col); - centers(row, col) = names(i); - } - - // weighted correlation - auto WI = GooseEYE::W2({101, 101}, W, I, W); - - // collapsed weighted correlation - auto WIc = GooseEYE::W2c({101, 101}, labels, centers, I, W); - - // check against previous versions - H5Easy::File data("W2c.h5", H5Easy::File::ReadOnly); - MYASSERT(xt::all(xt::equal(I, H5Easy::load(data, "I")))); - MYASSERT(xt::all(xt::equal(labels, H5Easy::load(data, "labels")))); - MYASSERT(xt::all(xt::equal(centers, H5Easy::load(data, "centers")))); - MYASSERT(xt::all(xt::equal(W, H5Easy::load(data, "W")))); - MYASSERT(xt::allclose(WI, H5Easy::load(data, "WI"))); - MYASSERT(xt::allclose(WIc, H5Easy::load(data, "WIc"))); - - return 0; -} diff --git a/docs/theory_W2.rst b/docs/theory_W2.rst index 32e439f7..75a516c8 100644 --- a/docs/theory_W2.rst +++ b/docs/theory_W2.rst @@ -154,7 +154,6 @@ Example ^^^^^^^ | :download:`W2c.py ` -| :download:`W2c.cpp ` .. image:: examples/W2c.svg :width: 700px @@ -173,9 +172,3 @@ Python :language: python :start-after: :end-before: - -C++ -^^^ - -.. literalinclude:: examples/W2c.cpp - :language: cpp