Matrix-vector product with dgemm/dgemv

匆匆过客 提交于 2019-12-04 11:19:15

You are right, the problem is in incx value - it should be 1, take a look at reference.

INCX is INTEGER
  On entry, INCX specifies the increment for the elements of
  X. INCX must not be zero.

So this value should be used when values of vector x is not placed one by one (vector of complex values for example, when you want to use only real part).

Also you can not use vecmatprod(v,A,v,SIZE) with v as both x and y. This is because how matrix-vector multiplication works (see wikipedia for example). You need values of original x the whole time to produce correct result. Small example:

y = A * x 

where

y = [ y1 y2 ]
A = [ [a11 a12] [a21 a22] ]
x = [ x1 x2 ]

And we calculate y like this

y1 = a11 * x1 + a12 * x2
y2 = a21 * x1 + a22 * x2

You can see, that when we calculate y2 we need x1 and x2, but if you use x = A * x(without temporary vector) you will replace x1 with y1 thus produce wrong answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!