Skip to content

Commit

Permalink
Merge b853ec8 into 1c866e7
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Feb 15, 2021
2 parents 1c866e7 + b853ec8 commit f4d47fb
Show file tree
Hide file tree
Showing 7 changed files with 3,764 additions and 14 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Expand Up @@ -12,8 +12,4 @@ build
*.cpp
.coverage
src/george/george_version.py
src/george/kernels.py
src/george/kerneldefs.pxd
src/george/solvers/kerneldefs.pxd
src/george/include/george/kernels.h
kernels/MyLocalGaussian.yml
4 changes: 4 additions & 0 deletions MANIFEST.in
@@ -1,5 +1,9 @@

graft vendor/eigen/Eigen

exclude .*
prune .github
prune docs
prune paper
prune kernels
prune templates
49 changes: 49 additions & 0 deletions generate_kernels.py
@@ -0,0 +1,49 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import glob
import yaml
from jinja2 import Template


def compile_kernels(fns):
template_dir = "templates"
output_dir = os.path.join("src", "george")

with open(os.path.join(template_dir, "parser.h")) as f:
PARSER_TEMPLATE = Template(f.read())
with open(os.path.join(template_dir, "kernels.h")) as f:
CPP_TEMPLATE = Template(f.read())
with open(os.path.join(template_dir, "kernels.py")) as f:
PYTHON_TEMPLATE = Template(f.read())

specs = []
for i, fn in enumerate(fns):
with open(fn, "r") as f:
spec = yaml.load(f.read(), Loader=yaml.FullLoader)
print("Found kernel '{0}'".format(spec["name"]))
spec["index"] = i
spec["reparams"] = spec.get("reparams", {})
specs.append(spec)
print("Found {0} kernel specifications".format(len(specs)))

fn = os.path.join(output_dir, "include", "george", "parser.h")
with open(fn, "w") as f:
print("Saving parser to '{0}'".format(fn))
f.write(PARSER_TEMPLATE.render(specs=specs))
fn = os.path.join(output_dir, "include", "george", "kernels.h")
with open(fn, "w") as f:
print("Saving C++ kernels to '{0}'".format(fn))
f.write(CPP_TEMPLATE.render(specs=specs))
fn = os.path.join(output_dir, "kernels.py")
with open(fn, "w") as f:
print("Saving Python kernels to '{0}'".format(fn))
f.write(PYTHON_TEMPLATE.render(specs=specs))


if __name__ == "__main__":
# If the kernel specifications are included (development mode) re-compile
# them first.
kernel_specs = glob.glob(os.path.join("kernels", "*.yml"))
compile_kernels(kernel_specs)
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=40.6.0", "wheel", "setuptools_scm[toml]", "PyYAML", "jinja2", "pybind11"]
requires = ["setuptools>=40.6.0", "wheel", "setuptools_scm[toml]", "pybind11"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
Expand Down
9 changes: 0 additions & 9 deletions setup.py
Expand Up @@ -52,15 +52,6 @@ def compile_kernels(fns):
if not os.path.exists(os.path.join(localincl, "eigen", "Eigen", "Core")):
raise RuntimeError("couldn't find Eigen headers")

# If the kernel specifications are included (development mode) re-compile
# them first.
kernel_specs = glob.glob(os.path.join("kernels", "*.yml"))
if len(kernel_specs):
print("Compiling kernels")
compile_kernels(kernel_specs)
if "kernels" in sys.argv:
sys.exit()

include_dirs = [
os.path.join("src", "george", "include"),
os.path.join(localincl, "eigen"),
Expand Down

0 comments on commit f4d47fb

Please sign in to comment.