Example #1
0
        public static void SdcaL1UpdateSparse(float primalUpdate, int count, ReadOnlySpan <float> source, ReadOnlySpan <int> indices, float threshold, Span <float> v, Span <float> w)
        {
            Contracts.AssertNonEmpty(source);
            Contracts.AssertNonEmpty(indices);
            Contracts.AssertNonEmpty(v);
            Contracts.AssertNonEmpty(w);
            Contracts.Assert(count > 0);
            Contracts.Assert(count <= source.Length);
            Contracts.Assert(count <= indices.Length);
            Contracts.Assert(count <= v.Length);
            Contracts.Assert(count <= w.Length);

            if (Avx.IsSupported)
            {
                AvxIntrinsics.SdcaL1UpdateSU(primalUpdate, count, source, indices, threshold, v, w);
            }
            else if (Sse.IsSupported)
            {
                SseIntrinsics.SdcaL1UpdateSU(primalUpdate, count, source, indices, threshold, v, w);
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    int index = indices[i];
                    v[index] += source[i] * primalUpdate;
                    float value = v[index];
                    w[index] = Math.Abs(value) > threshold ? (value > 0 ? value - threshold : value + threshold) : 0;
                }
            }
        }
Example #2
0
 private static void SdcaL1UpdateSparse(float primalUpdate, Span <float> src, Span <int> indices, float threshold, Span <float> v, Span <float> w)
 {
     if (Sse.IsSupported)
     {
         SseIntrinsics.SdcaL1UpdateSU(primalUpdate, src, indices, threshold, v, w);
     }
     else
     {
         for (int i = 0; i < indices.Length; i++)
         {
             int index = indices[i];
             v[index] += src[i] * primalUpdate;
             float value = v[index];
             w[index] = Math.Abs(value) > threshold ? (value > 0 ? value - threshold : value + threshold) : 0;
         }
     }
 }