Hello,
I would like to perform a broadcast operation on views with indices stored in a struct. I am not sure how exactly to acheive this with Julia syntax.
Essentially I have a struct like so:
struct Foo
id::Integer
work::AbstractArray
end
where work
contains a list of indices, and a vector of type Foo, bar = [Foo(1, [1,2]), Foo(2, [3,4])]
.
I would like to perform a broadcasting dot
operation for example, but with indices from bar
. So essentially, I would like to iterate through the array of Foo
and create views for two vecs using the indices work
.
out = broadcast(dot, view(vec1, ?bar.work), view(vec2, ?bar.work))
I know I can do this with a for loop:
out = zeros(Float, size(Bar))
idx=1
for i in eachindex(bar)
out[idx] = dot(view(vec1, i.work), view(vec2, i.work))
idx++
end
but I think this would be more efficient and scalable with a broadcast, as for me the indices are guaranteed to be indepedent.