@@ -353,6 +353,58 @@ namespace dlib
353353 return matrix_op<op>(op (a.ref (),b.ref ()));
354354 }
355355
356+ // ----------------------------------------------------------------------------------------
357+
358+ template <typename M1, typename M2, typename M3>
359+ struct op_min_pointwise3 : basic_op_mmm<M1,M2,M3>
360+ {
361+ op_min_pointwise3 ( const M1& m1_, const M2& m2_, const M3& m3_) :
362+ basic_op_mmm<M1,M2,M3>(m1_,m2_,m3_){}
363+
364+ typedef typename M1::type type;
365+ typedef const typename M1::type const_ret_type;
366+ const static long cost = M1::cost + M2::cost + M3::cost + 2 ;
367+
368+ const_ret_type apply (long r, long c) const
369+ { return std::min (this ->m1 (r,c),std::min (this ->m2 (r,c),this ->m3 (r,c))); }
370+ };
371+
372+ template <
373+ typename EXP1,
374+ typename EXP2,
375+ typename EXP3
376+ >
377+ inline const matrix_op<op_min_pointwise3<EXP1,EXP2,EXP3> >
378+ min_pointwise (
379+ const matrix_exp<EXP1>& a,
380+ const matrix_exp<EXP2>& b,
381+ const matrix_exp<EXP3>& c
382+ )
383+ {
384+ COMPILE_TIME_ASSERT ((is_same_type<typename EXP1::type,typename EXP2::type>::value == true ));
385+ COMPILE_TIME_ASSERT ((is_same_type<typename EXP2::type,typename EXP3::type>::value == true ));
386+ COMPILE_TIME_ASSERT (EXP1::NR == EXP2::NR || EXP1::NR == 0 || EXP2::NR == 0 );
387+ COMPILE_TIME_ASSERT (EXP1::NC == EXP2::NC || EXP1::NR == 0 || EXP2::NC == 0 );
388+ COMPILE_TIME_ASSERT (EXP2::NR == EXP3::NR || EXP2::NR == 0 || EXP3::NR == 0 );
389+ COMPILE_TIME_ASSERT (EXP2::NC == EXP3::NC || EXP2::NC == 0 || EXP3::NC == 0 );
390+ DLIB_ASSERT (a.nr () == b.nr () &&
391+ a.nc () == b.nc () &&
392+ b.nr () == c.nr () &&
393+ b.nc () == c.nc (),
394+ " \t const matrix_exp min_pointwise(a,b,c)"
395+ << " \n\t You can only make a do a pointwise min between equally sized matrices"
396+ << " \n\t a.nr(): " << a.nr ()
397+ << " \n\t a.nc(): " << a.nc ()
398+ << " \n\t b.nr(): " << b.nr ()
399+ << " \n\t b.nc(): " << b.nc ()
400+ << " \n\t c.nr(): " << c.nr ()
401+ << " \n\t c.nc(): " << c.nc ()
402+ );
403+
404+ typedef op_min_pointwise3<EXP1,EXP2,EXP3> op;
405+ return matrix_op<op>(op (a.ref (),b.ref (),c.ref ()));
406+ }
407+
356408// ----------------------------------------------------------------------------------------
357409
358410 template <typename M1, typename M2>
@@ -392,6 +444,58 @@ namespace dlib
392444 return matrix_op<op>(op (a.ref (),b.ref ()));
393445 }
394446
447+ // ----------------------------------------------------------------------------------------
448+
449+ template <typename M1, typename M2, typename M3>
450+ struct op_max_pointwise3 : basic_op_mmm<M1,M2,M3>
451+ {
452+ op_max_pointwise3 ( const M1& m1_, const M2& m2_, const M3& m3_) :
453+ basic_op_mmm<M1,M2,M3>(m1_,m2_,m3_){}
454+
455+ typedef typename M1::type type;
456+ typedef const typename M1::type const_ret_type;
457+ const static long cost = M1::cost + M2::cost + M3::cost + 2 ;
458+
459+ const_ret_type apply (long r, long c) const
460+ { return std::max (this ->m1 (r,c),std::max (this ->m2 (r,c),this ->m3 (r,c))); }
461+ };
462+
463+ template <
464+ typename EXP1,
465+ typename EXP2,
466+ typename EXP3
467+ >
468+ inline const matrix_op<op_max_pointwise3<EXP1,EXP2,EXP3> >
469+ max_pointwise (
470+ const matrix_exp<EXP1>& a,
471+ const matrix_exp<EXP2>& b,
472+ const matrix_exp<EXP3>& c
473+ )
474+ {
475+ COMPILE_TIME_ASSERT ((is_same_type<typename EXP1::type,typename EXP2::type>::value == true ));
476+ COMPILE_TIME_ASSERT ((is_same_type<typename EXP2::type,typename EXP3::type>::value == true ));
477+ COMPILE_TIME_ASSERT (EXP1::NR == EXP2::NR || EXP1::NR == 0 || EXP2::NR == 0 );
478+ COMPILE_TIME_ASSERT (EXP1::NC == EXP2::NC || EXP1::NR == 0 || EXP2::NC == 0 );
479+ COMPILE_TIME_ASSERT (EXP2::NR == EXP3::NR || EXP2::NR == 0 || EXP3::NR == 0 );
480+ COMPILE_TIME_ASSERT (EXP2::NC == EXP3::NC || EXP2::NC == 0 || EXP3::NC == 0 );
481+ DLIB_ASSERT (a.nr () == b.nr () &&
482+ a.nc () == b.nc () &&
483+ b.nr () == c.nr () &&
484+ b.nc () == c.nc (),
485+ " \t const matrix_exp max_pointwise(a,b,c)"
486+ << " \n\t You can only make a do a pointwise max between equally sized matrices"
487+ << " \n\t a.nr(): " << a.nr ()
488+ << " \n\t a.nc(): " << a.nc ()
489+ << " \n\t b.nr(): " << b.nr ()
490+ << " \n\t b.nc(): " << b.nc ()
491+ << " \n\t c.nr(): " << c.nr ()
492+ << " \n\t c.nc(): " << c.nc ()
493+ );
494+
495+ typedef op_max_pointwise3<EXP1,EXP2,EXP3> op;
496+ return matrix_op<op>(op (a.ref (),b.ref (),c.ref ()));
497+ }
498+
395499// ----------------------------------------------------------------------------------------
396500
397501 template <
0 commit comments