1
1
# SPDX-License-Identifier: MPL-2.0
2
2
from __future__ import annotations
3
3
4
- from functools import singledispatch
4
+ from functools import partial , singledispatch
5
5
from typing import TYPE_CHECKING , cast
6
6
7
7
import numpy as np
@@ -28,42 +28,46 @@ def to_dense_(
28
28
| types .CupySpMatrix ,
29
29
/ ,
30
30
* ,
31
- to_memory : bool = False ,
31
+ to_cpu_memory : bool = False ,
32
32
) -> NDArray [Any ] | types .CupyArray | types .DaskArray :
33
- del to_memory # it already is
33
+ del to_cpu_memory # it already is
34
34
return np .asarray (x )
35
35
36
36
37
37
@to_dense_ .register (types .spmatrix | types .sparray ) # type: ignore[call-overload,misc]
38
- def _to_dense_cs (x : types .spmatrix | types .sparray , / , * , to_memory : bool = False ) -> NDArray [Any ]:
38
+ def _to_dense_cs (
39
+ x : types .spmatrix | types .sparray , / , * , to_cpu_memory : bool = False
40
+ ) -> NDArray [Any ]:
39
41
from . import scipy
40
42
41
- del to_memory # it already is
43
+ del to_cpu_memory # it already is
42
44
return scipy .to_dense (x )
43
45
44
46
45
47
@to_dense_ .register (types .DaskArray )
46
48
def _to_dense_dask (
47
- x : types .DaskArray , / , * , to_memory : bool = False
49
+ x : types .DaskArray , / , * , to_cpu_memory : bool = False
48
50
) -> NDArray [Any ] | types .DaskArray :
49
51
from . import to_dense
50
52
51
- x = x .map_blocks (lambda x : to_dense ( x , to_memory = to_memory ))
52
- return x .compute () if to_memory else x # type: ignore[return-value]
53
+ x = x .map_blocks (partial ( to_dense , to_cpu_memory = to_cpu_memory ))
54
+ return x .compute () if to_cpu_memory else x # type: ignore[return-value]
53
55
54
56
55
57
@to_dense_ .register (types .CSDataset )
56
- def _to_dense_ooc (x : types .CSDataset , / , * , to_memory : bool = False ) -> NDArray [Any ]:
58
+ def _to_dense_ooc (x : types .CSDataset , / , * , to_cpu_memory : bool = False ) -> NDArray [Any ]:
57
59
from . import to_dense
58
60
59
- if not to_memory :
60
- msg = "to_memory must be True if x is an CS{R,C}Dataset"
61
+ if not to_cpu_memory :
62
+ msg = "to_cpu_memory must be True if x is an CS{R,C}Dataset"
61
63
raise ValueError (msg )
62
64
# TODO(flying-sheep): why is to_memory of type Any? # noqa: TD003
63
65
return to_dense (cast ("types.CSBase" , x .to_memory ()))
64
66
65
67
66
68
@to_dense_ .register (types .CupyArray | types .CupySpMatrix ) # type: ignore[call-overload,misc]
67
- def _to_dense_cupy (x : GpuArray , / , * , to_memory : bool = False ) -> NDArray [Any ] | types .CupyArray :
69
+ def _to_dense_cupy (
70
+ x : GpuArray , / , * , to_cpu_memory : bool = False
71
+ ) -> NDArray [Any ] | types .CupyArray :
68
72
x = x .toarray () if isinstance (x , types .CupySpMatrix ) else x
69
- return x .get () if to_memory else x
73
+ return x .get () if to_cpu_memory else x
0 commit comments