Skip to content

Add unsorted segment ops for prod, min, mean, sqrt_n #7389

Closed

Description

@PhilJd

As requested by @girving in #7362 I'll file a separate issue.

The sorted segment reduction ops feature prod, min, mean, sqrt_n while the unsorted ops don't include those. So I suggest to add the following functions:

tf.unsorted_segment_prod(data, segment_ids, num_segments, name=None)
tf.unsorted_segment_min(data, segment_ids, num_segments, name=None)
tf.unsorted_segment_mean(data, segment_ids, num_segments, name=None)
tf.unsorted_segment_sqrt_n(data, segment_ids, num_segments, name=None

If you mark this as contributions welcome, I'd start working on this.

Activity

  1. added
    stat:contribution welcome
    type:feature
    on Feb 9, 2017
  2. girving commented on Feb 9, 2017

    @girving
    Contributor

    Thank you for splitting this out!

  3. girving commented on Feb 9, 2017

    @girving
    Contributor

    I'd recommend spelling it num_segments, though.

  4. PhilJd commented on Feb 9, 2017

    @PhilJd
    ContributorAuthor

    Sorry, of course! Stupid typo, I'll change the issue description.

  5. lidalei commented on Apr 20, 2017

    @lidalei

    I am implementing batch k-means. In the update phase, new centers have to be computed according to the points re-assignments. It would make thing easier if there is unsorted_segment_mean.

  6. PhilJd commented on Apr 20, 2017

    @PhilJd
    ContributorAuthor

    Hi,
    sorry, I've been rather busy in the last few weeks. I'm 95% done implementing the CPU Kernels, with a bug remaining. Thanks for reminding me, I'll have a look at it tomorrow!
    Cheers,
    Phil

  7. PhilJd commented on Apr 20, 2017

    @PhilJd
    ContributorAuthor

    For now you could just compute the mean with existing tensorflow functions, e.g.

    import tensorflow as tf
    x = tf.constant([1.0, 2.0, 3.0, 4.0])
    ids = tf.constant([0, 1, 0, 1])
    ones = tf.ones_like(x)
    count = tf.unsorted_segment_sum(ones, ids, 2)
    sums = tf.unsorted_segment_sum(x, ids, 2)
    mean = tf.divide(sums, count)
    s = tf.Session()
    s.run(mean)
    
    

    The main advantage is that this runs on GPU.

  8. lidalei commented on Apr 20, 2017

    @lidalei

    This is great! Thanks a lot!

  9. itsmeolivia commented on Jun 16, 2017

    @itsmeolivia
    Contributor

    Automatically closing due to lack of recent activity. Since this issue is old at this point, please reopen the issue if it still occurs when tried with the latest version of Tensorflow. Thank you.

  10. added 3 commits that reference this issue on Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:contribution welcometype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions