public ILArray </*!HC:HCretArr*/ complex> /*!HC:funcName*/ FFTForward(ILArray </*!HC:HCinArr*/ double> A, int firstDim, int nDims) { if (A == null || nDims < 0 || firstDim < 0) { throw new ILArgumentException("invalid parameter!"); } if (A.IsEmpty) { return(ILArray </*!HC:HCretArr*/ complex> .empty(A.Dimensions)); } if (A.IsScalar || (A.Dimensions[firstDim] == 1 && nDims == 1)) { return /*!HC:convRet*/ (ILMath.tocomplex(A)); } if (nDims > A.Dimensions.NumberOfDimensions) { nDims = A.Dimensions.NumberOfDimensions; } // prepare output array ILArray </*!HC:HCretArr*/ complex> ret = /*!HC:convRet*/ ILMath.tocomplex(A); IntPtr plan = IntPtr.Zero; int hrank = 2; FFTW_DIRECTION dir = /*!HC:HCdir*/ FFTW_DIRECTION.FORWARD; lock (_lockobject) { FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE; if (nDims > m_n.Length) { resizeCache(nDims); } for (int i = 0; i < nDims; i++) { m_n[i] = A.Dimensions[i + firstDim]; m_is[i] = A.Dimensions.SequentialIndexDistance(i + firstDim); m_os[i] = m_is[i]; } m_hn[0] = A.Dimensions.SequentialIndexDistance(firstDim); m_his[0] = 1; m_hos[0] = 1; m_his[1] = A.Dimensions.SequentialIndexDistance(nDims + firstDim); m_hn[1] = A.Dimensions.NumberOfElements / m_his[1]; m_hos[1] = m_his[1]; fixed(/*!HC:HCretArr*/ complex *retArr = ret.m_data) { /*!HC:HCplanfun*/ dfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os, ref hrank, m_hn, m_his, m_hos, retArr, retArr, ref dir, ref flags); } } if (plan == IntPtr.Zero) { throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)"); } dfftw_execute_(ref plan); dfftw_destroy_plan_(ref plan); /*!HC:HCbackwScale*/ return(ret); }
public ILArray <complex> FFTBackward(ILArray <complex> A, int firstDim, int nDims) { if (A == null || nDims < 0 || firstDim < 0) { throw new ILArgumentException("invalid parameter!"); } if (A.IsEmpty) { return(ILArray <complex> .empty(A.Dimensions)); } if (A.IsScalar || (A.Dimensions[firstDim] == 1 && nDims == 1)) { return(A.C); } if (nDims > A.Dimensions.NumberOfDimensions) { nDims = A.Dimensions.NumberOfDimensions; } // prepare output array ILArray <complex> ret = A.C; IntPtr plan = IntPtr.Zero; int hrank = 2; FFTW_DIRECTION dir = FFTW_DIRECTION.BACKWARDS; lock (_lockobject) { FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE; if (nDims > m_n.Length) { resizeCache(nDims); } for (int i = 0; i < nDims; i++) { m_n[i] = A.Dimensions[i + firstDim]; m_is[i] = A.Dimensions.SequentialIndexDistance(i + firstDim); m_os[i] = m_is[i]; } m_hn[0] = A.Dimensions.SequentialIndexDistance(firstDim); m_his[0] = 1; m_hos[0] = 1; m_his[1] = A.Dimensions.SequentialIndexDistance(nDims + firstDim); m_hn[1] = A.Dimensions.NumberOfElements / m_his[1]; m_hos[1] = m_his[1]; fixed(complex *retArr = ret.m_data) { dfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os, ref hrank, m_hn, m_his, m_hos, retArr, retArr, ref dir, ref flags); } } if (plan == IntPtr.Zero) { throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)"); } dfftw_execute_(ref plan); dfftw_destroy_plan_(ref plan); ret /= new complex(m_his[1] / m_hn[0], 0.0f); return(ret); }
private static extern void dfftw_plan_r2r_2d_(ref IntPtr plan, ref int nx, ref int ny, [In, Out] double *input, [In, Out] double *output, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_r2r_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In,Out] double* input, [In,Out] double* output, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_guru_split_dft_r2c_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] int[] iS, [In,Out] int[] iO, ref int howmany_rank, [In,Out] int[] hn, [In,Out] int[] hiS, [In,Out] int[] hiO, [In,Out] double* ri, [In,Out] double* ro, [In,Out] double* io, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_dft_r2c_(ref IntPtr plan, ref int rank, [In, Out] int[] n, [In, Out] double *input, [In, Out] complex *output, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_guru_r2r_(ref IntPtr plan, ref int rank, [In, Out] int[] n, [In, Out] int[] iS, [In, Out] int[] iO, ref int howmany_rank, [In, Out] int[] hn, [In, Out] int[] hiS, [In, Out] int[] hiO, [In, Out] double *input, [In, Out] double *output, ref FFTW_KIND kind, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_guru_dft_(ref IntPtr plan, ref int rank, [In, Out] int[] n, [In, Out] int[] iS, [In, Out] int[] iO, ref int howmany_rank, [In, Out] int[] hn, [In, Out] int[] hiS, [In, Out] int[] hiO, [In, Out] complex *input, [In, Out] complex *output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_guru_dft_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] int[] iS, [In,Out] int[] iO, ref int howmany_rank, [In,Out] int[] hn, [In,Out] int[] hiS, [In,Out] int[] hiO, [In,Out] fcomplex* input, [In,Out] fcomplex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_many_r2r_( ref IntPtr plan, ref int rank, [In,Out] int [] n, ref int howmany, [In,Out] float [] input, [In,Out] int[] inembed, ref int istride, ref int idist, [In,Out] float* output, [In,Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_KIND kind, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_many_dft_(ref IntPtr plan, ref int rank, [In,Out] int[] n, ref int howmany, [In,Out] fcomplex* input, [In,Out] int[] inembed, ref int istride, ref int idist, [In,Out] fcomplex* output, [In,Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_r2r_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] float* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_dft_c2r_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In,Out] fcomplex* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_dft_r2c_1d_(ref IntPtr plan, ref int n, [In,Out] float* input, [In,Out] fcomplex* output, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_many_dft_(ref IntPtr plan, ref int rank, [In, Out] int[] n, ref int howmany, [In, Out] complex *input, [In, Out] int[] inembed, ref int istride, ref int idist, [In, Out] complex *output, [In, Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_many_r2r_(ref IntPtr plan, ref int rank, [In, Out] int [] n, ref int howmany, [In, Out] double [] input, [In, Out] int[] inembed, ref int istride, ref int idist, [In, Out] double *output, [In, Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_KIND kind, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_guru_split_dft_c2r_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] int[] iS, [In,Out] int[] iO, ref int howmany_rank, [In,Out] int[] hn, [In,Out] int[] hiS, [In,Out] int[] hiO, [In,Out] float* ri, [In,Out] float* ii, [In,Out] float* ro, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_guru_split_dft_c2r_(ref IntPtr plan, ref int rank, [In, Out] int[] n, [In, Out] int[] iS, [In, Out] int[] iO, ref int howmany_rank, [In, Out] int[] hn, [In, Out] int[] hiS, [In, Out] int[] hiO, [In, Out] double *ri, [In, Out] double *ii, [In, Out] double *ro, ref FFTW_PLANCREATION flags);
private static extern void sfftw_plan_guru_r2r_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] int[] iS, [In,Out] int[] iO, ref int howmany_rank, [In,Out] int[] hn, [In,Out] int[] hiS, [In,Out] int[] hiO, [In,Out] float* input, [In,Out] float* output, ref FFTW_KIND kind, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_dft_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In,Out] complex* input, [In,Out] complex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_dft_r2c_2d_(ref IntPtr plan, ref int nx, ref int ny, [In,Out] double* input, [In,Out] complex* output, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_dft_2d_(ref IntPtr plan, ref int nx, ref int ny, [In, Out] complex *input, [In, Out] complex *output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_dft_c2r_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] complex* input, [In,Out] double* output, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_dft_c2r_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In, Out] complex *input, [In, Out] double *output, ref FFTW_PLANCREATION flags);
private static extern void dfftw_plan_guru_dft_r2c_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] int[] iS, [In,Out] int[] iO, ref int howmany_rank, [In,Out] int[] hn, [In,Out] int[] hiS, [In,Out] int[] hiO, [In,Out] double* input, [In,Out] complex* output, ref FFTW_PLANCREATION flags);