From 330254878882aa606b97b7a04bcb404fee5b2cc3 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sat, 22 Feb 2025 11:40:45 +0800 Subject: [PATCH] tmp --- lib/core/array.h | 4 ++-- lib/core/matrix.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/core/array.h b/lib/core/array.h index bbaa2af..f094288 100644 --- a/lib/core/array.h +++ b/lib/core/array.h @@ -780,7 +780,7 @@ namespace gctl * * @return 返回的模长 */ - ArrValType module(norm_type_e n_type = L2); + ArrValType module(norm_type_e n_type = L2) const; /** * @brief Normalize the array to the given module value @@ -1815,7 +1815,7 @@ namespace gctl } template - ArrValType array::module(norm_type_e n_type) + ArrValType array::module(norm_type_e n_type) const { static_assert(std::is_arithmetic::value, "gctl::array::module(...) could only be used with an arithmetic type."); diff --git a/lib/core/matrix.h b/lib/core/matrix.h index 8a11226..7a998ac 100644 --- a/lib/core/matrix.h +++ b/lib/core/matrix.h @@ -245,6 +245,22 @@ namespace gctl */ void assign_all(MatValType in_val); + /** + * @brief 填充矩阵行 + * + * @param r_id 行索引 + * @param in_val 行数据 + */ + void fill_row(size_t r_id, const array &in_arr); + + /** + * @brief 填充矩阵列 + * + * @param c_id 列索引 + * @param in_val 列数据 + */ + void fill_column(size_t c_id, const array &in_arr); + /** * @brief 对全体元素进行缩放 * @@ -790,6 +806,32 @@ namespace gctl return; } + template + void matrix::fill_row(size_t r_id, const array &in_arr) + { + if (r_id >= row_length) throw std::out_of_range("[gctl::matrix::fill_row] Row index out of range."); + if (in_arr.size() != col_length) throw std::invalid_argument("[gctl::matrix::fill_row] Invalid array length."); + + for (size_t j = 0; j < col_length; j++) + { + val[r_id][j] = in_arr[j]; + } + return; + } + + template + void matrix::fill_column(size_t c_id, const array &in_arr) + { + if (c_id >= col_length) throw std::out_of_range("[gctl::matrix::fill_column] Column index out of range."); + if (in_arr.size()!= row_length) throw std::invalid_argument("[gctl::matrix::fill_column] Invalid array length."); + + for (size_t i = 0; i < row_length; i++) + { + val[i][c_id] = in_arr[i]; + } + return; + } + template void matrix::scale(MatValType s) {