diff --git a/include/typings/array2d.pyi b/include/typings/array2d.pyi index b371b278..0470c2a9 100644 --- a/include/typings/array2d.pyi +++ b/include/typings/array2d.pyi @@ -70,11 +70,5 @@ class array2d(Generic[T]): Returns a tuple `(x, y, width, height)` or raise `ValueError` if the value is not found. """ - def find_one(self, condition: Callable[[T], bool]) -> vec2i: - """Finds the position of the first cell that satisfies the condition. - - Returns a `vec2i` or raise `ValueError` if no cell satisfies the condition. - """ - def convolve(self: array2d[int], kernel: 'array2d[int]', padding: int) -> 'array2d[int]': """Convolves the array with the given kernel.""" diff --git a/src/modules/array2d.c b/src/modules/array2d.c index 24e58362..90e4d3ee 100644 --- a/src/modules/array2d.c +++ b/src/modules/array2d.c @@ -568,28 +568,6 @@ static bool array2d__setitem__(int argc, py_Ref argv) { } } -// find_one(self, condition: Callable[[T], bool]) -> vec2i -static bool array2d_find_one(int argc, py_Ref argv) { - PY_CHECK_ARGC(2); - c11_array2d* self = py_touserdata(argv); - py_Ref condition = py_arg(1); - for(int j = 0; j < self->n_rows; j++) { - for(int i = 0; i < self->n_cols; i++) { - bool ok = py_call(condition, 1, py_array2d__get(self, i, j)); - if(!ok) return false; - if(!py_isbool(py_retval())) return TypeError("condition must return a bool"); - if(py_tobool(py_retval())) { - py_newvec2i(py_retval(), - (c11_vec2i){ - {i, j} - }); - return true; - } - } - } - return ValueError("condition not met"); -} - static bool _array2d_is_all_ints(c11_array2d* self) { for(int i = 0; i < self->numel; i++) { if(!py_isint(self->data + i)) return false; @@ -684,7 +662,6 @@ void pk__add_module_array2d() { py_bindmethod(array2d, "count", array2d_count); py_bindmethod(array2d, "find_bounding_rect", array2d_find_bounding_rect); py_bindmethod(array2d, "count_neighbors", array2d_count_neighbors); - py_bindmethod(array2d, "find_one", array2d_find_one); py_bindmethod(array2d, "convolve", array2d_convolve); } diff --git a/tests/90_array2d.py b/tests/90_array2d.py index 75a500f4..fd3fd835 100644 --- a/tests/90_array2d.py +++ b/tests/90_array2d.py @@ -96,16 +96,6 @@ assert x == d and x is not d x.copy_([1, 2, 3, 4, 5, 6, 7, 8]) assert x.tolist() == [[1, 2], [3, 4], [5, 6], [7, 8]] -# test find_one -a = array2d(3, 3, default=0) -a[1, 1] = 1 -assert a.find_one(lambda x: x == 1) == vec2i(1, 1) -try: - a.find_one(lambda x: x == 2) - exit(1) -except ValueError: - pass - # test alive_neighbors a = array2d[int](3, 3, default=0) a[1, 1] = 1