Is there some way to get what a call to broadcast would return, possibly similar to how promote works? An example of what I need is something like this:
Unfortunately, it does not provide the correct result:
julia> promote_type(typeof(a1), typeof(a2))
SArray{S,Float32,N,L} where L where N where S<:Tuple
julia> promote_type(typeof(a1), typeof(a2)) == SArray{Tuple{3,4}, Float32, 2, 12}
false
Makes sense. Do you know if there is a way to get the specific type without doing the actual op? I’ve meanwhile come up with the following hacky way to get it to work, but I’m not knowledgable enough about Julia to identify its shortcomings:
function vector_op(a, b)
@. a + b
end
function promote_vectorized(a::DataType, b::DataType)::DataType
Base.promote_op(vector_op, a, b)
end
@assert typeof(a1 .+ a2) == promote_vectorized(typeof(a1), typeof(a2))
For my use case, I think this will work well enough. To briefly summarize, I am stringing together pieces of user-provided code and inserting type checks in between so that if one piece of code is written incorrectly, a nice error is produced before moving on to the other pieces of code, so the error can more easily be identified. I want to use it like this:
const StereoBuffer = SArray{Tuple{2, 512}, Float32, 2, 1024}
# Check that some_var can be used in math operations with other audio data.
@assert promote_vectorized(typeof(some_var), StereoBuffer) == StereoBuffer