FftwPlanC2C.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #region Copyright and License
  2. /*
  3. This file is part of FFTW.NET, a wrapper around the FFTW library
  4. for the .NET framework.
  5. Copyright (C) 2017 Tobias Meyer
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. #endregion
  16. using System;
  17. using System.Numerics;
  18. namespace FFTW.NET
  19. {
  20. public sealed class FftwPlanC2C : FftwPlan<Complex, Complex>
  21. {
  22. public IPinnedArray<Complex> Input => Buffer1;
  23. public IPinnedArray<Complex> Output => Buffer2;
  24. FftwPlanC2C(IPinnedArray<Complex> input, IPinnedArray<Complex> output, int rank, int[] n, bool verifyRankAndSize, DftDirection direction, PlannerFlags plannerFlags, int nThreads)
  25. : base(input, output, rank, n, verifyRankAndSize, direction, plannerFlags, nThreads) { }
  26. protected override IntPtr GetPlan(int rank, int[] n, IntPtr input, IntPtr output, DftDirection direction, PlannerFlags plannerFlags)
  27. {
  28. return FftwInterop.GetDelegate<FftwInterop.fftw_plan_dft>()(rank, n, input, output, direction, plannerFlags);
  29. }
  30. protected override void VerifyRankAndSize(IPinnedArray<Complex> input, IPinnedArray<Complex> output)
  31. {
  32. if (input.Rank != output.Rank)
  33. throw new ArgumentException($"{nameof(input)} and {nameof(output)} must have the same rank and size.");
  34. for (int i = 0; i < input.Rank; i++)
  35. {
  36. if (input.GetLength(i) != output.GetLength(i))
  37. throw new ArgumentException($"{nameof(input)} and {nameof(output)} must have the same rank and size.");
  38. }
  39. }
  40. protected override void VerifyMinSize(IPinnedArray<Complex> input, IPinnedArray<Complex> output, int[] n)
  41. {
  42. int size = Utils.GetTotalSize(n);
  43. if (input.Length < size)
  44. throw new ArgumentException($"{nameof(input)} is too small.");
  45. if (output.Length < size)
  46. throw new ArgumentException($"{nameof(output)} is too small.");
  47. }
  48. /// <summary>
  49. /// Initializes a new plan using the provided input and output buffers.
  50. /// These buffers may be overwritten during initialization.
  51. /// </summary>
  52. public static FftwPlanC2C Create(IPinnedArray<Complex> input, IPinnedArray<Complex> output, DftDirection direction, PlannerFlags plannerFlags = PlannerFlags.Default, int nThreads = 1)
  53. {
  54. FftwPlanC2C plan = new FftwPlanC2C(input, output, input.Rank, input.GetSize(), true, direction, plannerFlags, nThreads);
  55. if (plan.IsZero)
  56. return null;
  57. return plan;
  58. }
  59. internal static FftwPlanC2C Create(IPinnedArray<Complex> input, IPinnedArray<Complex> output, int rank, int[] n, DftDirection direction, PlannerFlags plannerFlags, int nThreads)
  60. {
  61. FftwPlanC2C plan = new FftwPlanC2C(input, output, rank, n, false, direction, plannerFlags, nThreads);
  62. if (plan.IsZero)
  63. return null;
  64. return plan;
  65. }
  66. }
  67. }