Expected object of scalar type Short but got scalar type Float for argument #2 'mat2' in call to _th_mm

Hi guys. as you can see I already tried to generate the input, h and c in ShortTensor format but I still got the same error. would be nice If you can explain what I’m doing wrong.
here is my Code:


> class data(Dataset):
>     def __init__(self, samples=10000, number=30):
>         self.x = torch.from_numpy(np.matrix
>                         (np.random.random_integers(0,9,samples*number).reshape(samples, number)))
>         self.y = torch.from_numpy(np.zeros((samples))).type(torch.ShortTensor)
>         for index, row in enumerate(self.x):
>             self.y[index] = 1 if torch.sum(row) >= 130 else 0
>     
> class LSTM(nn.Module):
>     def __init__(self,i_size, h_size, n_layer, batch_size = 30 ):
>         super().__init__()
>         self.lstm = nn.LSTM(input_size=i_size, hidden_size=h_size, num_layers=n_layer)
>         self.h = torch.randn(n_layer, batch_size, h_size).type(torch.ShortTensor)
>         self.c = torch.randn(n_layer, batch_size, h_size).type(torch.ShortTensor)
>         self.hidden = (self.h, self.c)
>         self.linear = nn.Linear(n_layer, 1)
>     
>     def forward(self,x):
>         out, hidden = self.lstm(x.type(torch.ShortTensor), self.hidden)
>         out = nn.Softmax(self.linear(out.short()))
>         return out
> 
> data_set = data()
> train_data = data_set.x[0:8000, :, None]
> train_label = data_set.y[0:8000]
> test_data = data_set.x[8000:, : , None]
> test_label = data_set.y[8000:]
> #train_data = train_data[:,:,None]
> train_data[0].shape
> 
> input_size = 1
> hidden_size = 30
> layer_num = 200
> model_LSTM = LSTM(input_size, hidden_size, layer_num)
> #model_LSTM.cuda()
> y = model_LSTM(train_data)`Preformatted text`

self.h = torch.randn(n_layer, batch_size, h_size).type(torch.ShortTensor)

But I was able to solve the problem. It turned out that it actually didnt need ShortTensor but float32. I think LSTM takes only float32. Everything else didn’t work for me.