added debug asserts to compare c and python implementation