Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-03 Thread Simon Byrne
If the zeros are known at compile time, LLVM may optimise away some unnecessary operations: julia> foo(x) = x + 0*(x*x + 2) foo (generic function with 1 method) julia> @code_llvm foo(1) define i64 @julia_foo_21664(i64) { top: ret i64 %0 } Unfortunately, this doesn't work as is with flo

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Jan Drugowitsch
My aim is to write a Hamiltonian MCMC sampler that samples bound and drift parameter posteriors for bounded diffusion models while assuming some parametric form for how these bounds and the drift change over time. This requires the first and second derivative of the first-passage densities that

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Stefan Karpinski
Can you elaborate on why that kind of code needs this unusual evaluation? It looks pretty reasonable as is to me. On Thu, Jul 2, 2015 at 5:20 PM, Jan Drugowitsch wrote: > Is this a toy reduction of a concept that you want to apply in a much more >> complex way? >> > > Yes, it was just meant to i

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Jutho
Depending on how much more complicated your actual use case is, could you not just write f(a,b,c) = a*b + a*c instead of a*(b+c)? I guess the former would be evaluated immediately at compile time if a is _zero ?

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Jan Drugowitsch
On Thursday, 2 July 2015 17:13:50 UTC+2, Yichao Yu wrote: > > On Thu, Jul 2, 2015 at 11:09 AM, Jan Drugowitsch > wrote: > > On Thursday, 2 July 2015 16:55:33 UTC+2, Yichao Yu wrote: > >> > >> On Thu, Jul 2, 2015 at 10:48 AM, Tom Breloff wrote: > >> > Just curious... is there a reason simply c

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Jan Drugowitsch
> > Is this a toy reduction of a concept that you want to apply in a much more > complex way? > Yes, it was just meant to illustrate the concept. It should be applied to a function that has roughly the complexity of https://github.com/jdrugo/DiffModels.jl/blob/master/src/fpt.jl#L153 (in fact,

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Yichao Yu
On Thu, Jul 2, 2015 at 11:09 AM, Jan Drugowitsch wrote: > On Thursday, 2 July 2015 16:55:33 UTC+2, Yichao Yu wrote: >> >> On Thu, Jul 2, 2015 at 10:48 AM, Tom Breloff wrote: >> > Just curious... is there a reason simply checking for non-zero isn't >> > enough? >> > Readability? Performance? >> >

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Stefan Karpinski
Is this a toy reduction of a concept that you want to apply in a much more complex way? On Thu, Jul 2, 2015 at 11:09 AM, Jan Drugowitsch wrote: > On Thursday, 2 July 2015 16:55:33 UTC+2, Yichao Yu wrote: >> >> On Thu, Jul 2, 2015 at 10:48 AM, Tom Breloff wrote: >> > Just curious... is there a r

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Jan Drugowitsch
On Thursday, 2 July 2015 16:55:33 UTC+2, Yichao Yu wrote: > > On Thu, Jul 2, 2015 at 10:48 AM, Tom Breloff > wrote: > > Just curious... is there a reason simply checking for non-zero isn't > enough? > > Readability? Performance? > > > > f(a,b,c) = (Bool(a) ? a * (b + c) : 0.0) > > I'm guessi

Re: [julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Yichao Yu
On Thu, Jul 2, 2015 at 10:48 AM, Tom Breloff wrote: > Just curious... is there a reason simply checking for non-zero isn't enough? > Readability? Performance? > > f(a,b,c) = (Bool(a) ? a * (b + c) : 0.0) I'm guessing he want all code that gets his type automatically gets this behavior? If yes, I

[julia-users] Re: Short-circuit evaluation for multiplication

2015-07-02 Thread Tom Breloff
Just curious... is there a reason simply checking for non-zero isn't enough? Readability? Performance? f(a,b,c) = (Bool(a) ? a * (b + c) : 0.0) On Thursday, July 2, 2015 at 9:47:59 AM UTC-4, Jan Drugowitsch wrote: > > Dear Julia users, > > I am implementing an algorithm to solve a specific ty