[9102] | 1 | ///
|
---|
| 2 | /// This file is part of ILNumerics Community Edition.
|
---|
| 3 | ///
|
---|
| 4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
| 5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
| 6 | ///
|
---|
| 7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
| 8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
| 9 | /// the Free Software Foundation.
|
---|
| 10 | ///
|
---|
| 11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
| 12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | /// GNU General Public License for more details.
|
---|
| 15 | ///
|
---|
| 16 | /// You should have received a copy of the GNU General Public License
|
---|
| 17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
| 18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | ///
|
---|
| 20 | /// In addition this software uses the following components and/or licenses:
|
---|
| 21 | ///
|
---|
| 22 | /// =================================================================================
|
---|
| 23 | /// The Open Toolkit Library License
|
---|
| 24 | ///
|
---|
| 25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
| 26 | ///
|
---|
| 27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
| 28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
| 29 | /// in the Software without restriction, including without limitation the rights to
|
---|
| 30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
| 31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
| 32 | /// so, subject to the following conditions:
|
---|
| 33 | ///
|
---|
| 34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
| 35 | /// copies or substantial portions of the Software.
|
---|
| 36 | ///
|
---|
| 37 | /// =================================================================================
|
---|
| 38 | ///
|
---|
| 39 |
|
---|
| 40 | #pragma warning disable 1591
|
---|
| 41 |
|
---|
| 42 | using System;
|
---|
| 43 | using System.Collections.Generic;
|
---|
| 44 | using System.Text;
|
---|
| 45 | using System.Security;
|
---|
| 46 | using System.Runtime.InteropServices;
|
---|
| 47 | using ILNumerics.Exceptions;
|
---|
| 48 | using ILNumerics.Misc;
|
---|
| 49 |
|
---|
| 50 | namespace ILNumerics.Native {
|
---|
| 51 |
|
---|
| 52 | /// <summary>
|
---|
| 53 | /// Wrapper for FFT interface using FFTW3 libs
|
---|
| 54 | /// </summary>
|
---|
| 55 | public unsafe class ILFFTW3FFT : IILFFT, IDisposable {
|
---|
| 56 |
|
---|
| 57 | #region pinvoke definitions
|
---|
| 58 |
|
---|
| 59 | /// <summary>
|
---|
| 60 | /// This struct is used to define (n-dimensional) transform sizes
|
---|
| 61 | /// </summary>
|
---|
| 62 | /// <remarks>This struct is only user in C-API. It is NOT used for the Fortran interface (i.e. it's not used in here)!!! </remarks>
|
---|
| 63 | [StructLayout(LayoutKind.Sequential)]
|
---|
| 64 | private struct fftw_iodim {
|
---|
| 65 | /// <summary>
|
---|
| 66 | /// length of dimension
|
---|
| 67 | /// </summary>
|
---|
| 68 | public int n;
|
---|
| 69 | /// <summary>
|
---|
| 70 | /// input stride
|
---|
| 71 | /// </summary>
|
---|
| 72 | public int iS;
|
---|
| 73 | /// <summary>
|
---|
| 74 | /// output stride
|
---|
| 75 | /// </summary>
|
---|
| 76 | public int oS;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | #region DOUBLE PRECISION INTERFACE ********* COMPLEX
|
---|
| 80 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 81 | private static extern void dfftw_plan_dft_1d_(ref IntPtr plan, ref int n, [In,Out] complex* input, [In,Out] complex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
|
---|
| 82 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 83 | 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);
|
---|
| 84 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 85 | 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);
|
---|
| 86 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 87 | private static extern void dfftw_plan_dft_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] complex* input, [In,Out] complex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
|
---|
| 88 |
|
---|
| 89 | /****************************************************************** REAL-COMPLEX ***/
|
---|
| 90 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 91 | private static extern void dfftw_plan_dft_r2c_1d_(ref IntPtr plan, ref int n, [In,Out] double* input, [In,Out] complex* output, ref FFTW_PLANCREATION flags);
|
---|
| 92 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 93 | 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);
|
---|
| 94 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 95 | private static extern void dfftw_plan_dft_r2c_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In,Out] double* input, [In,Out] complex* output, ref FFTW_PLANCREATION flags);
|
---|
| 96 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 97 | 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);
|
---|
| 98 |
|
---|
| 99 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 100 | private static extern void dfftw_plan_dft_c2r_1d_(ref IntPtr plan, ref int n, [In,Out] complex* input, [In,Out] double* output, ref FFTW_PLANCREATION flags);
|
---|
| 101 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 102 | private static extern void dfftw_plan_dft_c2r_2d_(ref IntPtr plan, ref int nx, ref int ny, [In,Out] complex* input, [In,Out] double* output, ref FFTW_PLANCREATION flags);
|
---|
| 103 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 104 | 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);
|
---|
| 105 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 106 | 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);
|
---|
| 107 |
|
---|
| 108 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 109 | private static extern void dfftw_plan_r2r_1d_(ref IntPtr plan, ref int n, [In,Out] double* input, [In,Out] double* output, ref FFTW_PLANCREATION flags);
|
---|
| 110 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 111 | 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);
|
---|
| 112 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 113 | 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);
|
---|
| 114 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 115 | private static extern void dfftw_plan_r2r_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] double* input, [In,Out] double* output, ref FFTW_PLANCREATION flags);
|
---|
| 116 |
|
---|
| 117 | /************************************ ADVANCED INTERFACE *************************************/
|
---|
| 118 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 119 | 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);
|
---|
| 120 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 121 | private static extern void dfftw_plan_many_dft_r2c_(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] complex* output, [In,Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_PLANCREATION flags);
|
---|
| 122 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 123 | private static extern void dfftw_plan_many_dft_c2r_(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] double* output, [In,Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_PLANCREATION flags);
|
---|
| 124 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 125 | 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);
|
---|
| 126 |
|
---|
| 127 | /************************************ GURU INTERFACE *************************************/
|
---|
| 128 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 129 | 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);
|
---|
| 130 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 131 | private static extern void dfftw_plan_guru_split_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] double* ri, [In,Out] double* ii, [In,Out] double* ro, [In,Out] double* io, ref FFTW_PLANCREATION flags);
|
---|
| 132 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 133 | 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);
|
---|
| 134 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 135 | private static extern void dfftw_plan_guru_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] complex* input, [In,Out] double* output, ref FFTW_PLANCREATION flags);
|
---|
| 136 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 137 | 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);
|
---|
| 138 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 139 | 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);
|
---|
| 140 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 141 | 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);
|
---|
| 142 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 143 | private static extern void dfftw_execute_dft_(ref IntPtr plan, [In,Out] complex* input, [In,Out] complex* output);
|
---|
| 144 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 145 | private static extern void dfftw_execute_split_dft_(ref IntPtr plan, [In,Out] double* ri, [In,Out] double* ii, [In,Out] double* ro, [In,Out] double* io);
|
---|
| 146 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 147 | private static extern void dfftw_execute_dft_r2c_(ref IntPtr plan, [In,Out] double* ri, [In,Out] complex* ii);
|
---|
| 148 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 149 | private static extern void dfftw_execute_split_dft_r2c_(ref IntPtr plan, [In,Out] double* input, [In,Out] double* ro, [In,Out] double* ri);
|
---|
| 150 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 151 | private static extern void dfftw_execute_dft_c2r_(ref IntPtr plan, [In,Out] complex* input, [In,Out] double* output);
|
---|
| 152 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 153 | private static extern void dfftw_execute_split_dft_c2r_(ref IntPtr plan, [In,Out] double* ri, [In,Out] double* ii, [In,Out] double* output);
|
---|
| 154 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 155 | private static extern void dfftw_execute_r2r_(ref IntPtr plan, [In,Out] double* input, [In,Out] double* output);
|
---|
| 156 |
|
---|
| 157 | /************************************ BASIC PLAN EXECUTION & MISC ******************************/
|
---|
| 158 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 159 | private static extern void dfftw_execute_(ref IntPtr plan);
|
---|
| 160 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 161 | private static extern void dfftw_destroy_plan_(ref IntPtr plan);
|
---|
| 162 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 163 | private static extern void dfftw_cleanup_();
|
---|
| 164 | [DllImport("libfftw3-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 165 | private static extern void fftw_set_timelimit(ref double seconds);
|
---|
| 166 | #endregion DOUBLE PRECISION INTERFACE
|
---|
| 167 |
|
---|
| 168 | #region SINGLE PRECISION INTERFACE
|
---|
| 169 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 170 | private static extern void sfftw_plan_dft_1d_(ref IntPtr plan, ref int n, [In,Out] fcomplex* input, [In,Out] fcomplex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
|
---|
| 171 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 172 | private static extern void sfftw_plan_dft_2d_(ref IntPtr plan, ref int nx, ref int ny, [In,Out] fcomplex* input, [In,Out] fcomplex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
|
---|
| 173 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 174 | private static extern void sfftw_plan_dft_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In,Out] fcomplex* input, [In,Out] fcomplex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
|
---|
| 175 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 176 | private static extern void sfftw_plan_dft_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] fcomplex* input, [In,Out] fcomplex* output, ref FFTW_DIRECTION sign, ref FFTW_PLANCREATION flags);
|
---|
| 177 |
|
---|
| 178 | /****************************************************************** REAL-COMPLEX ***/
|
---|
| 179 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 180 | 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);
|
---|
| 181 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 182 | private static extern void sfftw_plan_dft_r2c_2d_(ref IntPtr plan, ref int nx, ref int ny, [In,Out] float* input, [In,Out] fcomplex* output, ref FFTW_PLANCREATION flags);
|
---|
| 183 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 184 | private static extern void sfftw_plan_dft_r2c_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In,Out] float* input, [In,Out] fcomplex* output, ref FFTW_PLANCREATION flags);
|
---|
| 185 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 186 | private static extern void sfftw_plan_dft_r2c_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] float* input, [In,Out] fcomplex* output, ref FFTW_PLANCREATION flags);
|
---|
| 187 |
|
---|
| 188 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 189 | private static extern void sfftw_plan_dft_c2r_1d_(ref IntPtr plan, ref int n, [In,Out] fcomplex* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
|
---|
| 190 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 191 | private static extern void sfftw_plan_dft_c2r_2d_(ref IntPtr plan, ref int nx, ref int ny, [In,Out] fcomplex* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
|
---|
| 192 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 193 | 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);
|
---|
| 194 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 195 | private static extern void sfftw_plan_dft_c2r_(ref IntPtr plan, ref int rank, [In,Out] int[] n, [In,Out] fcomplex* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
|
---|
| 196 |
|
---|
| 197 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 198 | private static extern void sfftw_plan_r2r_1d_(ref IntPtr plan, ref int n, [In,Out] float* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
|
---|
| 199 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 200 | private static extern void sfftw_plan_r2r_2d_(ref IntPtr plan, ref int nx, ref int ny, [In,Out] float* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
|
---|
| 201 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 202 | private static extern void sfftw_plan_r2r_3d_(ref IntPtr plan, ref int nx, ref int ny, ref int nz, [In,Out] float* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
|
---|
| 203 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 204 | 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);
|
---|
| 205 |
|
---|
| 206 | /************************************ ADVANCED INTERFACE *************************************/
|
---|
| 207 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 208 | 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);
|
---|
| 209 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 210 | private static extern void sfftw_plan_many_dft_r2c_(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] fcomplex* output, [In,Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_PLANCREATION flags);
|
---|
| 211 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 212 | private static extern void sfftw_plan_many_dft_c2r_(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] float* output, [In,Out] int[] onembed, ref int ostride, ref int odist, ref FFTW_PLANCREATION flags);
|
---|
| 213 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 214 | 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);
|
---|
| 215 |
|
---|
| 216 | /************************************ GURU INTERFACE *************************************/
|
---|
| 217 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 218 | 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);
|
---|
| 219 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 220 | private static extern void sfftw_plan_guru_split_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] float* ri, [In,Out] float* ii, [In,Out] float* ro, [In,Out] float* io, ref FFTW_PLANCREATION flags);
|
---|
| 221 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 222 | private static extern void sfftw_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] float* input, [In,Out] fcomplex* output, ref FFTW_PLANCREATION flags);
|
---|
| 223 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 224 | private static extern void sfftw_plan_guru_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] fcomplex* input, [In,Out] float* output, ref FFTW_PLANCREATION flags);
|
---|
| 225 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 226 | private static extern void sfftw_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] float* ri, [In,Out] float* ro, [In,Out] float* io, ref FFTW_PLANCREATION flags);
|
---|
| 227 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 228 | 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);
|
---|
| 229 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 230 | 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);
|
---|
| 231 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 232 | private static extern void sfftw_execute_dft_(ref IntPtr plan, [In,Out] fcomplex* input, [In,Out] fcomplex* output);
|
---|
| 233 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 234 | private static extern void sfftw_execute_split_dft_(ref IntPtr plan, [In,Out] float* ri, [In,Out] float* ii, [In,Out] float* ro, [In,Out] float* io);
|
---|
| 235 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 236 | private static extern void sfftw_execute_dft_r2c_(ref IntPtr plan, [In,Out] float* ri, [In,Out] fcomplex* ii);
|
---|
| 237 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 238 | private static extern void sfftw_execute_split_dft_r2c_(ref IntPtr plan, [In,Out] float* input, [In,Out] float* ro, [In,Out] float* ri);
|
---|
| 239 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 240 | private static extern void sfftw_execute_dft_c2r_(ref IntPtr plan, [In,Out] fcomplex* input, [In,Out] float* output);
|
---|
| 241 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 242 | private static extern void sfftw_execute_split_dft_c2r_(ref IntPtr plan, [In,Out] float* ri, [In,Out] float* ii, [In,Out] float* output);
|
---|
| 243 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 244 | private static extern void sfftw_execute_r2r_(ref IntPtr plan, [In,Out] float* input, [In,Out] float* output);
|
---|
| 245 |
|
---|
| 246 | /************************************ BASIC PLAN EXECUTION & MISC ******************************/
|
---|
| 247 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 248 | private static extern void sfftw_execute_(ref IntPtr plan);
|
---|
| 249 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 250 | private static extern void sfftw_destroy_plan_(ref IntPtr plan);
|
---|
| 251 | [DllImport("libfftw3f-3",CallingConvention =CallingConvention.Cdecl),SuppressUnmanagedCodeSecurity]
|
---|
| 252 | private static extern void sfftw_cleanup_();
|
---|
| 253 | #endregion SINGLE PRECISION INTERFACE
|
---|
| 254 | #endregion
|
---|
| 255 |
|
---|
| 256 | #region FFTW CONSTANTS
|
---|
| 257 |
|
---|
| 258 | [FlagsAttribute]
|
---|
| 259 | public enum FFTW_PLANCREATION : uint {
|
---|
| 260 | MEASURE = 0u,
|
---|
| 261 | DESTROY_INPUT = (1U << 0),
|
---|
| 262 | UNALIGNED = (1U << 1),
|
---|
| 263 | CONSERVE_MEMORY = (1U << 2),
|
---|
| 264 | EXHAUSTIVE = (1U << 3), /* NO_EXHAUSTIVE is default */
|
---|
| 265 | PRESERVE_INPUT = (1U << 4), /* cancels FFTW_DESTROY_INPUT */
|
---|
| 266 | PATIENT = (1U << 5), /* IMPATIENT is default */
|
---|
| 267 | ESTIMATE = (1U << 6)
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | public enum FFTW_DIRECTION {
|
---|
| 271 | FORWARD = -1,
|
---|
| 272 | BACKWARDS = 1
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | public enum FFTW_KIND {
|
---|
| 276 | R2HC=0,
|
---|
| 277 | HC2R=1,
|
---|
| 278 | DHT=2,
|
---|
| 279 | REDFT00=3,
|
---|
| 280 | REDFT01=4,
|
---|
| 281 | REDFT10=5,
|
---|
| 282 | REDFT11=6,
|
---|
| 283 | RODFT00=7,
|
---|
| 284 | RODFT01=8,
|
---|
| 285 | RODFT10=9,
|
---|
| 286 | RODFT11=10
|
---|
| 287 | }
|
---|
| 288 | #endregion
|
---|
| 289 |
|
---|
| 290 | #region attributes
|
---|
| 291 | object _lockobject = new object();
|
---|
| 292 | int[] m_n,m_is,m_os, m_hn, m_his, m_hos;
|
---|
| 293 | //List<int> m_tmpDims = new List<int>(10);
|
---|
| 294 | #endregion
|
---|
| 295 |
|
---|
| 296 | #region constructor
|
---|
| 297 | public ILFFTW3FFT () {
|
---|
| 298 | // fftw internally caches the plans, so ....
|
---|
| 299 | m_n = new int[10];
|
---|
| 300 | m_is = new int[10];
|
---|
| 301 | m_os = new int[10];
|
---|
| 302 | m_hn = new int[2];
|
---|
| 303 | m_his = new int[2];
|
---|
| 304 | m_hos = new int[2];
|
---|
| 305 | }
|
---|
| 306 | #endregion
|
---|
| 307 |
|
---|
| 308 | #region IILFFT Member - 1-D
|
---|
| 309 |
|
---|
| 310 | |
---|
| 311 |
|
---|
| 312 | public ILRetArray< complex > FFTForward1D (ILInArray< double > A, int dim) {
|
---|
| 313 | return FFTForward (A,dim,1);
|
---|
| 314 | }
|
---|
| 315 | |
---|
| 316 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 317 | |
---|
| 318 |
|
---|
| 319 | public ILRetArray< fcomplex > FFTBackward1D (ILInArray< fcomplex > A, int dim) {
|
---|
| 320 | return FFTBackward (A,dim,1);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | public ILRetArray< complex > FFTBackward1D (ILInArray< complex > A, int dim) {
|
---|
| 324 | return FFTBackward (A,dim,1);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | public ILRetArray< fcomplex > FFTForward1D (ILInArray< fcomplex > A, int dim) {
|
---|
| 328 | return FFTForward (A,dim,1);
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | public ILRetArray< fcomplex > FFTForward1D (ILInArray< float > A, int dim) {
|
---|
| 332 | return FFTForward (A,dim,1);
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | public ILRetArray< complex > FFTForward1D (ILInArray< complex > A, int dim) {
|
---|
| 336 | return FFTForward (A,dim,1);
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 340 |
|
---|
| 341 | |
---|
| 342 |
|
---|
| 343 | public ILRetArray< double > FFTBackwSym1D(ILInArray< complex > A, int dim) {
|
---|
| 344 | return ILMath.real(FFTBackward1D(A,dim));
|
---|
| 345 | }
|
---|
| 346 | |
---|
| 347 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 348 | |
---|
| 349 |
|
---|
| 350 | public ILRetArray< float > FFTBackwSym1D(ILInArray< fcomplex > A, int dim) {
|
---|
| 351 | return ILMath.real(FFTBackward1D(A,dim));
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 355 |
|
---|
| 356 | #endregion
|
---|
| 357 |
|
---|
| 358 | #region IILFFT Member - n-D
|
---|
| 359 |
|
---|
| 360 | |
---|
| 361 |
|
---|
| 362 | public ILRetArray< complex > FFTForward (ILInArray< double > A, int nDims) {
|
---|
| 363 | return FFTForward (A,0,nDims);
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | public ILRetArray< complex> FFTForward(ILInArray< double> A, int firstDim, int nDims) {
|
---|
| 367 | using (ILScope.Enter(A)) {
|
---|
| 368 | if (object.Equals(A, null) || nDims < 0 || firstDim < 0)
|
---|
| 369 | throw new ILArgumentException("invalid parameter!");
|
---|
| 370 | if (A.IsEmpty) return ILArray< complex>.empty(A.Size);
|
---|
| 371 | if (A.IsScalar || (A.Size[firstDim] == 1 && nDims == 1))
|
---|
| 372 | return ILMath.tocomplex(A);
|
---|
| 373 | if (nDims > A.Size.NumberOfDimensions)
|
---|
| 374 | nDims = A.Size.NumberOfDimensions;
|
---|
| 375 | // prepare output array
|
---|
| 376 | ILArray< complex> ret = ILMath.tocomplex(A);
|
---|
| 377 | IntPtr plan = IntPtr.Zero;
|
---|
| 378 | int hrank = 2;
|
---|
| 379 | FFTW_DIRECTION dir = FFTW_DIRECTION.FORWARD;
|
---|
| 380 | lock (_lockobject) {
|
---|
| 381 | FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE;
|
---|
| 382 | if (nDims > m_n.Length) resizeCache(nDims);
|
---|
| 383 | for (int i = 0; i < nDims; i++) {
|
---|
| 384 | m_n[i] = A.Size[i + firstDim];
|
---|
| 385 | m_is[i] = A.Size.SequentialIndexDistance(i + firstDim);
|
---|
| 386 | m_os[i] = m_is[i];
|
---|
| 387 | }
|
---|
| 388 | m_hn[0] = A.Size.SequentialIndexDistance(firstDim);
|
---|
| 389 | m_his[0] = 1;
|
---|
| 390 | m_hos[0] = 1;
|
---|
| 391 | m_his[1] = A.Size.SequentialIndexDistance(nDims + firstDim);
|
---|
| 392 | m_hn[1] = A.Size.NumberOfElements / m_his[1];
|
---|
| 393 | m_hos[1] = m_his[1];
|
---|
| 394 | fixed ( complex* retArr = ret.GetArrayForWrite()) {
|
---|
| 395 |
|
---|
| 396 | dfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os,
|
---|
| 397 | ref hrank, m_hn, m_his, m_hos,
|
---|
| 398 | retArr, retArr,
|
---|
| 399 | ref dir, ref flags);
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 | if (plan == IntPtr.Zero)
|
---|
| 403 | throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)");
|
---|
| 404 | dfftw_execute_(ref plan);
|
---|
| 405 | dfftw_destroy_plan_(ref plan);
|
---|
| 406 |
|
---|
| 407 |
|
---|
| 408 | return ret;
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 | |
---|
| 412 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 413 | |
---|
| 414 |
|
---|
| 415 | public ILRetArray< fcomplex > FFTBackward (ILInArray< fcomplex > A, int nDims) {
|
---|
| 416 | return FFTBackward (A,0,nDims);
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | public ILRetArray< fcomplex> FFTBackward(ILInArray< fcomplex> A, int firstDim, int nDims) {
|
---|
| 420 | using (ILScope.Enter(A)) {
|
---|
| 421 | if (object.Equals(A, null) || nDims < 0 || firstDim < 0)
|
---|
| 422 | throw new ILArgumentException("invalid parameter!");
|
---|
| 423 | if (A.IsEmpty) return ILArray< fcomplex>.empty(A.Size);
|
---|
| 424 | if (A.IsScalar || (A.Size[firstDim] == 1 && nDims == 1))
|
---|
| 425 | return A.C;
|
---|
| 426 | if (nDims > A.Size.NumberOfDimensions)
|
---|
| 427 | nDims = A.Size.NumberOfDimensions;
|
---|
| 428 | // prepare output array
|
---|
| 429 | ILArray< fcomplex> ret = A.C;
|
---|
| 430 | IntPtr plan = IntPtr.Zero;
|
---|
| 431 | int hrank = 2;
|
---|
| 432 | FFTW_DIRECTION dir = FFTW_DIRECTION.BACKWARDS;
|
---|
| 433 | lock (_lockobject) {
|
---|
| 434 | FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE;
|
---|
| 435 | if (nDims > m_n.Length) resizeCache(nDims);
|
---|
| 436 | for (int i = 0; i < nDims; i++) {
|
---|
| 437 | m_n[i] = A.Size[i + firstDim];
|
---|
| 438 | m_is[i] = A.Size.SequentialIndexDistance(i + firstDim);
|
---|
| 439 | m_os[i] = m_is[i];
|
---|
| 440 | }
|
---|
| 441 | m_hn[0] = A.Size.SequentialIndexDistance(firstDim);
|
---|
| 442 | m_his[0] = 1;
|
---|
| 443 | m_hos[0] = 1;
|
---|
| 444 | m_his[1] = A.Size.SequentialIndexDistance(nDims + firstDim);
|
---|
| 445 | m_hn[1] = A.Size.NumberOfElements / m_his[1];
|
---|
| 446 | m_hos[1] = m_his[1];
|
---|
| 447 | fixed ( fcomplex* retArr = ret.GetArrayForWrite()) {
|
---|
| 448 |
|
---|
| 449 | sfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os,
|
---|
| 450 | ref hrank, m_hn, m_his, m_hos,
|
---|
| 451 | retArr, retArr,
|
---|
| 452 | ref dir, ref flags);
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | if (plan == IntPtr.Zero)
|
---|
| 456 | throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)");
|
---|
| 457 | dfftw_execute_(ref plan);
|
---|
| 458 | dfftw_destroy_plan_(ref plan);
|
---|
| 459 | ret /= new fcomplex(m_his[1]/m_hn[0],0.0f);
|
---|
| 460 | return ret;
|
---|
| 461 | }
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | public ILRetArray< complex > FFTBackward (ILInArray< complex > A, int nDims) {
|
---|
| 465 | return FFTBackward (A,0,nDims);
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | public ILRetArray< complex> FFTBackward(ILInArray< complex> A, int firstDim, int nDims) {
|
---|
| 469 | using (ILScope.Enter(A)) {
|
---|
| 470 | if (object.Equals(A, null) || nDims < 0 || firstDim < 0)
|
---|
| 471 | throw new ILArgumentException("invalid parameter!");
|
---|
| 472 | if (A.IsEmpty) return ILArray< complex>.empty(A.Size);
|
---|
| 473 | if (A.IsScalar || (A.Size[firstDim] == 1 && nDims == 1))
|
---|
| 474 | return A.C;
|
---|
| 475 | if (nDims > A.Size.NumberOfDimensions)
|
---|
| 476 | nDims = A.Size.NumberOfDimensions;
|
---|
| 477 | // prepare output array
|
---|
| 478 | ILArray< complex> ret = A.C;
|
---|
| 479 | IntPtr plan = IntPtr.Zero;
|
---|
| 480 | int hrank = 2;
|
---|
| 481 | FFTW_DIRECTION dir = FFTW_DIRECTION.BACKWARDS;
|
---|
| 482 | lock (_lockobject) {
|
---|
| 483 | FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE;
|
---|
| 484 | if (nDims > m_n.Length) resizeCache(nDims);
|
---|
| 485 | for (int i = 0; i < nDims; i++) {
|
---|
| 486 | m_n[i] = A.Size[i + firstDim];
|
---|
| 487 | m_is[i] = A.Size.SequentialIndexDistance(i + firstDim);
|
---|
| 488 | m_os[i] = m_is[i];
|
---|
| 489 | }
|
---|
| 490 | m_hn[0] = A.Size.SequentialIndexDistance(firstDim);
|
---|
| 491 | m_his[0] = 1;
|
---|
| 492 | m_hos[0] = 1;
|
---|
| 493 | m_his[1] = A.Size.SequentialIndexDistance(nDims + firstDim);
|
---|
| 494 | m_hn[1] = A.Size.NumberOfElements / m_his[1];
|
---|
| 495 | m_hos[1] = m_his[1];
|
---|
| 496 | fixed ( complex* retArr = ret.GetArrayForWrite()) {
|
---|
| 497 |
|
---|
| 498 | dfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os,
|
---|
| 499 | ref hrank, m_hn, m_his, m_hos,
|
---|
| 500 | retArr, retArr,
|
---|
| 501 | ref dir, ref flags);
|
---|
| 502 | }
|
---|
| 503 | }
|
---|
| 504 | if (plan == IntPtr.Zero)
|
---|
| 505 | throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)");
|
---|
| 506 | dfftw_execute_(ref plan);
|
---|
| 507 | dfftw_destroy_plan_(ref plan);
|
---|
| 508 | ret /= new complex(m_his[1]/m_hn[0],0.0f);
|
---|
| 509 | return ret;
|
---|
| 510 | }
|
---|
| 511 | }
|
---|
| 512 |
|
---|
| 513 | public ILRetArray< fcomplex > FFTForward (ILInArray< fcomplex > A, int nDims) {
|
---|
| 514 | return FFTForward (A,0,nDims);
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | public ILRetArray< fcomplex> FFTForward(ILInArray< fcomplex> A, int firstDim, int nDims) {
|
---|
| 518 | using (ILScope.Enter(A)) {
|
---|
| 519 | if (object.Equals(A, null) || nDims < 0 || firstDim < 0)
|
---|
| 520 | throw new ILArgumentException("invalid parameter!");
|
---|
| 521 | if (A.IsEmpty) return ILArray< fcomplex>.empty(A.Size);
|
---|
| 522 | if (A.IsScalar || (A.Size[firstDim] == 1 && nDims == 1))
|
---|
| 523 | return A.C;
|
---|
| 524 | if (nDims > A.Size.NumberOfDimensions)
|
---|
| 525 | nDims = A.Size.NumberOfDimensions;
|
---|
| 526 | // prepare output array
|
---|
| 527 | ILArray< fcomplex> ret = A.C;
|
---|
| 528 | IntPtr plan = IntPtr.Zero;
|
---|
| 529 | int hrank = 2;
|
---|
| 530 | FFTW_DIRECTION dir = FFTW_DIRECTION.FORWARD;
|
---|
| 531 | lock (_lockobject) {
|
---|
| 532 | FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE;
|
---|
| 533 | if (nDims > m_n.Length) resizeCache(nDims);
|
---|
| 534 | for (int i = 0; i < nDims; i++) {
|
---|
| 535 | m_n[i] = A.Size[i + firstDim];
|
---|
| 536 | m_is[i] = A.Size.SequentialIndexDistance(i + firstDim);
|
---|
| 537 | m_os[i] = m_is[i];
|
---|
| 538 | }
|
---|
| 539 | m_hn[0] = A.Size.SequentialIndexDistance(firstDim);
|
---|
| 540 | m_his[0] = 1;
|
---|
| 541 | m_hos[0] = 1;
|
---|
| 542 | m_his[1] = A.Size.SequentialIndexDistance(nDims + firstDim);
|
---|
| 543 | m_hn[1] = A.Size.NumberOfElements / m_his[1];
|
---|
| 544 | m_hos[1] = m_his[1];
|
---|
| 545 | fixed ( fcomplex* retArr = ret.GetArrayForWrite()) {
|
---|
| 546 |
|
---|
| 547 | sfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os,
|
---|
| 548 | ref hrank, m_hn, m_his, m_hos,
|
---|
| 549 | retArr, retArr,
|
---|
| 550 | ref dir, ref flags);
|
---|
| 551 | }
|
---|
| 552 | }
|
---|
| 553 | if (plan == IntPtr.Zero)
|
---|
| 554 | throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)");
|
---|
| 555 | dfftw_execute_(ref plan);
|
---|
| 556 | dfftw_destroy_plan_(ref plan);
|
---|
| 557 |
|
---|
| 558 | return ret;
|
---|
| 559 | }
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 | public ILRetArray< fcomplex > FFTForward (ILInArray< float > A, int nDims) {
|
---|
| 563 | return FFTForward (A,0,nDims);
|
---|
| 564 | }
|
---|
| 565 |
|
---|
| 566 | public ILRetArray< fcomplex> FFTForward(ILInArray< float> A, int firstDim, int nDims) {
|
---|
| 567 | using (ILScope.Enter(A)) {
|
---|
| 568 | if (object.Equals(A, null) || nDims < 0 || firstDim < 0)
|
---|
| 569 | throw new ILArgumentException("invalid parameter!");
|
---|
| 570 | if (A.IsEmpty) return ILArray< fcomplex>.empty(A.Size);
|
---|
| 571 | if (A.IsScalar || (A.Size[firstDim] == 1 && nDims == 1))
|
---|
| 572 | return ILMath.tofcomplex(A);
|
---|
| 573 | if (nDims > A.Size.NumberOfDimensions)
|
---|
| 574 | nDims = A.Size.NumberOfDimensions;
|
---|
| 575 | // prepare output array
|
---|
| 576 | ILArray< fcomplex> ret = ILMath.tofcomplex(A);
|
---|
| 577 | IntPtr plan = IntPtr.Zero;
|
---|
| 578 | int hrank = 2;
|
---|
| 579 | FFTW_DIRECTION dir = FFTW_DIRECTION.FORWARD;
|
---|
| 580 | lock (_lockobject) {
|
---|
| 581 | FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE;
|
---|
| 582 | if (nDims > m_n.Length) resizeCache(nDims);
|
---|
| 583 | for (int i = 0; i < nDims; i++) {
|
---|
| 584 | m_n[i] = A.Size[i + firstDim];
|
---|
| 585 | m_is[i] = A.Size.SequentialIndexDistance(i + firstDim);
|
---|
| 586 | m_os[i] = m_is[i];
|
---|
| 587 | }
|
---|
| 588 | m_hn[0] = A.Size.SequentialIndexDistance(firstDim);
|
---|
| 589 | m_his[0] = 1;
|
---|
| 590 | m_hos[0] = 1;
|
---|
| 591 | m_his[1] = A.Size.SequentialIndexDistance(nDims + firstDim);
|
---|
| 592 | m_hn[1] = A.Size.NumberOfElements / m_his[1];
|
---|
| 593 | m_hos[1] = m_his[1];
|
---|
| 594 | fixed ( fcomplex* retArr = ret.GetArrayForWrite()) {
|
---|
| 595 |
|
---|
| 596 | sfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os,
|
---|
| 597 | ref hrank, m_hn, m_his, m_hos,
|
---|
| 598 | retArr, retArr,
|
---|
| 599 | ref dir, ref flags);
|
---|
| 600 | }
|
---|
| 601 | }
|
---|
| 602 | if (plan == IntPtr.Zero)
|
---|
| 603 | throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)");
|
---|
| 604 | dfftw_execute_(ref plan);
|
---|
| 605 | dfftw_destroy_plan_(ref plan);
|
---|
| 606 |
|
---|
| 607 | return ret;
|
---|
| 608 | }
|
---|
| 609 | }
|
---|
| 610 |
|
---|
| 611 | public ILRetArray< complex > FFTForward (ILInArray< complex > A, int nDims) {
|
---|
| 612 | return FFTForward (A,0,nDims);
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | public ILRetArray< complex> FFTForward(ILInArray< complex> A, int firstDim, int nDims) {
|
---|
| 616 | using (ILScope.Enter(A)) {
|
---|
| 617 | if (object.Equals(A, null) || nDims < 0 || firstDim < 0)
|
---|
| 618 | throw new ILArgumentException("invalid parameter!");
|
---|
| 619 | if (A.IsEmpty) return ILArray< complex>.empty(A.Size);
|
---|
| 620 | if (A.IsScalar || (A.Size[firstDim] == 1 && nDims == 1))
|
---|
| 621 | return A.C;
|
---|
| 622 | if (nDims > A.Size.NumberOfDimensions)
|
---|
| 623 | nDims = A.Size.NumberOfDimensions;
|
---|
| 624 | // prepare output array
|
---|
| 625 | ILArray< complex> ret = A.C;
|
---|
| 626 | IntPtr plan = IntPtr.Zero;
|
---|
| 627 | int hrank = 2;
|
---|
| 628 | FFTW_DIRECTION dir = FFTW_DIRECTION.FORWARD;
|
---|
| 629 | lock (_lockobject) {
|
---|
| 630 | FFTW_PLANCREATION flags = FFTW_PLANCREATION.ESTIMATE;
|
---|
| 631 | if (nDims > m_n.Length) resizeCache(nDims);
|
---|
| 632 | for (int i = 0; i < nDims; i++) {
|
---|
| 633 | m_n[i] = A.Size[i + firstDim];
|
---|
| 634 | m_is[i] = A.Size.SequentialIndexDistance(i + firstDim);
|
---|
| 635 | m_os[i] = m_is[i];
|
---|
| 636 | }
|
---|
| 637 | m_hn[0] = A.Size.SequentialIndexDistance(firstDim);
|
---|
| 638 | m_his[0] = 1;
|
---|
| 639 | m_hos[0] = 1;
|
---|
| 640 | m_his[1] = A.Size.SequentialIndexDistance(nDims + firstDim);
|
---|
| 641 | m_hn[1] = A.Size.NumberOfElements / m_his[1];
|
---|
| 642 | m_hos[1] = m_his[1];
|
---|
| 643 | fixed ( complex* retArr = ret.GetArrayForWrite()) {
|
---|
| 644 |
|
---|
| 645 | dfftw_plan_guru_dft_(ref plan, ref nDims, m_n, m_is, m_os,
|
---|
| 646 | ref hrank, m_hn, m_his, m_hos,
|
---|
| 647 | retArr, retArr,
|
---|
| 648 | ref dir, ref flags);
|
---|
| 649 | }
|
---|
| 650 | }
|
---|
| 651 | if (plan == IntPtr.Zero)
|
---|
| 652 | throw new ILInvalidOperationException("error creating plan for fftw3 (guru interface)");
|
---|
| 653 | dfftw_execute_(ref plan);
|
---|
| 654 | dfftw_destroy_plan_(ref plan);
|
---|
| 655 |
|
---|
| 656 | return ret;
|
---|
| 657 | }
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 661 |
|
---|
| 662 | |
---|
| 663 |
|
---|
| 664 | public ILRetArray< double > FFTBackwSym(ILInArray< complex > A, int nDims) {
|
---|
| 665 | return ILMath.real(FFTBackward(A,nDims));
|
---|
| 666 | }
|
---|
| 667 | |
---|
| 668 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 669 | |
---|
| 670 |
|
---|
| 671 | public ILRetArray< float > FFTBackwSym(ILInArray< fcomplex > A, int nDims) {
|
---|
| 672 | return ILMath.real(FFTBackward(A,nDims));
|
---|
| 673 | }
|
---|
| 674 |
|
---|
| 675 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 676 |
|
---|
| 677 | #endregion
|
---|
| 678 |
|
---|
| 679 | #region IILFFT Member - Misc
|
---|
| 680 |
|
---|
| 681 | public bool CachePlans {
|
---|
| 682 | get {
|
---|
| 683 | return true;
|
---|
| 684 | }
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | public void FreePlans() {
|
---|
| 688 | FreeAllDescriptors();
|
---|
| 689 | }
|
---|
| 690 |
|
---|
| 691 | public bool SpeedyHermitian {
|
---|
| 692 | get { return false; }
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | #endregion
|
---|
| 696 |
|
---|
| 697 | #region private helper
|
---|
| 698 | private void FreeAllDescriptors() {
|
---|
| 699 | try {
|
---|
| 700 | dfftw_cleanup_();
|
---|
| 701 | sfftw_cleanup_();
|
---|
| 702 | } catch (Exception) { }
|
---|
| 703 | }
|
---|
| 704 | private void resizeCache(int size) {
|
---|
| 705 | if (m_n.Length >= size) return;
|
---|
| 706 | m_n = new int[size];
|
---|
| 707 | m_is = new int[size];
|
---|
| 708 | m_os = new int[size];
|
---|
| 709 | }
|
---|
| 710 | #endregion
|
---|
| 711 |
|
---|
| 712 | #region IDisposable Member
|
---|
| 713 |
|
---|
| 714 | public void Dispose() {
|
---|
| 715 | Dispose(true);
|
---|
| 716 | GC.SuppressFinalize(this);
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 | public virtual void Dispose (bool manual) {
|
---|
| 720 | if (manual) {
|
---|
| 721 | FreeAllDescriptors();
|
---|
| 722 | }
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | ~ILFFTW3FFT () {
|
---|
| 726 | Dispose(true);
|
---|
| 727 | }
|
---|
| 728 | #endregion
|
---|
| 729 |
|
---|
| 730 | }
|
---|
| 731 | }
|
---|