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>
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 trace::entering(
"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);
158 return a.to_result();
173 template <typename A, typename I, typename L>
174 util::array<mln_result(A)>
175 compute_with_weights(const Accumulator<A>& a_,
177 const Image<L>& label_,
178 const mln_value(L)& nlabels)
180 trace::entering(
"set::impl::generic::compute_with_weights");
182 mlc_equal(mln_site(I), mln_site(L))::check();
183 mlc_converts_to(mln_site(I), mln_argument(A))::check();
184 mlc_converts_to(mln_value(I),
unsigned)::check();
187 const I& w = exact(w_);
188 const L& label = exact(label_);
190 internal::compute_with_weights_tests(a, w, label);
192 util::array<A> accus(value::next(nlabels), a);
194 mln_piter(I) p(w.domain());
196 accus[label(p)].take_n_times(w(p), p);
198 util::array<mln_result(A)> r;
199 convert::from_to(accus, r);
201 trace::exiting("set::impl::generic::compute_with_weights");
214 template <typename A, typename I>
219 trace::entering(
"set::compute_with_weights");
221 mlc_converts_to(mln_site(I), mln_argument(A))::check();
222 mlc_converts_to(mln_value(I),
unsigned)::check();
223 mln_precondition(exact(w).is_valid());
225 mln_result(A) r = impl::generic::compute_with_weights(a, w);
227 trace::exiting(
"set::compute_with_weights");
232 template <
typename A,
typename I,
typename L>
237 const mln_value(L)& nlabels)
239 trace::entering(
"set::compute_with_weights");
241 mlc_equal(mln_site(I), mln_site(L))::check();
242 mlc_converts_to(mln_site(I), mln_argument(A))::check();
243 mlc_converts_to(mln_value(I),
unsigned)::check();
245 internal::compute_with_weights_tests(a, w, label);
248 r = impl::generic::compute_with_weights(a, w, label, nlabels);
250 trace::exiting(
"set::compute_with_weights");
255 template <
typename A,
typename I>
260 trace::entering(
"set::compute_with_weights");
262 mlc_converts_to(mln_value(I),
unsigned)::check();
264 mln_precondition(exact(w).is_valid());
266 typedef mln_site(I) P;
267 typedef mln_accu_with(A, P) A_;
268 A_ a_ = accu::unmeta(exact(a), P());
270 mln_result(A_) r = impl::generic::compute_with_weights(a_, w);
272 trace::exiting("
set::compute_with_weights");
276 # endif // ! MLN_INCLUDE_ONLY
283 #endif // ! MLN_SET_COMPUTE_WITH_WEIGHTS_HH