Example #1
0
        public void SdcaL1UpdateSUTest(string mode, string test, string scale, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) =>
            {
                CheckProperFlag(arg0);
                float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture);
                float[] src        = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] v          = (float[])src.Clone();
                float[] w          = (float[])src.Clone();
                int[] idx          = _testIndexArray;
                float[] expected   = (float[])w.Clone();

                for (int i = 0; i < idx.Length; i++)
                {
                    int index       = idx[i];
                    float value     = v[index] + src[i] * defaultScale;
                    expected[index] = Math.Abs(value) > defaultScale ? (value > 0 ? value - defaultScale : value + defaultScale) : 0;
                }

                CpuMathUtils.SdcaL1UpdateSparse(defaultScale, idx.Length, src, idx, defaultScale, v, w);
                var actual = w;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
Example #2
0
        public void DotSUTest(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg0);
                float[] src = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst = (float[])src.Clone();
                int[] idx   = _testIndexArray;

                // Ensures src and dst are different arrays
                for (int i = 0; i < dst.Length; i++)
                {
                    dst[i] += 1;
                }

                float expected = 0;
                for (int i = 0; i < idx.Length; i++)
                {
                    int index = idx[i];
                    expected += src[index] * dst[i];
                }

                var actual = CpuMathUtils.DotProductSparse(src, dst, idx, idx.Length);
                Assert.Equal(expected, actual, 2);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }
Example #3
0
        public void Dist2Test(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg0);
                float[] src = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst = (float[])src.Clone();

                // Ensures src and dst are different arrays
                for (int i = 0; i < dst.Length; i++)
                {
                    dst[i] += 1;
                }

                float expected = 0;
                for (int i = 0; i < dst.Length; i++)
                {
                    float distance = src[i] - dst[i];
                    expected      += distance * distance;
                }

                var actual = CpuMathUtils.L2DistSquared(src, dst, dst.Length);
                Assert.Equal(expected, actual, 0);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }
Example #4
0
        public void MulElementWiseUTest(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg1);
                float[] src1 = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] src2 = (float[])src1.Clone();
                float[] dst  = (float[])src1.Clone();

                // Ensures src1 and src2 are different arrays
                for (int i = 0; i < src2.Length; i++)
                {
                    src2[i] += 1;
                }

                float[] expected = (float[])src1.Clone();

                for (int i = 0; i < expected.Length; i++)
                {
                    expected[i] *= (1 + expected[i]);
                }

                CpuMathUtils.MulElementWise(src1, src2, dst, dst.Length);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }
Example #5
0
        public void AddUTest(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg0);
                float[] src      = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst      = (float[])src.Clone();
                float[] expected = (float[])src.Clone();

                // Ensures src and dst are different arrays
                for (int i = 0; i < dst.Length; i++)
                {
                    dst[i] += 1;
                }

                for (int i = 0; i < expected.Length; i++)
                {
                    expected[i] = 2 * expected[i] + 1;
                }

                CpuMathUtils.Add(src, dst, dst.Length);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }
Example #6
0
        public void AddSUTest(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg0);
                float[] src      = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst      = (float[])src.Clone();
                int[] idx        = _testIndexArray;
                float[] expected = (float[])dst.Clone();

                expected[0]  = 3.92f;
                expected[2]  = -12.14f;
                expected[5]  = -36.69f;
                expected[6]  = 46.29f;
                expected[8]  = -104.41f;
                expected[11] = -13.09f;
                expected[12] = -73.92f;
                expected[13] = -23.64f;
                expected[14] = 34.41f;

                CpuMathUtils.Add(src, idx, dst, idx.Length);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }
Example #7
0
        public void MatTimesSrcSparseTest(string mode, string matTest, string srcTest, string dstTest, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1, arg2, arg3) =>
            {
                CheckProperFlag(arg0);
                AlignedArray mat = _testMatrices[int.Parse(arg1)];
                AlignedArray src = _testSrcVectors[int.Parse(arg2)];
                AlignedArray dst = _testDstVectors[int.Parse(arg3)];
                int[] idx        = _testIndexArray;

                float[] expected = new float[dst.Size];
                int limit        = (int.Parse(arg2) == 0) ? 4 : 9;
                for (int i = 0; i < dst.Size; i++)
                {
                    float dotProduct = 0;
                    for (int j = 0; j < limit; j++)
                    {
                        int col     = idx[j];
                        dotProduct += mat[i * src.Size + col] * src[col];
                    }
                    expected[i] = dotProduct;
                }

                CpuMathUtils.MatrixTimesSource(mat, idx, src, 0, 0, limit, dst, dst.Size);
                float[] actual = new float[dst.Size];
                dst.CopyTo(actual, 0, dst.Size);
                Assert.Equal(expected, actual, _matMulComparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, matTest, srcTest, dstTest, new RemoteInvokeOptions(environmentVariables));
        }
