Commit 05161d95 authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Merge remote-tracking branch 'origin/development/filter_view' into development/sanitizer

parents 724c10c6 5879495a
Pipeline #12914 failed with stages
in 10 minutes and 51 seconds
......@@ -19,7 +19,6 @@ add_core_test(${test_prefix}range_zip range/zip.cpp)
# test Views
add_core_test(${test_prefix}view_adaptor image/view/adaptor.cpp)
add_core_test(${test_prefix}view_transform image/view/transform.cpp)
# FIXME: segfault
add_core_test(${test_prefix}view_filter image/view/filter.cpp)
add_core_test(${test_prefix}view_clip image/view/clip.cpp)
add_core_test(${test_prefix}view_mask image/view/mask.cpp)
......
#include <mln/core/algorithm/fill.hpp>
#include <helpers.hpp>
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/fill.hpp>
#include <mln/core/concept/new/archetype/image.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/image/view/clip.hpp>
#include <mln/core/concept/new/archetype/image.hpp>
#include <helpers.hpp>
#include <gtest/gtest.h>
......@@ -36,6 +36,14 @@ TEST(View, clip)
auto clipped = mln::view::clip(ima, domain);
fill(clipped, 42);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(clipped)>);
static_assert(concepts::ViewImage<decltype(clipped)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(clipped)>);
static_assert(not concepts::BidirectionalImage<decltype(clipped)>);
static_assert(not concepts::RawImage<decltype(clipped)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
for (auto p : clipped.domain())
{
ASSERT_EQ(42, ima(p));
......@@ -63,9 +71,26 @@ TEST(View, clip_twice)
auto A = mln::view::clip(ima, domain_a);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(A)>);
static_assert(concepts::ViewImage<decltype(A)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(A)>);
static_assert(not concepts::BidirectionalImage<decltype(A)>);
static_assert(not concepts::RawImage<decltype(A)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
auto B = mln::view::clip(A, domain_b);
fill(B, 42);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(B)>);
static_assert(concepts::ViewImage<decltype(B)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(B)>);
static_assert(not concepts::BidirectionalImage<decltype(B)>);
static_assert(not concepts::RawImage<decltype(B)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
for (auto p : B.domain())
{
ASSERT_EQ(42, ima(p));
......@@ -88,12 +113,21 @@ TEST(View, clip_other_a_box2d)
{5, 42, 42, 8, 9}, //
{10, 11, 12, 13, 14}};
mln::box2d domain = {{0,1}, {2,3}};
mln::box2d domain = {{0, 1}, {2, 3}};
// Clip returns an 'image2d'
mln::image2d<int> clipped = mln::view::clip(ima, domain);
fill(clipped, 42);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(clipped)>);
static_assert(not concepts::ViewImage<decltype(clipped)>);
static_assert(concepts::ConcreteImage<decltype(clipped)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(clipped)>);
static_assert(concepts::BidirectionalImage<decltype(clipped)>);
static_assert(concepts::RawImage<decltype(clipped)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
for (auto p : clipped.domain())
{
ASSERT_EQ(42, ima(p));
......@@ -104,9 +138,10 @@ TEST(View, clip_other_a_box2d)
}
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::AccessibleImage<mln::clip_view<mln::archetypes::AccessibleImage, mln::archetypes::Domain>>);
static_assert(mln::concepts::OutputImage<mln::clip_view<mln::archetypes::OutputAccessibleImage, mln::archetypes::Domain>>);
static_assert(mln::concepts::IndexableAndAccessibleImage<mln::clip_view<mln::archetypes::IndexableAndAccessibleImage, mln::archetypes::Domain>>);
#endif // PYLENE_CONCEPT_TS_ENABLED
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::AccessibleImage<mln::clip_view<mln::archetypes::AccessibleImage, mln::archetypes::Domain>>), "");
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::OutputImage<mln::clip_view<mln::archetypes::OutputAccessibleImage, mln::archetypes::Domain>>), "");
PYLENE_CONCEPT_TS_ASSERT((mln::concepts::IndexableAndAccessibleImage<
mln::clip_view<mln::archetypes::IndexableAndAccessibleImage, mln::archetypes::Domain>>),
"");
......@@ -9,6 +9,8 @@
#include <mln/core/rangev3/foreach.hpp>
#include <mln/core/rangev3/view/zip.hpp>
#include <mln/core/concept/new/concepts.hpp>
#include <helpers.hpp>
#include <gtest/gtest.h>
......@@ -24,6 +26,16 @@ TEST(View, filter_readonly)
mln::experimental::iota(ima, 0);
auto x = mln::view::filter(ima, [](int v) { return v > 10; });
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(x)>);
static_assert(concepts::Image<decltype(x)>);
static_assert(concepts::ViewImage<decltype(x)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(x)>);
static_assert(concepts::BidirectionalImage<decltype(x)>);
static_assert(not concepts::RawImage<decltype(x)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
ASSERT_TRUE(mln::experimental::all_of(x > 10));
mln_foreach_new (auto&& pix, ima.new_pixels())
......@@ -50,6 +62,15 @@ TEST(View, filter_writable)
mln::experimental::iota(ima, 0);
auto x = mln::view::filter(ima, [](int v) { return v > 10; });
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(x)>);
static_assert(concepts::ViewImage<decltype(x)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(x)>);
static_assert(concepts::BidirectionalImage<decltype(x)>);
static_assert(not concepts::RawImage<decltype(x)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
mln::experimental::fill(x, 10);
ASSERT_TRUE(mln::experimental::all_of(ima <= 10));
}
......@@ -63,27 +84,34 @@ TEST(View, filter_twice)
mln::image2d<int> ima(dom);
mln::experimental::iota(ima, 0);
auto u = mln::view::filter(ima, [](int v) { return v > 10 && v < 15; });
// FIXME:
// auto x = view::filter(ima, [](int v) { return v > 10; });
// auto u = view::filter(x, [](int v) { return v < 15; });
auto x = mln::view::filter(ima, [](int v) { return v > 10; });
auto u = mln::view::filter(x, [](int v) { return v < 15; });
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(u)>);
static_assert(concepts::ViewImage<decltype(u)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(u)>);
static_assert(concepts::BidirectionalImage<decltype(u)>);
static_assert(not concepts::RawImage<decltype(u)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
// FIXME:
// ASSERT_TRUE(mln::experimental::all(land(u > 10, u < 15)));
ASSERT_TRUE(mln::experimental::all_of(land(u > 10, u < 15)));
mln_foreach_new (auto&& pix, ima.new_pixels())
{
if (pix.val() > 10 and pix.val() < 15)
{
ASSERT_EQ(pix.val(), u(pix.point()));
ASSERT_TRUE(u.domain().has(pix.point()));
}
else
{
ASSERT_EQ(pix.val(), u.at(pix.point()));
// FIXME:
// ASSERT_TRUE(!u.domain().has(pix.point()));
ASSERT_FALSE(u.domain().has(pix.point()));
}
}
{
mln_foreach_new (auto&& pix, u.new_pixels())
ASSERT_EQ(pix.val(), ima(pix.point()));
......@@ -104,3 +132,22 @@ TEST(View, filter_twice)
mln_foreach_new (auto&& px, u.new_pixels())
ASSERT_EQ(px.val(), ima(px.point()));
}
struct archetype_pred_t
{
template <typename T>
bool operator()(T&&) const;
};
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::AccessibleImage<mln::filter_view<mln::archetypes::AccessibleImage, archetype_pred_t>>), "");
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::IndexableImage<mln::filter_view<mln::archetypes::IndexableAndAccessibleImage, archetype_pred_t>>),
"");
PYLENE_CONCEPT_TS_ASSERT((mln::concepts::IndexableAndAccessibleImage<
mln::filter_view<mln::archetypes::IndexableAndAccessibleImage, archetype_pred_t>>),
"");
PYLENE_CONCEPT_TS_ASSERT((mln::concepts::OutputImage<
mln::filter_view<mln::archetypes::OutputIndexableAndAccessibleImage, archetype_pred_t>>),
"");
......@@ -31,6 +31,14 @@ TEST(View, mask)
auto z = mln::view::mask(ima, mask);
fill(z, 42);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(z)>);
static_assert(concepts::ViewImage<decltype(z)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(z)>);
static_assert(not concepts::BidirectionalImage<decltype(z)>);
static_assert(not concepts::RawImage<decltype(z)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
for (auto p : z.domain())
{
ASSERT_EQ(42, ima(p));
......@@ -56,10 +64,26 @@ TEST(View, mask_twice)
auto mask_A = (ima % 2) == 1;
auto A = mln::view::mask(ima, mask_A);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(A)>);
static_assert(concepts::ViewImage<decltype(A)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(A)>);
static_assert(not concepts::BidirectionalImage<decltype(A)>);
static_assert(not concepts::RawImage<decltype(A)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
auto mask_B = (A % 4) == 1;
auto B = mln::view::mask(A, mask_B);
fill(B, 42);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(B)>);
static_assert(concepts::ViewImage<decltype(B)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(B)>);
static_assert(not concepts::BidirectionalImage<decltype(B)>);
static_assert(not concepts::RawImage<decltype(B)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
for (auto p : B.domain())
{
ASSERT_EQ(42, ima(p));
......@@ -70,19 +94,18 @@ TEST(View, mask_twice)
}
struct mask_archetype : mln::experimental::Image<mask_archetype>
{
using value_type = bool;
using reference = const bool&;
using domain_type = mln::archetypes::Domain;
using point_type = ::ranges::range_value_t<domain_type>;
using category_type = mln::forward_image_tag;
using concrete_type = mask_archetype;
using value_type = bool;
using reference = const bool&;
using domain_type = mln::archetypes::Domain;
using point_type = ::ranges::range_value_t<domain_type>;
using category_type = mln::forward_image_tag;
using concrete_type = mask_archetype;
struct new_pixel_type
{
bool val() const;
bool val() const;
point_type point() const;
};
......@@ -96,11 +119,11 @@ struct mask_archetype : mln::experimental::Image<mask_archetype>
using view = std::false_type;
domain_type domain() const;
reference operator()(point_type);
reference at(point_type);
new_pixel_type new_pixel(point_type);
new_pixel_type new_pixel_at(point_type);
domain_type domain() const;
reference operator()(point_type);
reference at(point_type);
new_pixel_type new_pixel(point_type);
new_pixel_type new_pixel_at(point_type);
struct pixel_range
{
......@@ -120,12 +143,18 @@ struct mask_archetype : mln::experimental::Image<mask_archetype>
};
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::AccessibleImage<mln::mask_view<mln::archetypes::AccessibleImage, mask_archetype>>);
static_assert(mln::concepts::IndexableImage<mln::mask_view<mln::archetypes::IndexableImage, mask_archetype>>);
static_assert(mln::concepts::IndexableAndAccessibleImage<mln::mask_view<mln::archetypes::IndexableAndAccessibleImage, mask_archetype>>);
static_assert(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputAccessibleImage, mask_archetype>>);
static_assert(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputIndexableImage, mask_archetype>>);
static_assert(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputIndexableAndAccessibleImage, mask_archetype>>);
#endif
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::AccessibleImage<mln::mask_view<mln::archetypes::AccessibleImage, mask_archetype>>), "");
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::IndexableImage<mln::mask_view<mln::archetypes::IndexableImage, mask_archetype>>), "");
PYLENE_CONCEPT_TS_ASSERT((mln::concepts::IndexableAndAccessibleImage<
mln::mask_view<mln::archetypes::IndexableAndAccessibleImage, mask_archetype>>),
"");
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputAccessibleImage, mask_archetype>>), "");
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputIndexableImage, mask_archetype>>), "");
PYLENE_CONCEPT_TS_ASSERT(
(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputIndexableAndAccessibleImage, mask_archetype>>),
"");
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment