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 Mat max@0: //! @{ max@0: max@0: max@0: template max@0: inline max@0: Mat::~Mat() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: if(mem_state == 0) max@0: { max@0: if(n_elem > arma_config::mat_prealloc) max@0: { max@0: #if defined(ARMA_USE_TBB_ALLOC) max@0: scalable_free((void *)(mem)); max@0: #else max@0: delete [] mem; max@0: #endif max@0: } max@0: } max@0: max@0: if(arma_config::debug == true) max@0: { max@0: // try to expose buggy user code that accesses deleted objects max@0: access::rw(n_rows) = 0; max@0: access::rw(n_cols) = 0; max@0: access::rw(n_elem) = 0; max@0: access::rw(mem) = 0; max@0: } max@0: max@0: arma_type_check(( is_supported_elem_type::value == false )); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: Mat::Mat() max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: } max@0: max@0: max@0: max@0: //! construct the matrix to have user specified dimensions max@0: template max@0: inline max@0: Mat::Mat(const uword in_n_rows, const uword in_n_cols) max@0: : n_rows(in_n_rows) max@0: , n_cols(in_n_cols) max@0: , n_elem(in_n_rows*in_n_cols) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init_cold(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat::init_cold() max@0: { max@0: arma_extra_debug_sigprint( arma_boost::format("n_rows = %d, n_cols = %d") % n_rows % n_cols ); max@0: max@0: // ensure that n_elem can hold the result of (n_rows * n_cols) max@0: max@0: arma_debug_check max@0: ( max@0: ( max@0: ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) ) max@0: ? ( (float(n_rows) * float(n_cols)) > float(ARMA_MAX_UWORD) ) max@0: : false max@0: ), max@0: "Mat::init(): requested size is too large" max@0: ); max@0: max@0: if(n_elem <= arma_config::mat_prealloc) max@0: { max@0: access::rw(mem) = mem_local; max@0: } max@0: else max@0: { max@0: arma_extra_debug_print("Mat::init(): allocating memory"); max@0: max@0: #if defined(ARMA_USE_TBB_ALLOC) max@0: access::rw(mem) = (eT *) scalable_malloc(sizeof(eT)*n_elem); max@0: #else max@0: access::rw(mem) = new(std::nothrow) eT[n_elem]; max@0: #endif max@0: max@0: arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! internal matrix construction; if the requested size is small enough, memory from the stack is used. otherwise memory is allocated via 'new' max@0: template max@0: inline max@0: void max@0: Mat::init_warm(uword in_n_rows, uword in_n_cols) max@0: { max@0: arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d") % in_n_rows % in_n_cols ); max@0: max@0: if( (n_rows == in_n_rows) && (n_cols == in_n_cols) ) max@0: { max@0: return; max@0: } max@0: max@0: bool err_state = false; max@0: char* err_msg = 0; max@0: max@0: const uhword t_vec_state = vec_state; max@0: const uhword t_mem_state = mem_state; max@0: max@0: arma_debug_set_error max@0: ( max@0: err_state, max@0: err_msg, max@0: (t_mem_state == 3), max@0: "Mat::init(): size is fixed and hence cannot be changed" max@0: ); max@0: max@0: if(t_vec_state > 0) max@0: { max@0: if( (in_n_rows == 0) && (in_n_cols == 0) ) max@0: { max@0: if(t_vec_state == 1) max@0: { max@0: in_n_cols = 1; max@0: } max@0: else max@0: if(t_vec_state == 2) max@0: { max@0: in_n_rows = 1; max@0: } max@0: } max@0: else max@0: { max@0: arma_debug_set_error max@0: ( max@0: err_state, max@0: err_msg, max@0: ( ((t_vec_state == 1) && (in_n_cols != 1)) || ((t_vec_state == 2) && (in_n_rows != 1)) ), max@0: "Mat::init(): object is a vector; requested size is not compatible" max@0: ); max@0: } max@0: } max@0: max@0: // ensure that n_elem can hold the result of (n_rows * n_cols) max@0: max@0: arma_debug_set_error max@0: ( max@0: err_state, max@0: err_msg, max@0: ( max@0: ( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) ) max@0: ? ( (float(in_n_rows) * float(in_n_cols)) > float(ARMA_MAX_UWORD) ) max@0: : false max@0: ), max@0: "Mat::init(): requested size is too large" max@0: ); max@0: max@0: arma_debug_check(err_state, err_msg); max@0: max@0: const uword old_n_elem = n_elem; max@0: const uword new_n_elem = in_n_rows * in_n_cols; max@0: max@0: if(old_n_elem == new_n_elem) max@0: { max@0: arma_extra_debug_print("Mat::init(): reusing memory"); max@0: max@0: access::rw(n_rows) = in_n_rows; max@0: access::rw(n_cols) = in_n_cols; max@0: } max@0: else max@0: { max@0: arma_debug_check max@0: ( max@0: (t_mem_state == 2), max@0: "Mat::init(): mismatch between size of auxiliary memory and requested size" max@0: ); max@0: max@0: if(t_mem_state == 0) max@0: { max@0: if(old_n_elem > arma_config::mat_prealloc) max@0: { max@0: arma_extra_debug_print("Mat::init(): freeing memory"); max@0: max@0: #if defined(ARMA_USE_TBB_ALLOC) max@0: scalable_free((void *)(mem)); max@0: #else max@0: delete [] mem; max@0: #endif max@0: } max@0: } max@0: max@0: max@0: if(new_n_elem <= arma_config::mat_prealloc) max@0: { max@0: access::rw(mem) = mem_local; max@0: } max@0: else max@0: { max@0: arma_extra_debug_print("Mat::init(): allocating memory"); max@0: max@0: #if defined(ARMA_USE_TBB_ALLOC) max@0: access::rw(mem) = (eT *) scalable_malloc(sizeof(eT)*new_n_elem); max@0: #else max@0: access::rw(mem) = new(std::nothrow) eT[new_n_elem]; max@0: #endif max@0: max@0: arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" ); max@0: } max@0: max@0: access::rw(n_rows) = in_n_rows; max@0: access::rw(n_cols) = in_n_cols; max@0: access::rw(n_elem) = new_n_elem; max@0: access::rw(mem_state) = 0; max@0: } max@0: } max@0: max@0: max@0: max@0: //! create the matrix from a textual description max@0: template max@0: inline max@0: Mat::Mat(const char* text) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init( std::string(text) ); max@0: } max@0: max@0: max@0: max@0: //! create the matrix from a textual description max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const char* text) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: init( std::string(text) ); max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! create the matrix from a textual description max@0: template max@0: inline max@0: Mat::Mat(const std::string& text) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init(text); max@0: } max@0: max@0: max@0: max@0: //! create the matrix from a textual description max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const std::string& text) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: init(text); max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! internal function to create the matrix from a textual description max@0: template max@0: inline max@0: void max@0: Mat::init(const std::string& text) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: // max@0: // work out the size max@0: max@0: uword t_n_rows = 0; max@0: uword t_n_cols = 0; max@0: max@0: bool t_n_cols_found = false; max@0: max@0: std::string token; max@0: max@0: std::string::size_type line_start = 0; max@0: std::string::size_type line_end = 0; max@0: max@0: while( line_start < text.length() ) max@0: { max@0: max@0: line_end = text.find(';', line_start); max@0: max@0: if(line_end == std::string::npos) max@0: line_end = text.length()-1; max@0: max@0: std::string::size_type line_len = line_end - line_start + 1; max@0: std::stringstream line_stream( text.substr(line_start,line_len) ); max@0: max@0: max@0: uword line_n_cols = 0; max@0: while(line_stream >> token) max@0: { max@0: ++line_n_cols; max@0: } max@0: max@0: max@0: if(line_n_cols > 0) max@0: { max@0: if(t_n_cols_found == false) max@0: { max@0: t_n_cols = line_n_cols; max@0: t_n_cols_found = true; max@0: } max@0: else max@0: arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent number of columns in given string"); max@0: max@0: ++t_n_rows; max@0: } max@0: line_start = line_end+1; max@0: max@0: } max@0: max@0: Mat& x = *this; max@0: x.set_size(t_n_rows, t_n_cols); max@0: max@0: line_start = 0; max@0: line_end = 0; max@0: max@0: uword row = 0; max@0: max@0: while( line_start < text.length() ) max@0: { max@0: max@0: line_end = text.find(';', line_start); max@0: max@0: if(line_end == std::string::npos) max@0: line_end = text.length()-1; max@0: max@0: std::string::size_type line_len = line_end - line_start + 1; max@0: std::stringstream line_stream( text.substr(line_start,line_len) ); max@0: max@0: // uword col = 0; max@0: // while(line_stream >> token) max@0: // { max@0: // x.at(row,col) = strtod(token.c_str(), 0); max@0: // ++col; max@0: // } max@0: max@0: uword col = 0; max@0: eT val; max@0: while(line_stream >> val) max@0: { max@0: x.at(row,col) = val; max@0: ++col; max@0: } max@0: max@0: ++row; max@0: line_start = line_end+1; max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: #if defined(ARMA_USE_CXX11) max@0: max@0: template max@0: inline max@0: Mat::Mat(const std::initializer_list& list) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init(list); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const std::initializer_list& list) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: init(list); max@0: max@0: return *this; max@0: } max@0: max@0: #endif max@0: max@0: max@0: max@0: //! Set the matrix to be equal to the specified scalar. max@0: //! NOTE: the size of the matrix will be 1x1 max@0: template max@0: arma_inline max@0: const Mat& max@0: Mat::operator=(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: init_warm(1,1); max@0: access::rw(mem[0]) = val; max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! In-place addition of a scalar to all elements of the matrix max@0: template max@0: arma_inline max@0: const Mat& max@0: Mat::operator+=(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_plus( memptr(), val, n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! In-place subtraction of a scalar from all elements of the matrix max@0: template max@0: arma_inline max@0: const Mat& max@0: Mat::operator-=(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_minus( memptr(), val, n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! In-place multiplication of all elements of the matrix with a scalar max@0: template max@0: arma_inline max@0: const Mat& max@0: Mat::operator*=(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_mul( memptr(), val, n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! In-place division of all elements of the matrix with a scalar max@0: template max@0: arma_inline max@0: const Mat& max@0: Mat::operator/=(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_div( memptr(), val, n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from a given matrix max@0: template max@0: inline max@0: Mat::Mat(const Mat& in_mat) max@0: : n_rows(in_mat.n_rows) max@0: , n_cols(in_mat.n_cols) max@0: , n_elem(in_mat.n_elem) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); max@0: max@0: init_cold(); max@0: max@0: arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from a given matrix max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const Mat& in_mat) max@0: { max@0: arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); max@0: max@0: if(this != &in_mat) max@0: { max@0: init_warm(in_mat.n_rows, in_mat.n_cols); max@0: max@0: arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: #if defined(ARMA_USE_CXX11) max@0: max@0: template max@0: inline max@0: void max@0: Mat::init(const std::initializer_list& list) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword N = list.size(); max@0: max@0: set_size(1, N); max@0: max@0: arrayops::copy( memptr(), list.begin(), N ); max@0: } max@0: max@0: #endif max@0: max@0: max@0: max@0: //! for constructing a complex matrix out of two non-complex matrices max@0: template max@0: template max@0: inline max@0: void max@0: Mat::init max@0: ( max@0: const Base::pod_type, T1>& A, max@0: const Base::pod_type, T2>& B max@0: ) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type T; max@0: typedef typename Proxy::ea_type ea_type1; max@0: typedef typename Proxy::ea_type ea_type2; max@0: max@0: arma_type_check(( is_complex::value == false )); //!< compile-time abort if eT isn't std::complex max@0: arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex max@0: max@0: arma_type_check(( is_same_type< std::complex, eT >::value == false )); //!< compile-time abort if types are not compatible max@0: max@0: const Proxy X(A.get_ref()); max@0: const Proxy Y(B.get_ref()); max@0: max@0: arma_assert_same_size(X, Y, "Mat()"); max@0: max@0: init_warm(X.get_n_rows(), X.get_n_cols()); max@0: max@0: const uword N = n_elem; max@0: eT* out_mem = memptr(); max@0: ea_type1 PX = X.get_ea(); max@0: ea_type2 PY = Y.get_ea(); max@0: max@0: for(uword i=0; i(PX[i], PY[i]); max@0: } max@0: } max@0: max@0: max@0: max@0: //! try to steal the memory from a given matrix; max@0: //! if memory can't be stolen, copy the given matrix max@0: template max@0: inline max@0: void max@0: Mat::steal_mem(Mat& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(this != &x) max@0: { max@0: const uword x_n_rows = x.n_rows; max@0: const uword x_n_cols = x.n_cols; max@0: const uword x_n_elem = x.n_elem; max@0: const uword x_vec_state = x.vec_state; max@0: const uword x_mem_state = x.mem_state; max@0: max@0: const uword t_vec_state = vec_state; max@0: max@0: bool layout_ok = false; max@0: max@0: if(t_vec_state == x_vec_state) max@0: { max@0: layout_ok = true; max@0: } max@0: else max@0: { max@0: if( (t_vec_state == 1) && ( x_n_cols == 1) ) max@0: { max@0: layout_ok = true; max@0: } max@0: max@0: if( (t_vec_state == 2) && ( x_n_rows == 1) ) max@0: { max@0: layout_ok = true; max@0: } max@0: } max@0: max@0: max@0: if( (x_mem_state == 0) && (x_n_elem > arma_config::mat_prealloc) && (layout_ok == true) ) max@0: { max@0: reset(); max@0: // note: calling reset() also prevents fixed size matrices from changing size or using non-local memory max@0: max@0: access::rw(n_rows) = x_n_rows; max@0: access::rw(n_cols) = x_n_cols; max@0: access::rw(n_elem) = x_n_elem; max@0: access::rw(mem) = x.mem; max@0: max@0: access::rw(x.n_rows) = 0; max@0: access::rw(x.n_cols) = 0; max@0: access::rw(x.n_elem) = 0; max@0: access::rw(x.mem) = 0; max@0: } max@0: else max@0: { max@0: (*this).operator=(x); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from a given auxiliary array of eTs. max@0: //! if copy_aux_mem is true, new memory is allocated and the array is copied. max@0: //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying). max@0: //! the default is to copy the array. max@0: max@0: template max@0: inline max@0: Mat::Mat(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem, const bool strict) max@0: : n_rows ( aux_n_rows ) max@0: , n_cols ( aux_n_cols ) max@0: , n_elem ( aux_n_rows*aux_n_cols ) max@0: , vec_state( 0 ) max@0: , mem_state( copy_aux_mem ? 0 : ( strict ? 2 : 1 ) ) max@0: , mem ( copy_aux_mem ? 0 : aux_mem ) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: if(copy_aux_mem == true) max@0: { max@0: init_cold(); max@0: max@0: arrayops::copy( memptr(), aux_mem, n_elem ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from a given auxiliary read-only array of eTs. max@0: //! the array is copied. max@0: template max@0: inline max@0: Mat::Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) max@0: : n_rows(aux_n_rows) max@0: , n_cols(aux_n_cols) max@0: , n_elem(aux_n_rows*aux_n_cols) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init_cold(); max@0: max@0: arrayops::copy( memptr(), aux_mem, n_elem ); max@0: } max@0: max@0: max@0: max@0: //! DANGEROUS! Construct a temporary matrix, using auxiliary memory. max@0: //! This constructor is NOT intended for usage by user code. max@0: //! Its sole purpose is to be used by the Cube class. max@0: max@0: template max@0: inline max@0: Mat::Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) max@0: : n_rows (aux_n_rows ) max@0: , n_cols (aux_n_cols ) max@0: , n_elem (aux_n_rows*aux_n_cols) max@0: , vec_state(0 ) max@0: , mem_state(3 ) max@0: , mem (aux_mem ) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: arma_ignore(junk); max@0: } max@0: max@0: max@0: max@0: //! in-place matrix addition max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const Mat& m) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(*this, m, "addition"); max@0: max@0: arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix subtraction max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const Mat& m) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(*this, m, "subtraction"); max@0: max@0: arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix multiplication max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const Mat& m) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: glue_times::apply_inplace(*this, m); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix multiplication max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const Mat& m) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(*this, m, "element-wise multiplication"); max@0: max@0: arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix division max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const Mat& m) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(*this, m, "element-wise division"); max@0: max@0: arrayops::inplace_div( memptr(), m.memptr(), n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat::Mat(const BaseCube& X) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: (*this).operator=(X); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat& out = *this; max@0: max@0: const unwrap_cube tmp(X.get_ref()); max@0: const Cube& in = tmp.M; 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: 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: 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 = in.at(0, i, slice); max@0: const eT tmp_j = in.at(0, j, 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] = in.at(0, i, 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: for(uword i=0; i max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat& out = *this; max@0: max@0: const unwrap_cube tmp(X.get_ref()); max@0: const Cube& in = tmp.M; 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: for(uword slice=0; slice < in_n_slices; ++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 = in.at(0, i, slice); max@0: const eT tmp_j = in.at(0, j, 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] += in.at(0, i, 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: for(uword i=0; i max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat& out = *this; max@0: max@0: const unwrap_cube tmp(X.get_ref()); max@0: const Cube& in = tmp.M; 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: for(uword slice=0; slice < in_n_slices; ++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 = in.at(0, i, slice); max@0: const eT tmp_j = in.at(0, j, 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] -= in.at(0, i, 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: for(uword i=0; i max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat B(X); max@0: max@0: (*this).operator*=(B); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat& out = *this; max@0: max@0: const unwrap_cube tmp(X.get_ref()); max@0: const Cube& in = tmp.M; 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: for(uword slice=0; slice < in_n_slices; ++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 = in.at(0, i, slice); max@0: const eT tmp_j = in.at(0, j, 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] *= in.at(0, i, 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: for(uword i=0; i max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat& out = *this; max@0: max@0: const unwrap_cube tmp(X.get_ref()); max@0: const Cube& in = tmp.M; 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: for(uword slice=0; slice < in_n_slices; ++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 = in.at(0, i, slice); max@0: const eT tmp_j = in.at(0, j, 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] /= in.at(0, i, 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: for(uword i=0; i max@0: template max@0: inline max@0: Mat::Mat max@0: ( max@0: const Base::pod_type,T1>& A, max@0: const Base::pod_type,T2>& B max@0: ) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init(A,B); max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation) max@0: template max@0: inline max@0: Mat::Mat(const subview& X) max@0: : n_rows(X.n_rows) max@0: , n_cols(X.n_cols) max@0: , n_elem(X.n_elem) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init_cold(); max@0: max@0: subview::extract(*this, X); max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool alias = (this == &(X.m)); max@0: max@0: if(alias == false) max@0: { max@0: init_warm(X.n_rows, X.n_cols); max@0: max@0: subview::extract(*this, X); max@0: } max@0: else max@0: { max@0: Mat tmp(X); max@0: max@0: steal_mem(tmp); max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: //! in-place matrix addition (using a submatrix on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::plus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: //! in-place matrix subtraction (using a submatrix on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::minus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix mutiplication (using a submatrix on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: glue_times::apply_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix mutiplication (using a submatrix on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::schur_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix division (using a submatrix on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::div_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from a subview_cube instance max@0: template max@0: inline max@0: Mat::Mat(const subview_cube& x) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: this->operator=(x); max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from a subview_cube instance max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const subview_cube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_cube::extract(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix addition (using a single-slice subcube on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const subview_cube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_cube::plus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix subtraction (using a single-slice subcube on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const subview_cube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_cube::minus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix mutiplication (using a single-slice subcube on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const subview_cube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat tmp(X); max@0: glue_times::apply_inplace(*this, tmp); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix mutiplication (using a single-slice subcube on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const subview_cube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_cube::schur_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix division (using a single-slice subcube on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const subview_cube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_cube::div_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation) max@0: template max@0: inline max@0: Mat::Mat(const diagview& X) max@0: : n_rows(X.n_rows) max@0: , n_cols(X.n_cols) max@0: , n_elem(X.n_elem) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init_cold(); max@0: max@0: diagview::extract(*this, X); max@0: } max@0: max@0: max@0: max@0: //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool alias = (this == &(X.m)); max@0: max@0: if(alias == false) max@0: { max@0: init_warm(X.n_rows, X.n_cols); max@0: max@0: diagview::extract(*this, X); max@0: } max@0: else max@0: { max@0: Mat tmp(X); max@0: max@0: steal_mem(tmp); max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix addition (using a diagview on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: diagview::plus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: //! in-place matrix subtraction (using a diagview on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: diagview::minus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix mutiplication (using a diagview on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: glue_times::apply_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix mutiplication (using a diagview on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: diagview::schur_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place element-wise matrix division (using a diagview on the right-hand-side) max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const diagview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: diagview::div_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat::Mat(const subview_elem1& X) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: this->operator=(X); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const subview_elem1& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_elem1::extract(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const subview_elem1& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_elem1::plus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const subview_elem1& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_elem1::minus_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const subview_elem1& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: glue_times::apply_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const subview_elem1& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_elem1::schur_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const subview_elem1& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview_elem1::div_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: mat_injector< Mat > max@0: Mat::operator<<(const eT val) max@0: { max@0: return mat_injector< Mat >(*this, val); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: mat_injector< Mat > max@0: Mat::operator<<(const injector_end_of_row& x) max@0: { max@0: return mat_injector< Mat >(*this, x); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (row vector) max@0: template max@0: arma_inline max@0: subview_row max@0: Mat::row(const uword row_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" ); max@0: max@0: return subview_row(*this, row_num); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (row vector) max@0: template max@0: arma_inline max@0: const subview_row max@0: Mat::row(const uword row_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" ); max@0: max@0: return subview_row(*this, row_num); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row max@0: Mat::operator()(const uword row_num, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: (row_num >= n_rows) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "Mat::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_row(*this, row_num, in_col1, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_row max@0: Mat::operator()(const uword row_num, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: (row_num >= n_rows) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "Mat::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_row(*this, row_num, in_col1, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (column vector) max@0: template max@0: arma_inline max@0: subview_col max@0: Mat::col(const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds"); max@0: max@0: return subview_col(*this, col_num); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (column vector) max@0: template max@0: arma_inline max@0: const subview_col max@0: Mat::col(const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds"); max@0: max@0: return subview_col(*this, col_num); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col max@0: Mat::operator()(const span& row_span, const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: (col_num >= n_cols) max@0: || max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: , max@0: "Mat::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_col(*this, col_num, in_row1, submat_n_rows); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_col max@0: Mat::operator()(const span& row_span, const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: (col_num >= n_cols) max@0: || max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: , max@0: "Mat::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_col(*this, col_num, in_row1, submat_n_rows); max@0: } max@0: max@0: max@0: max@0: //! create a Col object which uses memory from an existing matrix object. max@0: //! this approach is currently not alias safe max@0: //! and does not take into account that the parent matrix object could be deleted. max@0: //! if deleted memory is accessed by the created Col object, max@0: //! it will cause memory corruption and/or a crash max@0: template max@0: inline max@0: Col max@0: Mat::unsafe_col(const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): out of bounds"); max@0: max@0: return Col(colptr(col_num), n_rows, false, true); max@0: } max@0: max@0: max@0: max@0: //! create a Col object which uses memory from an existing matrix object. max@0: //! this approach is currently not alias safe max@0: //! and does not take into account that the parent matrix object could be deleted. max@0: //! if deleted memory is accessed by the created Col object, max@0: //! it will cause memory corruption and/or a crash max@0: template max@0: inline max@0: const Col max@0: Mat::unsafe_col(const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): out of bounds"); max@0: max@0: typedef const Col out_type; max@0: max@0: return out_type(const_cast(colptr(col_num)), n_rows, false, true); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified row vectors) max@0: template max@0: arma_inline max@0: subview max@0: Mat::rows(const uword in_row1, const uword in_row2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_row2 >= n_rows), max@0: "Mat::rows(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: max@0: return subview(*this, in_row1, 0, subview_n_rows, n_cols ); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified row vectors) max@0: template max@0: arma_inline max@0: const subview max@0: Mat::rows(const uword in_row1, const uword in_row2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_row2 >= n_rows), max@0: "Mat::rows(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: max@0: return subview(*this, in_row1, 0, subview_n_rows, n_cols ); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified column vectors) max@0: template max@0: arma_inline max@0: subview max@0: Mat::cols(const uword in_col1, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_col1 > in_col2) || (in_col2 >= n_cols), max@0: "Mat::cols(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: return subview(*this, 0, in_col1, n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified column vectors) max@0: template max@0: arma_inline max@0: const subview max@0: Mat::cols(const uword in_col1, const uword in_col2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_col1 > in_col2) || (in_col2 >= n_cols), max@0: "Mat::cols(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: return subview(*this, 0, in_col1, n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix) max@0: template max@0: arma_inline max@0: subview max@0: Mat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), max@0: "Mat::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: return subview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (generic submatrix) max@0: template max@0: arma_inline max@0: const subview max@0: Mat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), max@0: "Mat::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: return subview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix) max@0: template max@0: inline max@0: subview max@0: Mat::submat(const span& row_span, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "Mat::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (generic submatrix) max@0: template max@0: inline max@0: const subview max@0: Mat::submat(const span& row_span, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "Mat::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview max@0: Mat::operator()(const span& row_span, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).submat(row_span, col_span); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview max@0: Mat::operator()(const span& row_span, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).submat(row_span, col_span); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: subview_elem1 max@0: Mat::elem(const Base& a) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return subview_elem1(*this, a); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: const subview_elem1 max@0: Mat::elem(const Base& a) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return subview_elem1(*this, a); max@0: } max@0: max@0: max@0: max@0: // template max@0: // template max@0: // arma_inline max@0: // subview_elem2 max@0: // Mat::elem(const Base& a, const Base& b) max@0: // { max@0: // arma_extra_debug_sigprint(); max@0: // max@0: // return subview_elem2(*this, a, b); max@0: // } max@0: // max@0: // max@0: // max@0: // template max@0: // template max@0: // arma_inline max@0: // const subview_elem2 max@0: // Mat::elem(const Base& a, const Base& b) const max@0: // { max@0: // arma_extra_debug_sigprint(); max@0: // max@0: // return subview_elem2(*this, a, b); max@0: // } max@0: max@0: max@0: max@0: //! creation of diagview (diagonal) max@0: template max@0: arma_inline max@0: diagview max@0: Mat::diag(const sword in_id) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; max@0: const uword col_offset = (in_id > 0) ? uword( in_id) : 0; max@0: max@0: arma_debug_check max@0: ( max@0: ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), max@0: "Mat::diag(): requested diagonal out of bounds" max@0: ); max@0: max@0: const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); max@0: max@0: return diagview(*this, row_offset, col_offset, len); max@0: } max@0: max@0: max@0: max@0: //! creation of diagview (diagonal) max@0: template max@0: arma_inline max@0: const diagview max@0: Mat::diag(const sword in_id) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword row_offset = (in_id < 0) ? -in_id : 0; max@0: const uword col_offset = (in_id > 0) ? in_id : 0; max@0: max@0: arma_debug_check max@0: ( max@0: ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), max@0: "Mat::diag(): requested diagonal out of bounds" max@0: ); max@0: max@0: const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); max@0: max@0: return diagview(*this, row_offset, col_offset, len); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat::swap_rows(const uword in_row1, const uword in_row2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 >= n_rows) || (in_row2 >= n_rows), max@0: "Mat::swap_rows(): out of bounds" max@0: ); max@0: max@0: for(uword col=0; col max@0: inline max@0: void max@0: Mat::swap_cols(const uword in_col1, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_col1 >= n_cols) || (in_col2 >= n_cols), max@0: "Mat::swap_cols(): out of bounds" max@0: ); max@0: max@0: if(n_elem > 0) max@0: { max@0: eT* ptr1 = colptr(in_col1); max@0: eT* ptr2 = colptr(in_col2); max@0: max@0: for(uword row=0; row max@0: inline max@0: void max@0: Mat::shed_row(const uword row_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( row_num >= n_rows, "Mat::shed_row(): out of bounds"); max@0: max@0: shed_rows(row_num, row_num); max@0: } max@0: max@0: max@0: max@0: //! remove specified column max@0: template max@0: inline max@0: void max@0: Mat::shed_col(const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "Mat::shed_col(): out of bounds"); max@0: max@0: shed_cols(col_num, col_num); max@0: } max@0: max@0: max@0: max@0: //! remove specified rows max@0: template max@0: inline max@0: void max@0: Mat::shed_rows(const uword in_row1, const uword in_row2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_row2 >= n_rows), max@0: "Mat::shed_rows(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword n_keep_front = in_row1; max@0: const uword n_keep_back = n_rows - (in_row2 + 1); max@0: max@0: Mat X(n_keep_front + n_keep_back, n_cols); max@0: max@0: if(n_keep_front > 0) max@0: { max@0: X.rows( 0, (n_keep_front-1) ) = rows( 0, (in_row1-1) ); max@0: } max@0: max@0: if(n_keep_back > 0) max@0: { max@0: X.rows( n_keep_front, (n_keep_front+n_keep_back-1) ) = rows( (in_row2+1), (n_rows-1) ); max@0: } max@0: max@0: steal_mem(X); max@0: } max@0: max@0: max@0: max@0: //! remove specified columns max@0: template max@0: inline max@0: void max@0: Mat::shed_cols(const uword in_col1, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_col1 > in_col2) || (in_col2 >= n_cols), max@0: "Mat::shed_cols(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword n_keep_front = in_col1; max@0: const uword n_keep_back = n_cols - (in_col2 + 1); max@0: max@0: Mat X(n_rows, n_keep_front + n_keep_back); max@0: max@0: if(n_keep_front > 0) max@0: { max@0: X.cols( 0, (n_keep_front-1) ) = cols( 0, (in_col1-1) ); max@0: } max@0: max@0: if(n_keep_back > 0) max@0: { max@0: X.cols( n_keep_front, (n_keep_front+n_keep_back-1) ) = cols( (in_col2+1), (n_cols-1) ); max@0: } max@0: max@0: steal_mem(X); max@0: } max@0: max@0: max@0: max@0: //! insert N rows at the specified row position, max@0: //! optionally setting the elements of the inserted rows to zero max@0: template max@0: inline max@0: void max@0: Mat::insert_rows(const uword row_num, const uword N, const bool set_to_zero) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword t_n_rows = n_rows; max@0: const uword t_n_cols = n_cols; max@0: max@0: const uword A_n_rows = row_num; max@0: const uword B_n_rows = t_n_rows - row_num; max@0: max@0: // insertion at row_num == n_rows is in effect an append operation max@0: arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): out of bounds"); max@0: max@0: if(N > 0) max@0: { max@0: Mat out(t_n_rows + N, t_n_cols); max@0: max@0: if(A_n_rows > 0) max@0: { max@0: out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); max@0: } max@0: max@0: if(B_n_rows > 0) max@0: { max@0: out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows-1); max@0: } max@0: max@0: if(set_to_zero == true) max@0: { max@0: out.rows(row_num, row_num + N - 1).zeros(); max@0: } max@0: max@0: steal_mem(out); max@0: } max@0: } max@0: max@0: max@0: max@0: //! insert N columns at the specified column position, max@0: //! optionally setting the elements of the inserted columns to zero max@0: template max@0: inline max@0: void max@0: Mat::insert_cols(const uword col_num, const uword N, const bool set_to_zero) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword t_n_rows = n_rows; max@0: const uword t_n_cols = n_cols; max@0: max@0: const uword A_n_cols = col_num; max@0: const uword B_n_cols = t_n_cols - col_num; max@0: max@0: // insertion at col_num == n_cols is in effect an append operation max@0: arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): out of bounds"); max@0: max@0: if(N > 0) max@0: { max@0: Mat out(t_n_rows, t_n_cols + N); max@0: max@0: if(A_n_cols > 0) max@0: { max@0: out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); max@0: } max@0: max@0: if(B_n_cols > 0) max@0: { max@0: out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols-1); max@0: } max@0: max@0: if(set_to_zero == true) max@0: { max@0: out.cols(col_num, col_num + N - 1).zeros(); max@0: } max@0: max@0: steal_mem(out); max@0: } max@0: } max@0: max@0: max@0: max@0: //! insert the given object at the specified row position; max@0: //! the given object must have the same number of columns as the matrix max@0: template max@0: template max@0: inline max@0: void max@0: Mat::insert_rows(const uword row_num, const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(X.get_ref()); max@0: const Mat& C = tmp.M; max@0: max@0: const uword C_n_rows = C.n_rows; max@0: const uword C_n_cols = C.n_cols; max@0: max@0: const uword t_n_rows = n_rows; max@0: const uword t_n_cols = n_cols; max@0: max@0: const uword A_n_rows = row_num; max@0: const uword B_n_rows = t_n_rows - row_num; max@0: max@0: bool err_state = false; max@0: char* err_msg = 0; max@0: max@0: // insertion at row_num == n_rows is in effect an append operation max@0: max@0: arma_debug_set_error max@0: ( max@0: err_state, max@0: err_msg, max@0: (row_num > t_n_rows), max@0: "Mat::insert_rows(): out of bounds" max@0: ); max@0: max@0: arma_debug_set_error max@0: ( max@0: err_state, max@0: err_msg, max@0: ( (C_n_cols != t_n_cols) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), max@0: "Mat::insert_rows(): given object has an incompatible number of columns" max@0: ); max@0: max@0: arma_debug_check(err_state, err_msg); max@0: max@0: if(C_n_rows > 0) max@0: { max@0: Mat out( t_n_rows + C_n_rows, (std::max)(t_n_cols, C_n_cols) ); max@0: max@0: if(t_n_cols > 0) max@0: { max@0: if(A_n_rows > 0) max@0: { max@0: out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); max@0: } max@0: max@0: if( (t_n_cols > 0) && (B_n_rows > 0) ) max@0: { max@0: out.rows(row_num + C_n_rows, t_n_rows + C_n_rows - 1) = rows(row_num, t_n_rows - 1); max@0: } max@0: } max@0: max@0: if(C_n_cols > 0) max@0: { max@0: out.rows(row_num, row_num + C_n_rows - 1) = C; max@0: } max@0: max@0: steal_mem(out); max@0: } max@0: } max@0: max@0: max@0: max@0: //! insert the given object at the specified column position; max@0: //! the given object must have the same number of rows as the matrix max@0: template max@0: template max@0: inline max@0: void max@0: Mat::insert_cols(const uword col_num, const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(X.get_ref()); max@0: const Mat& C = tmp.M; max@0: max@0: const uword C_n_rows = C.n_rows; max@0: const uword C_n_cols = C.n_cols; max@0: max@0: const uword t_n_rows = n_rows; max@0: const uword t_n_cols = n_cols; max@0: max@0: const uword A_n_cols = col_num; max@0: const uword B_n_cols = t_n_cols - col_num; max@0: max@0: bool err_state = false; max@0: char* err_msg = 0; max@0: max@0: // insertion at col_num == n_cols is in effect an append operation max@0: max@0: arma_debug_set_error max@0: ( max@0: err_state, max@0: err_msg, max@0: (col_num > t_n_cols), max@0: "Mat::insert_cols(): out of bounds" max@0: ); max@0: max@0: arma_debug_set_error max@0: ( max@0: err_state, max@0: err_msg, max@0: ( (C_n_rows != t_n_rows) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), max@0: "Mat::insert_cols(): given object has an incompatible number of rows" max@0: ); max@0: max@0: arma_debug_check(err_state, err_msg); max@0: max@0: if(C_n_cols > 0) max@0: { max@0: Mat out( (std::max)(t_n_rows, C_n_rows), t_n_cols + C_n_cols ); max@0: max@0: if(t_n_rows > 0) max@0: { max@0: if(A_n_cols > 0) max@0: { max@0: out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); max@0: } max@0: max@0: if(B_n_cols > 0) max@0: { max@0: out.cols(col_num + C_n_cols, t_n_cols + C_n_cols - 1) = cols(col_num, t_n_cols - 1); max@0: } max@0: } max@0: max@0: if(C_n_rows > 0) max@0: { max@0: out.cols(col_num, col_num + C_n_cols - 1) = C; max@0: } max@0: max@0: steal_mem(out); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat::Mat(const Gen& X) max@0: : n_rows(X.n_rows) max@0: , n_cols(X.n_cols) max@0: , n_elem(n_rows*n_cols) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: init_cold(); max@0: max@0: X.apply(*this); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const Gen& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: init_warm(X.n_rows, X.n_cols); max@0: max@0: X.apply(*this); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const Gen& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: X.apply_inplace_plus(*this); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const Gen& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: X.apply_inplace_minus(*this); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const Gen& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat tmp(X); max@0: max@0: return (*this).operator*=(tmp); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const Gen& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: X.apply_inplace_schur(*this); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const Gen& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: X.apply_inplace_div(*this); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! create a matrix from Op, i.e. run the previously delayed unary operations max@0: template max@0: template max@0: inline max@0: Mat::Mat(const Op& X) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: op_type::apply(*this, X); max@0: } max@0: max@0: max@0: max@0: //! create a matrix from Op, i.e. run the previously delayed unary operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: op_type::apply(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix addition, with the right-hand-side operand having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator+=(m); max@0: } max@0: max@0: max@0: max@0: //! in-place matrix subtraction, with the right-hand-side operand having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator-=(m); max@0: } max@0: max@0: max@0: max@0: //! in-place matrix multiplication, with the right-hand-side operand having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: glue_times::apply_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix element-wise multiplication, with the right-hand-side operand having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator%=(m); max@0: } max@0: max@0: max@0: max@0: //! in-place matrix element-wise division, with the right-hand-side operand having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator/=(m); max@0: } max@0: max@0: max@0: max@0: //! create a matrix from eOp, i.e. run the previously delayed unary operations max@0: template max@0: template max@0: inline max@0: Mat::Mat(const eOp& X) max@0: : n_rows(X.get_n_rows()) max@0: , n_cols(X.get_n_cols()) max@0: , n_elem(X.get_n_elem()) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: init_cold(); max@0: max@0: eop_type::apply(*this, X); max@0: } max@0: max@0: max@0: max@0: //! create a matrix from eOp, i.e. run the previously delayed unary operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const eOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: const bool bad_alias = (X.P.has_subview && X.P.is_alias(*this)); max@0: max@0: if(bad_alias == false) max@0: { max@0: init_warm(X.get_n_rows(), X.get_n_cols()); max@0: max@0: eop_type::apply(*this, X); max@0: } max@0: else max@0: { max@0: Mat tmp(X); max@0: max@0: steal_mem(tmp); max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const eOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: eop_type::apply_inplace_plus(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const eOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: eop_type::apply_inplace_minus(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const eOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: glue_times::apply_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const eOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: eop_type::apply_inplace_schur(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const eOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: max@0: eop_type::apply_inplace_div(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL max@0: template max@0: template max@0: inline max@0: Mat::Mat(const mtOp& X) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: op_type::apply(*this, X); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const mtOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: op_type::apply(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const mtOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator+=(m); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const mtOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator-=(m); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const mtOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator*=(m); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const mtOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator%=(m); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const mtOp& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator/=(m); max@0: } max@0: max@0: max@0: max@0: //! create a matrix from Glue, i.e. run the previously delayed binary operations max@0: template max@0: template max@0: inline max@0: Mat::Mat(const Glue& X) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: glue_type::apply(*this, X); max@0: } max@0: max@0: max@0: max@0: //! create a matrix from Glue, i.e. run the previously delayed binary operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: glue_type::apply(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix addition, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator+=(m); max@0: } max@0: max@0: max@0: max@0: //! in-place matrix subtraction, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator-=(m); max@0: } max@0: max@0: max@0: max@0: //! in-place matrix multiplications, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: glue_times::apply_inplace(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator%=(m); max@0: } max@0: max@0: max@0: max@0: //! in-place matrix element-wise division, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator/=(m); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: glue_times::apply_inplace_plus(*this, X, sword(+1)); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: glue_times::apply_inplace_plus(*this, X, sword(-1)); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! create a matrix from eGlue, i.e. run the previously delayed binary operations max@0: template max@0: template max@0: inline max@0: Mat::Mat(const eGlue& X) max@0: : n_rows(X.get_n_rows()) max@0: , n_cols(X.get_n_cols()) max@0: , n_elem(X.get_n_elem()) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: init_cold(); max@0: max@0: eglue_type::apply(*this, X); max@0: } max@0: max@0: max@0: max@0: //! create a matrix from eGlue, i.e. run the previously delayed binary operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const eGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: const bool bad_alias = ( (X.P1.has_subview && X.P1.is_alias(*this)) || ( X.P2.has_subview && X.P2.is_alias(*this)) ); max@0: max@0: if(bad_alias == false) max@0: { max@0: init_warm(X.get_n_rows(), X.get_n_cols()); max@0: max@0: eglue_type::apply(*this, X); max@0: } max@0: else max@0: { max@0: Mat tmp(X); max@0: max@0: steal_mem(tmp); max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix addition, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const eGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: eglue_type::apply_inplace_plus(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! in-place matrix subtraction, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const eGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: eglue_type::apply_inplace_minus(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const eGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: glue_times::apply_inplace(*this, X); max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const eGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: eglue_type::apply_inplace_schur(*this, X); max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const eGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); max@0: arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); max@0: max@0: eglue_type::apply_inplace_div(*this, X); max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL: create a matrix from mtGlue, i.e. run the previously delayed binary operations max@0: template max@0: template max@0: inline max@0: Mat::Mat(const mtGlue& X) max@0: : n_rows(0) max@0: , n_cols(0) max@0: , n_elem(0) max@0: , vec_state(0) max@0: , mem_state(0) max@0: , mem() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: glue_type::apply(*this, X); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL: create a matrix from Glue, i.e. run the previously delayed binary operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator=(const mtGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: glue_type::apply(*this, X); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL: in-place matrix addition, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator+=(const mtGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator+=(m); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL: in-place matrix subtraction, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator-=(const mtGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator-=(m); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL: in-place matrix multiplications, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator*=(const mtGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: glue_times::apply_inplace(*this, m); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL: in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator%=(const mtGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator%=(m); max@0: } max@0: max@0: max@0: max@0: //! EXPERIMENTAL: in-place matrix element-wise division, with the right-hand-side operands having delayed operations max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::operator/=(const mtGlue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Mat m(X); max@0: max@0: return (*this).operator/=(m); max@0: } max@0: max@0: max@0: max@0: //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::operator() (const uword i) max@0: { max@0: arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds"); max@0: return access::rw(mem[i]); max@0: } max@0: max@0: max@0: max@0: //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::operator() (const uword i) const max@0: { max@0: arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds"); max@0: return mem[i]; max@0: } max@0: max@0: max@0: //! linear element accessor (treats the matrix as a vector); no bounds check. max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::operator[] (const uword i) max@0: { max@0: return access::rw(mem[i]); max@0: } max@0: max@0: max@0: max@0: //! linear element accessor (treats the matrix as a vector); no bounds check max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::operator[] (const uword i) const max@0: { max@0: return mem[i]; max@0: } max@0: max@0: max@0: max@0: //! linear element accessor (treats the matrix as a vector); no bounds check. max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::at(const uword i) max@0: { max@0: return access::rw(mem[i]); max@0: } max@0: max@0: max@0: max@0: //! linear element accessor (treats the matrix as a vector); no bounds check max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::at(const uword i) const max@0: { max@0: return mem[i]; max@0: } max@0: max@0: max@0: max@0: //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::operator() (const uword in_row, const uword in_col) max@0: { max@0: arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds"); max@0: return access::rw(mem[in_row + in_col*n_rows]); max@0: } max@0: max@0: max@0: max@0: //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::operator() (const uword in_row, const uword in_col) const max@0: { max@0: arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds"); max@0: return mem[in_row + in_col*n_rows]; max@0: } max@0: max@0: max@0: max@0: //! element accessor; no bounds check max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::at(const uword in_row, const uword in_col) max@0: { max@0: return access::rw( mem[in_row + in_col*n_rows] ); max@0: } max@0: max@0: max@0: max@0: //! element accessor; no bounds check max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::at(const uword in_row, const uword in_col) const max@0: { max@0: return mem[in_row + in_col*n_rows]; max@0: } max@0: max@0: max@0: max@0: //! prefix ++ max@0: template max@0: arma_inline max@0: const Mat& max@0: Mat::operator++() max@0: { max@0: Mat_aux::prefix_pp(*this); max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! postfix ++ (must not return the object by reference) max@0: template max@0: arma_inline max@0: void max@0: Mat::operator++(int) max@0: { max@0: Mat_aux::postfix_pp(*this); max@0: } max@0: max@0: max@0: max@0: //! prefix -- max@0: template max@0: arma_inline max@0: const Mat& max@0: Mat::operator--() max@0: { max@0: Mat_aux::prefix_mm(*this); max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! postfix -- (must not return the object by reference) max@0: template max@0: arma_inline max@0: void max@0: Mat::operator--(int) max@0: { max@0: Mat_aux::postfix_mm(*this); max@0: } max@0: max@0: max@0: max@0: //! returns true if the matrix has no elements max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::is_empty() const max@0: { max@0: return (n_elem == 0); max@0: } max@0: max@0: max@0: max@0: //! returns true if the object can be interpreted as a column or row vector max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::is_vec() const max@0: { max@0: return ( (n_rows == 1) || (n_cols == 1) ); max@0: } max@0: max@0: max@0: max@0: //! returns true if the object can be interpreted as a row vector max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::is_rowvec() const max@0: { max@0: return (n_rows == 1); max@0: } max@0: max@0: max@0: max@0: //! returns true if the object can be interpreted as a column vector max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::is_colvec() const max@0: { max@0: return (n_cols == 1); max@0: } max@0: max@0: max@0: max@0: //! returns true if the object has the same number of non-zero rows and columnns max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::is_square() const max@0: { max@0: return (n_rows == n_cols); max@0: } max@0: max@0: max@0: max@0: //! returns true if all of the elements are finite max@0: template max@0: inline max@0: arma_warn_unused max@0: bool max@0: Mat::is_finite() const max@0: { max@0: return arrayops::is_finite( memptr(), n_elem ); max@0: } max@0: max@0: max@0: max@0: //! returns true if the given index is currently in range max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::in_range(const uword i) const max@0: { max@0: return (i < n_elem); max@0: } max@0: max@0: max@0: max@0: //! returns true if the given start and end indices are currently in range max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::in_range(const span& x) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(x.whole == true) max@0: { max@0: return true; max@0: } max@0: else max@0: { max@0: const uword a = x.a; max@0: const uword b = x.b; max@0: max@0: return ( (a <= b) && (b < n_elem) ); max@0: } max@0: } max@0: max@0: max@0: max@0: //! returns true if the given location is currently in range max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::in_range(const uword in_row, const uword in_col) const max@0: { max@0: return ( (in_row < n_rows) && (in_col < n_cols) ); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::in_range(const span& row_span, const uword in_col) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(row_span.whole == true) max@0: { max@0: return (in_col < n_cols); max@0: } max@0: else max@0: { max@0: const uword in_row1 = row_span.a; max@0: const uword in_row2 = row_span.b; max@0: max@0: return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::in_range(const uword in_row, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(col_span.whole == true) max@0: { max@0: return (in_row < n_rows); max@0: } max@0: else max@0: { max@0: const uword in_col1 = col_span.a; max@0: const uword in_col2 = col_span.b; max@0: max@0: return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: Mat::in_range(const span& row_span, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword in_row1 = row_span.a; max@0: const uword in_row2 = row_span.b; max@0: max@0: const uword in_col1 = col_span.a; max@0: const uword in_col2 = col_span.b; max@0: max@0: const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); max@0: const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); max@0: max@0: return ( (rows_ok == true) && (cols_ok == true) ); max@0: } max@0: max@0: max@0: max@0: //! returns a pointer to array of eTs for a specified column; no bounds check max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT* max@0: Mat::colptr(const uword in_col) max@0: { max@0: return & access::rw(mem[in_col*n_rows]); max@0: } max@0: max@0: max@0: max@0: //! returns a pointer to array of eTs for a specified column; no bounds check max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: const eT* max@0: Mat::colptr(const uword in_col) const max@0: { max@0: return & mem[in_col*n_rows]; max@0: } max@0: max@0: max@0: max@0: //! returns a pointer to array of eTs used by the matrix max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT* max@0: Mat::memptr() max@0: { max@0: return const_cast(mem); max@0: } max@0: max@0: max@0: max@0: //! returns a pointer to array of eTs used by the matrix max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: const eT* max@0: Mat::memptr() const max@0: { max@0: return mem; max@0: } max@0: max@0: max@0: max@0: //! print contents of the matrix (to the cout stream), max@0: //! optionally preceding with a user specified line of text. max@0: //! the precision and cell width are modified. max@0: //! on return, the stream's state are restored to their original values. max@0: template max@0: inline max@0: void max@0: Mat::impl_print(const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(extra_text.length() != 0) max@0: { max@0: const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); max@0: max@0: ARMA_DEFAULT_OSTREAM << extra_text << '\n'; max@0: max@0: ARMA_DEFAULT_OSTREAM.width(orig_width); max@0: } max@0: max@0: arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true); max@0: } max@0: max@0: max@0: max@0: //! print contents of the matrix to a user specified stream, max@0: //! optionally preceding with a user specified line of text. max@0: //! the precision and cell width are modified. max@0: //! on return, the stream's state are restored to their original values. max@0: template max@0: inline max@0: void max@0: Mat::impl_print(std::ostream& user_stream, const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(extra_text.length() != 0) max@0: { max@0: const std::streamsize orig_width = user_stream.width(); max@0: max@0: user_stream << extra_text << '\n'; max@0: max@0: user_stream.width(orig_width); max@0: } max@0: max@0: arma_ostream::print(user_stream, *this, true); max@0: } max@0: max@0: max@0: max@0: //! DEPRECATED FUNCTION max@0: template max@0: inline max@0: void max@0: Mat::impl_print_trans(const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat tmp; max@0: op_strans::apply_noalias(tmp, *this); max@0: max@0: tmp.impl_print(extra_text); max@0: } max@0: max@0: max@0: max@0: //! DEPRECATED FUNCTION max@0: template max@0: inline max@0: void max@0: Mat::impl_print_trans(std::ostream& user_stream, const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat tmp; max@0: op_strans::apply_noalias(tmp, *this); max@0: max@0: tmp.impl_print(user_stream, extra_text); max@0: } max@0: max@0: max@0: max@0: //! print contents of the matrix (to the cout stream), max@0: //! optionally preceding with a user specified line of text. max@0: //! the stream's state are used as is and are not modified max@0: //! (i.e. the precision and cell width are not modified). max@0: template max@0: inline max@0: void max@0: Mat::impl_raw_print(const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(extra_text.length() != 0) max@0: { max@0: const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); max@0: max@0: ARMA_DEFAULT_OSTREAM << extra_text << '\n'; max@0: max@0: ARMA_DEFAULT_OSTREAM.width(orig_width); max@0: } max@0: max@0: arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false); max@0: } max@0: max@0: max@0: max@0: //! print contents of the matrix to a user specified stream, max@0: //! optionally preceding with a user specified line of text. max@0: //! the stream's state are used as is and are not modified. max@0: //! (i.e. the precision and cell width are not modified). max@0: template max@0: inline max@0: void max@0: Mat::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: if(extra_text.length() != 0) max@0: { max@0: const std::streamsize orig_width = user_stream.width(); max@0: max@0: user_stream << extra_text << '\n'; max@0: max@0: user_stream.width(orig_width); max@0: } max@0: max@0: arma_ostream::print(user_stream, *this, false); max@0: } max@0: max@0: max@0: max@0: //! DEPRECATED FUNCTION max@0: template max@0: inline max@0: void max@0: Mat::impl_raw_print_trans(const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat tmp; max@0: op_strans::apply_noalias(tmp, *this); max@0: max@0: tmp.impl_raw_print(extra_text); max@0: } max@0: max@0: max@0: max@0: //! DEPRECATED FUNCTION max@0: template max@0: inline max@0: void max@0: Mat::impl_raw_print_trans(std::ostream& user_stream, const std::string& extra_text) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat tmp; max@0: op_strans::apply_noalias(tmp, *this); max@0: max@0: tmp.impl_raw_print(user_stream, extra_text); max@0: } max@0: max@0: max@0: max@0: //! change the matrix to have user specified dimensions (data is not preserved) max@0: template max@0: inline max@0: void max@0: Mat::set_size(const uword in_elem) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: switch(vec_state) max@0: { max@0: case 0: max@0: case 1: max@0: init_warm(in_elem, 1); max@0: break; max@0: max@0: case 2: max@0: init_warm(1, in_elem); max@0: break; max@0: max@0: default: max@0: ; max@0: } max@0: } max@0: max@0: max@0: max@0: //! change the matrix to have user specified dimensions (data is not preserved) max@0: template max@0: inline max@0: void max@0: Mat::set_size(const uword in_rows, const uword in_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: init_warm(in_rows, in_cols); max@0: } max@0: max@0: max@0: max@0: //! change the matrix to have user specified dimensions (data is preserved) max@0: template max@0: inline max@0: void max@0: Mat::resize(const uword in_elem) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: switch(vec_state) max@0: { max@0: case 0: max@0: case 1: max@0: (*this).resize(in_elem, 1); max@0: break; max@0: max@0: case 2: max@0: (*this).resize(1, in_elem); max@0: break; max@0: max@0: default: max@0: ; max@0: } max@0: } max@0: max@0: max@0: max@0: //! change the matrix to have user specified dimensions (data is preserved) max@0: template max@0: inline max@0: void max@0: Mat::resize(const uword in_rows, const uword in_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: *this = arma::resize(*this, in_rows, in_cols); max@0: } max@0: max@0: max@0: max@0: //! change the matrix to have user specified dimensions (data is preserved) max@0: template max@0: inline max@0: void max@0: Mat::reshape(const uword in_rows, const uword in_cols, const uword dim) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: *this = arma::reshape(*this, in_rows, in_cols, dim); max@0: } max@0: max@0: max@0: max@0: //! change the matrix (without preserving data) to have the same dimensions as the given matrix max@0: template max@0: template max@0: inline max@0: void max@0: Mat::copy_size(const Mat& m) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: init_warm(m.n_rows, m.n_cols); max@0: } max@0: max@0: max@0: max@0: //! fill the matrix with the specified value max@0: template max@0: arma_hot max@0: inline max@0: const Mat& max@0: Mat::fill(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_set( memptr(), val, n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::zeros() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return fill(eT(0)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::zeros(const uword in_elem) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_elem); max@0: max@0: return fill(eT(0)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::zeros(const uword in_rows, const uword in_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_rows, in_cols); max@0: max@0: return fill(eT(0)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::ones() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return fill(eT(1)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::ones(const uword in_elem) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_elem); max@0: max@0: return fill(eT(1)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::ones(const uword in_rows, const uword in_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_rows, in_cols); max@0: max@0: return fill(eT(1)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::randu() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword N = n_elem; max@0: eT* ptr = memptr(); max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j()); max@0: const eT tmp_j = eT(eop_aux_randu()); max@0: max@0: ptr[i] = tmp_i; max@0: ptr[j] = tmp_j; max@0: } max@0: max@0: if(i < N) max@0: { max@0: ptr[i] = eT(eop_aux_randu()); max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::randu(const uword in_elem) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_elem); max@0: max@0: return (*this).randu(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::randu(const uword in_rows, const uword in_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_rows, in_cols); max@0: max@0: return (*this).randu(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::randn() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword N = n_elem; max@0: eT* ptr = memptr(); max@0: max@0: for(uword i=0; i()); max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::randn(const uword in_elem) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_elem); max@0: max@0: return (*this).randn(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::randn(const uword in_rows, const uword in_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_rows, in_cols); max@0: max@0: return (*this).randn(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const Mat& max@0: Mat::eye() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: fill(eT(0)); max@0: max@0: const uword N = (std::min)(n_rows, n_cols); max@0: max@0: for(uword i=0; i max@0: inline max@0: const Mat& max@0: Mat::eye(const uword in_rows, const uword in_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: set_size(in_rows, in_cols); max@0: max@0: return (*this).eye(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat::reset() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: switch(vec_state) max@0: { max@0: default: max@0: init_warm(0, 0); max@0: break; max@0: max@0: case 1: max@0: init_warm(0, 1); max@0: break; max@0: max@0: case 2: max@0: init_warm(1, 0); max@0: break; max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: Mat::set_real(const Base::pod_type,T1>& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat_aux::set_real(*this, X); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: Mat::set_imag(const Base::pod_type,T1>& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat_aux::set_imag(*this, X); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: Mat::min() const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (n_elem == 0), "min(): object has no elements" ); max@0: max@0: return op_min::direct_min(memptr(), n_elem); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: Mat::max() const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (n_elem == 0), "max(): object has no elements" ); max@0: max@0: return op_max::direct_max(memptr(), n_elem); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: Mat::min(uword& index_of_min_val) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (n_elem == 0), "min(): object has no elements" ); max@0: max@0: return op_min::direct_min(memptr(), n_elem, index_of_min_val); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: Mat::max(uword& index_of_max_val) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (n_elem == 0), "max(): object has no elements" ); max@0: max@0: return op_max::direct_max(memptr(), n_elem, index_of_max_val); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: Mat::min(uword& row_of_min_val, uword& col_of_min_val) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (n_elem == 0), "min(): object has no elements" ); max@0: max@0: uword i; max@0: max@0: eT val = op_min::direct_min(memptr(), n_elem, i); max@0: max@0: row_of_min_val = i % n_rows; max@0: col_of_min_val = i / n_rows; max@0: max@0: return val; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: Mat::max(uword& row_of_max_val, uword& col_of_max_val) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (n_elem == 0), "max(): object has no elements" ); max@0: max@0: uword i; max@0: max@0: eT val = op_max::direct_max(memptr(), n_elem, i); max@0: max@0: row_of_max_val = i % n_rows; max@0: col_of_max_val = i / n_rows; max@0: max@0: return val; max@0: } max@0: max@0: max@0: max@0: //! save the matrix to a file max@0: template max@0: inline max@0: bool max@0: Mat::save(const std::string name, const file_type type, const bool print_status) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: bool save_okay; max@0: max@0: switch(type) max@0: { max@0: case raw_ascii: max@0: save_okay = diskio::save_raw_ascii(*this, name); max@0: break; max@0: max@0: case arma_ascii: max@0: save_okay = diskio::save_arma_ascii(*this, name); max@0: break; max@0: max@0: case csv_ascii: max@0: save_okay = diskio::save_csv_ascii(*this, name); max@0: break; max@0: max@0: case raw_binary: max@0: save_okay = diskio::save_raw_binary(*this, name); max@0: break; max@0: max@0: case arma_binary: max@0: save_okay = diskio::save_arma_binary(*this, name); max@0: break; max@0: max@0: case pgm_binary: max@0: save_okay = diskio::save_pgm_binary(*this, name); max@0: break; max@0: max@0: default: max@0: arma_warn(print_status, "Mat::save(): unsupported file type"); max@0: save_okay = false; max@0: } max@0: max@0: arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to ", name); max@0: max@0: return save_okay; max@0: } max@0: max@0: max@0: max@0: //! save the matrix to a stream max@0: template max@0: inline max@0: bool max@0: Mat::save(std::ostream& os, const file_type type, const bool print_status) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: bool save_okay; max@0: max@0: switch(type) max@0: { max@0: case raw_ascii: max@0: save_okay = diskio::save_raw_ascii(*this, os); max@0: break; max@0: max@0: case arma_ascii: max@0: save_okay = diskio::save_arma_ascii(*this, os); max@0: break; max@0: max@0: case csv_ascii: max@0: save_okay = diskio::save_csv_ascii(*this, os); max@0: break; max@0: max@0: case raw_binary: max@0: save_okay = diskio::save_raw_binary(*this, os); max@0: break; max@0: max@0: case arma_binary: max@0: save_okay = diskio::save_arma_binary(*this, os); max@0: break; max@0: max@0: case pgm_binary: max@0: save_okay = diskio::save_pgm_binary(*this, os); max@0: break; max@0: max@0: default: max@0: arma_warn(print_status, "Mat::save(): unsupported file type"); max@0: save_okay = false; max@0: } max@0: max@0: arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to the given stream"); max@0: max@0: return save_okay; max@0: } max@0: max@0: max@0: max@0: //! load a matrix from a file max@0: template max@0: inline max@0: bool max@0: Mat::load(const std::string name, const file_type type, const bool print_status) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: bool load_okay; max@0: std::string err_msg; max@0: max@0: switch(type) max@0: { max@0: case auto_detect: max@0: load_okay = diskio::load_auto_detect(*this, name, err_msg); max@0: break; max@0: max@0: case raw_ascii: max@0: load_okay = diskio::load_raw_ascii(*this, name, err_msg); max@0: break; max@0: max@0: case arma_ascii: max@0: load_okay = diskio::load_arma_ascii(*this, name, err_msg); max@0: break; max@0: max@0: case csv_ascii: max@0: load_okay = diskio::load_csv_ascii(*this, name, err_msg); max@0: break; max@0: max@0: case raw_binary: max@0: load_okay = diskio::load_raw_binary(*this, name, err_msg); max@0: break; max@0: max@0: case arma_binary: max@0: load_okay = diskio::load_arma_binary(*this, name, err_msg); max@0: break; max@0: max@0: case pgm_binary: max@0: load_okay = diskio::load_pgm_binary(*this, name, err_msg); max@0: break; max@0: max@0: default: max@0: arma_warn(print_status, "Mat::load(): unsupported file type"); max@0: load_okay = false; max@0: } max@0: max@0: if( (print_status == true) && (load_okay == false) ) max@0: { max@0: if(err_msg.length() > 0) max@0: { max@0: arma_warn(true, "Mat::load(): ", err_msg, name); max@0: } max@0: else max@0: { max@0: arma_warn(true, "Mat::load(): couldn't read ", name); max@0: } max@0: } max@0: max@0: if(load_okay == false) max@0: { max@0: (*this).reset(); max@0: } max@0: max@0: return load_okay; max@0: } max@0: max@0: max@0: max@0: //! load a matrix from a stream max@0: template max@0: inline max@0: bool max@0: Mat::load(std::istream& is, const file_type type, const bool print_status) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: bool load_okay; max@0: std::string err_msg; max@0: max@0: switch(type) max@0: { max@0: case auto_detect: max@0: load_okay = diskio::load_auto_detect(*this, is, err_msg); max@0: break; max@0: max@0: case raw_ascii: max@0: load_okay = diskio::load_raw_ascii(*this, is, err_msg); max@0: break; max@0: max@0: case arma_ascii: max@0: load_okay = diskio::load_arma_ascii(*this, is, err_msg); max@0: break; max@0: max@0: case csv_ascii: max@0: load_okay = diskio::load_csv_ascii(*this, is, err_msg); max@0: break; max@0: max@0: case raw_binary: max@0: load_okay = diskio::load_raw_binary(*this, is, err_msg); max@0: break; max@0: max@0: case arma_binary: max@0: load_okay = diskio::load_arma_binary(*this, is, err_msg); max@0: break; max@0: max@0: case pgm_binary: max@0: load_okay = diskio::load_pgm_binary(*this, is, err_msg); max@0: break; max@0: max@0: default: max@0: arma_warn(print_status, "Mat::load(): unsupported file type"); max@0: load_okay = false; max@0: } max@0: max@0: max@0: if( (print_status == true) && (load_okay == false) ) max@0: { max@0: if(err_msg.length() > 0) max@0: { max@0: arma_warn(true, "Mat::load(): ", err_msg, "the given stream"); max@0: } max@0: else max@0: { max@0: arma_warn(true, "Mat::load(): couldn't load from the given stream"); max@0: } max@0: } max@0: max@0: if(load_okay == false) max@0: { max@0: (*this).reset(); max@0: } max@0: max@0: return load_okay; max@0: } max@0: max@0: max@0: max@0: //! save the matrix to a file, without printing any error messages max@0: template max@0: inline max@0: bool max@0: Mat::quiet_save(const std::string name, const file_type type) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).save(name, type, false); max@0: } max@0: max@0: max@0: max@0: //! save the matrix to a stream, without printing any error messages max@0: template max@0: inline max@0: bool max@0: Mat::quiet_save(std::ostream& os, const file_type type) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).save(os, type, false); max@0: } max@0: max@0: max@0: max@0: //! load a matrix from a file, without printing any error messages max@0: template max@0: inline max@0: bool max@0: Mat::quiet_load(const std::string name, const file_type type) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).load(name, type, false); max@0: } max@0: max@0: max@0: max@0: //! load a matrix from a stream, without printing any error messages max@0: template max@0: inline max@0: bool max@0: Mat::quiet_load(std::istream& is, const file_type type) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).load(is, type, false); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: Mat::row_iterator::row_iterator(Mat& in_M, const uword in_row) max@0: : M (in_M ) max@0: , row(in_row) max@0: , col(0 ) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT& max@0: Mat::row_iterator::operator*() max@0: { max@0: return M.at(row,col); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::row_iterator& max@0: Mat::row_iterator::operator++() max@0: { max@0: ++col; max@0: max@0: if(col >= M.n_cols) max@0: { max@0: col = 0; max@0: ++row; max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat::row_iterator::operator++(int) max@0: { max@0: operator++(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::row_iterator& max@0: Mat::row_iterator::operator--() max@0: { max@0: if(col > 0) max@0: { max@0: --col; max@0: } max@0: else max@0: { max@0: if(row > 0) max@0: { max@0: col = M.n_cols - 1; max@0: --row; max@0: } max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat::row_iterator::operator--(int) max@0: { max@0: operator--(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: Mat::row_iterator::operator!=(const typename Mat::row_iterator& X) const max@0: { max@0: return ( (row != X.row) || (col != X.col) ) ? true : false; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: Mat::row_iterator::operator==(const typename Mat::row_iterator& X) const max@0: { max@0: return ( (row == X.row) && (col == X.col) ) ? true : false; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: Mat::const_row_iterator::const_row_iterator(const Mat& in_M, const uword in_row) max@0: : M (in_M ) max@0: , row(in_row) max@0: , col(0 ) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: Mat::const_row_iterator::const_row_iterator(const typename Mat::row_iterator& X) max@0: : M (X.M) max@0: , row(X.row) max@0: , col(X.col) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: Mat::const_row_iterator::operator*() const max@0: { max@0: return M.at(row,col); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_row_iterator& max@0: Mat::const_row_iterator::operator++() max@0: { max@0: ++col; max@0: max@0: if(col >= M.n_cols) max@0: { max@0: col = 0; max@0: ++row; max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat::const_row_iterator::operator++(int) max@0: { max@0: operator++(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_row_iterator& max@0: Mat::const_row_iterator::operator--() max@0: { max@0: if(col > 0) max@0: { max@0: --col; max@0: } max@0: else max@0: { max@0: if(row > 0) max@0: { max@0: col = M.n_cols - 1; max@0: --row; max@0: } max@0: } max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat::const_row_iterator::operator--(int) max@0: { max@0: operator--(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: Mat::const_row_iterator::operator!=(const typename Mat::const_row_iterator& X) const max@0: { max@0: return ( (row != X.row) || (col != X.col) ) ? true : false; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: Mat::const_row_iterator::operator==(const typename Mat::const_row_iterator& X) const max@0: { max@0: return ( (row == X.row) && (col == X.col) ) ? true : false; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::iterator max@0: Mat::begin() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return memptr(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_iterator max@0: Mat::begin() const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return memptr(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::iterator max@0: Mat::end() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return memptr() + n_elem; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_iterator max@0: Mat::end() const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return memptr() + n_elem; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::col_iterator max@0: Mat::begin_col(const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds"); max@0: max@0: return colptr(col_num); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_col_iterator max@0: Mat::begin_col(const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds"); max@0: max@0: return colptr(col_num); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::col_iterator max@0: Mat::end_col(const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); max@0: max@0: return colptr(col_num) + n_rows; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_col_iterator max@0: Mat::end_col(const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); max@0: max@0: return colptr(col_num) + n_rows; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::row_iterator max@0: Mat::begin_row(const uword row_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); max@0: max@0: return typename Mat::row_iterator(*this, row_num); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_row_iterator max@0: Mat::begin_row(const uword row_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); max@0: max@0: return typename Mat::const_row_iterator(*this, row_num); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::row_iterator max@0: Mat::end_row(const uword row_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); max@0: max@0: return typename Mat::row_iterator(*this, row_num + 1); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: typename Mat::const_row_iterator max@0: Mat::end_row(const uword row_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); max@0: max@0: return typename Mat::const_row_iterator(*this, row_num + 1); max@0: } max@0: max@0: max@0: max@0: //! resets this matrix to an empty matrix max@0: template max@0: inline max@0: void max@0: Mat::clear() max@0: { max@0: reset(); max@0: } max@0: max@0: max@0: max@0: //! returns true if the matrix has no elements max@0: template max@0: inline max@0: bool max@0: Mat::empty() const max@0: { max@0: return (n_elem == 0); max@0: } max@0: max@0: max@0: max@0: //! returns the number of elements in this matrix max@0: template max@0: inline max@0: uword max@0: Mat::size() const max@0: { max@0: return n_elem; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: void max@0: Mat::fixed::mem_setup() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: access::rw(Mat::n_rows) = fixed_n_rows; max@0: access::rw(Mat::n_cols) = fixed_n_cols; max@0: access::rw(Mat::n_elem) = fixed_n_elem; max@0: access::rw(Mat::vec_state) = 0; max@0: access::rw(Mat::mem_state) = 3; max@0: access::rw(Mat::mem) = (use_extra) ? mem_local_extra : mem_local; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: Mat::fixed::fixed() max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: mem_setup(); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: Mat::fixed::fixed(const fixed& X) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: mem_setup(); max@0: max@0: eT* dest = (use_extra) ? mem_local_extra : mem_local; max@0: max@0: arrayops::copy( dest, X.mem, fixed_n_elem ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: template max@0: inline max@0: Mat::fixed::fixed(const Base& A) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: mem_setup(); max@0: max@0: Mat::operator=(A.get_ref()); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: template max@0: inline max@0: Mat::fixed::fixed(const Base& A, const Base& B) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: mem_setup(); max@0: max@0: Mat::init(A,B); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat::fixed::fixed(eT* aux_mem, const bool copy_aux_mem) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: access::rw(Mat::n_rows) = fixed_n_rows; max@0: access::rw(Mat::n_cols) = fixed_n_cols; max@0: access::rw(Mat::n_elem) = fixed_n_elem; max@0: access::rw(Mat::vec_state) = 0; max@0: access::rw(Mat::mem_state) = 3; max@0: max@0: if(copy_aux_mem == true) max@0: { max@0: eT* dest = (use_extra) ? mem_local_extra : mem_local; max@0: max@0: access::rw(Mat::mem) = dest; max@0: max@0: arrayops::copy( dest, aux_mem, fixed_n_elem ); max@0: } max@0: else max@0: { max@0: access::rw(Mat::mem) = aux_mem; max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat::fixed::fixed(const eT* aux_mem) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: mem_setup(); max@0: max@0: arrayops::copy( const_cast(Mat::mem), aux_mem, fixed_n_elem ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat::fixed::fixed(const char* text) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: mem_setup(); max@0: max@0: Mat::operator=(text); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat::fixed::fixed(const std::string& text) max@0: { max@0: arma_extra_debug_sigprint_this(this); max@0: max@0: mem_setup(); max@0: max@0: Mat::operator=(text); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::fixed::operator=(const Base& A) max@0: { max@0: Mat::operator=(A.get_ref()); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::fixed::operator=(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat::operator=(val); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::fixed::operator=(const char* text) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat::operator=(text); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const Mat& max@0: Mat::fixed::operator=(const std::string& text) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: Mat::operator=(text); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: subview_row max@0: Mat::fixed::operator()(const uword row_num, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Mat::operator()(row_num, col_span); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const subview_row max@0: Mat::fixed::operator()(const uword row_num, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Mat::operator()(row_num, col_span); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: subview_col max@0: Mat::fixed::operator()(const span& row_span, const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Mat::operator()(row_span, col_num); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const subview_col max@0: Mat::fixed::operator()(const span& row_span, const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Mat::operator()(row_span, col_num); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: subview max@0: Mat::fixed::operator()(const span& row_span, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Mat::operator()(row_span, col_span); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: const subview max@0: Mat::fixed::operator()(const span& row_span, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Mat::operator()(row_span, col_span); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::fixed::operator[] (const uword i) max@0: { max@0: return access::rw( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::fixed::operator[] (const uword i) const max@0: { max@0: return ( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::fixed::at(const uword i) max@0: { max@0: return access::rw( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::fixed::at(const uword i) const max@0: { max@0: return ( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::fixed::operator() (const uword i) max@0: { max@0: arma_debug_check( (i >= fixed_n_elem), "Mat::fixed::operator(): out of bounds"); max@0: max@0: return access::rw( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::fixed::operator() (const uword i) const max@0: { max@0: arma_debug_check( (i >= fixed_n_elem), "Mat::fixed::operator(): out of bounds"); max@0: max@0: return ( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::fixed::at(const uword in_row, const uword in_col) max@0: { max@0: const uword i = in_row + in_col*fixed_n_rows; max@0: max@0: return access::rw( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::fixed::at(const uword in_row, const uword in_col) const max@0: { max@0: const uword i = in_row + in_col*fixed_n_rows; max@0: max@0: return ( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT& max@0: Mat::fixed::operator() (const uword in_row, const uword in_col) max@0: { max@0: arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::fixed::operator(): out of bounds"); max@0: max@0: const uword i = in_row + in_col*fixed_n_rows; max@0: max@0: return access::rw( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: eT max@0: Mat::fixed::operator() (const uword in_row, const uword in_col) const max@0: { max@0: arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::fixed::operator(): out of bounds"); max@0: max@0: const uword i = in_row + in_col*fixed_n_rows; max@0: max@0: return ( Mat::mem[i] ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: const Mat& max@0: Mat::fixed::fill(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_set( const_cast(Mat::mem), val, fixed_n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: const Mat& max@0: Mat::fixed::zeros() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_set( const_cast(Mat::mem), eT(0), fixed_n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: const Mat& max@0: Mat::fixed::ones() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arrayops::inplace_set( const_cast(Mat::mem), eT(1), fixed_n_elem ); max@0: max@0: return *this; max@0: } max@0: max@0: max@0: max@0: //! prefix ++ max@0: template max@0: arma_inline max@0: void max@0: Mat_aux::prefix_pp(Mat& x) max@0: { max@0: eT* memptr = x.memptr(); max@0: const uword n_elem = x.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j max@0: arma_inline max@0: void max@0: Mat_aux::prefix_pp(Mat< std::complex >& x) max@0: { max@0: x += T(1); max@0: } max@0: max@0: max@0: max@0: //! postfix ++ max@0: template max@0: arma_inline max@0: void max@0: Mat_aux::postfix_pp(Mat& x) max@0: { max@0: eT* memptr = x.memptr(); max@0: const uword n_elem = x.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j max@0: arma_inline max@0: void max@0: Mat_aux::postfix_pp(Mat< std::complex >& x) max@0: { max@0: x += T(1); max@0: } max@0: max@0: max@0: max@0: //! prefix -- max@0: template max@0: arma_inline max@0: void max@0: Mat_aux::prefix_mm(Mat& x) max@0: { max@0: eT* memptr = x.memptr(); max@0: const uword n_elem = x.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j max@0: arma_inline max@0: void max@0: Mat_aux::prefix_mm(Mat< std::complex >& x) max@0: { max@0: x -= T(1); max@0: } max@0: max@0: max@0: max@0: //! postfix -- max@0: template max@0: arma_inline max@0: void max@0: Mat_aux::postfix_mm(Mat& x) max@0: { max@0: eT* memptr = x.memptr(); max@0: const uword n_elem = x.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j max@0: arma_inline max@0: void max@0: Mat_aux::postfix_mm(Mat< std::complex >& x) max@0: { max@0: x -= T(1); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat_aux::set_real(Mat& out, const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const unwrap tmp(X.get_ref()); max@0: const Mat& A = tmp.M; max@0: max@0: arma_debug_assert_same_size( out, A, "Mat::set_real()" ); max@0: max@0: out = A; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat_aux::set_imag(Mat& out, const Base& X) 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: Mat_aux::set_real(Mat< std::complex >& out, const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename std::complex eT; max@0: typedef typename Proxy::ea_type ea_type; max@0: max@0: const Proxy A(X.get_ref()); max@0: max@0: arma_debug_assert_same_size( out, A, "Mat::set_real()" ); max@0: max@0: const uword n_elem = out.n_elem; max@0: eT* out_mem = out.memptr(); max@0: ea_type PA = A.get_ea(); max@0: max@0: for(uword i=0; i( PA[i], out_mem[i].imag() ); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Mat_aux::set_imag(Mat< std::complex >& out, const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename std::complex eT; max@0: typedef typename Proxy::ea_type ea_type; max@0: max@0: const Proxy A(X.get_ref()); max@0: max@0: arma_debug_assert_same_size( out, A, "Mat::set_imag()" ); max@0: max@0: const uword n_elem = out.n_elem; max@0: eT* out_mem = out.memptr(); max@0: ea_type PA = A.get_ea(); max@0: max@0: for(uword i=0; i( out_mem[i].real(), PA[i] ); max@0: } max@0: } max@0: max@0: max@0: max@0: #ifdef ARMA_EXTRA_MAT_MEAT max@0: #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT) max@0: #endif max@0: max@0: max@0: max@0: //! @}