public void OverflowTest() { foreach (bool transpose 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[] yval = (new float[outchannels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch), yval); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2)); ComplexKernelProductDense ope = new ComplexKernelProductDense(inchannels, outchannels, transpose, batch); ope.Execute(x_tensor, y_tensor, gw_tensor); CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(yval, y_tensor.State); gw_tensor.CheckOverflow(); Console.WriteLine($"pass: {inchannels},{outchannels},{batch},{transpose}"); } } } } }
public void SpeedTest() { int inchannels = 32, outchannels = 32; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels)); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2)); ComplexKernelProductDense ope = new ComplexKernelProductDense(inchannels, outchannels); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(x_tensor, y_tensor, gw_tensor); ope.Execute(x_tensor, y_tensor, gw_tensor); ope.Execute(x_tensor, y_tensor, gw_tensor); ope.Execute(x_tensor, y_tensor, gw_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[] yval = (new float[outchannels * batch]).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[] ycval = (new System.Numerics.Complex[yval.Length / 2]) .Select((_, idx) => new System.Numerics.Complex(yval[idx * 2], yval[idx * 2 + 1])).ToArray(); ComplexMap0D x = new ComplexMap0D(inchannels / 2, batch, xcval); ComplexMap0D y = new ComplexMap0D(outchannels / 2, batch, ycval); ComplexFilter0D gw = Reference(x, y); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch), yval); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2)); ComplexKernelProductDense ope = new ComplexKernelProductDense(inchannels, outchannels, transpose: false, batch); ope.Execute(x_tensor, y_tensor, gw_tensor); float[] gw_expect = gw.ToArray(); float[] gw_actual = gw_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(yval, y_tensor.State); AssertError.Tolerance(gw_expect, gw_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{batch}"); } } } Console.WriteLine($"maxerr:{max_err}"); }