[tf-numpy] add experimental __array_module__ method
__array_module__ is an experimental protocol for "duck array" compatibility that for indicating how to find a "numpy compatible" module. The hope is to make it easier to write generic code that works across a range of array libraries. A full example, which should work equally work for TF-NumPy as for JAX, can be found at https://github.com/google/jax/pull/4076. More examples, and motivation for this protocol can be found at https://numpy.org/neps/nep-0037-array-module.html. This design has not yet been finalized in NumPy, so at present it requires using the experimental numpy_dispatch module: https://github.com/seberg/numpy-dispatch. Unlike NumPy's __array_ufunc__ and __array_function__ protocols, __array_module__ by design has no backwards compatibility consequences. The protocol only controls the behavior of numpy_dispatch.get_array_module() or numpy.get_array_module() -- it does not change any existing NumPy functions. PiperOrigin-RevId: 328181308 Change-Id: I98b648a59709ed3bc295aaf97f471a1ff7ae1f05
Showing
想要评论请 注册 或 登录