op_scalar_misc_meat.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 
00017 //! \addtogroup op_scalar_misc
00018 //! @{
00019 
00020 
00021 
00022 //! Add a scalar to all elements of a matrix
00023 template<typename T1>
00024 inline
00025 void
00026 op_scalar_plus::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scalar_plus>& in)
00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   typedef typename T1::elem_type eT;
00031   
00032   const unwrap_write<T1> tmp(out, in.m);
00033   const Mat<eT>& A     = tmp.M;
00034   
00035         eT* out_mem = out.memptr();
00036   const eT* A_mem   = A.memptr();
00037   const u32 n_elem  = out.n_elem;
00038   const eT  k       = in.aux;
00039     
00040   for(u32 i=0; i<n_elem; ++i)
00041     {
00042     out_mem[i] = A_mem[i] + k;
00043     }
00044   }
00045 
00046 
00047 
00048 //! Add a scalar to all elements of a cube
00049 template<typename T1>
00050 inline
00051 void
00052 op_scalar_plus::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_scalar_plus>& in)
00053   {
00054   arma_extra_debug_sigprint();
00055   
00056   typedef typename T1::elem_type eT;
00057   
00058   const unwrap_cube_write<T1> tmp(out, in.m);
00059   const Cube<eT>& A         = tmp.M;
00060   
00061         eT* out_mem = out.memptr();
00062   const eT* A_mem   = A.memptr();
00063   const u32 n_elem  = out.n_elem;
00064   const eT  k       = in.aux;
00065     
00066   for(u32 i=0; i<n_elem; ++i)
00067     {
00068     out_mem[i] = A_mem[i] + k;
00069     }
00070   }
00071 
00072 
00073 
00074 //! For each element of a matrix, subtract it from a scalar
00075 template<typename T1>
00076 inline
00077 void
00078 op_scalar_minus_pre::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scalar_minus_pre>& in)
00079   {
00080   arma_extra_debug_sigprint();
00081   
00082   typedef typename T1::elem_type eT;
00083   
00084   const unwrap_write<T1> tmp(out, in.m);
00085   const Mat<eT>& A     = tmp.M;
00086   
00087         eT* out_mem = out.memptr();
00088   const eT* A_mem   = A.memptr();
00089   const u32 n_elem  = out.n_elem;
00090   const eT  k       = in.aux;
00091     
00092   for(u32 i=0; i<n_elem; ++i)
00093     {
00094     out_mem[i] = k - A_mem[i];
00095     }
00096   }
00097 
00098 
00099 
00100 //! For each element of a cube, subtract it from a scalar
00101 template<typename T1>
00102 inline
00103 void
00104 op_scalar_minus_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_scalar_minus_pre>& in)
00105   {
00106   arma_extra_debug_sigprint();
00107   
00108   typedef typename T1::elem_type eT;
00109   
00110   const unwrap_cube_write<T1> tmp(out, in.m);
00111   const Cube<eT>& A         = tmp.M;
00112   
00113         eT* out_mem = out.memptr();
00114   const eT* A_mem   = A.memptr();
00115   const u32 n_elem  = out.n_elem;
00116   const eT  k       = in.aux;
00117     
00118   for(u32 i=0; i<n_elem; ++i)
00119     {
00120     out_mem[i] = k - A_mem[i];
00121     }
00122   }
00123 
00124 
00125 
00126 //! subtract a scalar from each element of a matrix
00127 template<typename T1>
00128 inline
00129 void
00130 op_scalar_minus_post::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scalar_minus_post>& in)
00131   {
00132   arma_extra_debug_sigprint();
00133   
00134   typedef typename T1::elem_type eT;
00135   
00136   const unwrap_write<T1> tmp(out, in.m);
00137   const Mat<eT>& A     = tmp.M;
00138   
00139         eT* out_mem = out.memptr();
00140   const eT* A_mem   = A.memptr();
00141   const u32 n_elem  = out.n_elem;
00142   const eT  k       = in.aux;
00143     
00144   for(u32 i=0; i<n_elem; ++i)
00145     {
00146     out_mem[i] = A_mem[i] - k;
00147     }
00148   }
00149 
00150 
00151 
00152 //! subtract a scalar from each element of a cube
00153 template<typename T1>
00154 inline
00155 void
00156 op_scalar_minus_post::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_scalar_minus_post>& in)
00157   {
00158   arma_extra_debug_sigprint();
00159   
00160   typedef typename T1::elem_type eT;
00161   
00162   const unwrap_cube_write<T1> tmp(out, in.m);
00163   const Cube<eT>& A         = tmp.M;
00164   
00165         eT* out_mem = out.memptr();
00166   const eT* A_mem   = A.memptr();
00167   const u32 n_elem  = out.n_elem;
00168   const eT  k       = in.aux;
00169     
00170   for(u32 i=0; i<n_elem; ++i)
00171     {
00172     out_mem[i] = A_mem[i] - k ;
00173     }
00174   }
00175 
00176 
00177 
00178 //! Multiply all elements of a matrix by a scalar
00179 template<typename T1>
00180 inline
00181 void
00182 op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scalar_times>& in)
00183   {
00184   arma_extra_debug_sigprint();
00185   
00186   typedef typename T1::elem_type eT;
00187   
00188   const unwrap_write<T1> tmp(out, in.m);
00189   const Mat<eT>& A     = tmp.M;
00190   
00191         eT* out_mem = out.memptr();
00192   const eT* A_mem   = A.memptr();
00193   const u32 n_elem  = out.n_elem;
00194   const eT  k       = in.aux;
00195     
00196   for(u32 i=0; i<n_elem; ++i)
00197     {
00198     out_mem[i] = A_mem[i] * k;
00199     }
00200   }
00201 
00202 
00203   
00204 //! Multiply all elements of a cube by a scalar
00205 template<typename T1>
00206 inline
00207 void
00208 op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_scalar_times>& in)
00209   {
00210   arma_extra_debug_sigprint();
00211   
00212   typedef typename T1::elem_type eT;
00213   
00214   const unwrap_cube_write<T1> tmp(out, in.m);
00215   const Cube<eT>& A         = tmp.M;
00216   
00217         eT* out_mem = out.memptr();
00218   const eT* A_mem   = A.memptr();
00219   const u32 n_elem  = out.n_elem;
00220   const eT  k       = in.aux;
00221     
00222   for(u32 i=0; i<n_elem; ++i)
00223     {
00224     out_mem[i] = A_mem[i] * k;
00225     }
00226   }
00227 
00228 
00229 
00230 #if defined(ARMA_GOOD_COMPILER)
00231 
00232 
00233 
00234 //! Evaluate A + B, and then multiply each element of the result by a scalar.
00235 template<typename T1, typename T2>
00236 inline
00237 void
00238 op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_plus>, op_scalar_times>& in)
00239   {
00240   arma_extra_debug_sigprint();
00241   
00242   const unwrap<T1> tmp1(in.m.A);
00243   const unwrap<T2> tmp2(in.m.B);
00244   
00245   typedef typename T1::elem_type eT;
00246   
00247   const Mat<eT>& A = tmp1.M;
00248   const Mat<eT>& B = tmp2.M;
00249   
00250   arma_debug_assert_same_size(A, B, "matrix addition");
00251   
00252   // no alias problems
00253   //out.set_size(A.n_rows, A.n_cols);
00254   out.copy_size(A);
00255   
00256         eT* out_mem = out.memptr();
00257   const eT* A_mem   = A.mem;
00258   const eT* B_mem   = B.mem;
00259   
00260   const eT  k       = in.aux;
00261   const u32 n_elem  = A.n_elem;
00262   
00263   for(u32 i=0; i<n_elem; ++i)
00264     {
00265     out_mem[i] = (A_mem[i] + B_mem[i]) * k;
00266     }
00267   
00268   }
00269 
00270 
00271 
00272 //! Evaluate A + B, and then multiply each element of the result by a scalar.
00273 template<typename T1, typename T2>
00274 inline
00275 void
00276 op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_plus>, op_scalar_times>& in)
00277   {
00278   arma_extra_debug_sigprint();
00279   
00280   const unwrap_cube<T1> tmp1(in.m.A);
00281   const unwrap_cube<T2> tmp2(in.m.B);
00282   
00283   typedef typename T1::elem_type eT;
00284   
00285   const Cube<eT>& A = tmp1.M;
00286   const Cube<eT>& B = tmp2.M;
00287   
00288   arma_debug_assert_same_size(A, B, "cube addition");
00289   
00290   // no alias problems
00291   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00292   out.copy_size(A);
00293   
00294         eT* out_mem = out.memptr();
00295   const eT* A_mem   = A.mem;
00296   const eT* B_mem   = B.mem;
00297   
00298   const eT  k       = in.aux;
00299   const u32 n_elem  = A.n_elem;
00300   
00301   for(u32 i=0; i<n_elem; ++i)
00302     {
00303     out_mem[i] = (A_mem[i] + B_mem[i]) * k;
00304     }
00305   
00306   }
00307 
00308 
00309 
00310 //! Evaluate A - B, and then multiply each element of the result by a scalar.
00311 template<typename T1, typename T2>
00312 inline
00313 void
00314 op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_minus>, op_scalar_times>& in)
00315   {
00316   arma_extra_debug_sigprint();
00317   
00318   const unwrap<T1> tmp1(in.m.A);
00319   const unwrap<T2> tmp2(in.m.B);
00320   
00321   typedef typename T1::elem_type eT;
00322   
00323   const Mat<eT>& A = tmp1.M;
00324   const Mat<eT>& B = tmp2.M;
00325   
00326   arma_debug_assert_same_size(A, B, "matrix subtraction");
00327   
00328   // no alias problems
00329   //out.set_size(A.n_rows, A.n_cols);
00330   out.copy_size(A);
00331   
00332         eT* out_mem = out.memptr();
00333   const eT* A_mem   = A.mem;
00334   const eT* B_mem   = B.mem;
00335   
00336   const eT  k       = in.aux;
00337   const u32 n_elem  = A.n_elem;
00338   
00339   for(u32 i=0; i<n_elem; ++i)
00340     {
00341     out_mem[i] = (A_mem[i] - B_mem[i]) * k;
00342     }
00343   
00344   }
00345 
00346 
00347 
00348 //! Evaluate A - B, and then multiply each element of the result by a scalar.
00349 template<typename T1, typename T2>
00350 inline
00351 void
00352 op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_minus>, op_scalar_times>& in)
00353   {
00354   arma_extra_debug_sigprint();
00355   
00356   const unwrap_cube<T1> tmp1(in.m.A);
00357   const unwrap_cube<T2> tmp2(in.m.B);
00358   
00359   typedef typename T1::elem_type eT;
00360   
00361   const Cube<eT>& A = tmp1.M;
00362   const Cube<eT>& B = tmp2.M;
00363   
00364   arma_debug_assert_same_size(A, B, "cube subtraction");
00365   
00366   // no alias problems
00367   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00368   out.copy_size(A);
00369   
00370         eT* out_mem = out.memptr();
00371   const eT* A_mem   = A.mem;
00372   const eT* B_mem   = B.mem;
00373   
00374   const eT  k       = in.aux;
00375   const u32 n_elem  = A.n_elem;
00376   
00377   for(u32 i=0; i<n_elem; ++i)
00378     {
00379     out_mem[i] = (A_mem[i] - B_mem[i]) * k;
00380     }
00381   
00382   }
00383 
00384 
00385 
00386 //! Evaluate A % B (where % is the element-wise multiply operation) and then multiply each element of the result by a scalar.
00387 template<typename T1, typename T2>
00388 inline
00389 void
00390 op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_schur>, op_scalar_times>& in)
00391   {
00392   arma_extra_debug_sigprint();
00393   
00394   const unwrap<T1> tmp1(in.m.A);
00395   const unwrap<T2> tmp2(in.m.B);
00396   
00397   typedef typename T1::elem_type eT;
00398   
00399   const Mat<eT>& A = tmp1.M;
00400   const Mat<eT>& B = tmp2.M;
00401   
00402   arma_debug_assert_same_size(A, B, "schur product");
00403   
00404   // no alias problems
00405   //out.set_size(A.n_rows, A.n_cols);
00406   out.copy_size(A);
00407   
00408         eT* out_mem = out.memptr();
00409   const eT* A_mem   = A.mem;
00410   const eT* B_mem   = B.mem;
00411   
00412   const eT  k       = in.aux;
00413   const u32 n_elem  = A.n_elem;
00414   
00415   for(u32 i=0; i<n_elem; ++i)
00416     {
00417     out_mem[i] = (A_mem[i] * B_mem[i]) * k;
00418     }
00419   
00420   }
00421 
00422 
00423 
00424 //! Evaluate A % B (where % is the element-wise multiply operation) and then multiply each element of the result by a scalar.
00425 template<typename T1, typename T2>
00426 inline
00427 void
00428 op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_schur>, op_scalar_times>& in)
00429   {
00430   arma_extra_debug_sigprint();
00431   
00432   const unwrap_cube<T1> tmp1(in.m.A);
00433   const unwrap_cube<T2> tmp2(in.m.B);
00434   
00435   typedef typename T1::elem_type eT;
00436   
00437   const Cube<eT>& A = tmp1.M;
00438   const Cube<eT>& B = tmp2.M;
00439   
00440   arma_debug_assert_same_size(A, B, "schur product");
00441   
00442   // no alias problems
00443   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00444   out.copy_size(A);
00445   
00446         eT* out_mem = out.memptr();
00447   const eT* A_mem   = A.mem;
00448   const eT* B_mem   = B.mem;
00449   
00450   const eT  k       = in.aux;
00451   const u32 n_elem  = A.n_elem;
00452   
00453   for(u32 i=0; i<n_elem; ++i)
00454     {
00455     out_mem[i] = (A_mem[i] * B_mem[i]) * k;
00456     }
00457   
00458   }
00459 
00460 
00461 
00462 #endif
00463 
00464 
00465 
00466 //
00467 // 
00468 // 
00469 
00470 
00471 
00472 template<typename T1>
00473 inline
00474 void
00475 op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scalar_div_pre>& in)
00476   {
00477   arma_extra_debug_sigprint();
00478   
00479   typedef typename T1::elem_type eT;
00480   
00481   const unwrap_write<T1> tmp(out, in.m);
00482   const Mat<eT>& A     = tmp.M;
00483   
00484         eT* out_mem = out.memptr();
00485   const eT* A_mem   = A.memptr();
00486   const u32 n_elem  = out.n_elem;
00487   const eT  k       = in.aux;
00488     
00489   for(u32 i=0; i<n_elem; ++i)
00490     {
00491     out_mem[i] = k / A_mem[i];
00492     }
00493   }
00494 
00495 
00496   
00497 template<typename T1>
00498 inline
00499 void
00500 op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_scalar_div_pre>& in)
00501   {
00502   arma_extra_debug_sigprint();
00503   
00504   typedef typename T1::elem_type eT;
00505   
00506   const unwrap_cube_write<T1> tmp(out, in.m);
00507   const Cube<eT>& A         = tmp.M;
00508   
00509         eT* out_mem = out.memptr();
00510   const eT* A_mem   = A.memptr();
00511   const u32 n_elem  = out.n_elem;
00512   const eT  k       = in.aux;
00513     
00514   for(u32 i=0; i<n_elem; ++i)
00515     {
00516     out_mem[i] = k / A_mem[i];
00517     }
00518   }
00519 
00520 
00521 
00522 #if defined(ARMA_GOOD_COMPILER)
00523 
00524 
00525 
00526 template<typename T1, typename T2>
00527 inline
00528 void
00529 op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_plus>, op_scalar_div_pre>& in)
00530   {
00531   arma_extra_debug_sigprint();
00532   
00533   unwrap<T1> tmp1(in.m.A);
00534   unwrap<T2> tmp2(in.m.B);
00535   
00536   typedef typename T1::elem_type eT;
00537   
00538   const Mat<eT>& A = tmp1.M;
00539   const Mat<eT>& B = tmp2.M;
00540   
00541   arma_debug_assert_same_size(A, B, "matrix addition");
00542   
00543   // no alias problems
00544   //out.set_size(A.n_rows, A.n_cols);
00545   out.copy_size(A);
00546   
00547         eT* out_mem = out.memptr();
00548   const eT* A_mem   = A.mem;
00549   const eT* B_mem   = B.mem;
00550   
00551   const eT  k       = in.aux;
00552   const u32 n_elem  = A.n_elem;
00553   
00554   for(u32 i=0; i<n_elem; ++i)
00555     {
00556     out_mem[i] = k / (A_mem[i] + B_mem[i]);
00557     }
00558   
00559   }
00560 
00561 
00562 
00563 template<typename T1, typename T2>
00564 inline
00565 void
00566 op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_plus>, op_scalar_div_pre>& in)
00567   {
00568   arma_extra_debug_sigprint();
00569   
00570   unwrap_cube<T1> tmp1(in.m.A);
00571   unwrap_cube<T2> tmp2(in.m.B);
00572   
00573   typedef typename T1::elem_type eT;
00574   
00575   const Cube<eT>& A = tmp1.M;
00576   const Cube<eT>& B = tmp2.M;
00577   
00578   arma_debug_assert_same_size(A, B, "cube addition");
00579   
00580   // no alias problems
00581   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00582   out.copy_size(A);
00583   
00584         eT* out_mem = out.memptr();
00585   const eT* A_mem   = A.mem;
00586   const eT* B_mem   = B.mem;
00587   
00588   const eT  k       = in.aux;
00589   const u32 n_elem  = A.n_elem;
00590   
00591   for(u32 i=0; i<n_elem; ++i)
00592     {
00593     out_mem[i] = k / (A_mem[i] + B_mem[i]);
00594     }
00595   
00596   }
00597 
00598 
00599 
00600 template<typename T1, typename T2>
00601 inline
00602 void
00603 op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_minus>, op_scalar_div_pre>& in)
00604   {
00605   arma_extra_debug_sigprint();
00606   
00607   unwrap<T1> tmp1(in.m.A);
00608   unwrap<T2> tmp2(in.m.B);
00609   
00610   typedef typename T1::elem_type eT;
00611   
00612   const Mat<eT>& A = tmp1.M;
00613   const Mat<eT>& B = tmp2.M;
00614   
00615   arma_debug_assert_same_size(A, B, "matrix subtraction");
00616   
00617   // no alias problems
00618   //out.set_size(A.n_rows, A.n_cols);
00619   out.copy_size(A);
00620   
00621         eT* out_mem = out.memptr();
00622   const eT* A_mem   = A.mem;
00623   const eT* B_mem   = B.mem;
00624   
00625   const eT  k       = in.aux;
00626   const u32 n_elem  = A.n_elem;
00627   
00628   for(u32 i=0; i<n_elem; ++i)
00629     {
00630     out_mem[i] = k / (A_mem[i] - B_mem[i]);
00631     }
00632   
00633   }
00634 
00635 
00636 
00637 template<typename T1, typename T2>
00638 inline
00639 void
00640 op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_minus>, op_scalar_div_pre>& in)
00641   {
00642   arma_extra_debug_sigprint();
00643   
00644   unwrap_cube<T1> tmp1(in.m.A);
00645   unwrap_cube<T2> tmp2(in.m.B);
00646   
00647   typedef typename T1::elem_type eT;
00648   
00649   const Cube<eT>& A = tmp1.M;
00650   const Cube<eT>& B = tmp2.M;
00651   
00652   arma_debug_assert_same_size(A, B, "cube subtraction");
00653   
00654   // no alias problems
00655   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00656   out.copy_size(A);
00657   
00658         eT* out_mem = out.memptr();
00659   const eT* A_mem   = A.mem;
00660   const eT* B_mem   = B.mem;
00661   
00662   const eT  k       = in.aux;
00663   const u32 n_elem  = A.n_elem;
00664   
00665   for(u32 i=0; i<n_elem; ++i)
00666     {
00667     out_mem[i] = k / (A_mem[i] - B_mem[i]);
00668     }
00669   
00670   }
00671 
00672 
00673 
00674 template<typename T1, typename T2>
00675 inline
00676 void
00677 op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_schur>, op_scalar_div_pre>& in)
00678   {
00679   arma_extra_debug_sigprint();
00680   
00681   unwrap<T1> tmp1(in.m.A);
00682   unwrap<T2> tmp2(in.m.B);
00683   
00684   typedef typename T1::elem_type eT;
00685   
00686   const Mat<eT>& A = tmp1.M;
00687   const Mat<eT>& B = tmp2.M;
00688   
00689   arma_debug_assert_same_size(A, B, "schur product");
00690   
00691   // no alias problems
00692   //out.set_size(A.n_rows, A.n_cols);
00693   out.copy_size(A);
00694   
00695         eT* out_mem = out.memptr();
00696   const eT* A_mem   = A.mem;
00697   const eT* B_mem   = B.mem;
00698   
00699   const eT  k       = in.aux;
00700   const u32 n_elem  = A.n_elem;
00701   
00702   for(u32 i=0; i<n_elem; ++i)
00703     {
00704     out_mem[i] = k / (A_mem[i] * B_mem[i]);
00705     }
00706   
00707   }
00708 
00709 
00710 
00711 template<typename T1, typename T2>
00712 inline
00713 void
00714 op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_schur>, op_scalar_div_pre>& in)
00715   {
00716   arma_extra_debug_sigprint();
00717   
00718   unwrap_cube<T1> tmp1(in.m.A);
00719   unwrap_cube<T2> tmp2(in.m.B);
00720   
00721   typedef typename T1::elem_type eT;
00722   
00723   const Cube<eT>& A = tmp1.M;
00724   const Cube<eT>& B = tmp2.M;
00725   
00726   arma_debug_assert_same_size(A, B, "schur product");
00727   
00728   // no alias problems
00729   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00730   out.copy_size(A);
00731 
00732         eT* out_mem = out.memptr();
00733   const eT* A_mem   = A.mem;
00734   const eT* B_mem   = B.mem;
00735   
00736   const eT  k       = in.aux;
00737   const u32 n_elem  = A.n_elem;
00738   
00739   for(u32 i=0; i<n_elem; ++i)
00740     {
00741     out_mem[i] = k / (A_mem[i] * B_mem[i]);
00742     }
00743   
00744   }
00745 
00746 
00747 
00748 #endif
00749 
00750 
00751 
00752 //
00753 //
00754 //
00755 
00756 
00757 
00758 template<typename T1>
00759 inline
00760 void
00761 op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scalar_div_post>& in)
00762   {
00763   arma_extra_debug_sigprint();
00764   
00765   typedef typename T1::elem_type eT;
00766   
00767   const unwrap_write<T1> tmp(out, in.m);
00768   const Mat<eT>& A     = tmp.M;
00769   
00770         eT* out_mem = out.memptr();
00771   const eT* A_mem   = A.memptr();
00772   const u32 n_elem  = out.n_elem;
00773   const eT  k       = in.aux;
00774     
00775   for(u32 i=0; i<n_elem; ++i)
00776     {
00777     out_mem[i] = A_mem[i] / k;
00778     }
00779   }
00780 
00781 
00782 
00783 template<typename T1>
00784 inline
00785 void
00786 op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_scalar_div_post>& in)
00787   {
00788   arma_extra_debug_sigprint();
00789   
00790   typedef typename T1::elem_type eT;
00791   
00792   const unwrap_cube_write<T1> tmp(out, in.m);
00793   const Cube<eT>& A         = tmp.M;
00794   
00795         eT* out_mem = out.memptr();
00796   const eT* A_mem   = A.memptr();
00797   const u32 n_elem  = out.n_elem;
00798   const eT  k       = in.aux;
00799     
00800   for(u32 i=0; i<n_elem; ++i)
00801     {
00802     out_mem[i] = A_mem[i] / k;
00803     }
00804   }
00805 
00806 
00807 
00808 #if defined(ARMA_GOOD_COMPILER)
00809 
00810 
00811 
00812 template<typename T1, typename T2>
00813 inline
00814 void
00815 op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_plus>, op_scalar_div_post>& in)
00816   {
00817   arma_extra_debug_sigprint();
00818   
00819   unwrap<T1> tmp1(in.m.A);
00820   unwrap<T2> tmp2(in.m.B);
00821   
00822   typedef typename T1::elem_type eT;
00823   
00824   const Mat<eT>& A = tmp1.M;
00825   const Mat<eT>& B = tmp2.M;
00826   
00827   arma_debug_assert_same_size(A, B, "matrix addition");
00828   
00829   // no alias problems
00830   //out.set_size(A.n_rows, A.n_cols);
00831   out.copy_size(A);
00832   
00833         eT* out_mem = out.memptr();
00834   const eT* A_mem   = A.mem;
00835   const eT* B_mem   = B.mem;
00836   
00837   const eT  k       = in.aux;
00838   const u32 n_elem  = A.n_elem;
00839   
00840   for(u32 i=0; i<n_elem; ++i)
00841     {
00842     out_mem[i] = (A_mem[i] + B_mem[i]) / k;
00843     }
00844   
00845   }
00846 
00847 
00848 
00849 template<typename T1, typename T2>
00850 inline
00851 void
00852 op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_plus>, op_scalar_div_post>& in)
00853   {
00854   arma_extra_debug_sigprint();
00855   
00856   unwrap_cube<T1> tmp1(in.m.A);
00857   unwrap_cube<T2> tmp2(in.m.B);
00858   
00859   typedef typename T1::elem_type eT;
00860   
00861   const Cube<eT>& A = tmp1.M;
00862   const Cube<eT>& B = tmp2.M;
00863   
00864   arma_debug_assert_same_size(A, B, "cube addition");
00865   
00866   // no alias problems
00867   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00868   out.copy_size(A);
00869   
00870         eT* out_mem = out.memptr();
00871   const eT* A_mem   = A.mem;
00872   const eT* B_mem   = B.mem;
00873   
00874   const eT  k       = in.aux;
00875   const u32 n_elem  = A.n_elem;
00876   
00877   for(u32 i=0; i<n_elem; ++i)
00878     {
00879     out_mem[i] = (A_mem[i] + B_mem[i]) / k;
00880     }
00881   
00882   }
00883 
00884 
00885 
00886 template<typename T1, typename T2>
00887 inline
00888 void
00889 op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_minus>, op_scalar_div_post>& in)
00890   {
00891   arma_extra_debug_sigprint();
00892   
00893   unwrap<T1> tmp1(in.m.A);
00894   unwrap<T2> tmp2(in.m.B);
00895   
00896   typedef typename T1::elem_type eT;
00897   
00898   const Mat<eT>& A = tmp1.M;
00899   const Mat<eT>& B = tmp2.M;
00900   
00901   arma_debug_assert_same_size(A, B, "matrix subtraction");
00902   
00903   // no alias problems
00904   //out.set_size(A.n_rows, A.n_cols);
00905   out.copy_size(A);
00906   
00907         eT* out_mem = out.memptr();
00908   const eT* A_mem   = A.mem;
00909   const eT* B_mem   = B.mem;
00910   
00911   const eT  k       = in.aux;
00912   const u32 n_elem  = A.n_elem;
00913   
00914   for(u32 i=0; i<n_elem; ++i)
00915     {
00916     out_mem[i] = (A_mem[i] - B_mem[i]) / k;
00917     }
00918   
00919   }
00920 
00921 
00922 
00923 template<typename T1, typename T2>
00924 inline
00925 void
00926 op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_minus>, op_scalar_div_post>& in)
00927   {
00928   arma_extra_debug_sigprint();
00929   
00930   unwrap_cube<T1> tmp1(in.m.A);
00931   unwrap_cube<T2> tmp2(in.m.B);
00932   
00933   typedef typename T1::elem_type eT;
00934   
00935   const Cube<eT>& A = tmp1.M;
00936   const Cube<eT>& B = tmp2.M;
00937   
00938   arma_debug_assert_same_size(A, B, "cube subtraction");
00939   
00940   // no alias problems
00941   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
00942   out.copy_size(A);
00943   
00944         eT* out_mem = out.memptr();
00945   const eT* A_mem   = A.mem;
00946   const eT* B_mem   = B.mem;
00947   
00948   const eT  k       = in.aux;
00949   const u32 n_elem  = A.n_elem;
00950   
00951   for(u32 i=0; i<n_elem; ++i)
00952     {
00953     out_mem[i] = (A_mem[i] - B_mem[i]) / k;
00954     }
00955   
00956   }
00957 
00958 
00959 
00960 template<typename T1, typename T2>
00961 inline
00962 void
00963 op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_schur>, op_scalar_div_post>& in)
00964   {
00965   arma_extra_debug_sigprint();
00966   
00967   unwrap<T1> tmp1(in.m.A);
00968   unwrap<T2> tmp2(in.m.B);
00969   
00970   typedef typename T1::elem_type eT;
00971   
00972   const Mat<eT>& A = tmp1.M;
00973   const Mat<eT>& B = tmp2.M;
00974   
00975   arma_debug_assert_same_size(A, B, "schur product");
00976   
00977   // no alias problems
00978   //out.set_size(A.n_rows, A.n_cols);
00979   out.copy_size(A);
00980   
00981         eT* out_mem = out.memptr();
00982   const eT* A_mem   = A.mem;
00983   const eT* B_mem   = B.mem;
00984   
00985   const eT  k       = in.aux;
00986   const u32 n_elem  = A.n_elem;
00987   
00988   for(u32 i=0; i<n_elem; ++i)
00989     {
00990     out_mem[i] = (A_mem[i] * B_mem[i]) / k;
00991     }
00992   
00993   }
00994 
00995 
00996 
00997 template<typename T1, typename T2>
00998 inline
00999 void
01000 op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube< GlueCube<T1,T2,glue_cube_schur>, op_scalar_div_post>& in)
01001   {
01002   arma_extra_debug_sigprint();
01003   
01004   unwrap_cube<T1> tmp1(in.m.A);
01005   unwrap_cube<T2> tmp2(in.m.B);
01006   
01007   typedef typename T1::elem_type eT;
01008   
01009   const Cube<eT>& A = tmp1.M;
01010   const Cube<eT>& B = tmp2.M;
01011   
01012   arma_debug_assert_same_size(A, B, "schur product");
01013   
01014   // no alias problems
01015   //out.set_size(A.n_rows, A.n_cols, A.n_slices);
01016   out.copy_size(A);
01017   
01018         eT* out_mem = out.memptr();
01019   const eT* A_mem   = A.mem;
01020   const eT* B_mem   = B.mem;
01021   
01022   const eT  k       = in.aux;
01023   const u32 n_elem  = A.n_elem;
01024   
01025   for(u32 i=0; i<n_elem; ++i)
01026     {
01027     out_mem[i] = (A_mem[i] * B_mem[i]) / k;
01028     }
01029   
01030   }
01031 
01032 
01033 
01034 #endif
01035 
01036 
01037 //! @}