@@ -5504,6 +5504,18 @@ Mat<eT>::Mat(const eOp<T1, eop_type>& X)
55045504 if (eT_ok && (X.aux == eT (0.5 ))) { eop_sqrt::apply (*this , reinterpret_cast < const eOp<T1 , eop_sqrt >& >(X)); return ; }
55055505 }
55065506
5507+ if (is_gen_eye<T1 >::value && is_same_type<eop_type, eop_scalar_times>::value)
5508+ {
5509+ zeros ();
5510+
5511+ const eT k = X.aux ;
5512+ const uword N = (std::min)(n_rows, n_cols);
5513+
5514+ for (uword ii=0 ; ii < N; ++ii) { at (ii,ii) = k; }
5515+
5516+ return ;
5517+ }
5518+
55075519 eop_type::apply (*this , X);
55085520 }
55095521
@@ -5534,6 +5546,18 @@ Mat<eT>::operator=(const eOp<T1, eop_type>& X)
55345546 if (eT_ok && (X.aux == eT (0.5 ))) { eop_sqrt::apply (*this , reinterpret_cast < const eOp<T1 , eop_sqrt >& >(X)); return *this ; }
55355547 }
55365548
5549+ if (is_gen_eye<T1 >::value && is_same_type<eop_type, eop_scalar_times>::value)
5550+ {
5551+ zeros ();
5552+
5553+ const eT k = X.aux ;
5554+ const uword N = (std::min)(n_rows, n_cols);
5555+
5556+ for (uword ii=0 ; ii < N; ++ii) { at (ii,ii) = k; }
5557+
5558+ return *this ;
5559+ }
5560+
55375561 eop_type::apply (*this , X);
55385562
55395563 return *this ;
@@ -5563,6 +5587,18 @@ Mat<eT>::operator+=(const eOp<T1, eop_type>& X)
55635587 if (eT_ok && (X.aux == eT (0.5 ))) { eop_sqrt::apply_inplace_plus (*this , reinterpret_cast < const eOp<T1 , eop_sqrt >& >(X)); return *this ; }
55645588 }
55655589
5590+ if (is_gen_eye<T1 >::value && is_same_type<eop_type, eop_scalar_times>::value)
5591+ {
5592+ arma_conform_assert_same_size (n_rows, n_cols, X.get_n_rows (), X.get_n_cols (), " addition" );
5593+
5594+ const eT k = X.aux ;
5595+ const uword N = (std::min)(n_rows, n_cols);
5596+
5597+ for (uword ii=0 ; ii < N; ++ii) { at (ii,ii) += k; }
5598+
5599+ return *this ;
5600+ }
5601+
55665602 eop_type::apply_inplace_plus (*this , X);
55675603
55685604 return *this ;
@@ -5592,6 +5628,18 @@ Mat<eT>::operator-=(const eOp<T1, eop_type>& X)
55925628 if (eT_ok && (X.aux == eT (0.5 ))) { eop_sqrt::apply_inplace_minus (*this , reinterpret_cast < const eOp<T1 , eop_sqrt >& >(X)); return *this ; }
55935629 }
55945630
5631+ if (is_gen_eye<T1 >::value && is_same_type<eop_type, eop_scalar_times>::value)
5632+ {
5633+ arma_conform_assert_same_size (n_rows, n_cols, X.get_n_rows (), X.get_n_cols (), " subtraction" );
5634+
5635+ const eT k = X.aux ;
5636+ const uword N = (std::min)(n_rows, n_cols);
5637+
5638+ for (uword ii=0 ; ii < N; ++ii) { at (ii,ii) -= k; }
5639+
5640+ return *this ;
5641+ }
5642+
55955643 eop_type::apply_inplace_minus (*this , X);
55965644
55975645 return *this ;
0 commit comments