InplaceOps.jl is a Julia package that provides macros that enable a simple syntax for performing in-place (i.e. overwriting) array operations using standard arithmetic operators.
InplaceOps.jl provides a macro @! which rewrites expressions of the form:
C = A*Btomul!(C,A,B)C = C*BorC *= Btormul!(C,B)C = A*Ctolmul!(A,B)C = A/Btordiv!(C,A,B)C = C/BorC /= Btordiv!(C,B)C = A\Btoldiv!(C,A,B)C = A\Ctoldiv!(A,B)
Functionality for broadcasting is no longer supported. Use the Base @. macro instead.
julia> using LinearAlgebra, InplaceOps
julia> T = UpperTriangular(ones(5,5))
5×5 UpperTriangular{Float64,Array{Float64,2}}:
1.0 1.0 1.0 1.0 1.0
⋅ 1.0 1.0 1.0 1.0
⋅ ⋅ 1.0 1.0 1.0
⋅ ⋅ ⋅ 1.0 1.0
⋅ ⋅ ⋅ ⋅ 1.0
julia> x_orig = x = [1.0,2.0,3.0,4.0,5.0]
5-element Array{Float64,1}:
1.0
2.0
3.0
4.0
5.0
julia> @! x = T \ x
5-element Array{Float64,1}:
-1.0
-1.0
-1.0
-1.0
5.0
julia> x === x_orig
true