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*B
tomul!(C,A,B)
C = C*B
orC *= B
tormul!(C,B)
C = A*C
tolmul!(A,B)
C = A/B
tordiv!(C,A,B)
C = C/B
orC /= B
tordiv!(C,B)
C = A\B
toldiv!(C,A,B)
C = A\C
toldiv!(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