Skip to content

Unnecessary C = in in-place expression is incompatible with immutable struct field #16

Open
@guiburon

Description

Hi,

The macro @! always returns an expression with a leading :($(esc(C)) =.
Using the README multiplication example, what are the use-cases for returning C = mul!(C,A,B) instead of only mul!(C,A,B)?

It renders the macro incompatible with a struct field result.

struct myStruct
    C
end

S = myStruct(rand(10))
A = rand(10,10)
B = rand(10)

@! S.C = A * B   # the macro would return S.C = mul!(S.C, A, B) but throws an error

As is, the macro throws an error because :(S.C) is not a Symbol. Without this test, it later throws the error immutable struct of type myStruct cannot be changed because of the leading S.C = that would mutate the field. However, mul!(S.C, A, B) works fine because it modifies S.C in-place.

It is common to use functors for in-place operations in linear algebra (see ArnoldiMethod.jl example) but @! is incompatible as is.

I forked this repo and implemented a @! compatible with in-place operations on struct fields. I relaxed the test on :C to Union{Symbol, Expr} and removed the leading :($(esc(C)) = that the macro returns.

I am curious to hear your opinion. Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions