From eda5bc26f44ee9a6f83dcf8c91f17296d7fc509d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 12 Feb 2024 14:52:43 +0100 Subject: Move into version control --- .../include/armadillo_bits/SpCol_meat.hpp | 432 +++++++++++++++++++++ 1 file changed, 432 insertions(+) create mode 100644 src/armadillo/include/armadillo_bits/SpCol_meat.hpp (limited to 'src/armadillo/include/armadillo_bits/SpCol_meat.hpp') diff --git a/src/armadillo/include/armadillo_bits/SpCol_meat.hpp b/src/armadillo/include/armadillo_bits/SpCol_meat.hpp new file mode 100644 index 0000000..9b3c824 --- /dev/null +++ b/src/armadillo/include/armadillo_bits/SpCol_meat.hpp @@ -0,0 +1,432 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// 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 +inline +SpCol::SpCol() + : SpMat(arma_vec_indicator(), 1) + { + arma_extra_debug_sigprint(); + } + + + +template +inline +SpCol::SpCol(const uword in_n_elem) + : SpMat(arma_vec_indicator(), in_n_elem, 1, 1) + { + arma_extra_debug_sigprint(); + } + + + +template +inline +SpCol::SpCol(const uword in_n_rows, const uword in_n_cols) + : SpMat(arma_vec_indicator(), in_n_rows, in_n_cols, 1) + { + arma_extra_debug_sigprint(); + } + + + +template +inline +SpCol::SpCol(const SizeMat& s) + : SpMat(arma_vec_indicator(), 0, 0, 1) + { + arma_extra_debug_sigprint(); + + SpMat::init(s.n_rows, s.n_cols); + } + + + +template +inline +SpCol::SpCol(const char* text) + : SpMat(arma_vec_indicator(), 1) + { + arma_extra_debug_sigprint(); + + SpMat::init(std::string(text)); + } + + + +template +inline +SpCol& +SpCol::operator=(const char* text) + { + arma_extra_debug_sigprint(); + + SpMat::init(std::string(text)); + + return *this; + } + + + +template +inline +SpCol::SpCol(const std::string& text) + : SpMat(arma_vec_indicator(), 1) + { + arma_extra_debug_sigprint(); + + SpMat::init(text); + } + + + +template +inline +SpCol& +SpCol::operator=(const std::string& text) + { + arma_extra_debug_sigprint(); + + SpMat::init(text); + + return *this; + } + + + +template +inline +SpCol& +SpCol::operator=(const eT val) + { + arma_extra_debug_sigprint(); + + SpMat::operator=(val); + + return *this; + } + + + +template +template +inline +SpCol::SpCol(const Base& X) + : SpMat(arma_vec_indicator(), 1) + { + arma_extra_debug_sigprint(); + + SpMat::operator=(X.get_ref()); + } + + + +template +template +inline +SpCol& +SpCol::operator=(const Base& X) + { + arma_extra_debug_sigprint(); + + SpMat::operator=(X.get_ref()); + + return *this; + } + + + +template +template +inline +SpCol::SpCol(const SpBase& X) + : SpMat(arma_vec_indicator(), 1) + { + arma_extra_debug_sigprint(); + + SpMat::operator=(X.get_ref()); + } + + + +template +template +inline +SpCol& +SpCol::operator=(const SpBase& X) + { + arma_extra_debug_sigprint(); + + SpMat::operator=(X.get_ref()); + + return *this; + } + + + +template +template +inline +SpCol::SpCol + ( + const SpBase::pod_type, T1>& A, + const SpBase::pod_type, T2>& B + ) + : SpMat(arma_vec_indicator(), 1) + { + arma_extra_debug_sigprint(); + + SpMat::init(A,B); + } + + + +template +inline +const SpOp,spop_htrans> +SpCol::t() const + { + return SpOp,spop_htrans>(*this); + } + + + +template +inline +const SpOp,spop_htrans> +SpCol::ht() const + { + return SpOp,spop_htrans>(*this); + } + + + +template +inline +const SpOp,spop_strans> +SpCol::st() const + { + return SpOp,spop_strans>(*this); + } + + + +//! remove specified row +template +inline +void +SpCol::shed_row(const uword row_num) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( row_num >= SpMat::n_rows, "SpCol::shed_row(): out of bounds" ); + + shed_rows(row_num, row_num); + } + + + +//! remove specified rows +template +inline +void +SpCol::shed_rows(const uword in_row1, const uword in_row2) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds + ( + (in_row1 > in_row2) || (in_row2 >= SpMat::n_rows), + "SpCol::shed_rows(): indices out of bounds or incorrectly used" + ); + + SpMat::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::n_nonzero; ++i) + { + // Start position found? + if(SpMat::row_indices[i] >= in_row1 && !start_found) + { + start = i; + start_found = true; + } + + // End position found? + if(SpMat::row_indices[i] > in_row2) + { + end = i; + end_found = true; + break; + } + } + + if(!end_found) + { + end = SpMat::n_nonzero; + } + + // Now we can make the copy. + if(start != end) + { + const uword elem_diff = end - start; + + eT* new_values = memory::acquire (SpMat::n_nonzero - elem_diff); + uword* new_row_indices = memory::acquire(SpMat::n_nonzero - elem_diff); + + // Copy before the section we are dropping (if it exists). + if(start > 0) + { + arrayops::copy(new_values, SpMat::values, start); + arrayops::copy(new_row_indices, SpMat::row_indices, start); + } + + // Copy after the section we are dropping (if it exists). + if(end != SpMat::n_nonzero) + { + arrayops::copy(new_values + start, SpMat::values + end, (SpMat::n_nonzero - end)); + arrayops::copy(new_row_indices + start, SpMat::row_indices + end, (SpMat::n_nonzero - end)); + arrayops::inplace_minus(new_row_indices + start, diff, (SpMat::n_nonzero - end)); + } + + memory::release(SpMat::values); + memory::release(SpMat::row_indices); + + access::rw(SpMat::values) = new_values; + access::rw(SpMat::row_indices) = new_row_indices; + + access::rw(SpMat::n_nonzero) -= elem_diff; + access::rw(SpMat::col_ptrs[1]) -= elem_diff; + } + + access::rw(SpMat::n_rows) -= diff; + access::rw(SpMat::n_elem) -= diff; + + SpMat::invalidate_cache(); + } + + + +// //! insert N rows at the specified row position, +// //! optionally setting the elements of the inserted rows to zero +// template +// inline +// void +// SpCol::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_bounds((row_num > SpMat::n_rows), "SpCol::insert_rows(): out of bounds"); +// +// for(uword row = 0; row < SpMat::n_rows; ++row) +// { +// if(SpMat::row_indices[row] >= row_num) +// { +// access::rw(SpMat::row_indices[row]) += N; +// } +// } +// +// access::rw(SpMat::n_rows) += N; +// access::rw(SpMat::n_elem) += N; +// } + + + +template +inline +typename SpCol::row_iterator +SpCol::begin_row(const uword row_num) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= SpMat::n_rows), "SpCol::begin_row(): index out of bounds" ); + + SpMat::sync_csc(); + + return row_iterator(*this, row_num, 0); + } + + + +template +inline +typename SpCol::const_row_iterator +SpCol::begin_row(const uword row_num) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= SpMat::n_rows), "SpCol::begin_row(): index out of bounds" ); + + SpMat::sync_csc(); + + return const_row_iterator(*this, row_num, 0); + } + + + +template +inline +typename SpCol::row_iterator +SpCol::end_row(const uword row_num) + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= SpMat::n_rows), "SpCol::end_row(): index out of bounds" ); + + SpMat::sync_csc(); + + return row_iterator(*this, row_num + 1, 0); + } + + + +template +inline +typename SpCol::const_row_iterator +SpCol::end_row(const uword row_num) const + { + arma_extra_debug_sigprint(); + + arma_debug_check_bounds( (row_num >= SpMat::n_rows), "SpCol::end_row(): index out of bounds" ); + + SpMat::sync_csc(); + + return const_row_iterator(*this, row_num + 1, 0); + } + + + +#if defined(ARMA_EXTRA_SPCOL_MEAT) + #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPCOL_MEAT) +#endif + + + +//! @} -- cgit v1.2.1