Let’s say I have a function
function compute(x::Vector, y::Vector) return (x' * y) / sum(y) end
y are vector with 0 or 1 values on each cell.
Based on this definition, I want to automatically generate a function, where for the variable in the denominator (
y), I created a matrix Y, the rest variables remain to be vectors. The generated function should be something like:
function compute_generated(x::Vector, Y::Matrix) n = size(Y, 1) result = 0 for i = 1:n result += x' * Y[:,i] / i end return result end
What is the best way to perform this task?
I took a look at the Julia manual about
@generated function, but I am still confused about if the concept can be applied to the task.