当前位置: 首页>>代码示例>>Python>>正文


Python special.typeof函数代码示例

本文整理汇总了Python中numba.special.typeof函数的典型用法代码示例。如果您正苦于以下问题:Python typeof函数的具体用法?Python typeof怎么用?Python typeof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了typeof函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dtype

    def test_dtype(self):
        dtype = np.dtype("int64")
        self.assertEqual(typeof(dtype), types.DType(types.int64))

        dtype = np.dtype([("m", np.int32), ("n", "S5")])
        rec_ty = numpy_support.from_struct_dtype(dtype)
        self.assertEqual(typeof(dtype), types.DType(rec_ty))
开发者ID:shivamvats,项目名称:numba,代码行数:7,代码来源:test_typeof.py

示例2: test_array_values

    def test_array_values(self):
        """
        Test special.typeof() with ndarray values.
        """
        def check(arr, ndim, layout, mutable, aligned):
            ty = typeof(arr)
            self.assertIsInstance(ty, types.Array)
            self.assertEqual(ty.ndim, ndim)
            self.assertEqual(ty.layout, layout)
            self.assertEqual(ty.mutable, mutable)
            self.assertEqual(ty.aligned, aligned)

        a1 = np.arange(10)
        check(a1, 1, 'C', True, True)
        a2 = np.arange(10).reshape(2, 5)
        check(a2, 2, 'C', True, True)
        check(a2.T, 2, 'F', True, True)
        a3 = (np.arange(60))[::2].reshape((2, 5, 3))
        check(a3, 3, 'A', True, True)
        a4 = np.arange(1).reshape(())
        check(a4, 0, 'C', True, True)
        a4.flags.writeable = False
        check(a4, 0, 'C', False, True)

        # Unsupported dtype
        a5 = a1.astype(a1.dtype.newbyteorder())
        with self.assertRaises(ValueError) as raises:
            typeof(a5)
        self.assertIn("Unsupported array dtype: %s" % (a5.dtype,),
                      str(raises.exception))
开发者ID:cpcloud,项目名称:numba,代码行数:30,代码来源:test_typeof.py

示例3: test_slices

 def test_slices(self):
     for args in [(1,), (1, 2), (1, 2, 1), (1, 2, None)]:
         v = slice(*args)
         self.assertIs(typeof(v), types.slice2_type)
     for args in [(1, 2, 2), (1, 2, -1), (None, None, -2)]:
         v = slice(*args)
         self.assertIs(typeof(v), types.slice3_type)
开发者ID:cpcloud,项目名称:numba,代码行数:7,代码来源:test_typeof.py

示例4: test_tuples

 def test_tuples(self):
     v = (1, 2)
     self.assertEqual(typeof(v), types.UniTuple(types.intp, 2))
     v = (1, (2.0, 3))
     self.assertEqual(typeof(v),
                      types.Tuple((types.intp,
                                   types.Tuple((types.float64, types.intp))))
                      )
开发者ID:cpcloud,项目名称:numba,代码行数:8,代码来源:test_typeof.py

示例5: test_number_values

 def test_number_values(self):
     """
     Test special.typeof() with scalar number values.
     """
     self.check_number_values(typeof)
     # These values mirror Dispatcher semantics
     self.assertEqual(typeof(1), types.int64)
     self.assertEqual(typeof(-1), types.int64)
开发者ID:shivamvats,项目名称:numba,代码行数:8,代码来源:test_typeof.py

示例6: test_ctypes

 def test_ctypes(self):
     ty_cos = typeof(c_cos)
     ty_sin = typeof(c_sin)
     self.assertIsInstance(ty_cos, types.ExternalFunctionPointer)
     self.assertEqual(ty_cos.sig.args, (types.float64,))
     self.assertEqual(ty_cos.sig.return_type, types.float64)
     self.assertEqual(ty_cos, ty_sin)
     self.assertNotEqual(ty_cos.get_pointer(c_cos), ty_sin.get_pointer(c_sin))
开发者ID:shivamvats,项目名称:numba,代码行数:8,代码来源:test_typeof.py

示例7: test_omitted_args

 def test_omitted_args(self):
     ty0 = typeof(OmittedArg(0.0))
     ty1 = typeof(OmittedArg(1))
     ty2 = typeof(OmittedArg(1.0))
     ty3 = typeof(OmittedArg(1.0))
     self.assertEqual(ty0, types.Omitted(0.0))
     self.assertEqual(ty1, types.Omitted(1))
     self.assertEqual(ty2, types.Omitted(1.0))
     self.assertEqual(len({ty0, ty1, ty2}), 3)
     self.assertEqual(ty3, ty2)
开发者ID:cpcloud,项目名称:numba,代码行数:10,代码来源:test_typeof.py

示例8: test_namedtuple

 def test_namedtuple(self):
     v = Point(1, 2)
     tp_point = typeof(v)
     self.assertEqual(tp_point, types.NamedUniTuple(types.intp, 2, Point))
     v = Point(1, 2.0)
     self.assertEqual(typeof(v), types.NamedTuple([types.intp, types.float64], Point))
     w = Rect(3, 4)
     tp_rect = typeof(w)
     self.assertEqual(tp_rect, types.NamedUniTuple(types.intp, 2, Rect))
     self.assertNotEqual(tp_rect, tp_point)
     self.assertNotEqual(tp_rect, types.UniTuple(tp_rect.dtype, tp_rect.count))
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:11,代码来源:test_typeof.py

示例9: test_cffi

    def test_cffi(self):
        from .cffi_usecases import cffi_cos, cffi_sin

        ty_cffi_cos = typeof(cffi_cos)
        ty_cffi_sin = typeof(cffi_sin)
        self.assertIsInstance(ty_cffi_cos, types.ExternalFunctionPointer)
        self.assertEqual(ty_cffi_cos.sig.args, (types.float64,))
        self.assertEqual(ty_cffi_cos.sig.return_type, types.float64)
        self.assertEqual(ty_cffi_cos, ty_cffi_sin)
        ty_ctypes_cos = typeof(c_cos)
        self.assertNotEqual(ty_cffi_cos, ty_ctypes_cos)
        self.assertNotEqual(ty_cffi_cos.get_pointer(cffi_cos), ty_cffi_sin.get_pointer(cffi_sin))
        self.assertEqual(ty_cffi_cos.get_pointer(cffi_cos), ty_ctypes_cos.get_pointer(c_cos))
开发者ID:shivamvats,项目名称:numba,代码行数:13,代码来源:test_typeof.py

示例10: check

 def check(arr, ndim, layout, mutable, aligned):
     ty = typeof(arr)
     self.assertIsInstance(ty, types.Array)
     self.assertEqual(ty.ndim, ndim)
     self.assertEqual(ty.layout, layout)
     self.assertEqual(ty.mutable, mutable)
     self.assertEqual(ty.aligned, aligned)
开发者ID:cpcloud,项目名称:numba,代码行数:7,代码来源:test_typeof.py

示例11: test_buffers

    def test_buffers(self):
        if sys.version_info >= (3,):
            b = b"xx"
            ty = typeof(b)
            self.assertEqual(ty, types.Bytes(types.uint8, 1, "C"))
            self.assertFalse(ty.mutable)
            ty = typeof(memoryview(b))
            self.assertEqual(ty, types.MemoryView(types.uint8, 1, "C", readonly=True))
            self.assertFalse(ty.mutable)
            ty = typeof(array.array("i", [0, 1, 2]))
            self.assertEqual(ty, types.PyArray(types.int32, 1, "C"))
            self.assertTrue(ty.mutable)

        b = bytearray(10)
        ty = typeof(b)
        self.assertEqual(ty, types.ByteArray(types.uint8, 1, "C"))
        self.assertTrue(ty.mutable)
开发者ID:shivamvats,项目名称:numba,代码行数:17,代码来源:test_typeof.py

示例12: test_enum

    def test_enum(self):
        tp_red = typeof(Color.red)
        self.assertEqual(tp_red, types.EnumMember(Color, types.intp))
        self.assertEqual(tp_red, typeof(Color.blue))
        tp_choc = typeof(Shake.chocolate)
        self.assertEqual(tp_choc, types.EnumMember(Shake, types.intp))
        self.assertEqual(tp_choc, typeof(Shake.mint))
        self.assertNotEqual(tp_choc, tp_red)
        tp_404 = typeof(RequestError.not_found)
        self.assertEqual(tp_404, types.IntEnumMember(RequestError, types.intp))
        self.assertEqual(tp_404, typeof(RequestError.internal_error))

        with self.assertRaises(ValueError) as raises:
            typeof(HeterogeneousEnum.red)
        self.assertEqual(str(raises.exception),
                         "Cannot type heterogeneous enum: got value types complex128, float64")
开发者ID:cpcloud,项目名称:numba,代码行数:16,代码来源:test_typeof.py

示例13: test_enum_class

    def test_enum_class(self):
        tp_color = typeof(Color)
        self.assertEqual(tp_color, types.EnumClass(Color, types.intp))
        tp_shake = typeof(Shake)
        self.assertEqual(tp_shake, types.EnumClass(Shake, types.intp))
        self.assertNotEqual(tp_shake, tp_color)
        tp_shape = typeof(Shape)
        self.assertEqual(tp_shape, types.IntEnumClass(Shape, types.intp))
        tp_error = typeof(RequestError)
        self.assertEqual(tp_error,
                         types.IntEnumClass(RequestError, types.intp))
        self.assertNotEqual(tp_error, tp_shape)

        with self.assertRaises(ValueError) as raises:
            typeof(HeterogeneousEnum)
        self.assertEqual(str(raises.exception),
                         "Cannot type heterogeneous enum: got value types complex128, float64")
开发者ID:cpcloud,项目名称:numba,代码行数:17,代码来源:test_typeof.py

示例14: test_ellipsis

 def test_ellipsis(self):
     ty = typeof(Ellipsis)
     self.assertEqual(ty, types.ellipsis)
开发者ID:cpcloud,项目名称:numba,代码行数:3,代码来源:test_typeof.py

示例15: check

 def check(arr, ndim, layout, mutable):
     ty = special.typeof(arr)
     self.assertIsInstance(ty, types.Array)
     self.assertEqual(ty.ndim, ndim)
     self.assertEqual(ty.layout, layout)
     self.assertEqual(ty.mutable, mutable)
开发者ID:CaptainAL,项目名称:Spyder,代码行数:6,代码来源:test_special.py


注:本文中的numba.special.typeof函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。