Commit 125d1978 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Fix rows(...) to take only non-temporaries and fix algoithms.

parent 74c8b8cd
...@@ -66,7 +66,8 @@ namespace mln ...@@ -66,7 +66,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>()); static_assert(mln::is_a<InputImage, Image>());
auto a = accu::make_accumulator(exact(accu), image_value_t<InputImage>()); auto a = accu::make_accumulator(exact(accu), image_value_t<InputImage>());
for (auto row : mln::ranges::rows(input.new_values())) auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row) for (auto&& v : row)
a.take(v); a.take(v);
return ex(a); return ex(a);
...@@ -78,7 +79,8 @@ namespace mln ...@@ -78,7 +79,8 @@ namespace mln
{ {
static_assert(mln::is_a<InputImage, Image>()); static_assert(mln::is_a<InputImage, Image>());
for (auto row : mln::ranges::rows(input.new_values())) auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row) for (auto&& v : row)
init = op(init, v); init = op(init, v);
......
...@@ -29,7 +29,8 @@ namespace mln ...@@ -29,7 +29,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>()); static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>()); static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
for (auto r : ranges::rows(input.new_values())) auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (::ranges::any_of(r, p)) if (::ranges::any_of(r, p))
return true; return true;
return false; return false;
...@@ -41,7 +42,8 @@ namespace mln ...@@ -41,7 +42,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>()); static_assert(mln::is_a<InputImage, Image>());
static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>); static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);
for (auto r : ranges::rows(input.new_values())) auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
for (auto&& v : r) for (auto&& v : r)
if (v) if (v)
return true; return true;
......
...@@ -113,10 +113,10 @@ namespace mln ...@@ -113,10 +113,10 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>()); static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<image_value_t<InputImage>, image_value_t<OutputImage>>); static_assert(std::is_convertible_v<image_value_t<InputImage>, image_value_t<OutputImage>>);
auto input_rows = ranges::rows(input.new_values()); auto&& ivals = input.new_values();
auto output_rows = ranges::rows(output.new_values()); auto&& ovals = output.new_values();
for (auto [r1, r2] : ranges::view::zip(input_rows, output_rows)) for (auto [r1, r2] : ranges::view::zip(ranges::rows(ivals), ranges::rows(ovals)))
::ranges::copy(r1, ::ranges::begin(r2)); ::ranges::copy(r1, ::ranges::begin(r2));
} }
} // namespace experimental } // namespace experimental
......
...@@ -29,7 +29,8 @@ namespace mln ...@@ -29,7 +29,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>()); static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Invocable<UnaryFunction, image_reference_t<InputImage>>()); static_assert(::ranges::Invocable<UnaryFunction, image_reference_t<InputImage>>());
for (auto r : ranges::rows(input.new_values())) auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
::ranges::for_each(r, f); ::ranges::for_each(r, f);
} }
} // namespace experimental } // namespace experimental
......
...@@ -23,7 +23,8 @@ namespace mln ...@@ -23,7 +23,8 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>()); static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<std::invoke_result_t<Generator>, image_value_t<OutputImage>>); static_assert(std::is_convertible_v<std::invoke_result_t<Generator>, image_value_t<OutputImage>>);
for (auto row : mln::ranges::rows(output.new_values())) auto&& vals = output.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto& v : row) for (auto& v : row)
v = g(); v = g();
} }
......
...@@ -73,7 +73,8 @@ namespace mln ...@@ -73,7 +73,8 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>()); static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<Value, image_value_t<OutputImage>>); static_assert(std::is_convertible_v<Value, image_value_t<OutputImage>>);
for (auto row : mln::ranges::rows(output.new_values())) auto&& vals = output.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto& v : row) for (auto& v : row)
v = val++; v = val++;
} }
......
...@@ -29,7 +29,8 @@ namespace mln ...@@ -29,7 +29,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>()); static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>()); static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
for (auto r : ranges::rows(input.new_values())) auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (!::ranges::none_of(r, p)) if (!::ranges::none_of(r, p))
return false; return false;
return true; return true;
...@@ -41,7 +42,8 @@ namespace mln ...@@ -41,7 +42,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>()); static_assert(mln::is_a<InputImage, Image>());
static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>); static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);
for (auto r : ranges::rows(input.new_values())) auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
for (auto&& v : r) for (auto&& v : r)
if (v) if (v)
return false; return false;
......
...@@ -82,10 +82,9 @@ namespace mln ...@@ -82,10 +82,9 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>()); static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<image_value_t<InputImage>, image_value_t<OutputImage>>); static_assert(std::is_convertible_v<image_value_t<InputImage>, image_value_t<OutputImage>>);
auto input_rows = ranges::rows(src.new_pixels()); auto&& pixels = src.new_pixels();
for (auto row : ranges::rows(pixels))
for (auto r : input_rows) for (auto px : row)
for (auto px : r)
dest(px.point()) = px.val(); dest(px.point()) = px.val();
} }
......
...@@ -122,9 +122,9 @@ namespace mln ...@@ -122,9 +122,9 @@ namespace mln
mln_entering("mln::experimental::transform"); mln_entering("mln::experimental::transform");
mln_precondition(in.domain() == out.domain()); mln_precondition(in.domain() == out.domain());
auto input_rows = ranges::rows(in.new_values()); auto&& ivals = in.new_values();
auto output_rows = ranges::rows(out.new_values()); auto&& ovals = out.new_values();
for (auto [r1, r2] : ranges::view::zip(input_rows, output_rows)) for (auto [r1, r2] : ranges::view::zip(ranges::rows(ivals), ranges::rows(ovals)))
::ranges::transform(r1, ::ranges::begin(r2), f); ::ranges::transform(r1, ::ranges::begin(r2), f);
} }
......
...@@ -15,6 +15,7 @@ namespace mln::ranges ...@@ -15,6 +15,7 @@ namespace mln::ranges
template <class R, typename = std::enable_if_t<is_segmented_range_v<std::remove_reference_t<R>>>> template <class R, typename = std::enable_if_t<is_segmented_range_v<std::remove_reference_t<R>>>>
decltype(auto) rows(R&& rng) // decltype for perfect forwarding decltype(auto) rows(R&& rng) // decltype for perfect forwarding
{ {
static_assert(std::is_lvalue_reference<R>(), "Cannot apply on a temporary range.");
return rng.rows(); return rng.rows();
} }
......
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