def hashfloat128(x,N):
'''
Convert a bit vector to a float128
Not to be confused with `pylab.packbits`
Parameters
----------
x : boolean or binary vector
N : positive integer, number of bits in each vector
Returns
-------
float128 : integer, stored in float128, whose binary bits match x
'''
x = (np.array(x)!=0)
if not x.shape[-1]==N:
raise ValueError('The last dimension of x should match the bit vector length N')
if N>63:
raise ValueError('No more than 63 bits are safe at the moment')
return x.dot(2**np.float128(np.arange(N)))
评论列表
文章目录