Support more variants of MemoryView

This commit is contained in:
Kitaiti Makoto 2026-04-03 07:31:33 +09:00
parent cba11bbbbf
commit cfdeaa2574
1 changed files with 5 additions and 3 deletions

View File

@ -304,11 +304,13 @@ VALUE ruby_whisper_model_type(VALUE self)
static bool
check_memory_view(rb_memory_view_t *memview)
{
if (memview->format != NULL && strcmp(memview->format, "f") != 0) {
rb_warn("currently only format \"f\" is supported for MemoryView, but given: %s", memview->format);
if (memview->format != NULL && strcmp(memview->format, "f") != 0 && strcmp(memview->format, "e") != 0) {
// TODO: Accept other formats and convert samples
rb_warn("currently only format \"f\" and \"e\" is supported for MemoryView, but given: %s", memview->format);
return false;
}
if (memview->format != NULL && memview->ndim != 1) {
if (memview->format != NULL && memview->ndim != 1 && !(memview->ndim == 2 && memview->shape[1] == 1)) {
// TODO: Accept ndim == 2 with shape [n_samples, channels] and channels > 1 by averaging the samples in different channels or just taking the first channel
rb_warn("currently only 1 dimensional MemoryView is supported, but given: %zd", memview->ndim);
return false;
}