Skip to content

Commit 974e332

Browse files
mmaterarocky
authored andcommitted
blacken files, add CHANGES.rst entry ...
and address some merge conflicts
1 parent 36c63da commit 974e332

3 files changed

Lines changed: 735 additions & 540 deletions

File tree

CHANGES.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ Enhancements
2121
Miscellanea
2222
+++++++++++
2323

24-
A pass was made to improve Microsoft Windows compatability and testing
24+
* A pass was made to improve Microsoft Windows compatability and testing
2525
Windows under MSYS.
2626

27+
* Mathics functions are accepted by ``Compile[]``. The return value or type will be
28+
``CompiledFunction``
29+
30+
2731
2.0.0
2832
-----
2933

mathics/builtin/compilation.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import ctypes
22

33
from mathics.builtin.base import Builtin, BoxConstruct
4+
from mathics.core.evaluation import Evaluation
45
from mathics.core.expression import (
56
Atom,
6-
Evaluation,
77
Expression,
88
Symbol,
99
String,
@@ -14,7 +14,7 @@
1414

1515

1616
class Compile(Builtin):
17-
'''
17+
"""
1818
<dl>
1919
<dt>'Compile[{x1, x2, ...}, expr_]'
2020
<dd>Compiles $expr$ assuming each $xi$ is a $Real$ number.
@@ -61,8 +61,7 @@ class Compile(Builtin):
6161
Loops and variable assignments are supported as python (not llvmlite)
6262
functions
6363
>> Compile[{{a, _Integer}, {b, _Integer}}, While[b != 0, {a, b} = {b, Mod[a, b]}]; a] (* GCD of a, b *)
64-
: Expression While[b != 0, {a, b} = {b, Mod[a, b]}] ; a could not be compiled.
65-
= Function[{Global`a, Global`b}, While[b != 0, {a, b} = {b, Mod[a, b]}] ; a]
64+
= CompiledFunction[{a, b}, a, -CompiledCode-]
6665
"""
6766

6867
requires = ("llvmlite",)
@@ -128,20 +127,22 @@ def apply(self, vars, expr, evaluation):
128127

129128
if cfunc is None:
130129
try:
130+
131131
def _pythonized_mathics_expr(*x):
132132
inner_evaluation = Evaluation(definitions=evaluation.definitions)
133-
vars = dict(list(zip(names, x[:len(names)])))
133+
vars = dict(list(zip(names, x[: len(names)])))
134134
pyexpr = expr.replace_vars(vars)
135135
pyexpr = Expression("N", pyexpr).evaluate(inner_evaluation)
136136
res = pyexpr.to_python(n_evaluation=inner_evaluation)
137137
return res
138-
#TODO: check if we can use numba to compile this...
138+
139+
# TODO: check if we can use numba to compile this...
139140
cfunc = _pythonized_mathics_expr
140141
except Exception as e:
141142
cfunc = None
142143

143144
if cfunc is None:
144-
evaluation.message('Compile', 'comperr', expr)
145+
evaluation.message("Compile", "comperr", expr)
145146
args = Expression("List", *names)
146147
return Expression("Function", args, expr)
147148

0 commit comments

Comments
 (0)