Unless I’m missing something or misunderstanding, I don’t think this works. For example:
A = rand(8,8)
a22 = view(A, 4:8,4:8)
mul!(a22, 10*randn(5,5), a22)
errors. This is expected, as the docstring for mul!
says
mul!(Y, A, B) -> Y
Calculates the matrix-matrix or matrix-vector product AB and stores the result in Y, overwriting the existing value of Y. Note that Y must not be aliased with either A or B.
To do in-place, overwriting matrix multiplication you need to use rmul!
or lmul!
. Unfortunately those functions don’t seems to work with sub-arrays:
julia> rmul!(a22,4*randn(5,5))
ERROR: MethodError: no method matching rmul!(::SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}, ::Array{Float64,2})
Closest candidates are:
rmul!(::AbstractArray, ::Number) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/generic.jl:161
rmul!(::StridedArray{T, 2}, ::LowerTriangular{T,var"#s817"} where var"#s817"<:(StridedArray{T, 2} where T)) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/triangular.jl:749
rmul!(::StridedArray{T, 2}, ::Transpose{var"#s807",var"#s806"} where var"#s806"<:(LowerTriangular{T,var"#s805"} where var"#s805"<:(StridedArray{T, 2} where T)) where var"#s807") where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/triangular.jl:759
Is there a reason why this shouldn’t work for subarrays?