mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
remove indexed_apply_
This commit is contained in:
parent
a6c4b33e8b
commit
a07d2df278
@ -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
|
||||
|
@ -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)){
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user