diff --git a/docs/performance.md b/docs/performance.md index 87b7162..d77d628 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -6,7 +6,7 @@ Here's a contrived rough benchmark to show the magnitude differences between Pyt **Spoiler**: GPU-backed KlongPy is about 790x faster than naive Python and 36x faster than NumPy-backed KlongPy. -### Python +## Python ```python def python_vec(number=100): @@ -14,7 +14,7 @@ def python_vec(number=100): return r/number ``` -### KlongPy +## KlongPy ```python # NumPy and CuPy (CuPy is enabled via USE_GPU=1 environment variable @@ -24,7 +24,7 @@ def klong_vec(number=100): return r/number ``` -### NumPy (explicit usage) +## NumPy (explicit usage) ```python def NumPy_vec(number=100): @@ -36,19 +36,22 @@ def NumPy_vec(number=100): ### CPU (AMD Ryzen 9 7950x) - $ python3 tests/perf_vector.py - Python: 0.369111s - KlongPy USE_GPU=None: 0.017946s - Numpy: 0.017896s - Python / KlongPy => 20.568334 - Numpy / KlongPy => 0.997245 +```bash +$ python3 tests/perf_vector.py +Python: 0.369111s +KlongPy USE_GPU=None: 0.017946s +Numpy: 0.017896s +Python / KlongPy => 20.568334 +Numpy / KlongPy => 0.997245 +``` ### GPU (Same CPU with NVIDIA GeForce RTX 3090) - $ USE_GPU=1 python3 tests/perf_vector.py - Python: 0.364893s - KlongPy USE_GPU=1: 0.000461s - NumPy: 0.017053s - Python / KlongPy => 790.678069 - Numpy / KlongPy => 36.951443 - +```bash +$ USE_GPU=1 python3 tests/perf_vector.py +Python: 0.364893s +KlongPy USE_GPU=1: 0.000461s +NumPy: 0.017053s +Python / KlongPy => 790.678069 +Numpy / KlongPy => 36.951443 +``` diff --git a/klongpy/dyads.py b/klongpy/dyads.py index 85ab815..1ab7417 100644 --- a/klongpy/dyads.py +++ b/klongpy/dyads.py @@ -478,14 +478,8 @@ def eval_dyad_integer_divide(a, b): def _arr_to_list(a): - if np.isarray(a): - if a.ndim == 1: - return a - elif a.shape[0] == 1: - return [a.flatten()] # TODO: test squeeze - elif a.shape[0] > 1: - return a - return [a] if not is_list(a) else a + """ Convert a to a list if it is not already one """ + return a if is_list(a) else [a]# if not is_list(a) else a def eval_dyad_join(a, b): diff --git a/tests/kgtests/language/test_nested_join.kg b/tests/kgtests/language/test_nested_join.kg new file mode 100644 index 0000000..48709e0 --- /dev/null +++ b/tests/kgtests/language/test_nested_join.kg @@ -0,0 +1,10 @@ +:" test that we can create new arrays with nested arrays and the result has the right shape " + +data::{!3} +t("1,,{data()}'!2";1,,{data()}'!2;[1 [[0 1 2] [0 1 2]]]) + + +a::!10 +k::3 +c::(,,,1#a),k +t("c::(,,,1#a),k";c::(,,,1#a),k;[[[[0]]] 3]) diff --git a/tests/test_known_bugs.py b/tests/test_known_bugs.py index 3500c1f..d1a8860 100644 --- a/tests/test_known_bugs.py +++ b/tests/test_known_bugs.py @@ -39,13 +39,6 @@ def test_table_access_with_at(self): r = klong('T@"col1"') self.assertTrue(kg_equal(r, data['col1'])) - @unittest.skip - def test_join_nested_array(self): - klong = KlongInterpreter() - r = klong("a::!10;k::3;c::(,,,1#a),k") - # currently this flattens to [[0], 3] - self.assertTrue(kg_equal(r,[[[[0]]],3])) - @unittest.skip def test_extra_spaces(self): klong = KlongInterpreter()