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[] { 4, 8, 12 }) { foreach (int outchannels in new int[] { 4, 8, 12 }) { 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 / 4)); QuaternionKernelProductDense ope = new QuaternionKernelProductDense(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 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 OverflowTest() { foreach (bool gradmode in new bool[] { false, true }) { foreach (int batch in new int[] { 1, 2, 3 }) { foreach (int inchannels in new int[] { 3, 6, 9, 12 }) { foreach (int outchannels in new int[] { 3, 6, 9, 12 }) { float[] yval = (new float[outchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[inchannels * outchannels / 9 * 4]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch), yval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels / 3 * 4, outchannels / 3), wval); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch)); TrivectorTransposeDense ope = new TrivectorTransposeDense(outchannels, inchannels, gradmode, batch); ope.Execute(y_tensor, w_tensor, x_tensor); CollectionAssert.AreEqual(yval, y_tensor.State); CollectionAssert.AreEqual(wval, w_tensor.State); x_tensor.CheckOverflow(); Console.WriteLine($"pass: {inchannels},{outchannels},{batch},{gradmode}"); } } } } }
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[] { 4, 8, 12 }) { foreach (int outchannels in new int[] { 4, 8, 12 }) { foreach (int kwidth in new int[] { 1, 3, 5 }) { foreach (int stride in new int[] { 1, 2, 3 }) { foreach (int inwidth in new int[] { 8, 9, 13, 17 }) { int outwidth = (inwidth - kwidth) / stride + 1; float[] xval = (new float[inwidth * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[kwidth * inchannels * outchannels / 4]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Quaternion[] xcval = (new Quaternion[xval.Length / 4]) .Select((_, idx) => new Quaternion(xval[idx * 4], xval[idx * 4 + 1], xval[idx * 4 + 2], xval[idx * 4 + 3])).ToArray(); Quaternion[] wcval = (new Quaternion[wval.Length / 4]) .Select((_, idx) => new Quaternion(wval[idx * 4], wval[idx * 4 + 1], wval[idx * 4 + 2], wval[idx * 4 + 3])).ToArray(); QuaternionMap1D x = new QuaternionMap1D(inchannels / 4, inwidth, batch, xcval); QuaternionFilter1D w = new QuaternionFilter1D(inchannels / 4, outchannels / 4, kwidth, wcval); QuaternionMap1D y = Reference(x, w, kwidth, stride); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel1D(inchannels, outchannels / 4, kwidth), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, outwidth, batch)); QuaternionConvolution1D ope = new QuaternionConvolution1D(inwidth, inchannels, outchannels, kwidth, stride, 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},{kwidth},{stride},{inwidth},{batch},{gradmode}"); } } } } } } } }
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[] { 3, 6, 9, 12 }) { foreach (int outchannels in new int[] { 3, 6, 9, 12 }) { foreach (int kheight in new int[] { 1, 3, 5 }) { foreach (int kwidth in new int[] { 1, 3, 5 }) { foreach (int stride in new int[] { 1, 2, 3 }) { foreach (int inwidth in new int[] { 8, 9, 13, 17 }) { foreach (int inheight in new int[] { 8, 9, 19, 23 }) { int outwidth = (inwidth - kwidth) / stride + 1, outheight = (inheight - kheight) / stride + 1; float[] xval = (new float[inwidth * inheight * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] yval = (new float[outwidth * outheight * outchannels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); float[] wval = (new float[kwidth * kheight * inchannels * outchannels / 9 * 4]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(inchannels, inwidth, inheight, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(outchannels, outwidth, outheight, batch), yval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel2D(inchannels / 3 * 4, outchannels / 3, kwidth, kheight), wval); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel2D(inchannels / 3 * 4, outchannels / 3, kwidth, kheight)); TrivectorKernelProduct2D ope = new TrivectorKernelProduct2D(inwidth, inheight, inchannels, outchannels, kwidth, kheight, stride, transpose, batch); ope.Execute(x_tensor, y_tensor, w_tensor, gw_tensor); CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(yval, y_tensor.State); CollectionAssert.AreEqual(wval, w_tensor.State); gw_tensor.CheckOverflow(); Console.WriteLine($"pass: {inchannels},{outchannels},{kwidth},{kheight},{stride},{inwidth},{inheight},{batch},{transpose}"); } } } } } } } } } }
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 }) { foreach (int kheight in new int[] { 1, 3, 5 }) { foreach (int kwidth in new int[] { 1, 3, 5 }) { foreach (int stride in new int[] { 1, 2, 3 }) { foreach (int inwidth in new int[] { 8, 9, 13, 17 }) { foreach (int inheight in new int[] { 8, 9, 19, 23 }) { int outwidth = (inwidth - kwidth) / stride + 1, outheight = (inheight - kheight) / stride + 1; float[] xval = (new float[inwidth * inheight * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[kwidth * kheight * inchannels * outchannels / 2]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(inchannels, inwidth, inheight, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel2D(inchannels, outchannels / 2, kwidth, kheight), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(outchannels, outwidth, outheight, batch)); ComplexConvolution2D ope = new ComplexConvolution2D(inwidth, inheight, inchannels, outchannels, kwidth, kheight, stride, 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},{kwidth},{kheight},{stride},{inwidth},{inheight},{batch},{gradmode}"); } } } } } } } } } }
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[] { 3, 6, 9, 12 }) { foreach (int outchannels in new int[] { 3, 6, 9, 12 }) { foreach (int kwidth in new int[] { 1, 3, 5 }) { foreach (int stride in new int[] { 1, 2, 3 }) { foreach (int inwidth in new int[] { 8, 9, 13, 17 }) { int outwidth = (inwidth - kwidth) / stride + 1; float[] xval = (new float[inwidth * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[kwidth * inchannels * outchannels / 9 * 4]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel1D(inchannels / 3 * 4, outchannels / 3, kwidth), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, outwidth, batch)); TrivectorConvolution1D ope = new TrivectorConvolution1D(inwidth, inchannels, outchannels, kwidth, stride, 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},{kwidth},{stride},{inwidth},{batch},{gradmode}"); } } } } } } } }
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 }) { foreach (int kwidth in new int[] { 1, 3, 5 }) { foreach (int stride in new int[] { 1, 2, 3 }) { foreach (int inwidth in new int[] { 8, 9, 13, 17 }) { int outwidth = (inwidth - kwidth) / stride + 1; float[] xval = (new float[inwidth * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] yval = (new float[outwidth * outchannels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, outwidth, batch), yval); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel1D(inchannels, outchannels / 2, kwidth)); ComplexKernelProduct1D ope = new ComplexKernelProduct1D(inwidth, inchannels, outchannels, kwidth, stride, 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},{kwidth},{stride},{inwidth},{batch},{transpose}"); } } } } } } } }