Example #8
0
        public void SumAbsUTest(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg0);
                float[] src    = (float[])_testArrays[int.Parse(arg1)].Clone();
                float expected = 0;
                for (int i = 0; i < src.Length; i++)
                {
                    expected += Math.Abs(src[i]);
                }

                var actual = CpuMathUtils.SumAbs(src);
                Assert.Equal(expected, actual, 2);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }
Example #9
0
        public void SumSqDiffUTest(string mode, string test, string scale, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) =>
            {
                CheckProperFlag(arg0);
                float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture);
                float[] src        = (float[])_testArrays[int.Parse(arg1)].Clone();
                var actual         = CpuMathUtils.SumSq(defaultScale, src);

                float expected = 0;
                for (int i = 0; i < src.Length; i++)
                {
                    expected += (src[i] - defaultScale) * (src[i] - defaultScale);
                }

                Assert.Equal(expected, actual, 2);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
Example #10
0
        public void ScaleAddUTest(string mode, string test, string scale, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) =>
            {
                CheckProperFlag(arg0);
                float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture);
                float[] dst        = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] expected   = (float[])dst.Clone();

                for (int i = 0; i < expected.Length; i++)
                {
                    expected[i] = defaultScale * (dst[i] + defaultScale);
                }

                CpuMathUtils.ScaleAdd(defaultScale, defaultScale, dst);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
Example #11
0
        public void AddScaleSUTest(string mode, string test, string scale, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) =>
            {
                CheckProperFlag(arg0);
                float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture);
                float[] src        = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst        = (float[])src.Clone();
                int[] idx          = _testIndexArray;
                float[] expected   = (float[])dst.Clone();

                CpuMathUtils.AddScale(defaultScale, src, idx, dst, idx.Length);
                for (int i = 0; i < idx.Length; i++)
                {
                    int index        = idx[i];
                    expected[index] += defaultScale * src[i];
                }

                Assert.Equal(expected, dst, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
Example #12
0
        public void AddScaleCopyUTest(string mode, string test, string scale, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) =>
            {
                CheckProperFlag(arg0);
                float defaultScale = float.Parse(arg2);
                float[] src        = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst        = (float[])src.Clone();
                float[] result     = (float[])dst.Clone();
                float[] expected   = (float[])dst.Clone();

                for (int i = 0; i < expected.Length; i++)
                {
                    expected[i] *= (1 + defaultScale);
                }

                CpuMathUtils.AddScaleCopy(defaultScale, src, dst, result, dst.Length);
                var actual = result;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
Example #13
0
        public void AddSUTest(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg0);
                float[] src      = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst      = (float[])src.Clone();
                int[] idx        = _testIndexArray;
                int limit        = int.Parse(arg1) == 2 ? 9 : 18;
                float[] expected = (float[])dst.Clone();

                for (int i = 0; i < limit; i++)
                {
                    int index        = idx[i];
                    expected[index] += src[i];
                }

                CpuMathUtils.Add(src, idx, dst, limit);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }
Example #14
0
        public void DotUTest(string mode, string test, Dictionary <string, string> environmentVariables)
        {
            RemoteExecutor.RemoteInvoke((arg0, arg1) =>
            {
                CheckProperFlag(arg0);
                float[] src = (float[])_testArrays[int.Parse(arg1)].Clone();
                float[] dst = (float[])src.Clone();

                for (int i = 0; i < dst.Length; i++)
                {
                    dst[i] += 1;
                }

                float expected = 0;
                for (int i = 0; i < dst.Length; i++)
                {
                    expected += src[i] * dst[i];
                }

                var actual = CpuMathUtils.DotProductDense(src, dst, dst.Length);
                Assert.Equal(expected, actual, 1);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, new RemoteInvokeOptions(environmentVariables));
        }