Assignment via [] is implemented here:

  
      github.com
  
  
    pytorch/pytorch/blob/9d4d0640f26b044747927aa8cfc818d6e7861b7a/torch/csrc/generic/Tensor.cpp#L1543 2

  }
}
THPUtils_setError("An unknown error has occurred when indexing a tensor "
    "in THPTensor_(getValue). Please report this in a github issue at: "
    "https://github.com/pytorch/pytorch");
return NULL;
END_HANDLE_TH_ERRORS
}


template<bool force_tensor>
static int THPTensor_(setValue)(THPTensor *self, PyObject *index, PyObject *value)
{
HANDLE_TH_ERRORS


#ifndef TH_REAL_IS_HALF
#if defined(THC_GENERIC_FILE)
THCPByteTensor *mask = THCPByteTensor_Check(index) ? (THCPByteTensor*)index : NULL;
THCPAutoGPU __gpu_guard(NULL, (PyObject*)self);
#elif defined(THD_GENERIC_FILE)
THDPByteTensor *mask = THDPByteTensor_Check(index) ? (THDPByteTensor*)index : NULL;
#else



  
  
    
    
  
  


The case where the “key” is a ByteTensor (x < 0 returns a ByteTensor of 0s and 1s in PyTorch) is in the if (mask) section.