/// <summary> /// Accord.NET /// Computes the product <c>A*B'</c> of matrix <c>A</c> and transpose of <c>B</c>. /// </summary> /// /// <param name="a">The left matrix <c>A</c>.</param> /// <param name="b">The transposed right matrix <c>B</c>.</param> /// /// <returns>The product <c>A*B'</c> of the given matrices <c>A</c> and <c>B</c>.</returns> /// public static double[,] DotWithTransposed(this double[,] a, double[,] b, double[,] result) { #if DEBUG if (a.Columns() != b.Columns() || result.Rows() > a.Rows() || result.Columns() > b.Rows()) { throw new Exception("Dimension mismatch!"); } // var C = MatrixEx.Dot(a.To <double[, ]>(), b.Transpose().To <double[, ]>()); #endif int n = a.Columns(); int m = a.Rows(); int p = b.Rows(); unsafe { fixed(double *A = a) fixed(double *B = b) fixed(double *R = result) { double *pr = R; for (int i = 0; i < m; i++) { double *pb = B; for (int j = 0; j < p; j++, pr++) { double *pa = A + n * i; double s = (double)0; for (int k = 0; k < n; k++) { s += (double)((double)(*pa++) * (double)(*pb++)); } *pr = (double)s; } } } } #if DEBUG if (!MatrixEx.IsEqual(C, result.To <double[, ]>(), 1e-4)) { throw new Exception(); } #endif return(result); }