Sinusoidal time embedding: cat([cos(t*freqs), sin(t*freqs)]).
(t: f32, dim: usize, device: &Device, dtype: DType)
| 133 | |
| 134 | /// Sinusoidal time embedding: cat([cos(t*freqs), sin(t*freqs)]). |
| 135 | fn sinusoidal_time_embedding(t: f32, dim: usize, device: &Device, dtype: DType) -> Result<Tensor> { |
| 136 | let half = dim / 2; |
| 137 | let mut data = vec![0.0f32; dim]; |
| 138 | let log_10000 = 10000.0f32.ln(); |
| 139 | for i in 0..half { |
| 140 | let freq = (-log_10000 / (half as f32 - 1.0) * i as f32).exp(); |
| 141 | let arg = t * freq; |
| 142 | data[i] = arg.cos(); |
| 143 | data[half + i] = arg.sin(); |
| 144 | } |
| 145 | Ok(Tensor::from_vec(data, (1, dim), device)?.to_dtype(dtype)?) |
| 146 | } |
| 147 | |
| 148 | #[async_trait] |
| 149 | impl Generator for LuxTTS { |