raysect / source

The main source repository for the Raysect project.
http://www.raysect.org
BSD 3-Clause "New" or "Revised" License
86 stars 23 forks source link

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

Open CnlPepper opened 3 years ago

CnlPepper commented 3 years ago

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 commented 3 years ago

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.