takes parameter vector, constructs pardict, returns sum of lnlikes of non-leaf nodes
491239
def lnlike(self, p, use_cache=True):
        
        if use_cache and self._cache_key is not None and np.all(p==self._cache_key):
            return self._cache_val
        self._cache_key = p

        pardict = self.p2pardict(p)

        # lnlike from photometry
        lnl = 0
        for n in self:
            if n is not self:
                lnl += n.lnlike(pardict, use_cache=use_cache)
            if not np.isfinite(lnl):
                self._cache_val = -np.inf
                return -np.inf

        # lnlike from spectroscopy
        for l in self.spectroscopy:
            for prop,(val,err) in self.spectroscopy[l].items():
                mod = self.get_leaf(l).evaluate(pardict[l], prop)
                lnl += -0.5*(val - mod)**2/err**2
            if not np.isfinite(lnl):
                self._cache_val = -np.inf
                return -np.inf

        # enforce limits
        for l in self.limits:
            for prop,(vmin,vmax) in self.limits[l].items():
                mod = self.get_leaf(l).evaluate(pardict[l], prop)
                if mod < vmin or mod > vmax or not np.isfinite(mod):
                    self._cache_val = -np.inf
                    return -np.inf

        # lnlike from parallax
        for s,(val,err) in self.parallax.items():
            dist = pardict['{}_0'.format(s)][3]
            mod = 1./dist * 1000.
            lnl += -0.5*(val-mod)**2/err**2

        if not np.isfinite(lnl):
            self._cache_val = -np.inf
            return -np.inf

        self._cache_val = lnl
        return lnl
142655
def _total_rectangles(tree):
    '''
    
    '''
    return sum(len(sec.children) + sec.points.shape[0] - 1
               for sec in tree.iter_sections())
581367
def data_nodes(self):
        

        return {k: v for k, v in self.nodes.items() if v['type'] == 'data'}
631798
def normalize(vector):
    '''
    '''
    d = sum(x * x for x in vector) ** 0.5
    return tuple(x / d for x in vector)
1021497
def stats_on_depth(d, depth):
        
        root_nodes, leaf_nodes = 0, 0
        for _, node in DictTree.kv_depth(d, depth):
            if DictTree.length(node) == 0:
                leaf_nodes += 1
            else:
                root_nodes += 1
        total = root_nodes + leaf_nodes
        print("On depth %s, having %s root nodes, %s leaf nodes. "
              "%s nodes in total." % (depth, root_nodes, leaf_nodes, total))
91077
def p_const_vector_vector_list(p):
    
    if len(p[3]) != len(p[1][0]):
        syntax_error(p.lineno(2), 'All rows must have the same number of elements')
        p[0] = None
        return

    p[0] = p[1] + [p[3]]
890781
def p_arglist(self, tree):
        ''' '''
        if type(tree[0].value) == type([]):
            tree.value = tree[0].value + [tree[2].value]
        else:
            tree.value = [tree[0].value, tree[2].value]
        try:
            tree.svalue = "%s,%s"%(tree[0].svalue,tree[2].svalue)
        except AttributeError:
            pass
671492
def leaves(tree):
    
    lvs = []
    def _leaves(node):
        if np.isscalar(node):
            lvs.append(node)
        elif isinstance(node, tuple) and len(node) == 2:
            _leaves(node[0])
            _leaves(node[1])
        else:
            raise Exception("Not a tree!")

    _leaves(tree)
    return lvs
1271403
def sumad(array):
    
    n = ctypes.c_int(len(array))
    array = stypes.toDoubleVector(array)
    return libspice.sumad_c(array, n)
1262763
function slice(vtrees, counter, length) {
  return vtrees.slice(counter.count, counter.count += length);
}
1111544
def nx_gen_node_values(G, key, nodes, default=util_const.NoParam):
    
    node_dict = nx_node_dict(G)
    if default is util_const.NoParam:
        return (node_dict[n][key] for n in nodes)
    else:
        return (node_dict[n].get(key, default) for n in nodes)
1064241
def p_parens_expr(p):
    
    p[0] = node.expr(op="parens", args=node.expr_list([p[2]]))
807107
def from_dict(cls, tree_dict, previous=None):
        """"""
        instance = cls(tree_dict['tree_type'])

        fitted = tree_dict['fitted']
        instance.fitted = fitted
        if fitted:
            instance.level = tree_dict['level']
            instance.n_nodes = tree_dict['n_nodes']
            instance.tau_matrix = np.array(tree_dict['tau_matrix'])
            instance.previous_tree = cls._deserialize_previous_tree(tree_dict, previous)
            instance.edges = [Edge.from_dict(edge) for edge in tree_dict['edges']]

        return instance
123619
def visit_dict(self, node, parent):
        """"""
        newnode = nodes.Dict(node.lineno, node.col_offset, parent)
        items = list(self._visit_dict_items(node, parent, newnode))
        newnode.postinit(items)
        return newnode
1002265
def parse(self) -> typing.Union[list, dict, None]:
        """"""
        root_node_offset = self._read_u32(12)
        if root_node_offset == 0:
            return None

        node_type = self._data[root_node_offset]
        if not _is_container_type(node_type):
            raise ValueError("Invalid root node: expected array or dict, got type 0x%x" % node_type)
        return self._parse_node(node_type, 12)
860051
def visit_Dict(self, node):
        
        self.generic_visit(node)
        if node.keys:
            for key, value in zip(node.keys, node.values):
                value_type = self.result[value]
                self.combine(node, key,
                             unary_op=partial(self.builder.DictType,
                                              of_val=value_type))
        else:
            self.result[node] = self.builder.NamedType(
                "pythonic::types::empty_dict")
