def test_dtype(): from pybind11_tests import print_dtypes, test_dtype_ctors, test_dtype_methods assert print_dtypes() == [ "{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':12}", "[('x', '?'), ('y', '<u4'), ('z', '<f4')]", "[('a', {'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':12}), ('b', [('x', '?'), ('y', '<u4'), ('z', '<f4')])]", "{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}", "{'names':['a'], 'formats':[{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}], 'offsets':[8], 'itemsize':40}", "[('a', 'S3'), ('b', 'S3')]" ] d1 = np.dtype({ 'names': ['a', 'b'], 'formats': ['int32', 'float64'], 'offsets': [1, 10], 'itemsize': 20 }) d2 = np.dtype([('a', 'i4'), ('b', 'f4')]) assert test_dtype_ctors() == [ np.dtype('int32'), np.dtype('float64'), np.dtype('bool'), d1, d1, np.dtype('uint32'), d2 ] assert test_dtype_methods() == [ np.dtype('int32'), simple_dtype, False, True, np.dtype('int32').itemsize, simple_dtype.itemsize ]
def test_dtype(simple_dtype): from pybind11_tests import (print_dtypes, test_dtype_ctors, test_dtype_methods, trailing_padding_dtype, buffer_to_dtype) assert print_dtypes() == [ "{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':12}", "[('x', '?'), ('y', '<u4'), ('z', '<f4')]", "[('a', {'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8]," " 'itemsize':12}), ('b', [('x', '?'), ('y', '<u4'), ('z', '<f4')])]", "{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}", "{'names':['a'], 'formats':[{'names':['x','y','z'], 'formats':['?','<u4','<f4']," " 'offsets':[0,4,8], 'itemsize':24}], 'offsets':[8], 'itemsize':40}", "[('a', 'S3'), ('b', 'S3')]", "[('e1', '<i8'), ('e2', 'u1')]", "[('x', 'i1'), ('y', '<u8')]" ] d1 = np.dtype({'names': ['a', 'b'], 'formats': ['int32', 'float64'], 'offsets': [1, 10], 'itemsize': 20}) d2 = np.dtype([('a', 'i4'), ('b', 'f4')]) assert test_dtype_ctors() == [np.dtype('int32'), np.dtype('float64'), np.dtype('bool'), d1, d1, np.dtype('uint32'), d2] assert test_dtype_methods() == [np.dtype('int32'), simple_dtype, False, True, np.dtype('int32').itemsize, simple_dtype.itemsize] assert trailing_padding_dtype() == buffer_to_dtype(np.zeros(1, trailing_padding_dtype()))
def test_dtype(simple_dtype): from pybind11_tests import (print_dtypes, test_dtype_ctors, test_dtype_methods, trailing_padding_dtype, buffer_to_dtype) from sys import byteorder e = '<' if byteorder == 'little' else '>' assert print_dtypes() == [ simple_dtype_fmt(), packed_dtype_fmt(), "[('a', {}), ('b', {})]".format(simple_dtype_fmt(), packed_dtype_fmt()), partial_dtype_fmt(), partial_nested_fmt(), "[('a', 'S3'), ('b', 'S3')]", ("{{'names':['a','b','c','d'], " + "'formats':[('S4', (3,)),('<i4', (2,)),('u1', (3,)),('<f4', (4, 2))], " + "'offsets':[0,12,20,24], 'itemsize':56}}").format(e=e), "[('e1', '" + e + "i8'), ('e2', 'u1')]", "[('x', 'i1'), ('y', '" + e + "u8')]", "[('cflt', '" + e + "c8'), ('cdbl', '" + e + "c16')]" ] d1 = np.dtype({'names': ['a', 'b'], 'formats': ['int32', 'float64'], 'offsets': [1, 10], 'itemsize': 20}) d2 = np.dtype([('a', 'i4'), ('b', 'f4')]) assert test_dtype_ctors() == [np.dtype('int32'), np.dtype('float64'), np.dtype('bool'), d1, d1, np.dtype('uint32'), d2] assert test_dtype_methods() == [np.dtype('int32'), simple_dtype, False, True, np.dtype('int32').itemsize, simple_dtype.itemsize] assert trailing_padding_dtype() == buffer_to_dtype(np.zeros(1, trailing_padding_dtype()))
def test_dtype(simple_dtype): from pybind11_tests import (print_dtypes, test_dtype_ctors, test_dtype_methods, trailing_padding_dtype, buffer_to_dtype) from sys import byteorder e = '<' if byteorder == 'little' else '>' assert print_dtypes() == [ simple_dtype_fmt(), packed_dtype_fmt(), "[('a', {}), ('b', {})]".format(simple_dtype_fmt(), packed_dtype_fmt()), partial_dtype_fmt(), partial_nested_fmt(), "[('a', 'S3'), ('b', 'S3')]", "[('e1', '" + e + "i8'), ('e2', 'u1')]", "[('x', 'i1'), ('y', '" + e + "u8')]" ] d1 = np.dtype({'names': ['a', 'b'], 'formats': ['int32', 'float64'], 'offsets': [1, 10], 'itemsize': 20}) d2 = np.dtype([('a', 'i4'), ('b', 'f4')]) assert test_dtype_ctors() == [np.dtype('int32'), np.dtype('float64'), np.dtype('bool'), d1, d1, np.dtype('uint32'), d2] assert test_dtype_methods() == [np.dtype('int32'), simple_dtype, False, True, np.dtype('int32').itemsize, simple_dtype.itemsize] assert trailing_padding_dtype() == buffer_to_dtype(np.zeros(1, trailing_padding_dtype()))
def test_dtype(simple_dtype): from pybind11_tests import (print_dtypes, test_dtype_ctors, test_dtype_methods, trailing_padding_dtype, buffer_to_dtype) if print_dtypes() != [ simple_dtype_fmt(), packed_dtype_fmt(), "[('a', {}), ('b', {})]".format( simple_dtype_fmt(), packed_dtype_fmt()), partial_dtype_fmt(), partial_nested_fmt(), "[('a', 'S3'), ('b', 'S3')]", "[('e1', '<i8'), ('e2', 'u1')]", "[('x', 'i1'), ('y', '<u8')]" ]: raise AssertionError d1 = np.dtype({ 'names': ['a', 'b'], 'formats': ['int32', 'float64'], 'offsets': [1, 10], 'itemsize': 20 }) d2 = np.dtype([('a', 'i4'), ('b', 'f4')]) if test_dtype_ctors() != [ np.dtype('int32'), np.dtype('float64'), np.dtype('bool'), d1, d1, np.dtype('uint32'), d2 ]: raise AssertionError if test_dtype_methods() != [ np.dtype('int32'), simple_dtype, False, True, np.dtype('int32').itemsize, simple_dtype.itemsize ]: raise AssertionError if trailing_padding_dtype() != buffer_to_dtype( np.zeros(1, trailing_padding_dtype())): raise AssertionError
def test_dtype(simple_dtype): from pybind11_tests import (print_dtypes, test_dtype_ctors, test_dtype_methods, trailing_padding_dtype, buffer_to_dtype) assert print_dtypes() == [ "{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':12}", "[('x', '?'), ('y', '<u4'), ('z', '<f4')]", "[('a', {'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8]," " 'itemsize':12}), ('b', [('x', '?'), ('y', '<u4'), ('z', '<f4')])]", "{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}", "{'names':['a'], 'formats':[{'names':['x','y','z'], 'formats':['?','<u4','<f4']," " 'offsets':[0,4,8], 'itemsize':24}], 'offsets':[8], 'itemsize':40}", "[('a', 'S3'), ('b', 'S3')]", "[('e1', '<i8'), ('e2', 'u1')]", "[('x', 'i1'), ('y', '<u8')]" ] d1 = np.dtype({ 'names': ['a', 'b'], 'formats': ['int32', 'float64'], 'offsets': [1, 10], 'itemsize': 20 }) d2 = np.dtype([('a', 'i4'), ('b', 'f4')]) assert test_dtype_ctors() == [ np.dtype('int32'), np.dtype('float64'), np.dtype('bool'), d1, d1, np.dtype('uint32'), d2 ] assert test_dtype_methods() == [ np.dtype('int32'), simple_dtype, False, True, np.dtype('int32').itemsize, simple_dtype.itemsize ] assert trailing_padding_dtype() == buffer_to_dtype( np.zeros(1, trailing_padding_dtype()))