| Cube_meat.hpp | | Cube_meat.hpp | |
| | | | |
| skipping to change at line 688 | | skipping to change at line 688 | |
| Cube<eT>::slices(const u32 in_slice1, const u32 in_slice2) | | Cube<eT>::slices(const u32 in_slice1, const u32 in_slice2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_slice1 > in_slice2) || (in_slice2 >= n_slices), | | (in_slice1 > in_slice2) || (in_slice2 >= n_slices), | |
| "Cube::slices(): indices out of bounds or incorrectly used" | | "Cube::slices(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_cube<eT>(*this, 0, 0, in_slice1, ( (n_rows>0) ? n_rows-1 : | | const u32 subcube_n_slices = in_slice2 - in_slice1 + 1; | |
| 0 ), ( (n_cols>0) ? n_cols-1 : 0 ), in_slice2); | | | |
| | | return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n | |
| | | _slices); | |
| } | | } | |
| | | | |
| //! creation of subview_cube (subcube comprised of specified slices) | | //! creation of subview_cube (subcube comprised of specified slices) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const subview_cube<eT> | | const subview_cube<eT> | |
| Cube<eT>::slices(const u32 in_slice1, const u32 in_slice2) const | | Cube<eT>::slices(const u32 in_slice1, const u32 in_slice2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_slice1 > in_slice2) || (in_slice2 >= n_slices), | | (in_slice1 > in_slice2) || (in_slice2 >= n_slices), | |
| "Cube::rows(): indices out of bounds or incorrectly used" | | "Cube::rows(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_cube<eT>(*this, 0, 0, in_slice1, ( (n_rows>0) ? n_rows-1 : | | const u32 subcube_n_slices = in_slice2 - in_slice1 + 1; | |
| 0 ), ( (n_cols>0) ? n_cols-1 : 0 ), in_slice2); | | | |
| | | return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n | |
| | | _slices); | |
| } | | } | |
| | | | |
| //! creation of subview_cube (generic subcube) | | //! creation of subview_cube (generic subcube) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_cube<eT> | | subview_cube<eT> | |
| Cube<eT>::subcube(const u32 in_row1, const u32 in_col1, const u32 in_slice1
, const u32 in_row2, const u32 in_col2, const u32 in_slice2) | | Cube<eT>::subcube(const u32 in_row1, const u32 in_col1, const u32 in_slice1
, const u32 in_row2, const u32 in_col2, const u32 in_slice2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2
) || | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2
) || | |
| (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices)
, | | (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices)
, | |
| "Cube::subcube(): indices out of bounds or incorrectly used" | | "Cube::subcube(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c | | const u32 subcube_n_rows = in_row2 - in_row1 + 1; | |
| ol2, in_slice2); | | const u32 subcube_n_cols = in_col2 - in_col1 + 1; | |
| | | const u32 subcube_n_slices = in_slice2 - in_slice1 + 1; | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_row | |
| | | s, subcube_n_cols, subcube_n_slices); | |
| } | | } | |
| | | | |
| //! creation of subview_cube (generic subcube) | | //! creation of subview_cube (generic subcube) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const subview_cube<eT> | | const subview_cube<eT> | |
| Cube<eT>::subcube(const u32 in_row1, const u32 in_col1, const u32 in_slice1
, const u32 in_row2, const u32 in_col2, const u32 in_slice2) const | | Cube<eT>::subcube(const u32 in_row1, const u32 in_col1, const u32 in_slice1
, const u32 in_row2, const u32 in_col2, const u32 in_slice2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2
) || | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2
) || | |
| (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices)
, | | (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices)
, | |
| "Cube::subcube(): indices out of bounds or incorrectly used" | | "Cube::subcube(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c | | const u32 subcube_n_rows = in_row2 - in_row1 + 1; | |
| ol2, in_slice2); | | const u32 subcube_n_cols = in_col2 - in_col1 + 1; | |
| | | const u32 subcube_n_slices = in_slice2 - in_slice1 + 1; | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_row | |
| | | s, subcube_n_cols, subcube_n_slices); | |
| } | | } | |
| | | | |
| //! creation of subview_cube (generic subcube) | | //! creation of subview_cube (generic subcube) | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| subview_cube<eT> | | subview_cube<eT> | |
| Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s
lice_span) | | Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s
lice_span) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 in_row1 = row_span.a; | | const bool row_all = row_span.whole; | |
| const u32 in_row2 = row_span.b; | | const bool col_all = col_span.whole; | |
| | | const bool slice_all = slice_span.whole; | |
| const u32 in_col1 = col_span.a; | | | |
| const u32 in_col2 = col_span.b; | | const u32 local_n_rows = n_rows; | |
| | | const u32 local_n_cols = n_cols; | |
| const u32 in_slice1 = slice_span.a; | | const u32 local_n_slices = n_slices; | |
| const u32 in_slice2 = slice_span.b; | | | |
| | | const u32 in_row1 = row_all ? 0 : row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | const u32 subcube_n_rows = row_all ? local_n_rows : in_row2 - in_ro | |
| | | w1 + 1; | |
| | | | |
| | | const u32 in_col1 = col_all ? 0 : col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | const u32 subcube_n_cols = col_all ? local_n_cols : in_col2 - in_co | |
| | | l1 + 1; | |
| | | | |
| | | const u32 in_slice1 = slice_all ? 0 : slice_span.a; | |
| | | const u32 in_slice2 = slice_span.b; | |
| | | const u32 subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_ | |
| | | slice1 + 1; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2 | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_ | |
| ) || | | n_rows)) ) | |
| (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices) | | || | |
| , | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_ | |
| | | n_cols)) ) | |
| | | || | |
| | | ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_ | |
| | | n_slices)) ) | |
| | | , | |
| "Cube::subcube(): indices out of bounds or incorrectly used" | | "Cube::subcube(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c
ol2, in_slice2); | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_row
s, subcube_n_cols, subcube_n_slices); | |
| } | | } | |
| | | | |
| //! creation of subview_cube (generic subcube) | | //! creation of subview_cube (generic subcube) | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| const subview_cube<eT> | | const subview_cube<eT> | |
| Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s
lice_span) const | | Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s
lice_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 in_row1 = row_span.a; | | const bool row_all = row_span.whole; | |
| const u32 in_row2 = row_span.b; | | const bool col_all = col_span.whole; | |
| | | const bool slice_all = slice_span.whole; | |
| const u32 in_col1 = col_span.a; | | | |
| const u32 in_col2 = col_span.b; | | const u32 local_n_rows = n_rows; | |
| | | const u32 local_n_cols = n_cols; | |
| const u32 in_slice1 = slice_span.a; | | const u32 local_n_slices = n_slices; | |
| const u32 in_slice2 = slice_span.b; | | | |
| | | const u32 in_row1 = row_all ? 0 : row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | const u32 subcube_n_rows = row_all ? local_n_rows : in_row2 - in_ro | |
| | | w1 + 1; | |
| | | | |
| | | const u32 in_col1 = col_all ? 0 : col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | const u32 subcube_n_cols = col_all ? local_n_cols : in_col2 - in_co | |
| | | l1 + 1; | |
| | | | |
| | | const u32 in_slice1 = slice_all ? 0 : slice_span.a; | |
| | | const u32 in_slice2 = slice_span.b; | |
| | | const u32 subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_ | |
| | | slice1 + 1; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2 | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_ | |
| ) || | | n_rows)) ) | |
| (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices) | | || | |
| , | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_ | |
| | | n_cols)) ) | |
| | | || | |
| | | ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_ | |
| | | n_slices)) ) | |
| | | , | |
| "Cube::subcube(): indices out of bounds or incorrectly used" | | "Cube::subcube(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_row | |
| ol2, in_slice2); | | s, subcube_n_cols, subcube_n_slices); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | subview_cube<eT> | |
| | | Cube<eT>::operator()(const span& row_span, const span& col_span, const span | |
| | | & slice_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).subcube(row_span, col_span, slice_span); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview_cube<eT> | |
| | | Cube<eT>::operator()(const span& row_span, const span& col_span, const span | |
| | | & slice_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).subcube(row_span, col_span, slice_span); | |
| } | | } | |
| | | | |
| //! remove specified slice | | //! remove specified slice | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::shed_slice(const u32 slice_num) | | Cube<eT>::shed_slice(const u32 slice_num) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
End of changes. 12 change blocks. |
| 37 lines changed or deleted | | 109 lines changed or added | |
|
| Mat_meat.hpp | | Mat_meat.hpp | |
| | | | |
| skipping to change at line 593 | | skipping to change at line 593 | |
| } | | } | |
| | | | |
| //! in-place matrix addition | | //! in-place matrix addition | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator+=(const Mat<eT>& m) | | Mat<eT>::operator+=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(*this, m, "matrix addition"); | | arma_debug_assert_same_size(*this, m, "addition"); | |
| | | | |
| arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); | | arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix subtraction | | //! in-place matrix subtraction | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator-=(const Mat<eT>& m) | | Mat<eT>::operator-=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(*this, m, "matrix subtraction"); | | arma_debug_assert_same_size(*this, m, "subtraction"); | |
| | | | |
| arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); | | arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix multiplication | | //! in-place matrix multiplication | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| | | | |
| skipping to change at line 636 | | skipping to change at line 636 | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix multiplication | | //! in-place element-wise matrix multiplication | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator%=(const Mat<eT>& m) | | Mat<eT>::operator%=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(*this, m, "element-wise matrix multplication"
); | | arma_debug_assert_same_size(*this, m, "element-wise multiplication"); | |
| | | | |
| arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); | | arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix division | | //! in-place element-wise matrix division | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator/=(const Mat<eT>& m) | | Mat<eT>::operator/=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(*this, m, "element-wise matrix division"); | | arma_debug_assert_same_size(*this, m, "element-wise division"); | |
| | | | |
| arrayops::inplace_div( memptr(), m.memptr(), n_elem ); | | arrayops::inplace_div( memptr(), m.memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | Mat<eT>::Mat(const BaseCube<eT,T1>& X) | |
| | | : n_rows(0) | |
| | | , n_cols(0) | |
| | | , n_elem(0) | |
| | | , vec_state(0) | |
| | | , mem_state(0) | |
| | | , mem(mem) //, mem(0) | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | (*this).operator=(X); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator=(const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>& out = *this; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<eT>& in = tmp.M; | |
| | | | |
| | | arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| | | { | |
| | | out.set_size(in_n_rows, in_n_cols); | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows ) | |
| | | ; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if(in_n_cols == 1) | |
| | | { | |
| | | out.set_size(in_n_rows, in_n_slices); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ) | |
| | | ; | |
| | | } | |
| | | } | |
| | | else | |
| | | if(in_n_rows == 1) | |
| | | { | |
| | | out.set_size(in_n_slices, in_n_cols); | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] = in.at(0, col, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | out.set_size(in_n_slices); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] = in.at(0, 0, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator+=(const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>& out = *this; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<eT>& in = tmp.M; | |
| | | | |
| | | arma_debug_assert_cube_as_mat(out, in, "addition", true); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
| | | const u32 out_n_rows = out.n_rows; | |
| | | const u32 out_n_cols = out.n_cols; | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_ | |
| | | n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_ | |
| | | n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] += in.at(0, col, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] += in.at(0, 0, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator-=(const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>& out = *this; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<eT>& in = tmp.M; | |
| | | | |
| | | arma_debug_assert_cube_as_mat(out, in, "subtraction", true); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
| | | const u32 out_n_rows = out.n_rows; | |
| | | const u32 out_n_cols = out.n_cols; | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in | |
| | | _n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in | |
| | | _n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] -= in.at(0, col, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] -= in.at(0, 0, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator*=(const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const Mat<eT> B(X); | |
| | | | |
| | | (*this).operator*=(B); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator%=(const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>& out = *this; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<eT>& in = tmp.M; | |
| | | | |
| | | arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", tru | |
| | | e); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
| | | const u32 out_n_rows = out.n_rows; | |
| | | const u32 out_n_cols = out.n_cols; | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] *= in.at(0, col, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] *= in.at(0, 0, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator/=(const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>& out = *this; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<eT>& in = tmp.M; | |
| | | | |
| | | arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
| | | const u32 out_n_rows = out.n_rows; | |
| | | const u32 out_n_cols = out.n_cols; | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] /= in.at(0, col, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] /= in.at(0, 0, i); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| //! for constructing a complex matrix out of two non-complex matrices | | //! for constructing a complex matrix out of two non-complex matrices | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| Mat<eT>::Mat | | Mat<eT>::Mat | |
| ( | | ( | |
| const Base<typename Mat<eT>::pod_type,T1>& A, | | const Base<typename Mat<eT>::pod_type,T1>& A, | |
| const Base<typename Mat<eT>::pod_type,T2>& B | | const Base<typename Mat<eT>::pod_type,T2>& B | |
| ) | | ) | |
| : n_rows(0) | | : n_rows(0) | |
| | | | |
| skipping to change at line 1072 | | skipping to change at line 1454 | |
| inline | | inline | |
| mat_injector< Mat<eT> > | | mat_injector< Mat<eT> > | |
| Mat<eT>::operator<<(const eT val) | | Mat<eT>::operator<<(const eT val) | |
| { | | { | |
| return mat_injector< Mat<eT> >(*this, val); | | return mat_injector< Mat<eT> >(*this, val); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| mat_injector< Mat<eT> > | | mat_injector< Mat<eT> > | |
|
| Mat<eT>::operator<<(const injector_helper x) | | Mat<eT>::operator<<(const injector_end_of_row& x) | |
| { | | { | |
| return mat_injector< Mat<eT> >(*this, x); | | return mat_injector< Mat<eT> >(*this, x); | |
| } | | } | |
| | | | |
| //! creation of subview (row vector) | | //! creation of subview (row vector) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_row<eT> | | subview_row<eT> | |
| Mat<eT>::row(const u32 row_num) | | Mat<eT>::row(const u32 row_num) | |
| { | | { | |
| | | | |
| skipping to change at line 1104 | | skipping to change at line 1486 | |
| Mat<eT>::row(const u32 row_num) const | | Mat<eT>::row(const u32 row_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" ); | | arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" ); | |
| | | | |
| return subview_row<eT>(*this, row_num); | | return subview_row<eT>(*this, row_num); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| subview_row<eT> | | subview_row<eT> | |
|
| Mat<eT>::operator()(const u32 row_num, const span_helper) | | Mat<eT>::operator()(const u32 row_num, const span& col_span) | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (row_num >= n_rows), "Mat::operator(): row out of bound | | | |
| s" ); | | | |
| | | | |
| return subview_row<eT>(*this, row_num); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| arma_inline | | | |
| const subview_row<eT> | | | |
| Mat<eT>::operator()(const u32 row_num, const span_helper) const | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (row_num >= n_rows), "Mat::operator(): row out of bound | | const bool col_all = col_span.whole; | |
| s" ); | | | |
| | | | |
| return subview_row<eT>(*this, row_num); | | | |
| } | | | |
| | | | |
|
| template<typename eT> | | const u32 local_n_cols = n_cols; | |
| arma_inline | | | |
| subview_row<eT> | | | |
| Mat<eT>::operator()(const u32 row_num, const span& col_span) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| const u32 a = col_span.a; | | const u32 in_col1 = col_all ? 0 : col_span.a; | |
| const u32 b = col_span.b; | | const u32 in_col2 = col_span.b; | |
| | | const u32 submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (row_num >= n_rows) || (a > b) || (b >= n_cols), | | (row_num >= n_rows) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | |
| | | ) | |
| | | , | |
| "Mat::operator(): indices out of bounds or incorrectly used" | | "Mat::operator(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_row<eT>(*this, row_num, a, b); | | return subview_row<eT>(*this, row_num, in_col1, submat_n_cols); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| const subview_row<eT> | | const subview_row<eT> | |
| Mat<eT>::operator()(const u32 row_num, const span& col_span) const | | Mat<eT>::operator()(const u32 row_num, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 a = col_span.a; | | const bool col_all = col_span.whole; | |
| const u32 b = col_span.b; | | | |
| | | const u32 local_n_cols = n_cols; | |
| | | | |
| | | const u32 in_col1 = col_all ? 0 : col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | const u32 submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (row_num >= n_rows) || (a > b) || (b >= n_cols), | | (row_num >= n_rows) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | |
| | | ) | |
| | | , | |
| "Mat::operator(): indices out of bounds or incorrectly used" | | "Mat::operator(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_row<eT>(*this, row_num, a, b); | | return subview_row<eT>(*this, row_num, in_col1, submat_n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview (column vector) | | //! creation of subview (column vector) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_col<eT> | | subview_col<eT> | |
| Mat<eT>::col(const u32 col_num) | | Mat<eT>::col(const u32 col_num) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 1192 | | skipping to change at line 1566 | |
| Mat<eT>::col(const u32 col_num) const | | Mat<eT>::col(const u32 col_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds"); | | arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds"); | |
| | | | |
| return subview_col<eT>(*this, col_num); | | return subview_col<eT>(*this, col_num); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| subview_col<eT> | | subview_col<eT> | |
|
| Mat<eT>::operator()(const span_helper, const u32 col_num) | | Mat<eT>::operator()(const span& row_span, const u32 col_num) | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( col_num >= n_cols, "Mat::operator(): column out of boun | | | |
| ds"); | | | |
| | | | |
| return subview_col<eT>(*this, col_num); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| arma_inline | | | |
| const subview_col<eT> | | | |
| Mat<eT>::operator()(const span_helper, const u32 col_num) const | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( col_num >= n_cols, "Mat::operator(): column out of boun
ds"); | | const bool row_all = row_span.whole; | |
| | | | |
|
| return subview_col<eT>(*this, col_num); | | const u32 local_n_rows = n_rows; | |
| } | | | |
| | | | |
|
| template<typename eT> | | const u32 in_row1 = row_all ? 0 : row_span.a; | |
| arma_inline | | const u32 in_row2 = row_span.b; | |
| subview_col<eT> | | const u32 submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; | |
| Mat<eT>::operator()(const span& row_span, const u32 col_num) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const u32 a = row_span.a; | | | |
| const u32 b = row_span.b; | | | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (col_num >= n_cols) || (a > b) || (b >= n_rows), | | (col_num >= n_cols) | |
| | | || | |
| | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | |
| | | ) | |
| | | , | |
| "Mat::operator(): indices out of bounds or incorrectly used" | | "Mat::operator(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_col<eT>(*this, col_num, a, b); | | return subview_col<eT>(*this, col_num, in_row1, submat_n_rows); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| const subview_col<eT> | | const subview_col<eT> | |
| Mat<eT>::operator()(const span& row_span, const u32 col_num) const | | Mat<eT>::operator()(const span& row_span, const u32 col_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 a = row_span.a; | | const bool row_all = row_span.whole; | |
| const u32 b = row_span.b; | | | |
| | | const u32 local_n_rows = n_rows; | |
| | | | |
| | | const u32 in_row1 = row_all ? 0 : row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | const u32 submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (col_num >= n_cols) || (a > b) || (b >= n_rows), | | (col_num >= n_cols) | |
| | | || | |
| | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | |
| | | ) | |
| | | , | |
| "Mat::operator(): indices out of bounds or incorrectly used" | | "Mat::operator(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_col<eT>(*this, col_num, a, b); | | return subview_col<eT>(*this, col_num, in_row1, submat_n_rows); | |
| } | | } | |
| | | | |
| //! create a Col object which uses memory from an existing matrix object. | | //! create a Col object which uses memory from an existing matrix object. | |
| //! this approach is currently not alias safe | | //! this approach is currently not alias safe | |
| //! and does not take into account that the parent matrix object could be d
eleted. | | //! and does not take into account that the parent matrix object could be d
eleted. | |
| //! if deleted memory is accessed by the created Col object, | | //! if deleted memory is accessed by the created Col object, | |
| //! it will cause memory corruption and/or a crash | | //! it will cause memory corruption and/or a crash | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT> | | Col<eT> | |
| | | | |
| skipping to change at line 1301 | | skipping to change at line 1667 | |
| Mat<eT>::rows(const u32 in_row1, const u32 in_row2) | | Mat<eT>::rows(const u32 in_row1, const u32 in_row2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_row2 >= n_rows), | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| "Mat::rows(): indices out of bounds or incorrectly used" | | "Mat::rows(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, 0, in_row2, ((n_cols>0) ? n_cols-1 : 0 | | const u32 subview_n_rows = in_row2 - in_row1 + 1; | |
| ) ); | | | |
| | | return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols ); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix comprised of specified row vectors) | | //! creation of subview (submatrix comprised of specified row vectors) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::rows(const u32 in_row1, const u32 in_row2) const | | Mat<eT>::rows(const u32 in_row1, const u32 in_row2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_row2 >= n_rows), | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| "Mat::rows(): indices out of bounds or incorrectly used" | | "Mat::rows(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, 0, in_row2, ((n_cols>0) ? n_cols-1 : 0 | | const u32 subview_n_rows = in_row2 - in_row1 + 1; | |
| ) ); | | | |
| | | return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols ); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix comprised of specified column vectors) | | //! creation of subview (submatrix comprised of specified column vectors) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview<eT> | | subview<eT> | |
| Mat<eT>::cols(const u32 in_col1, const u32 in_col2) | | Mat<eT>::cols(const u32 in_col1, const u32 in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_col1 > in_col2) || (in_col2 >= n_cols), | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| "Mat::cols(): indices out of bounds or incorrectly used" | | "Mat::cols(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, 0, in_col1, ((n_rows>0) ? n_rows-1 : 0), in_col | | const u32 subview_n_cols = in_col2 - in_col1 + 1; | |
| 2); | | | |
| | | return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix comprised of specified column vectors) | | //! creation of subview (submatrix comprised of specified column vectors) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::cols(const u32 in_col1, const u32 in_col2) const | | Mat<eT>::cols(const u32 in_col1, const u32 in_col2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_col1 > in_col2) || (in_col2 >= n_cols), | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| "Mat::cols(): indices out of bounds or incorrectly used" | | "Mat::cols(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, 0, in_col1, ((n_rows>0) ? n_rows-1 : 0), in_col | | const u32 subview_n_cols = in_col2 - in_col1 + 1; | |
| 2); | | | |
| | | return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix) | | //! creation of subview (submatrix) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview<eT> | | subview<eT> | |
| Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, co
nst u32 in_col2) | | Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, co
nst u32 in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (
in_col2 >= n_cols), | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (
in_col2 >= n_cols), | |
| "Mat::submat(): indices out of bounds or incorrectly used" | | "Mat::submat(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | | const u32 subview_n_rows = in_row2 - in_row1 + 1; | |
| | | const u32 subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_col | |
| | | s); | |
| } | | } | |
| | | | |
| //! creation of subview (generic submatrix) | | //! creation of subview (generic submatrix) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, co
nst u32 in_col2) const | | Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, co
nst u32 in_col2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (
in_col2 >= n_cols), | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (
in_col2 >= n_cols), | |
| "Mat::submat(): indices out of bounds or incorrectly used" | | "Mat::submat(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | | const u32 subview_n_rows = in_row2 - in_row1 + 1; | |
| | | const u32 subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_col | |
| | | s); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix) | | //! creation of subview (submatrix) | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| subview<eT> | | subview<eT> | |
| Mat<eT>::submat(const span& row_span, const span& col_span) | | Mat<eT>::submat(const span& row_span, const span& col_span) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 in_row1 = row_span.a; | | const bool row_all = row_span.whole; | |
| const u32 in_row2 = row_span.b; | | const bool col_all = col_span.whole; | |
| | | | |
|
| const u32 in_col1 = col_span.a; | | const u32 local_n_rows = n_rows; | |
| const u32 in_col2 = col_span.b; | | const u32 local_n_cols = n_cols; | |
| | | | |
| | | const u32 in_row1 = row_all ? 0 : row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | const u32 submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; | |
| | | | |
| | | const u32 in_col1 = col_all ? 0 : col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | const u32 submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | |
| in_col2 >= n_cols), | | ) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | |
| | | ) | |
| | | , | |
| "Mat::submat(): indices out of bounds or incorrectly used" | | "Mat::submat(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | | return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols)
; | |
| } | | } | |
| | | | |
| //! creation of subview (generic submatrix) | | //! creation of subview (generic submatrix) | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::submat(const span& row_span, const span& col_span) const | | Mat<eT>::submat(const span& row_span, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 in_row1 = row_span.a; | | const bool row_all = row_span.whole; | |
| const u32 in_row2 = row_span.b; | | const bool col_all = col_span.whole; | |
| | | | |
|
| const u32 in_col1 = col_span.a; | | const u32 local_n_rows = n_rows; | |
| const u32 in_col2 = col_span.b; | | const u32 local_n_cols = n_cols; | |
| | | | |
| | | const u32 in_row1 = row_all ? 0 : row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | const u32 submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; | |
| | | | |
| | | const u32 in_col1 = col_all ? 0 : col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | const u32 submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | |
| in_col2 >= n_cols), | | ) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | |
| | | ) | |
| | | , | |
| "Mat::submat(): indices out of bounds or incorrectly used" | | "Mat::submat(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | | return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols)
; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| subview<eT> | | subview<eT> | |
| Mat<eT>::operator()(const span& row_span, const span& col_span) | | Mat<eT>::operator()(const span& row_span, const span& col_span) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| return submat(row_span, col_span); | | return (*this).submat(row_span, col_span); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::operator()(const span& row_span, const span& col_span) const | | Mat<eT>::operator()(const span& row_span, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| return submat(row_span, col_span); | | return (*this).submat(row_span, col_span); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| arma_inline | | arma_inline | |
| subview_elem1<eT,T1> | | subview_elem1<eT,T1> | |
| Mat<eT>::elem(const Base<u32,T1>& a) | | Mat<eT>::elem(const Base<u32,T1>& a) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 2782 | | skipping to change at line 3184 | |
| | | | |
| //! returns true if the given start and end indices are currently in range | | //! returns true if the given start and end indices are currently in range | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| Mat<eT>::in_range(const span& x) const | | Mat<eT>::in_range(const span& x) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 a = x.a; | | if(x.whole == true) | |
| const u32 b = x.b; | | { | |
| | | return true; | |
| | | } | |
| | | else | |
| | | { | |
| | | const u32 a = x.a; | |
| | | const u32 b = x.b; | |
| | | | |
|
| return ( (a <= b) && (b < n_elem) ); | | return ( (a <= b) && (b < n_elem) ); | |
| | | } | |
| } | | } | |
| | | | |
| //! returns true if the given location is currently in range | | //! returns true if the given location is currently in range | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| Mat<eT>::in_range(const u32 in_row, const u32 in_col) const | | Mat<eT>::in_range(const u32 in_row, const u32 in_col) const | |
| { | | { | |
| return ( (in_row < n_rows) && (in_col < n_cols) ); | | return ( (in_row < n_rows) && (in_col < n_cols) ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| Mat<eT>::in_range(const span& row_span, const u32 in_col) const | | Mat<eT>::in_range(const span& row_span, const u32 in_col) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 in_row1 = row_span.a; | | if(row_span.whole == true) | |
| const u32 in_row2 = row_span.b; | | { | |
| | | return (in_col < n_cols); | |
| return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) | | } | |
| ); | | else | |
| } | | { | |
| | | const u32 in_row1 = row_span.a; | |
| template<typename eT> | | const u32 in_row2 = row_span.b; | |
| arma_inline | | | |
| arma_warn_unused | | | |
| bool | | | |
| Mat<eT>::in_range(const span& row_span, const span_helper) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const u32 in_row1 = row_span.a; | | | |
| const u32 in_row2 = row_span.b; | | | |
| | | | |
|
| return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (n_cols > 0) ); | | return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols | |
| | | ) ); | |
| | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| Mat<eT>::in_range(const u32 in_row, const span& col_span) const | | Mat<eT>::in_range(const u32 in_row, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 in_col1 = col_span.a; | | if(col_span.whole == true) | |
| const u32 in_col2 = col_span.b; | | { | |
| | | return (in_row < n_rows); | |
| return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) | | } | |
| ); | | else | |
| } | | { | |
| | | const u32 in_col1 = col_span.a; | |
| template<typename eT> | | const u32 in_col2 = col_span.b; | |
| arma_inline | | | |
| arma_warn_unused | | | |
| bool | | | |
| Mat<eT>::in_range(const span_helper, const span& col_span) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const u32 in_col1 = col_span.a; | | | |
| const u32 in_col2 = col_span.b; | | | |
| | | | |
|
| return ( (n_rows > 0) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); | | return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols | |
| | | ) ); | |
| | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| Mat<eT>::in_range(const span& row_span, const span& col_span) const | | Mat<eT>::in_range(const span& row_span, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 in_row1 = row_span.a; | | const u32 in_row1 = row_span.a; | |
| const u32 in_row2 = row_span.b; | | const u32 in_row2 = row_span.b; | |
| | | | |
| const u32 in_col1 = col_span.a; | | const u32 in_col1 = col_span.a; | |
| const u32 in_col2 = col_span.b; | | const u32 in_col2 = col_span.b; | |
| | | | |
|
| return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col1 <= in_col | | const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (i | |
| 2) && (in_col2 < n_cols) ); | | n_row2 < n_rows) ); | |
| | | const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (i | |
| | | n_col2 < n_cols) ); | |
| | | | |
| | | return ( (rows_ok == true) && (cols_ok == true) ); | |
| } | | } | |
| | | | |
| //! returns a pointer to array of eTs for a specified column; no bounds che
ck | | //! returns a pointer to array of eTs for a specified column; no bounds che
ck | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT* | | eT* | |
| Mat<eT>::colptr(const u32 in_col) | | Mat<eT>::colptr(const u32 in_col) | |
| { | | { | |
| return & access::rw(mem[in_col*n_rows]); | | return & access::rw(mem[in_col*n_rows]); | |
| | | | |
End of changes. 55 change blocks. |
| 145 lines changed or deleted | | 564 lines changed or added | |
|
| Mat_proto.hpp | | Mat_proto.hpp | |
| | | | |
| skipping to change at line 71 | | skipping to change at line 71 | |
| arma_inline const Mat& operator/=(const eT val); | | arma_inline const Mat& operator/=(const eT val); | |
| | | | |
| inline Mat(const Mat& m); | | inline Mat(const Mat& m); | |
| inline const Mat& operator=(const Mat& m); | | inline const Mat& operator=(const Mat& m); | |
| inline const Mat& operator+=(const Mat& m); | | inline const Mat& operator+=(const Mat& m); | |
| inline const Mat& operator-=(const Mat& m); | | inline const Mat& operator-=(const Mat& m); | |
| inline const Mat& operator*=(const Mat& m); | | inline const Mat& operator*=(const Mat& m); | |
| inline const Mat& operator%=(const Mat& m); | | inline const Mat& operator%=(const Mat& m); | |
| inline const Mat& operator/=(const Mat& m); | | inline const Mat& operator/=(const Mat& m); | |
| | | | |
|
| | | template<typename T1> inline Mat(const BaseCube<eT,T1>& | |
| | | X); | |
| | | template<typename T1> inline const Mat& operator=(const BaseCube<eT,T1>& | |
| | | X); | |
| | | template<typename T1> inline const Mat& operator+=(const BaseCube<eT,T1>& | |
| | | X); | |
| | | template<typename T1> inline const Mat& operator-=(const BaseCube<eT,T1>& | |
| | | X); | |
| | | template<typename T1> inline const Mat& operator*=(const BaseCube<eT,T1>& | |
| | | X); | |
| | | template<typename T1> inline const Mat& operator%=(const BaseCube<eT,T1>& | |
| | | X); | |
| | | template<typename T1> inline const Mat& operator/=(const BaseCube<eT,T1>& | |
| | | X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline explicit Mat(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | | inline explicit Mat(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | |
| | | | |
| inline Mat(const subview<eT>& X); | | inline Mat(const subview<eT>& X); | |
| inline const Mat& operator=(const subview<eT>& X); | | inline const Mat& operator=(const subview<eT>& X); | |
| inline const Mat& operator+=(const subview<eT>& X); | | inline const Mat& operator+=(const subview<eT>& X); | |
| inline const Mat& operator-=(const subview<eT>& X); | | inline const Mat& operator-=(const subview<eT>& X); | |
| inline const Mat& operator*=(const subview<eT>& X); | | inline const Mat& operator*=(const subview<eT>& X); | |
| inline const Mat& operator%=(const subview<eT>& X); | | inline const Mat& operator%=(const subview<eT>& X); | |
| inline const Mat& operator/=(const subview<eT>& X); | | inline const Mat& operator/=(const subview<eT>& X); | |
| | | | |
| skipping to change at line 109 | | skipping to change at line 117 | |
| | | | |
| template<typename T1> inline Mat(const subview_elem1<eT
,T1>& X); | | template<typename T1> inline Mat(const subview_elem1<eT
,T1>& X); | |
| template<typename T1> inline const Mat& operator= (const subview_elem1<eT
,T1>& X); | | template<typename T1> inline const Mat& operator= (const subview_elem1<eT
,T1>& X); | |
| template<typename T1> inline const Mat& operator+=(const subview_elem1<eT
,T1>& X); | | template<typename T1> inline const Mat& operator+=(const subview_elem1<eT
,T1>& X); | |
| template<typename T1> inline const Mat& operator-=(const subview_elem1<eT
,T1>& X); | | template<typename T1> inline const Mat& operator-=(const subview_elem1<eT
,T1>& X); | |
| template<typename T1> inline const Mat& operator*=(const subview_elem1<eT
,T1>& X); | | template<typename T1> inline const Mat& operator*=(const subview_elem1<eT
,T1>& X); | |
| template<typename T1> inline const Mat& operator%=(const subview_elem1<eT
,T1>& X); | | template<typename T1> inline const Mat& operator%=(const subview_elem1<eT
,T1>& X); | |
| template<typename T1> inline const Mat& operator/=(const subview_elem1<eT
,T1>& X); | | template<typename T1> inline const Mat& operator/=(const subview_elem1<eT
,T1>& X); | |
| | | | |
| inline mat_injector<Mat> operator<<(const eT val); | | inline mat_injector<Mat> operator<<(const eT val); | |
|
| inline mat_injector<Mat> operator<<(const injector_helper x); | | inline mat_injector<Mat> operator<<(const injector_end_of_row& x); | |
| | | | |
| arma_inline subview_row<eT> row(const u32 row_num); | | arma_inline subview_row<eT> row(const u32 row_num); | |
| arma_inline const subview_row<eT> row(const u32 row_num) const; | | arma_inline const subview_row<eT> row(const u32 row_num) const; | |
| | | | |
|
| arma_inline subview_row<eT> operator()(const u32 row_num, const spa | | inline subview_row<eT> operator()(const u32 row_num, const spa | |
| n_helper); | | n& col_span); | |
| arma_inline const subview_row<eT> operator()(const u32 row_num, const spa | | inline const subview_row<eT> operator()(const u32 row_num, const spa | |
| n_helper) const; | | n& col_span) const; | |
| | | | |
| arma_inline subview_row<eT> operator()(const u32 row_num, const spa | | | |
| n& col_span); | | | |
| arma_inline const subview_row<eT> operator()(const u32 row_num, const spa | | | |
| n& col_span) const; | | | |
| | | | |
| arma_inline subview_col<eT> col(const u32 col_num); | | arma_inline subview_col<eT> col(const u32 col_num); | |
| arma_inline const subview_col<eT> col(const u32 col_num) const; | | arma_inline const subview_col<eT> col(const u32 col_num) const; | |
| | | | |
|
| arma_inline subview_col<eT> operator()(const span_helper, const | | inline subview_col<eT> operator()(const span& row_span, const | |
| u32 col_num); | | u32 col_num); | |
| arma_inline const subview_col<eT> operator()(const span_helper, const | | inline const subview_col<eT> operator()(const span& row_span, const | |
| u32 col_num) const; | | u32 col_num) const; | |
| | | | |
| arma_inline subview_col<eT> operator()(const span& row_span, const | | | |
| u32 col_num); | | | |
| arma_inline const subview_col<eT> operator()(const span& row_span, const | | | |
| u32 col_num) const; | | | |
| | | | |
| inline Col<eT> unsafe_col(const u32 col_num); | | inline Col<eT> unsafe_col(const u32 col_num); | |
| inline const Col<eT> unsafe_col(const u32 col_num) const; | | inline const Col<eT> unsafe_col(const u32 col_num) const; | |
| | | | |
| arma_inline subview<eT> rows(const u32 in_row1, const u32 in_row2); | | arma_inline subview<eT> rows(const u32 in_row1, const u32 in_row2); | |
| arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2)
const; | | arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2)
const; | |
| | | | |
| arma_inline subview<eT> cols(const u32 in_col1, const u32 in_col2); | | arma_inline subview<eT> cols(const u32 in_col1, const u32 in_col2); | |
| arma_inline const subview<eT> cols(const u32 in_col1, const u32 in_col2)
const; | | arma_inline const subview<eT> cols(const u32 in_col1, const u32 in_col2)
const; | |
| | | | |
| arma_inline subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2); | | arma_inline subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2); | |
| arma_inline const subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2) const; | | arma_inline const subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2) const; | |
| | | | |
|
| arma_inline subview<eT> submat (const span& row_span, const span | | inline subview<eT> submat (const span& row_span, const span | |
| & col_span); | | & col_span); | |
| arma_inline const subview<eT> submat (const span& row_span, const span | | inline const subview<eT> submat (const span& row_span, const span | |
| & col_span) const; | | & col_span) const; | |
| | | | |
|
| arma_inline subview<eT> operator()(const span& row_span, const span | | inline subview<eT> operator()(const span& row_span, const span | |
| & col_span); | | & col_span); | |
| arma_inline const subview<eT> operator()(const span& row_span, const span | | inline const subview<eT> operator()(const span& row_span, const span | |
| & col_span) const; | | & col_span) const; | |
| | | | |
| template<typename T1> arma_inline subview_elem1<eT,T1> elem(const B
ase<u32,T1>& a); | | template<typename T1> arma_inline subview_elem1<eT,T1> elem(const B
ase<u32,T1>& a); | |
| template<typename T1> arma_inline const subview_elem1<eT,T1> elem(const B
ase<u32,T1>& a) const; | | template<typename T1> arma_inline const subview_elem1<eT,T1> elem(const B
ase<u32,T1>& a) const; | |
| | | | |
| // template<typename T1, typename T2> arma_inline subview_elem2<eT,
T1,T2> submat(const Base<u32,T1>& a, const Base<u32,T2>& b); | | // template<typename T1, typename T2> arma_inline subview_elem2<eT,
T1,T2> submat(const Base<u32,T1>& a, const Base<u32,T2>& b); | |
| // template<typename T1, typename T2> arma_inline const subview_elem2<eT,
T1,T2> submat(const Base<u32,T1>& a, const Base<u32,T2>& b) const; | | // template<typename T1, typename T2> arma_inline const subview_elem2<eT,
T1,T2> submat(const Base<u32,T1>& a, const Base<u32,T2>& b) const; | |
| | | | |
| arma_inline diagview<eT> diag(const s32 in_id = 0); | | arma_inline diagview<eT> diag(const s32 in_id = 0); | |
| arma_inline const diagview<eT> diag(const s32 in_id = 0) const; | | arma_inline const diagview<eT> diag(const s32 in_id = 0) const; | |
| | | | |
| | | | |
| skipping to change at line 251 | | skipping to change at line 253 | |
| arma_inline arma_warn_unused bool is_vec() const; | | arma_inline arma_warn_unused bool is_vec() const; | |
| arma_inline arma_warn_unused bool is_square() const; | | arma_inline arma_warn_unused bool is_square() const; | |
| inline arma_warn_unused bool is_finite() const; | | inline arma_warn_unused bool is_finite() const; | |
| | | | |
| // TODO: test and add expanded .in_range() to user documentation | | // TODO: test and add expanded .in_range() to user documentation | |
| arma_inline arma_warn_unused bool in_range(const u32 i) const; | | arma_inline arma_warn_unused bool in_range(const u32 i) const; | |
| arma_inline arma_warn_unused bool in_range(const span& x) const; | | arma_inline arma_warn_unused bool in_range(const span& x) const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const u32 in_row, co
nst u32 in_col ) const; | | arma_inline arma_warn_unused bool in_range(const u32 in_row, co
nst u32 in_col ) const; | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, co
nst u32 in_col ) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, co
nst u32 in_col ) const; | |
|
| arma_inline arma_warn_unused bool in_range(const span& row_span, co
nst span_helper junk ) const; | | | |
| arma_inline arma_warn_unused bool in_range(const u32 in_row, co
nst span& col_span) const; | | arma_inline arma_warn_unused bool in_range(const u32 in_row, co
nst span& col_span) const; | |
|
| arma_inline arma_warn_unused bool in_range(const span_helper junk, co
nst span& col_span) const; | | | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, co
nst span& col_span) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, co
nst span& col_span) const; | |
| | | | |
| arma_inline arma_warn_unused eT* colptr(const u32 in_col); | | arma_inline arma_warn_unused eT* colptr(const u32 in_col); | |
| arma_inline arma_warn_unused const eT* colptr(const u32 in_col) const; | | arma_inline arma_warn_unused const eT* colptr(const u32 in_col) const; | |
| | | | |
| arma_inline arma_warn_unused eT* memptr(); | | arma_inline arma_warn_unused eT* memptr(); | |
| arma_inline arma_warn_unused const eT* memptr() const; | | arma_inline arma_warn_unused const eT* memptr() const; | |
| | | | |
| inline void print(const std::string extra_text = "") const; | | inline void print(const std::string extra_text = "") const; | |
| inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | | inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | |
| | | | |
End of changes. 8 change blocks. |
| 29 lines changed or deleted | | 32 lines changed or added | |
|
| debug.hpp | | debug.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| static std::ostream* log_stream = &(std::cout); | | static std::ostream* log_stream = &(std::cout); | |
| | | | |
| if(user_stream != NULL) | | if(user_stream != NULL) | |
| { | | { | |
| log_stream = user_stream; | | log_stream = user_stream; | |
| } | | } | |
| | | | |
| return *log_stream; | | return *log_stream; | |
| } | | } | |
| | | | |
|
| // TODO: add to user documentation | | | |
| inline | | inline | |
| void | | void | |
| set_log_stream(std::ostream& user_stream) | | set_log_stream(std::ostream& user_stream) | |
| { | | { | |
| arma_log_stream<char>(&user_stream); | | arma_log_stream<char>(&user_stream); | |
| } | | } | |
| | | | |
|
| // TODO: add to user documentation | | | |
| inline | | inline | |
| std::ostream& | | std::ostream& | |
| get_log_stream() | | get_log_stream() | |
| { | | { | |
| return arma_log_stream<char>(NULL); | | return arma_log_stream<char>(NULL); | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_stop | | // arma_stop | |
| | | | |
| //! print a message to get_log_stream() and/or throw a run-time error excep
tion | | //! print a message to get_log_stream() and/or throw a run-time error excep
tion | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| arma_cold | | arma_cold | |
| arma_stop(const T1& x) | | arma_stop(const T1& x) | |
| { | | { | |
|
| get_log_stream().flush(); | | std::ostream& log_stream = get_log_stream(); | |
| | | | |
|
| get_log_stream() << '\n'; | | log_stream.flush(); | |
| get_log_stream() << "run-time error: " << x << '\n'; | | | |
| get_log_stream() << '\n'; | | log_stream << '\n'; | |
| get_log_stream().flush(); | | log_stream << "run-time error: " << x << '\n'; | |
| | | log_stream << '\n'; | |
| | | log_stream.flush(); | |
| | | | |
| throw std::runtime_error(""); | | throw std::runtime_error(""); | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_print | | // arma_print | |
| | | | |
| inline | | inline | |
| void | | void | |
| arma_cold | | arma_cold | |
| | | | |
| skipping to change at line 212 | | skipping to change at line 212 | |
| arma_hot | | arma_hot | |
| arma_check(const bool state, const T1& x, const T2& y) | | arma_check(const bool state, const T1& x, const T2& y) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| arma_stop( std::string(x) + std::string(y) ); | | arma_stop( std::string(x) + std::string(y) ); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
|
| // functions for checking whether two matrices have the same dimensions | | // functions for generating strings indicating size errors | |
| | | | |
| inline | | inline | |
| std::string | | std::string | |
| arma_cold | | arma_cold | |
| arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32
B_n_rows, const u32 B_n_cols, const char* x) | | arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32
B_n_rows, const u32 B_n_cols, const char* x) | |
| { | | { | |
| std::stringstream tmp; | | std::stringstream tmp; | |
| | | | |
|
| tmp << x << ": incompatible matrix dimensions: (" << A_n_rows << ',' << A | | tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_ | |
| _n_cols << ") and (" << B_n_rows << ',' << B_n_cols << ')'; | | n_cols << " and " << B_n_rows << 'x' << B_n_cols; | |
| | | | |
| | | return tmp.str(); | |
| | | } | |
| | | | |
| | | inline | |
| | | arma_cold | |
| | | std::string | |
| | | arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 | |
| | | A_n_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, | |
| | | const char* x) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_ | |
| | | cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x' | |
| | | << B_n_slices; | |
| | | | |
| | | return tmp.str(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_cold | |
| | | std::string | |
| | | arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, cons | |
| | | t char* x) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": interpreting matrix as cube with dimenensions: " | |
| | | << A.n_rows << 'x' << A.n_cols << 'x' << 1 | |
| | | << " or " | |
| | | << A.n_rows << 'x' << 1 << 'x' << A.n_cols | |
| | | << " or " | |
| | | << 1 << 'x' << A.n_cols << 'x' << A.n_rows | |
| | | << " is incompatible with cube dimensions: " | |
| | | << Q.n_rows << 'x' << Q.n_cols << 'x' << Q.n_slices; | |
| | | | |
| return tmp.str(); | | return tmp.str(); | |
| } | | } | |
| | | | |
|
| | | // | |
| | | // functions for checking whether two matrices have the same dimensions | |
| | | | |
| inline | | inline | |
| void | | void | |
| arma_hot | | arma_hot | |
| arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n
_rows, const u32 B_n_cols, const char* x) | | arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n
_rows, const u32 B_n_cols, const char* x) | |
| { | | { | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| skipping to change at line 405 | | skipping to change at line 441 | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // functions for checking whether two cubes have the same dimensions | | // functions for checking whether two cubes have the same dimensions | |
| | | | |
| inline | | inline | |
|
| arma_cold | | | |
| std::string | | | |
| arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 | | | |
| A_n_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, | | | |
| const char* x) | | | |
| { | | | |
| std::stringstream tmp; | | | |
| | | | |
| tmp << x << ": incompatible cube dimensions: (" << A_n_rows << ',' << A_n | | | |
| _cols << ',' << A_n_slices << ") and (" << B_n_rows << ',' << B_n_cols << ' | | | |
| ,' << B_n_slices << ')'; | | | |
| | | | |
| return tmp.str(); | | | |
| } | | | |
| | | | |
| inline | | | |
| void | | void | |
| arma_hot | | arma_hot | |
| arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n
_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, cons
t char* x) | | arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n
_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, cons
t char* x) | |
| { | | { | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_
n_slices) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_
n_slices) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_
n_rows, B_n_cols, B_n_slices, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_
n_rows, B_n_cols, B_n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 548 | | skipping to change at line 572 | |
| void | | void | |
| arma_hot | | arma_hot | |
| arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const
char* x) | | arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const
char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices)
) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices)
) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
.n_cols, B.n_slices, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
.n_cols, B.n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | void | |
| | | arma_assert_cube_as_mat(const Mat<eT>& M, const T1& Q, const char* x, const | |
| | | bool check_compat_size) | |
| | | { | |
| | | const u32 Q_n_rows = Q.n_rows; | |
| | | const u32 Q_n_cols = Q.n_cols; | |
| | | const u32 Q_n_slices = Q.n_slices; | |
| | | | |
| | | const u32 M_vec_state = M.vec_state; | |
| | | | |
| | | if(M_vec_state == 0) | |
| | | { | |
| | | if( ( (Q_n_rows == 1) || (Q_n_cols == 1) || (Q_n_slices == 1) ) == fals | |
| | | e ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a matrix; one of the dimensions must be 1"; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(Q_n_slices == 1) | |
| | | { | |
| | | if( (M_vec_state == 1) && (Q_n_cols != 1) ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a column vector"; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | | |
| | | if( (M_vec_state == 2) && (Q_n_rows != 1) ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a row vector"; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if( (Q_n_cols != 1) && (Q_n_rows != 1) ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a vector"; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if(check_compat_size == true) | |
| | | { | |
| | | const u32 M_n_rows = M.n_rows; | |
| | | const u32 M_n_cols = M.n_cols; | |
| | | | |
| | | if(M_vec_state == 0) | |
| | | { | |
| | | if( | |
| | | ( | |
| | | ( (Q_n_rows == M_n_rows) && (Q_n_cols == M_n_cols) ) | |
| | | || | |
| | | ( (Q_n_rows == M_n_rows) && (Q_n_slices == M_n_cols) ) | |
| | | || | |
| | | ( (Q_n_cols == M_n_cols) && (Q_n_slices == M_n_rows) ) | |
| | | ) | |
| | | == false | |
| | | ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimenensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a matrix with dimensions " | |
| | | << M_n_rows << 'x' << M_n_cols; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(Q_n_slices == 1) | |
| | | { | |
| | | if( (M_vec_state == 1) && (Q_n_rows != M_n_rows) ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a column vector with dimensions " | |
| | | << M_n_rows << 'x' << M_n_cols; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | | |
| | | if( (M_vec_state == 2) && (Q_n_cols != M_n_cols) ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a row vector with dimensions " | |
| | | << M_n_rows << 'x' << M_n_cols; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if( ( (M_n_cols == Q_n_slices) || (M_n_rows == Q_n_slices) ) == fal | |
| | | se ) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x | |
| | | << ": can't interpret cube with dimensions " | |
| | | << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices | |
| | | << " as a vector with dimensions " | |
| | | << M_n_rows << 'x' << M_n_cols; | |
| | | | |
| | | arma_stop( tmp.str() ); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| // | | // | |
| // functions for checking whether two matrices have dimensions that are com
patible with the matrix multiply operation | | // functions for checking whether two matrices have dimensions that are com
patible with the matrix multiply operation | |
| | | | |
| inline | | inline | |
| void | | void | |
| arma_hot | | arma_hot | |
| arma_assert_mul_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_
rows, const u32 B_n_cols, const char* x) | | arma_assert_mul_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_
rows, const u32 B_n_cols, const char* x) | |
| { | | { | |
| if(A_n_cols != B_n_rows) | | if(A_n_cols != B_n_rows) | |
| { | | { | |
| | | | |
| skipping to change at line 652 | | skipping to change at line 823 | |
| #elif defined (_MSC_VER) | | #elif defined (_MSC_VER) | |
| #define ARMA_FNSIG __FUNCSIG__ | | #define ARMA_FNSIG __FUNCSIG__ | |
| #elif defined (ARMA_USE_BOOST) | | #elif defined (ARMA_USE_BOOST) | |
| #define ARMA_FNSIG BOOST_CURRENT_FUNCTION | | #define ARMA_FNSIG BOOST_CURRENT_FUNCTION | |
| #else | | #else | |
| #define ARMA_FNSIG "(unknown)" | | #define ARMA_FNSIG "(unknown)" | |
| #endif | | #endif | |
| | | | |
| #if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG) | | #if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG) | |
| | | | |
|
| #define arma_debug_print arma_print | | #define arma_debug_print arma_print | |
| #define arma_debug_warn arma_warn | | #define arma_debug_warn arma_warn | |
| #define arma_debug_check arma_check | | #define arma_debug_check arma_check | |
| #define arma_debug_assert_same_size arma_assert_same_size | | #define arma_debug_assert_same_size arma_assert_same_size | |
| #define arma_debug_assert_mul_size arma_assert_mul_size | | #define arma_debug_assert_mul_size arma_assert_mul_size | |
| | | #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat | |
| #else | | #else | |
| | | | |
| #undef ARMA_EXTRA_DEBUG | | #undef ARMA_EXTRA_DEBUG | |
| | | | |
|
| #define arma_debug_print true ? (void)0 : arma_print | | #define arma_debug_print true ? (void)0 : arma_print | |
| #define arma_debug_warn true ? (void)0 : arma_warn | | #define arma_debug_warn true ? (void)0 : arma_warn | |
| #define arma_debug_check true ? (void)0 : arma_check | | #define arma_debug_check true ? (void)0 : arma_check | |
| #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_siz | | #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_s | |
| e | | ize | |
| #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size | | #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_si | |
| | | ze | |
| | | #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_debug_assert_ | |
| | | cube_as_mat | |
| | | | |
| #endif | | #endif | |
| | | | |
| #if defined(ARMA_EXTRA_DEBUG) | | #if defined(ARMA_EXTRA_DEBUG) | |
| | | | |
| #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_b
ktprint | | #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_b
ktprint | |
| #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_t
hisprint | | #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_t
hisprint | |
| #define arma_extra_debug_print arma_print | | #define arma_extra_debug_print arma_print | |
| #define arma_extra_debug_warn arma_warn | | #define arma_extra_debug_warn arma_warn | |
| #define arma_extra_debug_check arma_check | | #define arma_extra_debug_check arma_check | |
| | | | |
End of changes. 12 change blocks. |
| 40 lines changed or deleted | | 218 lines changed or added | |
|
| field_meat.hpp | | field_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // Copyright (C) 2009-2010 Ian Cullinan | | // Copyright (C) 2009-2010 Ian Cullinan | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| skipping to change at line 272 | | skipping to change at line 272 | |
| inline | | inline | |
| field_injector< field<oT> > | | field_injector< field<oT> > | |
| field<oT>::operator<<(const oT& val) | | field<oT>::operator<<(const oT& val) | |
| { | | { | |
| return field_injector< field<oT> >(*this, val); | | return field_injector< field<oT> >(*this, val); | |
| } | | } | |
| | | | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| field_injector< field<oT> > | | field_injector< field<oT> > | |
|
| field<oT>::operator<<(const injector_helper x) | | field<oT>::operator<<(const injector_end_of_row& x) | |
| { | | { | |
| return field_injector< field<oT> >(*this, x); | | return field_injector< field<oT> >(*this, x); | |
| } | | } | |
| | | | |
| //! creation of subview_field (row of a field) | | //! creation of subview_field (row of a field) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| subview_field<oT> | | subview_field<oT> | |
| field<oT>::row(const u32 row_num) | | field<oT>::row(const u32 row_num) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds"
); | | arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds"
); | |
|
| return subview_field<oT>(*this, row_num, 0, row_num, n_cols-1); | | | |
| | | return subview_field<oT>(*this, row_num, 0, 1, n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview_field (row of a field) | | //! creation of subview_field (row of a field) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| const subview_field<oT> | | const subview_field<oT> | |
| field<oT>::row(const u32 row_num) const | | field<oT>::row(const u32 row_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds"
); | | arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds"
); | |
|
| return subview_field<oT>(*this, row_num, 0, row_num, n_cols-1); | | | |
| | | return subview_field<oT>(*this, row_num, 0, 1, n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview_field (column of a field) | | //! creation of subview_field (column of a field) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| subview_field<oT> | | subview_field<oT> | |
| field<oT>::col(const u32 col_num) | | field<oT>::col(const u32 col_num) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); | | arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); | |
|
| return subview_field<oT>(*this, 0, col_num, n_rows-1, col_num); | | | |
| | | return subview_field<oT>(*this, 0, col_num, n_rows, 1); | |
| } | | } | |
| | | | |
| //! creation of subview_field (column of a field) | | //! creation of subview_field (column of a field) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| const subview_field<oT> | | const subview_field<oT> | |
| field<oT>::col(const u32 col_num) const | | field<oT>::col(const u32 col_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); | | arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); | |
|
| return subview_field<oT>(*this, 0, col_num, n_rows-1, col_num); | | | |
| | | return subview_field<oT>(*this, 0, col_num, n_rows, 1); | |
| } | | } | |
| | | | |
| //! creation of subview_field (subfield comprised of specified rows) | | //! creation of subview_field (subfield comprised of specified rows) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| subview_field<oT> | | subview_field<oT> | |
| field<oT>::rows(const u32 in_row1, const u32 in_row2) | | field<oT>::rows(const u32 in_row1, const u32 in_row2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), | | ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), | |
| "field::rows(): indicies out of bounds or incorrectly used" | | "field::rows(): indicies out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_field<oT>(*this, in_row1, 0, in_row2, n_cols-1); | | const u32 subfield_n_rows = in_row2 - in_row1 + 1; | |
| | | | |
| | | return subview_field<oT>(*this, in_row1, 0, subfield_n_rows, n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview_field (subfield comprised of specified rows) | | //! creation of subview_field (subfield comprised of specified rows) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| const subview_field<oT> | | const subview_field<oT> | |
| field<oT>::rows(const u32 in_row1, const u32 in_row2) const | | field<oT>::rows(const u32 in_row1, const u32 in_row2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), | | ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), | |
| "field::rows(): indicies out of bounds or incorrectly used" | | "field::rows(): indicies out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_field<oT>(*this, in_row1, 0, in_row2, n_cols-1); | | const u32 subfield_n_rows = in_row2 - in_row1 + 1; | |
| | | | |
| | | return subview_field<oT>(*this, in_row1, 0, subfield_n_rows, n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview_field (subfield comprised of specified columns) | | //! creation of subview_field (subfield comprised of specified columns) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| subview_field<oT> | | subview_field<oT> | |
| field<oT>::cols(const u32 in_col1, const u32 in_col2) | | field<oT>::cols(const u32 in_col1, const u32 in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), | | ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), | |
| "field::cols(): indicies out of bounds or incorrectly used" | | "field::cols(): indicies out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_field<oT>(*this, 0, in_col1, n_rows-1, in_col2); | | const u32 subfield_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return subview_field<oT>(*this, 0, in_col1, n_rows, subfield_n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview_field (subfield comprised of specified columns) | | //! creation of subview_field (subfield comprised of specified columns) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| const subview_field<oT> | | const subview_field<oT> | |
| field<oT>::cols(const u32 in_col1, const u32 in_col2) const | | field<oT>::cols(const u32 in_col1, const u32 in_col2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), | | ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), | |
| "field::cols(): indicies out of bounds or incorrectly used" | | "field::cols(): indicies out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_field<oT>(*this, 0, in_col1, n_rows-1, in_col2); | | const u32 subfield_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return subview_field<oT>(*this, 0, in_col1, n_rows, subfield_n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview_field (subfield with arbitrary dimensions) | | //! creation of subview_field (subfield with arbitrary dimensions) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| subview_field<oT> | | subview_field<oT> | |
| field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2
, const u32 in_col2) | | field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2
, const u32 in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols), | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols), | |
| "field::subfield(): indices out of bounds or incorrectly used" | | "field::subfield(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2); | | const u32 subfield_n_rows = in_row2 - in_row1 + 1; | |
| | | const u32 subfield_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return subview_field<oT>(*this, in_row1, in_col1, subfield_n_rows, subfie | |
| | | ld_n_cols); | |
| } | | } | |
| | | | |
| //! creation of subview_field (generic submatrix) | | //! creation of subview_field (generic submatrix) | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| const subview_field<oT> | | const subview_field<oT> | |
| field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2
, const u32 in_col2) const | | field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2
, const u32 in_col2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols), | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols), | |
| "field::subfield(): indices out of bounds or incorrectly used" | | "field::subfield(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2); | | const u32 subfield_n_rows = in_row2 - in_row1 + 1; | |
| | | const u32 subfield_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return subview_field<oT>(*this, in_row1, in_col1, subfield_n_rows, subfie | |
| | | ld_n_cols); | |
| } | | } | |
| | | | |
| //! print contents of the field (to the cout stream), | | //! print contents of the field (to the cout stream), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the field class preserves the stream's flags | | //! the field class preserves the stream's flags | |
| //! but the associated operator<< function for type oT | | //! but the associated operator<< function for type oT | |
| //! may still modify the stream's parameters. | | //! may still modify the stream's parameters. | |
| //! NOTE: this function assumes that type oT can be printed, | | //! NOTE: this function assumes that type oT can be printed, | |
| //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" | | //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" | |
| //! has been defined. | | //! has been defined. | |
| | | | |
End of changes. 12 change blocks. |
| 13 lines changed or deleted | | 33 lines changed or added | |
|
| op_sort_meat.hpp | | op_sort_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup op_sort | | //! \addtogroup op_sort | |
| //! @{ | | //! @{ | |
| | | | |
|
| // using qsort() rather than std::sort() for now. | | | |
| // std::sort() will be used when a Random Access Iterator wrapper for plain | | | |
| arrays is ready, | | | |
| // otherwise using std::sort() would currently entail copying elements to/f | | | |
| rom std::vector | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class arma_qsort_helper | | class arma_ascend_sort_helper | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| static | | arma_inline | |
| int | | bool | |
| ascend_compare(const void* A_orig, const void* B_orig) | | operator() (eT a, eT b) const | |
| { | | { | |
|
| const eT& A = *(static_cast<const eT*>(A_orig)); | | return (a < b); | |
| const eT& B = *(static_cast<const eT*>(B_orig)); | | | |
| | | | |
| if(A < B) | | | |
| { | | | |
| return -1; | | | |
| } | | | |
| else | | | |
| if(A > B) | | | |
| { | | | |
| return +1; | | | |
| } | | | |
| else | | | |
| { | | | |
| return 0; | | | |
| } | | | |
| } | | } | |
|
| | | }; | |
| | | | |
|
| static | | template<typename eT> | |
| int | | class arma_descend_sort_helper | |
| descend_compare(const void* A_orig, const void* B_orig) | | { | |
| { | | public: | |
| const eT& A = *(static_cast<const eT*>(A_orig)); | | | |
| const eT& B = *(static_cast<const eT*>(B_orig)); | | | |
| | | | |
|
| if(A < B) | | arma_inline | |
| { | | bool | |
| return +1; | | operator() (eT a, eT b) const | |
| } | | { | |
| else | | return (a > b); | |
| if(A > B) | | | |
| { | | | |
| return -1; | | | |
| } | | | |
| else | | | |
| { | | | |
| return 0; | | | |
| } | | | |
| } | | } | |
|
| | | | |
| }; | | }; | |
| | | | |
|
| //template<> | | | |
| template<typename T> | | template<typename T> | |
|
| class arma_qsort_helper< std::complex<T> > | | class arma_ascend_sort_helper< std::complex<T> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename std::complex<T> eT; | | typedef typename std::complex<T> eT; | |
| | | | |
|
| static | | inline | |
| int | | bool | |
| ascend_compare(const void* A_orig, const void* B_orig) | | operator() (const eT& a, const eT& b) const | |
| { | | { | |
|
| const eT& A = *(static_cast<const eT*>(A_orig)); | | return (std::abs(a) < std::abs(b)); | |
| const eT& B = *(static_cast<const eT*>(B_orig)); | | | |
| | | | |
| const T abs_A = std::abs(A); | | | |
| const T abs_B = std::abs(B); | | | |
| | | | |
| if(abs_A < abs_B) | | | |
| { | | | |
| return -1; | | | |
| } | | | |
| else | | | |
| if(abs_A > abs_B) | | | |
| { | | | |
| return +1; | | | |
| } | | | |
| else | | | |
| { | | | |
| return 0; | | | |
| } | | | |
| } | | } | |
|
| | | }; | |
| | | | |
|
| static | | template<typename T> | |
| int | | class arma_descend_sort_helper< std::complex<T> > | |
| descend_compare(const void* A_orig, const void* B_orig) | | { | |
| { | | public: | |
| const eT& A = *(static_cast<const eT*>(A_orig)); | | | |
| const eT& B = *(static_cast<const eT*>(B_orig)); | | | |
| | | | |
|
| const T abs_A = std::abs(A); | | typedef typename std::complex<T> eT; | |
| const T abs_B = std::abs(B); | | | |
| | | | |
|
| if(abs_A < abs_B) | | inline | |
| { | | bool | |
| return +1; | | operator() (const eT& a, const eT& b) const | |
| } | | { | |
| else | | return (std::abs(a) > std::abs(b)); | |
| if(abs_A > abs_B) | | | |
| { | | | |
| return -1; | | | |
| } | | | |
| else | | | |
| { | | | |
| return 0; | | | |
| } | | | |
| } | | } | |
|
| | | | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| op_sort::direct_sort(eT* X, const u32 n_elem, const u32 sort_type) | | op_sort::direct_sort(eT* X, const u32 n_elem, const u32 sort_type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(sort_type == 0) | | if(sort_type == 0) | |
| { | | { | |
|
| std::qsort(X, n_elem, sizeof(eT), arma_qsort_helper<eT>::ascend_compare | | arma_ascend_sort_helper<eT> comparator; | |
| ); | | | |
| | | std::sort(&X[0], &X[n_elem], comparator); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| std::qsort(X, n_elem, sizeof(eT), arma_qsort_helper<eT>::descend_compar | | arma_descend_sort_helper<eT> comparator; | |
| e); | | | |
| | | std::sort(&X[0], &X[n_elem], comparator); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | op_sort::copy_row(eT* X, const Mat<eT>& A, const u32 row) | |
| | | { | |
| | | const u32 N = A.n_cols; | |
| | | | |
| | | u32 i,j; | |
| | | | |
| | | for(i=0, j=1; j<N; i+=2, j+=2) | |
| | | { | |
| | | X[i] = A.at(row,i); | |
| | | X[j] = A.at(row,j); | |
| | | } | |
| | | | |
| | | if(i < N) | |
| | | { | |
| | | X[i] = A.at(row,i); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | op_sort::copy_row(Mat<eT>& A, const eT* X, const u32 row) | |
| | | { | |
| | | const u32 N = A.n_cols; | |
| | | | |
| | | u32 i,j; | |
| | | | |
| | | for(i=0, j=1; j<N; i+=2, j+=2) | |
| | | { | |
| | | A.at(row,i) = X[i]; | |
| | | A.at(row,j) = X[j]; | |
| | | } | |
| | | | |
| | | if(i < N) | |
| | | { | |
| | | A.at(row,i) = X[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_sort::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sort>& in) | | op_sort::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sort>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| const u32 sort_type = in.aux_u32_a; | | const u32 sort_type = in.aux_u32_a; | |
| const u32 dim = in.aux_u32_b; | | const u32 dim = in.aux_u32_b; | |
| | | | |
|
| arma_debug_check( (X.is_finite() == false), "sort(): given object has non
-finite elements" ); | | | |
| arma_debug_check( (sort_type > 1), "sort(): incorrect usage. sor
t_type must be 0 or 1"); | | arma_debug_check( (sort_type > 1), "sort(): incorrect usage. sor
t_type must be 0 or 1"); | |
| arma_debug_check( (dim > 1), "sort(): incorrect usage. dim
must be 0 or 1" ); | | arma_debug_check( (dim > 1), "sort(): incorrect usage. dim
must be 0 or 1" ); | |
|
| | | arma_debug_check( (X.is_finite() == false), "sort(): given object has non
-finite elements" ); | |
| | | | |
|
| if(dim == 0) // column-wise | | if( (X.n_rows * X.n_cols) <= 1 ) | |
| | | { | |
| | | out = X; | |
| | | return; | |
| | | } | |
| | | | |
| | | if(dim == 0) // sort the contents of each column | |
| { | | { | |
| arma_extra_debug_print("op_sort::apply(), dim = 0"); | | arma_extra_debug_print("op_sort::apply(), dim = 0"); | |
| | | | |
| out = X; | | out = X; | |
| | | | |
|
| for(u32 col=0; col<out.n_cols; ++col) | | const u32 n_rows = out.n_rows; | |
| | | const u32 n_cols = out.n_cols; | |
| | | | |
| | | for(u32 col=0; col < n_cols; ++col) | |
| { | | { | |
|
| op_sort::direct_sort( out.colptr(col), out.n_rows, sort_type ); | | op_sort::direct_sort( out.colptr(col), n_rows, sort_type ); | |
| } | | } | |
| } | | } | |
| else | | else | |
|
| if(dim == 1) // row-wise | | if(dim == 1) // sort the contents of each row | |
| { | | { | |
|
| if(X.n_rows != 1) // not a row vector | | if(X.n_rows == 1) // a row vector | |
| | | { | |
| | | arma_extra_debug_print("op_sort::apply(), dim = 1, vector specific"); | |
| | | | |
| | | out = X; | |
| | | op_sort::direct_sort(out.memptr(), out.n_elem, sort_type); | |
| | | } | |
| | | else // not a row vector | |
| { | | { | |
| arma_extra_debug_print("op_sort::apply(), dim = 1, generic"); | | arma_extra_debug_print("op_sort::apply(), dim = 1, generic"); | |
| | | | |
|
| //out.set_size(X.n_rows, X.n_cols); | | | |
| out.copy_size(X); | | out.copy_size(X); | |
| | | | |
|
| podarray<eT> tmp_array(X.n_cols); | | const u32 n_rows = out.n_rows; | |
| | | const u32 n_cols = out.n_cols; | |
| | | | |
| | | podarray<eT> tmp_array(n_cols); | |
| | | | |
|
| for(u32 row=0; row<out.n_rows; ++row) | | for(u32 row=0; row < n_rows; ++row) | |
| { | | { | |
|
| | | op_sort::copy_row(tmp_array.memptr(), X, row); | |
| | | | |
|
| for(u32 col=0; col<out.n_cols; ++col) | | op_sort::direct_sort( tmp_array.memptr(), n_cols, sort_type ); | |
| { | | | |
| tmp_array[col] = X.at(row,col); | | | |
| } | | | |
| | | | |
| op_sort::direct_sort( tmp_array.memptr(), out.n_cols, sort_type ); | | | |
| | | | |
| for(u32 col=0; col<out.n_cols; ++col) | | | |
| { | | | |
| out.at(row,col) = tmp_array[col]; | | | |
| } | | | |
| | | | |
|
| | | op_sort::copy_row(out, tmp_array.memptr(), row); | |
| } | | } | |
| } | | } | |
|
| else // a row vector | | | |
| { | | | |
| arma_extra_debug_print("op_sort::apply(), dim = 1, vector specific"); | | | |
| | | | |
| out = X; | | | |
| op_sort::direct_sort(out.memptr(), out.n_elem, sort_type); | | | |
| } | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 34 change blocks. |
| 125 lines changed or deleted | | 111 lines changed or added | |
|
| subview_cube_meat.hpp | | subview_cube_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_cube<eT>::subview_cube | | subview_cube<eT>::subview_cube | |
| ( | | ( | |
| const Cube<eT>& in_m, | | const Cube<eT>& in_m, | |
| const u32 in_row1, | | const u32 in_row1, | |
| const u32 in_col1, | | const u32 in_col1, | |
| const u32 in_slice1, | | const u32 in_slice1, | |
|
| const u32 in_row2, | | const u32 in_n_rows, | |
| const u32 in_col2, | | const u32 in_n_cols, | |
| const u32 in_slice2 | | const u32 in_n_slices | |
| ) | | ) | |
| : m (in_m) | | : m (in_m) | |
| , m_ptr (0) | | , m_ptr (0) | |
| , aux_row1 (in_row1) | | , aux_row1 (in_row1) | |
| , aux_col1 (in_col1) | | , aux_col1 (in_col1) | |
| , aux_slice1 (in_slice1) | | , aux_slice1 (in_slice1) | |
|
| , aux_row2 (in_row2) | | , n_rows (in_n_rows) | |
| , aux_col2 (in_col2) | | , n_cols (in_n_cols) | |
| , aux_slice2 (in_slice2) | | , n_elem_slice(in_n_rows * in_n_cols) | |
| , n_rows (1 + in_row2 - in_row1) | | , n_slices (in_n_slices) | |
| , n_cols (1 + in_col2 - in_col1) | | , n_elem (n_elem_slice * in_n_slices) | |
| , n_elem_slice(n_rows * n_cols) | | | |
| , n_slices (1 + in_slice2 - in_slice1) | | | |
| , n_elem (n_elem_slice * n_slices) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_cube<eT>::subview_cube | | subview_cube<eT>::subview_cube | |
| ( | | ( | |
| Cube<eT>& in_m, | | Cube<eT>& in_m, | |
| const u32 in_row1, | | const u32 in_row1, | |
| const u32 in_col1, | | const u32 in_col1, | |
| const u32 in_slice1, | | const u32 in_slice1, | |
|
| const u32 in_row2, | | const u32 in_n_rows, | |
| const u32 in_col2, | | const u32 in_n_cols, | |
| const u32 in_slice2 | | const u32 in_n_slices | |
| ) | | ) | |
| : m (in_m) | | : m (in_m) | |
| , m_ptr (&in_m) | | , m_ptr (&in_m) | |
| , aux_row1 (in_row1) | | , aux_row1 (in_row1) | |
| , aux_col1 (in_col1) | | , aux_col1 (in_col1) | |
| , aux_slice1 (in_slice1) | | , aux_slice1 (in_slice1) | |
|
| , aux_row2 (in_row2) | | , n_rows (in_n_rows) | |
| , aux_col2 (in_col2) | | , n_cols (in_n_cols) | |
| , aux_slice2 (in_slice2) | | , n_elem_slice(in_n_rows * in_n_cols) | |
| , n_rows (1 + in_row2 - in_row1) | | , n_slices (in_n_slices) | |
| , n_cols (1 + in_col2 - in_col1) | | , n_elem (n_elem_slice * in_n_slices) | |
| , n_elem_slice(n_rows * n_cols) | | | |
| , n_slices (1 + in_slice2 - in_slice1) | | | |
| , n_elem (n_elem_slice * n_slices) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator+= (const eT val) | | subview_cube<eT>::operator+= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 312 | | skipping to change at line 306 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator= (const subview_cube<eT>& x_in) | | subview_cube<eT>::operator= (const subview_cube<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
|
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_i
n.n_cols, x_in.n_slices) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "copy into subcube"); | | arma_debug_assert_same_size(t, x, "copy into subcube"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| const u32 t_n_slices = t.n_slices; | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | | |
| skipping to change at line 349 | | skipping to change at line 343 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator+= (const subview_cube<eT>& x_in) | | subview_cube<eT>::operator+= (const subview_cube<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
|
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_i
n.n_cols, x_in.n_slices) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "addition"); | | arma_debug_assert_same_size(t, x, "addition"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| const u32 t_n_slices = t.n_slices; | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | | |
| skipping to change at line 386 | | skipping to change at line 380 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator-= (const subview_cube<eT>& x_in) | | subview_cube<eT>::operator-= (const subview_cube<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
|
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_i
n.n_cols, x_in.n_slices) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "subtraction"); | | arma_debug_assert_same_size(t, x, "subtraction"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| const u32 t_n_slices = t.n_slices; | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | | |
| skipping to change at line 423 | | skipping to change at line 417 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator%= (const subview_cube<eT>& x_in) | | subview_cube<eT>::operator%= (const subview_cube<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
|
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_i
n.n_cols, x_in.n_slices) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise multiplication"); | | arma_debug_assert_same_size(t, x, "element-wise multiplication"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| const u32 t_n_slices = t.n_slices; | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | | |
| skipping to change at line 460 | | skipping to change at line 454 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator/= (const subview_cube<eT>& x_in) | | subview_cube<eT>::operator/= (const subview_cube<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
|
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_i
n.n_cols, x_in.n_slices) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise division"); | | arma_debug_assert_same_size(t, x, "element-wise division"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| const u32 t_n_slices = t.n_slices; | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | | |
| skipping to change at line 500 | | skipping to change at line 494 | |
| void | | void | |
| subview_cube<eT>::operator= (const Base<eT,T1>& in) | | subview_cube<eT>::operator= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "copy into subcube"); | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
|
| const u32 t_n_rows = t.n_rows; | | const u32 x_n_rows = x.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 x_n_cols = x.n_cols; | |
| const u32 t_aux_slice1 = t.aux_slice1; | | | |
| | | | |
|
| for(u32 col = 0; col < t_n_cols; ++col) | | if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) | |
| | | ) | |
| | | { | |
| | | // interpret the matrix as a cube with one slice | |
| | | | |
| | | for(u32 col = 0; col < t_n_cols; ++col) | |
| | | { | |
| | | arrayops::copy( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) | |
| | | ) | |
| { | | { | |
|
| arrayops::copy( t.slice_colptr(t_aux_slice1, col), x.colptr(col), t_n_r | | // interpret the matrix as a cube with one column | |
| ows ); | | // and with the number of slices equal to the number of columns in the | |
| | | matrix | |
| | | | |
| | | for(u32 i=0; i < t_n_slices; ++i) | |
| | | { | |
| | | arrayops::copy( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == 1) && (t_n_cols == x_n_cols) && (t_n_slices == x_n_rows) | |
| | | ) | |
| | | { | |
| | | // interpret the matrix as a cube with one row | |
| | | // and with the number of slices equal to the number of rows in the mat | |
| | | rix | |
| | | | |
| | | Cube<eT>& Q = *(t.m_ptr); | |
| | | | |
| | | const u32 t_aux_row1 = t.aux_row1; | |
| | | const u32 t_aux_col1 = t.aux_col1; | |
| | | const u32 t_aux_slice1 = t.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < t_n_cols; ++col) | |
| | | { | |
| | | const eT* x_colptr = x.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < t_n_slices; ++i) | |
| | | { | |
| | | Q.at(t_aux_row1, t_aux_col1 + col, t_aux_slice1 + i) = x_colptr[i]; | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(arma_config::debug == true) | |
| | | { | |
| | | arma_stop( arma_incompat_size_string(t, x, "copy into subcube") ); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator+= (const Base<eT,T1>& in) | | subview_cube<eT>::operator+= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "addition"); | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
|
| const u32 t_n_rows = t.n_rows; | | const u32 x_n_rows = x.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 x_n_cols = x.n_cols; | |
| const u32 t_aux_slice1 = t.aux_slice1; | | | |
| | | | |
|
| for(u32 col = 0; col < t_n_cols; ++col) | | if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) | |
| | | ) | |
| | | { | |
| | | for(u32 col = 0; col < t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_plus( t.slice_colptr(0, col), x.colptr(col), t_n_ro | |
| | | ws ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) | |
| | | ) | |
| { | | { | |
|
| arrayops::inplace_plus( t.slice_colptr(t_aux_slice1, col), x.colptr(col | | for(u32 i=0; i < t_n_slices; ++i) | |
| ), t_n_rows ); | | { | |
| | | arrayops::inplace_plus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ) | |
| | | ; | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == 1) && (t_n_cols == x_n_cols) && (t_n_slices == x_n_rows) | |
| | | ) | |
| | | { | |
| | | Cube<eT>& Q = *(t.m_ptr); | |
| | | | |
| | | const u32 t_aux_row1 = t.aux_row1; | |
| | | const u32 t_aux_col1 = t.aux_col1; | |
| | | const u32 t_aux_slice1 = t.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < t_n_cols; ++col) | |
| | | { | |
| | | const eT* x_colptr = x.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < t_n_slices; ++i) | |
| | | { | |
| | | Q.at(t_aux_row1, t_aux_col1 + col, t_aux_slice1 + i) += x_colptr[i] | |
| | | ; | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(arma_config::debug == true) | |
| | | { | |
| | | arma_stop( arma_incompat_size_string(t, x, "addition") ); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator-= (const Base<eT,T1>& in) | | subview_cube<eT>::operator-= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "subtraction"); | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
|
| const u32 t_n_rows = t.n_rows; | | const u32 x_n_rows = x.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 x_n_cols = x.n_cols; | |
| const u32 t_aux_slice1 = t.aux_slice1; | | | |
| | | | |
|
| for(u32 col = 0; col < t_n_cols; ++col) | | if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) | |
| | | ) | |
| | | { | |
| | | for(u32 col = 0; col < t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_minus( t.slice_colptr(0, col), x.colptr(col), t_n_r | |
| | | ows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) | |
| | | ) | |
| { | | { | |
|
| arrayops::inplace_minus( t.slice_colptr(t_aux_slice1, col), x.colptr(co | | for(u32 i=0; i < t_n_slices; ++i) | |
| l), t_n_rows ); | | { | |
| | | arrayops::inplace_minus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows | |
| | | ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == 1) && (t_n_cols == x_n_cols) && (t_n_slices == x_n_rows) | |
| | | ) | |
| | | { | |
| | | Cube<eT>& Q = *(t.m_ptr); | |
| | | | |
| | | const u32 t_aux_row1 = t.aux_row1; | |
| | | const u32 t_aux_col1 = t.aux_col1; | |
| | | const u32 t_aux_slice1 = t.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < t_n_cols; ++col) | |
| | | { | |
| | | const eT* x_colptr = x.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < t_n_slices; ++i) | |
| | | { | |
| | | Q.at(t_aux_row1, t_aux_col1 + col, t_aux_slice1 + i) -= x_colptr[i] | |
| | | ; | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(arma_config::debug == true) | |
| | | { | |
| | | arma_stop( arma_incompat_size_string(t, x, "subtraction") ); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator%= (const Base<eT,T1>& in) | | subview_cube<eT>::operator%= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "element-wise multiplication"); | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
|
| const u32 t_n_rows = t.n_rows; | | const u32 x_n_rows = x.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 x_n_cols = x.n_cols; | |
| const u32 t_aux_slice1 = t.aux_slice1; | | | |
| | | | |
|
| for(u32 col = 0; col < t_n_cols; ++col) | | if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) | |
| | | ) | |
| | | { | |
| | | for(u32 col = 0; col < t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_mul( t.slice_colptr(0, col), x.colptr(col), t_n_row | |
| | | s ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) | |
| | | ) | |
| { | | { | |
|
| arrayops::inplace_mul( t.slice_colptr(t_aux_slice1, col), x.colptr(col) | | for(u32 i=0; i < t_n_slices; ++i) | |
| , t_n_rows ); | | { | |
| | | arrayops::inplace_mul( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == 1) && (t_n_cols == x_n_cols) && (t_n_slices == x_n_rows) | |
| | | ) | |
| | | { | |
| | | Cube<eT>& Q = *(t.m_ptr); | |
| | | | |
| | | const u32 t_aux_row1 = t.aux_row1; | |
| | | const u32 t_aux_col1 = t.aux_col1; | |
| | | const u32 t_aux_slice1 = t.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < t_n_cols; ++col) | |
| | | { | |
| | | const eT* x_colptr = x.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < t_n_slices; ++i) | |
| | | { | |
| | | Q.at(t_aux_row1, t_aux_col1 + col, t_aux_slice1 + i) *= x_colptr[i] | |
| | | ; | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(arma_config::debug == true) | |
| | | { | |
| | | arma_stop( arma_incompat_size_string(t, x, "element-wise multiplicati | |
| | | on") ); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator/= (const Base<eT,T1>& in) | | subview_cube<eT>::operator/= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "element-wise division"); | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
|
| const u32 t_n_rows = t.n_rows; | | const u32 x_n_rows = x.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 x_n_cols = x.n_cols; | |
| const u32 t_aux_slice1 = t.aux_slice1; | | | |
| | | | |
|
| for(u32 col = 0; col < t_n_cols; ++col) | | if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1)
) | |
| { | | { | |
|
| arrayops::inplace_div( t.slice_colptr(t_aux_slice1, col), x.colptr(col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| , t_n_rows ); | | { | |
| | | arrayops::inplace_div( t.slice_colptr(0, col), x.colptr(col), t_n_row | |
| | | s ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) | |
| | | ) | |
| | | { | |
| | | for(u32 i=0; i < t_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_div( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (t_n_rows == 1) && (t_n_cols == x_n_cols) && (t_n_slices == x_n_rows) | |
| | | ) | |
| | | { | |
| | | Cube<eT>& Q = *(t.m_ptr); | |
| | | | |
| | | const u32 t_aux_row1 = t.aux_row1; | |
| | | const u32 t_aux_col1 = t.aux_col1; | |
| | | const u32 t_aux_slice1 = t.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < t_n_cols; ++col) | |
| | | { | |
| | | const eT* x_colptr = x.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < t_n_slices; ++i) | |
| | | { | |
| | | Q.at(t_aux_row1, t_aux_col1 + col, t_aux_slice1 + i) /= x_colptr[i] | |
| | | ; | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(arma_config::debug == true) | |
| | | { | |
| | | arma_stop( arma_incompat_size_string(t, x, "element-wise division") ) | |
| | | ; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::fill(const eT val) | | subview_cube<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 790 | | skipping to change at line 982 | |
| subview_cube<eT>::check_overlap(const subview_cube<eT>& x) const | | subview_cube<eT>::check_overlap(const subview_cube<eT>& x) const | |
| { | | { | |
| const subview_cube<eT>& t = *this; | | const subview_cube<eT>& t = *this; | |
| | | | |
| if(&t.m != &x.m) | | if(&t.m != &x.m) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| const bool row_overlap = | | if( (t.n_elem == 0) || (x.n_elem == 0) ) | |
| ( | | { | |
| ( (x.aux_row1 >= t.aux_row1) && (x.aux_row1 <= t.aux_row2) ) | | return false; | |
| || | | } | |
| ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) ) | | else | |
| ); | | { | |
| | | const u32 t_aux_row1 = t.aux_row1; | |
| const bool col_overlap = | | const u32 t_aux_row2 = t_aux_row1 + t.n_rows - 1; | |
| ( | | | |
| ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) ) | | const u32 t_aux_col1 = t.aux_col1; | |
| || | | const u32 t_aux_col2 = t_aux_col1 + t.n_cols - 1; | |
| ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) ) | | | |
| ); | | const u32 t_aux_slice1 = t.aux_slice1; | |
| | | const u32 t_aux_slice2 = t_aux_slice1 + t.n_slices - 1; | |
| const bool slice_overlap = | | | |
| ( | | const u32 x_aux_row1 = x.aux_row1; | |
| ( (x.aux_slice1 >= t.aux_slice1) && (x.aux_slice1 <= t.aux_slice2) ) | | const u32 x_aux_row2 = x_aux_row1 + x.n_rows - 1; | |
| || | | | |
| ( (x.aux_slice2 >= t.aux_slice1) && (x.aux_slice2 <= t.aux_slice2) ) | | const u32 x_aux_col1 = x.aux_col1; | |
| ); | | const u32 x_aux_col2 = x_aux_col1 + x.n_cols - 1; | |
| | | | |
|
| const bool overlap = ( (row_overlap == true) && (col_overlap == true) & | | const u32 x_aux_slice1 = x.aux_slice1; | |
| & (slice_overlap == true) ); | | const u32 x_aux_slice2 = x_aux_slice1 + x.n_slices - 1; | |
| | | | |
|
| return overlap; | | const bool row_overlap = | |
| | | ( | |
| | | ( (x_aux_row1 >= t_aux_row1) && (x_aux_row1 <= t_aux_row2) ) | |
| | | || | |
| | | ( (x_aux_row2 >= t_aux_row1) && (x_aux_row2 <= t_aux_row2) ) | |
| | | ); | |
| | | | |
| | | const bool col_overlap = | |
| | | ( | |
| | | ( (x_aux_col1 >= t_aux_col1) && (x_aux_col1 <= t_aux_col2) ) | |
| | | || | |
| | | ( (x_aux_col2 >= t_aux_col1) && (x_aux_col2 <= t_aux_col2) ) | |
| | | ); | |
| | | | |
| | | const bool slice_overlap = | |
| | | ( | |
| | | ( (x_aux_slice1 >= t_aux_slice1) && (x_aux_slice1 <= t_aux_slice2) | |
| | | ) | |
| | | || | |
| | | ( (x_aux_slice2 >= t_aux_slice1) && (x_aux_slice2 <= t_aux_slice2) | |
| | | ) | |
| | | ); | |
| | | | |
| | | const bool overlap = ( (row_overlap == true) && (col_overlap == true) | |
| | | && (slice_overlap == true) ); | |
| | | | |
| | | return overlap; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| subview_cube<eT>::check_overlap(const Mat<eT>& x) const | | subview_cube<eT>::check_overlap(const Mat<eT>& x) const | |
| { | | { | |
| const subview_cube<eT>& t = *this; | | const subview_cube<eT>& t = *this; | |
| | | | |
|
| for(u32 slice = t.aux_slice1; slice <= t.aux_slice2; ++slice) | | const u32 t_aux_slice1 = t.aux_slice1; | |
| | | const u32 t_aux_slice2_plus_1 = t_aux_slice1 + t.n_slices; | |
| | | | |
| | | for(u32 slice = t_aux_slice1; slice < t_aux_slice2_plus_1; ++slice) | |
| { | | { | |
| const Mat<eT>& y = *(t.m.mat_ptrs[slice]); | | const Mat<eT>& y = *(t.m.mat_ptrs[slice]); | |
| | | | |
| if( x.memptr() == y.memptr() ) | | if( x.memptr() == y.memptr() ) | |
| { | | { | |
| return true; | | return true; | |
| } | | } | |
| } | | } | |
| | | | |
| return false; | | return false; | |
| | | | |
| skipping to change at line 877 | | skipping to change at line 1097 | |
| } | | } | |
| | | | |
| if(alias) | | if(alias) | |
| { | | { | |
| actual_out = out; | | actual_out = out; | |
| delete tmp; | | delete tmp; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! mat X = Y.subcube(...) | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| subview_cube<eT>::extract(Mat<eT>& out, const subview_cube<eT>& in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (in.n_slices != 1), "subview_cube::extract(): given sub | | | |
| cube doesn't have exactly one slice" ); | | | |
| | | | |
| const u32 n_rows = in.n_rows; | | | |
| const u32 n_cols = in.n_cols; | | | |
| const u32 aux_slice1 = in.aux_slice1; | | | |
| | | | |
| out.set_size(n_rows, n_cols); | | | |
| | | | |
| for(u32 col = 0; col < n_cols; ++col) | | | |
| { | | | |
| arrayops::copy( out.colptr(col), in.slice_colptr(aux_slice1, col), n_ro | | | |
| ws ); | | | |
| } | | | |
| } | | | |
| | | | |
| //! cube X += Y.subcube(...) | | //! cube X += Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::plus_inplace(Cube<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::plus_inplace(Cube<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "addition"); | | arma_debug_assert_same_size(out, in, "addition"); | |
| | | | |
| | | | |
| skipping to change at line 991 | | skipping to change at line 1189 | |
| | | | |
| for(u32 slice = 0; slice<n_slices; ++slice) | | for(u32 slice = 0; slice<n_slices; ++slice) | |
| { | | { | |
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col<n_cols; ++col) | |
| { | | { | |
| arrayops::inplace_div( out.slice_colptr(slice,col), in.slice_colptr(s
lice,col), n_rows ); | | arrayops::inplace_div( out.slice_colptr(slice,col), in.slice_colptr(s
lice,col), n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | //! mat X = Y.subcube(...) | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | subview_cube<eT>::extract(Mat<eT>& out, const subview_cube<eT>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| | | { | |
| | | out.set_size(in_n_rows, in_n_cols); | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows ) | |
| | | ; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if(in_n_cols == 1) | |
| | | { | |
| | | out.set_size(in_n_rows, in_n_slices); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ) | |
| | | ; | |
| | | } | |
| | | } | |
| | | else | |
| | | if(in_n_rows == 1) | |
| | | { | |
| | | out.set_size(in_n_slices, in_n_cols); | |
| | | | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] = Q.at(in_aux_row1, in_aux_col1 + col, in_aux_sli | |
| | | ce1 + i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | out.set_size(in_n_slices); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] = Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| //! mat X += Y.subcube(...) | | //! mat X += Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::plus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::plus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(out, in, "addition"); | | arma_debug_assert_cube_as_mat(out, in, "addition", true); | |
| | | | |
|
| const u32 in_n_rows = in.n_rows; | | const u32 in_n_rows = in.n_rows; | |
| const u32 in_n_cols = in.n_cols; | | const u32 in_n_cols = in.n_cols; | |
| const u32 in_aux_slice1 = in.aux_slice1; | | const u32 in_n_slices = in.n_slices; | |
| | | | |
|
| for(u32 col = 0; col < in_n_cols; ++col) | | const u32 out_n_rows = out.n_rows; | |
| | | const u32 out_n_cols = out.n_cols; | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| { | | { | |
|
| arrayops::inplace_plus( out.colptr(col), in.slice_colptr(in_aux_slice1, | | for(u32 col=0; col < in_n_cols; ++col) | |
| col), in_n_rows ); | | { | |
| | | arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_ | |
| | | n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_ | |
| | | n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] += Q.at(in_aux_row1, in_aux_col1 + col, in_aux_sl | |
| | | ice1 + i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] += Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); | |
| | | } | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! mat X -= Y.subcube(...) | | //! mat X -= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::minus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::minus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(out, in, "subtraction"); | | arma_debug_assert_cube_as_mat(out, in, "subtraction", true); | |
| | | | |
|
| const u32 in_n_rows = in.n_rows; | | const u32 in_n_rows = in.n_rows; | |
| const u32 in_n_cols = in.n_cols; | | const u32 in_n_cols = in.n_cols; | |
| const u32 in_aux_slice1 = in.aux_slice1; | | const u32 in_n_slices = in.n_slices; | |
| | | | |
|
| for(u32 col = 0; col < in_n_cols; ++col) | | const u32 out_n_rows = out.n_rows; | |
| | | const u32 out_n_cols = out.n_cols; | |
| | | const u32 out_vec_state = out.vec_state; | |
| | | | |
| | | if(in_n_slices == 1) | |
| { | | { | |
|
| arrayops::inplace_minus( out.colptr(col), in.slice_colptr(in_aux_slice1 | | for(u32 col=0; col < in_n_cols; ++col) | |
| , col), in_n_rows ); | | { | |
| | | arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in | |
| | | _n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in | |
| | | _n_rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] -= Q.at(in_aux_row1, in_aux_col1 + col, in_aux_sl | |
| | | ice1 + i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] -= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); | |
| | | } | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! mat X %= Y.subcube(...) | | //! mat X %= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::schur_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::schur_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(out, in, "element-wise multiplication"); | | arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", tru | |
| | | e); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
|
| const u32 in_n_rows = in.n_rows; | | const u32 out_n_rows = out.n_rows; | |
| const u32 in_n_cols = in.n_cols; | | const u32 out_n_cols = out.n_cols; | |
| const u32 in_aux_slice1 = in.aux_slice1; | | const u32 out_vec_state = out.vec_state; | |
| | | | |
|
| for(u32 col = 0; col < in_n_cols; ++col) | | if(in_n_slices == 1) | |
| | | { | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| arrayops::inplace_mul( out.colptr(col), in.slice_colptr(in_aux_slice1, | | if(out_vec_state == 0) | |
| col), in_n_rows ); | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] *= Q.at(in_aux_row1, in_aux_col1 + col, in_aux_sl | |
| | | ice1 + i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] *= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); | |
| | | } | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! mat X /= Y.subcube(...) | | //! mat X /= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::div_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::div_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(out, in, "element-wise division"); | | arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); | |
| | | | |
| | | const u32 in_n_rows = in.n_rows; | |
| | | const u32 in_n_cols = in.n_cols; | |
| | | const u32 in_n_slices = in.n_slices; | |
| | | | |
|
| const u32 in_n_rows = in.n_rows; | | const u32 out_n_rows = out.n_rows; | |
| const u32 in_n_cols = in.n_cols; | | const u32 out_n_cols = out.n_cols; | |
| const u32 in_aux_slice1 = in.aux_slice1; | | const u32 out_vec_state = out.vec_state; | |
| | | | |
|
| for(u32 col = 0; col < in_n_cols; ++col) | | if(in_n_slices == 1) | |
| { | | { | |
|
| arrayops::inplace_div( out.colptr(col), in.slice_colptr(in_aux_slice1, | | for(u32 col=0; col < in_n_cols; ++col) | |
| col), in_n_rows ); | | { | |
| | | arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | if(out_vec_state == 0) | |
| | | { | |
| | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == | |
| | | out_n_cols) ) | |
| | | { | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n | |
| | | _rows ); | |
| | | } | |
| | | } | |
| | | else | |
| | | if( (in_n_rows == 1) && (in_n_cols == out_n_cols) && (in_n_slices == | |
| | | out_n_rows) ) | |
| | | { | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 col=0; col < in_n_cols; ++col) | |
| | | { | |
| | | eT* out_colptr = out.colptr(col); | |
| | | | |
| | | for(u32 i=0; i < in_n_slices; ++i) | |
| | | { | |
| | | out_colptr[i] /= Q.at(in_aux_row1, in_aux_col1 + col, in_aux_sl | |
| | | ice1 + i); | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | const Cube<eT>& Q = in.m; | |
| | | | |
| | | const u32 in_aux_row1 = in.aux_row1; | |
| | | const u32 in_aux_col1 = in.aux_col1; | |
| | | const u32 in_aux_slice1 = in.aux_slice1; | |
| | | | |
| | | for(u32 i=0; i<in_n_slices; ++i) | |
| | | { | |
| | | out_mem[i] /= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); | |
| | | } | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 52 change blocks. |
| 140 lines changed or deleted | | 677 lines changed or added | |
|
| subview_meat.hpp | | subview_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| subview<eT>::~subview() | | subview<eT>::~subview() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
|
| subview<eT>::subview(const Mat<eT>& in_m, const u32 in_row1, const u32 in_c
ol1, const u32 in_row2, const u32 in_col2) | | subview<eT>::subview(const Mat<eT>& in_m, const u32 in_row1, const u32 in_c
ol1, const u32 in_n_rows, const u32 in_n_cols) | |
| : m(in_m) | | : m(in_m) | |
| , m_ptr(0) | | , m_ptr(0) | |
| , aux_row1(in_row1) | | , aux_row1(in_row1) | |
| , aux_col1(in_col1) | | , aux_col1(in_col1) | |
|
| , aux_row2(in_row2) | | , n_rows(in_n_rows) | |
| , aux_col2(in_col2) | | , n_cols(in_n_cols) | |
| , n_rows(1 + in_row2 - in_row1) | | , n_elem(in_n_rows*in_n_cols) | |
| , n_cols(1 + in_col2 - in_col1) | | | |
| , n_elem(n_rows*n_cols) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
|
| subview<eT>::subview(Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, c
onst u32 in_row2, const u32 in_col2) | | subview<eT>::subview(Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, c
onst u32 in_n_rows, const u32 in_n_cols) | |
| : m(in_m) | | : m(in_m) | |
| , m_ptr(&in_m) | | , m_ptr(&in_m) | |
| , aux_row1(in_row1) | | , aux_row1(in_row1) | |
| , aux_col1(in_col1) | | , aux_col1(in_col1) | |
|
| , aux_row2(in_row2) | | , n_rows(in_n_rows) | |
| , aux_col2(in_col2) | | , n_cols(in_n_cols) | |
| , n_rows(1 + in_row2 - in_row1) | | , n_elem(in_n_rows*in_n_cols) | |
| , n_cols(1 + in_col2 - in_col1) | | | |
| , n_elem(n_rows*n_cols) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator+= (const eT val) | | subview<eT>::operator+= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 553 | | skipping to change at line 549 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator= (const subview<eT>& x_in) | | subview<eT>::operator= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
|
| const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in
.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in
.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "insert into submatrix"); | | arma_debug_assert_same_size(t, x, "insert into submatrix"); | |
| | | | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| | | | |
| if(t_n_rows == 1) | | if(t_n_rows == 1) | |
| | | | |
| skipping to change at line 595 | | skipping to change at line 591 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator+= (const subview<eT>& x_in) | | subview<eT>::operator+= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
|
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "addition"); | | arma_debug_assert_same_size(t, x, "addition"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| if(t_n_rows == 1) | | if(t_n_rows == 1) | |
| | | | |
| skipping to change at line 637 | | skipping to change at line 633 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator-= (const subview<eT>& x_in) | | subview<eT>::operator-= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
|
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "subtraction"); | | arma_debug_assert_same_size(t, x, "subtraction"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| if(t_n_rows == 1) | | if(t_n_rows == 1) | |
| | | | |
| skipping to change at line 680 | | skipping to change at line 676 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator%= (const subview& x_in) | | subview<eT>::operator%= (const subview& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
|
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise multiplication"); | | arma_debug_assert_same_size(t, x, "element-wise multiplication"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| if(t_n_rows == 1) | | if(t_n_rows == 1) | |
| | | | |
| skipping to change at line 723 | | skipping to change at line 719 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator/= (const subview& x_in) | | subview<eT>::operator/= (const subview& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
|
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise division"); | | arma_debug_assert_same_size(t, x, "element-wise division"); | |
| | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| if(t_n_rows == 1) | | if(t_n_rows == 1) | |
| | | | |
| skipping to change at line 913 | | skipping to change at line 909 | |
| subview<eT>::check_overlap(const subview<eT>& x) const | | subview<eT>::check_overlap(const subview<eT>& x) const | |
| { | | { | |
| const subview<eT>& t = *this; | | const subview<eT>& t = *this; | |
| | | | |
| if(&t.m != &x.m) | | if(&t.m != &x.m) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| const bool row_overlap = | | if( (t.n_elem == 0) || (x.n_elem == 0) ) | |
| ( | | { | |
| ( (x.aux_row1 >= t.aux_row1) && (x.aux_row1 <= t.aux_row2) ) | | // if t.n_elem is 0, t.n_rows or t.n_cols is 0 | |
| || | | // if x.n_elem is 0, x.n_rows or x.n_cols is 0 | |
| ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) ) | | return false; | |
| ); | | } | |
| | | else | |
| const bool col_overlap = | | { | |
| ( | | // at this stage we have a guarantee that: | |
| ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) ) | | // t.n_rows > 0, t.n_cols > 0 | |
| || | | // and | |
| ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) ) | | // x.n_rows > 0, x.n_cols > 0 | |
| ); | | | |
| | | const u32 t_aux_row1 = t.aux_row1; | |
| | | const u32 t_aux_row2 = t_aux_row1 + t.n_rows - 1; | |
| | | | |
| | | const u32 t_aux_col1 = t.aux_col1; | |
| | | const u32 t_aux_col2 = t_aux_col1 + t.n_cols - 1; | |
| | | | |
| | | const u32 x_aux_row1 = x.aux_row1; | |
| | | const u32 x_aux_row2 = x_aux_row1 + x.n_rows - 1; | |
| | | | |
| | | const u32 x_aux_col1 = x.aux_col1; | |
| | | const u32 x_aux_col2 = x_aux_col1 + x.n_cols - 1; | |
| | | | |
| | | const bool row_overlap = | |
| | | ( | |
| | | ( (x_aux_row1 >= t_aux_row1) && (x_aux_row1 <= t_aux_row2) ) | |
| | | || | |
| | | ( (x_aux_row2 >= t_aux_row1) && (x_aux_row2 <= t_aux_row2) ) | |
| | | ); | |
| | | | |
| | | const bool col_overlap = | |
| | | ( | |
| | | ( (x_aux_col1 >= t_aux_col1) && (x_aux_col1 <= t_aux_col2) ) | |
| | | || | |
| | | ( (x_aux_col2 >= t_aux_col1) && (x_aux_col2 <= t_aux_col2) ) | |
| | | ); | |
| | | | |
|
| const bool overlap = ( (row_overlap == true) && (col_overlap == true) )
; | | const bool overlap = ( (row_overlap == true) && (col_overlap == true)
); | |
| | | | |
|
| return overlap; | | return overlap; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| subview<eT>::is_vec() const | | subview<eT>::is_vec() const | |
| { | | { | |
| return ( (n_rows == 1) || (n_cols == 1) ); | | return ( (n_rows == 1) || (n_cols == 1) ); | |
| } | | } | |
| | | | |
| skipping to change at line 1138 | | skipping to change at line 1160 | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col) | | subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col) | |
|
| : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col) | | : subview<eT>(in_m, 0, in_col, in_m.n_rows, 1) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col) | | subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col) | |
|
| : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col) | | : subview<eT>(in_m, 0, in_col, in_m.n_rows, 1) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
|
| subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col, const u | | subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col, const u | |
| 32 in_row1, const u32 in_row2) | | 32 in_row1, const u32 in_n_rows) | |
| : subview<eT>(in_m, in_row1, in_col, in_row2, in_col) | | : subview<eT>(in_m, in_row1, in_col, in_n_rows, 1) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
|
| subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col, const u32 in_ | | subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col, const u32 in_ | |
| row1, const u32 in_row2) | | row1, const u32 in_n_rows) | |
| : subview<eT>(in_m, in_row1, in_col, in_row2, in_col) | | : subview<eT>(in_m, in_row1, in_col, in_n_rows, 1) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_col<eT>::operator=(const subview<eT>& X) | | subview_col<eT>::operator=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 1208 | | skipping to change at line 1230 | |
| arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible
dimensions" ); | | arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible
dimensions" ); | |
| } | | } | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row) | | subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row) | |
|
| : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1) | | : subview<eT>(in_m, in_row, 0, 1, in_m.n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row) | | subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row) | |
|
| : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1) | | : subview<eT>(in_m, in_row, 0, 1, in_m.n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
|
| subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row, const u | | subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row, const u | |
| 32 in_col1, const u32 in_col2) | | 32 in_col1, const u32 in_n_cols) | |
| : subview<eT>(in_m, in_row, in_col1, in_row, in_col2) | | : subview<eT>(in_m, in_row, in_col1, 1, in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
|
| subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row, const u32 in_ | | subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row, const u32 in_ | |
| col1, const u32 in_col2) | | col1, const u32 in_n_cols) | |
| : subview<eT>(in_m, in_row, in_col1, in_row, in_col2) | | : subview<eT>(in_m, in_row, in_col1, 1, in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_row<eT>::operator=(const subview<eT>& X) | | subview_row<eT>::operator=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
End of changes. 21 change blocks. |
| 50 lines changed or deleted | | 72 lines changed or added | |
|