Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mathics/builtin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def is_builtin(var):
_builtins = []
builtins_by_module = {}

for subdir in ("specialfns",):
for subdir in ("drawing", "numbers", "specialfns",):
import_name = f"{__name__}.{subdir}"
builtin_module = importlib.import_module(import_name)
submodule_names = [
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1922,11 +1922,11 @@ class LoadModule(Builtin):
def apply(self, module, evaluation):
"LoadModule[module_String]"
try:
module_loaded = evaluation.definitions.load_pymathics_module(module.value)
except PyMathicsLoadException as e:
evaluation.definitions.load_pymathics_module(module.value)
except PyMathicsLoadException:
evaluation.message(self.name, "notmathicslib", module)
return SymbolFailed
except ImportError as e:
except ImportError:
evaluation.message(self.get_name(), "notfound", module)
return SymbolFailed
else:
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SympyFunction,
)

from mathics.builtin.constants import mp_convert_constant
from mathics.builtin.numbers.constants import mp_convert_constant

from mathics.core.expression import (
COMPARE_PREC,
Expand Down
3 changes: 3 additions & 0 deletions mathics/builtin/drawing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Graphics, Drawing, and Images
"""
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SymbolList,
)
from mathics.builtin.base import BoxConstructError, Builtin, InstanceableBuiltin
from .graphics import (
from mathics.builtin.graphics import (
Graphics,
GraphicsBox,
PolygonBox,
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/image.py → mathics/builtin/drawing/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
SymbolRule,
from_python,
)
from mathics.builtin.colors import (
from mathics.builtin.drawing.colors import (
convert as convert_color,
colorspaces as known_colorspaces,
)
Expand Down Expand Up @@ -1599,7 +1599,7 @@ def apply(self, values, evaluation, options):
):
color_function = String("LakeColors")

from mathics.builtin.plot import gradient_palette
from mathics.builtin.drawing.plot import gradient_palette

cmap = gradient_palette(color_function, n, evaluation)
if not cmap:
Expand Down
23 changes: 5 additions & 18 deletions mathics/builtin/plot.py → mathics/builtin/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
SymbolN,
SymbolRule,
)

from mathics.builtin.base import Builtin
from mathics.builtin.scoping import dynamic_scoping
from mathics.builtin.options import options_to_rules
from mathics.builtin.numeric import chop
from mathics.builtin.graphics import Graphics
from mathics.builtin.graphics3d import Graphics3D
from mathics.builtin.drawing.graphics3d import Graphics3D
from mathics.builtin.numeric import chop
from mathics.builtin.options import options_to_rules
from mathics.builtin.scoping import dynamic_scoping


try:
Expand All @@ -39,7 +40,6 @@
except ImportError:
has_compile = False


def gradient_palette(color_function, n, evaluation): # always returns RGB values
if isinstance(color_function, String):
color_data = Expression("ColorData", color_function).evaluate(evaluation)
Expand Down Expand Up @@ -340,7 +340,6 @@ def get_plot_range(values, all_values, option):


class _Plot(Builtin):
from .graphics import Graphics

attributes = ("HoldAll",)

Expand Down Expand Up @@ -705,8 +704,6 @@ def find_excl(excl):
class _Chart(Builtin):
attributes = ("HoldAll",)

from .graphics import Graphics

options = Graphics.options.copy()
options.update(
{
Expand Down Expand Up @@ -1135,8 +1132,6 @@ class Histogram(Builtin):
= -Graphics-
"""

from .graphics import Graphics

attributes = ("HoldAll",)

options = Graphics.options.copy()
Expand Down Expand Up @@ -2224,8 +2219,6 @@ class ListPlot(_ListPlot):
= -Graphics-
"""

from .graphics import Graphics

attributes = ("HoldAll",)

options = Graphics.options.copy()
Expand Down Expand Up @@ -2264,8 +2257,6 @@ class ListLinePlot(_ListPlot):
= -Graphics-
"""

from .graphics import Graphics

attributes = ("HoldAll",)

options = Graphics.options.copy()
Expand Down Expand Up @@ -2344,8 +2335,6 @@ class Plot3D(_Plot3D):
#> Plot3D[x + 2y, {x, -2, 2}, {y, -2, 2}] // TeXForm
"""

from .graphics import Graphics

attributes = ("HoldAll",)

options = Graphics.options.copy()
Expand Down Expand Up @@ -2428,8 +2417,6 @@ class DensityPlot(_Plot3D):
= -Graphics-
"""

from .graphics import Graphics

attributes = ("HoldAll",)

options = Graphics.options.copy()
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions mathics/builtin/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
String,
Symbol,
SymbolFailed,
SymbolFalse,
SymbolNull,
SymbolTrue,
from_mpmath,
Expand All @@ -46,10 +45,8 @@
Stream,
path_search,
stream_manager,
urlsave_tmp,
)
from mathics.builtin.base import Builtin, Predefined, BinaryOperator, PrefixOperator
from mathics.builtin.numeric import Hash
from mathics.builtin.strings import to_python_encoding
from mathics.builtin.base import MessageException

