Esempio n. 1
0
 def checkSubtoindResult(siParam):
     data = siParam.subscripts
     converter = _subToIndConverter(dims=siParam.dims, order=siParam.order, isOneBased=siParam.onebased)
     results = map(lambda x: converter(x), data)
     # check results individually to highlight specific failures
     for res, expected, subscript in zip(results, siParam.indices, siParam.subscripts):
         assert_equals(expected, res, 'Got index %d instead of %d for subscript:%s, dims:%s' %
                       (res, expected, str(subscript), str(siParam.dims)))
Esempio n. 2
0
    def subToInd(self, order='F', isOneBased=True):
        """
        Convert subscript index keys to linear index keys

        Parameters
        ----------
        order : str, 'C' or 'F', default = 'F'
            Specifies row-major or column-major array indexing. See numpy.ravel_multi_index.

        isOneBased : boolean, default = True
            True if subscript indices start at 1, False if they start at 0
        """
        from thunder.rdds.keys import _subToIndConverter

        converter = _subToIndConverter(self.dims.count, order=order, isOneBased=isOneBased)
        rdd = self.rdd.map(lambda (k, v): (converter(k), v))
        return self._constructor(rdd, index=self._index).__finalize__(self)
Esempio n. 3
0
    def subToInd(self, order='F', isOneBased=True):
        """
        Convert subscript index keys to linear index keys

        Parameters
        ----------
        order : str, 'C' or 'F', default = 'F'
            Specifies row-major or column-major array indexing. See numpy.ravel_multi_index.

        isOneBased : boolean, default = True
            True if subscript indices start at 1, False if they start at 0
        """
        from thunder.rdds.keys import _subToIndConverter

        converter = _subToIndConverter(self.dims.count,
                                       order=order,
                                       isOneBased=isOneBased)
        rdd = self.rdd.map(lambda (k, v): (converter(k), v))
        return self._constructor(rdd, index=self._index).__finalize__(self)
Esempio n. 4
0
    def setSource(self, series):
        """Readies the BlockingStrategy to operate over the passed Series.

        This implementation will set .nimages from the length of the passed object's .index attribute.

        No return value.
        """
        super(SeriesBlockingStrategy, self).setSource(series)
        from thunder.rdds.keys import _subToIndConverter
        # as we are currently doing in Series.saveAsBinarySeries, here we assume that len(series.index) is
        # equal to the length of a single record value. If not, we will probably end up in trouble downstream.
        self._nimages = len(series.index)
        self.__validateSplitsPerDimForSeries()
        slices = SimpleBlockingStrategy.generateSlicesFromSplits(self.splitsPerDim, self.dims)
        # flip slice ordering so that z index increments first
        reversedSlicesIter = itertools.product(*(slices[::-1]))
        self._slicesProduct = [sl[::-1] for sl in reversedSlicesIter]
        self._subToIndFcn = _subToIndConverter(self.dims, order='F', isOneBased=False)
        self._linIndices = self.generateMaxLinearIndicesForBlocksFromSlices()
Esempio n. 5
0
 def test_sub_to_ind_array(self):
     subs = [(1, 1, 1), (2, 1, 1), (1, 2, 1), (2, 2, 1), (1, 3, 1), (2, 3, 1),
             (1, 1, 2), (2, 1, 2), (1, 2, 2), (2, 2, 2), (1, 3, 2), (2, 3, 2)]
     converter = _subToIndConverter(dims=[2, 3, 2])
     inds = map(lambda x: converter(x), subs)
     assert(allclose(inds, array(range(1, 13))))