I've been wondering about this for a while now, so I'm going to ask. This is a question about the design of Mathematica, which perhaps cannot be directly answered by anyone but the designers, however similar queries have been fruitful in the past.
Simply: why aren't arrays of True
and False
values packed? Compile
handles True | False
so it seems Mathematica has some understanding of optimizing for this type, yet:
boolean = Developer`ToPackedArray @ RandomChoice[{True, False}, 1*^6];
Developer`PackedArrayQ @ boolean
False
This is rather frustrating because packing would be particularly effective on binary data:
bigint = FromDigits[Boole@boolean, 2];
ByteCount[boolean]
ByteCount[bigint]
8000032
125040
Yes, one can sometimes fall back to this storage format and use Bit*
operations, but that is inconvenient and it doesn't always help; data must be converted for functions that expect True
or False
and the opportunity for internal optimizations may be lost.
Is there some reason I fail to comprehend that makes implementing packing of Boolean arrays a bad idea?