Exemplo n.º 1
0
        public void ScaleUTest(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.Scale(DEFAULT_SCALE, dst, dst.Length);
            var actual = dst;

            Assert.Equal(expected, actual, comparer);
        }
Exemplo n.º 2
0
        public void ScaleTest(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.Scale(DefaultScale, dst);
            var actual = dst;

            Assert.Equal(expected, actual, _comparer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Multiples the array by a real value
        /// </summary>
        /// <param name="dst">The array</param>
        /// <param name="c">Value to multiply vector with</param>
        public static void ScaleBy(Float[] dst, Float c)
        {
            if (c == 1)
            {
                return;
            }

            if (c != 0)
            {
                CpuMathUtils.Scale(c, dst);
            }
            else
            {
                Array.Clear(dst, 0, dst.Length);
            }
        }
Exemplo n.º 4
0
        public void ScaleSrcUTest(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] *= defaultScale;
            }

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

            Assert.Equal(expected, actual, _comparer);
        }
Exemplo n.º 5
0
        public void ScaleTest(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.Scale(defaultScale, dst);
                var actual = dst;
                Assert.Equal(expected, actual, _comparer);
                return(RemoteExecutor.SuccessExitCode);
            }, mode, test, scale, new RemoteInvokeOptions(environmentVariables));
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
 public void ScaleSrcU()
 => CpuMathUtils.Scale(DefaultScale, src, dst, _smallInputLength);
Exemplo n.º 8
0
 public void Scale()
 => CpuMathUtils.Scale(DefaultScale, dst.AsSpan(0, _smallInputLength));
 public void ManagedScaleUPerf() => CpuMathUtils.Scale(DEFAULT_SCALE, dst, LEN);