I’m trying to apply eigs over an array of matrices using broadcast. The thing is I want to apply eigs with certain qualifiers such as: eigs(A;nev=6,which=:SM,sigma=0.01).
The general syntax for broadcast is however: broadcast(f,array). How do I use broadcast in my case? or is there another alternative?
What’s the problem of using
eigs.(arrayOfMatrices;nev=6,which=:SM,sigma=0.01)
?
(note the dot)
3 Likes
This discussion made me wonder how the dot deals with kwargs, because I always thought it lowered straightforwardly to broadcast
. That’s not the case.
The dot notation in conjuction with kwargs
creates a more involved broadcasted expression
julia> Meta.@lower f.([1,2];a=2)
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope'
1 ─ %1 = Base.vect(1, 2)
│ %2 = Base.broadcasted_kwsyntax
│ %3 = Core.tuple(:a)
│ %4 = Core.apply_type(Core.NamedTuple, %3)
│ %5 = Core.tuple(2)
│ %6 = (%4)(%5)
│ %7 = Core.kwfunc(%2)
│ %8 = (%7)(%6, %2, f, %1)
│ %9 = Base.materialize(%8)
└── return %9
))))
help?> Base.broadcasted_kwsyntax
No documentation found.
Base.Broadcast.broadcasted_kwsyntax is a Function.
# 1 method for generic function "broadcasted_kwsyntax":
[1] broadcasted_kwsyntax(f, args...; kwargs...) in Base.Broadcast at broadcast.jl:1297
julia> Base.broadcasted_kwsyntax(f, [1,2]; a=2)
Base.Broadcast.Broadcasted(#31, ([1, 2],))
So, yes, stick with the dot syntax