123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719 |
- // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
- // Copyright 2008-2016 National ICT Australia (NICTA)
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // ------------------------------------------------------------------------
- //! \addtogroup Row
- //! @{
- //! construct an empty row vector
- template<typename eT>
- inline
- Row<eT>::Row()
- : Mat<eT>(arma_vec_indicator(), 2)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Row<eT>::Row(const Row<eT>& X)
- : Mat<eT>(arma_vec_indicator(), 1, X.n_elem, 2)
- {
- arma_extra_debug_sigprint();
-
- arrayops::copy((*this).memptr(), X.memptr(), X.n_elem);
- }
- //! construct a row vector with the specified number of n_elem
- template<typename eT>
- inline
- Row<eT>::Row(const uword in_n_elem)
- : Mat<eT>(arma_vec_indicator(), 1, in_n_elem, 2)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Row<eT>::Row(const uword in_n_rows, const uword in_n_cols)
- : Mat<eT>(arma_vec_indicator(), 0, 0, 2)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::init_warm(in_n_rows, in_n_cols);
- }
- template<typename eT>
- inline
- Row<eT>::Row(const SizeMat& s)
- : Mat<eT>(arma_vec_indicator(), 0, 0, 2)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::init_warm(s.n_rows, s.n_cols);
- }
- template<typename eT>
- template<typename fill_type>
- inline
- Row<eT>::Row(const uword in_n_elem, const fill::fill_class<fill_type>& f)
- : Mat<eT>(arma_vec_indicator(), 1, in_n_elem, 2)
- {
- arma_extra_debug_sigprint();
-
- (*this).fill(f);
- }
- template<typename eT>
- template<typename fill_type>
- inline
- Row<eT>::Row(const uword in_n_rows, const uword in_n_cols, const fill::fill_class<fill_type>& f)
- : Mat<eT>(arma_vec_indicator(), 0, 0, 2)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::init_warm(in_n_rows, in_n_cols);
-
- (*this).fill(f);
- }
- template<typename eT>
- template<typename fill_type>
- inline
- Row<eT>::Row(const SizeMat& s, const fill::fill_class<fill_type>& f)
- : Mat<eT>(arma_vec_indicator(), 0, 0, 2)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::init_warm(s.n_rows, s.n_cols);
-
- (*this).fill(f);
- }
- template<typename eT>
- inline
- Row<eT>::Row(const char* text)
- : Mat<eT>(arma_vec_indicator(), 2)
- {
- arma_extra_debug_sigprint();
-
- (*this).operator=(text);
- }
-
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(const char* text)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT> tmp(text);
-
- arma_debug_check( ((tmp.n_elem > 0) && (tmp.is_vec() == false)), "Mat::init(): requested size is not compatible with row vector layout" );
-
- access::rw(tmp.n_rows) = 1;
- access::rw(tmp.n_cols) = tmp.n_elem;
-
- (*this).steal_mem(tmp);
-
- return *this;
- }
- template<typename eT>
- inline
- Row<eT>::Row(const std::string& text)
- : Mat<eT>(arma_vec_indicator(), 2)
- {
- arma_extra_debug_sigprint();
-
- (*this).operator=(text);
- }
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(const std::string& text)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT> tmp(text);
-
- arma_debug_check( ((tmp.n_elem > 0) && (tmp.is_vec() == false)), "Mat::init(): requested size is not compatible with row vector layout" );
-
- access::rw(tmp.n_rows) = 1;
- access::rw(tmp.n_cols) = tmp.n_elem;
-
- (*this).steal_mem(tmp);
-
- return *this;
- }
- //! create a row vector from std::vector
- template<typename eT>
- inline
- Row<eT>::Row(const std::vector<eT>& x)
- : Mat<eT>(arma_vec_indicator(), 1, uword(x.size()), 2)
- {
- arma_extra_debug_sigprint_this(this);
-
- if(x.size() > 0)
- {
- arrayops::copy( Mat<eT>::memptr(), &(x[0]), uword(x.size()) );
- }
- }
-
-
-
- //! create a row vector from std::vector
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(const std::vector<eT>& x)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::init_warm(1, uword(x.size()));
-
- if(x.size() > 0)
- {
- arrayops::copy( Mat<eT>::memptr(), &(x[0]), uword(x.size()) );
- }
-
- return *this;
- }
- #if defined(ARMA_USE_CXX11)
-
- template<typename eT>
- inline
- Row<eT>::Row(const std::initializer_list<eT>& list)
- : Mat<eT>(arma_vec_indicator(), 2)
- {
- arma_extra_debug_sigprint();
-
- (*this).operator=(list);
- }
-
-
-
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(const std::initializer_list<eT>& list)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT> tmp(list);
-
- arma_debug_check( ((tmp.n_elem > 0) && (tmp.is_vec() == false)), "Mat::init(): requested size is not compatible with row vector layout" );
-
- access::rw(tmp.n_rows) = 1;
- access::rw(tmp.n_cols) = tmp.n_elem;
-
- (*this).steal_mem(tmp);
-
- return *this;
- }
-
-
-
- template<typename eT>
- inline
- Row<eT>::Row(Row<eT>&& X)
- : Mat<eT>(arma_vec_indicator(), 2)
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X);
-
- access::rw(Mat<eT>::n_rows) = 1;
- access::rw(Mat<eT>::n_cols) = X.n_cols;
- access::rw(Mat<eT>::n_elem) = X.n_elem;
-
- if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) )
- {
- access::rw(Mat<eT>::mem_state) = X.mem_state;
- access::rw(Mat<eT>::mem) = X.mem;
-
- access::rw(X.n_rows) = 1;
- access::rw(X.n_cols) = 0;
- access::rw(X.n_elem) = 0;
- access::rw(X.mem_state) = 0;
- access::rw(X.mem) = 0;
- }
- else
- {
- (*this).init_cold();
-
- arrayops::copy( (*this).memptr(), X.mem, X.n_elem );
-
- if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) )
- {
- access::rw(X.n_rows) = 1;
- access::rw(X.n_cols) = 0;
- access::rw(X.n_elem) = 0;
- access::rw(X.mem) = 0;
- }
- }
- }
-
-
-
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(Row<eT>&& X)
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X);
-
- (*this).steal_mem(X);
-
- if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) )
- {
- access::rw(X.n_rows) = 1;
- access::rw(X.n_cols) = 0;
- access::rw(X.n_elem) = 0;
- access::rw(X.mem) = 0;
- }
-
- return *this;
- }
-
- #endif
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(val);
-
- return *this;
- }
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(const Row<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Row<eT>::Row(const Base<eT,T1>& X)
- : Mat<eT>(arma_vec_indicator(), 2)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(X.get_ref());
- }
- template<typename eT>
- template<typename T1>
- inline
- Row<eT>&
- Row<eT>::operator=(const Base<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(X.get_ref());
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Row<eT>::Row(const SpBase<eT,T1>& X)
- : Mat<eT>(arma_vec_indicator(), 2)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(X.get_ref());
- }
- template<typename eT>
- template<typename T1>
- inline
- Row<eT>&
- Row<eT>::operator=(const SpBase<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(X.get_ref());
-
- return *this;
- }
- //! construct a row vector from a given auxiliary array
- template<typename eT>
- inline
- Row<eT>::Row(eT* aux_mem, const uword aux_length, const bool copy_aux_mem, const bool strict)
- : Mat<eT>(aux_mem, 1, aux_length, copy_aux_mem, strict)
- {
- arma_extra_debug_sigprint();
-
- access::rw(Mat<eT>::vec_state) = 2;
- }
- //! construct a row vector from a given auxiliary array
- template<typename eT>
- inline
- Row<eT>::Row(const eT* aux_mem, const uword aux_length)
- : Mat<eT>(aux_mem, 1, aux_length)
- {
- arma_extra_debug_sigprint();
-
- access::rw(Mat<eT>::vec_state) = 2;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Row<eT>::Row
- (
- const Base<typename Row<eT>::pod_type, T1>& A,
- const Base<typename Row<eT>::pod_type, T2>& B
- )
- {
- arma_extra_debug_sigprint();
-
- access::rw(Mat<eT>::vec_state) = 2;
-
- Mat<eT>::init(A,B);
- }
- template<typename eT>
- template<typename T1>
- inline
- Row<eT>::Row(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- access::rw(Mat<eT>::vec_state) = 2;
-
- Mat<eT>::operator=(X);
- }
- template<typename eT>
- template<typename T1>
- inline
- Row<eT>&
- Row<eT>::operator=(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(X);
-
- return *this;
- }
- template<typename eT>
- inline
- Row<eT>::Row(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- access::rw(Mat<eT>::vec_state) = 2;
-
- Mat<eT>::operator=(X);
- }
- template<typename eT>
- inline
- Row<eT>&
- Row<eT>::operator=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::operator=(X);
-
- return *this;
- }
- template<typename eT>
- inline
- mat_injector< Row<eT> >
- Row<eT>::operator<<(const eT val)
- {
- return mat_injector< Row<eT> >(*this, val);
- }
- template<typename eT>
- arma_inline
- const Op<Row<eT>,op_htrans>
- Row<eT>::t() const
- {
- return Op<Row<eT>,op_htrans>(*this);
- }
- template<typename eT>
- arma_inline
- const Op<Row<eT>,op_htrans>
- Row<eT>::ht() const
- {
- return Op<Row<eT>,op_htrans>(*this);
- }
- template<typename eT>
- arma_inline
- const Op<Row<eT>,op_strans>
- Row<eT>::st() const
- {
- return Op<Row<eT>,op_strans>(*this);
- }
- template<typename eT>
- arma_inline
- const Op<Row<eT>,op_strans>
- Row<eT>::as_col() const
- {
- return Op<Row<eT>,op_strans>(*this);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::col(const uword in_col1)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_col1 >= Mat<eT>::n_cols), "Row::col(): indices out of bounds or incorrectly used");
-
- return subview_row<eT>(*this, 0, in_col1, 1);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::col(const uword in_col1) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_col1 >= Mat<eT>::n_cols), "Row::col(): indices out of bounds or incorrectly used");
-
- return subview_row<eT>(*this, 0, in_col1, 1);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::cols(const uword in_col1, const uword in_col2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used");
-
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview_row<eT>(*this, 0, in_col1, subview_n_cols);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::cols(const uword in_col1, const uword in_col2) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used");
-
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview_row<eT>(*this, 0, in_col1, subview_n_cols);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::subvec(const uword in_col1, const uword in_col2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used");
-
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview_row<eT>(*this, 0, in_col1, subview_n_cols);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::subvec(const uword in_col1, const uword in_col2) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used");
-
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview_row<eT>(*this, 0, in_col1, subview_n_cols);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::cols(const span& col_span)
- {
- arma_extra_debug_sigprint();
-
- return subvec(col_span);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::cols(const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- return subvec(col_span);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::subvec(const span& col_span)
- {
- arma_extra_debug_sigprint();
-
- const bool col_all = col_span.whole;
- const uword local_n_cols = Mat<eT>::n_cols;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
- arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used");
-
- return subview_row<eT>(*this, 0, in_col1, subvec_n_cols);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::subvec(const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- const bool col_all = col_span.whole;
- const uword local_n_cols = Mat<eT>::n_cols;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
- arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used");
-
- return subview_row<eT>(*this, 0, in_col1, subvec_n_cols);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::operator()(const span& col_span)
- {
- arma_extra_debug_sigprint();
-
- return subvec(col_span);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::operator()(const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- return subvec(col_span);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::subvec(const uword start_col, const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (s.n_rows != 1), "Row::subvec(): given size does not specify a row vector" );
-
- arma_debug_check( ( (start_col >= Mat<eT>::n_cols) || ((start_col + s.n_cols) > Mat<eT>::n_cols) ), "Row::subvec(): size out of bounds" );
-
- return subview_row<eT>(*this, 0, start_col, s.n_cols);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::subvec(const uword start_col, const SizeMat& s) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (s.n_rows != 1), "Row::subvec(): given size does not specify a row vector" );
-
- arma_debug_check( ( (start_col >= Mat<eT>::n_cols) || ((start_col + s.n_cols) > Mat<eT>::n_cols) ), "Row::subvec(): size out of bounds" );
-
- return subview_row<eT>(*this, 0, start_col, s.n_cols);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::head(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > Mat<eT>::n_cols), "Row::head(): size out of bounds");
-
- return subview_row<eT>(*this, 0, 0, N);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::head(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > Mat<eT>::n_cols), "Row::head(): size out of bounds");
-
- return subview_row<eT>(*this, 0, 0, N);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::tail(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > Mat<eT>::n_cols), "Row::tail(): size out of bounds");
-
- const uword start_col = Mat<eT>::n_cols - N;
-
- return subview_row<eT>(*this, 0, start_col, N);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::tail(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > Mat<eT>::n_cols), "Row::tail(): size out of bounds");
-
- const uword start_col = Mat<eT>::n_cols - N;
-
- return subview_row<eT>(*this, 0, start_col, N);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::head_cols(const uword N)
- {
- arma_extra_debug_sigprint();
-
- return (*this).head(N);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::head_cols(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).head(N);
- }
- template<typename eT>
- arma_inline
- subview_row<eT>
- Row<eT>::tail_cols(const uword N)
- {
- arma_extra_debug_sigprint();
-
- return (*this).tail(N);
- }
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Row<eT>::tail_cols(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).tail(N);
- }
- //! remove specified columns
- template<typename eT>
- inline
- void
- Row<eT>::shed_col(const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( col_num >= Mat<eT>::n_cols, "Row::shed_col(): index out of bounds");
-
- shed_cols(col_num, col_num);
- }
- //! remove specified columns
- template<typename eT>
- inline
- void
- Row<eT>::shed_cols(const uword in_col1, const uword in_col2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols),
- "Row::shed_cols(): indices out of bounds or incorrectly used"
- );
-
- const uword n_keep_front = in_col1;
- const uword n_keep_back = Mat<eT>::n_cols - (in_col2 + 1);
-
- Row<eT> X(n_keep_front + n_keep_back);
-
- eT* X_mem = X.memptr();
- const eT* t_mem = (*this).memptr();
-
- if(n_keep_front > 0)
- {
- arrayops::copy( X_mem, t_mem, n_keep_front );
- }
-
- if(n_keep_back > 0)
- {
- arrayops::copy( &(X_mem[n_keep_front]), &(t_mem[in_col2+1]), n_keep_back);
- }
-
- Mat<eT>::steal_mem(X);
- }
- //! remove specified columns
- template<typename eT>
- template<typename T1>
- inline
- void
- Row<eT>::shed_cols(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::shed_cols(indices);
- }
- //! insert N cols at the specified col position,
- //! optionally setting the elements of the inserted cols to zero
- template<typename eT>
- inline
- void
- Row<eT>::insert_cols(const uword col_num, const uword N, const bool set_to_zero)
- {
- arma_extra_debug_sigprint();
-
- const uword t_n_cols = Mat<eT>::n_cols;
-
- const uword A_n_cols = col_num;
- const uword B_n_cols = t_n_cols - col_num;
-
- // insertion at col_num == n_cols is in effect an append operation
- arma_debug_check( (col_num > t_n_cols), "Row::insert_cols(): index out of bounds");
-
- if(N > 0)
- {
- Row<eT> out(t_n_cols + N);
-
- eT* out_mem = out.memptr();
- const eT* t_mem = (*this).memptr();
-
- if(A_n_cols > 0)
- {
- arrayops::copy( out_mem, t_mem, A_n_cols );
- }
-
- if(B_n_cols > 0)
- {
- arrayops::copy( &(out_mem[col_num + N]), &(t_mem[col_num]), B_n_cols );
- }
-
- if(set_to_zero)
- {
- arrayops::inplace_set( &(out_mem[col_num]), eT(0), N );
- }
-
- Mat<eT>::steal_mem(out);
- }
- }
- //! insert the given object at the specified col position;
- //! the given object must have one row
- template<typename eT>
- template<typename T1>
- inline
- void
- Row<eT>::insert_cols(const uword col_num, const Base<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::insert_cols(col_num, X);
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Row<eT>::at(const uword i)
- {
- return access::rw(Mat<eT>::mem[i]);
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::at(const uword i) const
- {
- return Mat<eT>::mem[i];
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Row<eT>::at(const uword, const uword in_col)
- {
- return access::rw( Mat<eT>::mem[in_col] );
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::at(const uword, const uword in_col) const
- {
- return Mat<eT>::mem[in_col];
- }
- template<typename eT>
- inline
- typename Row<eT>::row_iterator
- Row<eT>::begin_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= Mat<eT>::n_rows), "Row::begin_row(): index out of bounds");
-
- return Mat<eT>::memptr();
- }
- template<typename eT>
- inline
- typename Row<eT>::const_row_iterator
- Row<eT>::begin_row(const uword row_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= Mat<eT>::n_rows), "Row::begin_row(): index out of bounds");
-
- return Mat<eT>::memptr();
- }
- template<typename eT>
- inline
- typename Row<eT>::row_iterator
- Row<eT>::end_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= Mat<eT>::n_rows), "Row::end_row(): index out of bounds");
-
- return Mat<eT>::memptr() + Mat<eT>::n_cols;
- }
- template<typename eT>
- inline
- typename Row<eT>::const_row_iterator
- Row<eT>::end_row(const uword row_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= Mat<eT>::n_rows), "Row::end_row(): index out of bounds");
-
- return Mat<eT>::memptr() + Mat<eT>::n_cols;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- Row<eT>::fixed<fixed_n_elem>::fixed()
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const fixed<fixed_n_elem>& X)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- eT* dest = (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
- const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local;
-
- arrayops::copy( dest, src, fixed_n_elem );
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const subview_cube<eT>& X)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Row<eT>::operator=(X);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- template<typename fill_type>
- inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const fill::fill_class<fill_type>&)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- if(is_same_type<fill_type, fill::fill_zeros>::yes) (*this).zeros();
- if(is_same_type<fill_type, fill::fill_ones >::yes) (*this).ones();
- if(is_same_type<fill_type, fill::fill_eye >::yes) (*this).eye();
- if(is_same_type<fill_type, fill::fill_randu>::yes) (*this).randu();
- if(is_same_type<fill_type, fill::fill_randn>::yes) (*this).randn();
- }
- template<typename eT>
- template<uword fixed_n_elem>
- template<typename T1>
- arma_inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const Base<eT,T1>& A)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Row<eT>::operator=(A.get_ref());
- }
- template<typename eT>
- template<uword fixed_n_elem>
- template<typename T1, typename T2>
- arma_inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Row<eT>::init(A,B);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const eT* aux_mem)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- eT* dest = (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
-
- arrayops::copy( dest, aux_mem, fixed_n_elem );
- }
- template<typename eT>
- template<uword fixed_n_elem>
- inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const char* text)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Row<eT>::operator=(text);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const std::string& text)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Row<eT>::operator=(text);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- template<typename T1>
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const Base<eT,T1>& A)
- {
- arma_extra_debug_sigprint();
-
- Row<eT>::operator=(A.get_ref());
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- Row<eT>::operator=(val);
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const char* text)
- {
- arma_extra_debug_sigprint();
-
- Row<eT>::operator=(text);
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const std::string& text)
- {
- arma_extra_debug_sigprint();
-
- Row<eT>::operator=(text);
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- Row<eT>::operator=(X);
-
- return *this;
- }
- #if defined(ARMA_USE_CXX11)
-
- template<typename eT>
- template<uword fixed_n_elem>
- inline
- Row<eT>::fixed<fixed_n_elem>::fixed(const std::initializer_list<eT>& list)
- : Row<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- (*this).operator=(list);
- }
-
-
-
- template<typename eT>
- template<uword fixed_n_elem>
- inline
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const std::initializer_list<eT>& list)
- {
- arma_extra_debug_sigprint();
-
- const uword N = uword(list.size());
-
- arma_debug_check( (N > fixed_n_elem), "Row::fixed: initialiser list is too long" );
-
- eT* this_mem = (*this).memptr();
-
- arrayops::copy( this_mem, list.begin(), N );
-
- for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); }
-
- return *this;
- }
-
- #endif
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const fixed<fixed_n_elem>& X)
- {
- arma_extra_debug_sigprint();
-
- if(this != &X)
- {
- eT* dest = (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
- const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local;
-
- arrayops::copy( dest, src, fixed_n_elem );
- }
-
- return *this;
- }
- #if defined(ARMA_GOOD_COMPILER)
-
- template<typename eT>
- template<uword fixed_n_elem>
- template<typename T1, typename eop_type>
- inline
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const bool bad_alias = (eOp<T1, eop_type>::proxy_type::has_subview && X.P.is_alias(*this));
-
- if(bad_alias == false)
- {
- arma_debug_assert_same_size(uword(1), fixed_n_elem, X.get_n_rows(), X.get_n_cols(), "Row::fixed::operator=");
-
- eop_type::apply(*this, X);
- }
- else
- {
- arma_extra_debug_print("bad_alias = true");
-
- Row<eT> tmp(X);
-
- (*this) = tmp;
- }
-
- return *this;
- }
-
-
-
- template<typename eT>
- template<uword fixed_n_elem>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::operator=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- const bool bad_alias =
- (
- (eGlue<T1, T2, eglue_type>::proxy1_type::has_subview && X.P1.is_alias(*this))
- ||
- (eGlue<T1, T2, eglue_type>::proxy2_type::has_subview && X.P2.is_alias(*this))
- );
-
- if(bad_alias == false)
- {
- arma_debug_assert_same_size(uword(1), fixed_n_elem, X.get_n_rows(), X.get_n_cols(), "Row::fixed::operator=");
-
- eglue_type::apply(*this, X);
- }
- else
- {
- arma_extra_debug_print("bad_alias = true");
-
- Row<eT> tmp(X);
-
- (*this) = tmp;
- }
-
- return *this;
- }
-
- #endif
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- const Op< typename Row<eT>::template fixed<fixed_n_elem>::Row_fixed_type, op_htrans >
- Row<eT>::fixed<fixed_n_elem>::t() const
- {
- return Op< typename Row<eT>::template fixed<fixed_n_elem>::Row_fixed_type, op_htrans >(*this);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- const Op< typename Row<eT>::template fixed<fixed_n_elem>::Row_fixed_type, op_htrans >
- Row<eT>::fixed<fixed_n_elem>::ht() const
- {
- return Op< typename Row<eT>::template fixed<fixed_n_elem>::Row_fixed_type, op_htrans >(*this);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- const Op< typename Row<eT>::template fixed<fixed_n_elem>::Row_fixed_type, op_strans >
- Row<eT>::fixed<fixed_n_elem>::st() const
- {
- return Op< typename Row<eT>::template fixed<fixed_n_elem>::Row_fixed_type, op_strans >(*this);
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::fixed<fixed_n_elem>::at_alt(const uword ii) const
- {
- #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE)
-
- return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
-
- #else
- const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
-
- memory::mark_as_aligned(mem_aligned);
-
- return mem_aligned[ii];
- #endif
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- eT&
- Row<eT>::fixed<fixed_n_elem>::operator[] (const uword ii)
- {
- return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::fixed<fixed_n_elem>::operator[] (const uword ii) const
- {
- return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- eT&
- Row<eT>::fixed<fixed_n_elem>::at(const uword ii)
- {
- return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::fixed<fixed_n_elem>::at(const uword ii) const
- {
- return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- eT&
- Row<eT>::fixed<fixed_n_elem>::operator() (const uword ii)
- {
- arma_debug_check( (ii >= fixed_n_elem), "Row::operator(): index out of bounds");
-
- return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::fixed<fixed_n_elem>::operator() (const uword ii) const
- {
- arma_debug_check( (ii >= fixed_n_elem), "Row::operator(): index out of bounds");
-
- return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- eT&
- Row<eT>::fixed<fixed_n_elem>::at(const uword, const uword in_col)
- {
- return (use_extra) ? mem_local_extra[in_col] : Mat<eT>::mem_local[in_col];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::fixed<fixed_n_elem>::at(const uword, const uword in_col) const
- {
- return (use_extra) ? mem_local_extra[in_col] : Mat<eT>::mem_local[in_col];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- eT&
- Row<eT>::fixed<fixed_n_elem>::operator() (const uword in_row, const uword in_col)
- {
- arma_debug_check( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" );
-
- return (use_extra) ? mem_local_extra[in_col] : Mat<eT>::mem_local[in_col];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- const eT&
- Row<eT>::fixed<fixed_n_elem>::operator() (const uword in_row, const uword in_col) const
- {
- arma_debug_check( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" );
-
- return (use_extra) ? mem_local_extra[in_col] : Mat<eT>::mem_local[in_col];
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- eT*
- Row<eT>::fixed<fixed_n_elem>::memptr()
- {
- return (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_inline
- arma_warn_unused
- const eT*
- Row<eT>::fixed<fixed_n_elem>::memptr() const
- {
- return (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_hot
- inline
- const Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::fill(const eT val)
- {
- arma_extra_debug_sigprint();
-
- eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat<eT>::mem_local[0]);
-
- arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, val );
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_hot
- inline
- const Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::zeros()
- {
- arma_extra_debug_sigprint();
-
- eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat<eT>::mem_local[0]);
-
- arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, eT(0) );
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_elem>
- arma_hot
- inline
- const Row<eT>&
- Row<eT>::fixed<fixed_n_elem>::ones()
- {
- arma_extra_debug_sigprint();
-
- eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat<eT>::mem_local[0]);
-
- arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, eT(1) );
-
- return *this;
- }
- template<typename eT>
- inline
- Row<eT>::Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem)
- : Mat<eT>(arma_fixed_indicator(), 1, in_n_elem, 2, in_mem)
- {
- arma_extra_debug_sigprint_this(this);
- }
- #ifdef ARMA_EXTRA_ROW_MEAT
- #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_MEAT)
- #endif
- //! @}
|