perm2 seems to contain quite unusual values and I assume that negative's size is smaller than these values and will thus raise the error. You would thus have to check why perm2 is containing these values and if they are expected.