Esempio n. 1
0
    def test_split(self):
        data = list(range(50))
        chu = iterables.split(data, 10)
        self.assertEqual(len(chu), 10)
        unchu = iterables.flatten(chu)
        self.assertEqual(data, unchu)

        chu = iterables.split(data, 1)
        self.assertEqual(len(chu), 1)
        unchu = iterables.flatten(chu)
        self.assertEqual(data, unchu)

        chu = iterables.split(data, 60, padWith=[None])
        self.assertEqual(len(chu), 60)
        unchu = iterables.flatten(chu)
        self.assertEqual(len(unchu), 60)

        chu = iterables.split(data, 60, padWith=[None])
        self.assertEqual(len(chu), 60)

        data = [0]
        chu = iterables.split(data, 1)
        unchu = iterables.flatten(chu)
        self.assertEqual(unchu, data)
Esempio n. 2
0
def createFormattedStrWithDelimiter(
    dataList, maxNumberOfValuesBeforeDelimiter=9, delimiter="\n"
):
    r"""
    Return a formatted string with delimiters from a list of data.

    Parameters
    ----------
    dataList : list
        List of data that will be formatted into a string
    maxNumberOfValuesBeforeDelimiter : int
        maximum number of values to have before the delimiter is added
    delimiter : str
        A delimiter on the formatted string (default: "\n")

    Notes
    -----
    As an example::

        >>> createFormattedStrWithDelimiter(['hello', 'world', '1', '2', '3', '4'],
        ...     maxNumberOfValuesBeforeDelimiter=3, delimiter = '\n')
        "hello, world, 1, \n2, 3, \n4, 5\n"

    """
    formattedString = ""
    if not dataList:
        return formattedString

    if not maxNumberOfValuesBeforeDelimiter:
        numRows = 1
    else:
        numRows = (
            int(
                math.ceil(
                    float(len(dataList)) / float(maxNumberOfValuesBeforeDelimiter)
                )
            )
            or 1
        )

    # Create a list of string delimiters to use when joining the strings
    commaList = ["," for d in dataList]
    commaList[-1] = ""
    dataList = [str(d) + commaList[i] for i, d in enumerate(dataList)]
    for splitList in iterables.split(dataList, n=numRows, padWith=""):
        formattedString += " ".join(splitList) + delimiter
    return formattedString
Esempio n. 3
0
    def getPreferredProduct(self, libraryNucNames):
        """
        Get the index of the most preferred transmutation product/decay daughter.

        Notes
        -----
        The ARMI burn chain is not a full burn chain. It short circuits shorter half-lives, and uses lumped nuclides
        as catch-all objects for things that just sit around. Consequently, the "preferred" product/daughter
        may not be actual physical product/daughter.
        """
        for product in self.productNuclides:
            if product in libraryNucNames:
                return product
        groupedNames = iterables.split(libraryNucNames,
                                       max(1, int(len(libraryNucNames) / 10)))
        msg = ("Could not find suitable product/daughter for {}.\n"
               "The available options were:\n  {}".format(
                   self,
                   ",\n  ".join(", ".join(chunk) for chunk in groupedNames)))
        raise KeyError(msg)
Esempio n. 4
0
def _scatterList(lst):
    if armi.MPI_RANK == 0:
        chunked = iterables.split(lst, armi.MPI_SIZE)
    else:
        chunked = None
    return armi.MPI_COMM.scatter(chunked, root=0)