public void SpeedTest() { int inwidth = 512, channels = 31, ksize = 3, stride = 2; int outwidth = (inwidth - ksize) / stride + 1; OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(channels, outwidth)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel1D(channels, 1, ksize)); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(channels, inwidth)); ChannelwiseDeconvolution ope = new ChannelwiseDeconvolution(inwidth, channels, ksize, stride); ope.Execute(y_tensor, w_tensor, x_tensor); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void SpeedTest() { int inwidth = 32, inchannels = 33, outchannels = 33, ksize = 3, stride = 2; int outwidth = (inwidth - ksize) / stride + 1; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel1D(inchannels / 3 * 4, outchannels / 3, ksize)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, outwidth)); TrivectorConvolution1D ope = new TrivectorConvolution1D(inwidth, inchannels, outchannels, ksize, stride); 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 SpeedTest() { int length = 65536, ch = 256, batch = 4; Shape shape = Shape.Map1D(ch, length, batch); OverflowCheckedTensor v1 = new OverflowCheckedTensor(shape); OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Vector(batch)); OverflowCheckedTensor v3 = new OverflowCheckedTensor(shape); BatchwiseMul ope = new BatchwiseMul(shape); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(v1, v2, v3); ope.Execute(v3, v2, v1); ope.Execute(v1, v2, v3); ope.Execute(v3, v2, v1); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void SpeedTest() { int inwidth = 512, inheight = 512, inchannels = 31, outchannels = 31, ksize = 3, stride = 2; int outwidth = (inwidth - ksize) / stride + 1, outheight = (inheight - ksize) / stride + 1; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(inchannels, inwidth, inheight)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel2D(inchannels, outchannels, ksize, ksize)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(outchannels, outwidth, outheight)); Convolution ope = new Convolution(inwidth, inheight, inchannels, outchannels, ksize, ksize, stride); 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 SpeedTest() { int inwidth = 512, inchannels = 32, outchannels = 32, ksize = 3, stride = 2; int outwidth = (inwidth - ksize) / stride + 1; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, outwidth)); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel1D(inchannels, outchannels / 2, ksize)); ComplexKernelProduct1D ope = new ComplexKernelProduct1D(inwidth, inchannels, outchannels, ksize, stride); 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() { Random rd = new Random(1234); { Shape shape = new Shape(ShapeType.Map, 17, 8, 2, 4, 1, 3, 67); for (int axis = 0; axis < shape.Ndim; axis++) { int stride = 1, length = shape[axis]; for (int i = 0; i < axis; i++) { stride *= shape[i]; } float[] x1 = (new float[shape.Length]).Select((_, idx) => (float)(idx / stride % length)).ToArray(); OverflowCheckedTensor tensor = new OverflowCheckedTensor(shape); Index ope = new Index(shape, axis); ope.Execute(tensor); CollectionAssert.AreEqual(x1, tensor.State); } } }
public void ExecuteTest() { Random rd = new Random(1234); foreach (int batch in new int[] { 1, 2, 3, 4, 8, 16, 32 }) { for (int channels = 1; channels <= 1024; channels *= 2) { float[] x1 = (new float[batch]).Select((_) => (float)rd.Next(channels)).ToArray(); OverflowCheckedTensor v1 = new OverflowCheckedTensor(Shape.Vector(batch), x1); OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map0D(channels, batch)); OneHotVector ope = new OneHotVector(channels, v1.Shape); ope.Execute(v1, v2); CollectionAssert.AreEqual(x1, v1.State); float[] y = v2.State; for (int j = 0; j < batch; j++) { for (int k = 0; k < channels; k++) { Assert.AreEqual(k == x1[j] ? 1 : 0, y[k + j * channels], $"batch:{batch},channels:{channels} idx:{j}"); } } Assert.AreEqual(batch, y.Sum()); } } }
public void ExecuteTest() { float max_err = 0; Random rd = new Random(1234); foreach (int batch in new int[] { 1, 2 }) { foreach (int channels in new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }) { foreach (int stride in new int[] { 2, 3, 4 }) { foreach (int inwidth in new int[] { 5, 7, 11 }) { foreach (int inheight in new int[] { 5, 7, 11 }) { int outwidth = inwidth / stride, outheight = inheight / stride; float[] xval = (new float[inwidth * inheight * channels * batch]).Select((_) => (float)rd.NextDouble()).ToArray(); float[] gyval = (new float[outwidth * outheight * channels * batch]).Select((_) => (float)rd.NextDouble()).ToArray(); Map2D x = new Map2D(channels, inwidth, inheight, batch, xval); Map2D gy = new Map2D(channels, outwidth, outheight, batch, gyval); Map2D gx = Reference(x, gy, stride); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight, batch)); OverflowCheckedTensor gy_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight, batch), gyval); OverflowCheckedTensor gx_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight, batch)); MaxPooling ope_pool = new MaxPooling(inwidth, inheight, channels, stride, batch); ope_pool.Execute(x_tensor, y_tensor); MaxUnpooling ope_unpool = new MaxUnpooling(inwidth, inheight, channels, stride, batch); ope_unpool.Execute(gy_tensor, x_tensor, y_tensor, gx_tensor); float[] gx_expect = gx.ToArray(); float[] gx_actual = gx_tensor.State; int gx_expect_nonzero = gx_expect.Count((v) => v != 0); int gx_actual_nonzero = gx_expect.Count((v) => v != 0); CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(gyval, gy_tensor.State); Assert.AreEqual(y_tensor.Length, gx_expect_nonzero); Assert.AreEqual(y_tensor.Length, gx_actual_nonzero); AssertError.Tolerance(gx_expect, gx_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {channels},{stride},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {channels},{stride},{inwidth},{inheight},{batch}"); } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public void SpeedTest() { int inchannels = 32, outchannels = 32; OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2)); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels)); ComplexTransposeDense ope = new ComplexTransposeDense(outchannels, inchannels); ope.Execute(y_tensor, w_tensor, x_tensor); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void SpeedTest() { int length = 65536 * 4; Shape inshape = Shape.Vector(length); Shape outshape = Shape.Vector(length * 3); OverflowCheckedTensor v1 = new OverflowCheckedTensor(inshape); OverflowCheckedTensor v2 = new OverflowCheckedTensor(inshape); OverflowCheckedTensor v3 = new OverflowCheckedTensor(inshape); OverflowCheckedTensor v4 = new OverflowCheckedTensor(outshape); TrivectorCast ope = new TrivectorCast(inshape); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(v1, v2, v3, v4); ope.Execute(v1, v2, v3, v4); ope.Execute(v1, v2, v3, v4); ope.Execute(v1, v2, v3, v4); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
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 SpeedTest() { Shape shape = Shape.Map0D(8192, 500); int length = shape.Length, axislength = shape[0]; float[] xval = (new float[length]).Select((_, idx) => (float)(((idx * 4969 % 17 + 3) * (idx * 6577 % 13 + 5) + idx) % 8)).ToArray(); OverflowCheckedTensor x = new OverflowCheckedTensor(shape, xval); OverflowCheckedTensor y = new OverflowCheckedTensor(shape); Sort ope = new Sort(shape, axis: 0); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(x, y); sw.Stop(); float[] v = y.State; for (int i = 1; i < axislength / 5; i++) { Assert.IsTrue(v[i - 1] <= v[i], $"{i}: {v[i - 1]}, {v[i]}"); Assert.IsTrue(v[i - 1 + axislength] <= v[i + axislength], $"{i + axislength}: {v[i - 1 + axislength]}, {v[i + axislength]}"); Assert.IsTrue(v[i - 1 + axislength * 2] <= v[i + axislength * 2], $"{i + axislength * 2}: {v[i - 1 + axislength * 2]}, {v[i + axislength * 2]}"); Assert.IsTrue(v[i - 1 + axislength * 3] <= v[i + axislength * 3], $"{i + axislength * 3}: {v[i - 1 + axislength * 3]}, {v[i + axislength * 3]}"); Assert.IsTrue(v[i - 1 + axislength * 4] <= v[i + axislength * 4], $"{i + axislength * 4}: {v[i - 1 + axislength * 4]}, {v[i + axislength * 4]}"); } Console.WriteLine($"{sw.ElapsedMilliseconds} msec"); }
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 SpeedTest() { int inwidth = 512, inheight = 512, channels = 32, stride = 2; int outwidth = inwidth / stride, outheight = inheight / stride; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight)); OverflowCheckedTensor gy_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight)); OverflowCheckedTensor gx_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight)); MaxUnpooling ope = new MaxUnpooling(inwidth, inheight, channels, stride); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(gy_tensor, x_tensor, y_tensor, gx_tensor); ope.Execute(gy_tensor, x_tensor, y_tensor, gx_tensor); ope.Execute(gy_tensor, x_tensor, y_tensor, gx_tensor); ope.Execute(gy_tensor, x_tensor, y_tensor, gx_tensor); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void SpeedTest() { Shape inshape = new Shape(ShapeType.Map, 3, 7, 19, 5, 11); Shape outshape1 = new Shape(ShapeType.Map, 3, 7, 6, 5, 11); Shape outshape2 = new Shape(ShapeType.Map, 3, 7, 9, 5, 11); Shape outshape3 = new Shape(ShapeType.Map, 3, 7, 4, 5, 11); OverflowCheckedTensor vc = new OverflowCheckedTensor(inshape); OverflowCheckedTensor v1 = new OverflowCheckedTensor(outshape1); OverflowCheckedTensor v2 = new OverflowCheckedTensor(outshape2); OverflowCheckedTensor v3 = new OverflowCheckedTensor(outshape3); Separate ope = new Separate(vc.Shape, new Shape[] { v1.Shape, v2.Shape, v3.Shape }, axis: 2); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(vc, v1, v2, v3); ope.Execute(vc, v1, v2, v3); ope.Execute(vc, v1, v2, v3); ope.Execute(vc, v1, v2, v3); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void SpeedTest() { int inwidth = 512, inchannels = 31, outchannels = 63; OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, inwidth)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels)); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth)); PointwiseDeconvolution ope = new PointwiseDeconvolution(inwidth, outchannels, inchannels); ope.Execute(y_tensor, w_tensor, x_tensor); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); ope.Execute(y_tensor, w_tensor, x_tensor); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
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 = 33, outchannels = 33; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels / 3 * 4, outchannels / 3)); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels / 3 * 4, outchannels / 3)); TrivectorKernelProductDense ope = new TrivectorKernelProductDense(inchannels, outchannels); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(x_tensor, y_tensor, w_tensor, gw_tensor); ope.Execute(x_tensor, y_tensor, w_tensor, gw_tensor); ope.Execute(x_tensor, y_tensor, w_tensor, gw_tensor); ope.Execute(x_tensor, y_tensor, w_tensor, gw_tensor); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void CopyTest() { int channels = 12, batch = 4, length = channels * batch; Random random = new Random(1234); float[] v1 = (new float[length]).Select((_) => (float)random.NextDouble()).ToArray(); { Tensor tensor1 = new Tensor(Shape.Map0D(channels, batch), v1); Tensor tensor2 = tensor1.Copy(); Assert.AreEqual(length, tensor2.Length); CollectionAssert.AreEqual(v1, tensor2.State); } { Tensor tensor1 = new OverflowCheckedTensor(Shape.Map0D(channels, batch), v1); Tensor tensor2 = tensor1.Copy(); Assert.IsTrue(tensor2 is OverflowCheckedTensor); Assert.AreEqual(length, tensor2.Length); CollectionAssert.AreEqual(v1, tensor2.State); } }
public void ZerosetTest() { int channels = 12, batch = 4, length = channels * batch; Random random = new Random(1234); float[] v1 = (new float[length]).Select((_) => (float)random.NextDouble()).ToArray(); { Tensor tensor = new Tensor(Shape.Map0D(channels, batch), v1); tensor.Zeroset(); Assert.AreEqual(length, tensor.Length); foreach (float v in tensor.State) { Assert.AreEqual(0f, v); } } { Tensor tensor = new OverflowCheckedTensor(Shape.Map0D(channels, batch), v1); tensor.Zeroset(); Assert.AreEqual(length, tensor.Length); foreach (float v in tensor.State) { Assert.AreEqual(0f, v); } } }
public void ReferenceTest() { Shape inshape = new Shape(ShapeType.Map, 3, 5, 1, 1, 2); Shape outshape = new Shape(ShapeType.Map, 3, 5, 2, 3, 2); float[] x = (new float[inshape.Length]).Select((_, idx) => (float)idx).ToArray(); OverflowCheckedTensor intensor = new OverflowCheckedTensor(inshape, x); OverflowCheckedTensor outtensor = new OverflowCheckedTensor(outshape); Broadcast broadcast = new Broadcast(inshape, outshape); broadcast.Execute(intensor, outtensor); float[] y = outtensor.State; float[] y_expect = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 }; CollectionAssert.AreEqual(y_expect, y); }
public void ExecuteTest() { float max_err = 0; 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[] yval = (new float[outwidth * outchannels * batch]).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[] ycval = (new Quaternion[yval.Length / 4]) .Select((_, idx) => new Quaternion(yval[idx * 4], yval[idx * 4 + 1], yval[idx * 4 + 2], yval[idx * 4 + 3])).ToArray(); QuaternionMap1D x = new QuaternionMap1D(inchannels / 4, inwidth, batch, xcval); QuaternionMap1D y = new QuaternionMap1D(outchannels / 4, outwidth, batch, ycval); QuaternionFilter1D gw = Reference(x, y, kwidth, stride); 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 / 4, kwidth)); QuaternionKernelProduct1D ope = new QuaternionKernelProduct1D(inwidth, inchannels, outchannels, kwidth, stride, 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},{kwidth},{stride},{inwidth},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{kwidth},{stride},{inwidth},{batch}"); } } } } } } Console.WriteLine($"maxerr:{max_err}"); }
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 }) { 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[] yval = (new float[outwidth * outchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[kwidth * inchannels * outchannels / 2]).Select((_, idx) => idx * 1e-3f).Reverse().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(); 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(); ComplexMap1D y = new ComplexMap1D(outchannels / 2, outwidth, batch, ycval); ComplexFilter1D w = new ComplexFilter1D(inchannels / 2, outchannels / 2, kwidth, wcval); ComplexMap1D x = Reference(y, w, inwidth, kwidth, stride); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, outwidth, batch), yval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel1D(inchannels, outchannels / 2, kwidth), wval); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth, batch)); ComplexDeconvolution1D ope = new ComplexDeconvolution1D(inwidth, outchannels, inchannels, kwidth, stride, gradmode: false, batch); ope.Execute(y_tensor, w_tensor, x_tensor); float[] x_expect = x.ToArray(); float[] x_actual = x_tensor.State; CollectionAssert.AreEqual(yval, y_tensor.State); CollectionAssert.AreEqual(wval, w_tensor.State); AssertError.Tolerance(x_expect, x_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{kwidth},{stride},{inwidth},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{kwidth},{stride},{inwidth},{batch}"); } } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public void ExecuteTest() { float max_err = 0; 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(); Trivector[] xcval = (new Trivector[xval.Length / 3]) .Select((_, idx) => new Trivector(xval[idx * 3], xval[idx * 3 + 1], xval[idx * 3 + 2])).ToArray(); Quaternion.Quaternion[] wcval = (new Quaternion.Quaternion[wval.Length / 4]) .Select((_, idx) => new Quaternion.Quaternion(wval[idx * 4], wval[idx * 4 + 1], wval[idx * 4 + 2], wval[idx * 4 + 3])).ToArray(); TrivectorMap1D x = new TrivectorMap1D(inchannels / 3, inwidth, batch, xcval); Quaternion.QuaternionFilter1D w = new Quaternion.QuaternionFilter1D(inchannels / 3, outchannels / 3, kwidth, wcval); TrivectorMap1D 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 / 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: 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},{kwidth},{stride},{inwidth},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{kwidth},{stride},{inwidth},{batch}"); } } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public void ExecuteTest() { float max_err = 0; foreach (int batch in new int[] { 1, 2 }) { foreach (int inchannels in new int[] { 1, 2, 3, 4, 5, 10, 15, 20 }) { foreach (int outchannels in new int[] { 7, 13 }) { 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]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Map2D x = new Map2D(inchannels, inwidth, inheight, batch, xval); Filter2D w = new Filter2D(inchannels, outchannels, kwidth, kheight, wval); Map2D y = Reference(x, w, kwidth, kheight, stride); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(inchannels, inwidth, inheight, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel2D(inchannels, outchannels, kwidth, kheight), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(outchannels, outwidth, outheight, batch)); Convolution ope = new Convolution(inwidth, inheight, inchannels, outchannels, kwidth, kheight, stride, 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},{kwidth},{kheight},{stride},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{kwidth},{kheight},{stride},{inwidth},{inheight},{batch}"); } } } } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public void ExecuteTest() { float max_err = 0; Random random = new Random(); foreach (int batch in new int[] { 1, 2 }) { foreach (int channels in new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }) { foreach (int leftpad in new int[] { 0, 1, 2 }) { foreach (int rightpad in new int[] { 0, 1, 2 }) { foreach (int toppad in new int[] { 0, 1, 2 }) { foreach (int bottompad in new int[] { 0, 1, 2 }) { foreach (int inwidth in new int[] { 5, 7, 11 }) { foreach (int inheight in new int[] { 5, 7, 11 }) { int outwidth = inwidth + leftpad + rightpad, outheight = inheight + toppad + bottompad; float[] xval = (new float[inwidth * inheight * channels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); Map2D x = new Map2D(channels, inwidth, inheight, batch, xval); Map2D y = Reference(x, leftpad, rightpad, toppad, bottompad); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight, batch)); TensorShaderAvxBackend.Randomize.Uniform((uint)y_tensor.Length, y_tensor.Buffer, random); ZeroPadding ope = new ZeroPadding(inwidth, inheight, channels, leftpad, rightpad, toppad, bottompad, batch); ope.Execute(x_tensor, y_tensor); float[] y_expect = y.ToArray(); float[] y_actual = y_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {channels},{leftpad},{rightpad},{toppad},{bottompad},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {channels},{leftpad},{rightpad},{toppad},{bottompad},{inwidth},{inheight},{batch}"); } } } } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public void ExecuteTest() { float max_err = 0; foreach (int batch in new int[] { 1, 2 }) { foreach (int channels in new int[] { 1, 2, 3, 4, 5, 10, 15, 20 }) { 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 * channels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] gyval = (new float[outwidth * outheight * channels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Map2D x = new Map2D(channels, inwidth, inheight, batch, xval); Map2D gy = new Map2D(channels, outwidth, outheight, batch, gyval); Filter2D gw = Reference(x, gy, kwidth, kheight, stride); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight, batch), xval); OverflowCheckedTensor gy_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight, batch), gyval); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel2D(channels, 1, kwidth, kheight)); ChannelwiseKernelProduct ope = new ChannelwiseKernelProduct(inwidth, inheight, channels, kwidth, kheight, stride, batch); ope.Execute(x_tensor, gy_tensor, gw_tensor); float[] gw_expect = gw.ToArray(); float[] gw_actual = gw_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(gyval, gy_tensor.State); AssertError.Tolerance(gw_expect, gw_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {channels},{kwidth},{kheight},{stride},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {channels},{kwidth},{kheight},{stride},{inwidth},{inheight},{batch}"); } } } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public void ExecuteTest() { float max_err = 0; 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[] xval = (new float[inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] yval = (new float[outchannels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); float[] wval = (new float[inchannels * outchannels / 9 * 4]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Trivector[] xcval = (new Trivector[xval.Length / 3]) .Select((_, idx) => new Trivector(xval[idx * 3], xval[idx * 3 + 1], xval[idx * 3 + 2])).ToArray(); Trivector[] ycval = (new Trivector[yval.Length / 3]) .Select((_, idx) => new Trivector(yval[idx * 3], yval[idx * 3 + 1], yval[idx * 3 + 2])).ToArray(); Quaternion.Quaternion[] wcval = (new Quaternion.Quaternion[wval.Length / 4]) .Select((_, idx) => new Quaternion.Quaternion(wval[idx * 4], wval[idx * 4 + 1], wval[idx * 4 + 2], wval[idx * 4 + 3])).ToArray(); TrivectorMap0D x = new TrivectorMap0D(inchannels / 3, batch, xcval); TrivectorMap0D y = new TrivectorMap0D(outchannels / 3, batch, ycval); Quaternion.QuaternionFilter0D w = new Quaternion.QuaternionFilter0D(inchannels / 3, outchannels / 3, wcval); Quaternion.QuaternionFilter0D gw = Reference(x, y, w); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch), yval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels / 3 * 4, outchannels / 3), wval); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels / 3 * 4, outchannels / 3)); TrivectorKernelProductDense ope = new TrivectorKernelProductDense(inchannels, outchannels, transpose: false, batch); ope.Execute(x_tensor, y_tensor, w_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); CollectionAssert.AreEqual(wval, w_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}"); }
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 ExecuteTest() { float max_err = 0; foreach (int batch in new int[] { 1, 2 }) { foreach (int channels in new int[] { 3, 5 }) { foreach (int lefttrim in new int[] { 0, 1, 2 }) { foreach (int righttrim in new int[] { 0, 1, 2 }) { foreach (int toptrim in new int[] { 0, 1, 2 }) { foreach (int bottomtrim in new int[] { 0, 1, 2 }) { foreach (int inwidth in new int[] { 5, 7, 11 }) { foreach (int inheight in new int[] { 5, 7, 11 }) { int outwidth = inwidth - lefttrim - righttrim, outheight = inheight - toptrim - bottomtrim; float[] xval = (new float[inwidth * inheight * channels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); Map2D x = new Map2D(channels, inwidth, inheight, batch, xval); Map2D y = Reference(x, lefttrim, righttrim, toptrim, bottomtrim); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight, batch)); Trimming ope = new Trimming(inwidth, inheight, channels, lefttrim, righttrim, toptrim, bottomtrim, batch); ope.Execute(x_tensor, y_tensor); float[] y_expect = y.ToArray(); float[] y_actual = y_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {channels},{lefttrim},{righttrim},{toptrim},{bottomtrim},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {channels},{lefttrim},{righttrim},{toptrim},{bottomtrim},{inwidth},{inheight},{batch}"); } } } } } } } } Console.WriteLine($"maxerr:{max_err}"); }