Пример #1
0
 public static void LoopSafeExp(this Algo.MathProvider provider, double[] array, double[] result, int count)
 {
     for (var i = 0; i < count; i++)
     {
         result[i] = System.Math.Exp(array[i]);
     }
 }
Пример #2
0
 public static void LoopSafeAdd(this Algo.MathProvider provider, float[] array, float scalar, float[] result, int count)
 {
     for (var i = 0; i < count; i++)
     {
         result[i] = array[i] + scalar;
     }
 }
Пример #3
0
 public static unsafe void LoopAdd(this Algo.MathProvider provider, float[] array, float scalar, float[] result, int count)
 {
     fixed(float *src = &array[0])
     fixed(float *tgt = &result[0])
     {
         for (var i = 0; i < count; i++)
         {
             *(float *)(tgt + i) = ((*(float *)(src + i)) + scalar);
         }
     }
 }
Пример #4
0
        public static void SIMDAdd(this Algo.MathProvider provider, float[] array, float scalar, float[] result, int count)
        {
            var vectorSize   = Vector <float> .Count;
            var scalarVector = new Vector <float>(scalar);
            int i            = 0;

            for (i = 0; i + vectorSize < count; i = i + vectorSize)
            {
                var vector       = new Vector <float>(array, i);
                var resultVector = vector * scalarVector;
                resultVector.CopyTo(result, i);
            }
            if (count > vectorSize)
            {
                i = i - vectorSize + 1;
            }
            for (int j = i; j < count; j++)
            {
                result[j] = array[j] + scalar;
            }
        }
Пример #5
0
 public static int AddTwoInts(this Algo.MathProvider provider, int first, int second)
 {
     return(first + second);
 }