diff --git a/src/Numerics.Tests/IntegralTransformsTests/FourierTest.cs b/src/Numerics.Tests/IntegralTransformsTests/FourierTest.cs index 53e2e529..78bd4b59 100644 --- a/src/Numerics.Tests/IntegralTransformsTests/FourierTest.cs +++ b/src/Numerics.Tests/IntegralTransformsTests/FourierTest.cs @@ -3,7 +3,7 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // -// Copyright (c) 2009-2016 Math.NET +// Copyright (c) 2009-2018 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -29,7 +29,6 @@ using System; using System.Numerics; -using MathNet.Numerics.Distributions; using MathNet.Numerics.IntegralTransforms; using NUnit.Framework; @@ -41,14 +40,6 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests [TestFixture, Category("FFT")] public class FourierTest { - /// - /// Continuous uniform distribution. - /// - IContinuousDistribution GetUniform(int seed) - { - return new ContinuousUniform(-1, 1, new System.Random(seed)); - } - /// /// Naive transforms real sine correctly. /// @@ -58,28 +49,28 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.PeriodicMap(16, w => new Complex32((float)Math.Sin(w), 0), 16, 1.0, Constants.Pi2); // real-odd transforms to imaginary odd - var spectrum = ReferenceDiscreteFourierTransform.NaiveForward(samples, FourierOptions.Matlab); + ReferenceDiscreteFourierTransform.Forward(samples, FourierOptions.Matlab); // all real components must be zero - foreach (var c in spectrum) + foreach (var c in samples) { Assert.AreEqual(0, c.Real, 1e-6, "real"); } // all imaginary components except second and last musth be zero - for (var i = 0; i < spectrum.Length; i++) + for (var i = 0; i < samples.Length; i++) { if (i == 1) { - Assert.AreEqual(-8, spectrum[i].Imaginary, 1e-12, "imag second"); + Assert.AreEqual(-8, samples[i].Imaginary, 1e-12, "imag second"); } - else if (i == spectrum.Length - 1) + else if (i == samples.Length - 1) { - Assert.AreEqual(8, spectrum[i].Imaginary, 1e-12, "imag last"); + Assert.AreEqual(8, samples[i].Imaginary, 1e-12, "imag last"); } else { - Assert.AreEqual(0, spectrum[i].Imaginary, 1e-6, "imag"); + Assert.AreEqual(0, samples[i].Imaginary, 1e-6, "imag"); } } } @@ -93,28 +84,28 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.PeriodicMap(16, w => new Complex(Math.Sin(w), 0), 16, 1.0, Constants.Pi2); // real-odd transforms to imaginary odd - var spectrum = ReferenceDiscreteFourierTransform.NaiveForward(samples, FourierOptions.Matlab); + ReferenceDiscreteFourierTransform.Forward(samples, FourierOptions.Matlab); // all real components must be zero - foreach (var c in spectrum) + foreach (var c in samples) { Assert.AreEqual(0, c.Real, 1e-12, "real"); } // all imaginary components except second and last musth be zero - for (var i = 0; i < spectrum.Length; i++) + for (var i = 0; i < samples.Length; i++) { if (i == 1) { - Assert.AreEqual(-8, spectrum[i].Imaginary, 1e-12, "imag second"); + Assert.AreEqual(-8, samples[i].Imaginary, 1e-12, "imag second"); } - else if (i == spectrum.Length - 1) + else if (i == samples.Length - 1) { - Assert.AreEqual(8, spectrum[i].Imaginary, 1e-12, "imag last"); + Assert.AreEqual(8, samples[i].Imaginary, 1e-12, "imag last"); } else { - Assert.AreEqual(0, spectrum[i].Imaginary, 1e-12, "imag"); + Assert.AreEqual(0, samples[i].Imaginary, 1e-12, "imag"); } } } diff --git a/src/Numerics.Tests/IntegralTransformsTests/InverseTransformTest.cs b/src/Numerics.Tests/IntegralTransformsTests/InverseTransformTest.cs index 9bb78a94..2b274dea 100644 --- a/src/Numerics.Tests/IntegralTransformsTests/InverseTransformTest.cs +++ b/src/Numerics.Tests/IntegralTransformsTests/InverseTransformTest.cs @@ -3,7 +3,7 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // -// Copyright (c) 2009-2016 Math.NET +// Copyright (c) 2009-2018 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -60,10 +60,10 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var work = new Complex32[samples.Length]; samples.CopyTo(work, 0); - work = ReferenceDiscreteFourierTransform.NaiveForward(work, options); + ReferenceDiscreteFourierTransform.Forward(work, options); Assert.IsFalse(work.ListAlmostEqual(samples, 6)); - work = ReferenceDiscreteFourierTransform.NaiveInverse(work, options); + ReferenceDiscreteFourierTransform.Inverse(work, options); AssertHelpers.AlmostEqual(samples, work, 11); } @@ -79,10 +79,10 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var work = new Complex[samples.Length]; samples.CopyTo(work, 0); - work = ReferenceDiscreteFourierTransform.NaiveForward(work, options); + ReferenceDiscreteFourierTransform.Forward(work, options); Assert.IsFalse(work.ListAlmostEqual(samples, 6)); - work = ReferenceDiscreteFourierTransform.NaiveInverse(work, options); + ReferenceDiscreteFourierTransform.Inverse(work, options); AssertHelpers.AlmostEqual(samples, work, 12); } diff --git a/src/Numerics.Tests/IntegralTransformsTests/MatchingNaiveTransformTest.cs b/src/Numerics.Tests/IntegralTransformsTests/MatchingNaiveTransformTest.cs index acf360ae..665763ea 100644 --- a/src/Numerics.Tests/IntegralTransformsTests/MatchingNaiveTransformTest.cs +++ b/src/Numerics.Tests/IntegralTransformsTests/MatchingNaiveTransformTest.cs @@ -3,7 +3,7 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // -// Copyright (c) 2009-2016 Math.NET +// Copyright (c) 2009-2018 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -51,38 +51,6 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests } static void Verify( - Complex32[] samples, - int maximumErrorDecimalPlaces, - FourierOptions options, - Func naive, - Action fast) - { - var spectrumNaive = naive(samples, options); - - var spectrumFast = new Complex32[samples.Length]; - samples.CopyTo(spectrumFast, 0); - fast(spectrumFast, options); - - AssertHelpers.AlmostEqual(spectrumNaive, spectrumFast, maximumErrorDecimalPlaces); - } - - static void Verify( - Complex[] samples, - int maximumErrorDecimalPlaces, - FourierOptions options, - Func naive, - Action fast) - { - var spectrumNaive = naive(samples, options); - - var spectrumFast = new Complex[samples.Length]; - samples.CopyTo(spectrumFast, 0); - fast(spectrumFast, options); - - AssertHelpers.AlmostEqual(spectrumNaive, spectrumFast, maximumErrorDecimalPlaces); - } - - static void VerifyInplace( Complex32[] samples, int maximumErrorDecimalPlaces, FourierOptions options, @@ -100,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests AssertHelpers.AlmostEqual(spectrumExpected, spectrumActual, maximumErrorDecimalPlaces); } - static void VerifyInplace( + static void Verify( Complex[] samples, int maximumErrorDecimalPlaces, FourierOptions options, @@ -129,8 +97,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.PeriodicMap(16, w => new Complex32((float)Math.Sin(w), 0), 16, 1.0, Constants.Pi2); - Verify(samples, 6, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 6, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 6, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 6, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -144,8 +112,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.PeriodicMap(16, w => new Complex(Math.Sin(w), 0), 16, 1.0, Constants.Pi2); - Verify(samples, 12, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 12, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 12, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 12, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -159,8 +127,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex32(0x80, GetUniform(1)); - Verify(samples, 5, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 5, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 5, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 5, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -174,8 +142,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex(0x80, GetUniform(1)); - Verify(samples, 10, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 10, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -189,8 +157,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.PeriodicMap(14, w => new Complex32((float)Math.Sin(w), 0), 14, 1.0, Constants.Pi2); - Verify(samples, 6, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 6, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 6, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 6, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -204,8 +172,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.PeriodicMap(14, w => new Complex(Math.Sin(w), 0), 14, 1.0, Constants.Pi2); - Verify(samples, 12, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 12, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 12, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 12, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -219,8 +187,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex32(0x80, GetUniform(1)); - Verify(samples, 5, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 5, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 5, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 5, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -234,8 +202,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex(0x80, GetUniform(1)); - Verify(samples, 10, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 10, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -249,8 +217,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex32(0x7F, GetUniform(1)); - Verify(samples, 5, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 5, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 5, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 5, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -264,8 +232,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex(0x7F, GetUniform(1)); - Verify(samples, 10, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); - Verify(samples, 10, options, ReferenceDiscreteFourierTransform.NaiveInverse, Fourier.Inverse); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Inverse, Fourier.Inverse); } /// @@ -282,8 +250,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex32(0x7F, GetUniform(1)); - VerifyInplace(samples, 5, options, Fourier.Forward, Fourier.Forward); - VerifyInplace(samples, 5, options, Fourier.Inverse, Fourier.Inverse); + Verify(samples, 5, options, Fourier.Forward, Fourier.Forward); + Verify(samples, 5, options, Fourier.Inverse, Fourier.Inverse); } /// @@ -300,8 +268,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = Generate.RandomComplex(0x7F, GetUniform(1)); - VerifyInplace(samples, 10, options, Fourier.Forward, Fourier.Forward); - VerifyInplace(samples, 10, options, Fourier.Inverse, Fourier.Inverse); + Verify(samples, 10, options, Fourier.Forward, Fourier.Forward); + Verify(samples, 10, options, Fourier.Inverse, Fourier.Inverse); } [TestCase(FourierOptions.Default, 128)] @@ -365,7 +333,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.RandomComplex32(65536, GetUniform(1)); var managed = FourierTransformControl.CreateManaged(); - VerifyInplace(samples, 5, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); + Verify(samples, 5, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); } [Test] @@ -375,7 +343,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.RandomComplex(65536, GetUniform(1)); var managed = FourierTransformControl.CreateManaged(); - VerifyInplace(samples, 10, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); + Verify(samples, 10, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); } [Test] @@ -385,7 +353,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.RandomComplex32(30870, GetUniform(1)); var managed = FourierTransformControl.CreateManaged(); - VerifyInplace(samples, 5, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); + Verify(samples, 5, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); } [Test] @@ -395,7 +363,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.RandomComplex(30870, GetUniform(1)); var managed = FourierTransformControl.CreateManaged(); - VerifyInplace(samples, 10, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); + Verify(samples, 10, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); } [Test] @@ -404,7 +372,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.RandomComplex32(46500, GetUniform(1)); var managed = FourierTransformControl.CreateManaged(); - VerifyInplace(samples, 5, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); + Verify(samples, 5, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); } [Test] @@ -413,7 +381,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var samples = Generate.RandomComplex(46500, GetUniform(1)); var managed = FourierTransformControl.CreateManaged(); - VerifyInplace(samples, 10, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); + Verify(samples, 10, FourierOptions.NoScaling, (s, o) => managed.Forward(s, FourierTransformScaling.NoScaling), (s, o) => FourierTransformControl.Provider.Forward(s, FourierTransformScaling.NoScaling)); } [Test, Explicit("Long-Running")] @@ -422,9 +390,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests // 65536 = 2^16 const FourierOptions options = FourierOptions.NoScaling; var samples = Generate.RandomComplex32(65536, GetUniform(1)); - var naive = ReferenceDiscreteFourierTransform.NaiveForward(samples, options); - Verify(samples, 3, options, (a, b) => naive, Fourier.Forward); + Verify(samples, 3, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); } [Test, Explicit("Long-Running")] @@ -433,9 +400,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests // 65536 = 2^16 const FourierOptions options = FourierOptions.NoScaling; var samples = Generate.RandomComplex(65536, GetUniform(1)); - var naive = ReferenceDiscreteFourierTransform.NaiveForward(samples, options); - Verify(samples, 10, options, (a, b) => naive, Fourier.Forward); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); } [Test, Explicit("Long-Running")] @@ -445,7 +411,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests const FourierOptions options = FourierOptions.NoScaling; var samples = Generate.RandomComplex32(30870, GetUniform(1)); - Verify(samples, 4, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); + Verify(samples, 4, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); } [Test, Explicit("Long-Running")] @@ -454,9 +420,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests // 30870 = 2*3*3*5*7*7*7 const FourierOptions options = FourierOptions.NoScaling; var samples = Generate.RandomComplex(30870, GetUniform(1)); - var naive = ReferenceDiscreteFourierTransform.NaiveForward(samples, options); - Verify(samples, 10, options, (a, b) => naive, Fourier.Forward); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); } [Test, Explicit("Long-Running")] @@ -465,7 +430,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests const FourierOptions options = FourierOptions.NoScaling; var samples = Generate.RandomComplex32(46500, GetUniform(1)); - Verify(samples, 4, options, ReferenceDiscreteFourierTransform.NaiveForward, Fourier.Forward); + Verify(samples, 4, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); } [Test, Explicit("Long-Running")] @@ -473,9 +438,8 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { const FourierOptions options = FourierOptions.NoScaling; var samples = Generate.RandomComplex(46500, GetUniform(1)); - var naive = ReferenceDiscreteFourierTransform.NaiveForward(samples, options); - Verify(samples, 10, options, (a, b) => naive, Fourier.Forward); + Verify(samples, 10, options, ReferenceDiscreteFourierTransform.Forward, Fourier.Forward); } } } diff --git a/src/Numerics.Tests/IntegralTransformsTests/ParsevalTheoremTest.cs b/src/Numerics.Tests/IntegralTransformsTests/ParsevalTheoremTest.cs index 5c7ab325..c61f8185 100644 --- a/src/Numerics.Tests/IntegralTransformsTests/ParsevalTheoremTest.cs +++ b/src/Numerics.Tests/IntegralTransformsTests/ParsevalTheoremTest.cs @@ -3,7 +3,7 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // -// Copyright (c) 2009-2016 Math.NET +// Copyright (c) 2009-2018 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation diff --git a/src/Numerics.Tests/IntegralTransformsTests/ReferenceDiscreteFourierTransform.cs b/src/Numerics.Tests/IntegralTransformsTests/ReferenceDiscreteFourierTransform.cs index 57584016..b6d9d9eb 100644 --- a/src/Numerics.Tests/IntegralTransformsTests/ReferenceDiscreteFourierTransform.cs +++ b/src/Numerics.Tests/IntegralTransformsTests/ReferenceDiscreteFourierTransform.cs @@ -10,53 +10,37 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// /// Naive forward DFT, useful e.g. to verify faster algorithms. /// - /// Time-space sample vector. - /// Fourier Transform Convention Options. - /// Corresponding frequency-space vector. - public static Complex32[] NaiveForward(Complex32[] samples, FourierOptions options = FourierOptions.Default) + public static void Forward(Complex32[] samples, FourierOptions options = FourierOptions.Default) { - var frequencySpace = Naive(samples, SignByOptions(options)); - ForwardScaleByOptions(options, frequencySpace); - return frequencySpace; + Naive(samples, SignByOptions(options)); + ForwardScaleByOptions(options, samples); } /// /// Naive forward DFT, useful e.g. to verify faster algorithms. /// - /// Time-space sample vector. - /// Fourier Transform Convention Options. - /// Corresponding frequency-space vector. - public static Complex[] NaiveForward(Complex[] samples, FourierOptions options = FourierOptions.Default) + public static void Forward(Complex[] samples, FourierOptions options = FourierOptions.Default) { - var frequencySpace = Naive(samples, SignByOptions(options)); - ForwardScaleByOptions(options, frequencySpace); - return frequencySpace; + Naive(samples, SignByOptions(options)); + ForwardScaleByOptions(options, samples); } /// /// Naive inverse DFT, useful e.g. to verify faster algorithms. /// - /// Frequency-space sample vector. - /// Fourier Transform Convention Options. - /// Corresponding time-space vector. - public static Complex32[] NaiveInverse(Complex32[] spectrum, FourierOptions options = FourierOptions.Default) + public static void Inverse(Complex32[] spectrum, FourierOptions options = FourierOptions.Default) { - var timeSpace = Naive(spectrum, -SignByOptions(options)); - InverseScaleByOptions(options, timeSpace); - return timeSpace; + Naive(spectrum, -SignByOptions(options)); + InverseScaleByOptions(options, spectrum); } /// /// Naive inverse DFT, useful e.g. to verify faster algorithms. /// - /// Frequency-space sample vector. - /// Fourier Transform Convention Options. - /// Corresponding time-space vector. - public static Complex[] NaiveInverse(Complex[] spectrum, FourierOptions options = FourierOptions.Default) + public static void Inverse(Complex[] spectrum, FourierOptions options = FourierOptions.Default) { - var timeSpace = Naive(spectrum, -SignByOptions(options)); - InverseScaleByOptions(options, timeSpace); - return timeSpace; + Naive(spectrum, -SignByOptions(options)); + InverseScaleByOptions(options, spectrum); } /// @@ -65,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// Time-space sample vector. /// Fourier series exponent sign. /// Corresponding frequency-space vector. - static Complex32[] Naive(Complex32[] samples, int exponentSign) + static void Naive(Complex32[] samples, int exponentSign) { var w0 = exponentSign * Constants.Pi2 / samples.Length; var spectrum = new Complex32[samples.Length]; @@ -86,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests } }); - return spectrum; + spectrum.Copy(samples); } /// @@ -95,7 +79,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// Time-space sample vector. /// Fourier series exponent sign. /// Corresponding frequency-space vector. - static Complex[] Naive(Complex[] samples, int exponentSign) + static void Naive(Complex[] samples, int exponentSign) { var w0 = exponentSign * Constants.Pi2 / samples.Length; var spectrum = new Complex[samples.Length]; @@ -116,7 +100,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests } }); - return spectrum; + spectrum.Copy(samples); } ///