From 17ec03194053892f75133ba6df5bcdd77e2cc8a9 Mon Sep 17 00:00:00 2001 From: Patrick Willner Date: Fri, 6 Nov 2020 15:26:31 +0100 Subject: [PATCH] Overload multiply functions --- src/core/sparse.h | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/core/sparse.h b/src/core/sparse.h index 8fcddb0..edef341 100644 --- a/src/core/sparse.h +++ b/src/core/sparse.h @@ -41,8 +41,11 @@ namespace ldpc void read_from_file(const std::string &filename, int skipLines); - std::vector multiply_left(const std::vector &left) const; // for encoding - std::vector multiply_right(const std::vector &right) const; // for syndrome + void multiply_left(const std::vector &left, std::vector &result) const; // for encoding + std::vector multiply_left(const std::vector &left) const; + + void multiply_right(const std::vector &right, std::vector &result) const; // for syndrome + std::vector multiply_right(const std::vector &right) const; int num_cols() const { return numCols; } int num_rows() const { return numRows; } @@ -101,13 +104,11 @@ namespace ldpc * * @tparam T finite field * @param left Row vector - * @return std::vector + * @param result Result row vector */ template - std::vector sparse_csr::multiply_left(const std::vector &left) const + void sparse_csr::multiply_left(const std::vector &left, std::vector &result) const { - std::vector result(numCols); - for (int j = 0; j < numCols; ++j) { for (const auto &n : colN[j]) @@ -115,7 +116,20 @@ namespace ldpc result[j] += left[n.nodeIndex] * nonZeroVals[n.edgeIndex].value; } } + } + /** + * @brief Multiply vector from left handside with matrix over field T + * + * @tparam T finite field + * @param left Row vector + * @return std::vector Result row vector + */ + template + std::vector sparse_csr::multiply_left(const std::vector &left) const + { + std::vector result(numCols); + multiply_left(left, result); return result; } @@ -124,13 +138,11 @@ namespace ldpc * * @tparam T finite field * @param right Column vector - * @return std::vector + * @param result Result column vector */ template - std::vector sparse_csr::multiply_right(const std::vector &right) const + void sparse_csr::multiply_right(const std::vector &right, std::vector &result) const { - std::vector result(numRows); - for (int i = 0; i < numRows; ++i) { for (const auto &n : rowN[i]) @@ -138,7 +150,20 @@ namespace ldpc result[i] += right[n.nodeIndex] * nonZeroVals[n.edgeIndex].value; } } + } + /** + * @brief Multiply vector from right handside with matrix over field T + * + * @tparam T finite field + * @param right Column vector + * @return std::vector Result column vector + */ + template + std::vector sparse_csr::multiply_right(const std::vector &right) const + { + std::vector result(numRows); + multiply_right(right, result); return result; } } // namespace ldpc