fftwf_execute_dft_c2r 写入输入缓冲区
fftwf_execute_dft_c2r writes the input buffer
我有以下代码:
auto in = std::array<std::complex<float>, 60>();
in[0] = 10000.0f;
auto out = std::array<float, 100>();
auto plan = fftwf_plan_dft_c2r_2d(10, 10, reinterpret_cast<fftwf_complex*>(in.data()), out.data(), FFTW_ESTIMATE | FFTW_UNALIGNED);
fftwf_execute_dft_c2r(plan, reinterpret_cast<fftwf_complex*>(in.data()), out.data());
当我 运行 它时,我的 in
数组被写入(特别是第一列设置为 10000.0)。这是正常的吗?我可以避免写入 in
数组吗?
如 documentation 中所述,使用 c2r
转换时输入数据将被覆盖
Second, the inverse transform (complex to real) has the side-effect of
overwriting its input array, by default. Neither of these
inconveniences should pose a serious problem for users, but it is
important to be aware of them.
As noted above, the c2r
transform destroys its input array even for
out-of-place transforms. This can be prevented, if necessary, by
including FFTW_PRESERVE_INPUT
in the flags, with unfortunately some
sacrifice in performance. This flag is also not currently supported
for multi-dimensional real DFTs (next section).
所以即使使用FFTW_PRESERVE_INPUT
,在这种情况下也是行不通的。来自 FFTW_PRESERVE_INPUT
documentation
FFTW_PRESERVE_INPUT
specifies that an out-of-place transform must not
change its input array. This is ordinarily the default, except for c2r
and hc2r
(i.e. complex-to-real) transforms for which
FFTW_DESTROY_INPUT
is the default. In the latter cases, passing
FFTW_PRESERVE_INPUT
will attempt to use algorithms that do not destroy
the input, at the expense of worse performance; for multi-dimensional
c2r
transforms, however, no input-preserving algorithms are
implemented and the planner will return NULL
if one is requested.
因此,解决这个问题的简单方法就是在将输入数组传递给计划函数之前复制它。
我有以下代码:
auto in = std::array<std::complex<float>, 60>();
in[0] = 10000.0f;
auto out = std::array<float, 100>();
auto plan = fftwf_plan_dft_c2r_2d(10, 10, reinterpret_cast<fftwf_complex*>(in.data()), out.data(), FFTW_ESTIMATE | FFTW_UNALIGNED);
fftwf_execute_dft_c2r(plan, reinterpret_cast<fftwf_complex*>(in.data()), out.data());
当我 运行 它时,我的 in
数组被写入(特别是第一列设置为 10000.0)。这是正常的吗?我可以避免写入 in
数组吗?
如 documentation 中所述,使用 c2r
转换时输入数据将被覆盖
Second, the inverse transform (complex to real) has the side-effect of overwriting its input array, by default. Neither of these inconveniences should pose a serious problem for users, but it is important to be aware of them.
As noted above, the
c2r
transform destroys its input array even for out-of-place transforms. This can be prevented, if necessary, by includingFFTW_PRESERVE_INPUT
in the flags, with unfortunately some sacrifice in performance. This flag is also not currently supported for multi-dimensional real DFTs (next section).
所以即使使用FFTW_PRESERVE_INPUT
,在这种情况下也是行不通的。来自 FFTW_PRESERVE_INPUT
documentation
FFTW_PRESERVE_INPUT
specifies that an out-of-place transform must not change its input array. This is ordinarily the default, except forc2r
andhc2r
(i.e. complex-to-real) transforms for whichFFTW_DESTROY_INPUT
is the default. In the latter cases, passingFFTW_PRESERVE_INPUT
will attempt to use algorithms that do not destroy the input, at the expense of worse performance; for multi-dimensionalc2r
transforms, however, no input-preserving algorithms are implemented and the planner will returnNULL
if one is requested.
因此,解决这个问题的简单方法就是在将输入数组传递给计划函数之前复制它。