// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup injector //! @{ template inline mat_injector_row::mat_injector_row() : n_cols(0) { arma_extra_debug_sigprint(); A.set_size( podarray_prealloc_n_elem::val ); } template inline void mat_injector_row::insert(const eT val) const { arma_extra_debug_sigprint(); if(n_cols < A.n_elem) { A[n_cols] = val; ++n_cols; } else { B.set_size(2 * A.n_elem); arrayops::copy(B.memptr(), A.memptr(), n_cols); B[n_cols] = val; ++n_cols; std::swap( access::rw(A.mem), access::rw(B.mem) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); } } // // // template inline mat_injector::mat_injector(T1& in_X, const typename mat_injector::elem_type val) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; AA = new podarray< mat_injector_row* >; BB = new podarray< mat_injector_row* >; podarray< mat_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*(A[0])).insert(val); } template inline mat_injector::mat_injector(T1& in_X, const injector_end_of_row<>& x) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); arma_ignore(x); typedef typename mat_injector::elem_type eT; AA = new podarray< mat_injector_row* >; BB = new podarray< mat_injector_row* >; podarray< mat_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*this).end_of_row(); } template inline mat_injector::~mat_injector() { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; if(n_rows > 0) { uword max_n_cols = (*(A[0])).n_cols; for(uword row=1; row::value == true) { X.set_size(max_n_rows, max_n_cols); for(uword row=0; row::value == true) { arma_debug_check( (max_n_rows > 1), "matrix initialisation: incompatible dimensions" ); const uword n_cols = (*(A[0])).n_cols; X.set_size(1, n_cols); arrayops::copy( X.memptr(), (*(A[0])).A.memptr(), n_cols ); } else if(is_Col::value == true) { const bool is_vec = ( (max_n_rows == 1) || (max_n_cols == 1) ); arma_debug_check( (is_vec == false), "matrix initialisation: incompatible dimensions" ); const uword n_elem = (std::max)(max_n_rows, max_n_cols); X.set_size(n_elem, 1); uword i = 0; for(uword row=0; row inline void mat_injector::insert(const typename mat_injector::elem_type val) const { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; (*(A[n_rows-1])).insert(val); } template inline void mat_injector::end_of_row() const { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; podarray< mat_injector_row* >& B = *BB; B.set_size( n_rows+1 ); arrayops::copy(B.memptr(), A.memptr(), n_rows); for(uword row=n_rows; row<(n_rows+1); ++row) { B[row] = new mat_injector_row; } std::swap(AA, BB); n_rows += 1; } template arma_inline const mat_injector& operator<<(const mat_injector& ref, const typename mat_injector::elem_type val) { arma_extra_debug_sigprint(); ref.insert(val); return ref; } template arma_inline const mat_injector& operator<<(const mat_injector& ref, const injector_end_of_row<>& x) { arma_extra_debug_sigprint(); arma_ignore(x); ref.end_of_row(); return ref; } //// using a mixture of operator << and , doesn't work yet //// e.g. A << 1, 2, 3 << endr //// in the above "3 << endr" requires special handling. //// similarly, special handling is necessary for "endr << 3" //// // template // arma_inline // const mat_injector& // operator,(const mat_injector& ref, const typename mat_injector::elem_type val) // { // arma_extra_debug_sigprint(); // // ref.insert(val); // // return ref; // } // template // arma_inline // const mat_injector& // operator,(const mat_injector& ref, const injector_end_of_row<>& x) // { // arma_extra_debug_sigprint(); // arma_ignore(x); // // ref.end_of_row(); // // return ref; // } // // // template inline field_injector_row::field_injector_row() : n_cols(0) { arma_extra_debug_sigprint(); AA = new field; BB = new field; field& A = *AA; A.set_size( field_prealloc_n_elem::val ); } template inline field_injector_row::~field_injector_row() { arma_extra_debug_sigprint(); delete AA; delete BB; } template inline void field_injector_row::insert(const oT& val) const { arma_extra_debug_sigprint(); field& A = *AA; field& B = *BB; if(n_cols < A.n_elem) { A[n_cols] = val; ++n_cols; } else { B.set_size(2 * A.n_elem); for(uword i=0; i inline field_injector::field_injector(T1& in_X, const typename field_injector::object_type& val) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; AA = new podarray< field_injector_row* >; BB = new podarray< field_injector_row* >; podarray< field_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*(A[0])).insert(val); } template inline field_injector::field_injector(T1& in_X, const injector_end_of_row<>& x) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); arma_ignore(x); typedef typename field_injector::object_type oT; AA = new podarray< field_injector_row* >; BB = new podarray< field_injector_row* >; podarray< field_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*this).end_of_row(); } template inline field_injector::~field_injector() { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; if(n_rows > 0) { uword max_n_cols = (*(A[0])).n_cols; for(uword row=1; row& tmp = *((*(A[row])).AA); X.at(row,col) = tmp[col]; } for(uword col=n_cols; col inline void field_injector::insert(const typename field_injector::object_type& val) const { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; (*(A[n_rows-1])).insert(val); } template inline void field_injector::end_of_row() const { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; podarray< field_injector_row* >& B = *BB; B.set_size( n_rows+1 ); for(uword row=0; row; } std::swap(AA, BB); n_rows += 1; } template arma_inline const field_injector& operator<<(const field_injector& ref, const typename field_injector::object_type& val) { arma_extra_debug_sigprint(); ref.insert(val); return ref; } template arma_inline const field_injector& operator<<(const field_injector& ref, const injector_end_of_row<>& x) { arma_extra_debug_sigprint(); arma_ignore(x); ref.end_of_row(); return ref; } //! @}