【问题标题】:Matrix-vector-multiplication, Lost in Lapack矩阵向量乘法,迷失在 Lapack 中
【发布时间】:2021-06-03 05:20:50
【问题描述】:

我想计算

x^T A x*(x转置乘以矩阵A乘以x共轭复数)

使用 Lapack。我没有找到这个功能。还是有一个?最快的方法是什么?

【问题讨论】:

  • 我假设您是在询问 Fortran 代码?

标签: matrix vector multiplication lapack


【解决方案1】:

您可以分两步计算运算:

  1. 计算y <- A x*
  2. 计算res <- x^T y

我在下面的程序中实现了这个

program main

  use blas95

  implicit none

  integer, parameter :: n = 2
  complex :: x(n), y(n), A(n,n), res

  complex :: cdotu

  ! init vector x, matrix A by some data
  x = [(1, 1), (-1, 2)]
  A = reshape([1, 2, 3, 4], [n, n])

  ! compute: y <- A * conjg(x)
  call cgemv('N', n, n, (1, 0), A, n, conjg(x), 1, (0, 0), y, 1)    ! standard BLAS
  call gemv(A, conjg(x), y)                                         ! BLAS95 from intel MKL

  ! compute: res <- x^T * y
  res = cdotu(n, x, 1, y, 1)                                        ! standard BLAS
  res = dotu(x, y)                                                  ! BLAS95 from intel MKL
end program

注意:我包括了标准 BLAS 例程以及通过英特尔 MKL 提供的 BLAS95 例程。


链接到英特尔的文档

【讨论】:

    猜你喜欢
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 2020-01-17
    • 2016-01-23
    • 2017-11-08
    相关资源
    最近更新 更多