Changeset 21e8408 for python


Ignore:
Timestamp:
Apr 29, 2016, 11:48:39 PM (9 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:
e84f7b9
Parents:
b055b4e
Message:

python/lib/gen_code.py: switch to using PyObjects? instead of fvec, cvec, fmat

Location:
python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/ext/py-filter.c

    rb055b4e r21e8408  
    77  uint_t order;
    88  fvec_t vec;
    9   fvec_t *out;
     9  PyObject *out;
     10  fvec_t c_out;
    1011} Py_filter;
    1112
     
    5051    return -1;
    5152  }
    52   self->out = new_fvec(Py_default_vector_length);
     53  self->out = NULL;
    5354  return 0;
    5455}
     
    5758Py_filter_del (Py_filter * self)
    5859{
    59   del_fvec(self->out);
     60  Py_XDECREF(self->out);
    6061  del_aubio_filter (self->o);
    6162  Py_TYPE(self)->tp_free ((PyObject *) self);
    6263}
    6364
    64 static PyObject * 
     65static PyObject *
    6566Py_filter_do(Py_filter * self, PyObject * args)
    6667{
     
    7980  }
    8081
    81   // reallocate the output if needed
    82   if (self->vec.length != self->out->length) {
    83     del_fvec(self->out);
    84     self->out = new_fvec(self->vec.length);
     82  // initialize output now
     83  if (self->out == NULL) {
     84    self->out = new_py_fvec(self->vec.length);
     85  }
     86
     87  Py_INCREF(self->out);
     88  if (!PyAubio_ArrayToCFvec(self->out, &(self->c_out)) ) {
     89    return NULL;
    8590  }
    8691  // compute the function
    87   aubio_filter_do_outplace (self->o, &(self->vec), self->out);
    88   return PyAubio_CFvecToArray(self->out);
    89 }
    90 
    91 static PyObject * 
     92  aubio_filter_do_outplace (self->o, &(self->vec), &(self->c_out));
     93  return self->out;
     94}
     95
     96static PyObject *
    9297Py_filter_set_c_weighting (Py_filter * self, PyObject *args)
    9398{
     
    107112}
    108113
    109 static PyObject * 
     114static PyObject *
    110115Py_filter_set_a_weighting (Py_filter * self, PyObject *args)
    111116{
  • python/lib/gen_code.py

    rb055b4e r21e8408  
    4949
    5050newfromtype_fn = {
    51         'fvec_t*': 'new_fvec',
    52         'fmat_t*': 'new_fmat',
    53         'cvec_t*': 'new_cvec',
     51        'fvec_t*': 'new_py_fvec',
     52        'fmat_t*': 'new_py_fmat',
     53        'cvec_t*': 'new_py_cvec',
    5454        }
    5555
    5656delfromtype_fn = {
    57         'fvec_t*': 'del_fvec',
    58         'fmat_t*': 'del_fmat',
    59         'cvec_t*': 'del_cvec',
     57        'fvec_t*': 'Py_DECREF',
     58        'fmat_t*': 'Py_DECREF',
     59        'cvec_t*': 'Py_DECREF',
    6060        }
    6161
     
    169169        self.do_inputs = [get_params_types_names(self.do_proto)[1]]
    170170        self.do_outputs = get_params_types_names(self.do_proto)[2:]
    171         self.outputs_flat = get_output_params(self.do_proto)
    172         self.output_results = "; ".join(self.outputs_flat)
     171        struct_output_str = ["PyObject *{0[name]}; {1} c_{0[name]}".format(i, i['type'][:-1]) for i in self.do_outputs]
     172        self.struct_outputs = ";\n    ".join(struct_output_str)
    173173
    174174        #print ("input_params: ", map(split_type, get_input_params(self.do_proto)))
     
    202202    {do_inputs_list};
    203203    // output results
    204     {output_results};
     204    {struct_outputs};
    205205}} Py_{shortname};
    206206"""
     
    380380        return NULL;
    381381    }}""".format(refs = refs, pyparamtypes = pyparamtypes, **self.__dict__)
    382         for p in input_params:
    383             out += """
     382        for input_param in input_params:
     383            out += """
     384
    384385    if (!{pytoaubio}(py_{0[name]}, &(self->{0[name]}))) {{
    385386        return NULL;
    386387    }}""".format(input_param, pytoaubio = pytoaubio_fn[input_param['type']])
     388        out += """
     389
     390    // TODO: check input sizes"""
     391        for output_param in output_params:
     392            out += """
     393
     394    Py_INCREF(self->{0[name]});
     395    if (!{pytoaubio}(self->{0[name]}, &(self->c_{0[name]}))) {{
     396        return NULL;
     397    }}""".format(output_param, pytoaubio = pytoaubio_fn[output_param['type']])
    387398        do_fn = get_name(self.do_proto)
    388399        inputs = ", ".join(['&(self->'+p['name']+')' for p in input_params])
     400        c_outputs = ", ".join(["&(self->c_%s)" % p['name'] for p in self.do_outputs])
    389401        outputs = ", ".join(["self->%s" % p['name'] for p in self.do_outputs])
    390402        out += """
    391403
    392     {do_fn}(self->o, {inputs}, {outputs});
    393 
    394     return (PyObject *) {aubiotonumpy} ({outputs});
     404    {do_fn}(self->o, {inputs}, {c_outputs});
     405
     406    return {outputs};
    395407}}
    396408""".format(
    397409        do_fn = do_fn,
    398         aubiotonumpy = pyfromaubio_fn[output['type']],
    399         inputs = inputs, outputs = outputs,
     410        inputs = inputs, outputs = outputs, c_outputs = c_outputs,
    400411        )
    401412        return out
Note: See TracChangeset for help on using the changeset viewer.