def circDiff(length, ary1, ary2):
x = np.arange(length)<EOL>mod = length % <NUM_LIT:2><EOL>if mod == <NUM_LIT:0>:<EOL><INDENT>temp = np.ones(length)<EOL>temp[length/<NUM_LIT:2>:] = -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>x = x - np.floor(length/<NUM_LIT:2>)<EOL>temp = np.copy(x)<EOL>temp[np.less(x, <NUM_LIT:0>)] = <NUM_LIT:1><EOL>temp[np.greater(x, <NUM_LIT:0>)] = -<NUM_LIT:1><EOL><DEDENT>x = np.cumsum(temp)<EOL>diagDiffmat = np.empty((length, length))<EOL>for idx in np.arange(length):<EOL><INDENT>x = np.roll(x, <NUM_LIT:1>)<EOL>diagDiffmat[idx, :] = x<EOL><DEDENT>flat = diagDiffmat.flatten()<EOL>ind = ary1*diagDiffmat.shape[<NUM_LIT:0>] + ary2<EOL>ind = ind.astype('<STR_LIT:int>')<EOL>return flat[ind]<EOL>
calculate the circular difference between two paired arrays.
    This function will return the difference between pairs of numbers; however
    the difference that is output will be minimal in the sense that if we
    assume an array with length = 4: [0, 1, 2, 3], the difference between
    0 and 3 will not be 3, but 1 (i.e. circular difference)