/// <summary>Performs a symmetric rank-2k update, i.e. C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C with a symmetric matrix C. /// </summary> /// <param name="n">The order of matrix C.</param> /// <param name="k">The The number of columns of matrices A and B or the number .</param> /// <param name="alpha">The scalar \alpha.</param> /// <param name="a">The matrix A supplied column-by-column of dimension (<paramref name="lda" />, ka), where ka is <paramref name="k" /> if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise <paramref name="n" />.</param> /// <param name="b">The matrix B supplied column-by-column of dimension (<paramref name="ldb" />, kb), where ka is at least max(1,<paramref name="n" />) if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise at least max(1,<paramref name="k" />).</param> /// <param name="beta">The scalar \beta.</param> /// <param name="c">The symmetric matrix C supplied column-by-column of dimension (<paramref name="ldc" />, <paramref name="n" />).</param> /// <param name="lda">The leading dimension of <paramref name="a" />, must be at least max(1,<paramref name="n" />) if to calculate C:= alpha*A*B^t+alpha*B*A^t+beta*C; max(1,<paramref name="k" />) otherwise.</param> /// <param name="ldb">The leading dimension of <paramref name="b" />, must be at least max(1,<paramref name="n" />) if to calculate C:= alpha*A*B^t+alpha*B*A^t+beta*C; max(1,<paramref name="k" />) otherwise.</param> /// <param name="ldc">The leading dimension of <paramref name="c" />, must be at least max(1,<paramref name="n" />).</param> /// <param name="triangularMatrixType">A value whether matrix C is in its upper or lower triangular representation.</param> /// <param name="operation">A value indicating whether to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C.</param> public void zsyr2k(int n, int k, Complex alpha, Complex[] a, Complex[] b, Complex beta, Complex[] c, int lda, int ldb, int ldc, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.UpperTriangularMatrix, BLAS.Xsyr2kOperation operation = BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans) { if (operation == BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans) // C := \alpha * A*B' + \alpha * B *A' +C { if (triangularMatrixType == BLAS.TriangularMatrixType.UpperTriangularMatrix) { for (int j = 0; j < n; j++) { for (int i = 0; i <= j; i++) { c[i + j * ldc] *= beta; } for (int ell = 0; ell < k; ell++) { Complex temp = alpha * b[j + ell * ldb]; Complex temp2 = alpha * a[j + ell * lda]; for (int i = 0; i <= j; i++) { c[i + j * ldc] += b[i + ell * ldb] * temp2 + a[i + ell * lda] * temp; } } } } else { for (int j = 0; j < n; j++) { for (int i = j; i < n; i++) { c[i + j * ldc] *= beta; } for (int ell = 0; ell < k; ell++) { Complex temp = alpha * b[j + ell * ldb]; Complex temp2 = alpha * a[j + ell * lda]; for (int i = j; i < n; i++) { c[i + j * ldc] += a[i + ell * lda] * temp + b[i + ell * ldb] * temp2; } } } } } else // C := \alpha * A' * B + \alpha * B' * A + C. { if (triangularMatrixType == BLAS.TriangularMatrixType.UpperTriangularMatrix) { for (int j = 0; j < n; j++) { for (int i = 0; i <= j; i++) { Complex temp = 0.0; Complex temp2 = 0.0; for (int ell = 0; ell < k; ell++) { temp += a[ell + i * lda] * b[ell + j * ldb]; temp2 += b[ell + i * ldb] * a[ell + j * lda]; } c[i + j * ldc] = alpha * temp2 + alpha * temp + beta * c[i + j * ldc]; } } } else { for (int j = 0; j < n; j++) { for (int i = j; i < n; i++) { Complex temp = 0.0; Complex temp2 = 0.0; for (int ell = 0; ell < k; ell++) { temp += a[ell + i * lda] * b[ell + j * ldb]; temp2 += b[ell + i * ldb] * a[ell + j * lda]; } c[i + j * ldc] = alpha * temp2 + alpha * temp + beta * c[i + j * ldc]; } } } } }
/// <summary>Performs a symmetric rank-2k update, i.e. C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C with a symmetric matrix C. /// </summary> /// <param name="level3">The BLAS level 3 implementation.</param> /// <param name="n">The order of matrix C.</param> /// <param name="k">The The number of columns of matrices A and B or the number .</param> /// <param name="alpha">The scalar \alpha.</param> /// <param name="a">The matrix A supplied column-by-column of dimension (<paramref name="lda"/>, ka), where ka is <paramref name="k"/> if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise <paramref name="n"/>.</param> /// <param name="b">The matrix B supplied column-by-column of dimension (<paramref name="ldb"/>, kb), where ka is at least max(1,<paramref name="n"/>) if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise at least max(1,<paramref name="k"/>).</param> /// <param name="beta">The scalar \beta.</param> /// <param name="c">The symmetric matrix C supplied column-by-column of dimension (<paramref name="ldc"/>, <paramref name="n"/>).</param> /// <param name="lda">The leading dimension of <paramref name="a"/>, must be at least max(1,<paramref name="n"/>) if to calculate C:= alpha*A*B^t+alpha*B*A^t+beta*C; max(1,<paramref name="k"/>) otherwise.</param> /// <param name="ldb">The leading dimension of <paramref name="b"/>, must be at least max(1,<paramref name="n"/>) if to calculate C:= alpha*A*B^t+alpha*B*A^t+beta*C; max(1,<paramref name="k"/>) otherwise.</param> /// <param name="ldc">The leading dimension of <paramref name="c"/>, must be at least max(1,<paramref name="n"/>).</param> /// <param name="triangularMatrixType">A value whether matrix C is in its upper or lower triangular representation.</param> /// <param name="operation">A value indicating whether to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C.</param> public static void dsyr2k(this ILevel3BLAS level3, int n, int k, double alpha, double[] a, double[] b, double beta, double[] c, int lda, int ldb, int ldc, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.UpperTriangularMatrix, BLAS.Xsyr2kOperation operation = BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans) { level3.dsyr2k(n, k, alpha, a, b, beta, c, operation == BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans ? n : k, operation == BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans ? n : k, n, triangularMatrixType, operation); }
/// <summary>Performs a symmetric rank-2k update, i.e. C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C with a symmetric matrix C. /// </summary> /// <param name="level3">The BLAS level 3 implementation.</param> /// <param name="n">The order of matrix C.</param> /// <param name="k">The The number of columns of matrices A and B or the number .</param> /// <param name="alpha">The scalar \alpha.</param> /// <param name="a">The matrix A supplied column-by-column of dimension (s, ka), where s = <paramref name="n"/>, ka = <paramref name="k"/> if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise s=<paramref name="k"/>, ka = <paramref name="n"/>.</param> /// <param name="b">The matrix B supplied column-by-column of dimension (s, kb), where s = <paramref name="n"/>, ka is at least max(1,<paramref name="n"/>) if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise s at least max(1,<paramref name="k"/> and ka at least max(1,<paramref name="k"/>).</param> /// <param name="beta">The scalar \beta.</param> /// <param name="c">The symmetric matrix C supplied column-by-column of dimension (<paramref name="n"/>, <paramref name="n"/>).</param> /// <param name="triangularMatrixType">A value whether matrix C is in its upper or lower triangular representation.</param> /// <param name="operation">A value indicating whether to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C.</param> public static void zsyr2k(this ILevel3BLAS level3, int n, int k, Complex alpha, Complex[] a, Complex[] b, Complex beta, Complex[] c, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.UpperTriangularMatrix, BLAS.Xsyr2kOperation operation = BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans) { level3.zsyr2k(n, k, alpha, a, b, beta, c, operation == BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans ? n : k, operation == BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans ? n : k, n, triangularMatrixType, operation); }
/// <summary>Performs a symmetric rank-2k update, i.e. C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C with a symmetric matrix C. /// </summary> /// <param name="n">The order of matrix C.</param> /// <param name="k">The The number of columns of matrices A and B or the number .</param> /// <param name="alpha">The scalar \alpha.</param> /// <param name="a">The matrix A supplied column-by-column of dimension (<paramref name="lda"/>, ka), where ka is <paramref name="k"/> if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise <paramref name="n"/>.</param> /// <param name="b">The matrix B supplied column-by-column of dimension (<paramref name="ldb"/>, kb), where ka is at least max(1,<paramref name="n"/>) if to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C; otherwise at least max(1,<paramref name="k"/>).</param> /// <param name="beta">The scalar \beta.</param> /// <param name="c">The symmetric matrix C supplied column-by-column of dimension (<paramref name="ldc"/>, <paramref name="n"/>).</param> /// <param name="lda">The leading dimension of <paramref name="a"/>, must be at least max(1,<paramref name="n"/>) if to calculate C:= alpha*A*B^t+alpha*B*A^t+beta*C; max(1,<paramref name="k"/>) otherwise.</param> /// <param name="ldb">The leading dimension of <paramref name="b"/>, must be at least max(1,<paramref name="n"/>) if to calculate C:= alpha*A*B^t+alpha*B*A^t+beta*C; max(1,<paramref name="k"/>) otherwise.</param> /// <param name="ldc">The leading dimension of <paramref name="c"/>, must be at least max(1,<paramref name="n"/>).</param> /// <param name="triangularMatrixType">A value whether matrix C is in its upper or lower triangular representation.</param> /// <param name="operation">A value indicating whether to calculate C := alpha*A*B^t + alpha*B*A^t + beta*C or C := alpha*A^t*B + alpha*B^t*A + beta*C.</param> public void dsyr2k(int n, int k, double alpha, double[] a, double[] b, double beta, double[] c, int lda, int ldb, int ldc, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.UpperTriangularMatrix, BLAS.Xsyr2kOperation operation = BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans) { if (n == 0 || ((alpha == 0.0 || k == 0) && (beta == 1.0))) { return; // nothing to do } if (operation == BLAS.Xsyr2kOperation.ATimesBTransPlusBTimesATrans) // C = \alpha *A*B' + \alpha *B*A' + C { if (triangularMatrixType == BLAS.TriangularMatrixType.UpperTriangularMatrix) { for (int j = 0; j < n; j++) { for (int i = 0; i <= j; i++) { c[i + j * ldc] = beta * c[i + j * ldc]; } for (int ell = 0; ell < k; ell++) { double temp1 = alpha * b[j + ell * ldb]; double temp2 = alpha * a[j + ell * lda]; for (int i = 0; i <= j; i++) { c[i + j * ldc] = c[i + j * ldc] + a[i + ell * lda] * temp1 + b[i + ell * ldb] * temp2; } } } } else { for (int j = 0; j < n; j++) { for (int i = j; i < n; i++) { c[i + j * ldc] = beta * c[i + j * ldc]; } for (int ell = 0; ell < k; ell++) { double temp1 = alpha * b[j + ell * ldb]; double temp2 = alpha * a[j + ell * lda]; for (int i = j; i < n; i++) { c[i + j * ldc] = c[i + j * ldc] + a[i + ell * lda] * temp1 + b[i + ell * ldb] * temp2; } } } } } else // C = \alpha *A' * B + \alpha *B' * A + C { if (triangularMatrixType == BLAS.TriangularMatrixType.UpperTriangularMatrix) { for (int j = 0; j < n; j++) { for (int i = 0; i <= j; i++) { double temp1 = 0.0; double temp2 = 0.0; for (int ell = 0; ell < k; ell++) { temp1 += a[ell + i * lda] * b[ell + j * ldb]; temp2 += b[ell + i * ldb] * a[ell + j * lda]; } c[i + j * ldc] = beta * c[i + j * ldc] + alpha * temp1 + alpha * temp2; } } } else { for (int j = 0; j < n; j++) { for (int i = j; i < n; i++) { double temp1 = 0.0; double temp2 = 0.0; for (int ell = 0; ell < k; ell++) { temp1 += a[ell + i * lda] * b[ell + j * ldb]; temp2 += b[ell + i * ldb] * a[ell + j * lda]; } c[i + j * ldc] = beta * c[i + j * ldc] + alpha * temp1 + alpha * temp2; } } } } }