{"record":{"id":"388d6599c1b716cd","repo":"jax-ml/jax","slug":"operand-to-reduce-window-sum-must-have-a-number-dt","errorCode":null,"errorMessage":"operand to reduce_window_sum must have a number dtype, got {}","messagePattern":"operand to reduce_window_sum must have a number dtype, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/windowed_reductions.py","lineNumber":522,"sourceCode":"      init_values=init_values,\n      init_values_avals=init_value_avals,\n      out_avals=ctx.avals_out,\n      window_dimensions=window_dimensions,\n      window_strides=window_strides,\n      base_dilation=base_dilation,\n      window_dilation=window_dilation,\n      padding=padding,\n  )\n\n\nmlir.register_lowering(reduce_window_p, _generic_reduce_window_lower)\n\n\ndef _reduce_window_sum_shape_rule(operand, *, window_dimensions, window_strides,\n                                  padding, base_dilation, window_dilation):\n  if not dtypes.issubdtype(operand.dtype, np.number):\n    msg = \"operand to reduce_window_sum must have a number dtype, got {}\"\n    raise TypeError(msg.format(np.dtype(operand.dtype).name))\n  return _common_reduce_window_shape_rule(operand, window_dimensions,\n                                          window_strides, padding,\n                                          base_dilation, window_dilation)\n\ndef _reduce_window_sum_transpose_rule(cotangent, operand, *, window_dimensions,\n                                      window_strides, padding, base_dilation,\n                                      window_dilation):\n  assert ad.is_undefined_primal(operand)\n  input_shape = operand.aval.shape\n  pads = convolution._conv_general_vjp_lhs_padding(\n      input_shape, window_dimensions, window_strides, cotangent.shape, padding,\n      base_dilation, window_dilation)\n  ones = [1] * len(input_shape)\n  padding_config = [(lo, hi, stride - 1)\n                    for (lo, hi), stride in zip(pads, window_strides)]\n  pad_cotangent = lax.pad(cotangent, lax._zero(cotangent), padding_config)\n  result = _reduce_window_sum(pad_cotangent, window_dimensions, base_dilation,\n                              [(0, 0)] * len(input_shape),","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/windowed_reductions.py#L504-L540","documentation":"reduce_window_sum (and lax.reduce_window with the sum reducer) requires a numeric dtype. The shape rule rejects operands with non-number dtypes such as bool or complex-incompatible types.","triggerScenarios":"Calling jax.lax.reduce_window_sum on a boolean array or an array with dtype like np.str_ / object.","commonSituations":"Summing a boolean mask over windows (e.g. counting valid pixels) without converting to an integer type first.","solutions":["Cast the operand: x.astype(jnp.float32) or x.astype(jnp.int32)","For bool masks, use reduce_window_max or cast before summing"],"exampleFix":"# before\nlax.reduce_window_sum(bool_mask, dims, strides, padding)\n# after\nlax.reduce_window_sum(bool_mask.astype(jnp.int32), dims, strides, padding)","handlingStrategy":"type-guard","validationCode":"assert jnp.issubdtype(x.dtype, jnp.number), f'requires number dtype, got {x.dtype}'","typeGuard":"def is_number_dtype(x): return jnp.issubdtype(x.dtype, jnp.number)","tryCatchPattern":null,"preventionTips":["Cast bool masks to int32/float32 before windowed sums","Standardize on one numeric dtype in the pipeline"],"tags":["jax","dtype","reduce-window","type-validation"],"backgroundTag":"jax-dtype-validation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}