Hi, I would like to perform the following element operations to a matrix W (m rows and n columns):
W(i, j) := a*W(i, j) - b*d(j)y(i),
where a and b are scalars, d(j) are the elements of a vector d with n elements, and y(i) are the elements of a vector y with m elements.
In Julia, this can be easily programmed using the following code:
W .= a.*W .- b.*(y*d')
Although the dots prevent some memory allocation, matrix product
y*d' allocates memory. (This operation is to be performed multiple time inside a cycle.)
Is there any way to do the whole operation with simple operations and without memory allocation (if there was no matrix product this could be easy done with broadcasting)? Or the only way out is to do two nested for cycles?
I can pre-allocate memory for the matrix product, but I would like to avoid that.