Optimize execution by removing checks on "given" method

Issue #77 resolved
Pierre Denis repo owner created an issue

Lea is stricter than Python when testing boolean expression in given method:

c = lea.vals(0,1,2)
print(c.given(c!=0))
# -> 1 : 0.5
#    2 : 0.5
print(c.given(c))
# -> lea.Error: boolean expression expected

However, coercion from 0 and 1 works fine:

b = lea.vals(0,1)
print(b.given(b))
# -> 1: 1.0

It would be less surprising to let Python coerce the values itself, without making explicit check ("Easier to ask forgiveness than permission!").

Also, and most importantly, the current checks if cv0 == True: ... elif cv0 == False: ... else: ... (see Ilea class) appear to be very time-consuming:

x = interval(1,100)
for _ in range(100_000):
    x.given(x<=50).calc()

takes ~50s on my computer. After simplification of Ilea class (if cv0: ... else: ...), the same test takes ~15s only! Massive gains could be obtained on several problems...

Comments (5)

  1. Log in to comment