def __init__(self, ir: IR, type: HailType, indices: Indices = Indices(), aggregations: LinkedList = LinkedList(Aggregation)): self._ir: IR = ir self._type = type self._indices = indices self._aggregations = aggregations
def __init__(self, ast: AST, type: HailType, indices: Indices = Indices(), aggregations: LinkedList = LinkedList(Aggregation)): self._ast: AST = ast self._type = type self._indices = indices self._aggregations = aggregations
def __init__(self, x: ir.IR, type: HailType, indices: Indices = Indices(), aggregations: LinkedList = LinkedList(Aggregation)): self._ir: ir.IR = x self._type = type self._indices = indices self._aggregations = aggregations self._summary = None
def test_linked_list(self): ll = LinkedList(int) self.assertEqual(list(ll), []) if ll: self.fail('empty linked list had an implicit boolean value of True') ll2 = ll.push(5).push(2) self.assertEqual(list(ll2), [2, 5]) if not ll2: self.fail('populated linked list had an implicit boolean value of False') ll3 = ll.push(5, 2) self.assertEqual(list(ll2), list(ll3)) self.assertEqual(ll2, ll3) ll4 = ll.push(1) ll5 = ll4.push(2, 3) ll6 = ll4.push(4, 5) self.assertEqual(list(ll5), [3, 2, 1]) self.assertEqual(list(ll6), [5, 4, 1])
def unify_all(*exprs) -> Tuple[Indices, LinkedList]: if len(exprs) == 0: return Indices(), LinkedList(Aggregation) try: new_indices = Indices.unify(*[e._indices for e in exprs]) except ExpressionException: # source mismatch from collections import defaultdict sources = defaultdict(lambda: []) for e in exprs: from .expression_utils import get_refs for name, inds in get_refs(e, *[e for a in e._aggregations for e in a.exprs]).items(): sources[inds.source].append(str(name)) raise ExpressionException("Cannot combine expressions from different source objects." "\n Found fields from {n} objects:{fields}".format( n=len(sources), fields=''.join("\n {}: {}".format(src, fds) for src, fds in sources.items()) )) from None first, rest = exprs[0], exprs[1:] aggregations = first._aggregations for e in rest: aggregations = aggregations.push(*e._aggregations) return new_indices, aggregations