27 #ifndef MLN_SET_COMPUTE_WITH_WEIGHTS_HH
28 # define MLN_SET_COMPUTE_WITH_WEIGHTS_HH
36 # include <mln/core/concept/meta_accumulator.hh>
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/concept/site_set.hh>
39 # include <mln/util/array.hh>
40 # include <mln/convert/from_to.hh>
41 # include <mln/value/next.hh>
56 template <
typename A,
typename I>
70 template <typename A, typename I, typename L>
71 util::array<mln_result(A)>
74 const Image<L>& label,
75 const mln_value(L)& nlabels);
84 template <typename A, typename I>
85 mln_meta_accu_result(A, mln_site(I))
90 # ifndef MLN_INCLUDE_ONLY
99 template <
typename A,
typename I,
typename L>
101 compute_with_weights_tests(
const Accumulator<A>& a_,
103 const Image<L>& label_)
105 const A& a =
exact(a_);
106 const I& w =
exact(w_);
107 const L& label =
exact(label_);
109 mln_precondition(w.is_valid());
110 mln_precondition(label.is_valid());
111 mln_precondition(w.domain() <= label.domain());
139 template <
typename A,
typename I>
144 mln_trace(
"set::impl::generic::compute_with_weights");
146 mlc_converts_to(mln_site(I), mln_argument(A))::check();
147 mlc_converts_to(mln_value(I),
unsigned)::check();
150 const I& w =
exact(w_);
153 mln_piter(I)
p(w.domain());
155 a.take_n_times(w(
p), p);
157 return a.to_result();
172 template <typename A, typename I, typename L>
173 util::array<mln_result(A)>
176 const Image<L>& label_,
177 const mln_value(L)& nlabels)
179 mln_trace(
"set::impl::generic::compute_with_weights");
181 mlc_equal(mln_site(I), mln_site(L))::check();
182 mlc_converts_to(mln_site(I), mln_argument(A))::check();
183 mlc_converts_to(mln_value(I),
unsigned)::check();
186 const I& w =
exact(w_);
187 const L& label =
exact(label_);
189 internal::compute_with_weights_tests(a, w, label);
193 mln_piter(I) p(w.domain());
195 accus[label(p)].take_n_times(w(p), p);
197 util::array<mln_result(A)> r;
212 template <typename A, typename I>
217 mln_trace(
"set::compute_with_weights");
219 mlc_converts_to(mln_site(I), mln_argument(A))::check();
220 mlc_converts_to(mln_value(I),
unsigned)::check();
221 mln_precondition(
exact(w).is_valid());
229 template <typename A, typename I, typename L>
230 util::array<mln_result(A)>
233 const Image<L>& label,
234 const mln_value(L)& nlabels)
236 mln_trace(
"set::compute_with_weights");
238 mlc_equal(mln_site(I), mln_site(L))::check();
239 mlc_converts_to(mln_site(I), mln_argument(A))::check();
240 mlc_converts_to(mln_value(I),
unsigned)::check();
242 internal::compute_with_weights_tests(a, w, label);
244 util::array<mln_result(A)> r;
251 template <
typename A,
typename I>
253 mln_meta_accu_result(A, mln_site(I))
256 mln_trace(
"set::compute_with_weights");
258 mlc_converts_to(mln_value(I),
unsigned)::check();
260 mln_precondition(
exact(w).is_valid());
262 typedef mln_site(I) P;
263 typedef mln_accu_with(A, P) A_;
264 A_ a_ = accu::unmeta(
exact(a), P());
271 # endif // ! MLN_INCLUDE_ONLY
278 #endif // ! MLN_SET_COMPUTE_WITH_WEIGHTS_HH