123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737 |
- // 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 SpBase
- //! @{
- template<typename elem_type, typename derived>
- arma_inline
- const derived&
- SpBase<elem_type,derived>::get_ref() const
- {
- return static_cast<const derived&>(*this);
- }
- template<typename elem_type, typename derived>
- arma_inline
- bool
- SpBase<elem_type,derived>::is_alias(const SpMat<elem_type>& X) const
- {
- return (*this).get_ref().is_alias(X);
- }
- template<typename elem_type, typename derived>
- inline
- const SpOp<derived, spop_htrans>
- SpBase<elem_type,derived>::t() const
- {
- return SpOp<derived,spop_htrans>( (*this).get_ref() );
- }
- template<typename elem_type, typename derived>
- inline
- const SpOp<derived, spop_htrans>
- SpBase<elem_type,derived>::ht() const
- {
- return SpOp<derived, spop_htrans>( (*this).get_ref() );
- }
- template<typename elem_type, typename derived>
- inline
- const SpOp<derived, spop_strans>
- SpBase<elem_type,derived>::st() const
- {
- return SpOp<derived, spop_strans>( (*this).get_ref() );
- }
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type,derived>::print(const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- tmp.M.impl_print(extra_text);
- }
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type,derived>::print(std::ostream& user_stream, const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- tmp.M.impl_print(user_stream, extra_text);
- }
-
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type,derived>::raw_print(const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- tmp.M.impl_raw_print(extra_text);
- }
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type,derived>::raw_print(std::ostream& user_stream, const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- tmp.M.impl_raw_print(user_stream, extra_text);
- }
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type, derived>::print_dense(const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
- tmp.M.impl_print_dense(extra_text);
- }
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type, derived>::print_dense(std::ostream& user_stream, const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
- tmp.M.impl_print_dense(user_stream, extra_text);
- }
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type, derived>::raw_print_dense(const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
- tmp.M.impl_raw_print_dense(extra_text);
- }
- template<typename elem_type, typename derived>
- arma_cold
- inline
- void
- SpBase<elem_type, derived>::raw_print_dense(std::ostream& user_stream, const std::string extra_text) const
- {
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
- tmp.M.impl_raw_print_dense(user_stream, extra_text);
- }
- //
- // extra functions defined in SpBase_eval_SpMat
- template<typename elem_type, typename derived>
- inline
- const derived&
- SpBase_eval_SpMat<elem_type, derived>::eval() const
- {
- arma_extra_debug_sigprint();
-
- return static_cast<const derived&>(*this);
- }
- //
- // extra functions defined in SpBase_eval_expr
- template<typename elem_type, typename derived>
- inline
- SpMat<elem_type>
- SpBase_eval_expr<elem_type, derived>::eval() const
- {
- arma_extra_debug_sigprint();
-
- return SpMat<elem_type>( static_cast<const derived&>(*this) );
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- elem_type
- SpBase<elem_type, derived>::min() const
- {
- return spop_min::min( (*this).get_ref() );
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- elem_type
- SpBase<elem_type, derived>::max() const
- {
- return spop_max::max( (*this).get_ref() );
- }
- template<typename elem_type, typename derived>
- inline
- elem_type
- SpBase<elem_type, derived>::min(uword& index_of_min_val) const
- {
- const SpProxy<derived> P( (*this).get_ref() );
-
- return spop_min::min_with_index(P, index_of_min_val);
- }
- template<typename elem_type, typename derived>
- inline
- elem_type
- SpBase<elem_type, derived>::max(uword& index_of_max_val) const
- {
- const SpProxy<derived> P( (*this).get_ref() );
-
- return spop_max::max_with_index(P, index_of_max_val);
- }
- template<typename elem_type, typename derived>
- inline
- elem_type
- SpBase<elem_type, derived>::min(uword& row_of_min_val, uword& col_of_min_val) const
- {
- const SpProxy<derived> P( (*this).get_ref() );
-
- uword index = 0;
-
- const elem_type val = spop_min::min_with_index(P, index);
-
- const uword local_n_rows = P.get_n_rows();
-
- row_of_min_val = index % local_n_rows;
- col_of_min_val = index / local_n_rows;
-
- return val;
- }
- template<typename elem_type, typename derived>
- inline
- elem_type
- SpBase<elem_type, derived>::max(uword& row_of_max_val, uword& col_of_max_val) const
- {
- const SpProxy<derived> P( (*this).get_ref() );
-
- uword index = 0;
-
- const elem_type val = spop_max::max_with_index(P, index);
-
- const uword local_n_rows = P.get_n_rows();
-
- row_of_max_val = index % local_n_rows;
- col_of_max_val = index / local_n_rows;
-
- return val;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- uword
- SpBase<elem_type,derived>::index_min() const
- {
- const SpProxy<derived> P( (*this).get_ref() );
-
- uword index = 0;
-
- if(P.get_n_elem() == 0)
- {
- arma_debug_check(true, "index_min(): object has no elements");
- }
- else
- {
- spop_min::min_with_index(P, index);
- }
-
- return index;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- uword
- SpBase<elem_type,derived>::index_max() const
- {
- const SpProxy<derived> P( (*this).get_ref() );
-
- uword index = 0;
-
- if(P.get_n_elem() == 0)
- {
- arma_debug_check(true, "index_max(): object has no elements");
- }
- else
- {
- spop_max::max_with_index(P, index);
- }
-
- return index;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_symmetric() const
- {
- arma_extra_debug_sigprint();
-
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- return tmp.M.is_symmetric();
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_symmetric(const typename get_pod_type<elem_type>::result tol) const
- {
- arma_extra_debug_sigprint();
-
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- return tmp.M.is_symmetric(tol);
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_hermitian() const
- {
- arma_extra_debug_sigprint();
-
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- return tmp.M.is_hermitian();
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_hermitian(const typename get_pod_type<elem_type>::result tol) const
- {
- arma_extra_debug_sigprint();
-
- const unwrap_spmat<derived> tmp( (*this).get_ref() );
-
- return tmp.M.is_hermitian(tol);
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_zero(const typename get_pod_type<elem_type>::result tol) const
- {
- arma_extra_debug_sigprint();
-
- typedef typename get_pod_type<elem_type>::result T;
-
- arma_debug_check( (tol < T(0)), "is_zero(): parameter 'tol' must be >= 0" );
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- if(P.get_n_elem() == 0) { return false; }
-
- if(P.get_n_nonzero() == 0) { return true; }
-
- if(is_SpMat<typename SpProxy<derived>::stored_type>::value)
- {
- const unwrap_spmat<typename SpProxy<derived>::stored_type> U(P.Q);
-
- return arrayops::is_zero(U.M.values, U.M.n_nonzero, tol);
- }
-
- typename SpProxy<derived>::const_iterator_type it = P.begin();
- typename SpProxy<derived>::const_iterator_type it_end = P.end();
-
- if(is_cx<elem_type>::yes)
- {
- while(it != it_end)
- {
- const elem_type val = (*it);
-
- const T val_real = access::tmp_real(val);
- const T val_imag = access::tmp_imag(val);
-
- if(eop_aux::arma_abs(val_real) > tol) { return false; }
- if(eop_aux::arma_abs(val_imag) > tol) { return false; }
-
- ++it;
- }
- }
- else // not complex
- {
- while(it != it_end)
- {
- if(eop_aux::arma_abs(*it) > tol) { return false; }
-
- ++it;
- }
- }
-
- return true;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_trimatu() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- if(P.get_n_rows() != P.get_n_cols()) { return false; }
-
- typename SpProxy<derived>::const_iterator_type it = P.begin();
- typename SpProxy<derived>::const_iterator_type it_end = P.end();
-
- while(it != it_end)
- {
- if(it.row() > it.col()) { return false; }
- ++it;
- }
-
- return true;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_trimatl() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- if(P.get_n_rows() != P.get_n_cols()) { return false; }
-
- typename SpProxy<derived>::const_iterator_type it = P.begin();
- typename SpProxy<derived>::const_iterator_type it_end = P.end();
-
- while(it != it_end)
- {
- if(it.row() < it.col()) { return false; }
- ++it;
- }
-
- return true;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_diagmat() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- typename SpProxy<derived>::const_iterator_type it = P.begin();
- typename SpProxy<derived>::const_iterator_type it_end = P.end();
-
- while(it != it_end)
- {
- if(it.row() != it.col()) { return false; }
- ++it;
- }
-
- return true;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_empty() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- return (P.get_n_elem() == uword(0));
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_square() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- return (P.get_n_rows() == P.get_n_cols());
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_vec() const
- {
- arma_extra_debug_sigprint();
-
- if( (SpProxy<derived>::is_row) || (SpProxy<derived>::is_col) || (SpProxy<derived>::is_xvec) ) { return true; }
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- return ( (P.get_n_rows() == uword(1)) || (P.get_n_cols() == uword(1)) );
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_colvec() const
- {
- arma_extra_debug_sigprint();
-
- if(SpProxy<derived>::is_col) { return true; }
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- return (P.get_n_cols() == uword(1));
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_rowvec() const
- {
- arma_extra_debug_sigprint();
-
- if(SpProxy<derived>::is_row) { return true; }
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- return (P.get_n_rows() == uword(1));
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::is_finite() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- if(is_SpMat<typename SpProxy<derived>::stored_type>::value)
- {
- const unwrap_spmat<typename SpProxy<derived>::stored_type> U(P.Q);
-
- return U.M.is_finite();
- }
- else
- {
- typename SpProxy<derived>::const_iterator_type it = P.begin();
- typename SpProxy<derived>::const_iterator_type it_end = P.end();
-
- while(it != it_end)
- {
- if(arma_isfinite(*it) == false) { return false; }
- ++it;
- }
- }
-
- return true;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::has_inf() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- if(is_SpMat<typename SpProxy<derived>::stored_type>::value)
- {
- const unwrap_spmat<typename SpProxy<derived>::stored_type> U(P.Q);
-
- return U.M.has_inf();
- }
- else
- {
- typename SpProxy<derived>::const_iterator_type it = P.begin();
- typename SpProxy<derived>::const_iterator_type it_end = P.end();
-
- while(it != it_end)
- {
- if(arma_isinf(*it)) { return true; }
- ++it;
- }
- }
-
- return false;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- bool
- SpBase<elem_type,derived>::has_nan() const
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<derived> P( (*this).get_ref() );
-
- if(is_SpMat<typename SpProxy<derived>::stored_type>::value)
- {
- const unwrap_spmat<typename SpProxy<derived>::stored_type> U(P.Q);
-
- return U.M.has_nan();
- }
- else
- {
- typename SpProxy<derived>::const_iterator_type it = P.begin();
- typename SpProxy<derived>::const_iterator_type it_end = P.end();
-
- while(it != it_end)
- {
- if(arma_isnan(*it)) { return true; }
- ++it;
- }
- }
-
- return false;
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- const SpOp<derived,spop_vectorise_col>
- SpBase<elem_type, derived>::as_col() const
- {
- return SpOp<derived,spop_vectorise_col>( (*this).get_ref() );
- }
- template<typename elem_type, typename derived>
- inline
- arma_warn_unused
- const SpOp<derived,spop_vectorise_row>
- SpBase<elem_type, derived>::as_row() const
- {
- return SpOp<derived,spop_vectorise_row>( (*this).get_ref() );
- }
- //! @}
|