From a08efa3a637f906a7adf84fdbc26d8677cfa4a92 Mon Sep 17 00:00:00 2001 From: Yaroslav Ganin Date: Fri, 11 Nov 2016 13:57:02 -0500 Subject: [PATCH 1/2] Sublime project --- smartdispatch.sublime-project | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 smartdispatch.sublime-project diff --git a/smartdispatch.sublime-project b/smartdispatch.sublime-project new file mode 100644 index 0000000..24db303 --- /dev/null +++ b/smartdispatch.sublime-project @@ -0,0 +1,8 @@ +{ + "folders": + [ + { + "path": "." + } + ] +} From f0f24908e68ce9fb762a6687ca1c71bf9142492e Mon Sep 17 00:00:00 2001 From: Mohamed Ishmael Diwan Belghazi Date: Tue, 10 Oct 2017 15:23:39 -0400 Subject: [PATCH 2/2] new arguments templates --- smartdispatch/argument_template.py | 42 ++++++++++++++++++++++++++++++ smartdispatch/smartdispatch.py | 4 +++ 2 files changed, 46 insertions(+) diff --git a/smartdispatch/argument_template.py b/smartdispatch/argument_template.py index 7ef67f4..0a46f81 100644 --- a/smartdispatch/argument_template.py +++ b/smartdispatch/argument_template.py @@ -1,4 +1,6 @@ import re +import numpy as np +import numpy.random as npr from collections import OrderedDict @@ -38,4 +40,44 @@ def unfold(self, match): return map(str, range(start, end, step)) +class LinearArgumentTemplate(ArgumentTemplate): + def __init__(self): + self.regex = "(Lin)\[(-?\d+)\,(-?\d+)\,(\d+)\]" + + def unfold(self, match): + groups = re.search(regex, match).groups() + start, stop, npoints = [int(el) for el in groups[1:]] + return map(str, np.linspace(start, stop, npoints)) + + +class LogArgumentTemplate(ArgumentTemplate): + def __init__(self): + self.regex = "(Log)\[(-?\d+)\,(-?\d+)\,(\d+)(?:,(\d+))?\]" + + def unfold(self, match): + groups = re.search(regex, match).groups() + start, stop, npoints = [int(el) for el in groups[1:-1]] + base = 10 if groups[-1] is None else int(groups[-1]) + return map(str, np.logspace(start, stop, npoints, base=base)) + + +class UniformArgumentTemplate(ArgumentTemplate): + def __init__(self): + self.regex = "(U)\[(-?\d+)\,(-?\d+),(-?\d+)\]" + + def unfold(self, match): + groups = re.search(self.regex, match).groups() + low, high, nsamples = [int(el) for el in groups[1:]] + return map(str, npr.uniform(low, high, size=(nsamples, ))) + + +class NormalArgumentTemplate(ArgumentTemplate): + def __init__(self): + self.regex = "(N)\[(-?\d+)\,(\d+),(-?\d+)\]" + + def unfold(self, match): + groups = re.search(self.regex, match).groups() + loc, scale, nsamples = [int(el) for el in groups[1:]] + return map(str, npr.normal(loc, scale, size=(nsamples, ))) + argument_templates = build_argument_templates_dictionnary() diff --git a/smartdispatch/smartdispatch.py b/smartdispatch/smartdispatch.py index b38e8cf..a303b8e 100644 --- a/smartdispatch/smartdispatch.py +++ b/smartdispatch/smartdispatch.py @@ -85,6 +85,10 @@ def unfold_command(command): ------------------ *list*: "[item1 item2 ... itemN]" *range*: "[start:end]" or "[start:end:step]" + *linear*: "[start,end,npoints]" + *logarithmic*: "[start,end,npoints]" or "[start,end,npoints,base]" + *uniform*: "[location,scale,nsamples]" + *normal*: "[low,high,nsamples]" ''' text = utils.encode_escaped_characters(command)