Is that ok to change variable's type in a custom loss function?

Is that ok to change variable‘s type in a custom loss function?
it seems work, but i am not sure if it can back propagate correctly

score =torch.sum(seg*gt).type(torch.FloatTensor)*2 /(torch.sum(seg) + torch.sum(gt)).type(torch.FloatTensor)
both seg and gt are longtesnsor type

Yes it is fine, to change it to float type you can also use the .float() function.