]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blobdiff - src/complexmat.cpp
complexmat: Move CPU-only methods from .hpp to .cpp
[hercules2020/kcf.git] / src / complexmat.cpp
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;
+}