Commit 20c0f64a authored by Joseph Weston's avatar Joseph Weston
Browse files

export size in bytes of different dtypes

This is useful for testing
parent 877101de
......@@ -1363,6 +1363,19 @@ MOD_INIT_FUNC(tinyarray)
PyModule_AddObject(m, "ndarray_complex",
(PyObject *)&Array<Complex>::pytype);
// export information on the sizes of different dtypes in bytes
PyObject *dtype_size = PyDict_New();
PyDict_SetItem(dtype_size,
(PyObject*)&PyInt_Type,
PyInt_FromSize_t(sizeof(long)));
PyDict_SetItem(dtype_size,
(PyObject*)&PyFloat_Type,
PyInt_FromSize_t(sizeof(double)));
PyDict_SetItem(dtype_size,
(PyObject*)&PyComplex_Type,
PyInt_FromSize_t(sizeof(Complex)));
PyModule_AddObject(m, "dtype_size", dtype_size);
// We never release these references but this is not a problem. The Python
// interpreter does the same, see try_complex_special_method in
// complexobject.c
......
......@@ -33,12 +33,6 @@ def machine_wordsize():
dtypes = [int, float, complex]
dtype_size = {
int: machine_wordsize(),
float: 8,
complex: 16
}
some_shapes = [(), 0, 1, 2, 3,
(0, 0), (1, 0), (0, 1), (2, 2), (17, 17),
(0, 0, 0), (1, 1, 1), (2, 2, 1), (2, 0, 3)]
......@@ -426,8 +420,8 @@ def test_sizeof():
# at the start of the buffer
if len(a.shape) > 1:
n_elements += (a.ndim * machine_wordsize() +
dtype_size[dtype] - 1) // dtype_size[dtype]
buffer_size = n_elements * dtype_size[dtype]
ta.dtype_size[dtype] - 1) // ta.dtype_size[dtype]
buffer_size = n_elements * ta.dtype_size[dtype]
# A Basic Python object has 3 pointer-sized members, or 5 if in
# debug mode.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment