Skip to content

EagerJAXArrayContext: return mutable numpy array in to_numpy #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3117,30 +3117,6 @@
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 53,
"endColumn": 62,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 23,
"endColumn": 46,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 33,
"endColumn": 36,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
Expand Down Expand Up @@ -3639,14 +3615,6 @@
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 12,
"endColumn": 21,
"lineCount": 1
}
},
{
"code": "reportUnknownParameterType",
"range": {
Expand All @@ -3663,14 +3631,6 @@
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 19,
"endColumn": 38,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
Expand Down Expand Up @@ -5337,14 +5297,6 @@
"lineCount": 1
}
},
{
"code": "reportArgumentType",
"range": {
"startColumn": 46,
"endColumn": 51,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
Expand Down
6 changes: 3 additions & 3 deletions arraycontext/impl/jax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from pytools.tag import ToTagSetConvertible

from arraycontext.container.traversal import rec_map_array_container, with_array_context
from arraycontext.context import Array, ArrayContext, ArrayOrContainer, ScalarLike
from arraycontext.context import ArrayContext, ArrayOrContainer, ScalarLike


class EagerJAXArrayContext(ArrayContext):
Expand Down Expand Up @@ -64,7 +64,7 @@ def _get_fake_numpy_namespace(self):
return EagerJAXFakeNumpyNamespace(self)

def _rec_map_container(
self, func: Callable[[Array], Array], array: ArrayOrContainer,
self, func: Callable[[object], object], array: ArrayOrContainer,
allowed_types: tuple[type, ...] | None = None, *,
default_scalar: ScalarLike | None = None,
strict: bool = False) -> ArrayOrContainer:
Expand Down Expand Up @@ -101,7 +101,7 @@ def _from_numpy(ary):
def to_numpy(self, array):
def _to_numpy(ary):
import jax
return jax.device_get(ary)
return np.copy(jax.device_get(ary)) # pyright: ignore[reportAny]

return with_array_context(
self._rec_map_container(_to_numpy, array),
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/impl/jax/fake_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def rec_equal(x, y):
def sum(self, a, axis=None, dtype=None):
return rec_map_reduce_array_container(
sum,
partial(jnp.sum, axis=axis, dtype=dtype),
partial(jnp.sum, axis=axis, dtype=dtype), # pyright: ignore[reportArgumentType]
a)

def amin(self, a, axis=None):
Expand Down
Loading