8000 Small incompatibility between C/Cuda maskedFill / maskedSelect · Issue #231 · torch/torch7 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
Small incompatibility between C/Cuda maskedFill / maskedSelect  #231
Open
@fmassa

Description

@fmassa

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 CudaTensors, while their C counterparts returns ByteTensors

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0