123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- // 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 SpCol
- //! @{
- template<typename eT>
- inline
- SpCol<eT>::SpCol()
- : SpMat<eT>(arma_vec_indicator(), 1)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- SpCol<eT>::SpCol(const uword in_n_elem)
- : SpMat<eT>(arma_vec_indicator(), in_n_elem, 1, 1)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- SpCol<eT>::SpCol(const uword in_n_rows, const uword in_n_cols)
- : SpMat<eT>(arma_vec_indicator(), in_n_rows, in_n_cols, 1)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- SpCol<eT>::SpCol(const SizeMat& s)
- : SpMat<eT>(arma_vec_indicator(), 0, 0, 1)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::init(s.n_rows, s.n_cols);
- }
- template<typename eT>
- inline
- SpCol<eT>::SpCol(const char* text)
- : SpMat<eT>(arma_vec_indicator(), 1)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::init(std::string(text));
- }
- template<typename eT>
- inline
- SpCol<eT>&
- SpCol<eT>::operator=(const char* text)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::init(std::string(text));
-
- return *this;
- }
- template<typename eT>
- inline
- SpCol<eT>::SpCol(const std::string& text)
- : SpMat<eT>(arma_vec_indicator(), 1)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::init(text);
- }
- template<typename eT>
- inline
- SpCol<eT>&
- SpCol<eT>::operator=(const std::string& text)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::init(text);
-
- return *this;
- }
- template<typename eT>
- inline
- SpCol<eT>&
- SpCol<eT>::operator=(const eT val)
- {
- arma_extra_debug_sigprint();
- SpMat<eT>::operator=(val);
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- SpCol<eT>::SpCol(const Base<eT,T1>& X)
- : SpMat<eT>(arma_vec_indicator(), 1)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::operator=(X.get_ref());
- }
- template<typename eT>
- template<typename T1>
- inline
- SpCol<eT>&
- SpCol<eT>::operator=(const Base<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::operator=(X.get_ref());
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- SpCol<eT>::SpCol(const SpBase<eT,T1>& X)
- : SpMat<eT>(arma_vec_indicator(), 1)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::operator=(X.get_ref());
- }
- template<typename eT>
- template<typename T1>
- inline
- SpCol<eT>&
- SpCol<eT>::operator=(const SpBase<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::operator=(X.get_ref());
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- SpCol<eT>::SpCol
- (
- const SpBase<typename SpCol<eT>::pod_type, T1>& A,
- const SpBase<typename SpCol<eT>::pod_type, T2>& B
- )
- : SpMat<eT>(arma_vec_indicator(), 1)
- {
- arma_extra_debug_sigprint();
-
- SpMat<eT>::init(A,B);
- }
- template<typename eT>
- inline
- const SpOp<SpCol<eT>,spop_htrans>
- SpCol<eT>::t() const
- {
- return SpOp<SpCol<eT>,spop_htrans>(*this);
- }
- template<typename eT>
- inline
- const SpOp<SpCol<eT>,spop_htrans>
- SpCol<eT>::ht() const
- {
- return SpOp<SpCol<eT>,spop_htrans>(*this);
- }
- template<typename eT>
- inline
- const SpOp<SpCol<eT>,spop_strans>
- SpCol<eT>::st() const
- {
- return SpOp<SpCol<eT>,spop_strans>(*this);
- }
- //! remove specified row
- template<typename eT>
- inline
- void
- SpCol<eT>::shed_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
- arma_debug_check( row_num >= SpMat<eT>::n_rows, "SpCol::shed_row(): out of bounds");
-
- shed_rows(row_num, row_num);
- }
- //! remove specified rows
- template<typename eT>
- inline
- void
- SpCol<eT>::shed_rows(const uword in_row1, const uword in_row2)
- {
- arma_extra_debug_sigprint();
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_row2 >= SpMat<eT>::n_rows),
- "SpCol::shed_rows(): indices out of bounds or incorrectly used"
- );
-
- SpMat<eT>::sync_csc();
-
- const uword diff = (in_row2 - in_row1 + 1);
- // This is easy because everything is in one column.
- uword start = 0, end = 0;
- bool start_found = false, end_found = false;
- for(uword i = 0; i < SpMat<eT>::n_nonzero; ++i)
- {
- // Start position found?
- if (SpMat<eT>::row_indices[i] >= in_row1 && !start_found)
- {
- start = i;
- start_found = true;
- }
- // End position found?
- if (SpMat<eT>::row_indices[i] > in_row2)
- {
- end = i;
- end_found = true;
- break;
- }
- }
- if (!end_found)
- {
- end = SpMat<eT>::n_nonzero;
- }
- // Now we can make the copy.
- if (start != end)
- {
- const uword elem_diff = end - start;
- eT* new_values = memory::acquire<eT> (SpMat<eT>::n_nonzero - elem_diff);
- uword* new_row_indices = memory::acquire<uword>(SpMat<eT>::n_nonzero - elem_diff);
- // Copy before the section we are dropping (if it exists).
- if (start > 0)
- {
- arrayops::copy(new_values, SpMat<eT>::values, start);
- arrayops::copy(new_row_indices, SpMat<eT>::row_indices, start);
- }
- // Copy after the section we are dropping (if it exists).
- if (end != SpMat<eT>::n_nonzero)
- {
- arrayops::copy(new_values + start, SpMat<eT>::values + end, (SpMat<eT>::n_nonzero - end));
- arrayops::copy(new_row_indices + start, SpMat<eT>::row_indices + end, (SpMat<eT>::n_nonzero - end));
- arrayops::inplace_minus(new_row_indices + start, diff, (SpMat<eT>::n_nonzero - end));
- }
- memory::release(SpMat<eT>::values);
- memory::release(SpMat<eT>::row_indices);
- access::rw(SpMat<eT>::values) = new_values;
- access::rw(SpMat<eT>::row_indices) = new_row_indices;
- access::rw(SpMat<eT>::n_nonzero) -= elem_diff;
- access::rw(SpMat<eT>::col_ptrs[1]) -= elem_diff;
- }
- access::rw(SpMat<eT>::n_rows) -= diff;
- access::rw(SpMat<eT>::n_elem) -= diff;
-
- SpMat<eT>::invalidate_cache();
- }
- // //! insert N rows at the specified row position,
- // //! optionally setting the elements of the inserted rows to zero
- // template<typename eT>
- // inline
- // void
- // SpCol<eT>::insert_rows(const uword row_num, const uword N, const bool set_to_zero)
- // {
- // arma_extra_debug_sigprint();
- //
- // arma_debug_check(set_to_zero == false, "SpCol::insert_rows(): cannot set nonzero values");
- //
- // arma_debug_check((row_num > SpMat<eT>::n_rows), "SpCol::insert_rows(): out of bounds");
- //
- // for(uword row = 0; row < SpMat<eT>::n_rows; ++row)
- // {
- // if (SpMat<eT>::row_indices[row] >= row_num)
- // {
- // access::rw(SpMat<eT>::row_indices[row]) += N;
- // }
- // }
- //
- // access::rw(SpMat<eT>::n_rows) += N;
- // access::rw(SpMat<eT>::n_elem) += N;
- // }
- template<typename eT>
- inline
- typename SpCol<eT>::row_iterator
- SpCol<eT>::begin_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= SpMat<eT>::n_rows), "SpCol::begin_row(): index out of bounds");
-
- SpMat<eT>::sync_csc();
-
- return row_iterator(*this, row_num, 0);
- }
- template<typename eT>
- inline
- typename SpCol<eT>::const_row_iterator
- SpCol<eT>::begin_row(const uword row_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= SpMat<eT>::n_rows), "SpCol::begin_row(): index out of bounds");
-
- SpMat<eT>::sync_csc();
-
- return const_row_iterator(*this, row_num, 0);
- }
- template<typename eT>
- inline
- typename SpCol<eT>::row_iterator
- SpCol<eT>::end_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= SpMat<eT>::n_rows), "SpCol::end_row(): index out of bounds");
-
- SpMat<eT>::sync_csc();
-
- return row_iterator(*this, row_num + 1, 0);
- }
- template<typename eT>
- inline
- typename SpCol<eT>::const_row_iterator
- SpCol<eT>::end_row(const uword row_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= SpMat<eT>::n_rows), "SpCol::end_row(): index out of bounds");
-
- SpMat<eT>::sync_csc();
-
- return const_row_iterator(*this, row_num + 1, 0);
- }
- #ifdef ARMA_EXTRA_SPCOL_MEAT
- #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPCOL_MEAT)
- #endif
- //! @}
|