Пример #1
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));
        }
Пример #2
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));
        }
Пример #3
0
 /// <summary>
 /// Perform in-place vector addition <c><paramref name="dst"/> += <paramref name="src"/></c>.
 /// </summary>
 public static void Add(Float[] src, Float[] dst)
 {
     Contracts.CheckValue(src, nameof(src));
     Contracts.CheckValue(dst, nameof(dst));
     Contracts.CheckParam(src.Length == dst.Length, nameof(dst), "Arrays must have the same dimensionality.");
     if (src.Length == 0)
     {
         return;
     }
     CpuMathUtils.Add(src, dst, src.Length);
 }
Пример #4
0
        public void AddScalarUTest(int test)
        {
            float[] dst      = (float[])testArrays[test].Clone();
            float[] expected = (float[])dst.Clone();

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

            CpuMathUtils.Add(DEFAULT_SCALE, dst, dst.Length);
            var actual = dst;

            Assert.Equal(expected, actual, comparer);
        }
Пример #5
0
        public void AddScalarUTest(int test)
        {
            float[] dst      = (float[])_testArrays[test].Clone();
            float[] expected = (float[])dst.Clone();

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

            CpuMathUtils.Add(DefaultScale, dst);
            var actual = dst;

            Assert.Equal(expected, actual, _comparer);
        }
Пример #6
0
        public void AddSUTest(int test)
        {
            float[] src      = (float[])testArrays[test].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;

            CpuMathUtils.Add(src, idx, dst, idx.Length);
            var actual = dst;

            Assert.Equal(expected, actual, comparer);
        }
Пример #7
0
        public void AddScalarUTest(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;
                }

                CpuMathUtils.Add(defaultScale, dst);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
Пример #8
0
        public void AddUTest(int test)
        {
            float[] src      = (float[])testArrays[test].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);
        }
Пример #9
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));
        }
Пример #10
0
        private static void FillValues(IExceptionContext ectx, ref VBuffer <Float> src, ref VBuffer <Float> dst, Float divisor, Float scale, Float offset = 0)
        {
            int count  = src.Count;
            int length = src.Length;

            ectx.Assert(Utils.Size(src.Values) >= count);
            ectx.Assert(divisor >= 0);

            if (count == 0)
            {
                dst = new VBuffer <Float>(length, 0, dst.Values, dst.Indices);
                return;
            }
            ectx.Assert(count > 0);
            ectx.Assert(length > 0);

            Float normScale = scale;

            if (divisor > 0)
            {
                normScale /= divisor;
            }

            // Don't normalize small values.
            if (normScale < MinScale)
            {
                normScale = 1;
            }

            if (offset == 0)
            {
                var dstValues = dst.Values;
                if (Utils.Size(dstValues) < count)
                {
                    dstValues = new Float[count];
                }
                var dstIndices = dst.Indices;
                if (!src.IsDense)
                {
                    if (Utils.Size(dstIndices) < count)
                    {
                        dstIndices = new int[count];
                    }
                    Array.Copy(src.Indices, dstIndices, count);
                }

                CpuMathUtils.Scale(normScale, src.Values, dstValues, count);
                dst = new VBuffer <Float>(length, count, dstValues, dstIndices);

                return;
            }

            // Subtracting the mean requires a dense representation.
            src.CopyToDense(ref dst);

            if (normScale != 1)
            {
                CpuMathUtils.ScaleAdd(normScale, -offset, dst.Values, length);
            }
            else
            {
                CpuMathUtils.Add(-offset, dst.Values, length);
            }
        }
Пример #11
0
 public void AddSU()
 => CpuMathUtils.Add(src, idx, dst, _smallInputLength);
Пример #12
0
 public void AddScalarU()
 => CpuMathUtils.Add(DefaultScale, dst.AsSpan(0, _smallInputLength));
Пример #13
0
 public void ManagedAddSUPerf() => CpuMathUtils.Add(src, idx, dst, IDXLEN);
Пример #14
0
 public void ManagedAddUPerf() => CpuMathUtils.Add(src, dst, LEN);
Пример #15
0
 public void ManagedAddScalarUPerf() => CpuMathUtils.Add(DEFAULT_SCALE, dst, LEN);