remove indexed_apply_

This commit is contained in:
blueloveTH 2024-04-28 21:01:07 +08:00
parent a6c4b33e8b
commit a07d2df278
3 changed files with 1 additions and 17 deletions

View File

@ -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

View File

@ -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)){

View File

@ -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