MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / decoder_sinusoidal_pos_emb

Function decoder_sinusoidal_pos_emb

src/models/chatterbox/s3gen_flow.cpp:132–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130
131std::vector<float> decoder_sinusoidal_pos_emb(
132 const std::vector<float> & timesteps,
133 int64_t batch,
134 int64_t dim,
135 float scale = 1000.0f) {
136 if ((dim % 2) != 0) {
137 throw std::runtime_error("decoder sinusoidal embedding requires even dim");
138 }
139 const int64_t half_dim = dim / 2;
140 std::vector<float> out(static_cast<size_t>(batch * dim), 0.0f);
141 const double emb_scale = std::log(10000.0) / static_cast<double>(half_dim - 1);
142 for (int64_t b = 0; b < batch; ++b) {
143 for (int64_t i = 0; i < half_dim; ++i) {
144 const double freq = std::exp(-static_cast<double>(i) * emb_scale);
145 const double angle = static_cast<double>(scale) * static_cast<double>(timesteps[static_cast<size_t>(b)]) * freq;
146 out[static_cast<size_t>(b * dim + i)] = static_cast<float>(std::sin(angle));
147 out[static_cast<size_t>(b * dim + half_dim + i)] = static_cast<float>(std::cos(angle));
148 }
149 }
150 return out;
151}
152
153std::vector<float> flow_relative_positional_encoding(int64_t frames, int64_t channels) {
154 const int64_t rel_frames = (frames * 2) - 1;
155 std::vector<float> positive(static_cast<size_t>(frames * channels), 0.0f);

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected