-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added python testing ready for development
- Loading branch information
1 parent
23ed1a4
commit bbd714f
Showing
23 changed files
with
201 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[build-system] | ||
requires = [ | ||
"setuptools>=42", | ||
"wheel", | ||
"pybind11>=2.6.0", | ||
] | ||
|
||
build-backend = "setuptools.build_meta" |
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 @@ | ||
from stator.core import * |
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,32 @@ | ||
#include <stator/string.hpp> | ||
#include <stator/symbolic/ad.hpp> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl_bind.h> | ||
|
||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
PYBIND11_MODULE(core, m) | ||
{ | ||
py::class_<sym::Expr>(m, "Expr") | ||
.def(py::init<std::string>()) | ||
.def(py::init<int>()) | ||
.def(py::init<double>()) | ||
.def("__repr__", +[](const sym::Expr& self) { return stator::repr(self); }) | ||
.def("__str__", +[](const sym::Expr& self) { return stator::repr(self); }) | ||
.def("latex", +[](const sym::Expr& self) { return stator::repr<stator::ReprConfig<stator::Latex_output> >(self); }) | ||
.def("simplify", +[](const sym::Expr& self) { return sym::simplify(self); }) | ||
.def("__add__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l+r); }) | ||
.def("__radd__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l+r); }) | ||
.def("__sub__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l-r); }) | ||
.def("__rsub__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l-r); }) | ||
.def("__mul__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l*r); }) | ||
.def("__rmul__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l*r); }) | ||
.def("__div__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l/r); }) | ||
.def("__rdiv__", +[](const sym::Expr& l, const sym::Expr& r) { return sym::Expr(l/r); }) | ||
.def(py::self / py::self) | ||
; | ||
|
||
py::implicitly_convertible<int, sym::Expr>(); | ||
py::implicitly_convertible<double, sym::Expr>(); | ||
} |
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,2 @@ | ||
[pytest] | ||
norecursedirs = extern build |
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,2 @@ | ||
[aliases] | ||
test=pytest |
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,50 @@ | ||
from setuptools import setup, find_packages | ||
import sys,os | ||
|
||
# Track down the pybind11 directory, add it to path, import | ||
# requirements, then remove it again. | ||
DIR = os.path.abspath(os.path.dirname(__file__)) | ||
sys.path.append(os.path.join(DIR, "extern", "pybind11")) | ||
from pybind11.setup_helpers import Pybind11Extension, build_ext | ||
from pybind11 import get_cmake_dir | ||
del sys.path[-1] | ||
|
||
|
||
__version__ = "0.0.1" | ||
|
||
# The main interface is through Pybind11Extension. | ||
# * You can add cxx_std=11/14/17, and then build_ext can be removed. | ||
# * You can set include_pybind11=false to add the include directory yourself, | ||
# say from a submodule. | ||
# | ||
# Note: | ||
# Sort input source files if you glob sources to ensure bit-for-bit | ||
# reproducible builds (https://github.com/pybind/python_example/pull/53) | ||
|
||
ext_modules = [ | ||
Pybind11Extension("stator.core", | ||
["pysrc/stator/core.cpp"], | ||
# Example: passing in the version to the compiled code | ||
define_macros = [('VERSION_INFO', __version__)], | ||
include_dirs=['.', 'extern/eigen'] | ||
), | ||
] | ||
|
||
setup( | ||
name="stator", | ||
version=__version__, | ||
author="Marcus Bannerman", | ||
author_email="[email protected]", | ||
url="https://github.com/toastedcrumpets/stator", | ||
description="The python stator interface.", | ||
long_description="", | ||
packages=find_packages('pysrc'), | ||
ext_modules=ext_modules, | ||
extras_require={"test": "pytest"}, | ||
# Currently, build_ext only provides an optional "highest supported C++ | ||
# level" feature, but in the future it may provide more features. | ||
cmdclass={"build_ext": build_ext}, | ||
setup_requires=['pytest-runner'], | ||
tests_require=['pytest'], | ||
zip_safe=False, | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,10 @@ | ||
import unittest | ||
import stator | ||
import stator.core | ||
|
||
class Testfit(unittest.TestCase): | ||
def test_interface(self): | ||
e = stator.core.Expr("1+1") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |