{"record":{"id":"bbaf8b4f1ef36953","repo":"jax-ml/jax","slug":"rpow-modulo-not-implemented","errorCode":null,"errorMessage":"__rpow__ modulo not implemented","messagePattern":"__rpow__ modulo not implemented","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/export/shape_poly.py","lineNumber":776,"sourceCode":"      return _DimExpr._linear_combination(self, other, 0, 0, self.scope)\n    return _ensure_poly(other, \"mul\", self.scope).__mul__(self)\n\n  def __pow__(self, power: core.DimSize, modulo=None):\n    if modulo is not None:\n      raise NotImplementedError(\"__pow__ modulo not implemented\")\n    if is_symbolic_dim(power):\n      return power.__rpow__(self)\n    if power != int(power):\n      raise ValueError(f\"Symbolic dimension cannot be raised to non-integer powers: '{self}' ** '{power}'\")\n    if power >= 0:\n      return functools.reduce(op.mul, [self] * power, 1)\n    # We don't support negative powers, because JAX does not allow negative\n    # powers for integers\n    raise ValueError(f\"Symbolic dimension cannot be raised to negative powers: '{self}' ** '{power}'\")\n\n  def __rpow__(self, other, modulo=None):\n    if modulo is not None:\n      raise NotImplementedError(\"__rpow__ modulo not implemented\")\n    return self.__jax_array__().__rpow__(other)\n\n  def __floordiv__(self, divisor):\n    if isinstance(divisor, core.Tracer) or not _convertible_to_poly(divisor):\n      return self.__jax_array__().__floordiv__(divisor)\n    return self._divmod(divisor)[0]\n\n  def __rfloordiv__(self, other):\n    if isinstance(other, core.Tracer) or not _convertible_to_poly(other):\n      return self.__jax_array__().__rfloordiv__(other)\n    return _ensure_poly(other, \"floordiv\", self.scope).__floordiv__(self)\n\n  def __truediv__(self, divisor):\n    # Used for \"/\", which always returns a float\n    return self.__jax_array__().__truediv__(divisor)\n\n  def __rtruediv__(self, dividend):\n    # Used for \"/\", when dividend is not a _DimExpr","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/export/shape_poly.py#L758-L794","documentation":"Python's reflected-power protocol can also receive a modulo argument; JAX symbolic dimensions do not support modular exponentiation, so __rpow__ with modulo raises NotImplementedError.","triggerScenarios":"pow(const_base, symbolic_dim, modulus) — three-argument pow where the exponent is a symbolic dimension during polymorphic tracing.","commonSituations":"Very rare; cryptography- or hashing-style code paths executed under jax.export/jit with symbolic dims.","solutions":["Avoid three-argument pow involving symbolic dims","Convert the dim to a concrete int or a jnp array before the pow call","Reorder so the symbolic dim is not the exponent of a scalar pow with modulus"],"exampleFix":"# before\nr = pow(2, dim, 101)\n# after\nr = jnp.power(2, jnp.asarray(dim)) % 101  # on arrays, outside symbolic dim algebra","handlingStrategy":"type-guard","validationCode":"if modulo is not None and is_symbolic_dim(exponent): raise TypeError('no modular pow with symbolic dims')","typeGuard":"def safe_pow3(b, e, m):\n    if m is not None and is_symbolic_dim(e): raise TypeError\n    return pow(b, e, m)","tryCatchPattern":"try:\n    r = pow(2, dim, 101)\nexcept NotImplementedError:\n    r = (jnp.power(2, jnp.asarray(dim))) % 101","preventionTips":["Avoid builtins.pow with modulus anywhere near traced dims","Convert dims to arrays for numeric algorithms"],"tags":["jax","shape-polymorphism","rpow","not-implemented"],"backgroundTag":"unsupported-operator-on-symbolic-dimension","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}