Ejemplo n.º 1
0
 /// <summary>
 /// Populates a target matrix with the product of the operands
 /// </summary>
 /// <param name="A">The left matrix</param>
 /// <param name="B">The right matrix</param>
 /// <param name="M">The number of rows in A and C</param>
 /// <param name="N">The number of columns in B and C</param>
 /// <param name="K">The number of columns in A and rows in B</param>
 public static ref BlockMatrix <N, T> gemm <N, T>(BlockMatrix <N, T> A, BlockMatrix <N, T> B, ref BlockMatrix <N, T> X)
     where N : ITypeNat, new()
     where T : struct
 {
     if (typeof(T) == typeof(float))
     {
         var Z = X.As <float>();
         gemm(A.As <float>(), B.As <float>(), ref Z);
     }
     else if (typeof(T) == typeof(double))
     {
         var x = X.As <double>();
         gemm(A.As <double>(), B.As <double>(), ref x);
     }
     else if (typeof(T) == typeof(int) || typeof(T) == typeof(uint) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort))
     {
         var Z = X.Convert <double>();
         X = gemm(A.Convert <double>(), B.Convert <double>(), ref Z).Convert <T>();
     }
     else if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong))
     {
         var Z = X.Convert <double>();
         X = gemm(A.Convert <double>(), B.Convert <double>(), ref Z).Convert <T>();
     }
     else if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte))
     {
         var Z = X.Convert <float>();
         X = gemm(A.Convert <float>(), B.Convert <float>(), ref Z).Convert <T>();
     }
     return(ref X);
 }