@@ -853,6 +853,74 @@ namespace dynamicgraph {
853
853
};
854
854
REGISTER_BINARY_OP ( ConvolutionTemporal,ConvolutionTemporal );
855
855
856
+ /* --- BOOLEAN REDUCTION ------------------------------------------------ */
857
+
858
+ template < typename T > struct Comparison
859
+ : public BinaryOpHeader <T, T, bool >
860
+ {
861
+ void operator ()( const T& a,const T& b, bool & res ) const
862
+ {
863
+ res = ( a < b);
864
+ }
865
+ virtual std::string getDocString () const
866
+ {
867
+ typedef BinaryOpHeader<T,T,bool > Base;
868
+ return std::string
869
+ (" Comparison of inputs:\n "
870
+ " - input " ) + Base::nameTypeIn1 () +
871
+ std::string (" \n "
872
+ " - " ) + Base::nameTypeIn2 () +
873
+ std::string (" \n "
874
+ " - output " ) + Base::nameTypeOut () +
875
+ std::string (" \n " " sout = ( sin1 < sin2 )\n " );
876
+ }
877
+ };
878
+
879
+ template < typename T1, typename T2 = T1 > struct MatrixComparison
880
+ : public BinaryOpHeader <T1, T2, bool >
881
+ {
882
+ // TODO T1 or T2 could be a scalar type.
883
+ typedef Eigen::Array<bool , T1::RowsAtCompileTime, T1::ColsAtCompileTime> Array;
884
+ void operator ()( const T1& a,const T2& b, bool & res ) const
885
+ {
886
+ Array r;
887
+ if (equal) r = (a.array () <= b.array ());
888
+ else r = (a.array () < b.array ());
889
+ if (any) res = r.any ();
890
+ else res = r.all ();
891
+ }
892
+ virtual std::string getDocString () const
893
+ {
894
+ typedef BinaryOpHeader<T1,T2,bool > Base;
895
+ return std::string
896
+ (" Comparison of inputs:\n "
897
+ " - input " ) + Base::nameTypeIn1 () +
898
+ std::string (" \n "
899
+ " - " ) + Base::nameTypeIn2 () +
900
+ std::string (" \n "
901
+ " - output " ) + Base::nameTypeOut () +
902
+ std::string (" \n " " sout = ( sin1 < sin2 ).op()\n " ) +
903
+ std::string (" \n " " where op is either any (default) or all. The comparison can be made <=.\n " );
904
+ }
905
+ MatrixComparison () : any (true ), equal (false ) {}
906
+ void addSpecificCommands (Entity& ent,
907
+ Entity::CommandMap_t& commandMap)
908
+ {
909
+ using namespace dynamicgraph ::command;
910
+ ADD_COMMAND ( " setTrueIfAny" ,
911
+ makeDirectSetter (ent,&any,docDirectSetter (" trueIfAny" ," bool" )));
912
+ ADD_COMMAND ( " getTrueIfAny" ,
913
+ makeDirectGetter (ent,&any,docDirectGetter (" trueIfAny" ," bool" )));
914
+ ADD_COMMAND ( " setEqual" ,
915
+ makeDirectSetter (ent,&equal,docDirectSetter (" equal" ," bool" )));
916
+ ADD_COMMAND ( " getEqual" ,
917
+ makeDirectGetter (ent,&equal,docDirectGetter (" equal" ," bool" )));
918
+ }
919
+ bool any, equal;
920
+ };
921
+
922
+ REGISTER_BINARY_OP (Comparison<double >, CompareDouble);
923
+ REGISTER_BINARY_OP (MatrixComparison<Vector>, CompareVector);
856
924
} /* namespace sot */ } /* namespace dynamicgraph */
857
925
858
926
0 commit comments