Some examples from broadcasting:
-
In
f.(u) .+ g.(v')
(with u,v both length N vectors) you could perhaps do N evaluations off
, notN^2
. But for something likef(x) = x + rand()
this would change the answer, perhaps that’s impure for this purpose. -
In the gradient calculation for
f.(u)
, knowing thatf
does not close over other parameters would I think simplify how we handle it. Heref(x) = y[1] + x
would be pure under Mason’s macro’s definition, but this needs something stronger.
Edit – it seems that Base.issingletontype(typeof(f))
is a reasonable test for the 2nd case. The 1st seems to want a weaker definition than @pure
’s, it’s not the method table that’s the concern. Whether this could be inferred, I don’t know. It could also be provided either when defining or when calling the function, like @purecast f.(u) .+ g.(v')
.