QNDArray: A Numpy Clone for C++/Qt
While Numpy/Scipy is an attractive implementation platform for many algorithms, in some cases C++ is mandated by a customer. However, a foundation of numpy's behavior is the notion of reference-counted instances, and implementing an efficient, cross-platform mechanism for reference counting is no trivial prerequisite.
The reference counting mechanisms already implemented in the Qt C++ toolkit provide a cross-platform foundation upon which a numpy-like array class can be built. In this talk one such implementation is discussed, QNDArray. In fact, by mimicking the numpy behaviors, the job of implementing QNDArray became much easier, as the task of "defining the behavior" became "adopting the behavior," to include function names.
In particular, the following aspects of the implementation were found to be tricky and deserve discussion in this presentation:
- slicing multidimensional arrays given the limitations of operator in C++,
- partial specialization
implicit vs. explicit data sharing in Qt QNDArray has been deployed in scientific research applications and currently has the following features:
bit-packed boolean arrays
- nascent masked array support
- unit test suite that validates QNDArray behavior against numpy behavior
- bounds checking with Q_ASSERT() (becomes a no-op in release mode)
- memmap()ed arrays via QFile::map()
- easily integrated as a QVariant value, leading to a natural mapping from QVariantMap to Python dict.
- float16 implementation including in-place compare
The author has approval from his management to submit the source code for QNDArray to the Qt Project and plans to have it freely available for download via http://qt.gitorious.org/ before the SciPy conference begins.