Skip to content

implement Axis.chunks & LArray.chunks #505

Open

Description

@gdementen

this would generalize/deprecate Axis.by

Axis.split(chunks=10, length=None, step=None, before=None, after=None, indices=None)
LArray.split(chunks=10, length=None, step=None, before=None, after=None, indices=None, axis=-1)
>>> age = Axis("0..99", "age")
>>> age.split(5)
(age.i[0:20], age.i[20:40], age.i[40:60], age.i[60:80], age.i[80:100])
>>> age.split(length=20)
(age.i[0:20], age.i[20:40], age.i[40:60], age.i[60:80], age.i[80:100])
>>> age.split(length=10, step=20)
(age.i[0:10], age.i[20:30], age.i[40:50], age.i[60:70], age.i[80:90])
>>> age.split(before=50)
(age.i[0:50], age.i[50:100])
>>> age.split(before=[10, 15, 20, 40])
(age.i[0:10], age.i[10:15], age.i[15:20], age.i[20:40], age.i[40:100])
>>> age.split(indices=50)
(age.i[0:50], age.i[50:100])
>>> age.split(indices=[10, 15, 20, 40])
(age.i[0:10], age.i[10:15], age.i[15:20], age.i[20:40], age.i[40:100])

>>> arr = ndrange(age) * 0.25
>>> arr.split(10, axis='age')
[age    0     1    2     3    4     5    6     7    8     9
     0.0  0.25  0.5  0.75  1.0  1.25  1.5  1.75  2.0  2.25,
age   10    11   12    13   14    15   16    17   18    19
     2.5  2.75  3.0  3.25  3.5  3.75  4.0  4.25  4.5  4.75,
age   20    21   22    23   24    25   26    27   28    29
     5.0  5.25  5.5  5.75  6.0  6.25  6.5  6.75  7.0  7.25,
age   30    31   32    33   34    35   36    37   38    39
     7.5  7.75  8.0  8.25  8.5  8.75  9.0  9.25  9.5  9.75,
age    40     41    42     43    44     45    46     47    48     49
     10.0  10.25  10.5  10.75  11.0  11.25  11.5  11.75  12.0  12.25,
age    50     51    52     53    54     55    56     57    58     59
     12.5  12.75  13.0  13.25  13.5  13.75  14.0  14.25  14.5  14.75,
age    60     61    62     63    64     65    66     67    68     69
     15.0  15.25  15.5  15.75  16.0  16.25  16.5  16.75  17.0  17.25,
age    70     71    72     73    74     75    76     77    78     79
     17.5  17.75  18.0  18.25  18.5  18.75  19.0  19.25  19.5  19.75,
age    80     81    82     83    84     85    86     87    88     89
     20.0  20.25  20.5  20.75  21.0  21.25  21.5  21.75  22.0  22.25,
age    90     91    92     93    94     95    96     97    98     99
     22.5  22.75  23.0  23.25  23.5  23.75  24.0  24.25  24.5  24.75]
>>> arr1d.split(10)
idem

FWIW: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.split.html

Activity

  1. gdementen commented on Oct 27, 2017

    @gdementen
    ContributorAuthor

    Oops, Axis.split is already taken for splitting labels. What do we do?

    • rename current Axis.split to Axis.split_labels or Axis.str_split or ...?
    • keep current Axis.split and name this new method .groups or .chunks?
  2. alixdamman commented on Oct 27, 2017

    @alixdamman
    Collaborator

    Certainly not renaming Axis.split. There is enough FutureWarning for now.
    Could you add outputs in your example from your first comment, please?
    I don't see exactly what you want to do.

  3. gdementen commented on Oct 27, 2017

    @gdementen
    ContributorAuthor

    I doubt anybody is using Axis.split yet :)

  4. alixdamman commented on Oct 27, 2017

    @alixdamman
    Collaborator

    But LArray.split yes and we should stay consistent as much as possible.

  5. alixdamman commented on Oct 27, 2017

    @alixdamman
    Collaborator

    Take Axis.chunks

  6. gdementen commented on Oct 27, 2017

    @gdementen
    ContributorAuthor

    FWIW, LArray.split does not exist (yet). LArray.split_axes does.

  7. alixdamman commented on Oct 27, 2017

    @alixdamman
    Collaborator

    Indeed sorry. But my mistake make me think that split is too close to split_axes and may be confusing.

  8. alixdamman commented on Oct 27, 2017

    @alixdamman
    Collaborator

    What are the expected outputs?

  9. gdementen commented on Oct 27, 2017

    @gdementen
    ContributorAuthor

    I updated the description

  10. alixdamman commented on Oct 27, 2017

    @alixdamman
    Collaborator

    Thanks

  11. changed the title [-]implement Axis.split & LArray.split[/-] [+]implement Axis.chunks & LArray.chunks[/+] on Nov 14, 2017
  12. added this to the 0.29 milestone on Dec 18, 2017
  13. modified the milestones: 0.29, 0.30 on Mar 16, 2018
  14. modified the milestones: 0.30, 0.31 on Jul 18, 2018
  15. removed this from the 0.31 milestone on Aug 1, 2019
  16. added this to the nice_to_have milestone on Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions