On ensuring the integrity between a handle and its interface arrays

7 views
Skip to first unread message

Ghislain Vaillant

unread,
Mar 29, 2016, 3:16:24 PM3/29/16
to python-cffi
Dear python-cffi community,

I made a Python package wrapping the FFTW library to a somewhat Pythonic API using CFFI:

https://github.com/ghisvail/fftw-cffi

The library exposes one structure (fftw_plan) though an opaque pointer, which is fed with the input
and output data pointer at initialization (via a call to fftw_plan_dft). The execution of the FFTW can
then be launched on these arrays with a call to fftw_plan_execute. However, the library also supports
operating on different arrays with a call to fftw_execute_dft, provided these arrays follow the same layout
as the ones used at initialization, which the user is responsible for checking.

Alongside the low-level wrappers to these methods, I want to provide a higher-level class which would
provide some additional safety, specially for handling operations on different arrays. The class is defined
here:

https://github.com/ghisvail/fftw-cffi/blob/master/fftw/fftw.py

And aggregates a handle to a plan and two interface arrays. As things stand now, some integrity checks are
done at construct time on the interface arrays but nothing is enforced at runtime when calling.

I suspect this sort of pattern, i.e. only allowing the interface arrays to be updated with arrays of exact same
layout, can probably be achieved with some sort of descriptor? Or perhaps a simpler solution than I did not
think of? Any examples?

Many thanks,
Ghis
Reply all
Reply to author
Forward
0 new messages