I wouldn’t do this with a macro. If you use StaticArrays.jl you’ll get the same codegen, and if you use Symbolics.jl you can easily trace it to symbolic form and call build_function
for codegen.
using Symbolics, StaticArrays
@variables A[1:4,1:4] B[1:4,1:4]
A,B = collect(A), collect(B)
A*B
4×4 Matrix{Num}:
A[1, 1]*B[1, 1] + A[1, 2]*B[2, 1] + A[1, 3]*B[3, 1] + A[1, 4]*B[4, 1] … A[1, 1]*B[1, 4] + A[1, 2]*B[2, 4] + A[1, 3]*B[3, 4] + A[1, 4]*B[4, 4]
A[2, 1]*B[1, 1] + A[2, 2]*B[2, 1] + A[2, 3]*B[3, 1] + A[2, 4]*B[4, 1] A[2, 1]*B[1, 4] + A[2, 2]*B[2, 4] + A[2, 3]*B[3, 4] + A[2, 4]*B[4, 4]
A[3, 1]*B[1, 1] + A[3, 2]*B[2, 1] + A[3, 3]*B[3, 1] + A[3, 4]*B[4, 1] A[3, 1]*B[1, 4] + A[3, 2]*B[2, 4] + A[3, 3]*B[3, 4] + A[3, 4]*B[4, 4]
A[4, 1]*B[1, 1] + A[4, 2]*B[2, 1] + A[4, 3]*B[3, 1] + A[4, 4]*B[4, 1] A[4, 1]*B[1, 4] + A[4, 2]*B[2, 4] + A[4, 3]*B[3, 4] + A[4, 4]*B[4, 4]
build_function(A*B,A,B)
:(function (ˍ₋out, ˍ₋arg1, ˍ₋arg2)
#= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:303 =#
#= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:304 =#
let var"A[1, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[1]), var"A[2, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[2]), var"A[3, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[3]), var"A[4, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[4]), var"A[1, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[5]), var"A[2, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[6]), var"A[3, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[7]), var"A[4, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[8]), var"A[1, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[9]), var"A[2, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[10]), var"A[3, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[11]), var"A[4, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[12]), var"A[1, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[13]), var"A[2, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[14]), var"A[3, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[15]), var"A[4, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg1[16]), var"B[1, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[1]), var"B[2, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[2]), var"B[3, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[3]), var"B[4, 1]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[4]), var"B[1, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[5]), var"B[2, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[6]), var"B[3, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[7]), var"B[4, 2]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[8]), var"B[1, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[9]), var"B[2, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[10]), var"B[3, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[11]), var"B[4, 3]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[12]), var"B[1, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[13]), var"B[2, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[14]), var"B[3, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[15]), var"B[4, 4]" = #= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:190 =# @inbounds(ˍ₋arg2[16])
#= C:\Users\accou\.julia\packages\Symbolics\LfLYY\src\build_function.jl:374 =#
#= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:350 =# @inbounds begin
#= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:346 =#
ˍ₋out[1] = (+)((+)((+)((*)(var"A[1, 1]", var"B[1, 1]"), (*)(var"A[1, 2]", var"B[2, 1]")), (*)(var"A[1, 3]", var"B[3, 1]")), (*)(var"A[1, 4]", var"B[4, 1]"))
ˍ₋out[2] = (+)((+)((+)((*)(var"A[2, 1]", var"B[1, 1]"), (*)(var"A[2, 2]", var"B[2, 1]")), (*)(var"A[2, 3]", var"B[3, 1]")), (*)(var"A[2, 4]", var"B[4, 1]"))
ˍ₋out[3] = (+)((+)((+)((*)(var"A[3, 1]", var"B[1, 1]"), (*)(var"A[3, 2]", var"B[2, 1]")), (*)(var"A[3, 3]", var"B[3, 1]")), (*)(var"A[3, 4]", var"B[4, 1]"))
ˍ₋out[4] = (+)((+)((+)((*)(var"A[4, 1]", var"B[1, 1]"), (*)(var"A[4, 2]", var"B[2, 1]")), (*)(var"A[4, 3]", var"B[3, 1]")), (*)(var"A[4, 4]", var"B[4, 1]"))
ˍ₋out[5] = (+)((+)((+)((*)(var"A[1, 1]", var"B[1, 2]"), (*)(var"A[1, 2]", var"B[2, 2]")), (*)(var"A[1, 3]", var"B[3, 2]")), (*)(var"A[1, 4]", var"B[4, 2]"))
ˍ₋out[6] = (+)((+)((+)((*)(var"A[2, 1]", var"B[1, 2]"), (*)(var"A[2, 2]", var"B[2, 2]")), (*)(var"A[2, 3]", var"B[3, 2]")), (*)(var"A[2, 4]", var"B[4, 2]"))
ˍ₋out[7] = (+)((+)((+)((*)(var"A[3, 1]", var"B[1, 2]"), (*)(var"A[3, 2]", var"B[2, 2]")), (*)(var"A[3, 3]", var"B[3, 2]")), (*)(var"A[3, 4]", var"B[4, 2]"))
ˍ₋out[8] = (+)((+)((+)((*)(var"A[4, 1]", var"B[1, 2]"), (*)(var"A[4, 2]", var"B[2, 2]")), (*)(var"A[4, 3]", var"B[3, 2]")), (*)(var"A[4, 4]", var"B[4, 2]"))
ˍ₋out[9] = (+)((+)((+)((*)(var"A[1, 1]", var"B[1, 3]"), (*)(var"A[1, 2]", var"B[2, 3]")), (*)(var"A[1, 3]", var"B[3, 3]")), (*)(var"A[1, 4]", var"B[4, 3]"))
ˍ₋out[10] = (+)((+)((+)((*)(var"A[2, 1]", var"B[1, 3]"), (*)(var"A[2, 2]", var"B[2, 3]")), (*)(var"A[2, 3]", var"B[3, 3]")), (*)(var"A[2, 4]", var"B[4, 3]"))
ˍ₋out[11] = (+)((+)((+)((*)(var"A[3, 1]", var"B[1, 3]"), (*)(var"A[3, 2]", var"B[2, 3]")), (*)(var"A[3, 3]", var"B[3, 3]")), (*)(var"A[3, 4]", var"B[4, 3]"))
ˍ₋out[12] = (+)((+)((+)((*)(var"A[4, 1]", var"B[1, 3]"), (*)(var"A[4, 2]", var"B[2, 3]")), (*)(var"A[4, 3]", var"B[3, 3]")), (*)(var"A[4, 4]", var"B[4, 3]"))
ˍ₋out[13] = (+)((+)((+)((*)(var"A[1, 1]", var"B[1, 4]"), (*)(var"A[1, 2]", var"B[2, 4]")), (*)(var"A[1, 3]", var"B[3, 4]")), (*)(var"A[1, 4]", var"B[4, 4]"))
ˍ₋out[14] = (+)((+)((+)((*)(var"A[2, 1]", var"B[1, 4]"), (*)(var"A[2, 2]", var"B[2, 4]")), (*)(var"A[2, 3]", var"B[3, 4]")), (*)(var"A[2, 4]", var"B[4, 4]"))
ˍ₋out[15] = (+)((+)((+)((*)(var"A[3, 1]", var"B[1, 4]"), (*)(var"A[3, 2]", var"B[2, 4]")), (*)(var"A[3, 3]", var"B[3, 4]")), (*)(var"A[3, 4]", var"B[4, 4]"))
ˍ₋out[16] = (+)((+)((+)((*)(var"A[4, 1]", var"B[1, 4]"), (*)(var"A[4, 2]", var"B[2, 4]")), (*)(var"A[4, 3]", var"B[3, 4]")), (*)(var"A[4, 4]", var"B[4, 4]"))
#= C:\Users\accou\.julia\packages\SymbolicUtils\0KTj4\src\code.jl:348 =#
nothing
end
end
end)