MCPcopy Create free account
hub / github.com/evilsocket/cake / sinusoidal_time_embedding

Function sinusoidal_time_embedding

cake-core/src/models/luxtts/model.rs:135–146  ·  view source on GitHub ↗

Sinusoidal time embedding: cat([cos(t*freqs), sin(t*freqs)]).

(t: f32, dim: usize, device: &Device, dtype: DType)

Source from the content-addressed store, hash-verified

133
134/// Sinusoidal time embedding: cat([cos(t*freqs), sin(t*freqs)]).
135fn 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]
149impl Generator for LuxTTS {

Callers 1

generate_speechMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected