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 }) { foreach (int channels in new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }) { foreach (int toppad in new int[] { 0, 1, 2 }) { foreach (int bottompad in new int[] { 0, 1, 2 }) { foreach (int leftpad in new int[] { 0, 1, 2 }) { foreach (int rightpad 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)); EdgePadding ope = new EdgePadding(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 ReferenceTest() { int inchannels = 12, scale = 2, inwidth = 7, inheight = 5; float[] xval = (new float[inwidth * inheight * inchannels]).Select((_, idx) => idx * 1e-3f).ToArray(); Map2D x = new Map2D(inchannels, inwidth, inheight, 1, xval); Map2D y = Reference(ChannelToSpaceTest.Reference(x, scale), scale); CollectionAssert.AreEqual(x.ToArray(), y.ToArray()); }
public static Filter2D OptimizedReference(Map2D x, Map2D gy, int kwidth, int kheight, int stride) { int inchannels = x.Channels, outchannels = gy.Channels, batch = x.Batch; int inw = x.Width, inh = x.Height, outw = gy.Width, outh = gy.Height; if (outw < (inw - kwidth) / stride + 1 || outh < (inh - kheight) / stride + 1) { throw new ArgumentException("mismatch shape"); } Filter2D w = new Filter2D(outchannels, inchannels, kwidth, kheight); for (int kx, ky = 0; ky < kheight; ky++) { for (kx = 0; kx < kwidth; kx++) { for (int th = 0; th < batch; th++) { for (int outch, inch = 0; inch < inchannels; inch++) { for (outch = 0; outch < outchannels; outch++) { int filter_idx = inch + inchannels * outch + (kx + ky * kwidth) * inchannels * outchannels; int inmap_org = inch + (kx + ky * inw) * inchannels + th * inw * inh * inchannels; int outmap_idx = outch + th * outw * outh * outchannels; double sum = 0; for (int ox, oy = 0; oy < outh; oy++) { int inmap_idx = inmap_org; for (ox = 0; ox < outw; ox++) { sum += x[inmap_idx] * gy[outmap_idx]; inmap_idx += inchannels * stride; outmap_idx += outchannels; } inmap_org += inchannels * inw * stride; } w[filter_idx] += sum; } } } } } return(w); }
public static Map2D OptimizedReference(Map2D x, Filter2D w, int kwidth, int kheight, int stride) { int inchannels = x.Channels, outchannels = w.OutChannels, batch = x.Batch; int inw = x.Width, inh = x.Height, outw = (inw - kwidth) / stride + 1, outh = (inh - kheight) / stride + 1; Map2D y = new Map2D(outchannels, outw, outh, batch); for (int kx, ky = 0; ky < kheight; ky++) { for (kx = 0; kx < kwidth; kx++) { int inmap_offset = (kx + ky * inw) * inchannels; int kernel_offset = (kx + ky * kwidth) * inchannels * outchannels; for (int th = 0; th < batch; th++) { for (int ox, oy = 0; oy < outh; oy++) { for (ox = 0; ox < outw; ox++) { int inmap_org = inmap_offset + (ox + oy * inw) * inchannels * stride + th * inw * inh * inchannels; int outmap_idx = (ox + oy * outw) * outchannels + th * outw * outh * outchannels; int kernel_idx = kernel_offset; for (int outch = 0; outch < outchannels; outch++) { double sum = y[outmap_idx]; int inmap_idx = inmap_org; for (int inch = 0; inch < inchannels; inch++) { sum += x[inmap_idx] * w[kernel_idx]; inmap_idx++; kernel_idx++; } y[outmap_idx] = sum; outmap_idx++; } } } } } } return(y); }
public void OptimizeTest() { 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); Map2D y_optimized = OptimizedReference(x, w, kwidth, kheight, stride); float[] y_expect = y.ToArray(); float[] y_actual = y_optimized.ToArray(); 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; foreach (int batch in new int[] { 1, 2 }) { foreach (int channels in new int[] { 3, 5 }) { 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((_, idx) => idx * 1e-3f).ToArray(); Map2D x = new Map2D(channels, inwidth, inheight, batch, xval); Map2D y = Reference(x, stride); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight, batch), xval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight, batch)); MaxPooling ope = new MaxPooling(inwidth, inheight, channels, stride, 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},{stride},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {channels},{stride},{inwidth},{inheight},{batch}"); } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public static Map2D OptimizedReference(Map2D x, int scale) { int inchannels = x.Channels, batch = x.Batch; if (inchannels % (scale * scale) != 0) { throw new ArgumentException(nameof(scale)); } int inw = x.Width, inh = x.Height, outw = inw * scale, outh = inh * scale; int outchannels = inchannels / (scale * scale); Map2D y = new Map2D(outchannels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ix, iy = 0; iy < inh; iy++) { for (ix = 0; ix < inw; ix++) { int inmap_idx = (ix + iy * inw) * inchannels + th * inw * inh * inchannels; int outmap_org = (ix * scale + iy * inw * scale * scale) * outchannels + th * outw * outh * outchannels; for (int ky = 0; ky < scale; ky++) { int outmap_idx = outmap_org; for (int i = 0; i < scale * outchannels; i++) { y[outmap_idx] = x[inmap_idx]; inmap_idx++; outmap_idx++; } outmap_org += inw * scale * outchannels; } } } } return(y); }
public static Map2D OptimizedReference(Map2D x, int scale) { int inw = x.Width, inh = x.Height, inchannels = x.Channels, batch = x.Batch; if (inw % scale != 0 || inh % scale != 0) { throw new ArgumentException(nameof(scale)); } int outw = inw / scale, outh = inh / scale; int outchannels = inchannels * scale * scale; Map2D y = new Map2D(outchannels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ox, oy = 0; oy < outh; oy++) { for (ox = 0; ox < outw; ox++) { int inmap_org = (ox * scale + oy * outw * scale * scale) * inchannels + th * inw * inh * inchannels; int outmap_idx = (ox + oy * outw) * outchannels + th * outw * outh * outchannels; for (int ky = 0; ky < scale; ky++) { int inmap_idx = inmap_org; for (int i = 0; i < scale * inchannels; i++) { y[outmap_idx] = x[inmap_idx]; inmap_idx++; outmap_idx++; } inmap_org += outw * scale * inchannels; } } } } return(y); }
public static Filter2D Reference(Map2D x, Map2D gy, int kwidth, int kheight, int stride) { int inchannels = x.Channels, outchannels = gy.Channels, batch = x.Batch; int inw = x.Width, inh = x.Height, outw = gy.Width, outh = gy.Height; if (outw != (inw - kwidth) / stride + 1 || outh != (inh - kheight) / stride + 1) { throw new ArgumentException("mismatch shape"); } Filter2D w = new Filter2D(inchannels, outchannels, kwidth, kheight); for (int kx, ky = 0; ky < kheight; ky++) { for (kx = 0; kx < kwidth; kx++) { for (int th = 0; th < batch; th++) { for (int inch, outch = 0; outch < outchannels; outch++) { for (inch = 0; inch < inchannels; inch++) { double sum = 0; for (int ix, iy = ky, ox, oy = 0; oy < outh; iy += stride, oy++) { for (ix = kx, ox = 0; ox < outw; ix += stride, ox++) { sum += x[inch, ix, iy, th] * gy[outch, ox, oy, th]; } } w[inch, outch, kx, ky] += sum; } } } } } return(w); }
public static Filter2D OptimizedReference(Map2D x, Map2D gy) { int inchannels = x.Channels, outchannels = gy.Channels, batch = x.Batch; int inw = x.Width, inh = x.Height; Filter2D w = new Filter2D(outchannels, inchannels, 1, 1); for (int th = 0; th < batch; th++) { for (int outch, inch = 0; inch < inchannels; inch++) { for (outch = 0; outch < outchannels; outch++) { int filter_idx = inch + inchannels * outch; int inmap_org = inch + th * inw * inh * inchannels; int outmap_idx = outch + th * inw * inh * outchannels; double sum = 0; for (int ix, iy = 0; iy < inh; iy++) { int inmap_idx = inmap_org; for (ix = 0; ix < inw; ix++) { sum += x[inmap_idx] * gy[outmap_idx]; inmap_idx += inchannels; outmap_idx += outchannels; } inmap_org += inchannels * inw; } w[filter_idx] += sum; } } } return(w); }
public static Map2D Reference(Map2D x, int scale) { int inw = x.Width, inh = x.Height, inchannels = x.Channels, batch = x.Batch; if (inw % scale != 0 || inh % scale != 0) { throw new ArgumentException(nameof(scale)); } int outw = inw / scale, outh = inh / scale; int outchannels = inchannels * scale * scale; Map2D y = new Map2D(outchannels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ox, oy = 0; oy < outh; oy++) { for (ox = 0; ox < outw; ox++) { for (int kx, ky = 0; ky < scale; ky++) { for (kx = 0; kx < scale; kx++) { for (int inch = 0; inch < inchannels; inch++) { int outch = inch + kx * inchannels + ky * inchannels * scale; y[outch, ox, oy, th] = x[inch, ox *scale + kx, oy *scale + ky, th]; } } } } } } return(y); }
public static Map2D Reference(Map2D x, int scale) { int inw = x.Width, inh = x.Height, channels = x.Channels, batch = x.Batch; int outw = inw * scale, outh = inh * scale; Map2D y = new Map2D(channels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ix, iy = 0; iy < inh; iy++) { for (ix = 0; ix < inw; ix++) { for (int f = 0; f < channels; f++) { double c = x[f, ix, iy, th]; double l = x[f, Math.Max(0, ix - 1), iy, th]; double r = x[f, Math.Min(inw - 1, ix + 1), iy, th]; double u = x[f, ix, Math.Max(0, iy - 1), th]; double d = x[f, ix, Math.Min(inh - 1, iy + 1), th]; double lu = x[f, Math.Max(0, ix - 1), Math.Max(0, iy - 1), th]; double ru = x[f, Math.Min(inw - 1, ix + 1), Math.Max(0, iy - 1), th]; double ld = x[f, Math.Max(0, ix - 1), Math.Min(inh - 1, iy + 1), th]; double rd = x[f, Math.Min(inw - 1, ix + 1), Math.Min(inh - 1, iy + 1), th]; y[f, ix * 2, iy * 2, th] = (4 * c + 2 * l + 2 * u + lu) / 9; y[f, ix * 2 + 1, iy * 2, th] = (4 * c + 2 * r + 2 * u + ru) / 9; y[f, ix * 2, iy * 2 + 1, th] = (4 * c + 2 * l + 2 * d + ld) / 9; y[f, ix * 2 + 1, iy * 2 + 1, th] = (4 * c + 2 * r + 2 * d + rd) / 9; } } } } return(y); }
public static Map2D Reference(Map2D x, int scale) { int inchannels = x.Channels, batch = x.Batch; if (inchannels % (scale * scale) != 0) { throw new ArgumentException(nameof(scale)); } int inw = x.Width, inh = x.Height, outw = inw * scale, outh = inh * scale; int outchannels = inchannels / (scale * scale); Map2D y = new Map2D(outchannels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ix, iy = 0; iy < inh; iy++) { for (ix = 0; ix < inw; ix++) { for (int kx, ky = 0; ky < scale; ky++) { for (kx = 0; kx < scale; kx++) { for (int outch = 0; outch < outchannels; outch++) { int inch = outch + kx * outchannels + ky * outchannels * scale; y[outch, ix *scale + kx, iy *scale + ky, th] = x[inch, ix, iy, th]; } } } } } } return(y); }
public static Map2D Reference(Map2D x, int leftpad, int rightpad, int toppad, int bottompad) { int channels = x.Channels, batch = x.Batch; int inw = x.Width, inh = x.Height, outw = inw + leftpad + rightpad, outh = inh + toppad + bottompad; Map2D y = new Map2D(channels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ix, iy = 0; iy < inh; iy++) { for (ix = 0; ix < inw; ix++) { for (int ch = 0; ch < channels; ch++) { y[ch, ix + leftpad, iy + toppad, th] = x[ch, ix, iy, th]; } } } } return(y); }
public static Map2D Reference(Map2D x, int lefttrim, int righttrim, int toptrim, int bottomtrim) { int channels = x.Channels, batch = x.Batch; int inw = x.Width, inh = x.Height, outw = inw - lefttrim - righttrim, outh = inh - toptrim - bottomtrim; Map2D y = new Map2D(channels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ox, oy = 0; oy < outh; oy++) { for (ox = 0; ox < outw; ox++) { for (int ch = 0; ch < channels; ch++) { y[ch, ox, oy, th] = x[ch, ox + lefttrim, oy + toptrim, th]; } } } } return(y); }
public static Map2D Reference(Map2D x, int scale) { int inw = x.Width, inh = x.Height, channels = x.Channels, batch = x.Batch; int outw = inw * scale, outh = inh * scale; Map2D y = new Map2D(channels, outw, outh, batch); for (int th = 0; th < batch; th++) { for (int ox, oy = 0; oy < outh; oy++) { for (ox = 0; ox < outw; ox++) { for (int f = 0; f < channels; f++) { y[f, ox, oy, th] = x[f, ox / 2, oy / 2, th]; } } } } return(y); }
public void OptimizeTest() { float max_err = 0; foreach (int batch in new int[] { 1, 2 }) { foreach (int outchannels in new int[] { 3, 5 }) { foreach (int scale 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 * scale, outheight = inheight * scale, inchannels = outchannels * scale * scale; float[] xval = (new float[inwidth * inheight * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); Map2D x = new Map2D(inchannels, inwidth, inheight, batch, xval); Map2D y = Reference(x, scale); Map2D y_optimized = OptimizedReference(x, scale); float[] y_expect = y.ToArray(); float[] y_actual = y_optimized.ToArray(); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{scale},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{scale},{inwidth},{inheight},{batch}"); } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public void OptimizeTest() { 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 inwidth in new int[] { 8, 9, 13, 17 }) { foreach (int inheight in new int[] { 8, 9, 19, 23 }) { float[] xval = (new float[inwidth * inheight * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] gyval = (new float[inwidth * inheight * outchannels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Map2D x = new Map2D(inchannels, inwidth, inheight, batch, xval); Map2D gy = new Map2D(outchannels, inwidth, inheight, batch, gyval); Filter2D gw = Reference(x, gy); Filter2D gw_optimized = OptimizedReference(x, gy); float[] gw_expect = gw.ToArray(); float[] gw_actual = gw_optimized.ToArray(); AssertError.Tolerance(gw_expect, gw_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{inwidth},{inheight},{batch}"); } } } } } Console.WriteLine($"maxerr:{max_err}"); }
public static Map2D Reference(Map2D x, Filter2D w, int kwidth, int kheight, int stride) { int inchannels = x.Channels, outchannels = w.OutChannels, batch = x.Batch; int inw = x.Width, inh = x.Height, outw = (inw - kwidth) / stride + 1, outh = (inh - kheight) / stride + 1; Map2D y = new Map2D(outchannels, outw, outh, batch); for (int kx, ky = 0; ky < kheight; ky++) { for (kx = 0; kx < kwidth; kx++) { for (int th = 0; th < batch; th++) { for (int ox, oy = 0; oy < outh; oy++) { for (ox = 0; ox < outw; ox++) { for (int outch = 0; outch < outchannels; outch++) { double sum = y[outch, ox, oy, th]; for (int inch = 0; inch < inchannels; inch++) { sum += x[inch, kx + ox * stride, ky + oy * stride, th] * w[inch, outch, kx, ky]; } y[outch, ox, oy, th] = sum; } } } } } } return(y); }
public void ReferenceTest() { int channels = 7, kwidth = 3, kheight = 5, stride = 2, inwidth = 13, inheight = 17; int outwidth = (inwidth - kwidth) / stride + 1, outheight = (inheight - kheight) / stride + 1; float[] xval = (new float[inwidth * inheight * channels]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] gyval = (new float[outwidth * outheight * channels]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Map2D x = new Map2D(channels, inwidth, inheight, 1, xval); Map2D gy = new Map2D(channels, outwidth, outheight, 1, gyval); Filter2D gw = Reference(x, gy, kwidth, kheight, stride); float[] gw_expect = { 2.3519020e+00f, 2.3337370e+00f, 2.3154880e+00f, 2.2971550e+00f, 2.2787380e+00f, 2.2602370e+00f, 2.2416520e+00f, 2.3958550e+00f, 2.3773960e+00f, 2.3588530e+00f, 2.3402260e+00f, 2.3215150e+00f, 2.3027200e+00f, 2.2838410e+00f, 2.4398080e+00f, 2.4210550e+00f, 2.4022180e+00f, 2.3832970e+00f, 2.3642920e+00f, 2.3452030e+00f, 2.3260300e+00f, 2.9232910e+00f, 2.9013040e+00f, 2.8792330e+00f, 2.8570780e+00f, 2.8348390e+00f, 2.8125160e+00f, 2.7901090e+00f, 2.9672440e+00f, 2.9449630e+00f, 2.9225980e+00f, 2.9001490e+00f, 2.8776160e+00f, 2.8549990e+00f, 2.8322980e+00f, 3.0111970e+00f, 2.9886220e+00f, 2.9659630e+00f, 2.9432200e+00f, 2.9203930e+00f, 2.8974820e+00f, 2.8744870e+00f, 3.4946800e+00f, 3.4688710e+00f, 3.4429780e+00f, 3.4170010e+00f, 3.3909400e+00f, 3.3647950e+00f, 3.3385660e+00f, 3.5386330e+00f, 3.5125300e+00f, 3.4863430e+00f, 3.4600720e+00f, 3.4337170e+00f, 3.4072780e+00f, 3.3807550e+00f, 3.5825860e+00f, 3.5561890e+00f, 3.5297080e+00f, 3.5031430e+00f, 3.4764940e+00f, 3.4497610e+00f, 3.4229440e+00f, 4.0660690e+00f, 4.0364380e+00f, 4.0067230e+00f, 3.9769240e+00f, 3.9470410e+00f, 3.9170740e+00f, 3.8870230e+00f, 4.1100220e+00f, 4.0800970e+00f, 4.0500880e+00f, 4.0199950e+00f, 3.9898180e+00f, 3.9595570e+00f, 3.9292120e+00f, 4.1539750e+00f, 4.1237560e+00f, 4.0934530e+00f, 4.0630660e+00f, 4.0325950e+00f, 4.0020400e+00f, 3.9714010e+00f, 4.6374580e+00f, 4.6040050e+00f, 4.5704680e+00f, 4.5368470e+00f, 4.5031420e+00f, 4.4693530e+00f, 4.4354800e+00f, 4.6814110e+00f, 4.6476640e+00f, 4.6138330e+00f, 4.5799180e+00f, 4.5459190e+00f, 4.5118360e+00f, 4.4776690e+00f, 4.7253640e+00f, 4.6913230e+00f, 4.6571980e+00f, 4.6229890e+00f, 4.5886960e+00f, 4.5543190e+00f, 4.5198580e+00f, }; float[] gw_actual = gw.ToArray(); AssertError.Tolerance(gw_expect, gw_actual, 1e-7f, 1e-5f, $"mismatch value {channels},{kwidth},{kheight},{stride},{inwidth},{inheight}"); }
public void ReferenceTest() { int inchannels = 7, outchannels = 11, kwidth = 3, kheight = 5, stride = 2, inwidth = 13, inheight = 17, batch = 2; int outwidth = (inwidth - kwidth) / stride + 1, outheight = (inheight - kheight) / stride + 1; float[] xval = (new float[batch * inwidth * inheight * inchannels]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[kwidth * kheight * outchannels * inchannels]).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); float[] y_expect = { 7.885360000e+00f, 7.744240000e+00f, 7.603120000e+00f, 7.462000000e+00f, 7.320880000e+00f, 7.179760000e+00f, 7.038640000e+00f, 6.897520000e+00f, 6.756400000e+00f, 6.615280000e+00f, 6.474160000e+00f, 8.785000000e+00f, 8.633590000e+00f, 8.482180000e+00f, 8.330770000e+00f, 8.179360000e+00f, 8.027950000e+00f, 7.876540000e+00f, 7.725130000e+00f, 7.573720000e+00f, 7.422310000e+00f, 7.270900000e+00f, 9.684640000e+00f, 9.522940000e+00f, 9.361240000e+00f, 9.199540000e+00f, 9.037840000e+00f, 8.876140000e+00f, 8.714440000e+00f, 8.552740000e+00f, 8.391040000e+00f, 8.229340000e+00f, 8.067640000e+00f, 1.058428000e+01f, 1.041229000e+01f, 1.024030000e+01f, 1.006831000e+01f, 9.896320000e+00f, 9.724330000e+00f, 9.552340000e+00f, 9.380350000e+00f, 9.208360000e+00f, 9.036370000e+00f, 8.864380000e+00f, 1.148392000e+01f, 1.130164000e+01f, 1.111936000e+01f, 1.093708000e+01f, 1.075480000e+01f, 1.057252000e+01f, 1.039024000e+01f, 1.020796000e+01f, 1.002568000e+01f, 9.843400000e+00f, 9.661120000e+00f, 1.238356000e+01f, 1.219099000e+01f, 1.199842000e+01f, 1.180585000e+01f, 1.161328000e+01f, 1.142071000e+01f, 1.122814000e+01f, 1.103557000e+01f, 1.084300000e+01f, 1.065043000e+01f, 1.045786000e+01f, 1.958068000e+01f, 1.930579000e+01f, 1.903090000e+01f, 1.875601000e+01f, 1.848112000e+01f, 1.820623000e+01f, 1.793134000e+01f, 1.765645000e+01f, 1.738156000e+01f, 1.710667000e+01f, 1.683178000e+01f, 2.048032000e+01f, 2.019514000e+01f, 1.990996000e+01f, 1.962478000e+01f, 1.933960000e+01f, 1.905442000e+01f, 1.876924000e+01f, 1.848406000e+01f, 1.819888000e+01f, 1.791370000e+01f, 1.762852000e+01f, 2.137996000e+01f, 2.108449000e+01f, 2.078902000e+01f, 2.049355000e+01f, 2.019808000e+01f, 1.990261000e+01f, 1.960714000e+01f, 1.931167000e+01f, 1.901620000e+01f, 1.872073000e+01f, 1.842526000e+01f, 2.227960000e+01f, 2.197384000e+01f, 2.166808000e+01f, 2.136232000e+01f, 2.105656000e+01f, 2.075080000e+01f, 2.044504000e+01f, 2.013928000e+01f, 1.983352000e+01f, 1.952776000e+01f, 1.922200000e+01f, 2.317924000e+01f, 2.286319000e+01f, 2.254714000e+01f, 2.223109000e+01f, 2.191504000e+01f, 2.159899000e+01f, 2.128294000e+01f, 2.096689000e+01f, 2.065084000e+01f, 2.033479000e+01f, 2.001874000e+01f, 2.407888000e+01f, 2.375254000e+01f, 2.342620000e+01f, 2.309986000e+01f, 2.277352000e+01f, 2.244718000e+01f, 2.212084000e+01f, 2.179450000e+01f, 2.146816000e+01f, 2.114182000e+01f, 2.081548000e+01f, 3.127600000e+01f, 3.086734000e+01f, 3.045868000e+01f, 3.005002000e+01f, 2.964136000e+01f, 2.923270000e+01f, 2.882404000e+01f, 2.841538000e+01f, 2.800672000e+01f, 2.759806000e+01f, 2.718940000e+01f, 3.217564000e+01f, 3.175669000e+01f, 3.133774000e+01f, 3.091879000e+01f, 3.049984000e+01f, 3.008089000e+01f, 2.966194000e+01f, 2.924299000e+01f, 2.882404000e+01f, 2.840509000e+01f, 2.798614000e+01f, 3.307528000e+01f, 3.264604000e+01f, 3.221680000e+01f, 3.178756000e+01f, 3.135832000e+01f, 3.092908000e+01f, 3.049984000e+01f, 3.007060000e+01f, 2.964136000e+01f, 2.921212000e+01f, 2.878288000e+01f, 3.397492000e+01f, 3.353539000e+01f, 3.309586000e+01f, 3.265633000e+01f, 3.221680000e+01f, 3.177727000e+01f, 3.133774000e+01f, 3.089821000e+01f, 3.045868000e+01f, 3.001915000e+01f, 2.957962000e+01f, 3.487456000e+01f, 3.442474000e+01f, 3.397492000e+01f, 3.352510000e+01f, 3.307528000e+01f, 3.262546000e+01f, 3.217564000e+01f, 3.172582000e+01f, 3.127600000e+01f, 3.082618000e+01f, 3.037636000e+01f, 3.577420000e+01f, 3.531409000e+01f, 3.485398000e+01f, 3.439387000e+01f, 3.393376000e+01f, 3.347365000e+01f, 3.301354000e+01f, 3.255343000e+01f, 3.209332000e+01f, 3.163321000e+01f, 3.117310000e+01f, 4.297132000e+01f, 4.242889000e+01f, 4.188646000e+01f, 4.134403000e+01f, 4.080160000e+01f, 4.025917000e+01f, 3.971674000e+01f, 3.917431000e+01f, 3.863188000e+01f, 3.808945000e+01f, 3.754702000e+01f, 4.387096000e+01f, 4.331824000e+01f, 4.276552000e+01f, 4.221280000e+01f, 4.166008000e+01f, 4.110736000e+01f, 4.055464000e+01f, 4.000192000e+01f, 3.944920000e+01f, 3.889648000e+01f, 3.834376000e+01f, 4.477060000e+01f, 4.420759000e+01f, 4.364458000e+01f, 4.308157000e+01f, 4.251856000e+01f, 4.195555000e+01f, 4.139254000e+01f, 4.082953000e+01f, 4.026652000e+01f, 3.970351000e+01f, 3.914050000e+01f, 4.567024000e+01f, 4.509694000e+01f, 4.452364000e+01f, 4.395034000e+01f, 4.337704000e+01f, 4.280374000e+01f, 4.223044000e+01f, 4.165714000e+01f, 4.108384000e+01f, 4.051054000e+01f, 3.993724000e+01f, 4.656988000e+01f, 4.598629000e+01f, 4.540270000e+01f, 4.481911000e+01f, 4.423552000e+01f, 4.365193000e+01f, 4.306834000e+01f, 4.248475000e+01f, 4.190116000e+01f, 4.131757000e+01f, 4.073398000e+01f, 4.746952000e+01f, 4.687564000e+01f, 4.628176000e+01f, 4.568788000e+01f, 4.509400000e+01f, 4.450012000e+01f, 4.390624000e+01f, 4.331236000e+01f, 4.271848000e+01f, 4.212460000e+01f, 4.153072000e+01f, 5.466664000e+01f, 5.399044000e+01f, 5.331424000e+01f, 5.263804000e+01f, 5.196184000e+01f, 5.128564000e+01f, 5.060944000e+01f, 4.993324000e+01f, 4.925704000e+01f, 4.858084000e+01f, 4.790464000e+01f, 5.556628000e+01f, 5.487979000e+01f, 5.419330000e+01f, 5.350681000e+01f, 5.282032000e+01f, 5.213383000e+01f, 5.144734000e+01f, 5.076085000e+01f, 5.007436000e+01f, 4.938787000e+01f, 4.870138000e+01f, 5.646592000e+01f, 5.576914000e+01f, 5.507236000e+01f, 5.437558000e+01f, 5.367880000e+01f, 5.298202000e+01f, 5.228524000e+01f, 5.158846000e+01f, 5.089168000e+01f, 5.019490000e+01f, 4.949812000e+01f, 5.736556000e+01f, 5.665849000e+01f, 5.595142000e+01f, 5.524435000e+01f, 5.453728000e+01f, 5.383021000e+01f, 5.312314000e+01f, 5.241607000e+01f, 5.170900000e+01f, 5.100193000e+01f, 5.029486000e+01f, 5.826520000e+01f, 5.754784000e+01f, 5.683048000e+01f, 5.611312000e+01f, 5.539576000e+01f, 5.467840000e+01f, 5.396104000e+01f, 5.324368000e+01f, 5.252632000e+01f, 5.180896000e+01f, 5.109160000e+01f, 5.916484000e+01f, 5.843719000e+01f, 5.770954000e+01f, 5.698189000e+01f, 5.625424000e+01f, 5.552659000e+01f, 5.479894000e+01f, 5.407129000e+01f, 5.334364000e+01f, 5.261599000e+01f, 5.188834000e+01f, 6.636196000e+01f, 6.555199000e+01f, 6.474202000e+01f, 6.393205000e+01f, 6.312208000e+01f, 6.231211000e+01f, 6.150214000e+01f, 6.069217000e+01f, 5.988220000e+01f, 5.907223000e+01f, 5.826226000e+01f, 6.726160000e+01f, 6.644134000e+01f, 6.562108000e+01f, 6.480082000e+01f, 6.398056000e+01f, 6.316030000e+01f, 6.234004000e+01f, 6.151978000e+01f, 6.069952000e+01f, 5.987926000e+01f, 5.905900000e+01f, 6.816124000e+01f, 6.733069000e+01f, 6.650014000e+01f, 6.566959000e+01f, 6.483904000e+01f, 6.400849000e+01f, 6.317794000e+01f, 6.234739000e+01f, 6.151684000e+01f, 6.068629000e+01f, 5.985574000e+01f, 6.906088000e+01f, 6.822004000e+01f, 6.737920000e+01f, 6.653836000e+01f, 6.569752000e+01f, 6.485668000e+01f, 6.401584000e+01f, 6.317500000e+01f, 6.233416000e+01f, 6.149332000e+01f, 6.065248000e+01f, 6.996052000e+01f, 6.910939000e+01f, 6.825826000e+01f, 6.740713000e+01f, 6.655600000e+01f, 6.570487000e+01f, 6.485374000e+01f, 6.400261000e+01f, 6.315148000e+01f, 6.230035000e+01f, 6.144922000e+01f, 7.086016000e+01f, 6.999874000e+01f, 6.913732000e+01f, 6.827590000e+01f, 6.741448000e+01f, 6.655306000e+01f, 6.569164000e+01f, 6.483022000e+01f, 6.396880000e+01f, 6.310738000e+01f, 6.224596000e+01f, 7.805728000e+01f, 7.711354000e+01f, 7.616980000e+01f, 7.522606000e+01f, 7.428232000e+01f, 7.333858000e+01f, 7.239484000e+01f, 7.145110000e+01f, 7.050736000e+01f, 6.956362000e+01f, 6.861988000e+01f, 7.895692000e+01f, 7.800289000e+01f, 7.704886000e+01f, 7.609483000e+01f, 7.514080000e+01f, 7.418677000e+01f, 7.323274000e+01f, 7.227871000e+01f, 7.132468000e+01f, 7.037065000e+01f, 6.941662000e+01f, 7.985656000e+01f, 7.889224000e+01f, 7.792792000e+01f, 7.696360000e+01f, 7.599928000e+01f, 7.503496000e+01f, 7.407064000e+01f, 7.310632000e+01f, 7.214200000e+01f, 7.117768000e+01f, 7.021336000e+01f, 8.075620000e+01f, 7.978159000e+01f, 7.880698000e+01f, 7.783237000e+01f, 7.685776000e+01f, 7.588315000e+01f, 7.490854000e+01f, 7.393393000e+01f, 7.295932000e+01f, 7.198471000e+01f, 7.101010000e+01f, 8.165584000e+01f, 8.067094000e+01f, 7.968604000e+01f, 7.870114000e+01f, 7.771624000e+01f, 7.673134000e+01f, 7.574644000e+01f, 7.476154000e+01f, 7.377664000e+01f, 7.279174000e+01f, 7.180684000e+01f, 8.255548000e+01f, 8.156029000e+01f, 8.056510000e+01f, 7.956991000e+01f, 7.857472000e+01f, 7.757953000e+01f, 7.658434000e+01f, 7.558915000e+01f, 7.459396000e+01f, 7.359877000e+01f, 7.260358000e+01f, 1.072955800e+02f, 1.060174150e+02f, 1.047392500e+02f, 1.034610850e+02f, 1.021829200e+02f, 1.009047550e+02f, 9.962659000e+01f, 9.834842500e+01f, 9.707026000e+01f, 9.579209500e+01f, 9.451393000e+01f, 1.081952200e+02f, 1.069067650e+02f, 1.056183100e+02f, 1.043298550e+02f, 1.030414000e+02f, 1.017529450e+02f, 1.004644900e+02f, 9.917603500e+01f, 9.788758000e+01f, 9.659912500e+01f, 9.531067000e+01f, 1.090948600e+02f, 1.077961150e+02f, 1.064973700e+02f, 1.051986250e+02f, 1.038998800e+02f, 1.026011350e+02f, 1.013023900e+02f, 1.000036450e+02f, 9.870490000e+01f, 9.740615500e+01f, 9.610741000e+01f, 1.099945000e+02f, 1.086854650e+02f, 1.073764300e+02f, 1.060673950e+02f, 1.047583600e+02f, 1.034493250e+02f, 1.021402900e+02f, 1.008312550e+02f, 9.952222000e+01f, 9.821318500e+01f, 9.690415000e+01f, 1.108941400e+02f, 1.095748150e+02f, 1.082554900e+02f, 1.069361650e+02f, 1.056168400e+02f, 1.042975150e+02f, 1.029781900e+02f, 1.016588650e+02f, 1.003395400e+02f, 9.902021500e+01f, 9.770089000e+01f, 1.117937800e+02f, 1.104641650e+02f, 1.091345500e+02f, 1.078049350e+02f, 1.064753200e+02f, 1.051457050e+02f, 1.038160900e+02f, 1.024864750e+02f, 1.011568600e+02f, 9.982724500e+01f, 9.849763000e+01f, 1.189909000e+02f, 1.175789650e+02f, 1.161670300e+02f, 1.147550950e+02f, 1.133431600e+02f, 1.119312250e+02f, 1.105192900e+02f, 1.091073550e+02f, 1.076954200e+02f, 1.062834850e+02f, 1.048715500e+02f, 1.198905400e+02f, 1.184683150e+02f, 1.170460900e+02f, 1.156238650e+02f, 1.142016400e+02f, 1.127794150e+02f, 1.113571900e+02f, 1.099349650e+02f, 1.085127400e+02f, 1.070905150e+02f, 1.056682900e+02f, 1.207901800e+02f, 1.193576650e+02f, 1.179251500e+02f, 1.164926350e+02f, 1.150601200e+02f, 1.136276050e+02f, 1.121950900e+02f, 1.107625750e+02f, 1.093300600e+02f, 1.078975450e+02f, 1.064650300e+02f, 1.216898200e+02f, 1.202470150e+02f, 1.188042100e+02f, 1.173614050e+02f, 1.159186000e+02f, 1.144757950e+02f, 1.130329900e+02f, 1.115901850e+02f, 1.101473800e+02f, 1.087045750e+02f, 1.072617700e+02f, 1.225894600e+02f, 1.211363650e+02f, 1.196832700e+02f, 1.182301750e+02f, 1.167770800e+02f, 1.153239850e+02f, 1.138708900e+02f, 1.124177950e+02f, 1.109647000e+02f, 1.095116050e+02f, 1.080585100e+02f, 1.234891000e+02f, 1.220257150e+02f, 1.205623300e+02f, 1.190989450e+02f, 1.176355600e+02f, 1.161721750e+02f, 1.147087900e+02f, 1.132454050e+02f, 1.117820200e+02f, 1.103186350e+02f, 1.088552500e+02f, 1.306862200e+02f, 1.291405150e+02f, 1.275948100e+02f, 1.260491050e+02f, 1.245034000e+02f, 1.229576950e+02f, 1.214119900e+02f, 1.198662850e+02f, 1.183205800e+02f, 1.167748750e+02f, 1.152291700e+02f, 1.315858600e+02f, 1.300298650e+02f, 1.284738700e+02f, 1.269178750e+02f, 1.253618800e+02f, 1.238058850e+02f, 1.222498900e+02f, 1.206938950e+02f, 1.191379000e+02f, 1.175819050e+02f, 1.160259100e+02f, 1.324855000e+02f, 1.309192150e+02f, 1.293529300e+02f, 1.277866450e+02f, 1.262203600e+02f, 1.246540750e+02f, 1.230877900e+02f, 1.215215050e+02f, 1.199552200e+02f, 1.183889350e+02f, 1.168226500e+02f, 1.333851400e+02f, 1.318085650e+02f, 1.302319900e+02f, 1.286554150e+02f, 1.270788400e+02f, 1.255022650e+02f, 1.239256900e+02f, 1.223491150e+02f, 1.207725400e+02f, 1.191959650e+02f, 1.176193900e+02f, 1.342847800e+02f, 1.326979150e+02f, 1.311110500e+02f, 1.295241850e+02f, 1.279373200e+02f, 1.263504550e+02f, 1.247635900e+02f, 1.231767250e+02f, 1.215898600e+02f, 1.200029950e+02f, 1.184161300e+02f, 1.351844200e+02f, 1.335872650e+02f, 1.319901100e+02f, 1.303929550e+02f, 1.287958000e+02f, 1.271986450e+02f, 1.256014900e+02f, 1.240043350e+02f, 1.224071800e+02f, 1.208100250e+02f, 1.192128700e+02f, 1.423815400e+02f, 1.407020650e+02f, 1.390225900e+02f, 1.373431150e+02f, 1.356636400e+02f, 1.339841650e+02f, 1.323046900e+02f, 1.306252150e+02f, 1.289457400e+02f, 1.272662650e+02f, 1.255867900e+02f, 1.432811800e+02f, 1.415914150e+02f, 1.399016500e+02f, 1.382118850e+02f, 1.365221200e+02f, 1.348323550e+02f, 1.331425900e+02f, 1.314528250e+02f, 1.297630600e+02f, 1.280732950e+02f, 1.263835300e+02f, 1.441808200e+02f, 1.424807650e+02f, 1.407807100e+02f, 1.390806550e+02f, 1.373806000e+02f, 1.356805450e+02f, 1.339804900e+02f, 1.322804350e+02f, 1.305803800e+02f, 1.288803250e+02f, 1.271802700e+02f, 1.450804600e+02f, 1.433701150e+02f, 1.416597700e+02f, 1.399494250e+02f, 1.382390800e+02f, 1.365287350e+02f, 1.348183900e+02f, 1.331080450e+02f, 1.313977000e+02f, 1.296873550e+02f, 1.279770100e+02f, 1.459801000e+02f, 1.442594650e+02f, 1.425388300e+02f, 1.408181950e+02f, 1.390975600e+02f, 1.373769250e+02f, 1.356562900e+02f, 1.339356550e+02f, 1.322150200e+02f, 1.304943850e+02f, 1.287737500e+02f, 1.468797400e+02f, 1.451488150e+02f, 1.434178900e+02f, 1.416869650e+02f, 1.399560400e+02f, 1.382251150e+02f, 1.364941900e+02f, 1.347632650e+02f, 1.330323400e+02f, 1.313014150e+02f, 1.295704900e+02f, 1.540768600e+02f, 1.522636150e+02f, 1.504503700e+02f, 1.486371250e+02f, 1.468238800e+02f, 1.450106350e+02f, 1.431973900e+02f, 1.413841450e+02f, 1.395709000e+02f, 1.377576550e+02f, 1.359444100e+02f, 1.549765000e+02f, 1.531529650e+02f, 1.513294300e+02f, 1.495058950e+02f, 1.476823600e+02f, 1.458588250e+02f, 1.440352900e+02f, 1.422117550e+02f, 1.403882200e+02f, 1.385646850e+02f, 1.367411500e+02f, 1.558761400e+02f, 1.540423150e+02f, 1.522084900e+02f, 1.503746650e+02f, 1.485408400e+02f, 1.467070150e+02f, 1.448731900e+02f, 1.430393650e+02f, 1.412055400e+02f, 1.393717150e+02f, 1.375378900e+02f, 1.567757800e+02f, 1.549316650e+02f, 1.530875500e+02f, 1.512434350e+02f, 1.493993200e+02f, 1.475552050e+02f, 1.457110900e+02f, 1.438669750e+02f, 1.420228600e+02f, 1.401787450e+02f, 1.383346300e+02f, 1.576754200e+02f, 1.558210150e+02f, 1.539666100e+02f, 1.521122050e+02f, 1.502578000e+02f, 1.484033950e+02f, 1.465489900e+02f, 1.446945850e+02f, 1.428401800e+02f, 1.409857750e+02f, 1.391313700e+02f, 1.585750600e+02f, 1.567103650e+02f, 1.548456700e+02f, 1.529809750e+02f, 1.511162800e+02f, 1.492515850e+02f, 1.473868900e+02f, 1.455221950e+02f, 1.436575000e+02f, 1.417928050e+02f, 1.399281100e+02f, 1.657721800e+02f, 1.638251650e+02f, 1.618781500e+02f, 1.599311350e+02f, 1.579841200e+02f, 1.560371050e+02f, 1.540900900e+02f, 1.521430750e+02f, 1.501960600e+02f, 1.482490450e+02f, 1.463020300e+02f, 1.666718200e+02f, 1.647145150e+02f, 1.627572100e+02f, 1.607999050e+02f, 1.588426000e+02f, 1.568852950e+02f, 1.549279900e+02f, 1.529706850e+02f, 1.510133800e+02f, 1.490560750e+02f, 1.470987700e+02f, 1.675714600e+02f, 1.656038650e+02f, 1.636362700e+02f, 1.616686750e+02f, 1.597010800e+02f, 1.577334850e+02f, 1.557658900e+02f, 1.537982950e+02f, 1.518307000e+02f, 1.498631050e+02f, 1.478955100e+02f, 1.684711000e+02f, 1.664932150e+02f, 1.645153300e+02f, 1.625374450e+02f, 1.605595600e+02f, 1.585816750e+02f, 1.566037900e+02f, 1.546259050e+02f, 1.526480200e+02f, 1.506701350e+02f, 1.486922500e+02f, 1.693707400e+02f, 1.673825650e+02f, 1.653943900e+02f, 1.634062150e+02f, 1.614180400e+02f, 1.594298650e+02f, 1.574416900e+02f, 1.554535150e+02f, 1.534653400e+02f, 1.514771650e+02f, 1.494889900e+02f, 1.702703800e+02f, 1.682719150e+02f, 1.662734500e+02f, 1.642749850e+02f, 1.622765200e+02f, 1.602780550e+02f, 1.582795900e+02f, 1.562811250e+02f, 1.542826600e+02f, 1.522841950e+02f, 1.502857300e+02f, 1.774675000e+02f, 1.753867150e+02f, 1.733059300e+02f, 1.712251450e+02f, 1.691443600e+02f, 1.670635750e+02f, 1.649827900e+02f, 1.629020050e+02f, 1.608212200e+02f, 1.587404350e+02f, 1.566596500e+02f, 1.783671400e+02f, 1.762760650e+02f, 1.741849900e+02f, 1.720939150e+02f, 1.700028400e+02f, 1.679117650e+02f, 1.658206900e+02f, 1.637296150e+02f, 1.616385400e+02f, 1.595474650e+02f, 1.574563900e+02f, 1.792667800e+02f, 1.771654150e+02f, 1.750640500e+02f, 1.729626850e+02f, 1.708613200e+02f, 1.687599550e+02f, 1.666585900e+02f, 1.645572250e+02f, 1.624558600e+02f, 1.603544950e+02f, 1.582531300e+02f, 1.801664200e+02f, 1.780547650e+02f, 1.759431100e+02f, 1.738314550e+02f, 1.717198000e+02f, 1.696081450e+02f, 1.674964900e+02f, 1.653848350e+02f, 1.632731800e+02f, 1.611615250e+02f, 1.590498700e+02f, 1.810660600e+02f, 1.789441150e+02f, 1.768221700e+02f, 1.747002250e+02f, 1.725782800e+02f, 1.704563350e+02f, 1.683343900e+02f, 1.662124450e+02f, 1.640905000e+02f, 1.619685550e+02f, 1.598466100e+02f, 1.819657000e+02f, 1.798334650e+02f, 1.777012300e+02f, 1.755689950e+02f, 1.734367600e+02f, 1.713045250e+02f, 1.691722900e+02f, 1.670400550e+02f, 1.649078200e+02f, 1.627755850e+02f, 1.606433500e+02f }; float[] y_actual = y.ToArray(); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, $"mismatch value {inchannels},{outchannels},{kwidth},{kheight},{stride},{inwidth},{inheight},{batch}"); }
public void ReferenceTest() { int inchannels = 12, scale = 2, inwidth = 7, inheight = 5; int outchannels = inchannels / (scale * scale), outwidth = inwidth * scale, outheight = inheight * scale; float[] xval = (new float[inwidth * inheight * inchannels]).Select((_, idx) => idx * 1e-3f).ToArray(); Map2D x = new Map2D(inchannels, inwidth, inheight, 1, xval); Map2D y = Reference(x, scale); float[] y_expect = { 0.000f, 0.001f, 0.002f, 0.003f, 0.004f, 0.005f, 0.012f, 0.013f, 0.014f, 0.015f, 0.016f, 0.017f, 0.024f, 0.025f, 0.026f, 0.027f, 0.028f, 0.029f, 0.036f, 0.037f, 0.038f, 0.039f, 0.040f, 0.041f, 0.048f, 0.049f, 0.050f, 0.051f, 0.052f, 0.053f, 0.060f, 0.061f, 0.062f, 0.063f, 0.064f, 0.065f, 0.072f, 0.073f, 0.074f, 0.075f, 0.076f, 0.077f, 0.006f, 0.007f, 0.008f, 0.009f, 0.010f, 0.011f, 0.018f, 0.019f, 0.020f, 0.021f, 0.022f, 0.023f, 0.030f, 0.031f, 0.032f, 0.033f, 0.034f, 0.035f, 0.042f, 0.043f, 0.044f, 0.045f, 0.046f, 0.047f, 0.054f, 0.055f, 0.056f, 0.057f, 0.058f, 0.059f, 0.066f, 0.067f, 0.068f, 0.069f, 0.070f, 0.071f, 0.078f, 0.079f, 0.080f, 0.081f, 0.082f, 0.083f, 0.084f, 0.085f, 0.086f, 0.087f, 0.088f, 0.089f, 0.096f, 0.097f, 0.098f, 0.099f, 0.100f, 0.101f, 0.108f, 0.109f, 0.110f, 0.111f, 0.112f, 0.113f, 0.120f, 0.121f, 0.122f, 0.123f, 0.124f, 0.125f, 0.132f, 0.133f, 0.134f, 0.135f, 0.136f, 0.137f, 0.144f, 0.145f, 0.146f, 0.147f, 0.148f, 0.149f, 0.156f, 0.157f, 0.158f, 0.159f, 0.160f, 0.161f, 0.090f, 0.091f, 0.092f, 0.093f, 0.094f, 0.095f, 0.102f, 0.103f, 0.104f, 0.105f, 0.106f, 0.107f, 0.114f, 0.115f, 0.116f, 0.117f, 0.118f, 0.119f, 0.126f, 0.127f, 0.128f, 0.129f, 0.130f, 0.131f, 0.138f, 0.139f, 0.140f, 0.141f, 0.142f, 0.143f, 0.150f, 0.151f, 0.152f, 0.153f, 0.154f, 0.155f, 0.162f, 0.163f, 0.164f, 0.165f, 0.166f, 0.167f, 0.168f, 0.169f, 0.170f, 0.171f, 0.172f, 0.173f, 0.180f, 0.181f, 0.182f, 0.183f, 0.184f, 0.185f, 0.192f, 0.193f, 0.194f, 0.195f, 0.196f, 0.197f, 0.204f, 0.205f, 0.206f, 0.207f, 0.208f, 0.209f, 0.216f, 0.217f, 0.218f, 0.219f, 0.220f, 0.221f, 0.228f, 0.229f, 0.230f, 0.231f, 0.232f, 0.233f, 0.240f, 0.241f, 0.242f, 0.243f, 0.244f, 0.245f, 0.174f, 0.175f, 0.176f, 0.177f, 0.178f, 0.179f, 0.186f, 0.187f, 0.188f, 0.189f, 0.190f, 0.191f, 0.198f, 0.199f, 0.200f, 0.201f, 0.202f, 0.203f, 0.210f, 0.211f, 0.212f, 0.213f, 0.214f, 0.215f, 0.222f, 0.223f, 0.224f, 0.225f, 0.226f, 0.227f, 0.234f, 0.235f, 0.236f, 0.237f, 0.238f, 0.239f, 0.246f, 0.247f, 0.248f, 0.249f, 0.250f, 0.251f, 0.252f, 0.253f, 0.254f, 0.255f, 0.256f, 0.257f, 0.264f, 0.265f, 0.266f, 0.267f, 0.268f, 0.269f, 0.276f, 0.277f, 0.278f, 0.279f, 0.280f, 0.281f, 0.288f, 0.289f, 0.290f, 0.291f, 0.292f, 0.293f, 0.300f, 0.301f, 0.302f, 0.303f, 0.304f, 0.305f, 0.312f, 0.313f, 0.314f, 0.315f, 0.316f, 0.317f, 0.324f, 0.325f, 0.326f, 0.327f, 0.328f, 0.329f, 0.258f, 0.259f, 0.260f, 0.261f, 0.262f, 0.263f, 0.270f, 0.271f, 0.272f, 0.273f, 0.274f, 0.275f, 0.282f, 0.283f, 0.284f, 0.285f, 0.286f, 0.287f, 0.294f, 0.295f, 0.296f, 0.297f, 0.298f, 0.299f, 0.306f, 0.307f, 0.308f, 0.309f, 0.310f, 0.311f, 0.318f, 0.319f, 0.320f, 0.321f, 0.322f, 0.323f, 0.330f, 0.331f, 0.332f, 0.333f, 0.334f, 0.335f, 0.336f, 0.337f, 0.338f, 0.339f, 0.340f, 0.341f, 0.348f, 0.349f, 0.350f, 0.351f, 0.352f, 0.353f, 0.360f, 0.361f, 0.362f, 0.363f, 0.364f, 0.365f, 0.372f, 0.373f, 0.374f, 0.375f, 0.376f, 0.377f, 0.384f, 0.385f, 0.386f, 0.387f, 0.388f, 0.389f, 0.396f, 0.397f, 0.398f, 0.399f, 0.400f, 0.401f, 0.408f, 0.409f, 0.410f, 0.411f, 0.412f, 0.413f, 0.342f, 0.343f, 0.344f, 0.345f, 0.346f, 0.347f, 0.354f, 0.355f, 0.356f, 0.357f, 0.358f, 0.359f, 0.366f, 0.367f, 0.368f, 0.369f, 0.370f, 0.371f, 0.378f, 0.379f, 0.380f, 0.381f, 0.382f, 0.383f, 0.390f, 0.391f, 0.392f, 0.393f, 0.394f, 0.395f, 0.402f, 0.403f, 0.404f, 0.405f, 0.406f, 0.407f, 0.414f, 0.415f, 0.416f, 0.417f, 0.418f, 0.419f, }; float[] y_actual = y.ToArray(); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, $"mismatch value {inchannels},{outchannels},{scale},{inwidth},{inheight}"); }