[Python-Dev] bools aren't ints in Fortran
Tim Peters
tim.one@comcast.net
Sun, 10 Mar 2002 15:43:33 -0500
[Paul F Dubois]
> ...
> BTW, the Fortran standard does not specify a representation for logical,
It does have to consume "one numeric storage unit", though (at least in
F77 -- maybe F90 dropped that?), making it close to impossible to arrange
for logical array storage as bit vectors.
> and there was even a period where mixing libraries compiled with
> different compilers on the the Crays could get errors because the
> representations differed. One compiler had chosen to use a hardware
> feature that made it quick to test a sign bit.
The original CFT used .TRUE. same-as -1 for this reason. People playing
games with EQUIVALENCE statements kept whining about that, when they came
from a platform where .TRUE. same-as 1 was the norm. Last I paid attention,
SGI still refused to guarantee what the represenation of .TRUE. was, but did
guarantee that-- if you played EQUIVALENCE games mixing types --only a 0
value would be treated as .FALSE. when viewed again as a logical.
Later, interoperabilibty with C also suffered. Minor pressure came from
people coming from array languages (like APL and MATLAB), where true same-as
1 is the norm.
If Python did change to "true booleans", would you change numarray to return
them for arrays of comparison results? (array1 < array2, greater(array1,
array2), etc)? If so, do you predict existing numarray users wouldn't
notice?
> This points out another fallacy with making bool a subclass of int --
> it binds the implementation too much to one view.
"Peak speed" is a Fortran goal, not a Python goal. Refusing to commit to a
specific representation doesn't do anything for Python except open it to the
porting and interoperability headaches Fortran programmers enjoy. It could
very well be that checking the sign bit is a little cheaper on some boxes,
but Python doesn't (and shouldn't) care about that; Fortran should (and
does).
> True + True is neither True nor False. Hmmmmmm....
bool_1 + bool_2 + ... + bool_n
counts the number of true terms. If you have a matrix of boolean results,
doing a sum reduction across all dimensions yeilds the number of true
entries. Etc. Stuff like that is darned useful, IMO.