Let input is a tensor, dim is a dimension to mask, and mask is a ByteTensor. And, the following statement is true:
len(mask.size())==1 and input.size(dim)==mask.size(0)

I wrote this simple function for this task,
def masked_index(input, dim, mask):
	assert(len(mask.size())==1 and input.size(dim)==mask.size(0))
	sizes = input.size()
	for i in xrange(len(sizes)-1):
		mask = mask.unsqueeze(1)
	mask = mask.expand_as(input)
	return input[mask].view(-1, sizes[1], sizes[2])

, however, I don’t know if there is a better solution for this.
The gist is that sometimes we want to select indices on a dimension using a mask (ByteTensor), which usually comes from comparison ops (e.g. torch.eq()), instead of indices (LongTensor).
@Soumith_Chintala  Any comment is welcome!

THIS FUNCTION HAS A BUG! PLEASE SEE THE BELOW COMMENT.