# How can I speed up add/sub math operation using PyTorch?

**URL:** <https://discuss.pytorch.org/t/how-can-i-speed-up-add-sub-math-operation-using-pytorch/9950>\
**Category:** Uncategorized\
**Created:** [November 14, 2017, 10:09pm UTC](https://discuss.pytorch.org/t/how-can-i-speed-up-add-sub-math-operation-using-pytorch/9950 "2017-11-14T22:09:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JMPPS](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@JMPPS](https://discuss.pytorch.org/u/JMPPS)\
**Post date:** [November 14, 2017, 10:09pm UTC](https://discuss.pytorch.org/t/how-can-i-speed-up-add-sub-math-operation-using-pytorch/9950/1 "2017-11-14T22:09:41Z")

</div>

Hello,

I am trying to speed up the PSO algorithm. I have two question, want can I do to speed up the following:

1. The creation of the particles;
2. The movement equation.

> 1. x = (xmax - xmin)\*torch.rand(pop).dtype + xmin

> 1. vnext = w_torch.rand(pop).dtype + c1_torch.rand(pop).dtype\*(b - x) + c2_torch.rand(pop).dtype_(bg - x)

When I use `dtype = torch.cuda.FloatTensor` is slower then using `dtype =torch.FloatTensor`.  
How can I speed up the math using the GPU?
