build up HuffTab[t][c] using L and V.
190928
private void buildHuffTable(final int tab[], final int L[], final int V[][]) throws IOException {
        int temp = 256;
        int k = 0;

        for (int i = 0; i < 8; i++) { // i+1 is Code length
            for (int j = 0; j < L[i]; j++) {
                for (int n = 0; n < (temp >> (i + 1)); n++) {
                    tab[k] = V[i][j] | ((i + 1) << 8);
                    k++;
                }
            }
        }

        for (int i = 1; k < 256; i++, k++) {
            tab[k] = i | MSB;
        }

        int currentTable = 1;
        k = 0;

        for (int i = 8; i < 16; i++) { // i+1 is Code length
            for (int j = 0; j < L[i]; j++) {
                for (int n = 0; n < (temp >> (i - 7)); n++) {
                    tab[(currentTable * 256) + k] = V[i][j] | ((i + 1) << 8);
                    k++;
                }
                if (k >= 256) {
                    if (k > 256) {
                        throw new IIOException("JPEG Huffman Table error");
                    }

                    k = 0;
                    currentTable++;
                }
            }
        }
    }
1214264
def load_vpatt(filename1, filename2):
    

    with open(filename1) as f: 
        lines = f.readlines()

        lst = lines[0].split(',')

        patt1 = np.zeros([int(lst[0]), int(lst[1])],
                        dtype=np.complex128)

        lines.pop(0)

        for line in lines:
            lst = line.split(',')
            n = int(lst[0])
            m = int(lst[1])
            re = float(lst[2])
            im = float(lst[3])
            patt1[n, m] = re + 1j * im

    with open(filename2) as f: 
        lines2 = f.readlines()

        lst = lines2[0].split(',')

        patt2 = np.zeros([int(lst[0]), int(lst[1])],
                        dtype=np.complex128)

        lines2.pop(0)

        for line in lines2:
            lst = line.split(',')
            n = int(lst[0])
            m = int(lst[1])
            re = float(lst[2])
            im = float(lst[3])
            patt2[n, m] = re + 1j * im

    return sp.VectorPatternUniform(patt1, patt2)
625773
def colgen(*lstcol,**kargs):
    """"""
    if len(lstcol) < 2:
        lstcol *= 2
    trans = kargs.get("trans", lambda x,y,z: (x,y,z))
    while 1:
        for i in range(len(lstcol)):
            for j in range(len(lstcol)):
                for k in range(len(lstcol)):
                    if i != j or j != k or k != i:
                        yield trans(lstcol[(i+j)%len(lstcol)],lstcol[(j+k)%len(lstcol)],lstcol[(k+i)%len(lstcol)])
102160
def iter_left_col_tcs(self):
        """"""
        col_idx = self._left
        for tr in self._tbl.tr_lst[self._top:self._bottom]:
            yield tr.tc_lst[col_idx]
38315
def p_insertx(self,t):
    ""
    t[0] = InsertX(t[3],t[4],t[7].children,t[9])
834624
def libvlc_vprinterr(fmt, ap):
    '''
    '''
    f = _Cfunctions.get('libvlc_vprinterr', None) or \
        _Cfunction('libvlc_vprinterr', ((1,), (1,),), None,
                    ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p)
    return f(fmt, ap)
493866
def dot_v3(v, w):
    """"""

    return sum([x * y for x, y in zip(v, w)])
27389
def _tffunc(*argtypes):
        '''
        '''
        placeholders = list(map(tf.placeholder, argtypes))
        def wrap(f):
            out = f(*placeholders)
            def wrapper(*args, **kw):
                return out.eval(dict(zip(placeholders, args)), session=kw.get('session'))
            return wrapper
        return wrap
809259
def dump_t_coords(dataset_dir, data_dir, dataset, root=None, compress=True):
    """"""
    if root is None:
        root = {}
    tcoords = dataset.GetPointData().GetTCoords()
    if tcoords:
        dumped_array = dump_data_array(dataset_dir, data_dir, tcoords, {}, compress)
        root['pointData']['activeTCoords'] = len(root['pointData']['arrays'])
        root['pointData']['arrays'].append({'data': dumped_array})
