@static but do not parse the invalid branch

We would like to make use of an 0.5 feature which fails to parse on 0.4

@static if Base.VERSION.major == 0 && Base.VERSION.minor < 5 
         sN = sparsevec(sum(N[1:ncategories[i],:], 1)) # Slower, but should be supported by Julia 0.4
         sN = sum(N[i,:] for i=1:ncategories[i])

The problem with the above implementation is that Julia 0.4 still parses both branches, and thus fails. Is there a way to insert something like this such that you get the desired code in each Julia version?

Thank you!


If this is a part that’s really performance critical (I doubt), you can put it in another function that’s conditionally included and put the 0.4 and 0.5 defs in two different files.

1 Like