Created
June 6, 2015 22:46
-
-
Save kmill/3d076b864a8fec1517af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quantize(w, x, y, z, n) : | |
if z == None : | |
z = 1.0 - w - x - y | |
n = int(n) | |
v = [w, x, y, z] | |
vn = [a * n for a in v] | |
vni = [int(a) for a in vn] | |
vnf = [a - ai for a, ai in zip(vn, vni)] | |
cutoff = sum(vnf) / 4 | |
def cround(xi, xf) : | |
return float(xi + (0 if xf < cutoff else 1)) / n | |
return [cround(ai, af) for ai, af in zip(vni, vnf)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment