diff --git a/include/armadillo_bits/BaseCube_meat.hpp b/include/armadillo_bits/BaseCube_meat.hpp index d22e479b..b3ed7572 100644 --- a/include/armadillo_bits/BaseCube_meat.hpp +++ b/include/armadillo_bits/BaseCube_meat.hpp @@ -261,24 +261,52 @@ BaseCube::is_zero(const typename get_pod_type::res const typename ProxyCube::ea_type Pea = P.get_ea(); - if(is_cx::yes) + if(tol == T(0)) { - for(uword i=0; i::yes) { - const elem_type val = Pea[i]; - - const T val_real = access::tmp_real(val); - const T val_imag = access::tmp_imag(val); - - if(eop_aux::arma_abs(val_real) > tol) { return false; } - if(eop_aux::arma_abs(val_imag) > tol) { return false; } + for(uword i=0; i::yes) { - if(eop_aux::arma_abs(Pea[i]) > tol) { return false; } + for(uword i=0; i tol) || arma_isnan(val_real) ) { return false; } + if( (eop_aux::arma_abs(val_imag) > tol) || arma_isnan(val_imag) ) { return false; } + } + } + else // not complex + { + for(uword i=0; i < n_elem; ++i) + { + const elem_type val = Pea[i]; + + if( (eop_aux::arma_abs(val) > tol) || arma_isnan(val) ) { return false; } + } } } diff --git a/include/armadillo_bits/subview_cube_meat.hpp b/include/armadillo_bits/subview_cube_meat.hpp index 76b4ae96..657c2c68 100644 --- a/include/armadillo_bits/subview_cube_meat.hpp +++ b/include/armadillo_bits/subview_cube_meat.hpp @@ -1395,18 +1395,21 @@ subview_cube::is_zero(const typename get_pod_type::result tol) const { arma_debug_sigprint(); + typedef typename get_pod_type::result T; + + arma_conform_check( (tol < T(0)), "is_zero(): parameter 'tol' must be >= 0" ); + const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; - if( (local_n_rows != 0) && (local_n_cols != 0) ) + if( (local_n_rows == 0) || (local_n_cols == 0) || (local_n_slices == 0) ) { return false; } + + for(uword slice = 0; slice < local_n_slices; ++slice) { - for(uword slice = 0; slice < local_n_slices; ++slice) + for(uword col = 0; col < local_n_cols; ++col) { - for(uword col = 0; col < local_n_cols; ++col) - { - if(arrayops::is_zero(slice_colptr(slice,col), local_n_rows, tol) == false) { return false; } - } + if(arrayops::is_zero(slice_colptr(slice,col), local_n_rows, tol) == false) { return false; } } }