/// <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) { SseUtils.Scale(c, dst, dst.Length); } else { Array.Clear(dst, 0, dst.Length); } }
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 Scale(float a, float[] dst, int count) => SseUtils.Scale(a, dst, count);