26 #ifndef MLN_ARITH_DIV_HH
27 # define MLN_ARITH_DIV_HH
35 # include <mln/arith/includes.hh>
38 # include <mln/arith/div.spe.hh>
48 template <
typename L,
typename R>
49 struct set_binary_< op::
div, Image, L, Image, R >
51 typedef mln_trait_op_div(mln_value(L), mln_value(R)) value;
52 typedef mln_ch_value(L, value) ret;
55 template <typename I, typename S>
56 struct set_binary_< op::div, Image, I, mln::value::Scalar, S >
58 typedef mln_trait_op_div(mln_value(I), S) value;
59 typedef mln_ch_value(I, value) ret;
66 template <typename L, typename R>
68 operator/(const Image<L>& lhs, const Image<R>& rhs);
70 template <typename L, typename R>
72 operator/=(Image<L>& lhs, const Image<R>& rhs);
75 template <typename I, typename S>
77 operator/(const Image<I>& ima, const value::Scalar<S>& s);
79 template <typename I, typename S>
81 operator/=(Image<I>& ima, const value::Scalar<S>& s);
96 template <
typename L,
typename R,
typename O>
97 void div(
const Image<L>& lhs,
const Image<R>& rhs, Image<O>& output);
108 template <
typename I,
typename V,
typename O>
109 void div_cst(
const Image<I>& input,
const V& val, Image<O>& output);
123 template <
typename L,
typename R>
124 void div_inplace(Image<L>& lhs,
const Image<R>& rhs);
132 # ifndef MLN_INCLUDE_ONLY
135 template <
typename L,
typename R>
137 mln_trait_op_div(L,R)
138 operator/(const Image<L>& lhs, const Image<R>& rhs)
140 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
141 mln_trait_op_div(L,R) tmp;
143 arith::div(lhs, rhs, tmp);
147 template <typename L, typename R>
150 operator/=(Image<L>& lhs, const Image<R>& rhs)
152 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
158 template <
typename I,
typename S>
160 mln_trait_op_div(I,S)
161 operator/(const Image<I>& ima, const value::Scalar<S>& s)
163 mln_precondition(exact(ima).is_valid());
164 mln_precondition(s != 0);
165 mln_trait_op_div(I,S) tmp;
167 arith::div_cst(ima, exact(s), tmp);
171 template <typename I, typename S>
174 operator/=(Image<I>& ima, const value::Scalar<S>& s)
176 mln_precondition(exact(ima).is_valid());
192 template <
typename L,
typename R,
typename O>
194 void div_(
const L& lhs,
const R& rhs, O& output)
196 trace::entering(
"arith::impl::generic::div_");
198 mln_piter(L) p(lhs.domain());
200 output(p) = lhs(p) / rhs(p);
202 trace::exiting("arith::impl::generic::div_");
205 template <typename L, typename R>
207 void div_inplace_(L& lhs, const R& rhs)
209 trace::entering(
"arith::impl::generic::div_inplace_");
211 mln_piter(R) p(rhs.domain());
215 trace::exiting("arith::impl::generic::div_inplace_");
225 template <typename L, typename R, typename O>
227 void div(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
229 trace::entering(
"arith::div");
231 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
232 mln_precondition(exact(output).domain() == exact(lhs).domain());
233 impl::div_(mln_trait_image_speed(L)(), exact(lhs),
234 mln_trait_image_speed(R)(), exact(rhs),
235 mln_trait_image_speed(O)(), exact(output));
237 trace::exiting(
"arith::div");
240 template <
typename I,
typename V,
typename O>
244 trace::entering(
"arith::div_cst");
246 mln_precondition(exact(output).domain() == exact(input).domain());
247 div(input, pw::cst(val) | exact(input).domain(), output);
250 trace::exiting(
"arith::div_cst");
253 template <
typename L,
typename R>
257 trace::entering(
"arith::div_inplace");
259 mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
260 impl::div_inplace_(mln_trait_image_speed(L)(), exact(lhs),
261 mln_trait_image_speed(R)(), exact(rhs));
263 trace::exiting(
"arith::div_inplace");
266 template <
typename I,
typename V>
268 void div_cst_inplace(
Image<I>& input,
const V& val)
270 trace::entering(
"arith::div_cst_inplace");
272 mln_precondition(exact(input).is_valid());
273 div_inplace(input, pw::cst(val) | exact(input).domain());
276 trace::exiting(
"arith::div_cst_inplace");
281 # endif // ! MLN_INCLUDE_ONLY
286 #endif // ! MLN_ARITH_DIV_HH