-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- merge cython source files (reduce disk overhead from generated boilerplate code) - exclude unused Python implementation of core algorithm from distributions
- Loading branch information
1 parent
cdff96c
commit 5dc7c07
Showing
14 changed files
with
362 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
import os | ||
from distutils.extension import Extension | ||
from pathlib import Path | ||
|
||
import numpy | ||
import numpy as np | ||
from Cython.Build import cythonize | ||
from setuptools import setup | ||
|
||
SRC_DIR = Path(__file__).parent / "src" / "gpgi" | ||
|
||
def make_ext(path: str) -> Extension: | ||
name, _ = os.path.splitext(path) | ||
name = name.replace("/", ".") | ||
|
||
return Extension( | ||
name, | ||
sources=[f"src/{path}"], | ||
include_dirs=[numpy.get_include()], | ||
define_macros=[ | ||
# keep in sync with runtime requirements (pyproject.toml) | ||
("NPY_TARGET_VERSION", "NPY_1_23_API_VERSION"), | ||
("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"), | ||
], | ||
) | ||
|
||
|
||
setup( | ||
ext_modules=cythonize( | ||
if os.getenv("GPGI_PY_LIB", "0").lower() in ("1", "true"): | ||
if not SRC_DIR.joinpath("_lib.py").exists(): | ||
raise RuntimeError( | ||
"GPGI's pure Python implementation can only be built " | ||
"from the development version in editable mode." | ||
) | ||
ext_modules = [] | ||
for sofile in SRC_DIR.glob("*.so"): | ||
os.remove(sofile) | ||
else: | ||
ext_modules = cythonize( | ||
[ | ||
make_ext("gpgi/clib/_indexing.pyx"), | ||
make_ext("gpgi/clib/_deposition_methods.pyx"), | ||
Extension( | ||
"gpgi._lib", | ||
sources=["src/gpgi/_lib.pyx"], | ||
include_dirs=[np.get_include()], | ||
define_macros=[ | ||
# keep in sync with runtime requirements (pyproject.toml) | ||
("NPY_TARGET_VERSION", "NPY_1_23_API_VERSION"), | ||
("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"), | ||
], | ||
) | ||
], | ||
compiler_directives={"language_level": 3}, | ||
), | ||
) | ||
) | ||
|
||
setup(ext_modules=ext_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
|
||
from .types import Dataset, FieldMap, Geometry, Grid, ParticleSet | ||
|
||
__version__ = "1.0.0" | ||
|
||
|
||
def load( | ||
*, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import numpy as np | ||
from numpy.typing import NDArray | ||
|
||
NDArrayReal = NDArray[np.float64 | np.float32] | ||
NDArrayUInt = NDArray[np.uint16] | ||
|
||
def _index_particles( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
dx: NDArrayReal, | ||
out: NDArrayUInt, | ||
) -> None: ... | ||
def _deposit_ngp_1D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_ngp_2D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_ngp_3D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_cic_1D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_cic_2D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_cic_3D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_tsc_1D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_tsc_2D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... | ||
def _deposit_tsc_3D( | ||
cell_edges_x1: NDArrayReal, | ||
cell_edges_x2: NDArrayReal, | ||
cell_edges_x3: NDArrayReal, | ||
particles_x1: NDArrayReal, | ||
particles_x2: NDArrayReal, | ||
particles_x3: NDArrayReal, | ||
field: NDArrayReal, | ||
weight_field: NDArrayReal, | ||
hci: NDArrayUInt, # dim: 2 | ||
out: NDArrayReal, | ||
) -> None: ... |
Oops, something went wrong.