Skip to content
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

Introduce wrapper eager_function #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
astensor manage non tensor arguments and behave like identity if the …
…argument is not a tensor
  • Loading branch information
eserie committed Apr 25, 2021
commit 81bba4d5ccdcbd485dc71d57d393bb93880fa7d7
5 changes: 3 additions & 2 deletions eagerpy/astensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def astensor(x: NativeTensor) -> Tensor: # type: ignore
...


def astensor(x: Union[NativeTensor, Tensor]) -> Tensor: # type: ignore
def astensor(x: Union[NativeTensor, Tensor, Any]) -> Union[Tensor, Any]: # type: ignore
if isinstance(x, Tensor):
return x
# we use the module name instead of isinstance
Expand All @@ -64,7 +64,8 @@ def astensor(x: Union[NativeTensor, Tensor]) -> Tensor: # type: ignore
return JAXTensor(x)
if name == "numpy" and isinstance(x, m[name].ndarray): # type: ignore
return NumPyTensor(x)
raise ValueError(f"Unknown type: {type(x)}")
return x
# raise ValueError(f"Unknown type: {type(x)}")


def astensors(*xs: Union[NativeTensor, Tensor]) -> Tuple[Tensor, ...]: # type: ignore
Expand Down