From cea7cde9b0cf59d6253eabbbb33619cd6e66bf88 Mon Sep 17 00:00:00 2001 From: conrad Date: Sun, 10 Jan 2021 12:08:53 +1000 Subject: [PATCH] better layout --- include/armadillo_bits/field_meat.hpp | 106 ++++++++------------------ 1 file changed, 30 insertions(+), 76 deletions(-) diff --git a/include/armadillo_bits/field_meat.hpp b/include/armadillo_bits/field_meat.hpp index 7fef4640..2d240644 100644 --- a/include/armadillo_bits/field_meat.hpp +++ b/include/armadillo_bits/field_meat.hpp @@ -74,6 +74,7 @@ field::operator=(const field& x) arma_extra_debug_sigprint(); init(x); + return *this; } @@ -105,6 +106,7 @@ field::operator=(const subview_field& X) arma_extra_debug_sigprint(); subview_field::extract(*this, X); + return *this; } @@ -280,10 +282,7 @@ field::operator=(const std::vector& x) set_size(N, 1); - for(uword i=0; i::operator=(const std::initializer_list& list) const oT* item_ptr = list.begin(); - for(uword i=0; i::operator=(const std::initializer_list< std::initializer_list >& l auto it = list.begin(); auto it_end = list.end(); - for(; it != it_end; ++it) - { - x_n_cols = (std::max)(x_n_cols, uword((*it).size())); - } + for(; it != it_end; ++it) { x_n_cols = (std::max)(x_n_cols, uword((*it).size())); } field& t = (*this); @@ -525,6 +518,7 @@ oT& field::operator() (const uword i) { arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds" ); + return (*mem[i]); } @@ -537,6 +531,7 @@ const oT& field::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds" ); + return (*mem[i]); } @@ -549,6 +544,7 @@ oT& field::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (0 >= n_slices) ), "field::operator(): index out of bounds" ); + return (*mem[in_row + in_col*n_rows]); } @@ -561,6 +557,7 @@ const oT& field::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (0 >= n_slices) ), "field::operator(): index out of bounds" ); + return (*mem[in_row + in_col*n_rows]); } @@ -573,6 +570,7 @@ oT& field::operator() (const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices)), "field::operator(): index out of bounds" ); + return (*mem[in_row + in_col*n_rows + in_slice*(n_rows*n_cols)]); } @@ -585,6 +583,7 @@ const oT& field::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices)), "field::operator(): index out of bounds" ); + return (*mem[in_row + in_col*n_rows + in_slice*(n_rows*n_cols)]); } @@ -1420,10 +1419,7 @@ field::for_each(const std::function< void(oT&) >& F) { arma_extra_debug_sigprint(); - for(uword i=0; i < n_elem; ++i) - { - F(operator[](i)); - } + for(uword i=0; i < n_elem; ++i) { F(operator[](i)); } return *this; } @@ -1437,10 +1433,7 @@ field::for_each(const std::function< void(const oT&) >& F) const { arma_extra_debug_sigprint(); - for(uword i=0; i < n_elem; ++i) - { - F(operator[](i)); - } + for(uword i=0; i < n_elem; ++i) { F(operator[](i)); } return *this; } @@ -1457,10 +1450,7 @@ field::fill(const oT& x) field& t = *this; - for(uword i=0; i::save(const std::string name, const file_type type, const bool print_s arma_extra_debug_sigprint(); std::string err_msg; + const bool save_okay = field_aux::save(*this, name, type, err_msg); if(print_status && (save_okay == false)) @@ -1737,6 +1728,7 @@ field::save(std::ostream& os, const file_type type, const bool print_status) arma_extra_debug_sigprint(); std::string err_msg; + const bool save_okay = field_aux::save(*this, os, type, err_msg); if(print_status && (save_okay == false)) @@ -1765,6 +1757,7 @@ field::load(const std::string name, const file_type type, const bool print_s arma_extra_debug_sigprint(); std::string err_msg; + const bool load_okay = field_aux::load(*this, name, type, err_msg); if(print_status && (load_okay == false)) @@ -1779,10 +1772,7 @@ field::load(const std::string name, const file_type type, const bool print_s } } - if(load_okay == false) - { - (*this).reset(); - } + if(load_okay == false) { (*this).reset(); } return load_okay; } @@ -1812,10 +1802,7 @@ field::load(std::istream& is, const file_type type, const bool print_status) } } - if(load_okay == false) - { - (*this).reset(); - } + if(load_okay == false) { (*this).reset(); } return load_okay; } @@ -1961,25 +1948,16 @@ field::init(const uword n_rows_in, const uword n_cols_in, const uword n_slic { delete_objects(); - if(n_elem > field_prealloc_n_elem::val) - { - delete [] mem; - } + if(n_elem > field_prealloc_n_elem::val) { delete [] mem; } if(n_elem_new <= field_prealloc_n_elem::val) { - if(n_elem_new == 0) - { - mem = nullptr; - } - else - { - mem = mem_local; - } + mem = (n_elem_new == 0) ? nullptr : mem_local; } else { mem = new(std::nothrow) oT* [n_elem_new]; + arma_check_bad_alloc( (mem == nullptr), "field::init(): out of memory" ); } @@ -2020,10 +1998,7 @@ field::create_objects() { arma_extra_debug_sigprint( arma_str::format("n_elem = %d") % n_elem ); - for(uword i=0; i::iterator& field::iterator::operator--() { - if(i > 0) - { - --i; - } + if(i > 0) { --i; } return *this; } @@ -2175,10 +2147,7 @@ inline typename field::const_iterator& field::const_iterator::operator--() { - if(i > 0) - { - --i; - } + if(i > 0) { --i; } return *this; } @@ -2343,10 +2312,7 @@ field_aux::reset_objects(field< Mat >& x) { arma_extra_debug_sigprint(); - for(uword i=0; i >& x) { arma_extra_debug_sigprint(); - for(uword i=0; i >& x) { arma_extra_debug_sigprint(); - for(uword i=0; i >& x) { arma_extra_debug_sigprint(); - for(uword i=0; i& x) { arma_extra_debug_sigprint(); - for(uword i=0; i