Changeset bf54364 for python/lib


Ignore:
Timestamp:
Jul 12, 2016, 8:17:12 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
c395732
Parents:
34e753c
Message:

python/lib/gen_code.py: add input size checks (see #63)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/gen_code.py

    r34e753c rbf54364  
    8585        }
    8686
     87objinputsize = {
     88        'mfcc': 'self->buf_size / 2 + 1',
     89        'notes': 'self->hop_size',
     90        'onset': 'self->hop_size',
     91        'pitch': 'self->hop_size',
     92        'sampler': 'self->hop_size',
     93        'specdesc': 'self->buf_size / 2 + 1',
     94        'tempo': 'self->hop_size',
     95        'wavetable': 'self->hop_size',
     96        }
     97
    8798def get_name(proto):
    8899    name = proto.replace(' *', '* ').split()[1].split('(')[0]
     
    378389        return NULL;
    379390    }}""".format(input_param, pytoaubio = pytoaubio_fn[input_param['type']])
    380         out += """
     391        if self.shortname in objinputsize:
     392            out += """
     393
     394    if (self->{0[name]}.length != {expected_size}) {{
     395        PyErr_Format (PyExc_ValueError,
     396            "input size of {shortname} should be %d, not %d",
     397            {expected_size}, self->{0[name]}.length);
     398        return NULL;
     399    }}""".format(input_param, expected_size = objinputsize[self.shortname], **self.__dict__)
     400        else:
     401            out += """
    381402
    382403    // TODO: check input sizes"""
Note: See TracChangeset for help on using the changeset viewer.