Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Traits with functions not defined in the namespace where @derive is called #9

Open
mtfishman opened this issue Dec 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mtfishman
Copy link
Member

The following kind of pattern doesn't work right now:

module MyArrays
struct MyArray{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N}
  parent::A
end

using Derive: Derive
using LinearAlgebra: LinearAlgebra
function Derive.derive(::Val{:Mul}, type)
  return quote
    LinearAlgebra.mul!(::Any, ::$type, ::$type, ::Number, ::Number)
  end
end
end

@derive MyArrays.MyArray MyArrays.Mul

We should be able to make it work with judicious use of GlobalRef in @derive, see for example https://github.com/ITensor/Derive.jl/blob/f97d55a21109e0390bb542237da532aec9d3ce0c/src/interface_macro.jl#L36.

This will allow us to include these functions in the AbstractArrayOps trait: https://github.com/ITensor/Derive.jl/blob/f97d55a21109e0390bb542237da532aec9d3ce0c/src/traits.jl#L18-L19.

@mtfishman mtfishman added the bug Something isn't working label Dec 6, 2024
@mtfishman mtfishman transferred this issue from ITensor/Derive.jl Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant