Changeset 93004d5
- Timestamp:
- Jul 12, 2012, 1:38:18 AM (12 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:
- f6cbefe
- Parents:
- 83b385f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/aubioproxy.c
r83b385f r93004d5 12 12 if (PyArray_Check(input)) { 13 13 14 // we got an array, convert it to an fvec 14 // we got an array, convert it to an fvec 15 15 if (PyArray_NDIM ((PyArrayObject *)input) == 0) { 16 16 PyErr_SetString (PyExc_ValueError, "input array is a scalar"); … … 34 34 35 35 // vec = new_fvec (vec->length); 36 // no need to really allocate fvec, just its struct member 36 // no need to really allocate fvec, just its struct member 37 37 vec = (fvec_t *)malloc(sizeof(fvec_t)); 38 38 vec->length = PyArray_SIZE ((PyArrayObject *)array); … … 62 62 Py_cvec * 63 63 PyAubio_CCvecToPyCvec (cvec_t * input) { 64 Py_cvec *vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 64 Py_cvec *vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 65 65 vec->length = input->length; 66 66 vec->o = input; … … 98 98 fmat_t * 99 99 PyAubio_ArrayToCFmat (PyObject *input) { 100 PyObject *array; 101 fmat_t *mat; 102 uint_t i; 103 if (input == NULL) { 104 PyErr_SetString (PyExc_ValueError, "input array is not a python object"); 105 goto fail; 106 } 107 // parsing input object into a Py_fvec 108 if (PyArray_Check(input)) { 109 110 // we got an array, convert it to an fvec 111 if (PyArray_NDIM ((PyArrayObject *)input) == 0) { 112 PyErr_SetString (PyExc_ValueError, "input array is a scalar"); 113 goto fail; 114 } else if (PyArray_NDIM ((PyArrayObject *)input) > 2) { 115 PyErr_SetString (PyExc_ValueError, 116 "input array has more than two dimensions"); 117 goto fail; 118 } 119 120 if (!PyArray_ISFLOAT ((PyArrayObject *)input)) { 121 PyErr_SetString (PyExc_ValueError, "input array should be float"); 122 goto fail; 123 } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) { 124 PyErr_SetString (PyExc_ValueError, "input array should be float32"); 125 goto fail; 126 } else { 127 // input data type is float32, nothing else to do 128 array = input; 129 } 130 131 // no need to really allocate fvec, just its struct member 132 mat = (fmat_t *)malloc(sizeof(fmat_t)); 133 mat->length = PyArray_DIM ((PyArrayObject *)array, 1); 134 mat->height = PyArray_DIM ((PyArrayObject *)array, 0); 135 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height); 136 for (i=0; i< mat->height; i++) { 137 mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i); 138 } 139 140 } else if (PyObject_TypeCheck (input, &PyList_Type)) { 141 PyErr_SetString (PyExc_ValueError, "can not convert list to fmat"); 142 return NULL; 143 } else { 144 PyErr_SetString (PyExc_ValueError, "can only accept matrix of float as input"); 145 return NULL; 146 } 147 148 return mat; 149 150 fail: 100 151 return NULL; 101 152 }
Note: See TracChangeset
for help on using the changeset viewer.