Changeset ede5d38 for python/ext/py-cvec.c
- Timestamp:
- Apr 29, 2016, 9:19:28 PM (9 years ago)
- 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:
- 1ee5e21
- Parents:
- ee092a8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/py-cvec.c
ree092a8 rede5d38 21 21 22 22 static char Py_cvec_doc[] = "cvec object"; 23 24 25 PyObject * 26 new_py_cvec(uint_t length) { 27 Py_cvec* vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 28 npy_intp dims[] = { length / 2 + 1, 1 }; 29 vec->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 30 vec->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 31 vec->length = length / 2 + 1; 32 return (PyObject*)vec; 33 } 23 34 24 35 PyObject * … … 40 51 if (PyObject_TypeCheck (input, &Py_cvecType)) { 41 52 Py_cvec * in = (Py_cvec *)input; 42 if (in->norm == NULL) {43 npy_intp dims[] = { in->length, 1 };44 in->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);45 }46 if (in->phas == NULL) {47 npy_intp dims[] = { in->length, 1 };48 in->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);49 }50 53 i->norm = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->norm), 0); 51 54 i->phas = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->phas), 0); … … 92 95 Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds) 93 96 { 94 self->norm = NULL; 95 self->phas = NULL; 97 npy_intp dims[] = { self->length, 1 }; 98 self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 99 self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 96 100 return 0; 97 101 } … … 100 104 Py_cvec_del (Py_cvec * self) 101 105 { 102 Py_ XDECREF(self->norm);103 Py_ XDECREF(self->phas);106 Py_DECREF(self->norm); 107 Py_DECREF(self->phas); 104 108 Py_TYPE(self)->tp_free ((PyObject *) self); 105 109 } … … 135 139 Py_cvec_get_norm (Py_cvec * self, void *closure) 136 140 { 137 // if it norm hasn't been created, create it now 138 if (self->norm == NULL) { 139 npy_intp dims[] = { self->length, 1 }; 140 self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 141 } 141 // we want self->norm to still exist after our caller return it 142 142 Py_INCREF(self->norm); 143 143 return (PyObject*)(self->norm); … … 147 147 Py_cvec_get_phas (Py_cvec * self, void *closure) 148 148 { 149 // if it phas hasn't been created, create it now 150 if (self->phas == NULL) { 151 npy_intp dims[] = { self->length, 1 }; 152 self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 153 } 149 // we want self->phas to still exist after our caller return it 154 150 Py_INCREF(self->phas); 155 151 return (PyObject *)(self->phas);
Note: See TracChangeset
for help on using the changeset viewer.