예제 #1
0
        /// <summary>
        /// Adds a multiple of an array to a second array.
        /// </summary>
        /// <param name="src">Array to add</param>
        /// <param name="dst">Array to add to</param>
        /// <param name="c">Multiple</param>
        public static void AddMult(Float[] src, Float[] dst, Float c)
        {
            Contracts.Check(src.Length == dst.Length, "Arrays must have the same dimensionality.");

            if (c == 0)
            {
                return;
            }

            CpuMathUtils.AddScale(c, src, dst, src.Length);
        }
예제 #2
0
        public void AddScaleSUTest(int test, float defaultScale)
        {
            float[] src      = (float[])_testArrays[test].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);
        }
예제 #3
0
        public void AddScaleUTest(int test)
        {
            float[] src      = (float[])testArrays[test].Clone();
            float[] dst      = (float[])src.Clone();
            float[] expected = (float[])dst.Clone();

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

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

            Assert.Equal(expected, actual, comparer);
        }
예제 #4
0
        public void AddScaleUTest(int test, float defaultScale)
        {
            float[] src      = (float[])_testArrays[test].Clone();
            float[] dst      = (float[])src.Clone();
            float[] expected = (float[])dst.Clone();

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

            CpuMathUtils.AddScale(defaultScale, src, dst, dst.Length);
            var actual = dst;

            Assert.Equal(expected, actual, _comparer);
        }
예제 #5
0
        public void AddScaleSUTest(int test)
        {
            float[] src      = (float[])testArrays[test].Clone();
            float[] dst      = (float[])src.Clone();
            int[]   idx      = testIndexArray;
            float[] expected = (float[])dst.Clone();

            expected[0] = 5.292f;
            expected[2] = -13.806f;
            expected[5] = -43.522f;
            expected[6] = 55.978f;

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

            Assert.Equal(expected, actual, comparer);
        }
예제 #6
0
        public void AddScaleUTest(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();
                float[] expected   = (float[])dst.Clone();

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

                CpuMathUtils.AddScale(defaultScale, src, dst, dst.Length);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
예제 #7
0
        /// <summary>
        /// Adds a multiple of a <see cref="VBuffer{T}"/> to a <see cref="Float"/> array.
        /// </summary>
        /// <param name="src">Buffer to add</param>
        /// <param name="dst">Array to add to</param>
        /// <param name="c">Coefficient</param>
        public static void AddMult(ref VBuffer <Float> src, Float[] dst, Float c)
        {
            Contracts.CheckValue(dst, nameof(dst));
            Contracts.CheckParam(src.Length == dst.Length, nameof(dst), "Arrays must have the same dimensionality.");

            if (src.Count == 0 || c == 0)
            {
                return;
            }

            if (src.IsDense)
            {
                CpuMathUtils.AddScale(c, src.Values, dst, src.Count);
            }
            else
            {
                for (int i = 0; i < src.Count; i++)
                {
                    dst[src.Indices[i]] += c * src.Values[i];
                }
            }
        }
예제 #8
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));
        }
예제 #9
0
        public void AddScaleSUTest(int test)
        {
            float[] src      = (float[])_testArrays[test].Clone();
            float[] dst      = (float[])src.Clone();
            int[]   idx      = _testIndexArray;
            float[] expected = (float[])dst.Clone();

            expected[0]  = 5.292f;
            expected[2]  = -13.806f;
            expected[5]  = -43.522f;
            expected[6]  = 55.978f;
            expected[8]  = -178.869f;
            expected[11] = -31.941f;
            expected[12] = -51.205f;
            expected[13] = -21.337f;
            expected[14] = 35.782f;

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

            Assert.Equal(expected, actual, _comparer);
        }
예제 #10
0
 public void AddScaleSU()
 => CpuMathUtils.AddScale(DefaultScale, src, idx, dst, _smallInputLength);
예제 #11
0
 public void ManagedAddScaleSUPerf() => CpuMathUtils.AddScale(DEFAULT_SCALE, src, idx, dst, IDXLEN);
예제 #12
0
 public void ManagedAddScaleUPerf() => CpuMathUtils.AddScale(DEFAULT_SCALE, src, dst, LEN);