Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python 3.9 represenation of abs #812

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions fipy/variables/operatorVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ def _py3kInstructions(self, instructions, style, argDict, id, freshen):
return s
elif ins.opname == 'LOAD_CONST':
stack.append(ins.argval)
elif ins.opname == 'LOAD_ATTR':
elif ins.opname in ['LOAD_ATTR', 'LOAD_METHOD']:
stack.append(stack.pop() + "." + ins.argval)
elif ins.opname == 'COMPARE_OP':
stack.append(stack.pop(-2) + " " + dis.cmp_op[ins.arg] + " " + stack.pop())
elif ins.opname == 'LOAD_GLOBAL':
stack.append(ins.argval)
elif ins.opname == 'LOAD_FAST':
stack.append(self.__var(ins.arg, style=style, argDict=argDict, id=id, freshen=freshen))
elif ins.opname == 'CALL_FUNCTION':
elif ins.opname in ['CALL_FUNCTION', 'CALL_METHOD']:
# args are last ins.arg items on stack
args, stack = stack[-ins.arg:], stack[:-ins.arg]
stack.append(stack.pop() + "(" + ", ".join(args) + ")")
Expand Down
6 changes: 6 additions & 0 deletions fipy/variables/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,12 @@ def __abs__(self):
>>> print(abs(Variable(2.3) - Variable(1.2)))
1.1


Check representation works with different versions of numpy

>>> print(repr(abs(Variable(2.3))))
numerix.fabs(Variable(value=array(2.3)))

"""
return self._UnaryOperatorVariable(lambda a: numerix.fabs(a))

Expand Down