license import { FloorDiv , KernelConfig , KernelFunc } from '@tensorflow/tfjs-core' ; import { binaryKernelFunc } from '../kernel_utils/kernel_funcs_utils' ; const INT_DIV = `
  float s = sign(a) * sign(b);
  int ia = round(a);
  int ib = round(b);
  if (ib != 0) {
    // Windows (D3D) wants guaranteed non-zero int division at compile-time.
    return float(idiv(ia, ib, s));
  } else {
    return NAN;
  }
` ; const INT_DIV_PACKED = `
  ivec4 ia = round(a);
  ivec4 ib = round(b);
  bvec4 cond = notEqual(ib, ivec4(0));
  ivec4 result = ivec4(0);
  vec4 s = sign(a) * sign(b);

  // Windows (D3D) wants guaranteed non-zero int division at compile-time.
  if (cond[0]) {
    result[0] = idiv(ia[0], ib[0], s[0]);
  }
  if (cond[1]) {
    result[1] = idiv(ia[1], ib[1], s[1]);
  }
  if (cond[2]) {
    result[2] = idiv(ia[2], ib[2], s[2]);
  }
  if (cond[3]) {
    result[3] = idiv(ia[3], ib[3], s[3]);
  }
  return vec4(result);
` ; export const floorDiv = binaryKernelFunc ( { opSnippet : INT_DIV , packedOpSnippet : INT_DIV_PACKED , dtype : 'int32' } ) ; export const floorDivConfig = { kernelName : FloorDiv , backendName : 'webgl' , kernelFunc : floorDiv as { } as KernelFunc } ;