If b = rand(Bool, 3)
then all of
- .!b
- .~b
- xor.(true, b)
return a BitArray{1} type. Given that the input types are always Array{Bool, 1}, I find that curious. Is this behavior wanted, and if so, why?
If b = rand(Bool, 3)
then all of
return a BitArray{1} type. Given that the input types are always Array{Bool, 1}, I find that curious. Is this behavior wanted, and if so, why?
Smaller memory size and faster vectorized bit-wise operations?
See also: Arrays · The Julia Language
That makes sense. Wouldn’t it then be more consistent to have rand(Bool, 3) return a BitArray too? I just find it surprising that these functions do not preserve the type.
No, it would be inconsistent, as rand(T, n)
gives Vector{T}
s. See bitrand
.