예제 #1
0
        public FftwArray(params int[] lengths)
        {
            _lengths = lengths;
            long size = LongLength * Marshal.SizeOf <T>();

            _ptr = FftwInterop.fftw_malloc(new IntPtr(size));
            GC.AddMemoryPressure(size);
        }
예제 #2
0
파일: FftwPlan.cs 프로젝트: zlwind/FFTW.NET
        public void Execute()
        {
            if (_plan == IntPtr.Zero)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            FftwInterop.fftw_execute(_plan);
        }
예제 #3
0
        public static string fftw_export_wisdom_to_string()
        {
            // We cannot use the fftw_export_wisdom_to_string function here
            // because we have no way of releasing the returned memory.
            StringBuilder sb = new StringBuilder();

            FftwInterop.WriteCharHandler writeChar = (c, ptr) => sb.Append((char)c);
            FftwInterop.fftw_export_wisdom(writeChar, IntPtr.Zero);
            return(sb.ToString());
        }
예제 #4
0
 public void Dispose()
 {
     if (_ptr == IntPtr.Zero)
     {
         return;
     }
     FftwInterop.fftw_free(_ptr);
     _ptr = IntPtr.Zero;
     GC.RemoveMemoryPressure(LongLength * Marshal.SizeOf <T>());
 }
예제 #5
0
 protected override IntPtr GetPlan(int rank, int[] n, IntPtr bufferReal, IntPtr bufferComplex, DftDirection direction, PlannerFlags plannerFlags)
 {
     if (direction == DftDirection.Forwards)
     {
         return(FftwInterop.fftw_plan_dft_r2c(rank, n, bufferReal, bufferComplex, plannerFlags));
     }
     else
     {
         return(FftwInterop.fftw_plan_dft_c2r(rank, n, bufferComplex, bufferReal, plannerFlags));
     }
 }
예제 #6
0
파일: FftwPlan.cs 프로젝트: zlwind/FFTW.NET
 public void Dispose()
 {
     if (_plan == IntPtr.Zero)
     {
         return;
     }
     lock (FftwInterop.Lock)
     {
         if (_plan == IntPtr.Zero)
         {
             return;
         }
         FftwInterop.fftw_destroy_plan(_plan);
         _plan = IntPtr.Zero;
     }
 }
예제 #7
0
        static string GetVersion()
        {
            const string VersionPrefix = "fftw-";
            const byte   WhiteSpace    = (byte)' ';

            byte[]        prefix = Encoding.ASCII.GetBytes(VersionPrefix);
            int           i      = 0;
            StringBuilder sb     = new StringBuilder();

            FftwInterop.WriteCharHandler writeChar = (c, ptr) =>
            {
                if (i < 0)
                {
                    return;
                }

                if (i == VersionPrefix.Length)
                {
                    if (c == WhiteSpace)
                    {
                        i = -1;
                    }
                    else
                    {
                        sb.Append((char)c);
                    }
                }
                else if (c == prefix[i])
                {
                    i++;
                }
                else
                {
                    i = 0;
                }
            };
            // This is only called on initialization, so no synchronization/lock is required
            FftwInterop.fftw_export_wisdom(writeChar, IntPtr.Zero);
            return(sb.ToString());
        }
예제 #8
0
파일: FftwPlan.cs 프로젝트: zlwind/FFTW.NET
        internal protected FftwPlan(IPinnedArray <T1> buffer1, IPinnedArray <T2> buffer2, int rank, int[] n, bool verifyRankAndSize, DftDirection direction, PlannerFlags plannerFlags, int nThreads)
        {
            if (!FftwInterop.IsAvailable)
            {
                throw new InvalidOperationException($"{nameof(FftwInterop.IsAvailable)} returns false.");
            }

            if (buffer1.IsDisposed)
            {
                throw new ObjectDisposedException(nameof(buffer1));
            }
            if (buffer2.IsDisposed)
            {
                throw new ObjectDisposedException(nameof(buffer2));
            }

            if (verifyRankAndSize)
            {
                VerifyRankAndSize(buffer1, buffer2);
            }
            else
            {
                VerifyMinSize(buffer1, buffer2, n);
            }

            if (nThreads < 1)
            {
                nThreads = Environment.ProcessorCount;
            }

            _buffer1 = buffer1;
            _buffer2 = buffer2;
            _plan    = IntPtr.Zero;

            lock (FftwInterop.Lock)
            {
                FftwInterop.fftw_plan_with_nthreads(nThreads);
                _plan = GetPlan(rank, n, _buffer1.Pointer, _buffer2.Pointer, direction, plannerFlags);
            }
        }
예제 #9
0
 protected override IntPtr GetPlan(int rank, int[] n, IntPtr input, IntPtr output, DftDirection direction, PlannerFlags plannerFlags)
 {
     return(FftwInterop.fftw_plan_dft(rank, n, input, output, direction, plannerFlags));
 }
예제 #10
0
 /// <summary>
 /// Clears the current wisdom.
 /// </summary>
 /// <seealso cref="http://www.fftw.org/fftw3_doc/Forgetting-Wisdom.html#Forgetting-Wisdom"/>
 public static void Clear()
 {
     lock (FftwInterop.Lock) { FftwInterop.fftw_forget_wisdom(); }
 }
예제 #11
0
 /// <summary>
 /// Imports wisdom from a file. The Current accumulated wisdom is replaced.
 /// Wisdom is hardware specific, thus importing wisdom created with different hardware
 /// can result in sub-optimal plans and should not be done.
 /// <seealso cref="http://www.fftw.org/fftw3_doc/Wisdom-Import.html#Wisdom-Import"/>
 /// <seealso cref="http://www.fftw.org/fftw3_doc/Caveats-in-Using-Wisdom.html#Caveats-in-Using-Wisdom"/>
 public static bool Import(string filename)
 {
     lock (FftwInterop.Lock) { return(FftwInterop.fftw_import_wisdom_from_filename(filename)); }
 }
예제 #12
0
 /// <summary>
 /// Exports the accumulated wisdom to a file.
 /// </summary>
 /// <seealso cref="http://www.fftw.org/fftw3_doc/Wisdom-Export.html#Wisdom-Export"/>
 /// <seealso cref="http://www.fftw.org/fftw3_doc/Caveats-in-Using-Wisdom.html#Caveats-in-Using-Wisdom"/>
 public static bool Export(string filename)
 {
     lock (FftwInterop.Lock) { return(FftwInterop.fftw_export_wisdom_to_filename(filename)); }
 }