From 063a699dae80008f1ea592aa4f30177b38109e76 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 4 Oct 2018 23:33:44 +0200 Subject: [PATCH] complexmat: Move CPU-only methods from .hpp to .cpp --- src/complexmat.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ src/complexmat.hpp | 60 ++++------------------------------------------ 2 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/complexmat.cpp b/src/complexmat.cpp index 18d5064..97e1ca7 100644 --- a/src/complexmat.cpp +++ b/src/complexmat.cpp @@ -87,3 +87,63 @@ ComplexMat_ ComplexMat_::operator*(const ComplexMat_ &rhs) const { return mat_mat_operator([](std::complex &c_lhs, const std::complex &c_rhs) { c_lhs *= c_rhs; }, rhs); } + +ComplexMat_ ComplexMat_::mat_mat_operator(void (*op)(std::complex &, const std::complex &), const ComplexMat_ &mat_rhs) const +{ + assert(mat_rhs.n_channels == n_channels/n_scales && mat_rhs.cols == cols && mat_rhs.rows == rows); + + ComplexMat_ result = *this; + for (uint s = 0; s < n_scales; ++s) { + auto lhs = result.p_data.hostMem() + (s * n_channels/n_scales * rows * cols); + auto rhs = mat_rhs.p_data.hostMem(); + for (uint i = 0; i < n_channels/n_scales * rows * cols; ++i) + op(*(lhs + i), *(rhs + i)); + } + + return result; +} + +ComplexMat_ ComplexMat_::matn_mat1_operator(void (*op)(std::complex &, const std::complex &), const ComplexMat_ &mat_rhs) const +{ + assert(mat_rhs.n_channels == 1 && mat_rhs.cols == cols && mat_rhs.rows == rows); + + ComplexMat_ result = *this; + for (uint i = 0; i < n_channels; ++i) { + auto lhs = result.p_data.hostMem() + i * rows * cols; + auto rhs = mat_rhs.p_data.hostMem(); + for (; lhs != result.p_data.hostMem() + (i + 1) * rows * cols; ++lhs, ++rhs) + op(*lhs, *rhs); + } + + return result; +} + +ComplexMat_ ComplexMat_::matn_mat2_operator(void (*op)(std::complex &, const std::complex &), const ComplexMat_ &mat_rhs) const +{ + assert(mat_rhs.n_channels == n_channels / n_scales && mat_rhs.cols == cols && mat_rhs.rows == rows); + + int n_channels_per_scale = n_channels / n_scales; + int scale_offset = n_channels_per_scale * rows * cols; + ComplexMat_ result = *this; + for (uint i = 0; i < n_scales; ++i) { + for (int j = 0; j < n_channels_per_scale; ++j) { + auto lhs = result.p_data.hostMem() + (j * rows * cols) + (i * scale_offset); + auto rhs = mat_rhs.p_data.hostMem() + (j * rows * cols); + for (; lhs != result.p_data.hostMem() + ((j + 1) * rows * cols) + (i * scale_offset); ++lhs, ++rhs) + op(*lhs, *rhs); + } + } + + return result; +} + +ComplexMat_ ComplexMat_::mat_const_operator(const std::function &)> &op) const +{ + ComplexMat_ result = *this; + for (uint i = 0; i < n_channels; ++i) { + for (auto lhs = result.p_data.hostMem() + i * rows * cols; + lhs != result.p_data.hostMem() + (i + 1) * rows * cols; ++lhs) + op(*lhs); + } + return result; +} diff --git a/src/complexmat.hpp b/src/complexmat.hpp index 60c8255..9da81e6 100644 --- a/src/complexmat.hpp +++ b/src/complexmat.hpp @@ -6,6 +6,7 @@ #include #include #include "dynmem.hpp" +#include "pragmas.h" #ifdef CUFFT #include @@ -141,63 +142,12 @@ class ComplexMat_ { } ComplexMat_ mat_mat_operator(void (*op)(std::complex &c_lhs, const std::complex &c_rhs), - const ComplexMat_ &mat_rhs) const - { - assert(mat_rhs.n_channels == n_channels/n_scales && mat_rhs.cols == cols && mat_rhs.rows == rows); - - ComplexMat_ result = *this; - for (uint s = 0; s < n_scales; ++s) { - auto lhs = result.p_data.hostMem() + (s * n_channels/n_scales * rows * cols); - auto rhs = mat_rhs.p_data.hostMem(); - for (uint i = 0; i < n_channels/n_scales * rows * cols; ++i) - op(*(lhs + i), *(rhs + i)); - } - - return result; - } + const ComplexMat_ &mat_rhs) const; ComplexMat_ matn_mat1_operator(void (*op)(std::complex &c_lhs, const std::complex &c_rhs), - const ComplexMat_ &mat_rhs) const - { - assert(mat_rhs.n_channels == 1 && mat_rhs.cols == cols && mat_rhs.rows == rows); - - ComplexMat_ result = *this; - for (uint i = 0; i < n_channels; ++i) { - auto lhs = result.p_data.hostMem() + i * rows * cols; - auto rhs = mat_rhs.p_data.hostMem(); - for (; lhs != result.p_data.hostMem() + (i + 1) * rows * cols; ++lhs, ++rhs) - op(*lhs, *rhs); - } - - return result; - } + const ComplexMat_ &mat_rhs) const; ComplexMat_ matn_mat2_operator(void (*op)(std::complex &c_lhs, const std::complex &c_rhs), - const ComplexMat_ &mat_rhs) const - { - assert(mat_rhs.n_channels == n_channels / n_scales && mat_rhs.cols == cols && mat_rhs.rows == rows); - - int n_channels_per_scale = n_channels / n_scales; - int scale_offset = n_channels_per_scale * rows * cols; - ComplexMat_ result = *this; - for (uint i = 0; i < n_scales; ++i) { - for (int j = 0; j < n_channels_per_scale; ++j) { - auto lhs = result.p_data.hostMem() + (j * rows * cols) + (i * scale_offset); - auto rhs = mat_rhs.p_data.hostMem() + (j * rows * cols); - for (; lhs != result.p_data.hostMem() + ((j + 1) * rows * cols) + (i * scale_offset); ++lhs, ++rhs) - op(*lhs, *rhs); - } - } - - return result; - } - ComplexMat_ mat_const_operator(const std::function &c_rhs)> &op) const - { - ComplexMat_ result = *this; - for (uint i = 0; i < n_channels; ++i) - for (auto lhs = result.p_data.hostMem() + i * rows * cols; - lhs != result.p_data.hostMem() + (i + 1) * rows * cols; ++lhs) - op(*lhs); - return result; - } + const ComplexMat_ &mat_rhs) const; + ComplexMat_ mat_const_operator(const std::function &c_rhs)> &op) const; cv::Mat channel_to_cv_mat(int channel_id) const { -- 2.39.2