Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of @code_warntype in Julia

Tags:

types

julia

When trying to write type-stable code, examining using @code_warntype, should I only worry about not having any Any or Union in the variables section or I should also check the body section?

like image 207
amrods Avatar asked Nov 26 '15 04:11

amrods


1 Answers

Depending on your version of julia, @code_warntype can sometimes flag certain expressions that are harmless. With a little bit of practice you can easily recognize these expressions (e.g., they often have to do with module/name lookup).

The easy path, as Reza says, is to look at the variables section and the function's return-type; if you don't see any type-uncertain quantities (either Any or Unions) you probably have nothing to worry about. If you want to dig deeper, start trying to make sense of the body expressions that it's flagging. For learning, one useful thing to do is compare the results against those obtained with track-allocation, since true type instability is associated with memory allocation.

However, I think the issues with @code_warntype have been fixed on current master, so in any case the next release of julia should make it easier to interpret.

like image 85
tholy Avatar answered Sep 30 '22 16:09

tholy