本文整理汇总了Python中numba._dispatcher.compute_fingerprint函数的典型用法代码示例。如果您正苦于以下问题:Python compute_fingerprint函数的具体用法?Python compute_fingerprint怎么用?Python compute_fingerprint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compute_fingerprint函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_records
def test_records(self):
d1 = np.dtype([('m', np.int32), ('n', np.int64)])
d2 = np.dtype([('m', np.int32), ('n', np.int16)])
v1 = np.empty(1, dtype=d1)[0]
v2 = np.empty(1, dtype=d2)[0]
self.assertNotEqual(compute_fingerprint(v1),
compute_fingerprint(v2))
开发者ID:cpcloud,项目名称:numba,代码行数:7,代码来源:test_typeof.py
示例2: test_datetime
def test_datetime(self):
a = np.datetime64(1, "Y")
b = np.datetime64(2, "Y")
c = np.datetime64(2, "s")
d = np.timedelta64(2, "s")
self.assertEqual(compute_fingerprint(a), compute_fingerprint(b))
distinct = set(compute_fingerprint(x) for x in (a, c, d))
self.assertEqual(len(distinct), 3, distinct)
开发者ID:shivamvats,项目名称:numba,代码行数:8,代码来源:test_typeof.py
示例3: test_ints
def test_ints(self):
s = compute_fingerprint(1)
for v in (-1, 2 ** 60):
self.assertEqual(compute_fingerprint(v), s)
# Different int widths resolve to different fingerprints
distinct = set()
for tp in ("int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64"):
tp = getattr(np, tp)
distinct.add(compute_fingerprint(tp()))
self.assertEqual(len(distinct), 8, distinct)
开发者ID:shivamvats,项目名称:numba,代码行数:10,代码来源:test_typeof.py
示例4: test_omitted_args
def test_omitted_args(self):
distinct = DistinctChecker()
v0 = OmittedArg(0.0)
v1 = OmittedArg(1.0)
v2 = OmittedArg(1)
s = compute_fingerprint(v0)
self.assertEqual(compute_fingerprint(v1), s)
distinct.add(s)
distinct.add(compute_fingerprint(v2))
distinct.add(compute_fingerprint(0.0))
distinct.add(compute_fingerprint(1))
开发者ID:cpcloud,项目名称:numba,代码行数:13,代码来源:test_typeof.py
示例5: test_sets
def test_sets(self):
distinct = DistinctChecker()
s = compute_fingerprint(set([1]))
self.assertEqual(compute_fingerprint(set([2, 3])), s)
distinct.add(s)
distinct.add(compute_fingerprint([1]))
distinct.add(compute_fingerprint(set([1j])))
distinct.add(compute_fingerprint(set([4.5, 6.7])))
distinct.add(compute_fingerprint(set([(1,)])))
with self.assertRaises(ValueError):
compute_fingerprint(set())
with self.assertRaises(NotImplementedError):
compute_fingerprint(frozenset([2, 3]))
开发者ID:cpcloud,项目名称:numba,代码行数:16,代码来源:test_typeof.py
示例6: test_dtype
def test_dtype(self):
distinct = DistinctChecker()
s = compute_fingerprint(np.dtype("int64"))
self.assertEqual(compute_fingerprint(np.dtype("int64")), s)
distinct.add(s)
for descr in ("int32", "m8[s]", "m8[W]", "M8[s]"):
distinct.add(np.dtype(descr))
distinct.add(recordtype)
distinct.add(recordtype2)
# np.recarray() is peculiar: it creates a new dtype instance in
# its constructor; check that the fingerprint remains efficient
a = np.recarray(1, dtype=recordtype)
b = np.recarray(1, dtype=recordtype)
self.assertEqual(compute_fingerprint(a.dtype), compute_fingerprint(b.dtype))
开发者ID:shivamvats,项目名称:numba,代码行数:18,代码来源:test_typeof.py
示例7: test_tuples
def test_tuples(self):
distinct = DistinctChecker()
s = compute_fingerprint((1,))
self.assertEqual(compute_fingerprint((2,)), s)
distinct.add(s)
distinct.add(compute_fingerprint(()))
distinct.add(compute_fingerprint((1, 2, 3)))
distinct.add(compute_fingerprint((1j, 2, 3)))
distinct.add(compute_fingerprint((1, (), np.empty(5))))
distinct.add(compute_fingerprint((1, (), np.empty((5, 1)))))
开发者ID:cpcloud,项目名称:numba,代码行数:12,代码来源:test_typeof.py
示例8: test_lists
def test_lists(self):
distinct = DistinctChecker()
s = compute_fingerprint([1])
self.assertEqual(compute_fingerprint([2, 3]), s)
distinct.add(s)
distinct.add(compute_fingerprint([1j]))
distinct.add(compute_fingerprint([4.5, 6.7]))
distinct.add(compute_fingerprint([(1,)]))
with self.assertRaises(ValueError):
compute_fingerprint([])
开发者ID:cpcloud,项目名称:numba,代码行数:13,代码来源:test_typeof.py
示例9: test_fingerprint_failure
def test_fingerprint_failure(self):
"""
Failure in computing the fingerprint cannot affect a nopython=False
function. On the other hand, with nopython=True, a ValueError should
be raised to report the failure with fingerprint.
"""
@jit
def foo(x):
return x
# Empty list will trigger failure in compile_fingerprint
errmsg = 'cannot compute fingerprint of empty list'
with self.assertRaises(ValueError) as raises:
_dispatcher.compute_fingerprint([])
self.assertIn(errmsg, str(raises.exception))
# It should work in fallback
self.assertEqual(foo([]), [])
# But, not in nopython=True
strict_foo = jit(nopython=True)(foo.py_func)
with self.assertRaises(ValueError) as raises:
strict_foo([])
self.assertIn(errmsg, str(raises.exception))
# Test in loop lifting context
@jit
def bar():
object() # force looplifting
x = []
for i in range(10):
x = foo(x)
return x
self.assertEqual(bar(), [])
# Make sure it was looplifted
[cr] = bar.overloads.values()
self.assertEqual(len(cr.lifted), 1)
开发者ID:yuguen,项目名称:numba,代码行数:36,代码来源:test_dispatcher.py
示例10: test_buffers
def test_buffers(self):
distinct = DistinctChecker()
s = compute_fingerprint(b'')
self.assertEqual(compute_fingerprint(b'xx'), s)
distinct.add(s)
distinct.add(compute_fingerprint(bytearray()))
distinct.add(compute_fingerprint(memoryview(b'')))
m_uint8_1d = compute_fingerprint(memoryview(bytearray()))
distinct.add(m_uint8_1d)
if sys.version_info >= (3,):
arr = array.array('B', [42])
distinct.add(compute_fingerprint(arr))
self.assertEqual(compute_fingerprint(memoryview(arr)), m_uint8_1d)
for array_code in 'bi':
arr = array.array(array_code, [0, 1, 2])
distinct.add(compute_fingerprint(arr))
distinct.add(compute_fingerprint(memoryview(arr)))
arr = np.empty(16, dtype=np.uint8)
distinct.add(compute_fingerprint(arr))
self.assertEqual(compute_fingerprint(memoryview(arr)), m_uint8_1d)
arr = arr.reshape((4, 4))
distinct.add(compute_fingerprint(arr))
distinct.add(compute_fingerprint(memoryview(arr)))
arr = arr.T
distinct.add(compute_fingerprint(arr))
distinct.add(compute_fingerprint(memoryview(arr)))
arr = arr[::2]
distinct.add(compute_fingerprint(arr))
distinct.add(compute_fingerprint(memoryview(arr)))
if sys.version_info >= (3,):
m = mmap.mmap(-1, 16384)
distinct.add(compute_fingerprint(m))
self.assertEqual(compute_fingerprint(memoryview(m)), m_uint8_1d)
开发者ID:cpcloud,项目名称:numba,代码行数:37,代码来源:test_typeof.py
示例11: test_arrays
def test_arrays(self):
distinct = DistinctChecker()
# 1D
arr = np.empty(4, dtype=np.float64)
s = compute_fingerprint(arr)
distinct.add(s)
self.assertEqual(compute_fingerprint(arr[:1]), s)
# Non-contiguous
distinct.add(compute_fingerprint(arr[::2]))
# Other type
distinct.add(compute_fingerprint(arr.astype(np.complex64)))
# Readonly
arr.setflags(write=False)
distinct.add(compute_fingerprint(arr))
# 2D
arr = np.empty((4, 4), dtype=np.float64)
distinct.add(compute_fingerprint(arr))
# F-contiguous
distinct.add(compute_fingerprint(arr.T))
# Non-contiguous
distinct.add(compute_fingerprint(arr[::2]))
# 0D
arr = np.empty((), dtype=np.float64)
distinct.add(compute_fingerprint(arr))
# Structured arrays
arr = np.empty(5, dtype=recordtype)
s = compute_fingerprint(arr)
distinct.add(s)
self.assertEqual(compute_fingerprint(arr[:1]), s)
arr = np.empty(5, dtype=recordtype2)
distinct.add(compute_fingerprint(arr))
arr = np.empty(5, dtype=recordtype3)
distinct.add(compute_fingerprint(arr))
# np.recarray() is peculiar: it creates a new dtype instance in
# its constructor; check that the fingerprint remains efficient
a = np.recarray(1, dtype=recordtype)
b = np.recarray(1, dtype=recordtype)
self.assertEqual(compute_fingerprint(a),
compute_fingerprint(b))
开发者ID:cpcloud,项目名称:numba,代码行数:44,代码来源:test_typeof.py
示例12: test_none
def test_none(self):
compute_fingerprint(None)
开发者ID:cpcloud,项目名称:numba,代码行数:2,代码来源:test_typeof.py
示例13: test_complex
def test_complex(self):
s = compute_fingerprint(1j)
self.assertEqual(s, compute_fingerprint(1+0j))
s = compute_fingerprint(np.complex64())
self.assertEqual(compute_fingerprint(np.complex64(2.0)), s)
self.assertNotEqual(compute_fingerprint(np.complex128()), s)
开发者ID:cpcloud,项目名称:numba,代码行数:6,代码来源:test_typeof.py
示例14: test_bool
def test_bool(self):
s = compute_fingerprint(True)
self.assertEqual(compute_fingerprint(False), s)
self.assertNotEqual(compute_fingerprint(1), s)
开发者ID:cpcloud,项目名称:numba,代码行数:4,代码来源:test_typeof.py
示例15: test_floats
def test_floats(self):
s = compute_fingerprint(1.0)
self.assertEqual(compute_fingerprint(2.0), s)
s = compute_fingerprint(np.float32())
self.assertEqual(compute_fingerprint(np.float32(2.0)), s)
self.assertNotEqual(compute_fingerprint(np.float64()), s)
开发者ID:cpcloud,项目名称:numba,代码行数:6,代码来源:test_typeof.py
示例16: test_complicated_type
def test_complicated_type(self):
# Generating a large fingerprint
t = None
for i in range(1000):
t = (t,)
s = compute_fingerprint(t)
开发者ID:cpcloud,项目名称:numba,代码行数:6,代码来源:test_typeof.py
示例17: test_enums
def test_enums(self):
# Enums should fail fingerprinting, even IntEnums
with self.assertRaises(NotImplementedError):
compute_fingerprint(Color.red)
with self.assertRaises(NotImplementedError):
compute_fingerprint(RequestError.not_found)
开发者ID:cpcloud,项目名称:numba,代码行数:6,代码来源:test_typeof.py
注:本文中的numba._dispatcher.compute_fingerprint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论