Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method error when broadcast and sum of matrices #166

Open
zxm403089989 opened this issue Mar 29, 2023 · 1 comment
Open

Method error when broadcast and sum of matrices #166

zxm403089989 opened this issue Mar 29, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@zxm403089989
Copy link

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?

@mcabbott
Copy link
Owner

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

@mcabbott mcabbott added the documentation Improvements or additions to documentation label Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants