A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://scikit-learn.org/dev/developers/../developers/../developers/cython.html below:

Cython Best Practices, Conventions and Knowledge — scikit-learn 1.8.dev0 documentation

Cython Best Practices, Conventions and Knowledge#

This document contains tips to develop Cython code in scikit-learn.

Tips for developing with Cython in scikit-learn# Tips to ease development# Tips for performance# Using OpenMP#

Since scikit-learn can be built without OpenMP, it’s necessary to protect each direct call to OpenMP.

The _openmp_helpers module, available in sklearn/utils/_openmp_helpers.pyx provides protected versions of the OpenMP routines. To use OpenMP routines, they must be cimported from this module and not from the OpenMP library directly:

from sklearn.utils._openmp_helpers cimport omp_get_max_threads
max_threads = omp_get_max_threads()

The parallel loop, prange, is already protected by cython and can be used directly from cython.parallel.

Types#

Cython code requires to use explicit types. This is one of the reasons you get a performance boost. In order to avoid code duplication, we have a central place for the most used types in sklearn/utils/_typedefs.pyd. Ideally you start by having a look there and cimport types you need, for example

from sklearn.utils._typedefs cimport float32, float64

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4