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

using ChainRulesCore changes type promotion logic #649

Open
liushang0322 opened this issue Jan 3, 2024 · 1 comment
Open

using ChainRulesCore changes type promotion logic #649

liushang0322 opened this issue Jan 3, 2024 · 1 comment
Labels
upsteam A problem that need to be resolved upstream in one of our dependencies or in julia itself

Comments

@liushang0322
Copy link

I'm using Julia 1.9 and ChainRulesCore v1.19.0

When I use the following code, the results change

a = ones(Complex,100,100)
a'

ela = eltype(a') # Complex

using ChainRulesCore
a = ones(Complex,100,100)
a'

ela1 = eltype(a') # Any

ela is Complex but ela1 is Any

Please tell me how to avoid this problem (constructing the Complex type is inevitable),Please tell me how to avoid this problem (constructing the Complex type is inevitable), or is this a bug?

@oxinabox
Copy link
Member

oxinabox commented Jan 4, 2024

Work around, is don't use Complex use ComplexF64, which will also make your code all round faster.
Since Complex is an nonconcrete type. See https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-abstract-container
If you do
ones(ComplexF64, 100, 100) then everything works fine.

I don't know exactly what is happening have no idea what is happening here.
ChainRulesCore doesn't monkey patch ' or really touch anything in the promotion machiner at all. (It doesn't monkey patch anything). so I don't think this is something we have done.

I think this is because the eltype of adjoint is determines using
Base.promote_op(adjoint, typeof(a)) which is documented as extremely fragile.

I will open an issue in julia itself

@oxinabox oxinabox added the upsteam A problem that need to be resolved upstream in one of our dependencies or in julia itself label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upsteam A problem that need to be resolved upstream in one of our dependencies or in julia itself
Projects
None yet
Development

No branches or pull requests

2 participants