Solved by googlebot in post #2 
              
              
                I = torch.arange(C,dtype=T.dtype) 
bools = (( I >= T [:,0,None]) & ( I <= T[:,1,None])) # broadcasting (1,C) with (N,1) 
ints = bools.long()