#pragma once #include //uint64_t #include "utils/vector.h" #include "utils/matrix.h" namespace numerics::detail{ // // ---------------- Greater - Vectors ---------------- // template inline void inplace_greater_serial(utils::Vector& v, const T c) { const uint64_t n = v.size(); if (n == 0){ throw std::runtime_error("inplace_greater_serial: empty vector"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] < c){ v[i] = T{0}; } else{ v[i] = T{1}; } } } template inline void inplace_greater_serial(utils::Vector& v, const utils::Vector& p) { const uint64_t n = v.size(); const uint64_t m = p.size(); if (n == 0){ throw std::runtime_error("inplace_greater_serial: empty vector"); } if (n != m){ throw std::runtime_error("inplace_greater_serial: vector size mismatch"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] < p[i]){ v[i] = T{0}; } else{ v[i] = T{1}; } } } // // ---------------- Greater - Matrices ---------------- // template inline void inplace_greater_serial(utils::Matrix& A, const T c) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_serial: empty matrix"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) < c){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_greater_rowwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_rowwise_serial: empty matrix"); } if (rows != v.size()){ throw std::runtime_error("inplace_greater_rowwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) < v[i]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_greater_colwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_colwise_serial: empty matrix"); } if (cols != v.size()){ throw std::runtime_error("inplace_greater_colwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) < v[j]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_greater_serial(utils::Matrix& A, const utils::Matrix& B) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_serial: empty matrix"); } if (rows != B.rows() || cols != B.cols()){ throw std::runtime_error("inplace_greater_serial: Matrix size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) < B(i,j)){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } // // ---------------- Greater or Equal - Vectors ---------------- // template inline void inplace_greater_equal_serial(utils::Vector& v, const T c) { const uint64_t n = v.size(); if (n == 0){ throw std::runtime_error("inplace_greater_equal_serial: empty vector"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] <= c){ v[i] = T{0}; } else{ v[i] = T{1}; } } } template inline void inplace_greater_equal_serial(utils::Vector& v, const utils::Vector& p) { const uint64_t n = v.size(); const uint64_t m = p.size(); if (n == 0){ throw std::runtime_error("inplace_greater_equal_serial: empty vector"); } if (n != m){ throw std::runtime_error("inplace_greater_equal_serial: vector size mismatch"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] <= p[i]){ v[i] = T{0}; } else{ v[i] = T{1}; } } } // // ---------------- Greater - Matrices ---------------- // template inline void inplace_greater_equal_serial(utils::Matrix& A, const T c) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_equal_serial: empty matrix"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) <= c){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_greater_equal_rowwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_equal_rowwise_serial: empty matrix"); } if (rows != v.size()){ throw std::runtime_error("inplace_greater_equal_rowwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) <= v[i]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_greater_equal_colwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_equal_colwise_serial: empty matrix"); } if (cols != v.size()){ throw std::runtime_error("inplace_greater_equal_colwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) <= v[j]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_greater_equal_serial(utils::Matrix& A, const utils::Matrix& B) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_greater_equal_serial: empty matrix"); } if (rows != B.rows() || cols != B.cols()){ throw std::runtime_error("inplace_greater_equal_serial: Matrix size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) <= B(i,j)){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } // // ---------------- Less - Vectors ---------------- // template inline void inplace_less_serial(utils::Vector& v, const T c) { const uint64_t n = v.size(); if (n == 0){ throw std::runtime_error("inplace_less_serial: empty vector"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] > c){ v[i] = T{0}; } else{ v[i] = T{1}; } } } template inline void inplace_less_serial(utils::Vector& v, const utils::Vector& p) { const uint64_t n = v.size(); const uint64_t m = p.size(); if (n == 0){ throw std::runtime_error("inplace_less_serial: empty vector"); } if (n != m){ throw std::runtime_error("inplace_less_serial: vector size mismatch"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] > p[i]){ v[i] = T{0}; } else{ v[i] = T{1}; } } } // // ---------------- Greater - Matrices ---------------- // template inline void inplace_less_serial(utils::Matrix& A, const T c) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_serial: empty matrix"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) > c){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_less_rowwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_rowwise_serial: empty matrix"); } if (rows != v.size()){ throw std::runtime_error("inplace_less_rowwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) > v[i]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_less_colwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_colwise_serial: empty matrix"); } if (cols != v.size()){ throw std::runtime_error("inplace_less_colwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) > v[j]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_less_serial(utils::Matrix& A, const utils::Matrix& B) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_serial: empty matrix"); } if (rows != B.rows() || cols != B.cols()){ throw std::runtime_error("inplace_less_serial: Matrix size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) > B(i,j)){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } // // ---------------- Less or Equal - Vectors ---------------- // template inline void inplace_less_equal_serial(utils::Vector& v, const T c) { const uint64_t n = v.size(); if (n == 0){ throw std::runtime_error("inplace_less_equal_serial: empty vector"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] >= c){ v[i] = T{0}; } else{ v[i] = T{1}; } } } template inline void inplace_less_equal_serial(utils::Vector& v, const utils::Vector& p) { const uint64_t n = v.size(); const uint64_t m = p.size(); if (n == 0){ throw std::runtime_error("inplace_less_equal_serial: empty vector"); } if (n != m){ throw std::runtime_error("inplace_less_equal_serial: vector size mismatch"); } for (uint64_t i = 0; i < n; ++i){ if (v[i] >= p[i]){ v[i] = T{0}; } else{ v[i] = T{1}; } } } // // ---------------- Greater - Matrices ---------------- // template inline void inplace_less_equal_serial(utils::Matrix& A, const T c) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_equal_serial: empty matrix"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) >= c){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_less_equal_rowwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_equal_rowwise_serial: empty matrix"); } if (rows != v.size()){ throw std::runtime_error("inplace_less_equal_rowwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) >= v[i]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_less_equal_colwise_serial(utils::Matrix& A, const utils::Vector& v) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_equal_colwise_serial: empty matrix"); } if (cols != v.size()){ throw std::runtime_error("inplace_less_equal_colwise_serial: Matrix-Vector size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) >= v[j]){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } template inline void inplace_less_equal_serial(utils::Matrix& A, const utils::Matrix& B) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); if (rows == 0 || cols == 0){ throw std::runtime_error("inplace_less_equal_serial: empty matrix"); } if (rows != B.rows() || cols != B.cols()){ throw std::runtime_error("inplace_less_equal_serial: Matrix size mismatch"); } for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ if (A(i,j) >= B(i,j)){ A(i,j) = T{0}; } else{ A(i,j) = T{1}; } } } } } // namespace numerics