diff --git a/cuda/matrix/sellp_kernels.cu b/cuda/matrix/sellp_kernels.cu index 6273266be47..9f40b61c41e 100644 --- a/cuda/matrix/sellp_kernels.cu +++ b/cuda/matrix/sellp_kernels.cu @@ -205,6 +205,12 @@ void count_nonzeros(std::shared_ptr exec, size_type *result) { const auto num_rows = source->get_size()[0]; + + if (num_rows <= 0) { + *result = 0; + return; + } + const auto slice_size = source->get_slice_size(); const auto slice_sets = source->get_const_slice_sets(); const auto values = source->get_const_values(); diff --git a/hip/matrix/sellp_kernels.hip.cpp b/hip/matrix/sellp_kernels.hip.cpp index f7a875de2d7..bc2d0a2e64e 100644 --- a/hip/matrix/sellp_kernels.hip.cpp +++ b/hip/matrix/sellp_kernels.hip.cpp @@ -210,6 +210,12 @@ void count_nonzeros(std::shared_ptr exec, size_type *result) { const auto num_rows = source->get_size()[0]; + + if (num_rows <= 0) { + *result = 0; + return; + } + const auto slice_size = source->get_slice_size(); const auto slice_sets = source->get_const_slice_sets(); const auto values = source->get_const_values();