UXsim icon indicating copy to clipboard operation
UXsim copied to clipboard

Specify dtypes for NumPy arrays

Open EwoutH opened this issue 1 year ago • 4 comments

The default dtype in NumPy is float64, or a 64-bit floating point number. These are very large and not that fast in calculations.

In this commit a dtype is defined for every array, with a fitting type and precision. Often float32 is used, which is the fastest in calculations (fully hardware accelerated, often 2x faster than float64) and has only half the memory footprint of float64. Sometimes an even faster int or uint (for counts) or bool (for masks) is used. Contrary to floats, smaller ints are faster than the larger ints, so often int16 (which covers -32768 to 32767) or uint16 (0 to 65535) is often enough for counters.

After #144, this further reduced memory usage from 471 MB to 407 MB.

See for reference: https://numpy.org/doc/stable/user/basics.types.html

Part of: https://github.com/toruseo/UXsim/issues/143.

EwoutH avatar Sep 24 '24 19:09 EwoutH