Le mardi 27 septembre 2016 à 17:13 -0400, Stefan Karpinski a écrit :
> I believe the actual term for this kind of optimization is "loop
> peeling", which makes much more sense. I'm probably still gonna call
> it henchmen unrolling though. An issue with henchmen unrolling is
> that while it may improve type inference for the loop body, it often
> doesn't improve the inferred type for the entire function. The
> classic example is the type-unstable summation loop:
>
> function sumit(v::Vector{Float64})
> s = 0
> for x in v
> s += x
> end
> return s
> end
>
> Henchmen unrolling this makes the loop body type-stable – s is
> Float64 – but the function can still return an Int in the case where
> v is empty, so the function remains type unstable. I guess that a
> return type annotation plus henchmen unrolling does fix the problem,
> but it seems better to use static analysis to uncover this to the
> programmer so they know to write s = 0.0 instead.
It would be so nice to be able to tell the compiler to choose a 0 of
whatever type it needs to make the function type stable... These zero()
initialization steps can be so tedious to write fully correctly when
the computation inside the loop is complex. This is true in particular
when it involves a multiplication and an addition, for which custom
types might have arbitrary promotion rules. A poster child for this is
computing the deviance of a linear model:
https://github.com/JuliaStats/GLM.jl/blob/4d9399b559345b3926c74631019d645073b53bb0/src/lm.jl#L31
Any chance we could find a solution to this? Julia is generally smart
enough to infer the best type everywhere it's logically possible, and
this is one of the very few places were it doesn't.
Regards
> On Tue, Sep 27, 2016 at 3:32 PM, Jeff Bezanson
> <
jeff.b...@gmail.com> wrote:
> > Just a footnote that the term "henchmen unrolling" makes no sense,
> > and
> > I believe originates from an iphone autocorrect in an email by
> > Stefan.
> > We found it funny so we just kept it. Hopefully this term will
> > eventually appear in a textbook somewhere :)
> >
> >
> > On Mon, Sep 26, 2016 at 8:15 AM, Yichao Yu <
yyc...@gmail.com>
> > wrote:
> > > On Mon, Sep 26, 2016 at 3:23 AM, Tsur Herman <tsur.herman@gmail.c