Skip to content

Commit e5821b3

Browse files
authored
LinearAlgebra: replace internal broadcast indexing method by getindex (#54071)
Within the `@inbounds` annotation, these two should be equivalent, so we may call the public method instead of the internal one. Performance remains unchanged by this.
1 parent 7ee15d1 commit e5821b3

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

stdlib/LinearAlgebra/src/structuredbroadcast.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function copyto!(dest::Diagonal, bc::Broadcasted{<:StructuredMatrixStyle})
178178
axs = axes(dest)
179179
axes(bc) == axs || Broadcast.throwdm(axes(bc), axs)
180180
for i in axs[1]
181-
dest.diag[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i, i))
181+
dest.diag[i] = @inbounds bc[CartesianIndex(i, i)]
182182
end
183183
return dest
184184
end
@@ -188,15 +188,15 @@ function copyto!(dest::Bidiagonal, bc::Broadcasted{<:StructuredMatrixStyle})
188188
axs = axes(dest)
189189
axes(bc) == axs || Broadcast.throwdm(axes(bc), axs)
190190
for i in axs[1]
191-
dest.dv[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i, i))
191+
dest.dv[i] = @inbounds bc[CartesianIndex(i, i)]
192192
end
193193
if dest.uplo == 'U'
194194
for i = 1:size(dest, 1)-1
195-
dest.ev[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i, i+1))
195+
dest.ev[i] = @inbounds bc[CartesianIndex(i, i+1)]
196196
end
197197
else
198198
for i = 1:size(dest, 1)-1
199-
dest.ev[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i+1, i))
199+
dest.ev[i] = @inbounds bc[CartesianIndex(i+1, i)]
200200
end
201201
end
202202
return dest
@@ -207,11 +207,11 @@ function copyto!(dest::SymTridiagonal, bc::Broadcasted{<:StructuredMatrixStyle})
207207
axs = axes(dest)
208208
axes(bc) == axs || Broadcast.throwdm(axes(bc), axs)
209209
for i in axs[1]
210-
dest.dv[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i, i))
210+
dest.dv[i] = @inbounds bc[CartesianIndex(i, i)]
211211
end
212212
for i = 1:size(dest, 1)-1
213-
v = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i, i+1))
214-
v == (@inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i+1, i))) || throw(ArgumentError(lazy"broadcasted assignment breaks symmetry between locations ($i, $(i+1)) and ($(i+1), $i)"))
213+
v = @inbounds bc[CartesianIndex(i, i+1)]
214+
v == (@inbounds bc[CartesianIndex(i+1, i)]) || throw(ArgumentError(lazy"broadcasted assignment breaks symmetry between locations ($i, $(i+1)) and ($(i+1), $i)"))
215215
dest.ev[i] = v
216216
end
217217
return dest
@@ -222,11 +222,11 @@ function copyto!(dest::Tridiagonal, bc::Broadcasted{<:StructuredMatrixStyle})
222222
axs = axes(dest)
223223
axes(bc) == axs || Broadcast.throwdm(axes(bc), axs)
224224
for i in axs[1]
225-
dest.d[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i, i))
225+
dest.d[i] = @inbounds bc[CartesianIndex(i, i)]
226226
end
227227
for i = 1:size(dest, 1)-1
228-
dest.du[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i, i+1))
229-
dest.dl[i] = @inbounds Broadcast._broadcast_getindex(bc, CartesianIndex(i+1, i))
228+
dest.du[i] = @inbounds bc[CartesianIndex(i, i+1)]
229+
dest.dl[i] = @inbounds bc[CartesianIndex(i+1, i)]
230230
end
231231
return dest
232232
end
@@ -237,7 +237,7 @@ function copyto!(dest::LowerTriangular, bc::Broadcasted{<:StructuredMatrixStyle}
237237
axes(bc) == axs || Broadcast.throwdm(axes(bc), axs)
238238
for j in axs[2]
239239
for i in j:axs[1][end]
240-
@inbounds dest.data[i,j] = Broadcast._broadcast_getindex(bc, CartesianIndex(i, j))
240+
@inbounds dest.data[i,j] = bc[CartesianIndex(i, j)]
241241
end
242242
end
243243
return dest
@@ -249,7 +249,7 @@ function copyto!(dest::UpperTriangular, bc::Broadcasted{<:StructuredMatrixStyle}
249249
axes(bc) == axs || Broadcast.throwdm(axes(bc), axs)
250250
for j in axs[2]
251251
for i in 1:j
252-
@inbounds dest.data[i,j] = Broadcast._broadcast_getindex(bc, CartesianIndex(i, j))
252+
@inbounds dest.data[i,j] = bc[CartesianIndex(i, j)]
253253
end
254254
end
255255
return dest

0 commit comments

Comments
 (0)