Take the following matrix and vector:
vij = [-2 -2 -2; 1 0 0; 0 1 0; 0 0 1; 1 1 1] xj = [0.1 0.15 0.1]
This operation will work, resulting in a vector (as expected):
However, if the matrix is reduced to one row and the vector to one element, as follows:
vij = [-2 -2 -2] xj = [0.1]
; the previous calculation will fail.
The only line of code I have come up with to make it work in both cases is the following:
However, the trade-off is a higher computational cost, which may become relevant for large systems (> 1E6 rows/columns). I am trying to write a script that can be generalized to any matrix/vector system while being as efficient as possible.
Is there a way to make this
sum(vij.*xj, dims=2) much faster, or just a different approach to this problem?