我们在代码中大量使用 Armadillo,但有些地方我们更喜欢直接从向量数学库中使用 MKL。我们有 cx_vec 即双精度向量。但是犰狳的 exp 函数使用 std::exp 这不是很好,所以我们开始使用 MKL。将 cx_vec 转换为 MKL_Complex16 数组并返回时出现问题。该方法有效,但我不确定是否有更好的方法或推荐的方法。有没有更好的方法来使用 Armadillo 的 MKL?这是我们当前使用的代码示例。请注意开头的演员表和结尾的副本,这是我想重写的。欢迎任何建议。
void Exp_MKL(const cx_vec& VectorInput, cx_vec& VectorOutput) {
if (VectorInput.size() != VectorOutput.size())
VectorOutput.set_size(VectorInput.size());
const MKL_Complex16* in = reinterpret_cast<const MKL_Complex16*>(VectorInput.memptr());
const int size = VectorInput.n_elem;
MKL_Complex16* out = (MKL_Complex16*) mkl_malloc(size * sizeof(MKL_Complex16), 64);
VZEXP(&size, in, out);
cx_vec newoutput(reinterpret_cast<cx_double*>(out), VectorInput.size(), false);
VectorOutput = newoutput;
mkl_free(out);
}