max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup subview_cube max@0: //! @{ max@0: max@0: max@0: template max@0: inline max@0: subview_cube::~subview_cube() max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: subview_cube::subview_cube max@0: ( max@0: const Cube& in_m, max@0: const uword in_row1, max@0: const uword in_col1, max@0: const uword in_slice1, max@0: const uword in_n_rows, max@0: const uword in_n_cols, max@0: const uword in_n_slices max@0: ) max@0: : m (in_m) max@0: , m_ptr (0) max@0: , aux_row1 (in_row1) max@0: , aux_col1 (in_col1) max@0: , aux_slice1 (in_slice1) max@0: , n_rows (in_n_rows) max@0: , n_cols (in_n_cols) max@0: , n_elem_slice(in_n_rows * in_n_cols) max@0: , n_slices (in_n_slices) max@0: , n_elem (n_elem_slice * in_n_slices) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: subview_cube::subview_cube max@0: ( max@0: Cube& in_m, max@0: const uword in_row1, max@0: const uword in_col1, max@0: const uword in_slice1, max@0: const uword in_n_rows, max@0: const uword in_n_cols, max@0: const uword in_n_slices max@0: ) max@0: : m (in_m) max@0: , m_ptr (&in_m) max@0: , aux_row1 (in_row1) max@0: , aux_col1 (in_col1) max@0: , aux_slice1 (in_slice1) max@0: , n_rows (in_n_rows) max@0: , n_cols (in_n_cols) max@0: , n_elem_slice(in_n_rows * in_n_cols) max@0: , n_slices (in_n_slices) max@0: , n_elem (n_elem_slice * in_n_slices) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator+= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_slices = n_slices; max@0: max@0: for(uword slice = 0; slice < local_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < local_n_cols; ++col) max@0: { max@0: arrayops::inplace_plus( slice_colptr(slice,col), val, local_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator-= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_slices = n_slices; max@0: max@0: for(uword slice = 0; slice < local_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < local_n_cols; ++col) max@0: { max@0: arrayops::inplace_minus( slice_colptr(slice,col), val, local_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator*= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_slices = n_slices; max@0: max@0: for(uword slice = 0; slice < local_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < local_n_cols; ++col) max@0: { max@0: arrayops::inplace_mul( slice_colptr(slice,col), val, local_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator/= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_slices = n_slices; max@0: max@0: for(uword slice = 0; slice < local_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < local_n_cols; ++col) max@0: { max@0: arrayops::inplace_div( slice_colptr(slice,col), val, local_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator= (const BaseCube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap_cube tmp(in.get_ref()); max@0: max@0: const Cube& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "copy into subcube"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator+= (const BaseCube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap_cube tmp(in.get_ref()); max@0: max@0: const Cube& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "addition"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator-= (const BaseCube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap_cube tmp(in.get_ref()); max@0: max@0: const Cube& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "subtraction"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator%= (const BaseCube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap_cube tmp(in.get_ref()); max@0: max@0: const Cube& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "element-wise multiplication"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator/= (const BaseCube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap_cube tmp(in.get_ref()); max@0: max@0: const Cube& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "element-wise division"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: //! x.subcube(...) = y.subcube(...) max@0: template max@0: inline max@0: void max@0: subview_cube::operator= (const subview_cube& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; max@0: const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; max@0: const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; max@0: max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "copy into subcube"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: max@0: if(overlap) max@0: { max@0: delete tmp_subview_cube; max@0: delete tmp_cube; max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator+= (const subview_cube& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; max@0: const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; max@0: const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; max@0: max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "addition"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: max@0: if(overlap) max@0: { max@0: delete tmp_subview_cube; max@0: delete tmp_cube; max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator-= (const subview_cube& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; max@0: const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; max@0: const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; max@0: max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "subtraction"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: max@0: if(overlap) max@0: { max@0: delete tmp_subview_cube; max@0: delete tmp_cube; max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator%= (const subview_cube& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; max@0: const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; max@0: const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; max@0: max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "element-wise multiplication"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: max@0: if(overlap) max@0: { max@0: delete tmp_subview_cube; max@0: delete tmp_cube; max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::operator/= (const subview_cube& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; max@0: const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; max@0: const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; max@0: max@0: subview_cube& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "element-wise division"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: for(uword slice = 0; slice < t_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); max@0: } max@0: } max@0: max@0: if(overlap) max@0: { max@0: delete tmp_subview_cube; max@0: delete tmp_cube; max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: max@0: const Mat& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: const uword x_n_rows = x.n_rows; max@0: const uword x_n_cols = x.n_cols; max@0: max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) max@0: { max@0: // interpret the matrix as a cube with one slice max@0: max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::copy( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) max@0: { max@0: for(uword i=0; i < t_n_slices; ++i) max@0: { max@0: arrayops::copy( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) max@0: { max@0: Cube& Q = *(t.m_ptr); max@0: max@0: const uword t_aux_row1 = t.aux_row1; max@0: const uword t_aux_col1 = t.aux_col1; max@0: const uword t_aux_slice1 = t.aux_slice1; max@0: max@0: for(uword slice=0; slice < t_n_slices; ++slice) max@0: { max@0: const uword mod_slice = t_aux_slice1 + slice; max@0: max@0: const eT* x_colptr = x.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = x_colptr[i]; max@0: const eT tmp_j = x_colptr[j]; max@0: max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = tmp_i; max@0: Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) = tmp_j; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = x_colptr[i]; max@0: } max@0: } max@0: } max@0: else max@0: { max@0: if(arma_config::debug == true) max@0: { max@0: arma_stop( arma_incompat_size_string(t, x, "copy into subcube") ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator+= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: max@0: const Mat& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: const uword x_n_rows = x.n_rows; max@0: const uword x_n_cols = x.n_cols; max@0: max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_plus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) max@0: { max@0: for(uword i=0; i < t_n_slices; ++i) max@0: { max@0: arrayops::inplace_plus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) max@0: { max@0: Cube& Q = *(t.m_ptr); max@0: max@0: const uword t_aux_row1 = t.aux_row1; max@0: const uword t_aux_col1 = t.aux_col1; max@0: const uword t_aux_slice1 = t.aux_slice1; max@0: max@0: for(uword slice=0; slice < t_n_slices; ++slice) max@0: { max@0: const uword mod_slice = t_aux_slice1 + slice; max@0: max@0: const eT* x_colptr = x.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = x_colptr[i]; max@0: const eT tmp_j = x_colptr[j]; max@0: max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += tmp_i; max@0: Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) += tmp_j; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += x_colptr[i]; max@0: } max@0: } max@0: } max@0: else max@0: { max@0: if(arma_config::debug == true) max@0: { max@0: arma_stop( arma_incompat_size_string(t, x, "addition") ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator-= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: max@0: const Mat& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: const uword x_n_rows = x.n_rows; max@0: const uword x_n_cols = x.n_cols; max@0: max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_minus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) max@0: { max@0: for(uword i=0; i < t_n_slices; ++i) max@0: { max@0: arrayops::inplace_minus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) max@0: { max@0: Cube& Q = *(t.m_ptr); max@0: max@0: const uword t_aux_row1 = t.aux_row1; max@0: const uword t_aux_col1 = t.aux_col1; max@0: const uword t_aux_slice1 = t.aux_slice1; max@0: max@0: for(uword slice=0; slice < t_n_slices; ++slice) max@0: { max@0: const uword mod_slice = t_aux_slice1 + slice; max@0: max@0: const eT* x_colptr = x.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = x_colptr[i]; max@0: const eT tmp_j = x_colptr[j]; max@0: max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= tmp_i; max@0: Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) -= tmp_j; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= x_colptr[i]; max@0: } max@0: } max@0: } max@0: else max@0: { max@0: if(arma_config::debug == true) max@0: { max@0: arma_stop( arma_incompat_size_string(t, x, "subtraction") ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator%= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: max@0: const Mat& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: const uword x_n_rows = x.n_rows; max@0: const uword x_n_cols = x.n_cols; max@0: max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_mul( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) max@0: { max@0: for(uword i=0; i < t_n_slices; ++i) max@0: { max@0: arrayops::inplace_mul( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) max@0: { max@0: Cube& Q = *(t.m_ptr); max@0: max@0: const uword t_aux_row1 = t.aux_row1; max@0: const uword t_aux_col1 = t.aux_col1; max@0: const uword t_aux_slice1 = t.aux_slice1; max@0: max@0: for(uword slice=0; slice < t_n_slices; ++slice) max@0: { max@0: const uword mod_slice = t_aux_slice1 + slice; max@0: max@0: const eT* x_colptr = x.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = x_colptr[i]; max@0: const eT tmp_j = x_colptr[j]; max@0: max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= tmp_i; max@0: Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) *= tmp_j; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= x_colptr[i]; max@0: } max@0: } max@0: } max@0: else max@0: { max@0: if(arma_config::debug == true) max@0: { max@0: arma_stop( arma_incompat_size_string(t, x, "element-wise multiplication") ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_cube::operator/= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: max@0: const Mat& x = tmp.M; max@0: subview_cube& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_slices = t.n_slices; max@0: max@0: const uword x_n_rows = x.n_rows; max@0: const uword x_n_cols = x.n_cols; max@0: max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) max@0: { max@0: for(uword col = 0; col < t_n_cols; ++col) max@0: { max@0: arrayops::inplace_div( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) max@0: { max@0: for(uword i=0; i < t_n_slices; ++i) max@0: { max@0: arrayops::inplace_div( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); max@0: } max@0: } max@0: else max@0: if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) max@0: { max@0: Cube& Q = *(t.m_ptr); max@0: max@0: const uword t_aux_row1 = t.aux_row1; max@0: const uword t_aux_col1 = t.aux_col1; max@0: const uword t_aux_slice1 = t.aux_slice1; max@0: max@0: for(uword slice=0; slice < t_n_slices; ++slice) max@0: { max@0: const uword mod_slice = t_aux_slice1 + slice; max@0: max@0: const eT* x_colptr = x.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = x_colptr[i]; max@0: const eT tmp_j = x_colptr[j]; max@0: max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= tmp_i; max@0: Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) /= tmp_j; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= x_colptr[i]; max@0: } max@0: } max@0: } max@0: else max@0: { max@0: if(arma_config::debug == true) max@0: { max@0: arma_stop( arma_incompat_size_string(t, x, "element-wise division") ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::fill(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_slices = n_slices; max@0: max@0: for(uword slice = 0; slice < local_n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < local_n_cols; ++col) max@0: { max@0: arrayops::inplace_set( slice_colptr(slice,col), val, local_n_rows ); max@0: } max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::zeros() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: fill(eT(0)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_cube::ones() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: fill(eT(1)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT& max@0: subview_cube::operator[](const uword i) max@0: { max@0: const uword in_slice = i / n_elem_slice; max@0: const uword offset = in_slice * n_elem_slice; max@0: const uword j = i - offset; max@0: max@0: const uword in_col = j / n_rows; max@0: const uword in_row = j % n_rows; max@0: max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: subview_cube::operator[](const uword i) const max@0: { max@0: const uword in_slice = i / n_elem_slice; max@0: const uword offset = in_slice * n_elem_slice; max@0: const uword j = i - offset; max@0: max@0: const uword in_col = j / n_rows; max@0: const uword in_row = j % n_rows; max@0: max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT& max@0: subview_cube::operator()(const uword i) max@0: { max@0: arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds"); max@0: max@0: const uword in_slice = i / n_elem_slice; max@0: const uword offset = in_slice * n_elem_slice; max@0: const uword j = i - offset; max@0: max@0: const uword in_col = j / n_rows; max@0: const uword in_row = j % n_rows; max@0: max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: subview_cube::operator()(const uword i) const max@0: { max@0: arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds"); max@0: max@0: const uword in_slice = i / n_elem_slice; max@0: const uword offset = in_slice * n_elem_slice; max@0: const uword j = i - offset; max@0: max@0: const uword in_col = j / n_rows; max@0: const uword in_row = j % n_rows; max@0: max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT& max@0: subview_cube::operator()(const uword in_row, const uword in_col, const uword in_slice) max@0: { max@0: arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds"); max@0: max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT max@0: subview_cube::operator()(const uword in_row, const uword in_col, const uword in_slice) const max@0: { max@0: arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds"); max@0: max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT& max@0: subview_cube::at(const uword in_row, const uword in_col, const uword in_slice) max@0: { max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT max@0: subview_cube::at(const uword in_row, const uword in_col, const uword in_slice) const max@0: { max@0: const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT* max@0: subview_cube::slice_colptr(const uword in_slice, const uword in_col) max@0: { max@0: return & access::rw((*m_ptr).mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: const eT* max@0: subview_cube::slice_colptr(const uword in_slice, const uword in_col) const max@0: { max@0: return & m.mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: subview_cube::check_overlap(const subview_cube& x) const max@0: { max@0: const subview_cube& t = *this; max@0: max@0: if(&t.m != &x.m) max@0: { max@0: return false; max@0: } max@0: else max@0: { max@0: if( (t.n_elem == 0) || (x.n_elem == 0) ) max@0: { max@0: return false; max@0: } max@0: else max@0: { max@0: const uword t_row_start = t.aux_row1; max@0: const uword t_row_end_p1 = t_row_start + t.n_rows; max@0: max@0: const uword t_col_start = t.aux_col1; max@0: const uword t_col_end_p1 = t_col_start + t.n_cols; max@0: max@0: const uword t_slice_start = t.aux_slice1; max@0: const uword t_slice_end_p1 = t_slice_start + t.n_slices; max@0: max@0: max@0: const uword x_row_start = x.aux_row1; max@0: const uword x_row_end_p1 = x_row_start + x.n_rows; max@0: max@0: const uword x_col_start = x.aux_col1; max@0: const uword x_col_end_p1 = x_col_start + x.n_cols; max@0: max@0: const uword x_slice_start = x.aux_slice1; max@0: const uword x_slice_end_p1 = x_slice_start + x.n_slices; max@0: max@0: max@0: const bool outside_rows = ( (x_row_start >= t_row_end_p1 ) || (t_row_start >= x_row_end_p1 ) ); max@0: const bool outside_cols = ( (x_col_start >= t_col_end_p1 ) || (t_col_start >= x_col_end_p1 ) ); max@0: const bool outside_slices = ( (x_slice_start >= t_slice_end_p1) || (t_slice_start >= x_slice_end_p1) ); max@0: max@0: return ( (outside_rows == false) && (outside_cols == false) && (outside_slices == false) ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: subview_cube::check_overlap(const Mat& x) const max@0: { max@0: const subview_cube& t = *this; max@0: max@0: const uword t_aux_slice1 = t.aux_slice1; max@0: const uword t_aux_slice2_plus_1 = t_aux_slice1 + t.n_slices; max@0: max@0: for(uword slice = t_aux_slice1; slice < t_aux_slice2_plus_1; ++slice) max@0: { max@0: const Mat& y = *(t.m.mat_ptrs[slice]); max@0: max@0: if( x.memptr() == y.memptr() ) max@0: { max@0: return true; max@0: } max@0: } max@0: max@0: return false; max@0: } max@0: max@0: max@0: max@0: //! cube X = Y.subcube(...) max@0: template max@0: inline max@0: void max@0: subview_cube::extract(Cube& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing; max@0: // size setting and alias checking is done by either the Cube contructor or operator=() max@0: max@0: const uword n_rows = in.n_rows; max@0: const uword n_cols = in.n_cols; max@0: const uword n_slices = in.n_slices; max@0: max@0: arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_slices = %d") % out.n_rows % out.n_cols % out.n_slices % in.m.n_rows % in.m.n_cols % in.m.n_slices); max@0: max@0: max@0: for(uword slice = 0; slice < n_slices; ++slice) max@0: { max@0: for(uword col = 0; col < n_cols; ++col) max@0: { max@0: arrayops::copy( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: //! cube X += Y.subcube(...) max@0: template max@0: inline max@0: void max@0: subview_cube::plus_inplace(Cube& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "addition"); max@0: max@0: const uword n_rows = out.n_rows; max@0: const uword n_cols = out.n_cols; max@0: const uword n_slices = out.n_slices; max@0: max@0: for(uword slice = 0; slice max@0: inline max@0: void max@0: subview_cube::minus_inplace(Cube& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "subtraction"); max@0: max@0: const uword n_rows = out.n_rows; max@0: const uword n_cols = out.n_cols; max@0: const uword n_slices = out.n_slices; max@0: max@0: for(uword slice = 0; slice max@0: inline max@0: void max@0: subview_cube::schur_inplace(Cube& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "element-wise multiplication"); max@0: max@0: const uword n_rows = out.n_rows; max@0: const uword n_cols = out.n_cols; max@0: const uword n_slices = out.n_slices; max@0: max@0: for(uword slice = 0; slice max@0: inline max@0: void max@0: subview_cube::div_inplace(Cube& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "element-wise division"); max@0: max@0: const uword n_rows = out.n_rows; max@0: const uword n_cols = out.n_cols; max@0: const uword n_slices = out.n_slices; max@0: max@0: for(uword slice = 0; slice max@0: inline max@0: void max@0: subview_cube::extract(Mat& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); max@0: max@0: const uword in_n_rows = in.n_rows; max@0: const uword in_n_cols = in.n_cols; max@0: const uword in_n_slices = in.n_slices; max@0: max@0: const uword out_vec_state = out.vec_state; max@0: max@0: if(in_n_slices == 1) max@0: { max@0: out.set_size(in_n_rows, in_n_cols); max@0: max@0: for(uword col=0; col < in_n_cols; ++col) max@0: { max@0: arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); max@0: } max@0: } max@0: else max@0: { max@0: if(out_vec_state == 0) max@0: { max@0: if(in_n_cols == 1) max@0: { max@0: out.set_size(in_n_rows, in_n_slices); max@0: max@0: for(uword i=0; i < in_n_slices; ++i) max@0: { max@0: arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); max@0: } max@0: } max@0: else max@0: if(in_n_rows == 1) max@0: { max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: out.set_size(in_n_cols, in_n_slices); max@0: max@0: for(uword slice=0; slice < in_n_slices; ++slice) max@0: { max@0: const uword mod_slice = in_aux_slice1 + slice; max@0: max@0: eT* out_colptr = out.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < in_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); max@0: max@0: out_colptr[i] = tmp_i; max@0: out_colptr[j] = tmp_j; max@0: } max@0: max@0: if(i < in_n_cols) max@0: { max@0: out_colptr[i] = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: } max@0: } max@0: } max@0: } max@0: else max@0: { max@0: out.set_size(in_n_slices); max@0: max@0: eT* out_mem = out.memptr(); max@0: max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword i=0; i max@0: inline max@0: void max@0: subview_cube::plus_inplace(Mat& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_cube_as_mat(out, in, "addition", true); max@0: max@0: const uword in_n_rows = in.n_rows; max@0: const uword in_n_cols = in.n_cols; max@0: const uword in_n_slices = in.n_slices; max@0: max@0: const uword out_n_rows = out.n_rows; max@0: const uword out_n_cols = out.n_cols; max@0: const uword out_vec_state = out.vec_state; max@0: max@0: if(in_n_slices == 1) max@0: { max@0: for(uword col=0; col < in_n_cols; ++col) max@0: { max@0: arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); max@0: } max@0: } max@0: else max@0: { max@0: if(out_vec_state == 0) max@0: { max@0: if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) max@0: { max@0: for(uword i=0; i < in_n_slices; ++i) max@0: { max@0: arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); max@0: } max@0: } max@0: else max@0: if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) max@0: { max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword slice=0; slice < in_n_slices; ++slice) max@0: { max@0: const uword mod_slice = in_aux_slice1 + slice; max@0: max@0: eT* out_colptr = out.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < in_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); max@0: max@0: out_colptr[i] += tmp_i; max@0: out_colptr[j] += tmp_j; max@0: } max@0: max@0: if(i < in_n_cols) max@0: { max@0: out_colptr[i] += Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: } max@0: } max@0: } max@0: } max@0: else max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword i=0; i max@0: inline max@0: void max@0: subview_cube::minus_inplace(Mat& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_cube_as_mat(out, in, "subtraction", true); max@0: max@0: const uword in_n_rows = in.n_rows; max@0: const uword in_n_cols = in.n_cols; max@0: const uword in_n_slices = in.n_slices; max@0: max@0: const uword out_n_rows = out.n_rows; max@0: const uword out_n_cols = out.n_cols; max@0: const uword out_vec_state = out.vec_state; max@0: max@0: if(in_n_slices == 1) max@0: { max@0: for(uword col=0; col < in_n_cols; ++col) max@0: { max@0: arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); max@0: } max@0: } max@0: else max@0: { max@0: if(out_vec_state == 0) max@0: { max@0: if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) max@0: { max@0: for(uword i=0; i < in_n_slices; ++i) max@0: { max@0: arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); max@0: } max@0: } max@0: else max@0: if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) max@0: { max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword slice=0; slice < in_n_slices; ++slice) max@0: { max@0: const uword mod_slice = in_aux_slice1 + slice; max@0: max@0: eT* out_colptr = out.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < in_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); max@0: max@0: out_colptr[i] -= tmp_i; max@0: out_colptr[j] -= tmp_j; max@0: } max@0: max@0: if(i < in_n_cols) max@0: { max@0: out_colptr[i] -= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: } max@0: } max@0: } max@0: } max@0: else max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword i=0; i max@0: inline max@0: void max@0: subview_cube::schur_inplace(Mat& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true); max@0: max@0: const uword in_n_rows = in.n_rows; max@0: const uword in_n_cols = in.n_cols; max@0: const uword in_n_slices = in.n_slices; max@0: max@0: const uword out_n_rows = out.n_rows; max@0: const uword out_n_cols = out.n_cols; max@0: const uword out_vec_state = out.vec_state; max@0: max@0: if(in_n_slices == 1) max@0: { max@0: for(uword col=0; col < in_n_cols; ++col) max@0: { max@0: arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); max@0: } max@0: } max@0: else max@0: { max@0: if(out_vec_state == 0) max@0: { max@0: if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) max@0: { max@0: for(uword i=0; i < in_n_slices; ++i) max@0: { max@0: arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); max@0: } max@0: } max@0: else max@0: if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) max@0: { max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword slice=0; slice < in_n_slices; ++slice) max@0: { max@0: const uword mod_slice = in_aux_slice1 + slice; max@0: max@0: eT* out_colptr = out.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < in_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); max@0: max@0: out_colptr[i] *= tmp_i; max@0: out_colptr[j] *= tmp_j; max@0: } max@0: max@0: if(i < in_n_cols) max@0: { max@0: out_colptr[i] *= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: } max@0: } max@0: } max@0: } max@0: else max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword i=0; i max@0: inline max@0: void max@0: subview_cube::div_inplace(Mat& out, const subview_cube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); max@0: max@0: const uword in_n_rows = in.n_rows; max@0: const uword in_n_cols = in.n_cols; max@0: const uword in_n_slices = in.n_slices; max@0: max@0: const uword out_n_rows = out.n_rows; max@0: const uword out_n_cols = out.n_cols; max@0: const uword out_vec_state = out.vec_state; max@0: max@0: if(in_n_slices == 1) max@0: { max@0: for(uword col=0; col < in_n_cols; ++col) max@0: { max@0: arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); max@0: } max@0: } max@0: else max@0: { max@0: if(out_vec_state == 0) max@0: { max@0: if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) max@0: { max@0: for(uword i=0; i < in_n_slices; ++i) max@0: { max@0: arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); max@0: } max@0: } max@0: else max@0: if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) max@0: { max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword slice=0; slice < in_n_slices; ++slice) max@0: { max@0: const uword mod_slice = in_aux_slice1 + slice; max@0: max@0: eT* out_colptr = out.colptr(slice); max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < in_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); max@0: max@0: out_colptr[i] /= tmp_i; max@0: out_colptr[j] /= tmp_j; max@0: } max@0: max@0: if(i < in_n_cols) max@0: { max@0: out_colptr[i] /= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); max@0: } max@0: } max@0: } max@0: } max@0: else max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Cube& Q = in.m; max@0: max@0: const uword in_aux_row1 = in.aux_row1; max@0: const uword in_aux_col1 = in.aux_col1; max@0: const uword in_aux_slice1 = in.aux_slice1; max@0: max@0: for(uword i=0; i