diff --git a/src/MaybeInplace.jl b/src/MaybeInplace.jl index 12ad64f..558f750 100644 --- a/src/MaybeInplace.jl +++ b/src/MaybeInplace.jl @@ -12,20 +12,21 @@ __bangbang__docs = """ The `@bangbang` macro rewrites expressions to use out-of-place operations if needed. The following operations are supported: - 1. `copyto!(y, x)` - 2. `x .(+/-/*)= ` - 3. `x ./= ` - 4. `copy(x)` - 5. `x .= ` - 6. `@. ` + 1. `copyto!(y, x)` + 2. `x .(+/-/*)= ` + 3. `x ./= ` + 4. `copy(x)` + 5. `x .= ` + 6. `@. ` + 7. `x = copy(y)` This macro also allows some custom operators: - 1. `×` (typed with `\\times`): This is effectively a matmul operator. It is - rewritten to use `mul!` if `y` can be setindex-ed else it is rewritten to use - `restructure` to create a new array. If there is a `vec` on the rhs, `vec` is also - applied to the lhs. This is useful for handling arbitrary dimensional arrays by - flattening them. + 1. `×` (typed with `\\times`): This is effectively a matmul operator. It is + rewritten to use `mul!` if `y` can be setindex-ed else it is rewritten to use + `restructure` to create a new array. If there is a `vec` on the rhs, `vec` is also + applied to the lhs. This is useful for handling arbitrary dimensional arrays by + flattening them. !!! warning @@ -78,7 +79,7 @@ all operations on the list. ## Main Function function __bangbang__(M, expr; depth::Int = 1) new_expr = nothing - if @capture(expr, a_Symbol = copy(b_)) + if @capture(expr, a_Symbol=copy(b_)) new_expr = :($(a) = $(__copy)($(setindex_trait)($(b)), $(b))) elseif @capture(expr, f_(a_Symbol, args__)) g = get(OP_MAPPING, f, nothing)