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

specialization on function argument not occuring as expected #19137

Closed
Sacha0 opened this issue Oct 27, 2016 · 7 comments
Closed

specialization on function argument not occuring as expected #19137

Sacha0 opened this issue Oct 27, 2016 · 7 comments
Labels
docs This change adds or pertains to documentation

Comments

@Sacha0
Copy link
Member

Sacha0 commented Oct 27, 2016

julia> VERSION
v"0.6.0-dev.1079"

julia> notricks(f, x) = broadcast(f, x)
notricks (generic function with 1 method)

julia> forcespec{TF}(f::TF, x) = broadcast(f, x)
forcespec (generic function with 1 method)

julia> x = rand(10^2);

julia> using BenchmarkTools

julia> @benchmark notricks($abs, $x)
BenchmarkTools.Trial:
  samples:          10000
  evals/sample:     1
  time tolerance:   5.00%
  memory tolerance: 1.00%
  memory estimate:  1.91 kb
  allocs estimate:  28
  minimum time:     19.00 μs (0.00% GC)
  median time:      20.26 μs (0.00% GC)
  mean time:        22.96 μs (0.00% GC)
  maximum time:     295.82 μs (0.00% GC)

julia> @benchmark forcespec($abs, $x)
BenchmarkTools.Trial:
  samples:          10000
  evals/sample:     849
  time tolerance:   5.00%
  memory tolerance: 1.00%
  memory estimate:  912.00 bytes
  allocs estimate:  2
  minimum time:     146.00 ns (0.00% GC)
  median time:      157.00 ns (0.00% GC)
  mean time:        201.21 ns (14.08% GC)
  maximum time:     1.63 μs (82.76% GC)

See #18975 (comment) for the original discussion and ref. #19065. Best!

@vtjnash
Copy link
Member

vtjnash commented Oct 27, 2016

This is working as intended and as required to ensure compile times are reasonable

@Sacha0
Copy link
Member Author

Sacha0 commented Oct 28, 2016

Cheers, closing then. Thanks!

@Sacha0 Sacha0 closed this as completed Oct 28, 2016
@stevengj stevengj added the docs This change adds or pertains to documentation label Oct 29, 2016
@stevengj
Copy link
Member

stevengj commented Oct 29, 2016

Re-opening this as a doc issue. It doesn't seem documented that higher-order function specialization works this way, and it seems pretty crucial to explain.

For any other abstract argument type, like Integer, a specialized version gets compiled when a concretely typed argument is passed, so I find it surprising that Function is handled differently.

@stevengj stevengj reopened this Oct 29, 2016
@mauro3
Copy link
Contributor

mauro3 commented Oct 30, 2016

Also, doesn't #8974 mean that f{TF}(f::TF, x)=... and f(f, x)=... their signature type will become identical? See e.g. #19159 (comment). Then both definitions would need to have identical results.

@vtjnash
Copy link
Member

vtjnash commented Oct 31, 2016

no. #8974 only says that you'll get a warning when you define two methods whose signatures cover exactly the same set of types. it doesn't require that every method do the same thing.

@mauro3
Copy link
Contributor

mauro3 commented Oct 31, 2016

Still, it would make this even more confusing. If this is needed, maybe being more explicit would be better?

@KristofferC
Copy link
Member

This is now documented in the performance tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

No branches or pull requests

5 participants