1 #include "complexmat.hpp"
3 ComplexMat_::T ComplexMat_::sqr_norm() const
7 int n_channels_per_scale = n_channels / n_scales;
9 for (int i = 0; i < n_channels_per_scale; ++i) {
10 for (auto lhs = p_data.hostMem() + i * rows * cols; lhs != p_data.hostMem() + (i + 1) * rows * cols; ++lhs)
11 sum_sqr_norm += lhs->real() * lhs->real() + lhs->imag() * lhs->imag();
13 sum_sqr_norm = sum_sqr_norm / static_cast<T>(cols * rows);
17 void ComplexMat_::sqr_norm(DynMem_<ComplexMat_::T> &result) const
19 int n_channels_per_scale = n_channels / n_scales;
20 int scale_offset = n_channels_per_scale * rows * cols;
21 for (uint scale = 0; scale < n_scales; ++scale) {
23 for (int i = 0; i < n_channels_per_scale; ++i)
24 for (auto lhs = p_data.hostMem() + i * rows * cols + scale * scale_offset;
25 lhs != p_data.hostMem() + (i + 1) * rows * cols + scale * scale_offset; ++lhs)
26 sum_sqr_norm += lhs->real() * lhs->real() + lhs->imag() * lhs->imag();
27 result.hostMem()[scale] = sum_sqr_norm / static_cast<T>(cols * rows);
32 ComplexMat_ ComplexMat_::sqr_mag() const
34 return mat_const_operator([](std::complex<T> &c) { c = c.real() * c.real() + c.imag() * c.imag(); });
37 ComplexMat_ ComplexMat_::conj() const
39 return mat_const_operator([](std::complex<T> &c) { c = std::complex<T>(c.real(), -c.imag()); });
42 ComplexMat_ ComplexMat_::sum_over_channels() const
44 assert(p_data.num_elem == n_channels * rows * cols);
46 uint n_channels_per_scale = n_channels / n_scales;
47 uint scale_offset = n_channels_per_scale * rows * cols;
49 ComplexMat_ result(this->rows, this->cols, 1, n_scales);
50 for (uint scale = 0; scale < n_scales; ++scale) {
51 for (uint i = 0; i < rows * cols; ++i) {
52 std::complex<T> acc = 0;
53 for (uint ch = 0; ch < n_channels_per_scale; ++ch)
54 acc += p_data[scale * scale_offset + i + ch * rows * cols];
55 result.p_data.hostMem()[scale * rows * cols + i] = acc;
61 ComplexMat_ ComplexMat_::operator/(const ComplexMat_ &rhs) const
63 return mat_mat_operator([](std::complex<T> &c_lhs, const std::complex<T> &c_rhs) { c_lhs /= c_rhs; }, rhs);
66 ComplexMat_ ComplexMat_::operator+(const ComplexMat_ &rhs) const
68 return mat_mat_operator([](std::complex<T> &c_lhs, const std::complex<T> &c_rhs) { c_lhs += c_rhs; }, rhs);
71 ComplexMat_ ComplexMat_::operator*(const ComplexMat_::T &rhs) const
73 return mat_const_operator([&rhs](std::complex<T> &c) { c *= rhs; });
76 ComplexMat_ ComplexMat_::mul(const ComplexMat_ &rhs) const
78 return matn_mat1_operator([](std::complex<T> &c_lhs, const std::complex<T> &c_rhs) { c_lhs *= c_rhs; }, rhs);
81 ComplexMat_ ComplexMat_::operator+(const ComplexMat_::T &rhs) const
83 return mat_const_operator([&rhs](std::complex<T> &c) { c += rhs; });
86 ComplexMat_ ComplexMat_::operator*(const ComplexMat_ &rhs) const
88 return mat_mat_operator([](std::complex<T> &c_lhs, const std::complex<T> &c_rhs) { c_lhs *= c_rhs; }, rhs);