本文整理汇总了Python中numpy.uint64函数的典型用法代码示例。如果您正苦于以下问题:Python uint64函数的具体用法?Python uint64怎么用?Python uint64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uint64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_synapse
def check_synapse(self, id):
""" Get neuron pairs and coordinates
"""
# Get the resolution and the scale
res = 0
sc = 0.5**res
scales = np.array([sc, sc, 1])
# If synapse exists
if self.is_synapse(id):
# Get the neuron pairs
parents = self.synapse_parent(id)['parent_neurons']
# Reverse the dictionary
parents = {i[1]:i[0] for i in parents.items()}
# If bidirectionl synapse
if 3 in parents:
neurons = [parents[3], parents[3]]
# If two neuron parents
else:
neurons = [parents[1], parents[2]]
# Get the synapse coordinates
keypoint = self.synapse_keypoint(res, id)['keypoint']
full_keypoint = np.uint64(keypoint / scales).tolist()
# Return all neuron ids and cooridnates
return np.uint64(neurons + full_keypoint)
# Return nothing if non-existent
return np.uint64([])
示例2: uint64_from_uint63
def uint64_from_uint63(x):
out = np.empty(len(x) // 2, dtype=np.uint64)
for i in range(0, len(x), 2):
a = x[i] & np.uint64(0xffffffff00000000)
b = x[i + 1] >> np.uint64(32)
out[i // 2] = a | b
return out
示例3: calculateComplexDerefOpAddress
def calculateComplexDerefOpAddress(complexDerefOp, registerMap):
match = re.match("((?:\\-?0x[0-9a-f]+)?)\\(%([a-z0-9]+),%([a-z0-9]+),([0-9]+)\\)", complexDerefOp)
if match != None:
offset = 0L
if len(match.group(1)) > 0:
offset = long(match.group(1), 16)
regA = RegisterHelper.getRegisterValue(match.group(2), registerMap)
regB = RegisterHelper.getRegisterValue(match.group(3), registerMap)
mult = long(match.group(4), 16)
# If we're missing any of the two register values, return None
if regA == None or regB == None:
if regA == None:
return (None, "Missing value for register %s" % match.group(2))
else:
return (None, "Missing value for register %s" % match.group(3))
if RegisterHelper.getBitWidth(registerMap) == 32:
val = int32(uint32(regA)) + int32(uint32(offset)) + (int32(uint32(regB)) * int32(uint32(mult)))
else:
# Assume 64 bit width
val = int64(uint64(regA)) + int64(uint64(offset)) + (int64(uint64(regB)) * int64(uint64(mult)))
return (long(val), None)
return (None, "Unknown failure.")
示例4: _ints_arr_to_bits
def _ints_arr_to_bits(ints_arr, out):
"""
Convert an array of integers representing the set bits into the
corresponding integer.
Compiled as a ufunc by Numba's `@guvectorize`: if the input is a
2-dim array with shape[0]=K, the function returns a 1-dim array of
K converted integers.
Parameters
----------
ints_arr : ndarray(int32, ndim=1)
Array of distinct integers from 0, ..., 63.
Returns
-------
np.uint64
Integer with set bits represented by the input integers.
Examples
--------
>>> ints_arr = np.array([0, 1, 2], dtype=np.int32)
>>> _ints_arr_to_bits(ints_arr)
7
>>> ints_arr2d = np.array([[0, 1, 2], [3, 0, 1]], dtype=np.int32)
>>> _ints_arr_to_bits(ints_arr2d)
array([ 7, 11], dtype=uint64)
"""
m = ints_arr.shape[0]
out[0] = 0
for i in range(m):
out[0] |= np.uint64(1) << np.uint64(ints_arr[i])
示例5: get_bucket
def get_bucket(uhash, pieces, first_bucket_vector, second_bucket_vector):
h_index = np.uint64(first_bucket_vector[0]) + np.uint64(second_bucket_vector[0 + 2])
if h_index >= const.prime_default:
h_index -= const.prime_default
assert(h_index < const.prime_default)
h_index = np.uint32(h_index)
h_index = h_index % uhash.table_size
control = np.uint64(first_bucket_vector[1]) + np.uint64(second_bucket_vector[1 + 2])
if control >= const.prime_default:
control -= const.prime_default
assert(control < const.prime_default)
control = np.uint32(control)
if uhash.t == 2:
index_hybrid = uhash.hybrid_hash_table[h_index]
while index_hybrid:
if index_hybrid.control_value == control:
index_hybrid = C.pointer(index_hybrid)[1]
return index_hybrid
else:
index_hybrid = C.pointer(index_hybrid)[1]
if index_hybrid.point.is_last_bucket:
return None
l = index_hybrid.point.bucket_length
index_hybrid = C.pointer(index_hybrid)[l]
return None
示例6: __init__
def __init__(self, index, desc):
opt_lis = desc.split(',')
self.key = opt_lis[0]
self.index = index
self.control = False
self.event = False
self.width = None
self.mult = None
self.unit = None
# TODO Add gauge.
for opt in opt_lis[1:]:
if len(opt) == 0:
continue
elif opt[0] == 'C':
self.control = True
elif opt[0] == 'E':
self.event = True
elif opt[0:2] == 'W=':
self.width = int(opt[2:])
elif opt[0:2] == 'U=':
i = 2
while i < len(opt) and opt[i].isdigit():
i += 1
if i > 2:
self.mult = numpy.uint64((opt[2:i]))
if i < len(opt):
self.unit = opt[i:]
if self.unit == "KB":
self.mult = numpy.uint64(1024)
self.unit = "B"
else:
error("unrecognized option `%s' in schema entry spec `%s'\n", opt, desc)
示例7: testInt
def testInt(self):
num = np.int(2562010)
self.assertEqual(np.int(ujson.decode(ujson.encode(num))), num)
num = np.int8(127)
self.assertEqual(np.int8(ujson.decode(ujson.encode(num))), num)
num = np.int16(2562010)
self.assertEqual(np.int16(ujson.decode(ujson.encode(num))), num)
num = np.int32(2562010)
self.assertEqual(np.int32(ujson.decode(ujson.encode(num))), num)
num = np.int64(2562010)
self.assertEqual(np.int64(ujson.decode(ujson.encode(num))), num)
num = np.uint8(255)
self.assertEqual(np.uint8(ujson.decode(ujson.encode(num))), num)
num = np.uint16(2562010)
self.assertEqual(np.uint16(ujson.decode(ujson.encode(num))), num)
num = np.uint32(2562010)
self.assertEqual(np.uint32(ujson.decode(ujson.encode(num))), num)
num = np.uint64(2562010)
self.assertEqual(np.uint64(ujson.decode(ujson.encode(num))), num)
示例8: _combine_hash_arrays
def _combine_hash_arrays(arrays, num_items):
"""
Parameters
----------
arrays : generator
num_items : int
Should be the same as CPython's tupleobject.c
"""
try:
first = next(arrays)
except StopIteration:
return np.array([], dtype=np.uint64)
arrays = itertools.chain([first], arrays)
mult = np.uint64(1000003)
out = np.zeros_like(first) + np.uint64(0x345678)
for i, a in enumerate(arrays):
inverse_i = num_items - i
out ^= a
out *= mult
mult += np.uint64(82520 + inverse_i + inverse_i)
assert i + 1 == num_items, 'Fed in wrong num_items'
out += np.uint64(97531)
return out
示例9: __init__
def __init__(self, i, s):
opt_lis = s.split(',')
self.key = opt_lis[0]
self.index = i
self.is_control = False
self.is_event = False
self.width = None
self.mult = None
self.unit = None
for opt in opt_lis[1:]:
if len(opt) == 0:
continue
elif opt[0] == 'C':
self.is_control = True
elif opt[0] == 'E':
self.is_event = True
elif opt[0:2] == 'W=':
self.width = int(opt[2:])
elif opt[0:2] == 'U=':
j = 2
while j < len(opt) and opt[j].isdigit():
j += 1
if j > 2:
self.mult = numpy.uint64(opt[2:j])
if j < len(opt):
self.unit = opt[j:]
if self.unit == "KB":
self.mult = numpy.uint64(1024)
self.unit = "B"
else:
# XXX
raise ValueError("unrecognized option `%s' in schema entry spec `%s'\n", opt, s)
示例10: __compile_kernels
def __compile_kernels(self):
""" DFS module """
f = self.forest
self.find_min_kernel = f.find_min_kernel
self.fill_kernel = f.fill_kernel
self.scan_reshuffle_tex = f.scan_reshuffle_tex
self.comput_total_2d = f.comput_total_2d
self.reduce_2d = f.reduce_2d
self.scan_total_2d = f.scan_total_2d
self.scan_reduce = f.scan_reduce
""" BFS module """
self.scan_total_bfs = f.scan_total_bfs
self.comput_bfs_2d = f.comput_bfs_2d
self.fill_bfs = f.fill_bfs
self.reshuffle_bfs = f.reshuffle_bfs
self.reduce_bfs_2d = f.reduce_bfs_2d
self.get_thresholds = f.get_thresholds
""" Other """
self.predict_kernel = f.predict_kernel
self.mark_table = f.mark_table
const_sorted_indices = f.bfs_module.get_global("sorted_indices_1")[0]
const_sorted_indices_ = f.bfs_module.get_global("sorted_indices_2")[0]
cuda.memcpy_htod(const_sorted_indices, np.uint64(self.sorted_indices_gpu.ptr))
cuda.memcpy_htod(const_sorted_indices_, np.uint64(self.sorted_indices_gpu_.ptr))
示例11: __init__
def __init__(self, fpga, comb, f_start, f_stop, logger=logging.getLogger(__name__)):
""" f_start and f_stop must be in Hz
"""
self.logger = logger
snap_name = "snap_{a}x{b}".format(a=comb[0], b=comb[1])
self.snapshot0 = Snapshot(fpga,
"{name}_0".format(name = snap_name),
dtype='>i8',
cvalue=True,
logger=self.logger.getChild("{name}_0".format(name = snap_name)))
self.snapshot1 = Snapshot(fpga,
"{name}_1".format(name = snap_name),
dtype='>i8',
cvalue=True,
logger=self.logger.getChild("{name}_1".format(name = snap_name)))
self.f_start = np.uint64(f_start)
self.f_stop = np.uint64(f_stop)
# this will change from None to an array of phase offsets for each frequency bin
# if calibration gets applied at a later stage.
# this is an array of phases introduced by the system. So if a value is positive,
# it means that the system is introducing a phase shift between comb[0] and comb[1]
# in other words comb1 is artificially delayed.
self.calibration_phase_offsets = None
self.calibration_cable_length_offsets = None
self.arm()
self.fetch_signal()
self.frequency_bins = np.linspace(
start = self.f_start,
stop = self.f_stop,
num = len(self.signal),
endpoint = False)
示例12: hash_array
def hash_array(vals):
"""Given a 1d array, return an array of deterministic integers."""
# work with cagegoricals as ints. (This check is above the complex
# check so that we don't ask numpy if categorical is a subdtype of
# complex, as it will choke.
if is_categorical_dtype(vals.dtype):
vals = vals.codes
# we'll be working with everything as 64-bit values, so handle this
# 128-bit value early
if np.issubdtype(vals.dtype, np.complex128):
return hash_array(vals.real) + 23 * hash_array(vals.imag)
# MAIN LOGIC:
# First, turn whatever array this is into unsigned 64-bit ints, if we can
# manage it.
if vals.dtype == np.bool:
vals = vals.astype('u8')
elif (np.issubdtype(vals.dtype, np.datetime64) or
np.issubdtype(vals.dtype, np.timedelta64) or
np.issubdtype(vals.dtype, np.number)) and vals.dtype.itemsize <= 8:
vals = vals.view('u{}'.format(vals.dtype.itemsize)).astype('u8')
else:
vals = np.array([hash(x) for x in vals], dtype=np.uint64)
# Then, redistribute these 64-bit ints within the space of 64-bit ints
vals ^= vals >> 30
vals *= np.uint64(0xbf58476d1ce4e5b9)
vals ^= vals >> 27
vals *= np.uint64(0x94d049bb133111eb)
vals ^= vals >> 31
return vals
示例13: write_mwhite_subsample
def write_mwhite_subsample(self, subsample, output):
size = self.comm.allreduce(len(subsample))
offset = sum(self.comm.allgather(len(subsample))[: self.comm.rank])
if self.comm.rank == 0:
with open(output, "wb") as ff:
dtype = numpy.dtype(
[
("eflag", "int32"),
("hsize", "int32"),
("npart", "int32"),
("nsph", "int32"),
("nstar", "int32"),
("aa", "float"),
("gravsmooth", "float"),
]
)
header = numpy.zeros((), dtype=dtype)
header["eflag"] = 1
header["hsize"] = 20
header["npart"] = size
header.tofile(ff)
self.comm.barrier()
with open(output, "r+b") as ff:
ff.seek(28 + offset * 12)
numpy.float32(subsample["Position"]).tofile(ff)
ff.seek(28 + offset * 12 + size * 12)
numpy.float32(subsample["Velocity"]).tofile(ff)
ff.seek(28 + offset * 4 + size * 24)
numpy.float32(subsample["Density"]).tofile(ff)
ff.seek(28 + offset * 8 + size * 28)
numpy.uint64(subsample["ID"]).tofile(ff)
示例14: testIntMax
def testIntMax(self):
num = np.int(np.iinfo(np.int).max)
self.assertEqual(np.int(ujson.decode(ujson.encode(num))), num)
num = np.int8(np.iinfo(np.int8).max)
self.assertEqual(np.int8(ujson.decode(ujson.encode(num))), num)
num = np.int16(np.iinfo(np.int16).max)
self.assertEqual(np.int16(ujson.decode(ujson.encode(num))), num)
num = np.int32(np.iinfo(np.int32).max)
self.assertEqual(np.int32(ujson.decode(ujson.encode(num))), num)
num = np.uint8(np.iinfo(np.uint8).max)
self.assertEqual(np.uint8(ujson.decode(ujson.encode(num))), num)
num = np.uint16(np.iinfo(np.uint16).max)
self.assertEqual(np.uint16(ujson.decode(ujson.encode(num))), num)
num = np.uint32(np.iinfo(np.uint32).max)
self.assertEqual(np.uint32(ujson.decode(ujson.encode(num))), num)
if platform.architecture()[0] != '32bit':
num = np.int64(np.iinfo(np.int64).max)
self.assertEqual(np.int64(ujson.decode(ujson.encode(num))), num)
# uint64 max will always overflow as it's encoded to signed
num = np.uint64(np.iinfo(np.int64).max)
self.assertEqual(np.uint64(ujson.decode(ujson.encode(num))), num)
示例15: FromByteString
def FromByteString(cls,bytestr):
"""
Initialize Packet from the given byte string
"""
# check correct size packet
len_bytes = len(bytestr)
if not len_bytes == cls.BYTES_IN_PACKET:
raise ValueError("Packet should comprise {0} bytes, but has {1} bytes".format(len_bytes,cls.BYTES_IN_PACKET))
# unpack header
hdr = unpack(">{0}Q".format(cls.BYTES_IN_HEADER/8),bytestr[:cls.BYTES_IN_HEADER])
ut = uint32(hdr[0] & 0xFFFFFFFF)
pktnum = uint32((hdr[0]>>uint32(32)) & 0xFFFFF)
did = uint8(hdr[0]>>uint32(52) & 0x3F)
ifid = uint8(hdr[0]>>uint32(58) & 0x3F)
ud1 = uint32(hdr[1] & 0xFFFFFFFF)
ud0 = uint32((hdr[1]>>uint32(32)) & 0xFFFFFFFF)
res0 = uint64(hdr[2])
res1 = uint64(hdr[3]&0x7FFFFFFFFFFFFFFF)
fnt = not (hdr[3]&0x8000000000000000 == 0)
# unpack data in 64bit mode to correct for byte-order
data_64bit = array(unpack(">{0}Q".format(cls.BYTES_IN_PAYLOAD/8),bytestr[cls.BYTES_IN_HEADER:]),dtype=uint64)
data = zeros(cls.BYTES_IN_PAYLOAD,dtype=int8)
for ii in xrange(len(data_64bit)):
for jj in xrange(8):
data[ii*8+jj] = int8((data_64bit[ii]>>uint64(8*jj))&uint64(0xFF))
return Packet(ut,pktnum,did,ifid,ud0,ud1,res0,res1,fnt,data)