JuliaTeachingCTU / Scientific-Programming-in-Julia

Repository for B0M36SPJ
https://juliateachingctu.github.io/Scientific-Programming-in-Julia/dev/
MIT License
78 stars 15 forks source link

Homework 05 warntype improvements #41

Open janfrancu opened 2 years ago

janfrancu commented 2 years ago

Checking type stability on function with optional arguments does not show the whole picture

@code_warntype find_root(p, Newton(), -5.0, 5.0) # shows only the wrapper function which is stable
@code_warntype find_root(p, Newton(), -5.0, 5.0, 100, 0.95, 1e-12)  # fully specified (shows type instabilities - also used in the eval)

The problem here is that the function is type stable in the way that the compiler knows the output type before execution, however the eval pipeline checks for all ::Any entries in the fully specified function, i.e. for runtime dispatches of which there are few. This leads to confusion based on what has been said in the lab.