Skip to content

Commit

Permalink
Partial fix for issue #434 as suggested by timbrist
Browse files Browse the repository at this point in the history
  • Loading branch information
robbmcleod committed Jun 28, 2023
1 parent d631645 commit 26d7e10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
23 changes: 8 additions & 15 deletions numexpr/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@

from numexpr import interpreter

class Expression(object):
def __init__(self):
object.__init__(self)
class Expression():

def __getattr__(self, name):
if name.startswith('_'):
Expand Down Expand Up @@ -271,17 +269,13 @@ def rtruediv_op(a, b):

@ophelper
def pow_op(a, b):
if (b.astKind in ('int', 'long') and
a.astKind in ('int', 'long') and
numpy.any(b.value < 0)):

raise ValueError(
'Integers to negative integer powers are not allowed.')

if allConstantNodes([a, b]):
return ConstantNode(a.value ** b.value)

if isinstance(b, ConstantNode):
x = b.value
if ( a.astKind in ('int', 'long') and
b.astKind in ('int', 'long') and x < 0) :
raise ValueError(
'Integers to negative integer powers are not allowed.')
if get_optimization() == 'aggressive':
RANGE = 50 # Approximate break even point with pow(x,y)
# Optimize all integral and half integral powers in [-RANGE, RANGE]
Expand Down Expand Up @@ -379,7 +373,7 @@ def multiply(x, y):
}


class ExpressionNode(object):
class ExpressionNode():
"""
An object that represents a generic number object.
Expand All @@ -389,7 +383,6 @@ class ExpressionNode(object):
astType = 'generic'

def __init__(self, value=None, kind=None, children=None):
object.__init__(self)
self.value = value
if kind is None:
kind = 'none'
Expand Down Expand Up @@ -477,7 +470,7 @@ def __init__(self, value=None, kind=None, children=None):
LeafNode.__init__(self, value=value, kind=kind)


class RawNode(object):
class RawNode():
"""
Used to pass raw integers to interpreter.
For instance, for selecting what function to use in func1.
Expand Down
5 changes: 2 additions & 3 deletions numexpr/necompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
]


class ASTNode(object):
class ASTNode():
"""Abstract Syntax Tree node.
Members:
Expand All @@ -84,7 +84,6 @@ class ASTNode(object):
cmpnames = ['astType', 'astKind', 'value', 'children']

def __init__(self, astType='generic', astKind='unknown', value=None, children=()):
object.__init__(self)
self.astType = astType
self.astKind = astKind
self.value = value
Expand Down Expand Up @@ -219,7 +218,7 @@ def typeCompileAst(ast):
[typeCompileAst(c) for c in children])


class Register(object):
class Register():
"""Abstraction for a register in the VM.
Members:
Expand Down

0 comments on commit 26d7e10

Please sign in to comment.