// SPDX-License-Identifier: Apache-2.0 // // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) // Copyright 2008-2016 National ICT Australia (NICTA) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ //! \addtogroup subview_cube_slices //! @{ template inline subview_cube_slices::~subview_cube_slices() { arma_extra_debug_sigprint(); } template arma_inline subview_cube_slices::subview_cube_slices ( const Cube& in_m, const Base& in_si ) : m (in_m ) , base_si(in_si) { arma_extra_debug_sigprint(); } template inline void subview_cube_slices::inplace_rand(const uword rand_mode) { arma_extra_debug_sigprint(); Cube& m_local = const_cast< Cube& >(m); const uword m_n_slices = m_local.n_slices; const uword m_n_elem_slice = m_local.n_elem_slice; const quasi_unwrap U(base_si.get_ref()); const umat& si = U.M; arma_debug_check ( ( (si.is_vec() == false) && (si.is_empty() == false) ), "Cube::slices(): given object must be a vector" ); const uword* si_mem = si.memptr(); const uword si_n_elem = si.n_elem; for(uword si_count=0; si_count < si_n_elem; ++si_count) { const uword i = si_mem[si_count]; arma_debug_check_bounds( (i >= m_n_slices), "Cube::slices(): index out of bounds" ); eT* m_slice_ptr = m_local.slice_memptr(i); if(rand_mode == 0) { arma_rng::randu::fill(m_slice_ptr, m_n_elem_slice); } if(rand_mode == 1) { arma_rng::randn::fill(m_slice_ptr, m_n_elem_slice); } } } template template inline void subview_cube_slices::inplace_op(const eT val) { arma_extra_debug_sigprint(); Cube& m_local = const_cast< Cube& >(m); const uword m_n_slices = m_local.n_slices; const uword m_n_elem_slice = m_local.n_elem_slice; const quasi_unwrap U(base_si.get_ref()); const umat& si = U.M; arma_debug_check ( ( (si.is_vec() == false) && (si.is_empty() == false) ), "Cube::slices(): given object must be a vector" ); const uword* si_mem = si.memptr(); const uword si_n_elem = si.n_elem; for(uword si_count=0; si_count < si_n_elem; ++si_count) { const uword i = si_mem[si_count]; arma_debug_check_bounds( (i >= m_n_slices), "Cube::slices(): index out of bounds" ); eT* m_slice_ptr = m_local.slice_memptr(i); if(is_same_type::yes) { arrayops::inplace_set (m_slice_ptr, val, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_plus (m_slice_ptr, val, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_minus(m_slice_ptr, val, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_mul (m_slice_ptr, val, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_div (m_slice_ptr, val, m_n_elem_slice); } } } template template inline void subview_cube_slices::inplace_op(const BaseCube& x) { arma_extra_debug_sigprint(); Cube& m_local = const_cast< Cube& >(m); const uword m_n_slices = m_local.n_slices; const uword m_n_elem_slice = m_local.n_elem_slice; const quasi_unwrap U(base_si.get_ref()); const umat& si = U.M; arma_debug_check ( ( (si.is_vec() == false) && (si.is_empty() == false) ), "Cube::slices(): given object must be a vector" ); const uword* si_mem = si.memptr(); const uword si_n_elem = si.n_elem; const unwrap_cube_check tmp(x.get_ref(), m_local); const Cube& X = tmp.M; arma_debug_assert_same_size( m_local.n_rows, m_local.n_cols, si_n_elem, X.n_rows, X.n_cols, X.n_slices, "Cube::slices()" ); for(uword si_count=0; si_count < si_n_elem; ++si_count) { const uword i = si_mem[si_count]; arma_debug_check_bounds( (i >= m_n_slices), "Cube::slices(): index out of bounds" ); eT* m_slice_ptr = m_local.slice_memptr(i); const eT* X_slice_ptr = X.slice_memptr(si_count); if(is_same_type::yes) { arrayops::copy (m_slice_ptr, X_slice_ptr, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_plus (m_slice_ptr, X_slice_ptr, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_minus(m_slice_ptr, X_slice_ptr, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_mul (m_slice_ptr, X_slice_ptr, m_n_elem_slice); } if(is_same_type::yes) { arrayops::inplace_div (m_slice_ptr, X_slice_ptr, m_n_elem_slice); } } } // // template inline void subview_cube_slices::fill(const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_cube_slices::zeros() { arma_extra_debug_sigprint(); inplace_op(eT(0)); } template inline void subview_cube_slices::ones() { arma_extra_debug_sigprint(); inplace_op(eT(1)); } template inline void subview_cube_slices::randu() { arma_extra_debug_sigprint(); inplace_rand(0); } template inline void subview_cube_slices::randn() { arma_extra_debug_sigprint(); inplace_rand(1); } template inline void subview_cube_slices::operator+= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_cube_slices::operator-= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_cube_slices::operator*= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_cube_slices::operator/= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } // // template template inline void subview_cube_slices::operator_equ(const subview_cube_slices& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator= (const subview_cube_slices& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } //! work around compiler bugs template inline void subview_cube_slices::operator= (const subview_cube_slices& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } template template inline void subview_cube_slices::operator+= (const subview_cube_slices& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator-= (const subview_cube_slices& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator%= (const subview_cube_slices& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator/= (const subview_cube_slices& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator= (const BaseCube& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator+= (const BaseCube& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator-= (const BaseCube& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator%= (const BaseCube& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_cube_slices::operator/= (const BaseCube& x) { arma_extra_debug_sigprint(); inplace_op(x); } // // template inline void subview_cube_slices::extract(Cube& out, const subview_cube_slices& in) { arma_extra_debug_sigprint(); const Cube& m_local = in.m; const uword m_n_slices = m_local.n_slices; const uword m_n_elem_slice = m_local.n_elem_slice; const quasi_unwrap U(in.base_si.get_ref()); const umat& si = U.M; arma_debug_check ( ( (si.is_vec() == false) && (si.is_empty() == false) ), "Cube::slices(): given object must be a vector" ); const uword* si_mem = si.memptr(); const uword si_n_elem = si.n_elem; out.set_size(m_local.n_rows, m_local.n_cols, si_n_elem); for(uword si_count=0; si_count < si_n_elem; ++si_count) { const uword i = si_mem[si_count]; arma_debug_check_bounds( (i >= m_n_slices), "Cube::slices(): index out of bounds" ); eT* out_slice_ptr = out.slice_memptr(si_count); const eT* m_slice_ptr = m_local.slice_memptr(i); arrayops::copy(out_slice_ptr, m_slice_ptr, m_n_elem_slice); } } // TODO: implement a dedicated function instead of creating a temporary template inline void subview_cube_slices::plus_inplace(Cube& out, const subview_cube_slices& in) { arma_extra_debug_sigprint(); const Cube tmp(in); out += tmp; } template inline void subview_cube_slices::minus_inplace(Cube& out, const subview_cube_slices& in) { arma_extra_debug_sigprint(); const Cube tmp(in); out -= tmp; } template inline void subview_cube_slices::schur_inplace(Cube& out, const subview_cube_slices& in) { arma_extra_debug_sigprint(); const Cube tmp(in); out %= tmp; } template inline void subview_cube_slices::div_inplace(Cube& out, const subview_cube_slices& in) { arma_extra_debug_sigprint(); const Cube tmp(in); out /= tmp; } //! @}