Skip to content

Commit

Permalink
Rename function prepend to append
Browse files Browse the repository at this point in the history
and swap the arguments, for consistency with `Mapping.then`
  • Loading branch information
r-owen committed Jun 1, 2017
1 parent 8ae4b76 commit 86c21c8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
8 changes: 3 additions & 5 deletions include/astshim/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ namespace ast {
* original FrameSets (in particular, reassignments of their base or current
* frames) shall not affect it.
*
* @param second, first the FrameSets to concatenate. The operations are given
* in right-to-left order for consistency with, e.g.,
* Mapping::of.
* @param first, second the FrameSets to concatenate.
* @return a pointer to a combined FrameSet as described above
*
* Example: if `first` has 3 frames and `second `has 4, then the result shall
* contain 7 frames, of which frames 1-3 are the same as frames 1-3 of
* `first`, in order, and merged frames `4-7` are the same as frames
* `first`, in order, and frames 4-7 are the same as frames
* 1-4 of `second`, in order.
*/
std::shared_ptr<FrameSet> prepend(FrameSet const& second, FrameSet const& first);
std::shared_ptr<FrameSet> append(FrameSet const& first, FrameSet const& second);

} // namespace ast

Expand Down
2 changes: 1 addition & 1 deletion python/astshim/functional.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PYBIND11_PLUGIN(functional) {

py::module::import("astshim.frameSet");

mod.def("prepend", &prepend, "second"_a, "first"_a);
mod.def("append", &append, "first"_a, "second"_a);

return mod.ptr();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functional.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace ast {

std::shared_ptr<FrameSet> prepend(FrameSet const& second, FrameSet const& first) {
std::shared_ptr<FrameSet> append(FrameSet const& first, FrameSet const& second) {
std::shared_ptr<FrameSet> const merged = first.copy();
std::shared_ptr<FrameSet> const newFrames = second.copy();

Expand Down
24 changes: 12 additions & 12 deletions tests/test_prepend.py → tests/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import unittest
from numpy.testing import assert_allclose

from astshim import Frame, SkyFrame, UnitMap, FrameSet, prepend
from astshim import Frame, SkyFrame, UnitMap, FrameSet, append
from astshim.test import makeForwardPolyMap, makeTwoWayPolyMap


class TestFrameSetPrepend(unittest.TestCase):
class TestFrameSetAppend(unittest.TestCase):

def makeFrameSet(self, nIn, nOut):
"""Create a FrameSet with the specified dimensions.
Expand Down Expand Up @@ -41,16 +41,16 @@ def makeFrameSet(self, nIn, nOut):
assert frameSet.getFrame(4).ident == "fork"
return frameSet

def test_PrependEffect(self):
def test_AppendEffect(self):
"""Check that a concatenated FrameSet transforms correctly.
"""
set1 = self.makeFrameSet(2, 3)
set2 = self.makeFrameSet(3, 1)
set12 = prepend(set2, set1)
set12 = append(set1, set2)

# Can't match 1D output to 2D input
with self.assertRaises(RuntimeError):
prepend(set1, set2)
append(set2, set1)

x = [1.2, 3.4]
y_merged = set12.tranForward(x)
Expand All @@ -68,15 +68,15 @@ def test_PrependEffect(self):
self.assertEqual(set2.base, 1)
self.assertEqual(set2.current, 3)

def test_PrependFrames(self):
def test_AppendFrames(self):
"""Check that a concatenated FrameSet preserves all Frames.
"""
set1 = self.makeFrameSet(1, 3)
# AST docs say FrameSets always have contiguously numbered frames,
# but let's make sure
set1.removeFrame(2)
set2 = self.makeFrameSet(3, 2)
set12 = prepend(set2, set1)
set12 = append(set1, set2)

self.assertEquals(set1.nFrame + set2.nFrame,
set12.nFrame)
Expand All @@ -100,13 +100,13 @@ def test_PrependFrames(self):
else:
self.assertFalse(offset + i == set12.current)

def test_PrependIndependent(self):
def test_AppendIndependent(self):
"""Check that a concatenated FrameSet is not affected by changes
to its constituents.
"""
set1 = self.makeFrameSet(3, 3)
set2 = self.makeFrameSet(3, 3)
set12 = prepend(set2, set1)
set12 = append(set1, set2)

nTotal = set12.nFrame
x = [1.2, 3.4, 5.6]
Expand All @@ -122,14 +122,14 @@ def test_PrependIndependent(self):
self.assertEquals(set12.nFrame, nTotal)
self.assertEquals(set12.tranForward(x), y)

def test_PrependMismatch(self):
"""Check that prepend behaves as expected when joining non-identical frames.
def test_AppendMismatch(self):
"""Check that append behaves as expected when joining non-identical frames.
"""
set1 = self.makeFrameSet(3, 2)
set2 = self.makeFrameSet(2, 3)
set1.addFrame(FrameSet.CURRENT, makeForwardPolyMap(2, 2),
SkyFrame("Ident=sky"))
set12 = prepend(set2, set1)
set12 = append(set1, set2)

x = [1.2, 3.4, 5.6]
y_merged = set12.tranForward(x)
Expand Down

0 comments on commit 86c21c8

Please sign in to comment.