def test_floorint(): from numpy import array, all from pylada.math import floor_int from pylada.error import TypeError assert floor_int(array([0.1, -0.1, -0.5, 0.5, -0.55, 0.55])).dtype == 'int64' assert all( floor_int(array([0.1, -0.1, -0.5, 0.5, -0.55, 0.55, 1.999, -1.99])) == [0, -1, -1, 0, -1, 0, 1, -2] ) assert all( floor_int(array([[0.1, -0.1, -0.5, 0.5], [-0.55, 0.55, 1.999, -1.99]])) == [[0, -1, -1, 0], [-1, 0, 1, -2]] ) try: floor_int([5, 6, 7]) except TypeError: pass else: raise Exception()
def indices(invcell, pos, n): from numpy import cast, dot, array from pylada.math import floor_int int_fractional = cast["int64"](floor_int(dot(invcell, pos))) int_fractional = array([u + (ni if u < 0 else (-ni if u >= ni else 0)) for u, ni in zip(int_fractional, n)]) neg = int_fractional % n return array([u+ni if u < 0 else u for u, ni in zip(neg, n)])
def test_floorint(): from numpy import array, all from pylada.math import floor_int from pylada.error import TypeError assert floor_int(array([0.1, -0.1, -0.5, 0.5, -0.55, 0.55])).dtype == 'int64' assert all( floor_int(array([0.1, -0.1, -0.5, 0.5, -0.55, 0.55, 1.999, -1.99])) == [0, -1, -1, 0, -1, 0, 1, -2]) assert all( floor_int(array([[0.1, -0.1, -0.5, 0.5], [-0.55, 0.55, 1.999, -1.99]])) == [[0, -1, -1, 0], [-1, 0, 1, -2]]) try: floor_int([5, 6, 7]) except TypeError: pass else: raise Exception()