Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion array_api_compat/torch/_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,12 @@ def count_nonzero(
) -> Array:
result = torch.count_nonzero(x, dim=axis)
if keepdims:
if axis is not None:
if isinstance(axis, int):
return result.unsqueeze(axis)
elif isinstance(axis, tuple):
n_axis = [x.ndim + ax if ax < 0 else ax for ax in axis]
sh = [1 if i in n_axis else x.shape[i] for i in range(x.ndim)]
return torch.reshape(result, sh)
return _axis_none_keepdims(result, x.ndim, keepdims)
else:
return result
Expand Down
7 changes: 7 additions & 0 deletions numpy-1-22-xfails.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_sc
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[divide]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[hypot]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[subtract]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[logaddexp]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[nextafter]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[multiply]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[maximum]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[copysign]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[pow]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[pow]

array_api_tests/test_operators_and_elementwise_functions.py::test_where_with_scalars

Expand Down
Loading