matrix - 矩阵向量乘法,迷失在 Lapack 中
问题描述
我想计算
x^TA x* (x 转置乘以矩阵 A 乘以 x 共轭复数)
使用 Lapack。我没有找到这个功能。还是有一个?最快的方法是什么?
解决方案
您可以分两个单独的步骤计算操作:
- 计算
y <- A x*
- 计算
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 例程。
链接到英特尔的文档
推荐阅读
- kubernetes - 从 http 到 https 的重定向不适用于 Kubernetes Nginx Ingress Controller 中的自定义后端服务
- ios - 使用 multipartFormData 请求 Swift 保存 Alamofire 上传
- ios - 谷歌地图不显示 - 未能解码瓷砖
- python - 将任务的结果输入到 Celery 中的地图中
- python - 每批更新损失值以获得平均历元损失
- namedtuple - 更新 NamedTuple 中的字段(通过键入)
- javascript - 如何使用javascript删除数组中甚至没有再次出现的元素?
- git - Visual Code Studio 和 Github:我的新分支没有考虑我的更改
- angular - 在 Angular 中,我应该在哪里存储用户对象,以便在导航设置中引用它以获取可用性?
- javascript - 使用 Context API 与 CloneElement 为直接后代传递道具