[4.3.1] Test failure on i386 in test_grid_arrays_view
olebole opened this issue · 2 comments
Bug report
Bug summary
When running the tests on a 32-bit Intel machine, test_grid_arrays_view fails. This failure does not happen on x86_64.
Actual outcome
____________________________ test_grid_arrays_view _____________________________
self = unyt_array([0. , 0. , 0. , 0.25 , 0.25 , 0.25 , 0.25 , 0.25 ,
0.375 , 0.5 , 0.5 , 0.375 , 0.3125, 0.3125, 0.4375, 0.5625,
0.5625, 0.4375], 'code_length')
ufunc = <ufunc 'subtract'>, method = '__call__'
inputs = (array([0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 5.28944752e-315,
5.28944752e-315, 5.28944752e-315, 2... 0.25 ,
0.375 , 0.5 , 0.5 , 0.375 , 0.3125, 0.3125, 0.4375, 0.5625,
0.5625, 0.4375], 'code_length'))
kwargs = {}
func = <method-wrapper '__call__' of numpy.ufunc object at 0xf533b4a8>
out = None, out_func = None
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
func = getattr(ufunc, method)
[…]
if unit_operator is _comparison_unit:
[…]
else:
> raise UnitOperationError(ufunc, u0, u1)
E unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units 'dimensionless' (dimensions '1') and 'code_length' (dimensions '(length)') is not well defined.
/usr/lib/python3/dist-packages/unyt/array.py:1931: UnitOperationError
During handling of the above exception, another exception occurred:
def test_grid_arrays_view():
ds = setup_test_ds()
tree = ds.index._get_grid_tree()
grid_arr = tree.grid_arrays
> assert_equal(grid_arr["left_edge"], ds.index.grid_left_edge)
yt/geometry/tests/test_grid_container.py:141:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = (<built-in function eq>, array([[0.00000000e+000, 0.00000000e+000, 0.00000000e+000],
[5.28944752e-315, 5.289447... ],
[0.5 , 0.5 , 0.375 ],
[0.3125, 0.3125, 0.4375],
[0.5625, 0.5625, 0.4375]], 'code_length'))
kwds = {'err_msg': '', 'header': 'Arrays are not equal', 'strict': False, 'verbose': True}
@wraps(func)
def inner(*args, **kwds):
with self._recreate_cm():
> return func(*args, **kwds)
E ValueError:
E error during assertion:
E
E Traceback (most recent call last):
E File "/usr/lib/python3/dist-packages/numpy/testing/_private/utils.py", line 766, in assert_array_compare
E error = abs(x - y)
E ~~^~~
E File "/usr/lib/python3/dist-packages/unyt/array.py", line 1931, in __array_ufunc__
E raise UnitOperationError(ufunc, u0, u1)
E unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units 'dimensionless' (dimensions '1') and 'code_length' (dimensions '(length)') is not well defined.
E
E
E Arrays are not equal
E x: array([0.000000e+000, 0.000000e+000, 0.000000e+000, 5.289448e-315,
E 5.289448e-315, 5.289448e-315, 2.500000e-001, 3.750000e-001,
E 5.000000e-001, 5.294628e-315, 5.292038e-315, 5.297218e-315,...
E y: unyt_array([0. , 0. , 0. , 0.25 , 0.25 , 0.25 , 0.25 , 0.25 ,
E 0.375 , 0.5 , 0.5 , 0.375 , 0.3125, 0.3125, 0.4375, 0.5625,
E 0.5625, 0.4375], 'code_length')
/usr/lib/python3.11/contextlib.py:81: ValueError
Expected outcome
I'd expect the tests to pass. I am a bit wondering here why this happens only on i386, while the same runs on x86_64 with the same packages installed.
Version Information
- Operating System: Debian unstable
- Python Version: 3.11, 3.12
- yt version: 4.3.1
- Numpy: 1.26.4
- Unyt: 3.0.2
(All installed via apt-get)
Thanks for reporting this! I think this is likely due to the way we set up padding in these arrays. Internally, we have the GridTreeNode
objects, and then in the grid arrays we expose them as GridTreePadded
:
cdef struct GridTreeNode:
np.int32_t num_children
np.int32_t level
np.int64_t index
np.float64_t left_edge[3]
np.float64_t right_edge[3]
GridTreeNode **children
np.int64_t start_index[3]
np.int32_t dims[3]
np.float64_t dds[3]
cdef struct GridTreeNodePadded:
np.int32_t num_children
np.int32_t level
np.int64_t index
np.float64_t left_edge_x
np.float64_t left_edge_y
np.float64_t left_edge_z
np.float64_t right_edge_x
np.float64_t right_edge_y
np.float64_t right_edge_z
np.int_t children_pointers
np.int64_t start_index_x
np.int64_t start_index_y
np.int64_t start_index_z
np.int32_t dims_x
np.int32_t dims_y
np.int32_t dims_z
np.float64_t dds_x
np.float64_t dds_y
np.float64_t dds_z
So I would guess either the np.int
is wrong for the pointer values (and that would need to be fixed somehow to get it to work via numpy) or there's an alignment issue that I didn't take into account.
One possible solution -- which would break ABI but that's not so bad -- would be to move the children pointers to the end of the struct, and then remove them from the numpy array views. There we'd need to make sure our strides were still correct in the view.