用传入数据填充复杂矩阵的最快方法。 Armadillo图书馆
我的情况是,每个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C ++是
std :: Complex
的混叠和UB规则的特殊例外。这样做是为了兼容广泛使用的C子例程。https://en.cppreference.com/w/cpp/numeric/complex
因此,您可以使用这样的简单的东西:
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: