Files
rdkit/Code/DataStructs
Yakov Pechersky 872b054d5c Defer numpy initialization to first use (#9127)
* Defer numpy initialization to first use in rdchem, rdmolops, cDataStructs

`from rdkit import Chem` unconditionally bootstrapped numpy (~120ms) via
import_array()/boost::python::numpy::initialize() in module init functions,
even when no numpy-dependent APIs were called. This is costly in cold-start
environments like AWS Lambda.

Move numpy initialization behind lazy guards (static bool + first-call init)
in rdchem.so, rdmolops.so, and cDataStructs.so. Numpy now loads only when
an API that actually needs it is invoked (GetDistanceMatrix, GetPositions,
SetPositions, GetAdjacencyMatrix, ConvertToNumpyArray, etc.).

Also change Conformer::SetPos to accept python::object instead of
np::ndarray to prevent Boost.Python from requiring numpy type conversion
before the lazy guard runs.

Adds test_lazy_numpy.py with subprocess-based tests verifying:
- `from rdkit import Chem` does not load numpy
- SmilesToMol/MolToSmiles work without numpy
- numpy loads on demand when array APIs are called

* skip inchi tests if not available

* switch to threadsafe once_flag, like elsewhere

* finish ifdef style

* switch to magic static style

* Revert "switch to magic static style"

This reverts commit 7300188db7.
2026-02-23 18:42:42 +01:00
..
2025-10-08 16:08:01 +02:00
2019-04-16 12:05:47 -04:00
2026-01-03 06:42:29 +01:00
2018-07-25 09:14:17 +02:00
2019-04-16 12:05:47 -04:00
2026-01-03 06:42:29 +01:00
2022-04-12 13:53:07 +02:00
2024-06-20 09:27:27 +02:00
2024-06-20 09:27:27 +02:00
2024-06-20 09:27:27 +02:00
2025-10-08 16:08:01 +02:00