Esempio n. 1
0
        public void ScaleAddUTest(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 * (dst[i] + DEFAULT_SCALE);
            }

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

            Assert.Equal(expected, actual, comparer);
        }
Esempio n. 2
0
        public void ScaleAddUTest(int test)
        {
            float[] dst      = (float[])_testArrays[test].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);
        }
Esempio n. 3
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));
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
 public void ScaleAddU()
 => CpuMathUtils.ScaleAdd(DefaultScale, DefaultScale, dst.AsSpan(0, _smallInputLength));
Esempio n. 6
0
 public void ManagedScaleAddUPerf() => CpuMathUtils.ScaleAdd(DEFAULT_SCALE, DEFAULT_SCALE, dst, LEN);