TMgen icon indicating copy to clipboard operation
TMgen copied to clipboard

Build requirements and Cython type correction

Open MirkoZETA opened this issue 7 months ago • 0 comments

This pull request includes three distinct fixes/enhancements:

  1. The setup.py script requires importing numpy and cython early in the script's execution to configure the Cython extensions (numpy.get_include(), cythonize()). However, these packages were not automatically present within the isolated build environment used by pip and the setuptools.build_meta backend for collecting build requirements, even if they were installed in the user's main environment. This fix adds numpy and cython to the [build-system].requires list in pyproject.toml. This explicitly declares them as necessary dependencies for performing the build itself, ensuring they are installed within the isolated build environment before setup.py is evaluated for configuration and build requirements.
  2. The _peak_mean_cycle function in src/tmgen/models.pyx uses numpy.linspace(..., n, ...) where the n argument is expected by numpy.linspace to be an integer. However, the Cython function signature declared n as a double (cdef numpy.ndarray _peak_mean_cycle(double freq, double n, ...)). If n were passed as a non-integer double, this would lead to a TypeError at runtime when calling numpy.linspace. The type of the n parameter in the cdef function signature for _peak_mean_cycle has been changed from double to int.
  3. The lognormal_tm traffic matrix generation function was implemented in src/tmgen/models.pyx but was not properly exposed as part of the public API of the tmgen.models module. This meant it couldn't be reliably imported and used (e.g., from tmgen.models import lognormal_tm).

This change is Reviewable

MirkoZETA avatar May 07 '25 10:05 MirkoZETA