123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985 |
- // 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 diagview
- //! @{
- template<typename eT>
- inline
- diagview<eT>::~diagview()
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- arma_inline
- diagview<eT>::diagview(const Mat<eT>& in_m, const uword in_row_offset, const uword in_col_offset, const uword in_len)
- : m(in_m)
- , row_offset(in_row_offset)
- , col_offset(in_col_offset)
- , n_rows(in_len)
- , n_elem(in_len)
- {
- arma_extra_debug_sigprint();
- }
- //! set a diagonal of our matrix using a diagonal from a foreign matrix
- template<typename eT>
- inline
- void
- diagview<eT>::operator= (const diagview<eT>& x)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>& d = *this;
-
- arma_debug_check( (d.n_elem != x.n_elem), "diagview: diagonals have incompatible lengths");
-
- Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m);
- const Mat<eT>& x_m = x.m;
-
- if(&d_m != &x_m)
- {
- const uword d_n_elem = d.n_elem;
- const uword d_row_offset = d.row_offset;
- const uword d_col_offset = d.col_offset;
-
- const uword x_row_offset = x.row_offset;
- const uword x_col_offset = x.col_offset;
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = x_m.at(ii + x_row_offset, ii + x_col_offset);
- const eT tmp_j = x_m.at(jj + x_row_offset, jj + x_col_offset);
-
- d_m.at(ii + d_row_offset, ii + d_col_offset) = tmp_i;
- d_m.at(jj + d_row_offset, jj + d_col_offset) = tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at(ii + d_row_offset, ii + d_col_offset) = x_m.at(ii + x_row_offset, ii + x_col_offset);
- }
- }
- else
- {
- const Mat<eT> tmp = x;
-
- (*this).operator=(tmp);
- }
- }
- template<typename eT>
- inline
- void
- diagview<eT>::operator+=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& t_m = const_cast< Mat<eT>& >(m);
-
- const uword t_n_elem = n_elem;
- const uword t_row_offset = row_offset;
- const uword t_col_offset = col_offset;
-
- for(uword ii=0; ii < t_n_elem; ++ii)
- {
- t_m.at( ii + t_row_offset, ii + t_col_offset) += val;
- }
- }
- template<typename eT>
- inline
- void
- diagview<eT>::operator-=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& t_m = const_cast< Mat<eT>& >(m);
-
- const uword t_n_elem = n_elem;
- const uword t_row_offset = row_offset;
- const uword t_col_offset = col_offset;
-
- for(uword ii=0; ii < t_n_elem; ++ii)
- {
- t_m.at( ii + t_row_offset, ii + t_col_offset) -= val;
- }
- }
- template<typename eT>
- inline
- void
- diagview<eT>::operator*=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& t_m = const_cast< Mat<eT>& >(m);
-
- const uword t_n_elem = n_elem;
- const uword t_row_offset = row_offset;
- const uword t_col_offset = col_offset;
-
- for(uword ii=0; ii < t_n_elem; ++ii)
- {
- t_m.at( ii + t_row_offset, ii + t_col_offset) *= val;
- }
- }
- template<typename eT>
- inline
- void
- diagview<eT>::operator/=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& t_m = const_cast< Mat<eT>& >(m);
-
- const uword t_n_elem = n_elem;
- const uword t_row_offset = row_offset;
- const uword t_col_offset = col_offset;
-
- for(uword ii=0; ii < t_n_elem; ++ii)
- {
- t_m.at( ii + t_row_offset, ii + t_col_offset) /= val;
- }
- }
- //! set a diagonal of our matrix using data from a foreign object
- template<typename eT>
- template<typename T1>
- inline
- void
- diagview<eT>::operator= (const Base<eT,T1>& o)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>& d = *this;
-
- Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m);
-
- const uword d_n_elem = d.n_elem;
- const uword d_row_offset = d.row_offset;
- const uword d_col_offset = d.col_offset;
-
- const Proxy<T1> P( o.get_ref() );
-
- arma_debug_check
- (
- ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ),
- "diagview: given object has incompatible size"
- );
-
- const bool is_alias = P.is_alias(d_m);
-
- if(is_alias) { arma_extra_debug_print("aliasing detected"); }
-
- if( (is_Mat<typename Proxy<T1>::stored_type>::value) || (Proxy<T1>::use_at) || (is_alias) )
- {
- const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias);
- const Mat<eT>& x = tmp.M;
-
- const eT* x_mem = x.memptr();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = x_mem[ii];
- const eT tmp_j = x_mem[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) = tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) = tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) = x_mem[ii];
- }
- }
- else
- {
- typename Proxy<T1>::ea_type Pea = P.get_ea();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = Pea[ii];
- const eT tmp_j = Pea[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) = tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) = tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) = Pea[ii];
- }
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- diagview<eT>::operator+=(const Base<eT,T1>& o)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>& d = *this;
-
- Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m);
-
- const uword d_n_elem = d.n_elem;
- const uword d_row_offset = d.row_offset;
- const uword d_col_offset = d.col_offset;
-
- const Proxy<T1> P( o.get_ref() );
-
- arma_debug_check
- (
- ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ),
- "diagview: given object has incompatible size"
- );
-
- const bool is_alias = P.is_alias(d_m);
-
- if(is_alias) { arma_extra_debug_print("aliasing detected"); }
-
- if( (is_Mat<typename Proxy<T1>::stored_type>::value) || (Proxy<T1>::use_at) || (is_alias) )
- {
- const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias);
- const Mat<eT>& x = tmp.M;
-
- const eT* x_mem = x.memptr();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = x_mem[ii];
- const eT tmp_j = x_mem[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) += tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) += tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) += x_mem[ii];
- }
- }
- else
- {
- typename Proxy<T1>::ea_type Pea = P.get_ea();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = Pea[ii];
- const eT tmp_j = Pea[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) += tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) += tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) += Pea[ii];
- }
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- diagview<eT>::operator-=(const Base<eT,T1>& o)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>& d = *this;
-
- Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m);
-
- const uword d_n_elem = d.n_elem;
- const uword d_row_offset = d.row_offset;
- const uword d_col_offset = d.col_offset;
-
- const Proxy<T1> P( o.get_ref() );
-
- arma_debug_check
- (
- ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ),
- "diagview: given object has incompatible size"
- );
-
- const bool is_alias = P.is_alias(d_m);
-
- if(is_alias) { arma_extra_debug_print("aliasing detected"); }
-
- if( (is_Mat<typename Proxy<T1>::stored_type>::value) || (Proxy<T1>::use_at) || (is_alias) )
- {
- const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias);
- const Mat<eT>& x = tmp.M;
-
- const eT* x_mem = x.memptr();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = x_mem[ii];
- const eT tmp_j = x_mem[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) -= tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) -= tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) -= x_mem[ii];
- }
- }
- else
- {
- typename Proxy<T1>::ea_type Pea = P.get_ea();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = Pea[ii];
- const eT tmp_j = Pea[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) -= tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) -= tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) -= Pea[ii];
- }
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- diagview<eT>::operator%=(const Base<eT,T1>& o)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>& d = *this;
-
- Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m);
-
- const uword d_n_elem = d.n_elem;
- const uword d_row_offset = d.row_offset;
- const uword d_col_offset = d.col_offset;
-
- const Proxy<T1> P( o.get_ref() );
-
- arma_debug_check
- (
- ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ),
- "diagview: given object has incompatible size"
- );
-
- const bool is_alias = P.is_alias(d_m);
-
- if(is_alias) { arma_extra_debug_print("aliasing detected"); }
-
- if( (is_Mat<typename Proxy<T1>::stored_type>::value) || (Proxy<T1>::use_at) || (is_alias) )
- {
- const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias);
- const Mat<eT>& x = tmp.M;
-
- const eT* x_mem = x.memptr();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = x_mem[ii];
- const eT tmp_j = x_mem[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) *= tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) *= tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) *= x_mem[ii];
- }
- }
- else
- {
- typename Proxy<T1>::ea_type Pea = P.get_ea();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = Pea[ii];
- const eT tmp_j = Pea[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) *= tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) *= tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) *= Pea[ii];
- }
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- diagview<eT>::operator/=(const Base<eT,T1>& o)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>& d = *this;
-
- Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m);
-
- const uword d_n_elem = d.n_elem;
- const uword d_row_offset = d.row_offset;
- const uword d_col_offset = d.col_offset;
-
- const Proxy<T1> P( o.get_ref() );
-
- arma_debug_check
- (
- ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ),
- "diagview: given object has incompatible size"
- );
-
- const bool is_alias = P.is_alias(d_m);
-
- if(is_alias) { arma_extra_debug_print("aliasing detected"); }
-
- if( (is_Mat<typename Proxy<T1>::stored_type>::value) || (Proxy<T1>::use_at) || (is_alias) )
- {
- const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias);
- const Mat<eT>& x = tmp.M;
-
- const eT* x_mem = x.memptr();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = x_mem[ii];
- const eT tmp_j = x_mem[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) /= x_mem[ii];
- }
- }
- else
- {
- typename Proxy<T1>::ea_type Pea = P.get_ea();
-
- uword ii,jj;
- for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2)
- {
- const eT tmp_i = Pea[ii];
- const eT tmp_j = Pea[jj];
-
- d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i;
- d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j;
- }
-
- if(ii < d_n_elem)
- {
- d_m.at( ii + d_row_offset, ii + d_col_offset) /= Pea[ii];
- }
- }
- }
- //! extract a diagonal and store it as a column vector
- template<typename eT>
- inline
- void
- diagview<eT>::extract(Mat<eT>& out, const diagview<eT>& in)
- {
- arma_extra_debug_sigprint();
-
- // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing;
- // size setting and alias checking is done by either the Mat contructor or operator=()
-
- const Mat<eT>& in_m = in.m;
-
- const uword in_n_elem = in.n_elem;
- const uword in_row_offset = in.row_offset;
- const uword in_col_offset = in.col_offset;
-
- eT* out_mem = out.memptr();
-
- uword i,j;
- for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
- {
- const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
- const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
-
- out_mem[i] = tmp_i;
- out_mem[j] = tmp_j;
- }
-
- if(i < in_n_elem)
- {
- out_mem[i] = in_m.at( i + in_row_offset, i + in_col_offset );
- }
- }
- //! X += Y.diag()
- template<typename eT>
- inline
- void
- diagview<eT>::plus_inplace(Mat<eT>& out, const diagview<eT>& in)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "addition");
-
- const Mat<eT>& in_m = in.m;
-
- const uword in_n_elem = in.n_elem;
- const uword in_row_offset = in.row_offset;
- const uword in_col_offset = in.col_offset;
-
- eT* out_mem = out.memptr();
-
- uword i,j;
- for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
- {
- const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
- const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
-
- out_mem[i] += tmp_i;
- out_mem[j] += tmp_j;
- }
-
- if(i < in_n_elem)
- {
- out_mem[i] += in_m.at( i + in_row_offset, i + in_col_offset );
- }
- }
- //! X -= Y.diag()
- template<typename eT>
- inline
- void
- diagview<eT>::minus_inplace(Mat<eT>& out, const diagview<eT>& in)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "subtraction");
-
- const Mat<eT>& in_m = in.m;
-
- const uword in_n_elem = in.n_elem;
- const uword in_row_offset = in.row_offset;
- const uword in_col_offset = in.col_offset;
-
- eT* out_mem = out.memptr();
-
- uword i,j;
- for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
- {
- const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
- const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
-
- out_mem[i] -= tmp_i;
- out_mem[j] -= tmp_j;
- }
-
- if(i < in_n_elem)
- {
- out_mem[i] -= in_m.at( i + in_row_offset, i + in_col_offset );
- }
- }
- //! X %= Y.diag()
- template<typename eT>
- inline
- void
- diagview<eT>::schur_inplace(Mat<eT>& out, const diagview<eT>& in)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise multiplication");
-
- const Mat<eT>& in_m = in.m;
-
- const uword in_n_elem = in.n_elem;
- const uword in_row_offset = in.row_offset;
- const uword in_col_offset = in.col_offset;
-
- eT* out_mem = out.memptr();
-
- uword i,j;
- for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
- {
- const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
- const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
-
- out_mem[i] *= tmp_i;
- out_mem[j] *= tmp_j;
- }
-
- if(i < in_n_elem)
- {
- out_mem[i] *= in_m.at( i + in_row_offset, i + in_col_offset );
- }
- }
- //! X /= Y.diag()
- template<typename eT>
- inline
- void
- diagview<eT>::div_inplace(Mat<eT>& out, const diagview<eT>& in)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise division");
-
- const Mat<eT>& in_m = in.m;
-
- const uword in_n_elem = in.n_elem;
- const uword in_row_offset = in.row_offset;
- const uword in_col_offset = in.col_offset;
-
- eT* out_mem = out.memptr();
-
- uword i,j;
- for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
- {
- const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset );
- const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset );
-
- out_mem[i] /= tmp_i;
- out_mem[j] /= tmp_j;
- }
-
- if(i < in_n_elem)
- {
- out_mem[i] /= in_m.at( i + in_row_offset, i + in_col_offset );
- }
- }
- template<typename eT>
- arma_inline
- eT
- diagview<eT>::at_alt(const uword ii) const
- {
- return m.at(ii+row_offset, ii+col_offset);
- }
- template<typename eT>
- arma_inline
- eT&
- diagview<eT>::operator[](const uword ii)
- {
- return (const_cast< Mat<eT>& >(m)).at(ii+row_offset, ii+col_offset);
- }
- template<typename eT>
- arma_inline
- eT
- diagview<eT>::operator[](const uword ii) const
- {
- return m.at(ii+row_offset, ii+col_offset);
- }
- template<typename eT>
- arma_inline
- eT&
- diagview<eT>::at(const uword ii)
- {
- return (const_cast< Mat<eT>& >(m)).at(ii+row_offset, ii+col_offset);
- }
- template<typename eT>
- arma_inline
- eT
- diagview<eT>::at(const uword ii) const
- {
- return m.at(ii+row_offset, ii+col_offset);
- }
- template<typename eT>
- arma_inline
- eT&
- diagview<eT>::operator()(const uword ii)
- {
- arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" );
-
- return (const_cast< Mat<eT>& >(m)).at(ii+row_offset, ii+col_offset);
- }
- template<typename eT>
- arma_inline
- eT
- diagview<eT>::operator()(const uword ii) const
- {
- arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" );
-
- return m.at(ii+row_offset, ii+col_offset);
- }
- template<typename eT>
- arma_inline
- eT&
- diagview<eT>::at(const uword row, const uword)
- {
- return (const_cast< Mat<eT>& >(m)).at(row+row_offset, row+col_offset);
- }
- template<typename eT>
- arma_inline
- eT
- diagview<eT>::at(const uword row, const uword) const
- {
- return m.at(row+row_offset, row+col_offset);
- }
- template<typename eT>
- arma_inline
- eT&
- diagview<eT>::operator()(const uword row, const uword col)
- {
- arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" );
-
- return (const_cast< Mat<eT>& >(m)).at(row+row_offset, row+col_offset);
- }
- template<typename eT>
- arma_inline
- eT
- diagview<eT>::operator()(const uword row, const uword col) const
- {
- arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" );
-
- return m.at(row+row_offset, row+col_offset);
- }
- template<typename eT>
- arma_inline
- const Op<diagview<eT>,op_htrans>
- diagview<eT>::t() const
- {
- return Op<diagview<eT>,op_htrans>(*this);
- }
- template<typename eT>
- arma_inline
- const Op<diagview<eT>,op_htrans>
- diagview<eT>::ht() const
- {
- return Op<diagview<eT>,op_htrans>(*this);
- }
- template<typename eT>
- arma_inline
- const Op<diagview<eT>,op_strans>
- diagview<eT>::st() const
- {
- return Op<diagview<eT>,op_strans>(*this);
- }
- template<typename eT>
- inline
- void
- diagview<eT>::replace(const eT old_val, const eT new_val)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& x = const_cast< Mat<eT>& >(m);
-
- const uword local_n_elem = n_elem;
-
- if(arma_isnan(old_val))
- {
- for(uword ii=0; ii < local_n_elem; ++ii)
- {
- eT& val = x.at(ii+row_offset, ii+col_offset);
-
- val = (arma_isnan(val)) ? new_val : val;
- }
- }
- else
- {
- for(uword ii=0; ii < local_n_elem; ++ii)
- {
- eT& val = x.at(ii+row_offset, ii+col_offset);
-
- val = (val == old_val) ? new_val : val;
- }
- }
- }
- template<typename eT>
- inline
- void
- diagview<eT>::fill(const eT val)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& x = const_cast< Mat<eT>& >(m);
-
- const uword local_n_elem = n_elem;
-
- for(uword ii=0; ii < local_n_elem; ++ii)
- {
- x.at(ii+row_offset, ii+col_offset) = val;
- }
- }
- template<typename eT>
- inline
- void
- diagview<eT>::zeros()
- {
- arma_extra_debug_sigprint();
-
- (*this).fill(eT(0));
- }
- template<typename eT>
- inline
- void
- diagview<eT>::ones()
- {
- arma_extra_debug_sigprint();
-
- (*this).fill(eT(1));
- }
- template<typename eT>
- inline
- void
- diagview<eT>::randu()
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& x = const_cast< Mat<eT>& >(m);
-
- const uword local_n_elem = n_elem;
-
- for(uword ii=0; ii < local_n_elem; ++ii)
- {
- x.at(ii+row_offset, ii+col_offset) = eT(arma_rng::randu<eT>());
- }
- }
- template<typename eT>
- inline
- void
- diagview<eT>::randn()
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& x = const_cast< Mat<eT>& >(m);
-
- const uword local_n_elem = n_elem;
-
- for(uword ii=0; ii < local_n_elem; ++ii)
- {
- x.at(ii+row_offset, ii+col_offset) = eT(arma_rng::randn<eT>());
- }
- }
- //! @}
|