Skip to content

Commit e30cf83

Browse files
committed
ref #57, #62, #63 : remove unions in C-api + remove designated initializers
We are not ready for designated initializers - many compilers do not support this C++ feature yet, so removing it's non-trivial usages.
1 parent d6b84b2 commit e30cf83

File tree

4 files changed

+61
-59
lines changed

4 files changed

+61
-59
lines changed

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ int main(int argc, char ** argv) {
216216

217217
// run the inference
218218
{
219-
whisper_full_params wparams = whisper_full_default_params(WHISPER_DECODE_GREEDY);
219+
whisper_full_params wparams = whisper_full_default_params(WHISPER_SAMPLING_GREEDY);
220220

221221
wparams.print_realtime = true;
222222
wparams.print_progress = false;

stream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ int main(int argc, char ** argv) {
282282

283283
// run the inference
284284
{
285-
whisper_full_params wparams = whisper_full_default_params(WHISPER_DECODE_GREEDY);
285+
whisper_full_params wparams = whisper_full_default_params(WHISPER_SAMPLING_GREEDY);
286286

287287
wparams.print_progress = false;
288288
wparams.print_special_tokens = params.print_special_tokens;

whisper.cpp

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,59 +2256,63 @@ void whisper_print_timings(struct whisper_context * ctx) {
22562256

22572257
////////////////////////////////////////////////////////////////////////////
22582258

2259-
struct whisper_full_params whisper_full_default_params(enum whisper_decode_strategy strategy) {
2259+
struct whisper_full_params whisper_full_default_params(enum whisper_sampling_strategy strategy) {
22602260
struct whisper_full_params result;
22612261

22622262
switch (strategy) {
2263-
case WHISPER_DECODE_GREEDY:
2263+
case WHISPER_SAMPLING_GREEDY:
22642264
{
2265-
#if defined(_MSC_VER)
22662265
result = {
2267-
#else
2268-
result = (struct whisper_full_params) {
2269-
#endif
2270-
.strategy = WHISPER_DECODE_GREEDY,
2271-
.n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
2272-
.offset_ms = 0,
2266+
/*.strategy =*/ WHISPER_SAMPLING_GREEDY,
22732267

2274-
.translate = false,
2275-
.no_context = false,
2276-
.print_special_tokens = false,
2277-
.print_progress = true,
2278-
.print_realtime = false,
2279-
.print_timestamps = true,
2268+
/*.n_threads =*/ std::min(4, (int32_t) std::thread::hardware_concurrency()),
2269+
/*.offset_ms =*/ 0,
22802270

2281-
.language = "en",
2271+
/*.translate =*/ false,
2272+
/*.no_context =*/ false,
2273+
/*.print_special_tokens =*/ false,
2274+
/*.print_progress =*/ true,
2275+
/*.print_realtime =*/ false,
2276+
/*.print_timestamps =*/ true,
22822277

2283-
.greedy = {
2284-
.n_past = 0,
2278+
/*.language =*/ "en",
2279+
2280+
/*.greedy =*/ {
2281+
/*.n_past =*/ 0,
2282+
},
2283+
2284+
/*.beam_search =*/ {
2285+
/*.n_past =*/ -1,
2286+
/*.beam_width =*/ -1,
2287+
/*.n_best =*/ -1,
22852288
},
22862289
};
22872290
} break;
2288-
case WHISPER_DECODE_BEAM_SEARCH:
2291+
case WHISPER_SAMPLING_BEAM_SEARCH:
22892292
{
2290-
#if defined(_MSC_VER)
22912293
result = {
2292-
#else
2293-
result = (struct whisper_full_params) {
2294-
#endif
2295-
.strategy = WHISPER_DECODE_BEAM_SEARCH,
2296-
.n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
2297-
.offset_ms = 0,
2298-
2299-
.translate = false,
2300-
.no_context = false,
2301-
.print_special_tokens = false,
2302-
.print_progress = true,
2303-
.print_realtime = false,
2304-
.print_timestamps = true,
2305-
2306-
.language = "en",
2307-
2308-
.beam_search = {
2309-
.n_past = 0,
2310-
.beam_width = 10,
2311-
.n_best = 5,
2294+
/*.strategy =*/ WHISPER_SAMPLING_BEAM_SEARCH,
2295+
2296+
/*.n_threads =*/ std::min(4, (int32_t) std::thread::hardware_concurrency()),
2297+
/*.offset_ms =*/ 0,
2298+
2299+
/*.translate =*/ false,
2300+
/*.no_context =*/ false,
2301+
/*.print_special_tokens =*/ false,
2302+
/*.print_progress =*/ true,
2303+
/*.print_realtime =*/ false,
2304+
/*.print_timestamps =*/ true,
2305+
2306+
/*.language =*/ "en",
2307+
2308+
/*.greedy =*/ {
2309+
/*.n_past =*/ -1,
2310+
},
2311+
2312+
/*.beam_search =*/ {
2313+
/*.n_past =*/ 0,
2314+
/*.beam_width =*/ 10,
2315+
/*.n_best =*/ 5,
23122316
},
23132317
};
23142318
} break;

whisper.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ extern "C" {
153153

154154
////////////////////////////////////////////////////////////////////////////
155155

156-
// Available decoding strategies
157-
enum whisper_decode_strategy {
158-
WHISPER_DECODE_GREEDY, // Always select the most probable token
159-
WHISPER_DECODE_BEAM_SEARCH, // TODO: not implemented yet!
156+
// Available sampling strategies
157+
enum whisper_sampling_strategy {
158+
WHISPER_SAMPLING_GREEDY, // Always select the most probable token
159+
WHISPER_SAMPLING_BEAM_SEARCH, // TODO: not implemented yet!
160160
};
161161

162162
struct whisper_full_params {
163-
enum whisper_decode_strategy strategy;
163+
enum whisper_sampling_strategy strategy;
164164

165165
int n_threads;
166166
int offset_ms;
@@ -174,20 +174,18 @@ extern "C" {
174174

175175
const char * language;
176176

177-
union {
178-
struct {
179-
int n_past;
180-
} greedy;
181-
182-
struct {
183-
int n_past;
184-
int beam_width;
185-
int n_best;
186-
} beam_search;
187-
};
177+
struct {
178+
int n_past;
179+
} greedy;
180+
181+
struct {
182+
int n_past;
183+
int beam_width;
184+
int n_best;
185+
} beam_search;
188186
};
189187

190-
WHISPER_API struct whisper_full_params whisper_full_default_params(enum whisper_decode_strategy strategy);
188+
WHISPER_API struct whisper_full_params whisper_full_default_params(enum whisper_sampling_strategy strategy);
191189

192190
// Run the entire model: PCM -> log mel spectrogram -> encoder -> decoder -> text
193191
// Uses the specified decoding strategy to obtain the text.

0 commit comments

Comments
 (0)