div_rtn.h 465 B

12345678910111213141516
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. // Integer division rounding to -Infinity
  4. template <typename T>
  5. static inline T div_rtn(T x, T y) {
  6. int q = x / y;
  7. int r = x % y;
  8. if ((r != 0) && ((r < 0) != (y < 0)))
  9. --q;
  10. return q;
  11. }
  12. #else
  13. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  14. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)