浏览代码

remove `indexed_apply_`

blueloveTH 1 年之前
父节点
当前提交
a07d2df278
共有 3 个文件被更改,包括 1 次插入17 次删除
  1. 0 1
      include/typings/array2d.pyi
  2. 0 10
      src/array2d.cpp
  3. 1 6
      tests/83_array2d.py

+ 0 - 1
include/typings/array2d.pyi

@@ -39,7 +39,6 @@ class array2d(Generic[T]):
 
     def fill_(self, value: T) -> None: ...
     def apply_(self, f: Callable[[T], T]) -> None: ...
-    def indexed_apply_(self, f: Callable[[int, int, T], T]) -> None: ...
     def copy_(self, other: 'array2d[T] | list[T]') -> None: ...
 
     # algorithms

+ 0 - 10
src/array2d.cpp

@@ -229,16 +229,6 @@ struct Array2d{
             return vm->None;
         });
 
-        vm->bind(type, "indexed_apply_(self, f)", [](VM* vm, ArgsView args){
-            Array2d& self = PK_OBJ_GET(Array2d, args[0]);
-            PyObject* f = args[1];
-            for(int i = 0; i < self.numel; i++){
-                std::div_t res = std::div(i, self.n_cols);
-                self.data[i] = vm->call(f, VAR(res.rem), VAR(res.quot), self.data[i]);
-            }
-            return vm->None;
-        });
-
         vm->bind(type, "copy_(self, other)", [](VM* vm, ArgsView args){
             Array2d& self = PK_OBJ_GET(Array2d, args[0]);
             if(is_type(args[1], VM::tp_list)){

+ 1 - 6
tests/83_array2d.py

@@ -167,12 +167,7 @@ try:
 except TypeError:
     pass
 
-a = array2d(3, 4)
-a.indexed_apply_(lambda x, y, val: x+y)
-assert a[0, 0] == 0
-assert a[1, 2] == 3
-assert a[2, 0] == 2
-
+a = array2d(3, 4, default=1)
 for i, j, x in a:
     assert a[i, j] == x