Skip to content

Commit 3fb8cf5

Browse files
committed
Allow arbitrary int for threads
1 parent 5dd3dcb commit 3fb8cf5

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/julia/options.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ def _domain(self): # used in test
4141
return str
4242

4343

44+
class IntEtc(OptionDescriptor):
45+
def __init__(self, name, *, etc={}):
46+
self.name = name
47+
self.default = etc
48+
49+
def __set__(self, instance, value):
50+
if instance is None:
51+
raise AttributeError(self.name)
52+
elif value in {None, *self.default} or isinstance(value, int):
53+
setattr(instance, self.dataname, value)
54+
else:
55+
part = f" or {self.default}" if self.default else ""
56+
raise ValueError(
57+
f"Option {self.name} only accepts integers{part}. Got: {value}"
58+
)
59+
60+
def _domain(self):
61+
return {int, *self.default}
62+
63+
4464
class Choices(OptionDescriptor):
4565
def __init__(self, name, choicemap, default=None):
4666
self.name = name
@@ -114,7 +134,7 @@ def yes_no_etc(*etc):
114134
min_optlevel: {0, 1, 2, 3}
115135
Lower bound on the optimization level.
116136
117-
threads: int or "auto"
137+
threads: {int, 'auto'}
118138
How many threads to use.
119139
"""
120140

@@ -144,7 +164,7 @@ class JuliaOptions(object):
144164
optimize = Choices("optimize", dict(zip(range(4), map(str, range(4)))))
145165
inline = Choices("inline", yes_no_etc())
146166
check_bounds = Choices("check_bounds", yes_no_etc())
147-
threads = Choices("threads", dict(zip(range(12), map(str, range(12)))))
167+
threads = IntEtc("threads", etc={"auto"})
148168

149169
def __init__(self, **kwargs):
150170
unsupported = []
@@ -179,7 +199,7 @@ def as_args(self):
179199
if len(desc.cli_argument_name()) == 1:
180200
args.append(desc.cli_argument_name() + str(value))
181201
else:
182-
args.append(desc.cli_argument_name()+"="+str(value))
202+
args.append(desc.cli_argument_name() + "=" + str(value))
183203
return args
184204

185205
@classmethod

0 commit comments

Comments
 (0)