Skip to content
Snippets Groups Projects
Commit 9c0dc68f authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Bump version, document disable_subscript_by_getitem

parent 8e940fad
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXBUILD = python `which sphinx-build`
PAPER =
BUILDDIR = _build
......
pre {
line-height: 100%;
line-height: 110%;
}
.footer {
......@@ -23,17 +23,17 @@ code {
}
h1 {
padding-bottom:5px;
padding-bottom:7px;
border-bottom: 1px solid #ccc;
}
h2 {
padding-bottom:1px;
padding-bottom:5px;
border-bottom: 1px solid #ccc;
}
h3 {
padding-bottom:1px;
padding-bottom:5px;
border-bottom: 1px solid #ccc;
}
......
{% extends "!layout.html" %}
{% set css_files = css_files + ['_static/akdoc.css']%}
{% set bootswatch_css_custom = ['_static/akdoc.css']%}
......@@ -31,7 +31,7 @@ extensions = [
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode'
#'sphinx.ext.viewcode'
]
# Add any paths that contain templates here, relative to this directory.
......
......@@ -134,7 +134,7 @@ import pymbolic.mapper.distributor
import pymbolic.mapper.flattener
import pymbolic.primitives
from pymbolic.polynomial import Polynomial
from pymbolic.polynomial import Polynomial # noqa
var = pymbolic.primitives.Variable
variables = pymbolic.primitives.variables
......
......@@ -334,7 +334,7 @@ class IdentityMapper(Mapper):
)
def map_subscript(self, expr, *args):
return expr.__class__(
return type(expr)(
self.rec(expr.aggregate, *args),
self.rec(expr.index, *args))
......
......@@ -25,6 +25,8 @@ THE SOFTWARE.
import pymbolic.traits as traits
__doc__ = """
.. autofunction:: disable_subscript_by_getitem
Expression base class
---------------------
......@@ -37,6 +39,13 @@ Expression base class
The :class:`pymbolic.mapper.Mapper` method called for objects of
this type.
.. method:: __getitem__
Deprecated, see :func:`disable_subscript_by_getitem`. Use :meth:`index`
instead.
.. automethod:: index
.. automethod:: stringifier
.. automethod:: __eq__
......@@ -178,10 +187,32 @@ _SUBSCRIPT_BY_GETITEM = True
def disable_subscript_by_getitem():
"""In prior versions of :mod:`pymbolic`, directly subscripting an :class:`Expression`
subclass generated a :class:`Subscript`. For various reasons, this was a
very bad idea. For example, the following code snippet would result in an
infinite loop::
for el in expr:
print(el)
:mod:`numpy` does similar things under the hodd, leading to hard-to-debug
infinite loops. As a result, this behavior is being deprecated. In Pymbolic
2016.x, it will disappear entirely. It can also be disabled by this
function. Once disabled, it cannot be reenabled.
See also :meth:`Expression.index`.
.. versionadded:: 2014.3
"""
global _SUBSCRIPT_BY_GETITEM
_SUBSCRIPT_BY_GETITEM = False
del Expression.__getitem__
try:
del Expression.__getitem__
except AttributeError:
# Yay, somebody did the sane thing before us.
pass
class Expression(object):
......@@ -395,6 +426,11 @@ class Expression(object):
return NotImplemented
def index(self, subscript):
"""Return an expression representing ``self[subscript]``.
.. versionadded:: 2014.3
"""
if subscript == ():
return self
else:
......
VERSION = (2014, 2)
VERSION = (2014, 3)
VERSION_STATUS = ""
VERSION_TEXT = ".".join(str(x) for x in VERSION) + VERSION_STATUS
......@@ -22,9 +22,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import pymbolic
import pymbolic.primitives as prim
import pytest
from pymbolic.mapper import IdentityMapper
try:
......@@ -33,6 +35,8 @@ except NameError:
from functools import reduce
pymbolic.disable_subscript_by_getitem()
def test_integer_power():
from pymbolic.algorithm import integer_power
......@@ -250,6 +254,7 @@ def test_mappers():
WalkMapper()(expr)
DependencyMapper()(expr)
# {{{ geometric algebra
@pytest.mark.parametrize("dims", [2, 3, 4, 5])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment