Skip to content

Consider supporting multiple axes in reduce #7915

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

Closed
NeilGirdhar opened this issue Aug 7, 2016 · 6 comments
Closed

Consider supporting multiple axes in reduce #7915

NeilGirdhar opened this issue Aug 7, 2016 · 6 comments

Comments

@NeilGirdhar
Copy link
Contributor

Tensorflow supports multiple reduction axes. Numpy does not. Is this a useful feature to have?

In [30]: import tensorflow as tf

In [31]: sess = tf.Session()
I tensorflow/core/common_runtime/gpu/gpu_device.cc:839] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GT 750M, pci bus id: 0000:01:00.0)

In [32]: a = np.arange(24).reshape((2, 3, 4))

In [33]: ta = tf.constant(a)

In [34]: sess.run(tf.reduce_max(a, reduction_indices=0))
Out[34]:
array([[12, 13, 14, 15],
       [16, 17, 18, 19],
       [20, 21, 22, 23]])

In [35]: sess.run(tf.reduce_max(a, reduction_indices=[0, 2]))
Out[35]: array([15, 19, 23])

In [36]: np.maximum.reduce(a, axis=0)
Out[36]:
array([[12, 13, 14, 15],
       [16, 17, 18, 19],
       [20, 21, 22, 23]])

In [37]: np.maximum.reduce(a, axis=[0, 2])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-b4f45c212008> in <module>()
----> 1 np.maximum.reduce(a, axis=[0, 2])

TypeError: an integer is required
@shoyer
Copy link
Member

shoyer commented Aug 7, 2016

NumPy does support multiple axes in reduce. You just need to specify them with a tuple, not a list:

In [30]: np.maximum.reduce(a, axis=(0, 2))
Out[30]: array([15, 19, 23])

@NeilGirdhar
Copy link
Contributor Author

Oh, sorry! What's the argument for disallowing other collections?

@NeilGirdhar
Copy link
Contributor Author

NeilGirdhar commented Aug 7, 2016

Also, regardless, the error message ("an integer is required") should probably be fixed.

@shoyer
Copy link
Member

shoyer commented Aug 7, 2016

I don't think there's a principled reasons for disallowing other sequences for the axis argument. The logic for parsing the axis argument is written in C, though, so duck typing may be a little trickier (in any case it was not done).

#7916 will fix the error message.

@NeilGirdhar
Copy link
Contributor Author

Got it, thanks.

@charris
Copy link
Member

charris commented Aug 7, 2016

@shoyer I think there is a desire to keep things simple and consistent. The topic could be revisited on the mailing list if we want to make a formal rule. Indeed, maybe we should have some formal rules about the common keywords.

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

No branches or pull requests

3 participants