Closed seisman closed 6 days ago
Comparing ctypesarray
(09ac0a0) with main
(2454aa6)
⚡ 2
improvements
✅ 99
untouched benchmarks
Benchmark | main |
ctypesarray |
Change | |
---|---|---|---|---|
⚡ | test_sph2grd_no_outgrid |
323.6 ms | 289.1 ms | +11.95% |
⚡ | test_sphinterpolate_no_outgrid |
71.2 ms | 39 ms | +82.61% |
We can also declare it as a bug, since the data dtype was not preserved in the old version.
Description of proposed changes
There are two different ways to convert a ctypes array to a numpy array with a specific shape:
np.reshape(ctypes_array[:120], (10, 12))
np.ctypeslib.as_array(ctypes_array, (10, 12))
Currently we use option 1 but option 2 is better. In this PR, we use option 2.
As shown in the benchmarks below. Option 2 has at least two pros:
Also need to be cautious that we need to make a copy of the ctypes/numpy array, since the memory of the array is allocated by GMT and will be freed when exiting the session.