Skip to content
Open
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
8 changes: 8 additions & 0 deletions smartdispatch.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders":
[
{
"path": "."
}
]
}
42 changes: 42 additions & 0 deletions smartdispatch/argument_template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
import numpy as np
import numpy.random as npr
from collections import OrderedDict


Expand Down Expand Up @@ -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()
4 changes: 4 additions & 0 deletions smartdispatch/smartdispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down