Description
I almost posted this on torch/cutorch#70, but I think it should be addressed here.
There is a small incompatibility between C and CUDA versions of maskedFill
and maskedSelect
.
In the C version, the mask
needs to be a ByteTensor
, whereas CUDA version accepts both ByteTensor
and CudaTensor
.
This is probably motivated by the fact that the comparison operations in CUDA returns CudaTensor
s, while their C counterparts returns ByteTensor
s
By itself, that's not a big deal, but on C side, one needs two buffers when using comparison operations in order to use maskedFill
or maskedSelect
, one for the comparison operator (which is of type Tensor
if one reuses a tensor for the output), and one ByteTensor
for the masking.
An example is maybe clearer:
t = torch.rand(5)
mask = torch.Tensor()
mask_byte = torch.ByteTensor() -- only needed because of maskedFill / maskedSelect
mask:lt(t,0.5) -- puts the result in mask
-- mask_byte:lt(t,0.5) -- doesn't work, but could also be a solution if it worked
mask_byte:resize(mask:size()):copy(mask)
print(t[mask]) -- prints nil
print(t[mask_byte])
With that in mind, wouldn't it be better to adapt the C version of maskedFill
and maskedSelect
to also accept the current source Tensor
type for the mask
, as in its CUDA version ? Or maybe we should accept the output of the comparison operators to also be Tensor
instead of only ByteTensor
? Or both ?