Пример #1
0
        public static void SdcaL1UpdateDense(float primalUpdate, int count, ReadOnlySpan <float> source, float threshold, Span <float> v, Span <float> w)
        {
            Contracts.AssertNonEmpty(source);
            Contracts.AssertNonEmpty(v);
            Contracts.AssertNonEmpty(w);
            Contracts.Assert(count > 0);
            Contracts.Assert(count <= source.Length);
            Contracts.Assert(count <= v.Length);
            Contracts.Assert(count <= w.Length);

            if (Avx.IsSupported)
            {
                AvxIntrinsics.SdcaL1UpdateU(primalUpdate, count, source, threshold, v, w);
            }
            else if (Sse.IsSupported)
            {
                SseIntrinsics.SdcaL1UpdateU(primalUpdate, count, source, threshold, v, w);
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    v[i] += source[i] * primalUpdate;
                    float value = v[i];
                    w[i] = Math.Abs(value) > threshold ? (value > 0 ? value - threshold : value + threshold) : 0;
                }
            }
        }
Пример #2
0
 private static void SdcaL1UpdateDense(float primalUpdate, Span <float> src, float threshold, Span <float> v, Span <float> w)
 {
     if (Sse.IsSupported)
     {
         SseIntrinsics.SdcaL1UpdateU(primalUpdate, src, threshold, v, w);
     }
     else
     {
         for (int i = 0; i < src.Length; i++)
         {
             v[i] += src[i] * primalUpdate;
             float value = v[i];
             w[i] = Math.Abs(value) > threshold ? (value > 0 ? value - threshold : value + threshold) : 0;
         }
     }
 }