# Help regarding Slerp function for generative model sampling

**URL:** <https://discuss.pytorch.org/t/help-regarding-slerp-function-for-generative-model-sampling/32475>\
**Category:** Uncategorized\
**Created:** [December 18, 2018, 3:12pm UTC](https://discuss.pytorch.org/t/help-regarding-slerp-function-for-generative-model-sampling/32475 "2018-12-18T15:12:42Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [December 19, 2018, 10:47am UTC](https://discuss.pytorch.org/t/help-regarding-slerp-function-for-generative-model-sampling/32475/4 "2018-12-19T10:47:11Z")

</div>

There are some minor error regarding the shapes.  
Here is a working solution for batched inputs:

```python
def slerp(val, low, high):
    low_norm = low/torch.norm(low, dim=1, keepdim=True)
    high_norm = high/torch.norm(high, dim=1, keepdim=True)
    omega = torch.acos((low_norm*high_norm).sum(1))
    so = torch.sin(omega)
    res = (torch.sin((1.0-val)*omega)/so).unsqueeze(1)*low + (torch.sin(val*omega)/so).unsqueeze(1) * high
    return res

```

---

_[View the full topic](https://discuss.pytorch.org/t/help-regarding-slerp-function-for-generative-model-sampling/32475)._
