Closed BenTaylor-TfN closed 1 year ago
I managed to recreate the bug. For future reference, with intermittent bugs in tests like this, it is useful to use pytest-repeat, the run pytest with the additional arguments:
pytest --count=1000 -x
Telling pytest to repeat 1000 times, but quit as soon as it gets its first error.
import sparse
from caf.toolkit import array_utils
shape = (13, 11, 7)
data = [0.16858948, 0.8229999, 0.02905589, 0.3573722]
coords = [
[3, 4, 7, 10],
[3, 4, 2, 6],
[4, 4, 4, 4],
]
sum_axis = (1, 0)
arr = sparse.COO(
data=data,
shape=shape,
coords=coords,
fill_value=0,
)
result = array_utils.sparse_sum(arr, sum_axis)
This returns a float value of 1.37801747
, rather than the expected sparse.COO()
array.
There's a test that randomly fails in
test_array_utils
https://github.com/Transport-for-the-North/caf.toolkit/blob/186671cc42d6a598b7c2036ae3b03cce794f177e/tests/test_array_utils.py#L80-L91.Example of test fails can be seen on GitHub actions: https://github.com/Transport-for-the-North/caf.toolkit/actions/runs/5973932708/job/16207137874?pr=59 https://github.com/Transport-for-the-North/caf.toolkit/actions/runs/5953829958/job/16148999342
It looks like the error is being caused by the
achieved.todense()
line. The error looks like:AttributeError: 'numpy.float64' object has no attribute 'todense
It's likely that there is an attribute with some of the randomly created matrices that makes a float be returned from the
sparse_sum()
call, rather than an array. We need an example of what is causing this issue in order to ensure we remove the issue.