public void ReferenceTest() { int inchannels = 8, outchannels = 12, batch = 3; float[] xval = (new float[batch * inchannels]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[outchannels * inchannels / 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(); QuaternionMap0D x = new QuaternionMap0D(inchannels / 4, batch, xcval); QuaternionFilter0D w = new QuaternionFilter0D(inchannels / 4, outchannels / 4, wcval); QuaternionMap0D y = Reference(x, w); float[] y_expect = { -3.520000e-04f, 1.440000e-04f, 3.200000e-04f, 2.200000e-04f, -1.920000e-04f, 8.000000e-05f, 1.920000e-04f, 1.240000e-04f, -3.200000e-05f, 1.600000e-05f, 6.400000e-05f, 2.800000e-05f, -9.280000e-04f, 7.840000e-04f, 9.920000e-04f, 8.280000e-04f, -5.120000e-04f, 4.640000e-04f, 6.080000e-04f, 4.760000e-04f, -9.600000e-05f, 1.440000e-04f, 2.240000e-04f, 1.240000e-04f, -1.504000e-03f, 1.424000e-03f, 1.664000e-03f, 1.436000e-03f, -8.320000e-04f, 8.480000e-04f, 1.024000e-03f, 8.280000e-04f, -1.600000e-04f, 2.720000e-04f, 3.840000e-04f, 2.200000e-04f, }; float[] y_actual = y.ToArray(); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, $"mismatch value {inchannels},{outchannels},{batch}"); }
public void ReferenceTest() { int inchannels = 8, outchannels = 12, batch = 3; float[] yval = (new float[outchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[outchannels * inchannels / 4]).Select((_, idx) => idx * 1e-3f).Reverse().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(); 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(); QuaternionMap0D y = new QuaternionMap0D(outchannels / 4, batch, ycval); QuaternionFilter0D w = new QuaternionFilter0D(inchannels / 4, outchannels / 4, wcval); QuaternionMap0D x = Reference(y, w); float[] x_expect = { -3.880000e-04f, 2.080000e-04f, 4.120000e-04f, 2.740000e-04f, -2.200000e-04f, 1.120000e-04f, 2.680000e-04f, 1.540000e-04f, -1.252000e-03f, 1.216000e-03f, 1.492000e-03f, 1.210000e-03f, -7.960000e-04f, 8.320000e-04f, 1.060000e-03f, 8.020000e-04f, -2.116000e-03f, 2.224000e-03f, 2.572000e-03f, 2.146000e-03f, -1.372000e-03f, 1.552000e-03f, 1.852000e-03f, 1.450000e-03f, }; float[] x_actual = x.ToArray(); AssertError.Tolerance(x_expect, x_actual, 1e-7f, 1e-5f, $"mismatch value {inchannels},{outchannels},{batch}"); }
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 }) { float[] xval = (new float[inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[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(); QuaternionMap0D x = new QuaternionMap0D(inchannels / 4, batch, xcval); QuaternionFilter0D w = new QuaternionFilter0D(inchannels / 4, outchannels / 4, wcval); QuaternionMap0D y = Reference(x, w); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 4), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch)); QuaternionDense ope = new QuaternionDense(inchannels, outchannels, gradmode: false, batch); ope.Execute(x_tensor, w_tensor, y_tensor); float[] y_expect = y.ToArray(); float[] y_actual = y_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(wval, w_tensor.State); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{batch}"); } } } Console.WriteLine($"maxerr:{max_err}"); }