mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-06 19:22:27 +02:00
reworked pattern generator
This commit is contained in:
+17
-22
@@ -1,31 +1,26 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
def _bitmask(bit, word):
|
||||
dtype = word.dtype if hasattr(word, 'dtype') else np.uint64
|
||||
if bit >= np.iinfo(dtype).bits:
|
||||
raise ValueError(f"bit {bit} out of range for {np.dtype(dtype).name}")
|
||||
return np.dtype(dtype).type(1 << bit)
|
||||
|
||||
def setbit(bit, word):
|
||||
if isinstance(word, np.generic):
|
||||
mask = word.dtype.type(1)
|
||||
mask = mask << bit
|
||||
else:
|
||||
mask = 1 << bit
|
||||
return word | mask
|
||||
|
||||
|
||||
def setbit_arr(bit, arr):
|
||||
arr |= arr.dtype.type(1 << bit)
|
||||
|
||||
"""
|
||||
Set the bit at position bit in word(s).
|
||||
"""
|
||||
return word | _bitmask(bit, word)
|
||||
|
||||
def clearbit(bit, word):
|
||||
"""
|
||||
Clear the bit at position bit in word.
|
||||
Two paths to avoid converting the types.
|
||||
Clear the bit at position bit in word(s).
|
||||
"""
|
||||
if isinstance(word, np.generic):
|
||||
mask = word.dtype.type(1)
|
||||
mask = ~(mask << bit)
|
||||
else:
|
||||
mask = ~(1 << bit)
|
||||
return word & mask
|
||||
return word & ~_bitmask(bit, word)
|
||||
|
||||
|
||||
def clearbit_arr(bit, arr):
|
||||
arr &= arr.dtype.type(~(1 << bit))
|
||||
def flipbit(bit, word):
|
||||
"""
|
||||
Flip the bit at position bit in word(s).
|
||||
"""
|
||||
return word ^ _bitmask(bit, word)
|
||||
Reference in New Issue
Block a user