def do_median(vals, err=0.05, vrange=[0, 1000], verbose=True):

    # Get some test data
    vals = sorted([int(v) for v in vals])

    median = vals[int(len(vals) / 2)]
    if verbose:
        print("Correct sample median: %s (No. items: %s)" % (median, len(vals)))

    # Setup the crypto
    G = EcGroup()
    sec = G.order().random()
    y = sec * G.generator()
    

    xx = CountSketchCt.epsilondelta(err, err, y)
    d, w = xx.d, xx.w
    if verbose:
        print("Sketch: d=%s w=%s (Cmp. size: %s%%)" % (d, w, ((vrange[1] - vrange[0])/float(100*d*w))))

    # Add each sample to the sketch
    tic = time.clock()    

    all_cs = []
    for x in vals:
        cs_temp = CountSketchCt.epsilondelta(err, err, y) # CountSketchCt(d, w, y)
        cs_temp.insert("%s" % x)
        all_cs += [ cs_temp ]

    toc = time.clock()
    if verbose:
        print("Build Sketches: %2.4f sec (for %s)\tPer Sketch: %2.4f sec" % ((toc - tic), len(vals), (toc - tic) / len(vals)) )

    # Aggregate all sketches
    tic = time.clock()
    cs = CountSketchCt.aggregate(all_cs)

    toc = time.clock()
    dt = (toc - tic)
    if verbose:
        print("Aggregate Sketches: %2.4f sec (for %s)\tPer Sketch: %2.4f sec" % (dt, len(vals), dt / len(vals)) )

    # Now use test the median function
    proto = get_median(cs, min_b = vrange[0], max_b = vrange[1], steps = 20)

    tic = time.clock()

    plain = None
    no_decryptions = 0
    while True:
        v = proto.send(plain)
        if isinstance(v, int):
            break
        no_decryptions += 1
        plain = v.dec(sec)

    toc = time.clock()
    if verbose:
        print( "Find Median. Pivot: % 5d\tNo. Decryptions: %s\ttime: %2.4f sec" % (v, no_decryptions, toc - tic) )

    # Measure the size of the sketch
    bin_cs = cs.dump()
    if verbose:
        print("Sketch size: %s bytes" % len(bin_cs))    
        print("Estimated median: %s\t\tAbs. Err: %s" % (v, abs(v - median)))
    return v
dataset/ETHPy150Open gdanezis/petlib/examples/tormedian.py/do_median/swapped operands of `/`