コード例 #1
0
 def test_tuple(self):
     indata = ((4, slice(1, 6, 3)), 3)
     testname = 'index_tuple({}, {})'.format(*indata)
     actual = index_tuple(*indata)
     expected = indata[0] + (slice(None), )
     print_test_message(testname,
                        indata=indata,
                        actual=actual,
                        expected=expected)
     self.assertEqual(actual, expected, '{} failed'.format(testname))
コード例 #2
0
ファイル: indexingTests.py プロジェクト: NCAR/PyConform
 def test_slice(self):
     indata = (slice(1, 6, 3), 3)
     testname = "index_tuple({}, {})".format(*indata)
     actual = index_tuple(*indata)
     expected = (indata[0], slice(None), slice(None))
     print_test_message(testname,
                        indata=indata,
                        actual=actual,
                        expected=expected)
     self.assertEqual(actual, expected, "{} failed".format(testname))
コード例 #3
0
    def __getitem__(self, index):
        """
        Compute and retrieve the data associated with this FlowNode operation
        """

        # Request the input information without pulling data
        inp_info = self.inputs[0][None]

        # Get the input data dimensions
        inp_dims = inp_info.dimensions

        # The input/output dimensions will be the same
        # OR should be contained in the input-to-output dimension map
        out_dims = tuple(self._i2omap.get(d, d) for d in inp_dims)

        # Compute the input index in terms of input dimensions
        if index is None:
            inp_index = None

        elif isinstance(index, dict):
            inp_index = dict(
                (self._o2imap.get(d, d), i) for d, i in index.iteritems())

        else:
            out_index = index_tuple(index, len(inp_dims))
            inp_index = dict((self._o2imap.get(d, d), i)
                             for d, i in zip(out_dims, out_index))

        # Return the mapped data
        idims_str = ','.join(inp_dims)
        odims_str = ','.join(out_dims)
        if inp_dims == out_dims:
            name = inp_info.name
        else:
            name = 'map({}, from=[{}], to=[{}])'.format(
                inp_info.name, idims_str, odims_str)
        return PhysArray(self.inputs[0][inp_index],
                         name=name,
                         dimensions=out_dims)