Skip to content

Commit

Permalink
clean StringQ
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Aug 25, 2021
1 parent c7e9f17 commit fe6b5dc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mathics/builtin/drawing/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ImageImport(_ImageBuiltin):
"""

def apply(self, path, evaluation):
"""ImageImport[path_?StringQ]"""
"""ImageImport[path_String]"""
pillow = PIL.Image.open(path.get_string_value())
pixels = numpy.asarray(pillow)
is_rgb = len(pixels.shape) >= 3 and pixels.shape[2] >= 3
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def validate(self, unit, evaluation):
return True

def apply_makeboxes(self, mag, unit, f, evaluation):
"MakeBoxes[Quantity[mag_, unit_?StringQ], f:StandardForm|TraditionalForm|OutputForm|InputForm]"
"MakeBoxes[Quantity[mag_, unit_String], f:StandardForm|TraditionalForm|OutputForm|InputForm]"

q_unit = unit.get_string_value().lower()
if self.validate(unit, evaluation):
Expand All @@ -200,7 +200,7 @@ def apply_makeboxes(self, mag, unit, f, evaluation):
)

def apply_n(self, mag, unit, evaluation):
"Quantity[mag_, unit_?StringQ]"
"Quantity[mag_, unit_String]"

if self.validate(unit, evaluation):
if mag.has_form("List", None):
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Environment(Builtin):
"""

def apply(self, var, evaluation):
"Environment[var_?StringQ]"
"Environment[var_String]"
env_var = var.get_string_value()
if env_var not in os.environ:
return SymbolFailed
Expand Down Expand Up @@ -358,7 +358,7 @@ class Run(Builtin):
"""

def apply(self, command, evaluation):
"Run[command_?StringQ]"
"Run[command_String]"
command_str = command.to_python()
return Integer(subprocess.call(command_str, shell=True))

Expand Down

1 comment on commit fe6b5dc

@rocky
Copy link
Member

@rocky rocky commented on fe6b5dc Aug 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmatera @TiagoCavalcante

I have been doing some mini benchmarks on commits that improve performance to understand how much of a win we are getting from these. Here is my mini-benchmark data for the commits here and the previous one

python ./bench.py -v ../benchmarks/Qtype_vs_BlankType.yaml
Mathics git repo Mathics3/mathics-benchmark/Mathics at 7716c4
500 iterations of BlankVsBlankQ...
  0.059548 secs for: Environment["HOME"]
  0.057055 secs for: Environment["I bet this does not exist"]
  8.200021 secs for: SplitBy[{2, 1, 1.2}, Round]
  0.175019 secs for: ContainsOnly[{}, {a, b, c}]
  0.653186 secs for: ContainsOnly[{b, a, d}, {a, b, c}]

Mathics git repo Mathics3/mathics-benchmark/Mathics at fe6b5d
500 iterations of BlankVsBlankQ...
  0.058681 secs for: Environment["HOME"]
  0.056643 secs for: Environment["I bet this does not exist"]
  8.041217 secs for: SplitBy[{2, 1, 1.2}, Round]
  0.169857 secs for: ContainsOnly[{}, {a, b, c}]
  0.635656 secs for: ContainsOnly[{b, a, d}, {a, b, c}]

The code for this is in Mathics3/mathics-benchmark#1 in case you want to verify these results.

Please sign in to comment.