/usr/share/pyshared/ferari/util.py is in python-ferari 1.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | eps = 1.e-10
precision = 5
def nnz( u ):
nnz_cur = 0
for ui in u:
if abs( ui ) > eps:
nnz_cur += 1
return nnz_cur
def normalize_sign( u ):
"""Returns u or -u such that the first nonzero entry (up to eps)
is positive"""
for ui in u:
if abs(ui) > eps:
if ui < 0.0:
return -u
else:
return u
return u
def unit_vector( u ):
mau = max(abs(u))
if mau < eps:
print u
raise RuntimeError, "divide by zero"
return normalize_sign( u / mau )
|