From 85671d1d10d7e528888e180db1ff5db509b43634 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Fri, 29 Jun 2018 08:05:45 -0400 Subject: [PATCH 1/6] added summary stat performance test --- .../regressions/python/sum_stat_pref_test.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/regressions/python/sum_stat_pref_test.py diff --git a/tests/regressions/python/sum_stat_pref_test.py b/tests/regressions/python/sum_stat_pref_test.py new file mode 100644 index 000000000..bd6e9238e --- /dev/null +++ b/tests/regressions/python/sum_stat_pref_test.py @@ -0,0 +1,30 @@ +from phylanx import * +from phylanx.ast import * + +import numpy as np +from time import time + +def py_run(y, k): + x = np.zeros(k) + for i in range(k): + x[y[i]] += 1.0 + +@Phylanx +def phy_run(y, k): + x = constant(0.0, k) + for i in range(k): + x[y[i]] += 1.0 + +if __name__ == "__main__": + K = 100000 + y = np.random.randint(0, K, size=K) + + func = [ py_run, phy_run ] + func_nom = [ 'py_run', 'phy_run' ] + + for n, f in zip(func_nom, func): + print(n) + s = time() + f(y, K) + e = time() + print(e-s) From 084b28cb1751200c7f4b25ccb0d4686bd07bfbb5 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Fri, 29 Jun 2018 08:21:23 -0400 Subject: [PATCH 2/6] added one more test --- ...tat_pref_test.py => sum_stat_perf_test.py} | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) rename tests/regressions/python/{sum_stat_pref_test.py => sum_stat_perf_test.py} (54%) diff --git a/tests/regressions/python/sum_stat_pref_test.py b/tests/regressions/python/sum_stat_perf_test.py similarity index 54% rename from tests/regressions/python/sum_stat_pref_test.py rename to tests/regressions/python/sum_stat_perf_test.py index bd6e9238e..06318db0c 100644 --- a/tests/regressions/python/sum_stat_pref_test.py +++ b/tests/regressions/python/sum_stat_perf_test.py @@ -15,12 +15,25 @@ def phy_run(y, k): for i in range(k): x[y[i]] += 1.0 +def py_run_mat(y, k): + x = np.zeros((k, k)) + print(x.shape) + for i in range(k): + x[y[i], y[i]] += 1.0 + +@Phylanx +def phy_run_mat(y, k): + x = constant(0.0, make_list(k, k)) + for i in range(k): + x[y[i], y[i]] += 1.0 + + if __name__ == "__main__": - K = 100000 + K = 10000 # add a 0 y = np.random.randint(0, K, size=K) - func = [ py_run, phy_run ] - func_nom = [ 'py_run', 'phy_run' ] + func = [ py_run_mat, phy_run_mat, py_run, phy_run ] + func_nom = [ 'py_run_mat', 'phy_run_mat', 'py_run', 'phy_run' ] for n, f in zip(func_nom, func): print(n) From 022f54c686f8c4556d3c600ff136697275c6a31d Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Fri, 29 Jun 2018 08:22:24 -0400 Subject: [PATCH 3/6] added name, license --- tests/regressions/python/sum_stat_perf_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/regressions/python/sum_stat_perf_test.py b/tests/regressions/python/sum_stat_perf_test.py index 06318db0c..2be66cf5a 100644 --- a/tests/regressions/python/sum_stat_perf_test.py +++ b/tests/regressions/python/sum_stat_perf_test.py @@ -1,3 +1,8 @@ +# Copyright (c) 2018 Christopher Taylor +# +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + from phylanx import * from phylanx.ast import * From e5d6986cfe52560488ede0e8cf916fee0aa2edfd Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Fri, 29 Jun 2018 14:51:13 -0400 Subject: [PATCH 4/6] added self-ref update --- .../regressions/python/sum_stat_perf_test.py | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/regressions/python/sum_stat_perf_test.py b/tests/regressions/python/sum_stat_perf_test.py index 2be66cf5a..2d9625d18 100644 --- a/tests/regressions/python/sum_stat_perf_test.py +++ b/tests/regressions/python/sum_stat_perf_test.py @@ -32,13 +32,52 @@ def phy_run_mat(y, k): for i in range(k): x[y[i], y[i]] += 1.0 +def py_run_self_update(y, k): + x = np.zeros(k) + for i in range(k): + x[y[i]] = x[y[i]] + 1.0 + +@Phylanx +def phy_run_self_update(y, k): + x = constant(0.0, k) + for i in range(k): + x[y[i]] = x[y[i]] + 1.0 + +def py_run_mat_self_update(y, k): + x = np.zeros((k,k)) + for i in range(k): + x[y[i], y[i]] = x[y[i], y[i]] + 1.0 + +@Phylanx +def phy_run_mat_self_update(y, k): + x = constant(0.0, make_list(k, k)) + for i in range(k): + x[y[i], y[i]] = x[y[i], y[i]] + 1.0 + if __name__ == "__main__": K = 10000 # add a 0 y = np.random.randint(0, K, size=K) - func = [ py_run_mat, phy_run_mat, py_run, phy_run ] - func_nom = [ 'py_run_mat', 'phy_run_mat', 'py_run', 'phy_run' ] + func = [ py_run_mat + , phy_run_mat + , py_run + , phy_run + , py_run_self_update + , phy_run_self_update + , py_run_mat_self_update + , phy_run_mat_self_update + ] + + func_nom = [ 'py_run_mat' + , 'phy_run_mat' + , 'py_run' + , 'phy_run' + , 'py_run_self_update' + , 'phy_run_self_update' + , 'py_run_mat_self_update' + , 'phy_run_mat_self_update' + ] for n, f in zip(func_nom, func): print(n) From c9d2608bbd34e8d7ad97d34c55bc8dca59139b04 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Fri, 29 Jun 2018 15:39:28 -0400 Subject: [PATCH 5/6] tried working on whitespace issues --- tests/regressions/python/sum_stat_perf_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/regressions/python/sum_stat_perf_test.py b/tests/regressions/python/sum_stat_perf_test.py index 2d9625d18..dff922da8 100644 --- a/tests/regressions/python/sum_stat_perf_test.py +++ b/tests/regressions/python/sum_stat_perf_test.py @@ -54,7 +54,6 @@ def phy_run_mat_self_update(y, k): for i in range(k): x[y[i], y[i]] = x[y[i], y[i]] + 1.0 - if __name__ == "__main__": K = 10000 # add a 0 y = np.random.randint(0, K, size=K) From 9625c09dde47842bec5862e9fd7caf6887073281 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Fri, 29 Jun 2018 15:40:06 -0400 Subject: [PATCH 6/6] tried working on whitespace issues --- .../regressions/python/sum_stat_perf_test.py | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/regressions/python/sum_stat_perf_test.py b/tests/regressions/python/sum_stat_perf_test.py index dff922da8..afacdc81c 100644 --- a/tests/regressions/python/sum_stat_perf_test.py +++ b/tests/regressions/python/sum_stat_perf_test.py @@ -58,25 +58,23 @@ def phy_run_mat_self_update(y, k): K = 10000 # add a 0 y = np.random.randint(0, K, size=K) - func = [ py_run_mat - , phy_run_mat - , py_run - , phy_run - , py_run_self_update - , phy_run_self_update - , py_run_mat_self_update - , phy_run_mat_self_update - ] + func = [ py_run_mat \ + , phy_run_mat \ + , py_run \ + , phy_run \ + , py_run_self_update \ + , phy_run_self_update \ + , py_run_mat_self_update \ + , phy_run_mat_self_update ] - func_nom = [ 'py_run_mat' - , 'phy_run_mat' - , 'py_run' - , 'phy_run' - , 'py_run_self_update' - , 'phy_run_self_update' + func_nom = [ 'py_run_mat' \ + , 'phy_run_mat' \ + , 'py_run' \ + , 'phy_run' \ + , 'py_run_self_update' \ + , 'phy_run_self_update' \ , 'py_run_mat_self_update' - , 'phy_run_mat_self_update' - ] + , 'phy_run_mat_self_update' ] for n, f in zip(func_nom, func): print(n)