I am trying to have two arbitrary length vectors (typical length will be 2048) and multiply element by element. So Z[n] = X[n] * Y[n] for all n.
The code I have setup to test is fairly basic:
float inputX[4] = { 2, 4, 8, 16 };
float inputY[4] = { 2, 4, 8, 16 };
catlas_saxpby(4, 1, inputX, 1, 1, inputY, 1);
The result goes into inputY, and the result is
4.000000, 8.000000, 16.000000, 32.000000
Which if they were multiplying it should be 4, 16, 64, 256. But it looks like it is adding.
So this is not doing what I expect, and the documentation doesn’t give me enough information to figure what it is doing.
Any ideas?
Apple's documentation for BLAS says this:
Computes the product of two vectors, scaling each one separately (single-precision).
void catlas_saxpby (
const int N,
const float alpha,
const float *X,
const int incX,
const float beta,
float *Y,
const int incY
);
Parameters
N
Number of elements in the vector.
alpha
Scaling factor for X.
X
Input vector X.
incX
Stride within X. For example, if incX is 7, every 7th element is used.
beta
Scaling factor for Y.
Y
Input vector Y.
incY
Stride within Y. For example, if incY is 7, every 7th element is used.
Discussion
On return, the contents of vector Y are replaced with the result.
The Apple documentation is mistaken. The
saxpbyfunction computes the expressionalpha*X + beta*Yfor scalarsalphaandbetaand vectorsXandY.I don’t think there’s a function available to compute the element-wise product of two vectors, since that’s not a common operation in linear algebra. You could take the diagonal of the outer product, but that’s a severe waste of effort since it computes the entire outer product (N2 multiplications instead of N).