Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98628 > unrolled thread
| Started by | shriphanip@gmail.com |
|---|---|
| First post | 2015-11-10 17:09 -0800 |
| Last post | 2015-11-12 10:17 +0100 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
Swig + Numpy.i with a const int16_t pointer shriphanip@gmail.com - 2015-11-10 17:09 -0800
Re: Swig + Numpy.i with a const int16_t pointer Christian Gollwitzer <auriocus@gmx.de> - 2015-11-12 09:46 +0100
Re: Swig + Numpy.i with a const int16_t pointer Christian Gollwitzer <auriocus@gmx.de> - 2015-11-12 10:16 +0100
Re: Swig + Numpy.i with a const int16_t pointer Christian Gollwitzer <auriocus@gmx.de> - 2015-11-12 10:17 +0100
| From | shriphanip@gmail.com |
|---|---|
| Date | 2015-11-10 17:09 -0800 |
| Subject | Swig + Numpy.i with a const int16_t pointer |
| Message-ID | <05ae95fa-68f0-43ca-8b36-04a827c5d878@googlegroups.com> |
I am trying to wrap the following function with SWIG so I can call it from Python. The signature is: ``` int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame, size_t frame_length); ``` I have the following SWIG file: https://gist.github.com/shriphani/92c587ea4c32bafc9d97 At the end of this, I get the following error: webrtc_vad.i:22: Warning 453: Can't apply (int16_t const *IN_ARRAY1,unsigned int DIM1). No typemaps are defined. If I drop the unsigned bit in the signature, then it compiles fine but the function signature is carried as-is (i.e. the function expects an int pointer and all that business). Does anyone have a solution? Regards, Shriphani
[toc] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2015-11-12 09:46 +0100 |
| Message-ID | <n21jga$vea$1@dont-email.me> |
| In reply to | #98628 |
Am 11.11.15 um 02:09 schrieb shriphanip@gmail.com: > I am trying to wrap the following function with SWIG so I can call it from Python. The signature is: > > ``` > int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame, size_t frame_length); > ``` This is thing is an array of 16 bit unsigned integers for input. The closest object in Python is a numpy array. There is a numpy.i available for Python, I'm not sure if it handles this case correctly. If you are unlucky, you need to write your own typemap. Christian
[toc] | [prev] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2015-11-12 10:16 +0100 |
| Message-ID | <n21l9b$4vf$1@dont-email.me> |
| In reply to | #98683 |
Am 12.11.15 um 09:46 schrieb Christian Gollwitzer: > Am 11.11.15 um 02:09 schrieb shriphanip@gmail.com: >> I am trying to wrap the following function with SWIG so I can call it >> from Python. The signature is: >> >> ``` >> int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* >> audio_frame, size_t frame_length); >> ``` > > This is thing is an array of 16 bit unsigned integers for input. The > closest object in Python is a numpy array. There is a numpy.i available > for Python, I'm not sure if it handles this case correctly. If you are > unlucky, you need to write your own typemap. http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html It seems that you can create your own typemap easily using the macros provided by numpy.i; something like %numpy_typemaps(int16_t, NPY_UINT16, int) should be sufficient. Christian
[toc] | [prev] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2015-11-12 10:17 +0100 |
| Message-ID | <n21lba$4vf$2@dont-email.me> |
| In reply to | #98684 |
Am 12.11.15 um 10:16 schrieb Christian Gollwitzer: > Am 12.11.15 um 09:46 schrieb Christian Gollwitzer: >> Am 11.11.15 um 02:09 schrieb shriphanip@gmail.com: >>> I am trying to wrap the following function with SWIG so I can call it >>> from Python. The signature is: >>> >>> ``` >>> int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* >>> audio_frame, size_t frame_length); >>> ``` >> >> This is thing is an array of 16 bit unsigned integers for input. The >> closest object in Python is a numpy array. There is a numpy.i available >> for Python, I'm not sure if it handles this case correctly. If you are >> unlucky, you need to write your own typemap. > > http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html > > It seems that you can create your own typemap easily using the macros > provided by numpy.i; something like > > %numpy_typemaps(int16_t, NPY_UINT16, int) > > should be sufficient. That should be %numpy_typemaps(int16_t, NPY_INT16, int) of course.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web