-
Notifications
You must be signed in to change notification settings - Fork 434
Support Numpy Duck Arrays #74
Comments
I haven't tried it, but this should be doable by registering the existing numpy handler with the respective types. If they are ndarray-like, this should be sufficient. For example, modifying https://github.com/google/tangent/blob/master/tangent/utils.py#L633 to include
Something similar would need to be done for |
Would it be possible to (for example) do some metaprogramming and detect |
Yeah, so many projects have plugin mechanisms like this. This results in an I might suggest that you do a check like the following: def is_numpy_like(x):
return hasattr(x, 'shape') and hasattr(x, 'dtype') and hasattr(x, '__array_ufunc__')
Though this check will likely evolve in the future (and hopefully be upstreamed into numpy). |
I might be wrong here, but this project seems like it relies heavily on type checks. I'll see if I can check the code of the |
For well known types like The interaction matrix was designed as a more generic mechanism for cases when such a protocol does not exist. It's used for example with tensorflow arrays which are not array-like. It has constant access time and is cleaner than the alternative - calling |
Yes, and I think that this is the correct choice for these sorts of situations. My hope is that all numpy-like arrays can be a single row in this matrix. To be clear, when I'm talking about a matrix of interactions I'm not talking about a matrix like what is in tangent with axes of ndarray-container and operation, I'm talking about a higher level matrix that has axes projects-that-implement-ndarray-containers and projects-that-consume-ndarray-containers. In that matrix tangent is one column. |
Tangent provides source-to-source automatic differentiation of functions containing Numpy syntax
It currently has a pluggable mechanism to support both numpy arrays and tensorflow arrays explicitly. However, it would be nice if it also supported other numpy-like arrays using duck typing. Currently this appears not to be the case.
It would be convenient if tangent could be used for other objects that "quack like a numpy.ndarray" for which there are a few today (numpy, sparse, dask.array, cupy).
cc @njsmith @shoyer @ericmjl @hameerabbasi
The text was updated successfully, but these errors were encountered: