Suppose I have two bitboards represented using a numpy array:
import numpy
bitboard = numpy.zeros(2, dtype=numpy.int64)
Let's say that I want to set the 10th bit of the first bitboard. What's the fastest way to do this?
There are two ways that I can think of. Here's the first way:
numpy.bitwise_or(a[0], numpy.left_shift(1, 10), out=a, where=(True, False))
Here's the second way:
a[0] |= 1 << 10
Which one is faster? Is there any other way to do this? In particular, I'd like to know:
- When I access
a[0]
does numpy return anint64
or a Pythonlong
? - If it returns a Python
long
then I'm assuming that both methods are pretty slow because they work on arbitrary-precision numbers. Am I right in assuming that? - If so then is there any way to get bitwise operations to work on fixed-precision numbers?
Note that I'm using Python version 3.