Files
rdkit/Code/GraphMol
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-17 05:52:27 +02:00
2025-10-14 19:15:37 +02:00
2019-10-10 20:18:43 +09:00
2019-10-10 20:18:43 +09:00
2026-01-03 06:42:09 +01:00
2025-03-20 07:40:33 +01:00
2026-02-05 17:24:20 +01:00
2023-11-15 06:45:42 +01:00
2025-10-08 16:08:01 +02:00
2018-07-25 09:14:17 +02:00
2022-07-11 11:20:03 +02:00
2025-03-17 19:54:15 +01:00
2021-07-09 15:06:54 +02:00
2018-07-25 09:14:17 +02:00
2019-10-10 20:18:43 +09:00
2025-07-25 14:33:32 +02:00
2020-09-02 04:51:20 +02:00
2023-12-22 04:58:18 +01:00
2019-12-31 06:43:27 +01:00
2025-05-18 08:14:05 +02:00
2025-12-09 15:06:29 +01:00