Skip to content

ENH: alignaxis function added #44

Merged
merged 7 commits into from Feb 7, 2012

3 participants

@stroxler
stroxler commented Feb 6, 2012

Closes #19 (sort of)

Note: I cannot find the problem, but there is a little style issue in the doc for align, align_raw, and align_axis. The html output has a colon out of place where PARAMETERS are. The isaligned() function's doc looks fine, but I cannot find any difference in the formatting, so I'm not sure.

@kwgoodman kwgoodman commented on an outdated diff Feb 7, 2012
@@ -375,6 +375,69 @@ def align_raw(lar1, lar2, join='inner', cast=True):
return x1, x2, label, x1isview, x2isview
+def align_axis(lars, axis=0, join='inner', flag=False):
+ """
+ Align many larrys along potentially different axes.
+
+ Parameters
+ ----------
+ lars : array_like
+ A collection (list, tuple, set, array, etc.) of larrys to align.
+ axis : {int, array_like}, optional
+ An integer indicating which axis along which to align the larrys in
+ `lars`, or a sequence of integers of the same length as `lars`
+ indicating which axis to use for each entry in `lars`.
+ join : {'inner', 'outer', 'left', 'right'}
+ If inner, then labels present in every larry will be kept. If 'outer',
@kwgoodman
Owner
kwgoodman added a note Feb 7, 2012

inner --> 'inner'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@kwgoodman kwgoodman commented on an outdated diff Feb 7, 2012
+ indicating which axis to use for each entry in `lars`.
+ join : {'inner', 'outer', 'left', 'right'}
+ If inner, then labels present in every larry will be kept. If 'outer',
+ all labels appearing in any array are kept, and additional entries are
+ added to larrys containing fewer labels. See la.morph() for rules on
+ how this is done. If 'right' or 'left' then the labels of the output
+ will match those of either the first or last entry of `lars`,
+ respectively
+
+ Returns
+ -------
+ (lar1, lar2, ...) : tuple
+ Tuple of larrys, one corresponding to each entry of lars. None of the
+ output refer to input, and the labels of the output do not refer to one
+ another.
+
@kwgoodman
Owner
kwgoodman added a note Feb 7, 2012

This is a nice function. A couple of examples would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@kwgoodman kwgoodman commented on an outdated diff Feb 7, 2012
+ respectively
+
+ Returns
+ -------
+ (lar1, lar2, ...) : tuple
+ Tuple of larrys, one corresponding to each entry of lars. None of the
+ output refer to input, and the labels of the output do not refer to one
+ another.
+
+ """
+ # input checks and preprocessing
+ nlar = len(lars)
+ if isinstance(axis, int):
+ axis = np.repeat(axis, nlar)
+ if isinstance(axis, list) or isinstance(axis, tuple):
+ axis = np.array(axis)
@kwgoodman
Owner
kwgoodman added a note Feb 7, 2012

Why make axis into an array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@kwgoodman kwgoodman commented on an outdated diff Feb 7, 2012
+ raise ValueError("Value of `join` not recognized.")
+ # alignment
+ if join == 'left':
+ label = lars[0].label[axis[0]]
+ elif join == 'right':
+ label = lars[-1].label[axis[-1]]
+ else:
+ labels = [set(lar.label[axis[j]]) for j, lar in enumerate(lars)]
+ label = labels[0]
+ if join == 'inner':
+ for new_label in labels[1:]:
+ label &= new_label
+ elif join == 'outer':
+ for new_label in labels[1:]:
+ label |= new_label
+ if join in ('inner', 'outer'):
@kwgoodman
Owner
kwgoodman added a note Feb 7, 2012

Is this 'if statement' needed? Can

label = list(label); label.sort()

be put in the else above? Also can you put the two statements on two different lines instead of using ';'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@kwgoodman
Owner

This is a very handy function!

Can you update the unit test count in the readme? And add an entry in RELEASE.rst?

@kwgoodman kwgoodman commented on the diff Feb 7, 2012
la/flarry.py
@@ -375,6 +375,69 @@ def align_raw(lar1, lar2, join='inner', cast=True):
return x1, x2, label, x1isview, x2isview
+def align_axis(lars, axis=0, join='inner', flag=False):
+ """
+ Align many larrys along potentially different axes.
+
+ Parameters
+ ----------
+ lars : array_like
+ A collection (list, tuple, set, array, etc.) of larrys to align.
+ axis : {int, array_like}, optional
+ An integer indicating which axis along which to align the larrys in
+ `lars`, or a sequence of integers of the same length as `lars`
+ indicating which axis to use for each entry in `lars`.
+ join : {'inner', 'outer', 'left', 'right'}
@kwgoodman
Owner
kwgoodman added a note Feb 7, 2012

", optional"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@kwgoodman kwgoodman merged commit 5f7027a into kwgoodman:master Feb 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.