-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Description
I was wondering what is the recommended way to modify subviews of a band. My first naive try, which perhaps shows that I don't know that much about how array indexing works in julia, was the following:
B = BandedMatrix{Float64}(undef, 5, 5, 0, 0)
B[band(0)] .= 1.0
B5×5 BandedMatrix{Float64} with bandwidths (0, 0):
1.0 ⋅ ⋅ ⋅ ⋅
⋅ 1.0 ⋅ ⋅ ⋅
⋅ ⋅ 1.0 ⋅ ⋅
⋅ ⋅ ⋅ 1.0 ⋅
⋅ ⋅ ⋅ ⋅ 1.0
B[band(0)][2:end-1] .= -1.0 1.0 ⋅ ⋅ ⋅ ⋅
⋅ 1.0 ⋅ ⋅ ⋅
⋅ ⋅ 1.0 ⋅ ⋅
⋅ ⋅ ⋅ 1.0 ⋅
⋅ ⋅ ⋅ ⋅ 1.0
I can get this to work this way though:
view(B, band(0))[2:end-1] .= -1.0 1.0 ⋅ ⋅ ⋅ ⋅
⋅ -1.0 ⋅ ⋅ ⋅
⋅ ⋅ -1.0 ⋅ ⋅
⋅ ⋅ ⋅ -1.0 ⋅
⋅ ⋅ ⋅ ⋅ 1.0
which seems a bit verbose to me. Is there some shortcut I'm missing? Actually, I think being able to do the following would be very nice:
B[band(0), 2:end-1] .= -1.0Metadata
Metadata
Assignees
Labels
No labels