Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tensorflow: Add Tensor.__array__ method. #14342

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EthanAtLL
Copy link

This PR adds the Tensor.__array__ method to support code like:

from typing import Protocol
import numpy as np
import tensorflow as tf

class ArrayLike(Protocol):
    def __array__(self) -> np.ndarray: ...
def convert(x: ArrayLike):
    return np.array(x)
def f(t: tf.Tensor):
    return convert(t) # originally errs with "__array__" is not present

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant