public void ConvolutionTestMethod() { const int count = 10; var values = new double[count]; var vxv = new double[2 * values.Length - 1]; Array.Clear(values, 0, values.Length); Array.Clear(vxv, 0, vxv.Length); BinomialBuilder.GetDoubles(values); for (int i = 0; i < values.Length; i++) { for (int j = 0; j < values.Length; j++) { vxv[i + j] += values[i] * values[j]; } } var fxf = new double[2 * values.Length]; ConvolutionBuilder.Convolution(values, fxf); Console.WriteLine( string.Join(Environment.NewLine, vxv.Zip(fxf, (x, y) => string.Format("{0} - {1} = {2}", x, y, x - y))) + Environment.NewLine); Assert.IsTrue(vxv.Zip(fxf, (x, y) => x - y).All(x => Math.Abs(x) < 0.0001)); }
public void BinomialTestMethod() { var values = new double[4]; var valuesXvalues = new double[7]; Array.Clear(values, 0, values.Length); Array.Clear(valuesXvalues, 0, valuesXvalues.Length); using (var binomialBuilder = new BinomialBuilder()) binomialBuilder.GetDoubles(values); for (int i = 0; i < values.Length; i++) { for (int j = 0; j < values.Length; j++) { valuesXvalues[i + j] += values[i] * values[j]; } } using (var convolutionBuilder = new ConvolutionBuilder(FunctionType.NonPeriodic)) { double[] fxf = convolutionBuilder.Build(values); Console.WriteLine( string.Join(Environment.NewLine, valuesXvalues.Zip(fxf, (x, y) => string.Format("{0} - {1} = {2}", x, y, x - y))) + Environment.NewLine); Assert.IsTrue(valuesXvalues.Zip(fxf, (x, y) => x - y).All(x => Math.Abs(x) < 0.0001)); } }
public void ScalarTestMethod() { const int count = 10; var doubles = new double[count]; BinomialBuilder.GetDoubles(doubles); var scalar = new double[2 * doubles.Length]; ScalarBuilder.Scalar(doubles, scalar); double sum = doubles.Select(x => Math.Pow(x, 2)).Sum(); Assert.IsTrue(Math.Abs(sum - scalar[0]) < 0.0001); }
public void BinomialTestMethod() { const int count = 10; var doubles = new double[count]; var longs = new long[count]; BinomialBuilder.GetLongs(longs); BinomialBuilder.GetDoubles(doubles); Console.WriteLine( string.Join(Environment.NewLine, longs.Zip(doubles, (x, y) => string.Format("{0} - {1} = {2}", x, y, x - y))) + Environment.NewLine); Assert.IsTrue(doubles.Zip(longs, (x, y) => x - y).All(x => Math.Abs(x) < 0.001)); }