-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
promote_op/broadcast should not call the function for one(T) #17314
Comments
Maybe the guideline should be not to broadcast functions with side effects. As mentioned in #17300, using a version of I'm not really concerned about the cost of a single extra call to a function you already want to broadcast. To be significant, it would require that the function is very expensive and it's broadcast over a very short range. I'm not sure that case should be given too much weight in this decision. |
@andreasnoack, it totally does not fix the issue to change Nor do I think it is sensible to forbid side-effects, or assume that function calls are cheap — it is quite common to have functions In my mind, it is unacceptable for a programming language to call my function for arguments that I don't supply myself. Can't we just get rid of the fallback entirely, and use the |
IIUC Jeff's concern is that the |
I also wonder whether whether inference couldn't allow for a fast-path when the called function is type-stable for the passed input types. |
Inference already works fine here. If we can infer the result type of the function the code is specialized down to a compact loop. Anyway I think I should just merge #16622, which provides |
So in theory there should be no problem with removing that method? |
Can this be fixed now that #16622 was merged? |
This also causes a problem in SIUnits.jl: Keno/SIUnits.jl#84. In the issue above the error is because unit-less numbers can't be Also if you try So this is a case where |
As @yuyichao pointed out on julia-users, this also causes a Marking the issue as a regression since these problems weren't present in 0.4. |
Seems that the commit that closed this issue has been reverted (dbdaf72). Should the issue be re-opened? |
it was reverted on release-0.5. if it can be fixed in a way that doesn't hurt performance and doesn't break packages, we can consider re-applying along with backporting the fix |
As was commented at #17300 (comment) and #17172 (comment), the
promote_op
function has a fallback method that callstypeof(op(one(T)))
. This is not really acceptable.For one thing,
op(1)
may not even be valid—it may throw aDomainError
e.g. ifop(x)=log(log(log(x)))
. Even if1
is a valid argument, it is unexpected and undesirable thatop
should be called without the user requesting it. (e.g. imagine ifop
has side effects, or is simply an extremely expensive function.)The text was updated successfully, but these errors were encountered: