diff --git a/doc/index.rst b/doc/index.rst index d59ae5ff6b8aced394019dacc988c44701965c81..ad8d4111a216de8868d62f628f39de839f78086b 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -17,9 +17,9 @@ Contents :maxdepth: 2 primitives + mappers utilities algorithms - mappers geometric-algebra misc diff --git a/doc/utilities.rst b/doc/utilities.rst new file mode 100644 index 0000000000000000000000000000000000000000..48794784905c795d0dd9cdbdab559beb26dd05b5 --- /dev/null +++ b/doc/utilities.rst @@ -0,0 +1,41 @@ +Utilities for dealing with exressions +===================================== + +Parser +------ + +.. currentmodule:: pymbolic + +.. function:: parse(expr_str) + + Return a :class:`pymbolic.primitives.Expression` tree corresponding to *expr_str*. + +The parser is also relatively easy to extend. See the source code of the following +class. + +.. automodule:: pymbolic.parser + +.. autoclass:: Parser + +Compiler +-------- + +.. automodule:: pymbolic.compiler + +.. autoclass:: CompiledExpression + + .. method:: __call__(*args) + + +:mod:`sympy` interface +---------------------- + +.. automodule:: pymbolic.sympy_interface + +.. class:: SympyToPymbolicMapper + + .. method:: __call__(expr) + +.. class:: PymbolicToSympyMapper + + .. method:: __call__(expr) diff --git a/pymbolic/compiler.py b/pymbolic/compiler.py index 466554c2f57c2cd3f6cd4790490aac36f210371a..b3fa62690ca6d23bcc78c373132b6c95e432889e 100644 --- a/pymbolic/compiler.py +++ b/pymbolic/compiler.py @@ -99,13 +99,18 @@ class CompileMapper(StringifyMapper): class CompiledExpression: - """This class encapsulates a compiled expression. + """This class encapsulates an expression compiled into Python bytecode + for faster evaluation. - The main reason for its existence is the fact that a dynamically-constructed - lambda function is not picklable. + Its instances (unlike plain lambdas) are pickleable. """ def __init__(self, expression, variables = []): + """ + :arg variables: The first arguments to be used for the compiled function. + All variables used by the expression and not present here are added + in alphabetical order. + """ import pymbolic.primitives as primi self._Expression = expression diff --git a/setup.py b/setup.py index 137ef886804f41a565584be734d90706b89cc267..3288524c0e794a29b7316e6e453c4d7fe5e1a284 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,12 @@ distribute_setup.use_setuptools() from setuptools import setup +try: + from distutils.command.build_py import build_py_2to3 as build_py +except ImportError: + # 2.x + from distutils.command.build_py import build_py + ver_dic = {} version_file = open("pymbolic/version.py") try: @@ -27,6 +33,13 @@ setup(name="pymbolic", 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + # We use conditional expressions, so 2.5 is the bare minimum. + 'Programming Language :: Python :: 2.5', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Mathematics', 'Topic :: Software Development :: Libraries', @@ -43,4 +56,5 @@ setup(name="pymbolic", 'pytest>=2.3', ], - ) + # 2to3 invocation + cmdclass={'build_py': build_py}) diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index 684fc836defb5e1b5c2f48b88e38cd01eca798de..b9b9a80f1ef4667f24a61c87a4e8c407b84a5dbd 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -245,8 +245,7 @@ def test_geometric_algebra(dims): a*(b*c)) assert ((a^b)^c).close_to( a^(b^c)) - #assert ((a|b)|c).close_to( - #a|(b|c)) + # The inner product is not associative. # scalar product assert ( (c*b).project(0) ) .close_to( b.scalar_product(c) )