Tullio.jl
Tullio.jl copied to clipboard
Method error when broadcast and sum of matrices
I want to broadcast a vector of matrix, with summation inside. Here are codes:
julia> using Tullio
julia> x=range(start=-1,length=10,stop=1);
julia> e=rand(10);
julia> @tullio _[n]:=inv([x[n] -1.0;-1.0 x[n]-e[k]]);
ERROR: MethodError: no method matching zero(::Type{Matrix{Float64}})
How could I solve this?
One way around this would be to make an SMatrix:
julia> using StaticArrays
julia> @tullio _[n]:=inv(SA[x[n] -1.0;-1.0 x[n]-e[k]])
10-element Vector{SMatrix{2, 2, Float64, 4}}:
[-59.268603211659475 49.268603211659475; 49.268603211659475 -49.268603211659475]
[-105.02504355561057 71.68614498769712; 71.68614498769712 -55.75589054598665]
[32.05997726703162 -27.81109848168423; -27.81109848168423 15.450610267602352]
[11.503726225353875 -13.83457540845129; -13.83457540845129 4.61152513615043]
[6.187636920067604 -10.687515213340845; -10.687515213340845 1.187501690371205]
[3.252429208089766 -9.638618976878915; -9.638618976878915 -1.070957664097657]
[0.9437739165213922 -9.68540869449287; -9.68540869449287 -3.2284695648309567]
[-1.5995821417135907 -10.888656745396439; -10.888656745396439 -6.049253747442466]
[-5.961552626696227 -14.636763154097064; -14.636763154097064 -11.384149119853273]
[-39.26860321165948 -49.26860321165948; -49.26860321165948 -49.26860321165948]
julia> ans[1]
2×2 SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
-59.2686 49.2686
49.2686 -49.2686