def test_input_single(self): script = """ x2 = x1 + 1 x3 = x1 + 2 """ script = dml(script).input("x1", 5).out("x2", "x3") self.assertEqual(ml.execute(script).get("x2", "x3"), [6, 7])
def test_matrix_toDF(self): sums = """ s1 = sum(m1) m2 = m1 * 2 """ rdd1 = sc.parallelize(["1.0,2.0", "3.0,4.0"]) script = dml(sums).input(m1=rdd1).out("m2") m2 = ml.execute(script).get("m2") self.assertEqual(repr(m2.toDF()), "DataFrame[ID: double, C1: double, C2: double]")
def test_output_matrix(self): sums = """ s1 = sum(m1) m2 = m1 * 2 """ rdd1 = sc.parallelize(["1.0,2.0", "3.0,4.0"]) script = dml(sums).input(m1=rdd1).out("s1", "m2") s1, m2 = ml.execute(script).get("s1", "m2") self.assertEqual((s1, repr(m2)), (10.0, "Matrix"))
def test_output_list(self): script = """ x1 = 0.2 x2 = x1 + 1 x3 = x1 + 2 """ script = dml(script).out("x1", "x2", "x3") self.assertEqual(ml.execute(script).get("x1", "x2"), [0.2, 1.2]) self.assertEqual(ml.execute(script).get("x1", "x3"), [0.2, 2.2])
def test_rdd(self): sums = """ s1 = sum(m1) s2 = sum(m2) s3 = 'whatever' """ rdd1 = sc.parallelize(["1.0,2.0", "3.0,4.0"]) rdd2 = sc.parallelize(["5.0,6.0", "7.0,8.0"]) script = dml(sums).input(m1=rdd1).input(m2=rdd2).out("s1", "s2", "s3") self.assertEqual( ml.execute(script).get("s1", "s2", "s3"), [10.0, 26.0, "whatever"])
def test_input(self): script = """ x3 = x1 + x2 """ script = dml(script).input(x1=5, x2=3).out("x3") self.assertEqual(ml.execute(script).get("x3"), 8)
def test_output_string(self): script = dml("x1 = 'Hello World'").out("x1") self.assertEqual(ml.execute(script).get("x1"), "Hello World")