source icon indicating copy to clipboard operation
source copied to clipboard

Rework Spectrum classes to use array.array rather than numpy.array

Open CnlPepper opened this issue 4 years ago • 1 comments

The array() class in faster to construct and can be accessed via pointer in cython, removing the need for costly memoryview creation. Past experiments indicate that switching to array could lead to a 10-20% uplift in performance.

Access to wavelength and samples would return array objects. This would require users to convert the Spectrum arrays to numpy arrays if they need the richer interface. A helper method could be provided e.g. as_numpy() that returns a tuple containing the sample and wavelength arrays.

CnlPepper avatar Mar 28 '21 19:03 CnlPepper

An alternative is to move to C dynamically allocated arrays and internally manage the memory directly. This would avoid the need for checks that the user has not resized the array.array object, that may be necessary if moving to array.

CnlPepper avatar Mar 28 '21 19:03 CnlPepper