-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Memory allocation inconsistency in broadcasting #41565
Comments
Something a bit more minimal: function test(y)
y .= 0 .- y ./ (y.^2) # extra allocation
return y
end
function test(y, n)
y .= 0 .- y ./ (y.^n)
return y
end
const y = rand(1000);
@time test(y);
# 0.000002 seconds (2 allocations: 16 bytes)
@time test(y, 2);
# 0.000001 seconds So the literal pow (leading to a |
I tried your code in version 1.5.3 and I get
No allocations :) |
After some tests, I found that it's caused by an uninlined function Lines 987 to 989 in 7d0f769
Redefining the function to be inlined can fix the bug:
Running the code:
The fix is extremely easy, just add |
These should be equivalent, but in julia-1.6 x.^2 allocates because of a bug (JuliaLang/julia#41565).
I found the following inconsistency related to the use of the broadcasting dot macro.
When running, for example,
I get
This behavior occurs in versions 1.6.1 and 1.7.0-beta3 only. In version 1.5.3 I get no allocations in both calculations.
The text was updated successfully, but these errors were encountered: