8000 `__setitem__` with bool mask and dtype mismatch fails · Issue #150017 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
__setitem__ with bool mask and dtype mismatch fails #150017
Open
@crusaderky

Description

@crusaderky

🐛 Describe the bug

x[idx] = v fails when

  • x has ndim=0, and
  • idx is a boolean mask (also with ndim=0), and
  • v requires type promotion.
import torch as xp

x = xp.asarray([0], dtype=xp.float64)
x[x==0] = xp.asarray(1, dtype=xp.float32)  # OK

x = xp.asarray(0, dtype=xp.float64)
x[()] = xp.asarray(1, dtype=xp.float32)  # OK
x[x==0] = xp.asarray(1, dtype=xp.float64)  # OK
x[x==0] = xp.asarray(1, dtype=xp.float32)  # error
# RuntimeError: Index put requires the source and destination dtypes match, got Double for the destination and Float for the source.

Versions

torch 2.6.0 cpu

cc @nairbv @mruberry

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: advanced indexingRelated to x[i] = y, index functionsmodule: edge casesAdversarial inputs unlikely to occur in practicemodule: type promotionRelated to semantics of type promotiontriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0