45925
def n_dict(self, node):
        
        p = self.prec
        self.prec = 100

        self.indent_more(INDENT_PER_LEVEL)
        sep = INDENT_PER_LEVEL[:-1]
        if node[0] != 'dict_entry':
            self.write('{')
        line_number = self.line_number

        if self.version >= 3.0 and not self.is_pypy:
            if node[0].kind.startswith('kvlist'):
                # Python 3.5+ style key/value list in dict
                kv_node = node[0]
                l = list(kv_node)
                length = len(l)
                if kv_node[-1].kind.startswith("BUILD_MAP"):
                    length -= 1
                i = 0

                # Respect line breaks from source
                while i < length:
                    self.write(sep)
                    name = self.traverse(l[i], indent='')
                    if i > 0:
                        line_number = self.indent_if_source_nl(line_number,
                                                               self.indent + INDENT_PER_LEVEL[:-1])
                    line_number = self.line_number
                    self.write(name, ': ')
                    value = self.traverse(l[i+1], indent=self.indent+(len(name)+2)*' ')
                    self.write(value)
                    sep = ", "
                    if line_number != self.line_number:
                        sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
                        line_number = self.line_number
                    i += 2
                    pass
                pass
            elif len(node) > 1 and node[1].kind.startswith('kvlist'):
                # Python 3.0..3.4 style key/value list in dict
                kv_node = node[1]
                l = list(kv_node)
                if len(l) > 0 and l[0].kind == 'kv3':
                    # Python 3.2 does this
                    kv_node = node[1][0]
                    l = list(kv_node)
                i = 0
                while i < len(l):
                    self.write(sep)
                    name = self.traverse(l[i+1], indent='')
                    if i > 0:
                        line_number = self.indent_if_source_nl(line_number,
                                                               self.indent + INDENT_PER_LEVEL[:-1])
                        pass
                    line_number = self.line_number
                    self.write(name, ': ')
                    value = self.traverse(l[i], indent=self.indent+(len(name)+2)*' ')
                    self.write(value)
                    sep = ", "
                    if line_number != self.line_number:
                        sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
                        line_number = self.line_number
                    else:
                        sep += " "
                    i += 3
                    pass
                pass
            elif node[-1].kind.startswith('BUILD_CONST_KEY_MAP'):
                # Python 3.6+ style const map
                keys = node[-2].pattr
                values = node[:-2]
                # FIXME: Line numbers?
                for key, value in zip(keys, values):
                    self.write(sep)
                    self.write(repr(key))
                    line_number = self.line_number
                    self.write(':')
                    self.write(self.traverse(value[0]))
                    sep = ", "
                    if line_number != self.line_number:
                        sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
                        line_number = self.line_number
                    else:
                        sep += " "
                        pass
                    pass
                if sep.startswith(",\n"):
                    self.write(sep[1:])
                pass
            elif node[0].kind.startswith('dict_entry'):
                assert self.version >= 3.5
                template = ("%C", (0, len(node[0]), ", **"))
                self.template_engine(template, node[0])
                sep = ''
            elif (node[-1].kind.startswith('BUILD_MAP_UNPACK')
                  or node[-1].kind.startswith('dict_entry')):
                assert self.version >= 3.5
                # FIXME: I think we can intermingle dict_comp's with other
                # dictionary kinds of things. The most common though is
                # a sequence of dict_comp's
                kwargs = node[-1].attr
                template = ("**%C", (0, kwargs, ", **"))
                self.template_engine(template, node)
                sep = ''

            pass
        else:
            # Python 2 style kvlist. Find beginning of kvlist.
            if node[0].kind.startswith("BUILD_MAP"):
                if len(node) > 1 and node[1].kind in ('kvlist', 'kvlist_n'):
                    kv_node = node[1]
                else:
                    kv_node = node[1:]
            else:
                assert node[-1].kind.startswith('kvlist')
                kv_node = node[-1]

            first_time = True
            for kv in kv_node:
                assert kv in ('kv', 'kv2', 'kv3')

                # kv ::= DUP_TOP expr ROT_TWO expr STORE_SUBSCR
                # kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR
                # kv3 ::= expr expr STORE_MAP

                # FIXME: DRY this and the above
                indent = self.indent + "  "
                if kv == 'kv':
                    self.write(sep)
                    name = self.traverse(kv[-2], indent='')
                    if first_time:
                        line_number = self.indent_if_source_nl(line_number, indent)
                        first_time = False
                        pass
                    line_number = self.line_number
                    self.write(name, ': ')
                    value = self.traverse(kv[1], indent=self.indent+(len(name)+2)*' ')
                elif kv == 'kv2':
                    self.write(sep)
                    name = self.traverse(kv[1], indent='')
                    if first_time:
                        line_number = self.indent_if_source_nl(line_number, indent)
                        first_time = False
                        pass
                    line_number = self.line_number
                    self.write(name, ': ')
                    value = self.traverse(kv[-3], indent=self.indent+(len(name)+2)*' ')
                elif kv == 'kv3':
                    self.write(sep)
                    name = self.traverse(kv[-2], indent='')
                    if first_time:
                        line_number = self.indent_if_source_nl(line_number, indent)
                        first_time = False
                        pass
                    line_number = self.line_number
                    self.write(name, ': ')
                    line_number = self.line_number
                    value = self.traverse(kv[0], indent=self.indent+(len(name)+2)*' ')
                    pass
                self.write(value)
                sep = ", "
                if line_number != self.line_number:
                    sep += "\n" + self.indent + "  "
                    line_number = self.line_number
                    pass
                pass
            pass
        if sep.startswith(",\n"):
            self.write(sep[1:])
        if node[0] != 'dict_entry':
            self.write('}')
        self.indent_less(INDENT_PER_LEVEL)
        self.prec = p
        self.prune()