ooguntola / numexpr

Automatically exported from code.google.com/p/numexpr
MIT License
0 stars 0 forks source link

Algebra for boolean values doesn't work on arrays (interpret as 0 / 1 integer) #96

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. a = arange(10)
2. numexpr.evaluate('(a == a) + (a == a)')

What is the expected output? What do you see instead?
boolean array of length 10 with values 2. Python also
treats boolean values as integers for addition / multiplication

What version of the product are you using? On what operating system?
numexpr 1.4.2 on Ubuntu 12.04 64bit

Please provide any additional information below.
Workaround would be numexpr.evaluate('1 * (a == a) + (a == a)') which
causes a cast to integer.
In this specific case i used boolean algebra as a workaround to implement
sign(): sign(a) := (a > 0) - (a < 0)

Original issue reported on code.google.com by wayne.st...@googlemail.com on 7 Jan 2013 at 11:27