From eda5bc26f44ee9a6f83dcf8c91f17296d7fc509d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 12 Feb 2024 14:52:43 +0100 Subject: Move into version control --- src/armadillo/include/armadillo_bits/Row_meat.hpp | 1888 +++++++++++++++++++++ 1 file changed, 1888 insertions(+) create mode 100644 src/armadillo/include/armadillo_bits/Row_meat.hpp (limited to 'src/armadillo/include/armadillo_bits/Row_meat.hpp') diff --git a/src/armadillo/include/armadillo_bits/Row_meat.hpp b/src/armadillo/include/armadillo_bits/Row_meat.hpp new file mode 100644 index 0000000..f61a179 --- /dev/null +++ b/src/armadillo/include/armadillo_bits/Row_meat.hpp @@ -0,0 +1,1888 @@ +// 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 Row +//! @{ + + +//! construct an empty row vector +template +inline +Row::Row() + : Mat(arma_vec_indicator(), 2) + { + arma_extra_debug_sigprint(); + } + + + +template +inline +Row::Row(const Row& X) + : Mat(arma_vec_indicator(), 1, X.n_elem, 2) + { + arma_extra_debug_sigprint(); + + arrayops::copy((*this).memptr(), X.memptr(), X.n_elem); + } + + + +//! construct a row vector with the specified number of n_elem +template +inline +Row::Row(const uword in_n_elem) + : Mat(arma_vec_indicator(), 1, in_n_elem, 2) + { + arma_extra_debug_sigprint(); + + if(arma_config::zero_init) + { + arma_extra_debug_print("Row::constructor: zeroing memory"); + arrayops::fill_zeros(Mat::memptr(), Mat::n_elem); + } + } + + + +template +inline +Row::Row(const uword in_n_rows, const uword in_n_cols) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(in_n_rows, in_n_cols); + + if(arma_config::zero_init) + { + arma_extra_debug_print("Row::constructor: zeroing memory"); + arrayops::fill_zeros(Mat::memptr(), Mat::n_elem); + } + } + + + +template +inline +Row::Row(const SizeMat& s) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(s.n_rows, s.n_cols); + + if(arma_config::zero_init) + { + arma_extra_debug_print("Row::constructor: zeroing memory"); + arrayops::fill_zeros(Mat::memptr(), Mat::n_elem); + } + } + + + +//! internal use only +template +template +inline +Row::Row(const uword in_n_elem, const arma_initmode_indicator&) + : Mat(arma_vec_indicator(), 1, in_n_elem, 2) + { + arma_extra_debug_sigprint(); + + if(do_zeros) + { + arma_extra_debug_print("Row::constructor: zeroing memory"); + arrayops::fill_zeros(Mat::memptr(), Mat::n_elem); + } + } + + + +//! internal use only +template +template +inline +Row::Row(const uword in_n_rows, const uword in_n_cols, const arma_initmode_indicator&) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(in_n_rows, in_n_cols); + + if(do_zeros) + { + arma_extra_debug_print("Row::constructor: zeroing memory"); + arrayops::fill_zeros(Mat::memptr(), Mat::n_elem); + } + } + + + +//! internal use only +template +template +inline +Row::Row(const SizeMat& s, const arma_initmode_indicator&) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(s.n_rows, s.n_cols); + + if(do_zeros) + { + arma_extra_debug_print("Row::constructor: zeroing memory"); + arrayops::fill_zeros(Mat::memptr(), Mat::n_elem); + } + } + + + +template +template +inline +Row::Row(const uword in_n_elem, const fill::fill_class& f) + : Mat(arma_vec_indicator(), 1, in_n_elem, 2) + { + arma_extra_debug_sigprint(); + + (*this).fill(f); + } + + + +template +template +inline +Row::Row(const uword in_n_rows, const uword in_n_cols, const fill::fill_class& f) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(in_n_rows, in_n_cols); + + (*this).fill(f); + } + + + +template +template +inline +Row::Row(const SizeMat& s, const fill::fill_class& f) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(s.n_rows, s.n_cols); + + (*this).fill(f); + } + + + +template +inline +Row::Row(const uword in_n_elem, const fill::scalar_holder f) + : Mat(arma_vec_indicator(), 1, in_n_elem, 2) + { + arma_extra_debug_sigprint(); + + (*this).fill(f.scalar); + } + + + +template +inline +Row::Row(const uword in_n_rows, const uword in_n_cols, const fill::scalar_holder f) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(in_n_rows, in_n_cols); + + (*this).fill(f.scalar); + } + + + +template +inline +Row::Row(const SizeMat& s, const fill::scalar_holder f) + : Mat(arma_vec_indicator(), 0, 0, 2) + { + arma_extra_debug_sigprint(); + + Mat::init_warm(s.n_rows, s.n_cols); + + (*this).fill(f.scalar); + } + + + +template +inline +Row::Row(const char* text) + : Mat(arma_vec_indicator(), 2) + { + arma_extra_debug_sigprint(); + + (*this).operator=(text); + } + + + +template +inline +Row& +Row::operator=(const char* text) + { + arma_extra_debug_sigprint(); + + Mat tmp(text); + + arma_debug_check( ((tmp.n_elem > 0) && (tmp.is_vec() == false)), "Mat::init(): requested size is not compatible with row vector layout" ); + + access::rw(tmp.n_rows) = 1; + access::rw(tmp.n_cols) = tmp.n_elem; + + (*this).steal_mem(tmp); + + return *this; + } + + + +template +inline +Row::Row(const std::string& text) + : Mat(arma_vec_indicator(), 2) + { + arma_extra_debug_sigprint(); + + (*this).operator=(text); + } + + + +template +inline +Row& +Row::operator=(const std::string& text) + { + arma_extra_debug_sigprint(); + + Mat tmp(text); + + arma_debug_check( ((tmp.n_elem > 0) && (tmp.is_vec() == false)), "Mat::init(): requested size is not compatible with row vector layout" ); + + access::rw(tmp.n_rows) = 1; + access::rw(tmp.n_cols) = tmp.n_elem; + + (*this).steal_mem(tmp); + + return *this; + } + + + +//! create a row vector from std::vector +template +inline +Row::Row(const std::vector& x) + : Mat(arma_vec_indicator(), 1, uword(x.size()), 2) + { + arma_extra_debug_sigprint_this(this); + + const uword N = uword(x.size()); + + if(N > 0) { arrayops::copy( Mat::memptr(), &(x[0]), N ); } + } + + + +//! create a row vector from std::vector +template +inline +Row& +Row::operator=(const std::vector& x) + { + arma_extra_debug_sigprint(); + + const uword N = uword(x.size()); + + Mat::init_warm(1, N); + + if(N > 0) { arrayops::copy( Mat::memptr(), &(x[0]), N ); } + + return *this; + } + + + +template +inline +Row::Row(const std::initializer_list& list) + : Mat(arma_vec_indicator(), 1, uword(list.size()), 2) + { + arma_extra_debug_sigprint_this(this); + + const uword N = uword(list.size()); + + if(N > 0) { arrayops::copy( Mat::memptr(), list.begin(), N ); } + } + + + +template +inline +Row& +Row::operator=(const std::initializer_list& list) + { + arma_extra_debug_sigprint(); + + const uword N = uword(list.size()); + + Mat::init_warm(1, N); + + if(N > 0) { arrayops::copy( Mat::memptr(), list.begin(), N ); } + + return *this; + } + + + +template +inline +Row::Row(Row&& X) + : Mat(arma_vec_indicator(), 2) + { + arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); + + access::rw(Mat::n_rows) = 1; + access::rw(Mat::n_cols) = X.n_cols; + access::rw(Mat::n_elem) = X.n_elem; + access::rw(Mat::n_alloc) = X.n_alloc; + + if( (X.n_alloc > arma_config::mat_prealloc) || (X.mem_state == 1) || (X.mem_state == 2) ) + { + access::rw(Mat::mem_state) = X.mem_state; + access::rw(Mat::mem) = X.mem; + + access::rw(X.n_rows) = 1; + access::rw(X.n_cols) = 0; + access::rw(X.n_elem) = 0; + access::rw(X.n_alloc) = 0; + access::rw(X.mem_state) = 0; + access::rw(X.mem) = nullptr; + } + else // condition: (X.n_alloc <= arma_config::mat_prealloc) || (X.mem_state == 0) || (X.mem_state == 3) + { + (*this).init_cold(); + + arrayops::copy( (*this).memptr(), X.mem, X.n_elem ); + + if( (X.mem_state == 0) && (X.n_alloc <= arma_config::mat_prealloc) ) + { + access::rw(X.n_rows) = 1; + access::rw(X.n_cols) = 0; + access::rw(X.n_elem) = 0; + access::rw(X.mem) = nullptr; + } + } + } + + + +template +inline +Row& +Row::operator=(Row&& X) + { + arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); + + (*this).steal_mem(X, true); + + return *this; + } + + + +// template +// inline +// Row::Row(Mat&& X) +// : Mat(arma_vec_indicator(), 2) +// { +// arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); +// +// if(X.n_rows != 1) { const Mat& XX = X; Mat::operator=(XX); return; } +// +// access::rw(Mat::n_rows) = 1; +// access::rw(Mat::n_cols) = X.n_cols; +// access::rw(Mat::n_elem) = X.n_elem; +// access::rw(Mat::n_alloc) = X.n_alloc; +// +// if( (X.n_alloc > arma_config::mat_prealloc) || (X.mem_state == 1) || (X.mem_state == 2) ) +// { +// access::rw(Mat::mem_state) = X.mem_state; +// access::rw(Mat::mem) = X.mem; +// +// access::rw(X.n_cols) = 0; +// access::rw(X.n_elem) = 0; +// access::rw(X.n_alloc) = 0; +// access::rw(X.mem_state) = 0; +// access::rw(X.mem) = nullptr; +// } +// else // condition: (X.n_alloc <= arma_config::mat_prealloc) || (X.mem_state == 0) || (X.mem_state == 3) +// { +// (*this).init_cold(); +// +// arrayops::copy( (*this).memptr(), X.mem, X.n_elem ); +// +// if( (X.mem_state == 0) && (X.n_alloc <= arma_config::mat_prealloc) ) +// { +// access::rw(X.n_cols) = 0; +// access::rw(X.n_elem) = 0; +// access::rw(X.mem) = nullptr; +// } +// } +// } +// +// +// +// template +// inline +// Row& +// Row::operator=(Mat&& X) +// { +// arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); +// +// if(X.n_rows != 1) { const Mat& XX = X; Mat::operator=(XX); return *this; } +// +// (*this).steal_mem(X, true); +// +// return *this; +// } + + + +template +inline +Row& +Row::operator=(const eT val) + { + arma_extra_debug_sigprint(); + + Mat::operator=(val); + + return *this; + } + + + +template +inline +Row& +Row::operator=(const Row& X) + { + arma_extra_debug_sigprint(); + + Mat::operator=(X); + + return *this; + } + + + +template +template +inline +Row::Row(const Base& X) + : Mat(arma_vec_indicator(), 2) + { + arma_extra_debug_sigprint(); + + Mat::operator=(X.get_ref()); + } + + + +template +template +inline +Row& +Row::operator=(const Base& X) + { + arma_extra_debug_sigprint(); + + Mat::operator=(X.get_ref()); + + return *this; + } + + + +template +template +inline +Row::Row(const SpBase& X) + : Mat(arma_vec_indicator(), 2) + { + arma_extra_debug_sigprint(); + + Mat::operator=(X.get_ref()); + } + + + +template +template +inline +Row& +Row::operator=(const SpBase& X) + { + arma_extra_debug_sigprint(); + + Mat::operator=(X.get_ref()); + + return *this; + } + + + +//! construct a row vector from a given auxiliary array +template +inline +Row::Row(eT* aux_mem, const uword aux_length, const bool copy_aux_mem, const bool strict) + : Mat(aux_mem, 1, aux_length, copy_aux_mem, strict) + { + arma_extra_debug_sigprint(); + + access::rw(Mat::vec_state) = 2; + } + + + +//! construct a row vector from a given auxiliary array +template +inline +Row::Row(const eT* aux_mem, const uword aux_length) + : Mat(aux_mem, 1, aux_length) + { + arma_extra_debug_sigprint(); + + access::rw(Mat::vec_state) = 2; + } + + + +template +template +inline +Row::Row + ( + const Base::pod_type, T1>& A, + const Base::pod_type, T2>& B + ) + { + arma_extra_debug_sigprint(); + + access::rw(Mat::vec_state) = 2; + + Mat::init(A,B); + } + + + +template +template +inline +Row::Row(const BaseCube& X) + { + arma_extra_debug_sigprint(); + + access::rw(Mat::vec_state) = 2; + + Mat::operator=(X); + } + + + +template +template +inline +Row& +Row::operator=(const BaseCube& X) + { + arma_extra_debug_sigprint(); + + Mat::operator=(X); + + return *this; + } + + + +template +inline +Row::Row(const subview_cube& X) + { + arma_extra_debug_sigprint(); + + access::rw(Mat::vec_state) = 2; + + Mat::operator=(X); + } + + + +template +inline +Row& +Row::operator=(const subview_cube& X) + { + arma_extra_debug_sigprint(); + + Mat::operator=(X); + + return *this; + } + + + +template +inline +mat_injector< Row > +Row::operator<<(const eT val) + { + return mat_injector< Row >(*this, val); + } + + + +template +arma_inline +const Op,op_htrans> +Row::t() const + { + return Op,op_htrans>(*this); + } + + + +template +arma_inline +const Op,op_htrans> +Row::ht() const + { + return Op,op_htrans>(*this); + } + + + +template +arma_inline +const Op,op_strans> +Row::st() const + { + return Op,op_strans>(*this); + } + + + +template +arma_inline +const Op,op_strans> +Row::as_col() const + { + return Op,op_strans>(*this); + } + + + +template +arma_inline +subview_row +Row::col(const uword in_col1) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (in_col1 >= Mat::n_cols), "Row::col(): indices out of bounds or incorrectly used" ); + + return subview_row(*this, 0, in_col1, 1); + } + + + +template +arma_inline +const subview_row +Row::col(const uword in_col1) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (in_col1 >= Mat::n_cols), "Row::col(): indices out of bounds or incorrectly used" ); + + return subview_row(*this, 0, in_col1, 1); + } + + + +template +arma_inline +subview_row +Row::cols(const uword in_col1, const uword in_col2) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used" ); + + const uword subview_n_cols = in_col2 - in_col1 + 1; + + return subview_row(*this, 0, in_col1, subview_n_cols); + } + + + +template +arma_inline +const subview_row +Row::cols(const uword in_col1, const uword in_col2) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used" ); + + const uword subview_n_cols = in_col2 - in_col1 + 1; + + return subview_row(*this, 0, in_col1, subview_n_cols); + } + + + +template +arma_inline +subview_row +Row::subvec(const uword in_col1, const uword in_col2) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used" ); + + const uword subview_n_cols = in_col2 - in_col1 + 1; + + return subview_row(*this, 0, in_col1, subview_n_cols); + } + + + +template +arma_inline +const subview_row +Row::subvec(const uword in_col1, const uword in_col2) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used" ); + + const uword subview_n_cols = in_col2 - in_col1 + 1; + + return subview_row(*this, 0, in_col1, subview_n_cols); + } + + + +template +arma_inline +subview_row +Row::cols(const span& col_span) + { + arma_extra_debug_sigprint(); + + return subvec(col_span); + } + + + +template +arma_inline +const subview_row +Row::cols(const span& col_span) const + { + arma_extra_debug_sigprint(); + + return subvec(col_span); + } + + + +template +arma_inline +subview_row +Row::subvec(const span& col_span) + { + arma_extra_debug_sigprint(); + + const bool col_all = col_span.whole; + + const uword local_n_cols = Mat::n_cols; + + const uword in_col1 = col_all ? 0 : col_span.a; + const uword in_col2 = col_span.b; + const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; + + arma_debug_check_bounds( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used" ); + + return subview_row(*this, 0, in_col1, subvec_n_cols); + } + + + +template +arma_inline +const subview_row +Row::subvec(const span& col_span) const + { + arma_extra_debug_sigprint(); + + const bool col_all = col_span.whole; + + const uword local_n_cols = Mat::n_cols; + + const uword in_col1 = col_all ? 0 : col_span.a; + const uword in_col2 = col_span.b; + const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; + + arma_debug_check_bounds( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used" ); + + return subview_row(*this, 0, in_col1, subvec_n_cols); + } + + + +template +arma_inline +subview_row +Row::operator()(const span& col_span) + { + arma_extra_debug_sigprint(); + + return subvec(col_span); + } + + + +template +arma_inline +const subview_row +Row::operator()(const span& col_span) const + { + arma_extra_debug_sigprint(); + + return subvec(col_span); + } + + + +template +arma_inline +subview_row +Row::subvec(const uword start_col, const SizeMat& s) + { + arma_extra_debug_sigprint(); + + arma_debug_check( (s.n_rows != 1), "Row::subvec(): given size does not specify a row vector" ); + + arma_debug_check_bounds( ( (start_col >= Mat::n_cols) || ((start_col + s.n_cols) > Mat::n_cols) ), "Row::subvec(): size out of bounds" ); + + return subview_row(*this, 0, start_col, s.n_cols); + } + + + +template +arma_inline +const subview_row +Row::subvec(const uword start_col, const SizeMat& s) const + { + arma_extra_debug_sigprint(); + + arma_debug_check( (s.n_rows != 1), "Row::subvec(): given size does not specify a row vector" ); + + arma_debug_check_bounds( ( (start_col >= Mat::n_cols) || ((start_col + s.n_cols) > Mat::n_cols) ), "Row::subvec(): size out of bounds" ); + + return subview_row(*this, 0, start_col, s.n_cols); + } + + + +template +arma_inline +subview_row +Row::head(const uword N) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (N > Mat::n_cols), "Row::head(): size out of bounds" ); + + return subview_row(*this, 0, 0, N); + } + + + +template +arma_inline +const subview_row +Row::head(const uword N) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (N > Mat::n_cols), "Row::head(): size out of bounds" ); + + return subview_row(*this, 0, 0, N); + } + + + +template +arma_inline +subview_row +Row::tail(const uword N) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (N > Mat::n_cols), "Row::tail(): size out of bounds" ); + + const uword start_col = Mat::n_cols - N; + + return subview_row(*this, 0, start_col, N); + } + + + +template +arma_inline +const subview_row +Row::tail(const uword N) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (N > Mat::n_cols), "Row::tail(): size out of bounds" ); + + const uword start_col = Mat::n_cols - N; + + return subview_row(*this, 0, start_col, N); + } + + + +template +arma_inline +subview_row +Row::head_cols(const uword N) + { + arma_extra_debug_sigprint(); + + return (*this).head(N); + } + + + +template +arma_inline +const subview_row +Row::head_cols(const uword N) const + { + arma_extra_debug_sigprint(); + + return (*this).head(N); + } + + + +template +arma_inline +subview_row +Row::tail_cols(const uword N) + { + arma_extra_debug_sigprint(); + + return (*this).tail(N); + } + + + +template +arma_inline +const subview_row +Row::tail_cols(const uword N) const + { + arma_extra_debug_sigprint(); + + return (*this).tail(N); + } + + + +//! remove specified columns +template +inline +void +Row::shed_col(const uword col_num) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( col_num >= Mat::n_cols, "Row::shed_col(): index out of bounds" ); + + shed_cols(col_num, col_num); + } + + + +//! remove specified columns +template +inline +void +Row::shed_cols(const uword in_col1, const uword in_col2) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds + ( + (in_col1 > in_col2) || (in_col2 >= Mat::n_cols), + "Row::shed_cols(): indices out of bounds or incorrectly used" + ); + + const uword n_keep_front = in_col1; + const uword n_keep_back = Mat::n_cols - (in_col2 + 1); + + Row X(n_keep_front + n_keep_back, arma_nozeros_indicator()); + + eT* X_mem = X.memptr(); + const eT* t_mem = (*this).memptr(); + + if(n_keep_front > 0) + { + arrayops::copy( X_mem, t_mem, n_keep_front ); + } + + if(n_keep_back > 0) + { + arrayops::copy( &(X_mem[n_keep_front]), &(t_mem[in_col2+1]), n_keep_back); + } + + Mat::steal_mem(X); + } + + + +//! remove specified columns +template +template +inline +void +Row::shed_cols(const Base& indices) + { + arma_extra_debug_sigprint(); + + Mat::shed_cols(indices); + } + + + +template +inline +void +Row::insert_cols(const uword col_num, const uword N, const bool set_to_zero) + { + arma_extra_debug_sigprint(); + + arma_ignore(set_to_zero); + + (*this).insert_cols(col_num, N); + } + + + +template +inline +void +Row::insert_cols(const uword col_num, const uword N) + { + arma_extra_debug_sigprint(); + + const uword t_n_cols = Mat::n_cols; + + const uword A_n_cols = col_num; + const uword B_n_cols = t_n_cols - col_num; + + // insertion at col_num == n_cols is in effect an append operation + arma_debug_check_bounds( (col_num > t_n_cols), "Row::insert_cols(): index out of bounds" ); + + if(N == 0) { return; } + + Row out(t_n_cols + N, arma_nozeros_indicator()); + + eT* out_mem = out.memptr(); + const eT* t_mem = (*this).memptr(); + + if(A_n_cols > 0) + { + arrayops::copy( out_mem, t_mem, A_n_cols ); + } + + if(B_n_cols > 0) + { + arrayops::copy( &(out_mem[col_num + N]), &(t_mem[col_num]), B_n_cols ); + } + + arrayops::fill_zeros( &(out_mem[col_num]), N ); + + Mat::steal_mem(out); + } + + + +//! insert the given object at the specified col position; +//! the given object must have one row +template +template +inline +void +Row::insert_cols(const uword col_num, const Base& X) + { + arma_extra_debug_sigprint(); + + Mat::insert_cols(col_num, X); + } + + + +template +arma_inline +eT& +Row::at(const uword i) + { + return access::rw(Mat::mem[i]); + } + + + +template +arma_inline +const eT& +Row::at(const uword i) const + { + return Mat::mem[i]; + } + + + +template +arma_inline +eT& +Row::at(const uword, const uword in_col) + { + return access::rw( Mat::mem[in_col] ); + } + + + +template +arma_inline +const eT& +Row::at(const uword, const uword in_col) const + { + return Mat::mem[in_col]; + } + + + +template +inline +typename Row::row_iterator +Row::begin_row(const uword row_num) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= Mat::n_rows), "Row::begin_row(): index out of bounds" ); + + return Mat::memptr(); + } + + + +template +inline +typename Row::const_row_iterator +Row::begin_row(const uword row_num) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= Mat::n_rows), "Row::begin_row(): index out of bounds" ); + + return Mat::memptr(); + } + + + +template +inline +typename Row::row_iterator +Row::end_row(const uword row_num) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= Mat::n_rows), "Row::end_row(): index out of bounds" ); + + return Mat::memptr() + Mat::n_cols; + } + + + +template +inline +typename Row::const_row_iterator +Row::end_row(const uword row_num) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= Mat::n_rows), "Row::end_row(): index out of bounds" ); + + return Mat::memptr() + Mat::n_cols; + } + + + +template +template +arma_inline +Row::fixed::fixed() + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + if(arma_config::zero_init) + { + arma_extra_debug_print("Row::fixed::constructor: zeroing memory"); + + eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); + + arrayops::inplace_set_fixed( mem_use, eT(0) ); + } + } + + + +template +template +arma_inline +Row::fixed::fixed(const fixed& X) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; + const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; + + arrayops::copy( dest, src, fixed_n_elem ); + } + + + +template +template +arma_inline +Row::fixed::fixed(const subview_cube& X) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + Row::operator=(X); + } + + + +template +template +inline +Row::fixed::fixed(const fill::scalar_holder f) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + (*this).fill(f.scalar); + } + + + +template +template +template +inline +Row::fixed::fixed(const fill::fill_class&) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + if(is_same_type::yes) { (*this).zeros(); } + if(is_same_type::yes) { (*this).ones(); } + if(is_same_type::yes) { (*this).eye(); } + if(is_same_type::yes) { (*this).randu(); } + if(is_same_type::yes) { (*this).randn(); } + } + + + +template +template +template +arma_inline +Row::fixed::fixed(const Base& A) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + Row::operator=(A.get_ref()); + } + + + +template +template +template +arma_inline +Row::fixed::fixed(const Base& A, const Base& B) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + Row::init(A,B); + } + + + +template +template +inline +Row::fixed::fixed(const eT* aux_mem) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; + + arrayops::copy( dest, aux_mem, fixed_n_elem ); + } + + + +template +template +inline +Row::fixed::fixed(const char* text) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + Row::operator=(text); + } + + + +template +template +inline +Row::fixed::fixed(const std::string& text) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + Row::operator=(text); + } + + + +template +template +template +Row& +Row::fixed::operator=(const Base& A) + { + arma_extra_debug_sigprint(); + + Row::operator=(A.get_ref()); + + return *this; + } + + + +template +template +Row& +Row::fixed::operator=(const eT val) + { + arma_extra_debug_sigprint(); + + Row::operator=(val); + + return *this; + } + + + +template +template +Row& +Row::fixed::operator=(const char* text) + { + arma_extra_debug_sigprint(); + + Row::operator=(text); + + return *this; + } + + + +template +template +Row& +Row::fixed::operator=(const std::string& text) + { + arma_extra_debug_sigprint(); + + Row::operator=(text); + + return *this; + } + + + +template +template +Row& +Row::fixed::operator=(const subview_cube& X) + { + arma_extra_debug_sigprint(); + + Row::operator=(X); + + return *this; + } + + + +template +template +inline +Row::fixed::fixed(const std::initializer_list& list) + : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) + { + arma_extra_debug_sigprint_this(this); + + (*this).operator=(list); + } + + + +template +template +inline +Row& +Row::fixed::operator=(const std::initializer_list& list) + { + arma_extra_debug_sigprint(); + + const uword N = uword(list.size()); + + arma_debug_check( (N > fixed_n_elem), "Row::fixed: initialiser list is too long" ); + + eT* this_mem = (*this).memptr(); + + arrayops::copy( this_mem, list.begin(), N ); + + for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } + + return *this; + } + + + +template +template +arma_inline +Row& +Row::fixed::operator=(const fixed& X) + { + arma_extra_debug_sigprint(); + + if(this != &X) + { + eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; + const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; + + arrayops::copy( dest, src, fixed_n_elem ); + } + + return *this; + } + + + +#if defined(ARMA_GOOD_COMPILER) + + template + template + template + inline + Row& + Row::fixed::operator=(const eOp& X) + { + arma_extra_debug_sigprint(); + + arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); + + const bool bad_alias = (eOp::proxy_type::has_subview && X.P.is_alias(*this)); + + if(bad_alias == false) + { + arma_debug_assert_same_size(uword(1), fixed_n_elem, X.get_n_rows(), X.get_n_cols(), "Row::fixed::operator="); + + eop_type::apply(*this, X); + } + else + { + arma_extra_debug_print("bad_alias = true"); + + Row tmp(X); + + (*this) = tmp; + } + + return *this; + } + + + + template + template + template + inline + Row& + Row::fixed::operator=(const eGlue& X) + { + arma_extra_debug_sigprint(); + + arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); + arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); + + const bool bad_alias = + ( + (eGlue::proxy1_type::has_subview && X.P1.is_alias(*this)) + || + (eGlue::proxy2_type::has_subview && X.P2.is_alias(*this)) + ); + + if(bad_alias == false) + { + arma_debug_assert_same_size(uword(1), fixed_n_elem, X.get_n_rows(), X.get_n_cols(), "Row::fixed::operator="); + + eglue_type::apply(*this, X); + } + else + { + arma_extra_debug_print("bad_alias = true"); + + Row tmp(X); + + (*this) = tmp; + } + + return *this; + } + +#endif + + + +template +template +arma_inline +const Op< typename Row::template fixed::Row_fixed_type, op_htrans > +Row::fixed::t() const + { + return Op< typename Row::template fixed::Row_fixed_type, op_htrans >(*this); + } + + + +template +template +arma_inline +const Op< typename Row::template fixed::Row_fixed_type, op_htrans > +Row::fixed::ht() const + { + return Op< typename Row::template fixed::Row_fixed_type, op_htrans >(*this); + } + + + +template +template +arma_inline +const Op< typename Row::template fixed::Row_fixed_type, op_strans > +Row::fixed::st() const + { + return Op< typename Row::template fixed::Row_fixed_type, op_strans >(*this); + } + + + +template +template +arma_inline +const eT& +Row::fixed::at_alt(const uword ii) const + { + #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) + + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + + #else + const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat::mem_local; + + memory::mark_as_aligned(mem_aligned); + + return mem_aligned[ii]; + #endif + } + + + +template +template +arma_inline +eT& +Row::fixed::operator[] (const uword ii) + { + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + } + + + +template +template +arma_inline +const eT& +Row::fixed::operator[] (const uword ii) const + { + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + } + + + +template +template +arma_inline +eT& +Row::fixed::at(const uword ii) + { + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + } + + + +template +template +arma_inline +const eT& +Row::fixed::at(const uword ii) const + { + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + } + + + +template +template +arma_inline +eT& +Row::fixed::operator() (const uword ii) + { + arma_debug_check_bounds( (ii >= fixed_n_elem), "Row::operator(): index out of bounds" ); + + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + } + + + +template +template +arma_inline +const eT& +Row::fixed::operator() (const uword ii) const + { + arma_debug_check_bounds( (ii >= fixed_n_elem), "Row::operator(): index out of bounds" ); + + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + } + + + +template +template +arma_inline +eT& +Row::fixed::at(const uword, const uword in_col) + { + return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; + } + + + +template +template +arma_inline +const eT& +Row::fixed::at(const uword, const uword in_col) const + { + return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; + } + + + +template +template +arma_inline +eT& +Row::fixed::operator() (const uword in_row, const uword in_col) + { + arma_debug_check_bounds( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" ); + + return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; + } + + + +template +template +arma_inline +const eT& +Row::fixed::operator() (const uword in_row, const uword in_col) const + { + arma_debug_check_bounds( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" ); + + return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; + } + + + +template +template +arma_inline +eT* +Row::fixed::memptr() + { + return (use_extra) ? mem_local_extra : Mat::mem_local; + } + + + +template +template +arma_inline +const eT* +Row::fixed::memptr() const + { + return (use_extra) ? mem_local_extra : Mat::mem_local; + } + + + +template +template +inline +const Row& +Row::fixed::fill(const eT val) + { + arma_extra_debug_sigprint(); + + eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); + + arrayops::inplace_set_fixed( mem_use, val ); + + return *this; + } + + + +template +template +inline +const Row& +Row::fixed::zeros() + { + arma_extra_debug_sigprint(); + + eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); + + arrayops::inplace_set_fixed( mem_use, eT(0) ); + + return *this; + } + + + +template +template +inline +const Row& +Row::fixed::ones() + { + arma_extra_debug_sigprint(); + + eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); + + arrayops::inplace_set_fixed( mem_use, eT(1) ); + + return *this; + } + + + +template +inline +Row::Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem) + : Mat(arma_fixed_indicator(), 1, in_n_elem, 2, in_mem) + { + arma_extra_debug_sigprint_this(this); + } + + + +#if defined(ARMA_EXTRA_ROW_MEAT) + #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_MEAT) +#endif + + + +//! @} -- cgit v1.2.1