public void OverflowTest() { foreach (bool gradmode in new bool[] { false, true }) { foreach (int batch in new int[] { 1, 2, 3 }) { foreach (int inchannels in new int[] { 2, 4, 10, 20 }) { foreach (int outchannels in new int[] { 6, 14 }) { float[] xval = (new float[inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[inchannels * outchannels / 2]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch)); ComplexDense ope = new ComplexDense(inchannels, outchannels, gradmode, batch); ope.Execute(x_tensor, w_tensor, y_tensor); CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(wval, w_tensor.State); y_tensor.CheckOverflow(); Console.WriteLine($"pass: {inchannels},{outchannels},{batch},{gradmode}"); } } } } }
public void SpeedTest() { int inchannels = 32, outchannels = 32; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels)); ComplexDense ope = new ComplexDense(inchannels, outchannels); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(x_tensor, w_tensor, y_tensor); ope.Execute(x_tensor, w_tensor, y_tensor); ope.Execute(x_tensor, w_tensor, y_tensor); ope.Execute(x_tensor, w_tensor, y_tensor); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void ExecuteTest() { float max_err = 0; foreach (int batch in new int[] { 1, 2, 3 }) { foreach (int inchannels in new int[] { 2, 4, 10, 20 }) { foreach (int outchannels in new int[] { 6, 14 }) { float[] xval = (new float[inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[inchannels * outchannels / 2]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); System.Numerics.Complex[] xcval = (new System.Numerics.Complex[xval.Length / 2]) .Select((_, idx) => new System.Numerics.Complex(xval[idx * 2], xval[idx * 2 + 1])).ToArray(); System.Numerics.Complex[] wcval = (new System.Numerics.Complex[wval.Length / 2]) .Select((_, idx) => new System.Numerics.Complex(wval[idx * 2], wval[idx * 2 + 1])).ToArray(); ComplexMap0D x = new ComplexMap0D(inchannels / 2, batch, xcval); ComplexFilter0D w = new ComplexFilter0D(inchannels / 2, outchannels / 2, wcval); ComplexMap0D y = Reference(x, w); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch)); ComplexDense ope = new ComplexDense(inchannels, outchannels, gradmode: false, batch); ope.Execute(x_tensor, w_tensor, y_tensor); float[] y_expect = y.ToArray(); float[] y_actual = y_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(wval, w_tensor.State); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{batch}"); } } } Console.WriteLine($"maxerr:{max_err}"); }