operator_relational.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup operator_relational
00017 //! @{
00018 
00019 
00020 
00021 template<typename eT, typename T1, typename T2>
00022 inline
00023 umat
00024 operator==
00025 (const Base<eT,T1>& X, const Base<eT,T2>& Y)
00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   const unwrap<T1> tmp1(X.get_ref());
00030   const unwrap<T2> tmp2(Y.get_ref());
00031   
00032   const Mat<eT>& A = tmp1.M;
00033   const Mat<eT>& B = tmp2.M;
00034     
00035   arma_debug_assert_same_size(A, B, "operator==");
00036   
00037   umat out(A.n_rows, A.n_cols);
00038   
00039   const eT* A_mem = A.mem;
00040   const eT* B_mem = B.mem;
00041   
00042   typedef typename umat::elem_type umat_elem_type;
00043   umat_elem_type* out_mem = out.memptr();
00044   
00045   
00046   for(u32 i=0; i<A.n_elem; ++i)
00047     {
00048     if(A_mem[i] == B_mem[i])
00049       {
00050       out_mem[i] = umat_elem_type(1);
00051       }
00052     else
00053       {
00054       out_mem[i] = umat_elem_type(0);
00055       }
00056     }
00057   
00058   return out;
00059   }
00060 
00061 
00062 
00063 template<typename eT, typename T1, typename T2>
00064 inline
00065 umat
00066 operator!=
00067 (const Base<eT,T1>& X, const Base<eT,T2>& Y)
00068   {
00069   arma_extra_debug_sigprint();
00070   
00071   const unwrap<T1> tmp1(X.get_ref());
00072   const unwrap<T2> tmp2(Y.get_ref());
00073   
00074   const Mat<eT>& A = tmp1.M;
00075   const Mat<eT>& B = tmp2.M;
00076     
00077   arma_debug_assert_same_size(A, B, "operator!=");
00078   
00079   umat out(A.n_rows, A.n_cols);
00080   
00081   const eT* A_mem = A.mem;
00082   const eT* B_mem = B.mem;
00083   
00084   typedef typename umat::elem_type umat_elem_type;
00085   umat_elem_type* out_mem = out.memptr();
00086   
00087   
00088   for(u32 i=0; i<A.n_elem; ++i)
00089     {
00090     if(A_mem[i] != B_mem[i])
00091       {
00092       out_mem[i] = umat_elem_type(1);
00093       }
00094     else
00095       {
00096       out_mem[i] = umat_elem_type(0);
00097       }
00098     }
00099   
00100   return out;
00101   }
00102 
00103 
00104 
00105 template<typename eT, typename T1, typename T2>
00106 inline
00107 umat
00108 operator>=
00109 (const Base<eT,T1>& X, const Base<eT,T2>& Y)
00110   {
00111   arma_extra_debug_sigprint();
00112   
00113   const unwrap<T1> tmp1(X.get_ref());
00114   const unwrap<T2> tmp2(Y.get_ref());
00115   
00116   const Mat<eT>& A = tmp1.M;
00117   const Mat<eT>& B = tmp2.M;
00118     
00119   arma_debug_assert_same_size(A, B, "operator>=");
00120   
00121   umat out(A.n_rows, A.n_cols);
00122   
00123   const eT* A_mem = A.mem;
00124   const eT* B_mem = B.mem;
00125   
00126   typedef typename umat::elem_type umat_elem_type;
00127   umat_elem_type* out_mem = out.memptr();
00128   
00129   
00130   for(u32 i=0; i<A.n_elem; ++i)
00131     {
00132     if(A_mem[i] >= B_mem[i])
00133       {
00134       out_mem[i] = umat_elem_type(1);
00135       }
00136     else
00137       {
00138       out_mem[i] = umat_elem_type(0);
00139       }
00140     }
00141   
00142   return out;
00143   }
00144 
00145 
00146 
00147 template<typename eT, typename T1, typename T2>
00148 inline
00149 umat
00150 operator<=
00151 (const Base<eT,T1>& X, const Base<eT,T2>& Y)
00152   {
00153   arma_extra_debug_sigprint();
00154   
00155   const unwrap<T1> tmp1(X.get_ref());
00156   const unwrap<T2> tmp2(Y.get_ref());
00157   
00158   const Mat<eT>& A = tmp1.M;
00159   const Mat<eT>& B = tmp2.M;
00160     
00161   arma_debug_assert_same_size(A, B, "operator<=");
00162   
00163   umat out(A.n_rows, A.n_cols);
00164   
00165   const eT* A_mem = A.mem;
00166   const eT* B_mem = B.mem;
00167   
00168   typedef typename umat::elem_type umat_elem_type;
00169   umat_elem_type* out_mem = out.memptr();
00170   
00171   
00172   for(u32 i=0; i<A.n_elem; ++i)
00173     {
00174     if(A_mem[i] == B_mem[i])
00175       {
00176       out_mem[i] = umat_elem_type(1);
00177       }
00178     else
00179       {
00180       out_mem[i] = umat_elem_type(0);
00181       }
00182     }
00183   
00184   return out;
00185   }
00186 
00187 
00188 
00189 template<typename eT, typename T1, typename T2>
00190 inline
00191 umat
00192 operator>
00193 (const Base<eT,T1>& X, const Base<eT,T2>& Y)
00194   {
00195   arma_extra_debug_sigprint();
00196   
00197   const unwrap<T1> tmp1(X.get_ref());
00198   const unwrap<T2> tmp2(Y.get_ref());
00199   
00200   const Mat<eT>& A = tmp1.M;
00201   const Mat<eT>& B = tmp2.M;
00202     
00203   arma_debug_assert_same_size(A, B, "operator>");
00204   
00205   umat out(A.n_rows, A.n_cols);
00206   
00207   const eT* A_mem = A.mem;
00208   const eT* B_mem = B.mem;
00209   
00210   typedef typename umat::elem_type umat_elem_type;
00211   umat_elem_type* out_mem = out.memptr();
00212   
00213   
00214   for(u32 i=0; i<A.n_elem; ++i)
00215     {
00216     if(A_mem[i] > B_mem[i])
00217       {
00218       out_mem[i] = umat_elem_type(1);
00219       }
00220     else
00221       {
00222       out_mem[i] = umat_elem_type(0);
00223       }
00224     }
00225   
00226   return out;
00227   }
00228 
00229 
00230 
00231 template<typename eT, typename T1, typename T2>
00232 inline
00233 umat
00234 operator<
00235 (const Base<eT,T1>& X, const Base<eT,T2>& Y)
00236   {
00237   arma_extra_debug_sigprint();
00238   
00239   const unwrap<T1> tmp1(X.get_ref());
00240   const unwrap<T2> tmp2(Y.get_ref());
00241   
00242   const Mat<eT>& A = tmp1.M;
00243   const Mat<eT>& B = tmp2.M;
00244     
00245   arma_debug_assert_same_size(A, B, "operator<");
00246   
00247   umat out(A.n_rows, A.n_cols);
00248   
00249   const eT* A_mem = A.mem;
00250   const eT* B_mem = B.mem;
00251   
00252   typedef typename umat::elem_type umat_elem_type;
00253   umat_elem_type* out_mem = out.memptr();
00254   
00255   
00256   for(u32 i=0; i<A.n_elem; ++i)
00257     {
00258     if(A_mem[i] < B_mem[i])
00259       {
00260       out_mem[i] = umat_elem_type(1);
00261       }
00262     else
00263       {
00264       out_mem[i] = umat_elem_type(0);
00265       }
00266     }
00267   
00268   return out;
00269   }
00270 
00271 
00272 
00273 template<typename T1>
00274 inline
00275 umat
00276 operator==
00277 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
00278   {
00279   arma_extra_debug_sigprint();
00280   
00281   typedef typename T1::elem_type eT;
00282   
00283   const unwrap<T1> tmp1(X.get_ref());
00284   const Mat<eT>& A = tmp1.M;
00285   
00286   umat out(A.n_rows, A.n_cols);
00287   
00288   const eT* A_mem = A.mem;
00289   
00290   typedef typename umat::elem_type umat_elem_type;
00291   umat_elem_type* out_mem = out.memptr();
00292   
00293   for(u32 i=0; i<A.n_elem; ++i)
00294     {
00295     if(A_mem[i] == val)
00296       {
00297       out_mem[i] = umat_elem_type(1);
00298       }
00299     else
00300       {
00301       out_mem[i] = umat_elem_type(0);
00302       }
00303     }
00304   
00305   return out;
00306   }
00307 
00308 
00309 
00310 template<typename T1>
00311 inline
00312 umat
00313 operator!=
00314 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
00315   {
00316   arma_extra_debug_sigprint();
00317   
00318   typedef typename T1::elem_type eT;
00319   
00320   const unwrap<T1> tmp1(X.get_ref());
00321   const Mat<eT>& A = tmp1.M;
00322     
00323   umat out(A.n_rows, A.n_cols);
00324   
00325   const eT* A_mem = A.mem;
00326   
00327   typedef typename umat::elem_type umat_elem_type;
00328   umat_elem_type* out_mem = out.memptr();
00329   
00330   for(u32 i=0; i<A.n_elem; ++i)
00331     {
00332     if(A_mem[i] != val)
00333       {
00334       out_mem[i] = umat_elem_type(1);
00335       }
00336     else
00337       {
00338       out_mem[i] = umat_elem_type(0);
00339       }
00340     }
00341   
00342   return out;
00343   }
00344 
00345 
00346 
00347 template<typename T1>
00348 inline
00349 umat
00350 operator>=
00351 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
00352   {
00353   arma_extra_debug_sigprint();
00354   
00355   typedef typename T1::elem_type eT;
00356   
00357   const unwrap<T1> tmp1(X.get_ref());
00358   const Mat<eT>& A = tmp1.M;
00359     
00360   umat out(A.n_rows, A.n_cols);
00361   
00362   const eT* A_mem = A.mem;
00363   
00364   typedef typename umat::elem_type umat_elem_type;
00365   umat_elem_type* out_mem = out.memptr();
00366   
00367   for(u32 i=0; i<A.n_elem; ++i)
00368     {
00369     if(A_mem[i] >= val)
00370       {
00371       out_mem[i] = umat_elem_type(1);
00372       }
00373     else
00374       {
00375       out_mem[i] = umat_elem_type(0);
00376       }
00377     }
00378   
00379   return out;
00380   }
00381 
00382 
00383 
00384 template<typename T1>
00385 inline
00386 umat
00387 operator<=
00388 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
00389   {
00390   arma_extra_debug_sigprint();
00391   
00392   typedef typename T1::elem_type eT;
00393   
00394   const unwrap<T1> tmp1(X.get_ref());
00395   const Mat<eT>& A = tmp1.M;
00396     
00397   umat out(A.n_rows, A.n_cols);
00398   
00399   const eT* A_mem = A.mem;
00400   
00401   typedef typename umat::elem_type umat_elem_type;
00402   umat_elem_type* out_mem = out.memptr();
00403   
00404   for(u32 i=0; i<A.n_elem; ++i)
00405     {
00406     if(A_mem[i] <= val)
00407       {
00408       out_mem[i] = umat_elem_type(1);
00409       }
00410     else
00411       {
00412       out_mem[i] = umat_elem_type(0);
00413       }
00414     }
00415   
00416   return out;
00417   }
00418 
00419 
00420 
00421 template<typename T1>
00422 inline
00423 umat
00424 operator>
00425 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
00426   {
00427   arma_extra_debug_sigprint();
00428   
00429   typedef typename T1::elem_type eT;
00430   
00431   const unwrap<T1> tmp1(X.get_ref());
00432   const Mat<eT>& A = tmp1.M;
00433     
00434   umat out(A.n_rows, A.n_cols);
00435   
00436   const eT* A_mem = A.mem;
00437   
00438   typedef typename umat::elem_type umat_elem_type;
00439   umat_elem_type* out_mem = out.memptr();
00440   
00441   for(u32 i=0; i<A.n_elem; ++i)
00442     {
00443     if(A_mem[i] > val)
00444       {
00445       out_mem[i] = umat_elem_type(1);
00446       }
00447     else
00448       {
00449       out_mem[i] = umat_elem_type(0);
00450       }
00451     }
00452   
00453   return out;
00454   }
00455 
00456 
00457 
00458 template<typename T1>
00459 inline
00460 umat
00461 operator<
00462 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
00463   {
00464   arma_extra_debug_sigprint();
00465   
00466   typedef typename T1::elem_type eT;
00467   
00468   const unwrap<T1> tmp1(X.get_ref());
00469   const Mat<eT>& A = tmp1.M;
00470     
00471   umat out(A.n_rows, A.n_cols);
00472   
00473   const eT* A_mem = A.mem;
00474   
00475   typedef typename umat::elem_type umat_elem_type;
00476   umat_elem_type* out_mem = out.memptr();
00477   
00478   for(u32 i=0; i<A.n_elem; ++i)
00479     {
00480     if(A_mem[i] < val)
00481       {
00482       out_mem[i] = umat_elem_type(1);
00483       }
00484     else
00485       {
00486       out_mem[i] = umat_elem_type(0);
00487       }
00488     }
00489   
00490   return out;
00491   }
00492 
00493 
00494 
00495 template<typename T1>
00496 inline
00497 umat
00498 operator==
00499 (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X)
00500   {
00501   return operator==(X,val);
00502   }
00503 
00504 
00505 
00506 template<typename T1>
00507 inline
00508 umat
00509 operator!=
00510 (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X)
00511   {
00512   return operator!=(X,val);
00513   }
00514 
00515 
00516 
00517 template<typename T1>
00518 inline
00519 umat
00520 operator>=
00521 (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X)
00522   {
00523   arma_extra_debug_sigprint();
00524   
00525   typedef typename T1::elem_type eT;
00526   
00527   const unwrap<T1> tmp1(X.get_ref());
00528   const Mat<eT>& A = tmp1.M;
00529     
00530   umat out(A.n_rows, A.n_cols);
00531   
00532   const eT* A_mem = A.mem;
00533   
00534   typedef typename umat::elem_type umat_elem_type;
00535   umat_elem_type* out_mem = out.memptr();
00536   
00537   for(u32 i=0; i<A.n_elem; ++i)
00538     {
00539     if(val >= A_mem[i])
00540       {
00541       out_mem[i] = umat_elem_type(1);
00542       }
00543     else
00544       {
00545       out_mem[i] = umat_elem_type(0);
00546       }
00547     }
00548   
00549   return out;
00550   }
00551 
00552 
00553 
00554 template<typename T1>
00555 inline
00556 umat
00557 operator<=
00558 (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X)
00559   {
00560   arma_extra_debug_sigprint();
00561   
00562   typedef typename T1::elem_type eT;
00563   
00564   const unwrap<T1> tmp1(X.get_ref());
00565   const Mat<eT>& A = tmp1.M;
00566     
00567   umat out(A.n_rows, A.n_cols);
00568   
00569   const eT* A_mem = A.mem;
00570   
00571   typedef typename umat::elem_type umat_elem_type;
00572   umat_elem_type* out_mem = out.memptr();
00573   
00574   for(u32 i=0; i<A.n_elem; ++i)
00575     {
00576     if(val <= A_mem[i])
00577       {
00578       out_mem[i] = umat_elem_type(1);
00579       }
00580     else
00581       {
00582       out_mem[i] = umat_elem_type(0);
00583       }
00584     }
00585   
00586   return out;
00587   }
00588 
00589 
00590 
00591 template<typename T1>
00592 inline
00593 umat
00594 operator>
00595 (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X)
00596   {
00597   arma_extra_debug_sigprint();
00598   
00599   typedef typename T1::elem_type eT;
00600   
00601   const unwrap<T1> tmp1(X.get_ref());
00602   const Mat<eT>& A = tmp1.M;
00603     
00604   umat out(A.n_rows, A.n_cols);
00605   
00606   const eT* A_mem = A.mem;
00607   
00608   typedef typename umat::elem_type umat_elem_type;
00609   umat_elem_type* out_mem = out.memptr();
00610   
00611   for(u32 i=0; i<A.n_elem; ++i)
00612     {
00613     if(val > A_mem[i])
00614       {
00615       out_mem[i] = umat_elem_type(1);
00616       }
00617     else
00618       {
00619       out_mem[i] = umat_elem_type(0);
00620       }
00621     }
00622   
00623   return out;
00624   }
00625 
00626 
00627 
00628 template<typename T1>
00629 inline
00630 umat
00631 operator<
00632 (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X)
00633   {
00634   arma_extra_debug_sigprint();
00635   
00636   typedef typename T1::elem_type eT;
00637   
00638   const unwrap<T1> tmp1(X.get_ref());
00639   const Mat<eT>& A = tmp1.M;
00640   
00641   umat out(A.n_rows, A.n_cols);
00642   
00643   const eT* A_mem = A.mem;
00644   
00645   typedef typename umat::elem_type umat_elem_type;
00646   umat_elem_type* out_mem = out.memptr();
00647   
00648   for(u32 i=0; i<A.n_elem; ++i)
00649     {
00650     if(val < A_mem[i])
00651       {
00652       out_mem[i] = umat_elem_type(1);
00653       }
00654     else
00655       {
00656       out_mem[i] = umat_elem_type(0);
00657       }
00658     }
00659   
00660   return out;
00661   }
00662 
00663 
00664 
00665 //! @}