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: 6 additions & 0 deletions lib/src/nclsoverlaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pybind11::tuple perform_find_overlaps(
int min_overlap,
int num_threads=1) {

if (num_threads < 1) {
throw std::invalid_argument("num_threads must be >= 1");
}
py::buffer_info q_starts_buf = query_starts.request();
py::buffer_info q_ends_buf = query_ends.request();

Expand Down Expand Up @@ -160,6 +163,9 @@ pybind11::tuple perform_find_overlaps_groups(
int min_overlap,
int num_threads=1) {

if (num_threads < 1) {
throw std::invalid_argument("num_threads must be >= 1");
}
auto s_starts_ptr = static_cast<const Position*>(self_starts.request().ptr);
auto s_ends_ptr = static_cast<const Position*>(self_ends.request().ptr);
auto q_starts_ptr = static_cast<const Position*>(query_starts.request().ptr);
Expand Down
12 changes: 12 additions & 0 deletions lib/src/nclssearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ py::object perform_follow(
const std::string& select,
int num_threads = 1) {

if (num_threads < 1) {
throw std::invalid_argument("num_threads must be >= 1");
}
auto q_starts_ptr = static_cast<const Position*>(query_starts.request().ptr);
Index n_queries = query_starts.request().shape[0];

Expand Down Expand Up @@ -111,6 +114,9 @@ py::object perform_precede(
const std::string& select,
int num_threads = 1) {

if (num_threads < 1) {
throw std::invalid_argument("num_threads must be >= 1");
}
auto q_ends_ptr = static_cast<const Position*>(query_ends.request().ptr);
Index n_queries = query_ends.request().shape[0];

Expand Down Expand Up @@ -179,6 +185,9 @@ py::object perform_nearest(
int num_threads=1,
bool adjacent_equals_overlap=false) {

if (num_threads < 1) {
throw std::invalid_argument("num_threads must be >= 1");
}
auto q_starts_ptr = static_cast<const Position*>(query_starts.request().ptr);
auto q_ends_ptr = static_cast<const Position*>(query_ends.request().ptr);
Index n_queries = query_starts.request().shape[0];
Expand Down Expand Up @@ -275,6 +284,9 @@ pybind11::tuple perform_nearest_groups(
int num_threads=1,
bool adjacent_equals_overlap=false) {

if (num_threads < 1) {
throw std::invalid_argument("num_threads must be >= 1");
}
auto s_starts_ptr = static_cast<const Position*>(self_starts.request().ptr);
auto s_ends_ptr = static_cast<const Position*>(self_ends.request().ptr);
auto q_starts_ptr = static_cast<const Position*>(query_starts.request().ptr);
Expand Down
29 changes: 29 additions & 0 deletions tests/test_num_threads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np
import pytest

from iranges import IRanges, lib_iranges

__author__ = "btraven"
__copyright__ = "jkanche"
__license__ = "MIT"

ir = IRanges([2, 10], [1, 3])
starts, ends = np.array([2, 10], dtype=np.int32), np.array([3, 13], dtype=np.int32)
groups = [np.array([0, 1], dtype=np.int32)]

CALLS = {
"find_overlaps": lambda: ir.find_overlaps(ir, num_threads=0),
"precede": lambda: ir.precede(ir, num_threads=0),
"follow": lambda: ir.follow(ir, num_threads=0),
"nearest": lambda: ir.nearest(ir, num_threads=0),
"find_overlaps_groups": lambda: lib_iranges.find_overlaps_groups(
starts, ends, groups, starts, ends, groups, num_threads=0
),
"nearest_groups": lambda: lib_iranges.nearest_groups(starts, ends, groups, starts, ends, groups, num_threads=0),
}


@pytest.mark.parametrize("name", CALLS)
def test_num_threads_zero_raises(name):
with pytest.raises(ValueError, match="num_threads must be >= 1"):
CALLS[name]()
Loading