Ejemplo n.º 1
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;
     }
     SseUtils.Add(src, dst, src.Length);
 }
Ejemplo n.º 2
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);
                }

                SseUtils.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)
            {
                SseUtils.ScaleAdd(normScale, -offset, dst.Values, length);
            }
            else
            {
                SseUtils.Add(-offset, dst.Values, length);
            }
        }
 public static void Add(float[] src, int[] indices, float[] dst, int dstOffset, int count) => SseUtils.Add(src, indices, dst, dstOffset, count);
 public static void Add(float[] src, float[] dst, int count) => SseUtils.Add(src, dst, count);