用传入数据填充复杂矩阵的最快方法。 Armadillo图书馆

发布于 2025-01-24 18:41:44 字数 1017 浏览 3 评论 0原文

我的情况是,每个1MS都将到达2*200个INT16_T样本的新缓冲区。 (乘以2是因为复杂的数据)

应以最快的方式(小于1 ms)将这些数据添加到Armadillo Complect Double矩阵中。

有人知道更好的方法吗?

当前的测试代码需要超过1ms(两种情况测试)

nb_of_samples = 200;


    void write(uint32_t rawId, uint32_t slotId, int16_t *samples) 
    {
        size_t currentBlock = slotId * nb_of_samples; // slot identification 
        auto const memPtr = matrix.colptr(currentBlock) + rawId; // pointer to position from where to start write new received samples
        std::for_each(std::execution::par_unseq, m_index.begin(), m_index.end(), [&memPtr, &samples](size_t index)
        {
            new (memPtr + index) std::complex<double>(samples[index], samples[index+1]);
        });
//        second idea, simple for 
//        for(size_t i = 0; i < NB_OF_SAMPLES; ++i)
//        {
//            new (memPtr + i) std::complex<double>(samples[i], samples[i+1]);
//        }
    }

I have situation where each 1ms is coming new buffer of 2*200 samples of int16_t. (multiplied by 2 is because complex data)

Those data should be added into Armadillo Complex Double Matrix, in the fastest way possible (less than 1 ms), to specific slot.

Does anyone know better approach ?

Current test code takes longer than 1ms (tested with both cases)

nb_of_samples = 200;


    void write(uint32_t rawId, uint32_t slotId, int16_t *samples) 
    {
        size_t currentBlock = slotId * nb_of_samples; // slot identification 
        auto const memPtr = matrix.colptr(currentBlock) + rawId; // pointer to position from where to start write new received samples
        std::for_each(std::execution::par_unseq, m_index.begin(), m_index.end(), [&memPtr, &samples](size_t index)
        {
            new (memPtr + index) std::complex<double>(samples[index], samples[index+1]);
        });
//        second idea, simple for 
//        for(size_t i = 0; i < NB_OF_SAMPLES; ++i)
//        {
//            new (memPtr + i) std::complex<double>(samples[i], samples[i+1]);
//        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷途知返 2025-01-31 18:41:44

C ++是std :: Complex的混叠和UB规则的特殊例外。这样做是为了兼容广泛使用的C子例程。

https://en.cppreference.com/w/cpp/numeric/complex

因此,您可以使用这样的简单的东西:

void convert(std::complex<double> *pout, const uint16_t* pin)
{
    for (size_t i = 0; i < nb_of_samples*2 ; i++)
        reinterpret_cast<double*>(pout)[i] = pin[i];
}

C++ makes a special exception to aliasing and UB rules for std::complex. This is done for compatibility of widely used C subroutines.

https://en.cppreference.com/w/cpp/numeric/complex

So you can just use something simple like this:

void convert(std::complex<double> *pout, const uint16_t* pin)
{
    for (size_t i = 0; i < nb_of_samples*2 ; i++)
        reinterpret_cast<double*>(pout)[i] = pin[i];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文