public void Stress_SingleReal_262144() {//1048576 int numSamples = 262144; int half = numSamples >> 1; double[] dataEven = new double[numSamples]; for (int i = 0; i < numSamples; i++) { double z = (double)(i - half) / half; dataEven[i] = 1.0 / (z * z + 1.0); } RealTestTimeEven(dataEven); double[] evenReal = new double[0], evenImag = new double[0]; rft.Convention = TransformationConvention.Default; MyStopwatch.MethodToTime m = delegate { rft.TransformForward(dataEven, out evenReal, out evenImag); }; Console.Write("FFT Time (ms) for " + numSamples.ToString() + ": "); MyStopwatch.Time(m); // This time do a round trip check, too: double[] dataEven2; rft.TransformBackward(evenReal, evenImag, out dataEven2); // Compare with original samples for (int i = 0; i < numSamples; i += 2) { Assert.AreEqual(dataEven[i], dataEven2[i], 0.00001, "Inv: " + i.ToString()); } }
public void TestMatrix_Solve() { double[][] a = { new double[] { 1, 2 }, new double[] { 3, 5 } }; Matrix ma = Matrix.Create(a); double[][] b = { new double[] { 29.0 }, new double[] { 76.0 } }; Matrix mb = Matrix.Create(b); double[][] r = { new double[] { 7 }, new double[] { 11.0 } }; Matrix mr = Matrix.Create(r); //Console.WriteLine("a"); //Console.WriteLine(ma.ToString()); //Console.WriteLine("b"); //Console.WriteLine(mb.ToString()); Matrix mx = null; MyStopwatch.MethodToTime m = delegate { mx = ma.Solve(mb); }; Console.Write("Solve Time (ms): "); MyStopwatch.Time(m); //Console.WriteLine("solution"); //Console.WriteLine(mx.ToString()); //Console.WriteLine("expected solution"); //Console.WriteLine(mr.ToString()); Assert.AreEqual(mx.ToString(), mr.ToString(), "Matrices should be equal"); //Check by multiplying a by x Matrix mc = ma * mx; Assert.AreEqual(mc.ToString(), mb.ToString(), "Matrices should be equal"); }
/*Test a given solution by calculating b and then solving for x. * Shows only the elapsed time on console out so that we can use * matrices too large to print.*/ private Matrix TestMatrix_Solutions(Matrix ma, Matrix mx, double epsilon, bool showB) { Matrix mb = ma * mx; if (showB) { Console.WriteLine("b"); Console.WriteLine(mb.ToString()); } Matrix ms = null; MyStopwatch.MethodToTime m = delegate { ms = ma.Solve(mb); }; Console.Write("Solve Time (ms) for " + ma.ColumnCount + ": "); MyStopwatch.Time(m); Assert.IsTrue(CompareMatrices(ms, mx, epsilon), "Matrices should be equal"); //Assert.AreEqual(ms.ToString(), mx.ToString(), "Matrices should be equal"); return(ms); }