812948
def p_UseTrait(p):
    '''
    
    '''
    if len(p) <= 3:
        p[0] = UseTrait(p[1], p[2], None)
    else:
        p[0] = UseTrait(p[1], p[3], p[4])
1153696
def _generate_O_inv(self, L):
        """"""
        self._generate_O(L)
        self.O_inv = torch.from_numpy(np.linalg.inv(self.O.numpy())).float()
141293
def _lvard(ins):
    
    output = []

    l = eval(ins.quad[2])  # List of bytes to push
    label = tmp_label()
    offset = int(ins.quad[1])
    tmp = list(ins.quad)
    tmp[1] = label
    ins.quad = tmp
    AT_END.extend(_vard(ins))

    output.append('push ix')
    output.append('pop hl')
    output.append('ld bc, %i' % -offset)
    output.append('add hl, bc')
    output.append('ex de, hl')
    output.append('ld hl, %s' % label)
    output.append('ld bc, %i' % len(l))
    output.append('ldir')

    return output
550197
def main():
    from IPython import embed
    

    """ Python 3.5.3 (pypy3)
    libttl 2.387338638305664
    ttl 1.3430471420288086
    diff lt - ttl 1.0442914962768555
    librdfxml 24.70371127128601
    rdfxml 17.85916304588318
    diff lr - rl 6.844548225402832
    simple time 18.32300615310669
    """

    # well I guess that answers that question ...
    # librdf much faster for cpython, not for pypy3

    from time import time
    rdflib.plugin.register('librdfxml', rdflib.parser.Parser,
                        'librdflib', 'libRdfxmlParser')
    rdflib.plugin.register('libttl', rdflib.parser.Parser,
                        'librdflib', 'libTurtleParser')

    p1 = Path('~/git/NIF-Ontology/ttl/NIF-Molecule.ttl').expanduser()
    start = time()
    graph = rdflib.Graph().parse(p1.as_posix(), format='libttl')
    stop = time()
    lttime = stop - start
    print('libttl', lttime)
    #serialize(graph)

    start = time()
    graph = rdflib.Graph().parse(p1.as_posix(), format='turtle')
    stop = time()
    ttltime = stop - start
    print('ttl', ttltime)
    print('diff lt - ttl', lttime - ttltime)

    p2 = Path('~/git/NIF-Ontology/ttl/external/uberon.owl').expanduser()
    start = time()
    graph2 = rdflib.Graph().parse(p2.as_posix(), format='librdfxml')
    stop = time()
    lrtime = stop - start
    print('librdfxml', lrtime)
    if True:
        start = time()
        graph2 = rdflib.Graph().parse(p2.as_posix(), format='xml')
        stop = time()
        rltime = stop - start
        print('rdfxml', rltime)
        print('diff lr - rl', lrtime - rltime)

    if True:
        file_uri = p2.as_uri()
        parser = RDF.Parser(name='rdfxml')
        stream = parser.parse_as_stream(file_uri)
        start = time()
        # t = list(stream)
        t = tuple(statement_to_tuple(statement) for statement in stream)
        stop = time()
        stime = stop - start
        print('simple time', stime)

    embed()
264840
def p_recipe(self, t):
        """"""
        if len(t) == 3:
            t[0] = t[1] + t[2]
        else:
            t[0] = t[1]
381797
def huffman(freq):
    
    h = []
    for a in freq:
        heappush(h, (freq[a], a))
    while len(h) > 1:
        (fl, l) = heappop(h)
        (fr, r) = heappop(h)
        heappush(h, (fl + fr, [l, r]))
    code = {}
    extract(code, h[0][1])
    return code
834144
def fsplit(pred, objs):
    """"""
    t = []
    f = []
    for obj in objs:
        if pred(obj):
            t.append(obj)
        else:
            f.append(obj)
    return (t, f)
1014670
def tqx(mt, x, t):
    
    return (mt.lx[x] - mt.lx[x + t]) / mt.lx[x]