123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401 |
- // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
- // Copyright 2008-2016 National ICT Australia (NICTA)
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // ------------------------------------------------------------------------
- //! \addtogroup subview_each
- //! @{
- //
- //
- // subview_each_common
- template<typename parent, unsigned int mode>
- inline
- subview_each_common<parent,mode>::subview_each_common(const parent& in_P)
- : P(in_P)
- {
- arma_extra_debug_sigprint();
- }
- template<typename parent, unsigned int mode>
- arma_inline
- const Mat<typename parent::elem_type>&
- subview_each_common<parent,mode>::get_mat_ref_helper(const Mat<typename parent::elem_type>& X) const
- {
- return X;
- }
- template<typename parent, unsigned int mode>
- arma_inline
- const Mat<typename parent::elem_type>&
- subview_each_common<parent,mode>::get_mat_ref_helper(const subview<typename parent::elem_type>& X) const
- {
- return X.m;
- }
- template<typename parent, unsigned int mode>
- arma_inline
- const Mat<typename parent::elem_type>&
- subview_each_common<parent,mode>::get_mat_ref() const
- {
- return get_mat_ref_helper(P);
- }
- template<typename parent, unsigned int mode>
- inline
- void
- subview_each_common<parent,mode>::check_size(const Mat<typename parent::elem_type>& A) const
- {
- if(arma_config::debug == true)
- {
- if(mode == 0)
- {
- if( (A.n_rows != P.n_rows) || (A.n_cols != 1) )
- {
- arma_stop_logic_error( incompat_size_string(A) );
- }
- }
- else
- {
- if( (A.n_rows != 1) || (A.n_cols != P.n_cols) )
- {
- arma_stop_logic_error( incompat_size_string(A) );
- }
- }
- }
- }
- template<typename parent, unsigned int mode>
- arma_cold
- inline
- const std::string
- subview_each_common<parent,mode>::incompat_size_string(const Mat<typename parent::elem_type>& A) const
- {
- std::ostringstream tmp;
-
- if(mode == 0)
- {
- tmp << "each_col(): incompatible size; expected " << P.n_rows << "x1" << ", got " << A.n_rows << 'x' << A.n_cols;
- }
- else
- {
- tmp << "each_row(): incompatible size; expected 1x" << P.n_cols << ", got " << A.n_rows << 'x' << A.n_cols;
- }
-
- return tmp.str();
- }
-
- //
- //
- // subview_each1
- template<typename parent, unsigned int mode>
- inline
- subview_each1<parent,mode>::~subview_each1()
- {
- arma_extra_debug_sigprint();
- }
- template<typename parent, unsigned int mode>
- inline
- subview_each1<parent,mode>::subview_each1(const parent& in_P)
- : subview_each_common<parent,mode>::subview_each_common(in_P)
- {
- arma_extra_debug_sigprint();
- }
- template<typename parent, unsigned int mode>
- template<typename T1>
- inline
- void
- subview_each1<parent,mode>::operator= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const eT* A_mem = A.memptr();
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::copy( p.colptr(i), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_set( p.colptr(i), A_mem[i], p_n_rows);
- }
- }
- }
- template<typename parent, unsigned int mode>
- template<typename T1>
- inline
- void
- subview_each1<parent,mode>::operator+= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const eT* A_mem = A.memptr();
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_plus( p.colptr(i), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_plus( p.colptr(i), A_mem[i], p_n_rows);
- }
- }
- }
- template<typename parent, unsigned int mode>
- template<typename T1>
- inline
- void
- subview_each1<parent,mode>::operator-= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const eT* A_mem = A.memptr();
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_minus( p.colptr(i), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_minus( p.colptr(i), A_mem[i], p_n_rows);
- }
- }
- }
- template<typename parent, unsigned int mode>
- template<typename T1>
- inline
- void
- subview_each1<parent,mode>::operator%= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const eT* A_mem = A.memptr();
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_mul( p.colptr(i), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_mul( p.colptr(i), A_mem[i], p_n_rows);
- }
- }
- }
- template<typename parent, unsigned int mode>
- template<typename T1>
- inline
- void
- subview_each1<parent,mode>::operator/= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const eT* A_mem = A.memptr();
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_div( p.colptr(i), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- arrayops::inplace_div( p.colptr(i), A_mem[i], p_n_rows);
- }
- }
- }
- //
- //
- // subview_each2
- template<typename parent, unsigned int mode, typename TB>
- inline
- subview_each2<parent,mode,TB>::~subview_each2()
- {
- arma_extra_debug_sigprint();
- }
- template<typename parent, unsigned int mode, typename TB>
- inline
- subview_each2<parent,mode,TB>::subview_each2(const parent& in_P, const Base<uword, TB>& in_indices)
- : subview_each_common<parent,mode>::subview_each_common(in_P)
- , base_indices(in_indices)
- {
- arma_extra_debug_sigprint();
- }
- template<typename parent, unsigned int mode, typename TB>
- inline
- void
- subview_each2<parent,mode,TB>::check_indices(const Mat<uword>& indices) const
- {
- if(mode == 0)
- {
- arma_debug_check( ((indices.is_vec() == false) && (indices.is_empty() == false)), "each_col(): list of indices must be a vector" );
- }
- else
- {
- arma_debug_check( ((indices.is_vec() == false) && (indices.is_empty() == false)), "each_row(): list of indices must be a vector" );
- }
- }
- template<typename parent, unsigned int mode, typename TB>
- template<typename T1>
- inline
- void
- subview_each2<parent,mode,TB>::operator= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const unwrap_check_mixed<TB> U( base_indices.get_ref(), (*this).get_mat_ref() );
-
- check_indices(U.M);
-
- const eT* A_mem = A.memptr();
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::copy( p.colptr(col), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- for(uword col=0; col < p_n_cols; ++col)
- {
- p.at(row,col) = A_mem[col];
- }
- }
- }
- }
- template<typename parent, unsigned int mode, typename TB>
- template<typename T1>
- inline
- void
- subview_each2<parent,mode,TB>::operator+= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const unwrap_check_mixed<TB> U( base_indices.get_ref(), (*this).get_mat_ref() );
-
- check_indices(U.M);
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // each column
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_plus( p.colptr(col), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- p.row(row) += A;
- }
- }
- }
- template<typename parent, unsigned int mode, typename TB>
- template<typename T1>
- inline
- void
- subview_each2<parent,mode,TB>::operator-= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const unwrap_check_mixed<TB> U( base_indices.get_ref(), (*this).get_mat_ref() );
-
- check_indices(U.M);
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // each column
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_minus( p.colptr(col), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- p.row(row) -= A;
- }
- }
- }
- template<typename parent, unsigned int mode, typename TB>
- template<typename T1>
- inline
- void
- subview_each2<parent,mode,TB>::operator%= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const unwrap_check_mixed<TB> U( base_indices.get_ref(), (*this).get_mat_ref() );
-
- check_indices(U.M);
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // each column
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_mul( p.colptr(col), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- p.row(row) %= A;
- }
- }
- }
- template<typename parent, unsigned int mode, typename TB>
- template<typename T1>
- inline
- void
- subview_each2<parent,mode,TB>::operator/= (const Base<eT,T1>& in)
- {
- arma_extra_debug_sigprint();
-
- parent& p = access::rw(subview_each_common<parent,mode>::P);
-
- const unwrap_check<T1> tmp( in.get_ref(), (*this).get_mat_ref() );
- const Mat<eT>& A = tmp.M;
-
- subview_each_common<parent,mode>::check_size(A);
-
- const unwrap_check_mixed<TB> U( base_indices.get_ref(), (*this).get_mat_ref() );
-
- check_indices(U.M);
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // each column
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_div( p.colptr(col), A_mem, p_n_rows );
- }
- }
- else // each row
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- p.row(row) /= A;
- }
- }
- }
- //
- //
- // subview_each1_aux
- template<typename parent, unsigned int mode, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each1_aux::operator_plus
- (
- const subview_each1<parent,mode>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out(p_n_rows, p_n_cols);
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- X.check_size(A);
-
- const eT* A_mem = A.memptr();
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] + A_mem[row];
- }
- }
- }
-
- if(mode == 1) // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- const eT A_val = A_mem[i];
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] + A_val;
- }
- }
- }
-
- return out;
- }
- template<typename parent, unsigned int mode, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each1_aux::operator_minus
- (
- const subview_each1<parent,mode>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out(p_n_rows, p_n_cols);
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- X.check_size(A);
-
- const eT* A_mem = A.memptr();
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] - A_mem[row];
- }
- }
- }
-
- if(mode == 1) // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- const eT A_val = A_mem[i];
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] - A_val;
- }
- }
- }
-
- return out;
- }
- template<typename T1, typename parent, unsigned int mode>
- inline
- Mat<typename parent::elem_type>
- subview_each1_aux::operator_minus
- (
- const Base<typename parent::elem_type,T1>& X,
- const subview_each1<parent,mode>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = Y.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out(p_n_rows, p_n_cols);
-
- const quasi_unwrap<T1> tmp(X.get_ref());
- const Mat<eT>& A = tmp.M;
-
- Y.check_size(A);
-
- const eT* A_mem = A.memptr();
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = A_mem[row] - p_mem[row];
- }
- }
- }
-
- if(mode == 1) // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- const eT A_val = A_mem[i];
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = A_val - p_mem[row];
- }
- }
- }
-
- return out;
- }
- template<typename parent, unsigned int mode, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each1_aux::operator_schur
- (
- const subview_each1<parent,mode>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out(p_n_rows, p_n_cols);
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- X.check_size(A);
-
- const eT* A_mem = A.memptr();
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] * A_mem[row];
- }
- }
- }
-
- if(mode == 1) // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- const eT A_val = A_mem[i];
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] * A_val;
- }
- }
- }
-
- return out;
- }
- template<typename parent, unsigned int mode, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each1_aux::operator_div
- (
- const subview_each1<parent,mode>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out(p_n_rows, p_n_cols);
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- X.check_size(A);
-
- const eT* A_mem = A.memptr();
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] / A_mem[row];
- }
- }
- }
-
- if(mode == 1) // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- const eT A_val = A_mem[i];
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = p_mem[row] / A_val;
- }
- }
- }
-
- return out;
- }
- template<typename T1, typename parent, unsigned int mode>
- inline
- Mat<typename parent::elem_type>
- subview_each1_aux::operator_div
- (
- const Base<typename parent::elem_type,T1>& X,
- const subview_each1<parent,mode>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = Y.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out(p_n_rows, p_n_cols);
-
- const quasi_unwrap<T1> tmp(X.get_ref());
- const Mat<eT>& A = tmp.M;
-
- Y.check_size(A);
-
- const eT* A_mem = A.memptr();
-
- if(mode == 0) // each column
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = A_mem[row] / p_mem[row];
- }
- }
- }
-
- if(mode == 1) // each row
- {
- for(uword i=0; i < p_n_cols; ++i)
- {
- const eT* p_mem = p.colptr(i);
- eT* out_mem = out.colptr(i);
-
- const eT A_val = A_mem[i];
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = A_val / p_mem[row];
- }
- }
- }
-
- return out;
- }
- //
- //
- // subview_each2_aux
- template<typename parent, unsigned int mode, typename TB, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each2_aux::operator_plus
- (
- const subview_each2<parent,mode,TB>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out = p;
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- const unwrap<TB> U(X.base_indices.get_ref());
-
- X.check_size(A);
- X.check_indices(U.M);
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // process columns
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_plus( out.colptr(col), A_mem, p_n_rows );
- }
- }
-
- if(mode == 1) // process rows
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- out.row(row) += A;
- }
- }
-
- return out;
- }
- template<typename parent, unsigned int mode, typename TB, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each2_aux::operator_minus
- (
- const subview_each2<parent,mode,TB>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out = p;
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- const unwrap<TB> U(X.base_indices.get_ref());
-
- X.check_size(A);
- X.check_indices(U.M);
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // process columns
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_minus( out.colptr(col), A_mem, p_n_rows );
- }
- }
-
- if(mode == 1) // process rows
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- out.row(row) -= A;
- }
- }
-
- return out;
- }
- template<typename T1, typename parent, unsigned int mode, typename TB>
- inline
- Mat<typename parent::elem_type>
- subview_each2_aux::operator_minus
- (
- const Base<typename parent::elem_type,T1>& X,
- const subview_each2<parent,mode,TB>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = Y.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out = p;
-
- const quasi_unwrap<T1> tmp(X.get_ref());
- const Mat<eT>& A = tmp.M;
-
- const unwrap<TB> U(Y.base_indices.get_ref());
-
- Y.check_size(A);
- Y.check_indices(U.M);
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // process columns
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- const eT* p_mem = p.colptr(col);
- eT* out_mem = out.colptr(col);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = A_mem[row] - p_mem[row];
- }
- }
- }
-
- if(mode == 1) // process rows
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- out.row(row) = A - p.row(row);
- }
- }
-
- return out;
- }
- template<typename parent, unsigned int mode, typename TB, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each2_aux::operator_schur
- (
- const subview_each2<parent,mode,TB>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out = p;
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- const unwrap<TB> U(X.base_indices.get_ref());
-
- X.check_size(A);
- X.check_indices(U.M);
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // process columns
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_mul( out.colptr(col), A_mem, p_n_rows );
- }
- }
-
- if(mode == 1) // process rows
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- out.row(row) %= A;
- }
- }
-
- return out;
- }
- template<typename parent, unsigned int mode, typename TB, typename T2>
- inline
- Mat<typename parent::elem_type>
- subview_each2_aux::operator_div
- (
- const subview_each2<parent,mode,TB>& X,
- const Base<typename parent::elem_type,T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = X.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out = p;
-
- const quasi_unwrap<T2> tmp(Y.get_ref());
- const Mat<eT>& A = tmp.M;
-
- const unwrap<TB> U(X.base_indices.get_ref());
-
- X.check_size(A);
- X.check_indices(U.M);
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // process columns
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- arrayops::inplace_div( out.colptr(col), A_mem, p_n_rows );
- }
- }
-
- if(mode == 1) // process rows
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- out.row(row) /= A;
- }
- }
-
- return out;
- }
- template<typename T1, typename parent, unsigned int mode, typename TB>
- inline
- Mat<typename parent::elem_type>
- subview_each2_aux::operator_div
- (
- const Base<typename parent::elem_type,T1>& X,
- const subview_each2<parent,mode,TB>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename parent::elem_type eT;
-
- const parent& p = Y.P;
-
- const uword p_n_rows = p.n_rows;
- const uword p_n_cols = p.n_cols;
-
- Mat<eT> out = p;
-
- const quasi_unwrap<T1> tmp(X.get_ref());
- const Mat<eT>& A = tmp.M;
-
- const unwrap<TB> U(Y.base_indices.get_ref());
-
- Y.check_size(A);
- Y.check_indices(U.M);
-
- const uword* indices_mem = U.M.memptr();
- const uword N = U.M.n_elem;
-
- if(mode == 0) // process columns
- {
- const eT* A_mem = A.memptr();
-
- for(uword i=0; i < N; ++i)
- {
- const uword col = indices_mem[i];
-
- arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" );
-
- const eT* p_mem = p.colptr(col);
- eT* out_mem = out.colptr(col);
-
- for(uword row=0; row < p_n_rows; ++row)
- {
- out_mem[row] = A_mem[row] / p_mem[row];
- }
- }
- }
-
- if(mode == 1) // process rows
- {
- for(uword i=0; i < N; ++i)
- {
- const uword row = indices_mem[i];
-
- arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" );
-
- out.row(row) = A / p.row(row);
- }
- }
-
- return out;
- }
- //! @}
|