public void Dft_Convolution_Many() { var a = Enumerable.Range(3, 1 << 16).Select(x => (long)x).ToArray(); var b = Enumerable.Range(7, 1 << 16).Select(x => (long)x).ToArray(); Dft.Convolution(a, b); }
protected override Task ProcessRemoving(CancellationToken ct) { return(Task.Run(async() => { var p = ReadParameters(); var algorithm = new Dft(p); var result = algorithm.RemoveWatermark(ct); await ShowAlgorithmOutput(result); })); }
public void Convolution() { var a = new long[] { 1, 2, 3, 4 }; var b = new long[] { 5, 6, 7, 8, 9 }; var expected = new long[] { 5, 16, 34, 60, 70, 70, 59, 36 }; CollectionAssert.AreEqual(expected, Dft.Convolution(a, b)); CollectionAssert.AreEqual(expected, Dft0.Convolution(a, b)); CollectionAssert.AreEqual(expected, Ntt.Convolution(a, b)); CollectionAssert.AreEqual(expected, Ntt0.Convolution(a, b)); }
// 長さは n 以下で OK。 public static Complex[] Convolution(Complex[] a, Complex[] b) { var dft = new Dft(a.Length + b.Length - 1); var fa = dft.Fft(a); var fb = dft.Fft(b); for (int i = 0; i < dft.n; ++i) { fa[i] *= fb[i]; } return(dft.Fft(fa, true)); }
public void Dft_Fft_Many() { var n = 1 << 16; var a = Enumerable.Range(3, n).ToArray(); var c = Array.ConvertAll(a, x => new Complex(x, 0)); var dft = new Dft(n); var t = dft.Fft(c); var r = dft.Fft(t, true).ToInt(); CollectionAssert.AreEqual(a, r); }
protected override Task ProcessAdding(CancellationToken ct) { return(Task.Run(async() => { ct.ThrowIfCancellationRequested(); var p = ReadParameters(); ct.ThrowIfCancellationRequested(); var algorithm = new Dft(p); var result = algorithm.AddWatermark(ct); await ShowAlgorithmOutput(result); })); }
public void Setup() { originalBitmap = new Bitmap(resourcesPath + "c_corgi.png"); watermarkBitmap = new Bitmap(resourcesPath + "w_tekst_dolny.png"); expectedDftBitmap = new Bitmap(myResourcesPath + "original_fourier_test.png"); expectedDftWatermarkedBitmap = new Bitmap(myResourcesPath + "fourier_watermarked_test.png"); expectedWatermarkedBitmap = new Bitmap(myResourcesPath + "dft_watermarked_test.png"); key = 10; alpha = 0.01M; parameters = new DftParameters(originalBitmap.TransformToEffectiveBitmap(), watermarkBitmap.TransformToEffectiveBitmap(), null, key, alpha); algorithm = new Dft(parameters); }
public void Dft_Fft() { var n = 1 << 4; var a = Enumerable.Range(3, n).ToArray(); var c = Array.ConvertAll(a, x => new Complex(x, 0)); var t0 = Dft0.Naive(c); var r0 = Dft0.Naive(t0, true).ToInt(); var t1 = Dft0.Fft(c); var r1 = Dft0.Fft(t1, true).ToInt(); var dft = new Dft(n); var t2 = dft.Fft(c); var r2 = dft.Fft(t2, true).ToInt(); CollectionAssert.AreEqual(a, r0); CollectionAssert.AreEqual(a, r1); CollectionAssert.AreEqual(a, r2); }
static void Main() { var h = ReadL(); long n = h[0], m = h[1]; var a = ReadL(); var c = Tally(a, a.Max()); var conv = Dft.Convolution(c, c); long r = 0, count = 0; for (int x = conv.Length - 1; x >= 0 && count < m; x--) { if (conv[x] == 0) { continue; } var nc = Math.Min(m, count + conv[x]); r += x * (nc - count); count = nc; } Console.WriteLine(r); }
public void TestOptimalDftSize() { var optimalSize = Dft.GetOptimalSize(98); Assert.AreEqual(100, optimalSize); }