]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
complexmat: Move CPU-only methods from .hpp to .cpp
authorMichal Sojka <michal.sojka@cvut.cz>
Thu, 4 Oct 2018 21:33:44 +0000 (23:33 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 4 Oct 2018 21:36:09 +0000 (23:36 +0200)
src/complexmat.cpp
src/complexmat.hpp

index 18d506407829d1e7a0891165de662a205a552a6d..97e1ca787f949c44672cdf7960bd069bae407d5d 100644 (file)
@@ -87,3 +87,63 @@ ComplexMat_ ComplexMat_::operator*(const ComplexMat_ &rhs) const
 {
     return mat_mat_operator([](std::complex<T> &c_lhs, const std::complex<T> &c_rhs) { c_lhs *= c_rhs; }, rhs);
 }
+
+ComplexMat_ ComplexMat_::mat_mat_operator(void (*op)(std::complex<ComplexMat_::T> &, const std::complex<ComplexMat_::T> &), 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<ComplexMat_::T> &, const std::complex<ComplexMat_::T> &), 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<ComplexMat_::T> &, const std::complex<ComplexMat_::T> &), 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<void (std::complex<ComplexMat_::T> &)> &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;
+}
index 60c8255912b490a2dd90cd33e81dcdf28031c5a4..9da81e64acbcba78b50a795ce9ab5e4b2c7a4c0c 100644 (file)
@@ -6,6 +6,7 @@
 #include <algorithm>
 #include <functional>
 #include "dynmem.hpp"
+#include "pragmas.h"
 
 #ifdef CUFFT
 #include <cufft.h>
@@ -141,63 +142,12 @@ class ComplexMat_ {
     }
 
     ComplexMat_ mat_mat_operator(void (*op)(std::complex<T> &c_lhs, const std::complex<T> &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<T> &c_lhs, const std::complex<T> &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<T> &c_lhs, const std::complex<T> &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<void(std::complex<T> &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<void(std::complex<T> &c_rhs)> &op) const;
 
     cv::Mat channel_to_cv_mat(int channel_id) const
     {