@@ -174,7 +174,7 @@ op_norm::vec_norm_1(const Proxy<T1>& P, const typename arma_cx_only<typename T1:
174174 }
175175 else
176176 {
177- arma_extra_debug_print (" op_norm::vec_norm_1(): detected possible underflow or overflow" );
177+ arma_extra_debug_print (" detected possible underflow or overflow" );
178178
179179 const quasi_unwrap<typename Proxy<T1>::stored_type> R (P.Q );
180180
@@ -224,26 +224,32 @@ op_norm::vec_norm_1_direct_std(const Mat<eT>& X)
224224 const uword N = X.n_elem ;
225225 const eT* A = X.memptr ();
226226
227- if (N < uword (32 ))
227+ eT out_val = eT (0 );
228+
229+ #if defined(ARMA_USE_ATLAS)
228230 {
229- return op_norm::vec_norm_1_direct_mem (N,A);
231+ arma_extra_debug_print (" atlas::cblas_asum()" );
232+ out_val = atlas::cblas_asum (N,A);
230233 }
231- else
234+ # elif defined(ARMA_USE_BLAS)
232235 {
233- #if defined(ARMA_USE_ATLAS)
234- {
235- return atlas::cblas_asum (N,A);
236- }
237- #elif defined(ARMA_USE_BLAS)
236+ if (has_blas_float_bug<eT>::value)
238237 {
239- return blas::asum (N,A);
238+ out_val = op_norm::vec_norm_1_direct_mem (N,A);
240239 }
241- # else
240+ else
242241 {
243- return op_norm::vec_norm_1_direct_mem (N,A);
242+ arma_extra_debug_print (" blas::asum()" );
243+ out_val = blas::asum (N,A);
244244 }
245- #endif
246245 }
246+ #else
247+ {
248+ out_val = op_norm::vec_norm_1_direct_mem (N,A);
249+ }
250+ #endif
251+
252+ return (out_val <= eT (0 )) ? eT (0 ) : out_val;
247253 }
248254
249255
@@ -397,7 +403,7 @@ op_norm::vec_norm_2(const Proxy<T1>& P, const typename arma_not_cx<typename T1::
397403 }
398404 else
399405 {
400- arma_extra_debug_print (" op_norm::vec_norm_2(): detected possible underflow or overflow" );
406+ arma_extra_debug_print (" detected possible underflow or overflow" );
401407
402408 const quasi_unwrap<typename Proxy<T1>::stored_type> tmp (P.Q );
403409
@@ -476,7 +482,7 @@ op_norm::vec_norm_2(const Proxy<T1>& P, const typename arma_cx_only<typename T1:
476482 }
477483 else
478484 {
479- arma_extra_debug_print (" op_norm::vec_norm_2(): detected possible underflow or overflow" );
485+ arma_extra_debug_print (" detected possible underflow or overflow" );
480486
481487 const quasi_unwrap<typename Proxy<T1>::stored_type> R (P.Q );
482488
@@ -519,36 +525,38 @@ op_norm::vec_norm_2_direct_std(const Mat<eT>& X)
519525 const uword N = X.n_elem ;
520526 const eT* A = X.memptr ();
521527
522- eT result ;
528+ eT out_val = eT ( 0 ) ;
523529
524- if (N < uword ( 32 ) )
530+ # if defined(ARMA_USE_ATLAS )
525531 {
526- result = op_norm::vec_norm_2_direct_mem (N,A);
532+ arma_extra_debug_print (" atlas::cblas_nrm2()" );
533+ out_val = atlas::cblas_nrm2 (N,A);
527534 }
528- else
535+ # elif defined(ARMA_USE_BLAS)
529536 {
530- # if defined(ARMA_USE_ATLAS )
537+ if (has_blas_float_bug<eT>::value )
531538 {
532- result = atlas::cblas_nrm2 (N,A);
539+ out_val = op_norm::vec_norm_2_direct_mem (N,A);
533540 }
534- #elif defined(ARMA_USE_BLAS)
535- {
536- result = blas::nrm2 (N,A);
537- }
538- #else
541+ else
539542 {
540- result = op_norm::vec_norm_2_direct_mem (N,A);
543+ arma_extra_debug_print (" blas::nrm2()" );
544+ out_val = blas::nrm2 (N,A);
541545 }
542- #endif
543546 }
547+ #else
548+ {
549+ out_val = op_norm::vec_norm_2_direct_mem (N,A);
550+ }
551+ #endif
544552
545- if ( (result != eT (0 )) && arma_isfinite (result ) )
553+ if ( (out_val != eT (0 )) && arma_isfinite (out_val ) )
546554 {
547- return result ;
555+ return (out_val < eT ( 0 )) ? eT ( 0 ) : out_val ;
548556 }
549557 else
550558 {
551- arma_extra_debug_print (" op_norm::vec_norm_2_direct_std(): detected possible underflow or overflow" );
559+ arma_extra_debug_print (" detected possible underflow or overflow" );
552560
553561 return op_norm::vec_norm_2_direct_robust (X);
554562 }
@@ -563,7 +571,7 @@ op_norm::vec_norm_2_direct_mem(const uword N, const eT* A)
563571 {
564572 arma_extra_debug_sigprint ();
565573
566- eT acc;
574+ eT acc = eT ( 0 ) ;
567575
568576 #if (defined(ARMA_SIMPLE_LOOPS) || defined(__FAST_MATH__))
569577 {
@@ -673,7 +681,9 @@ op_norm::vec_norm_2_direct_robust(const Mat<eT>& X)
673681 acc1 += val_i * val_i;
674682 }
675683
676- return ( std::sqrt (acc1 + acc2) * max_val );
684+ const eT out_val = std::sqrt (acc1 + acc2) * max_val;
685+
686+ return (out_val <= eT (0 )) ? eT (0 ) : out_val;
677687 }
678688
679689
@@ -882,9 +892,12 @@ op_norm::mat_norm_2(const Mat<eT>& X)
882892 if (X.internal_has_nonfinite ()) { arma_debug_warn_level (1 , " norm(): given matrix has non-finite elements" ); }
883893
884894 Col<T> S;
895+
885896 svd (S, X);
886897
887- return (S.n_elem > 0 ) ? S[0 ] : T (0 );
898+ const T out_val = (S.n_elem > 0 ) ? S[0 ] : T (0 );
899+
900+ return (out_val <= T (0 )) ? T (0 ) : out_val;
888901 }
889902
890903
0 commit comments