2016-06-03 18:32:57 -07:00
|
|
|
import halo
|
2016-04-18 13:05:36 -07:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
# Test simple functionality
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([str], [str])
|
2016-04-18 13:05:36 -07:00
|
|
|
def print_string(string):
|
|
|
|
print "called print_string with", string
|
|
|
|
f = open("asdfasdf.txt", "w")
|
|
|
|
f.write("successfully called print_string with argument {}.".format(string))
|
|
|
|
return string
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([int, int], [int, int])
|
2016-04-18 13:05:36 -07:00
|
|
|
def handle_int(a, b):
|
|
|
|
return a + 1, b + 1
|
|
|
|
|
|
|
|
# Test aliasing
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([], [np.ndarray])
|
2016-04-18 13:05:36 -07:00
|
|
|
def test_alias_f():
|
|
|
|
return np.ones([3, 4, 5])
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([], [np.ndarray])
|
2016-04-18 13:05:36 -07:00
|
|
|
def test_alias_g():
|
|
|
|
return test_alias_f()
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([], [np.ndarray])
|
2016-04-18 13:05:36 -07:00
|
|
|
def test_alias_h():
|
|
|
|
return test_alias_g()
|
|
|
|
|
2016-05-22 10:05:14 -07:00
|
|
|
# Test timing
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([], [])
|
2016-05-22 10:05:14 -07:00
|
|
|
def empty_function():
|
|
|
|
return ()
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([], [int])
|
2016-05-22 10:05:14 -07:00
|
|
|
def trivial_function():
|
|
|
|
return 1
|
2016-06-03 00:10:17 -07:00
|
|
|
|
|
|
|
# Test keyword arguments
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([int, str], [str])
|
2016-06-03 00:10:17 -07:00
|
|
|
def keyword_fct1(a, b="hello"):
|
|
|
|
return "{} {}".format(a, b)
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([str, str], [str])
|
2016-06-03 00:10:17 -07:00
|
|
|
def keyword_fct2(a="hello", b="world"):
|
|
|
|
return "{} {}".format(a, b)
|
|
|
|
|
2016-06-03 18:41:45 -07:00
|
|
|
@halo.remote([int, int, str, str], [str])
|
2016-06-03 00:10:17 -07:00
|
|
|
def keyword_fct3(a, b, c="hello", d="world"):
|
|
|
|
return "{} {} {} {}".format(a, b, c, d)
|
2016-06-04 16:22:10 -07:00
|
|
|
|
|
|
|
# Test variable numbers of arguments
|
|
|
|
|
|
|
|
@halo.remote([int], [str])
|
|
|
|
def varargs_fct1(*a):
|
|
|
|
return " ".join(map(str, a))
|
|
|
|
|
|
|
|
@halo.remote([int, int], [str])
|
|
|
|
def varargs_fct2(a, *b):
|
|
|
|
return " ".join(map(str, b))
|
|
|
|
|
|
|
|
try:
|
|
|
|
@halo.remote([int], [])
|
|
|
|
def kwargs_throw_exception(**c):
|
|
|
|
return ()
|
|
|
|
kwargs_exception_thrown = False
|
|
|
|
except:
|
|
|
|
kwargs_exception_thrown = True
|
|
|
|
|
|
|
|
try:
|
|
|
|
@halo.remote([int, str, int], [str])
|
|
|
|
def varargs_and_kwargs_throw_exception(a, b="hi", *c):
|
|
|
|
return "{} {} {}".format(a, b, c)
|
|
|
|
varargs_and_kwargs_exception_thrown = False
|
|
|
|
except:
|
|
|
|
varargs_and_kwargs_exception_thrown = True
|