Expand Down
7 changes: 5 additions & 2 deletions mathics/builtin/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from mathics.version import __version__ # noqa used in loading to check consistency.

from mathics.core.expression import (
BaseExpression,
Expression,
String,
Symbol,
Expand All @@ -38,7 +37,11 @@
)

from mathics.builtin.base import Builtin, Predefined
from mathics.builtin.files import DIRECTORY_STACK, INITIAL_DIR, mathics_open
from mathics.builtin.files import (
DIRECTORY_STACK,
INITIAL_DIR, # noqa is used via global
mathics_open
)
from mathics.builtin.numeric import Hash
from mathics.builtin.strings import to_regex
from mathics.builtin.base import MessageException
Expand Down
35 changes: 23 additions & 12 deletions mathics/builtin/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
SymbolList,
SymbolN,
SymbolMakeBoxes,
strip_context,
system_symbols,
system_symbols_dict,
from_python,
)
from mathics.builtin.colors import convert as convert_color
from mathics.builtin.drawing.colors import convert as convert_color
from mathics.core.numbers import machine_epsilon

GRAPHICS_OPTIONS = {
Expand All @@ -60,7 +59,7 @@ class ColorError(BoxConstructError):


def get_class(name):
from mathics.builtin.graphics3d import GLOBALS3D
from mathics.builtin.drawing.graphics3d import GLOBALS3D

c = GLOBALS.get(name)
if c is None:
Expand Down Expand Up @@ -119,7 +118,9 @@ def cut(value):
return value


def create_css(edge_color=None, face_color=None, stroke_width=None, font_color=None, opacity=1.0):
def create_css(
edge_color=None, face_color=None, stroke_width=None, font_color=None, opacity=1.0
):
css = []
if edge_color is not None:
color, stroke_opacity = edge_color.to_css()
Expand Down Expand Up @@ -524,7 +525,7 @@ def convert(content):
options[option] = Expression(SymbolN, options[option]).evaluate(
evaluation
)
from mathics.builtin.graphics3d import Graphics3DBox, Graphics3D
from mathics.builtin.drawing.graphics3d import Graphics3DBox, Graphics3D

if type(self) is Graphics:
return GraphicsBox(
Expand Down Expand Up @@ -1004,7 +1005,7 @@ def distance(a, b):
else:
return Expression(
"List",
*[distance(a, b) for a, b in zip(c1.leaves, c2.leaves)]
*[distance(a, b) for a, b in zip(c1.leaves, c2.leaves)],
)
else:
return Expression(SymbolList, *[distance(c, c2) for c in c1.leaves])
Expand Down Expand Up @@ -1805,7 +1806,7 @@ def parse_component(segments):
k = spline_degree.get_int_value()
elif head == "System`BSplineCurve":
raise NotImplementedError # FIXME convert bspline to bezier here
parts = segment.leaves
# parts = segment.leaves
else:
raise BoxConstructError

Expand Down Expand Up @@ -2569,7 +2570,16 @@ def default_arrow(px, py, vx, vy, t1, s):


class InsetBox(_GraphicsElement):
def init(self, graphics, style, item=None, content=None, pos=None, opos=(0, 0), opacity=1.0):
def init(
self,
graphics,
style,
item=None,
content=None,
pos=None,
opos=(0, 0),
opacity=1.0,
):
super(InsetBox, self).init(graphics, item, style)

self.color = self.style.get_option("System`FontColor")
Expand Down Expand Up @@ -2618,15 +2628,16 @@ def to_svg(self, offset=None):
svg = "\n" + content + "\n"
else:
css_style = create_css(
font_color=self.color, edge_color=self.color, face_color=self.color, opacity=self.opacity
font_color=self.color,
edge_color=self.color,
face_color=self.color,
opacity=self.opacity,
)
text_pos_opts = f'x="{x}" y="{y}" ox="{self.opos[0]}" oy="{self.opos[1]}"'
# FIXME: don't hard code text_style_opts, but allow these to be adjustable.
text_style_opts = "text-anchor:middle; dominant-baseline:middle;"
content = self.content.boxes_to_text(evaluation=self.graphics.evaluation)
svg = (
f'<text {text_pos_opts} style="{text_style_opts} {css_style}">{content}</text>'
)
svg = f'<text {text_pos_opts} style="{text_style_opts} {css_style}">{content}</text>'

# content = self.content.boxes_to_mathml(evaluation=self.graphics.evaluation)
# style = create_css(font_color=self.color)
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from mathics.core.evaluation import BreakInterrupt, ContinueInterrupt, ReturnInterrupt
from mathics.core.rules import Pattern
from mathics.core.convert import from_sympy
from mathics.builtin.algebra import cancel
from mathics.builtin.numbers.algebra import cancel
from mathics.algorithm.introselect import introselect
from mathics.algorithm.clusters import (
optimize,
Expand Down
3 changes: 3 additions & 0 deletions mathics/builtin/numbers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Integer and Number-Theoretical Functions
"""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions mathics/builtin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from mathics.version import __version__ # noqa used in loading to check consistency.

from mathics.builtin.base import Builtin, Test, get_option
from mathics.core.expression import (
Symbol,
Expand All @@ -14,8 +15,7 @@
ensure_context,
strip_context,
)
from mathics.builtin.image import Image
from mathics.core.expression import strip_context
from mathics.builtin.drawing.image import Image


class Options(Builtin):
Expand Down
1 change: 1 addition & 0 deletions mathics/builtin/specialfns/expintegral.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mathics.version import __version__ # noqa used in loading to check consistency.

from mathics.builtin.arithmetic import _MPMathFunction
from mathics.core.expression import from_mpmath

class ExpIntegralE(_MPMathFunction):
"""
Expand Down
18 changes: 15 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,27 @@ def read(*rnames):
EXTENSIONS = []
CMDCLASS = {}
else:
EXTENSIONS = {
"core": ["expression", "numbers", "rules", "pattern"],
EXTENSIONS_DICT = {
"core": ("expression", "numbers", "rules", "pattern"),
"builtin": ["arithmetic", "numeric", "patterns", "graphics"],
}
EXTENSIONS = [
Extension(
"mathics.%s.%s" % (parent, module), ["mathics/%s/%s.py" % (parent, module)]
)
for parent, modules in EXTENSIONS.items()
for parent, modules in EXTENSIONS_DICT.items()
for module in modules
]
# EXTENSIONS_SUBDIR_DICT = {
# "builtin": [("numbers", "arithmetic"), ("numbers", "numeric"), ("drawing", "graphics")],
# }
# EXTENSIONS.append(
# Extension(
# "mathics.%s.%s.%s" % (parent, module[0], module[1]), ["mathics/%s/%s/%s.py" % (parent, module[0], module[1])]
# )
# for parent, modules in EXTENSIONS_SUBDIR_DICT.items()
# for module in modules
# )
CMDCLASS = {"build_ext": build_ext}
INSTALL_REQUIRES += ["cython>=0.15.1"]

Expand Down Expand Up @@ -113,6 +123,8 @@ def subdirs(root, file="*.*", depth=10):
"mathics.core.parser",
"mathics.builtin",
"mathics.builtin.compile",
"mathics.builtin.drawing",
"mathics.builtin.numbers",
"mathics.builtin.numpy_utils",
"mathics.builtin.pymimesniffer",
"mathics.builtin.pympler",
Expand Down
2 changes: 1 addition & 1 deletion test/test_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from random import random


import mathics.builtin.colors as colors
import mathics.builtin.drawing.colors as colors
from mathics.builtin.numpy_utils import array, stacked, vectorize
from mathics.core.definitions import Definitions
from mathics.core.evaluation import Evaluation
Expand Down
Loading