Hi Bill,
thanks for your response. So the function I am actually trying to wrap is:
static inline void
lilv_instance_connect_port(LilvInstance* instance,
uint32_t port_index,
void* data_location)
It just passes on the pointer to the data_location (the audio buffer) and
then you call lilv_instance_run(int nframes) where nframes could be the
dimension of your buffer, or possibly less if you really want.
So following your recommendations I tried to make a wrapper function:
lilv_instance_pyconnect(LilvInstance* instance,
uint32_t port_index,
float* data_location, int unused)
and then a typemap following what is in numpy.i :
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
fragment="NumPy_Macros")
(UNUSED1* UNUSED2, UNUSED3 UNUSED4, DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
{
$1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
DATA_TYPECODE);
}
%typemap(in,
fragment="NumPy_Fragments")
(UNUSED1* UNUSED2, UNUSED3 UNUSED4, DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
(PyArrayObject* array=NULL, int i=1)
{
array = obj_to_array_no_conversion($input, DATA_TYPECODE);
if (!array || !require_dimensions(array,1) || !require_contiguous(array)
|| !require_native(array)) SWIG_fail;
$1 = (DATA_TYPE*) array_data(array);
$2 = 1;
for (i=0; i < array_numdims(array); ++i) $2 *= array_size(array,i);
}
which I tried to apply with:
%apply (LilvInstance* instance, uint32_t port_index, float*
INPLACE_ARRAY1, int DIM1) {(LilvInstance* instance, uint32_t
port_index, float* data_location, int unused)}
But it doesn’t seem to do anything an I just get a TypeError.
You might have noticed I am a little bit out of my depth…
Ta,
Kaspar
On 22 November 2013 22:40, Bill Spotz <[email protected]> wrote:
> Kaspar,
>
> Yes, in order for numpy.i typemaps to work, you need to provide
> dimensions. How is lilv_test(float*) supposed to know how large the float
> array is? Is it actually a method where the class knows the size? In
> cases where dimensions are not passed through the argument list, you have
> two options:
>
> 1. Write a proxy function that does have dimension arguments and calls
> the original function, and then wrap that instead of the original function.
>
> 2. Use the functions and macros in numpy.i to write new typemaps that
> work for your case.
>
> -Bill
>
> On Nov 22, 2013, at 3:30 PM, Kaspar Emanuel wrote:
>
> > Hey,
> > I am trying to improve the Lilv Python bindings to include numpy.i to
> allow for creation and verification of audio test buffers using NumPy.
> >
> > I am just trying to get something working at the moment so I am tring to
> wrap a test function.
> >
> > static inline void
> > lilv_test(float* data_location){}
> >
> > and I have in lilv.i:
> >
> > %apply (float* INPLACE_ARRAY1) {(float* data_location)};
> > This doesn’t produce any warnings or anything but when I try and use it
> from Python I get:
> >
> > TypeError: in method 'lilv_test', argument 1 of type 'float *'
> > What does work is if I have:
> >
> > lilv_test(float* data_location, int n){}
> > and
> >
> > %apply (float* INPLACE_ARRAY1, int DIM1) {(float* data_location, int n)};
> > but this doesn’t fit very well with the functions I eventually want to
> wrap, as they don’t have a dimension argument.
> >
> > Is it not possible to use INPLACE_ARRAY1 without a dimension?
> >
> > Thanks for any help,
> >
> > Kaspar
> >
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > [email protected]
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> ** Bill Spotz **
> ** Sandia National Laboratories Voice: (505)845-0170 **
> ** P.O. Box 5800 Fax: (505)284-0154 **
> ** Albuquerque, NM 87185-0370 Email: [email protected] **
>
>
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion