Skip to content

Commit

Permalink
Merge pull request #2298 from Shaikh-Ubaid/ci_python_3_9
Browse files Browse the repository at this point in the history
CI: Test integration_tests with Python 3.9, 3.10 and 3.11
  • Loading branch information
certik authored Aug 25, 2023
2 parents c8b1ba9 + c5ef1af commit 615e7e7
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 80 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,13 @@ jobs:
./run_tests.py -b c_sym cpython_sym llvm_sym
./run_tests.py -b c_sym cpython_sym llvm_sym -f
python_3_11:
name: Run Integration tests with Python 3.11
integration_tests_cpython:
name: Run Integration tests with Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -466,16 +470,20 @@ jobs:
zlib
cmake
make
python=3.11.4
python=${{ matrix.python-version }}
numpy
- uses: hendrikmuhs/ccache-action@main
with:
key: ${{ github.job }}-${{ matrix.os }}
key: ${{ github.job }}-${{ matrix.python-version }}

- name: Show Python version
- name: Show Python Info
shell: bash -e -l {0}
run: python --version
run: |
which python
python -m pip -V
python -m pip list
python --version
- name: Build
shell: bash -e -l {0}
Expand All @@ -498,4 +506,4 @@ jobs:
shell: bash -e -l {0}
run: |
cd integration_tests
./run_tests.py -b cpython
./run_tests.py -b cpython c_py
19 changes: 16 additions & 3 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ endmacro(RUN_UTIL)

macro(RUN)
set(options FAIL NOFAST NOMOD ENABLE_CPYTHON LINK_NUMPY)
set(oneValueArgs NAME IMPORT_PATH COPY_TO_BIN)
set(oneValueArgs NAME IMPORT_PATH COPY_TO_BIN REQ_PY_VER)
set(multiValueArgs LABELS EXTRAFILES)
cmake_parse_arguments(RUN "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
Expand All @@ -334,6 +334,18 @@ macro(RUN)
set(RUN_EXTRA_ARGS ${RUN_EXTRA_ARGS} -I${CMAKE_CURRENT_SOURCE_DIR}/${RUN_IMPORT_PATH})
endif()

if (RUN_REQ_PY_VER)
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" PY_MAJOR_VERSION "${Python_VERSION}")
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" PY_MINOR_VERSION "${Python_VERSION}")
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1" REQ_PY_MAJOR_VERSION "${RUN_REQ_PY_VER}")
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\2" REQ_PY_MINOR_VERSION "${RUN_REQ_PY_VER}")

if (PY_MINOR_VERSION LESS REQ_PY_MINOR_VERSION)
# remove backends from the test that depend on CPython
list(REMOVE_ITEM RUN_LABELS cpython cpython_sym c_py c_sym llvm_sym llvm_py)
endif()
endif()

if (NOT FAST)
RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_EXTRAFILES RUN_NOMOD RUN_EXTRA_ARGS RUN_COPY_TO_BIN)
endif()
Expand Down Expand Up @@ -623,7 +635,7 @@ RUN(NAME bindpy_01 LABELS cpython c_py ENABLE_CPYTHON NOFAST COPY_TO_B
RUN(NAME bindpy_02 LABELS cpython c_py LINK_NUMPY COPY_TO_BIN bindpy_02_module.py)
RUN(NAME bindpy_03 LABELS cpython c_py LINK_NUMPY NOFAST COPY_TO_BIN bindpy_03_module.py)
RUN(NAME bindpy_04 LABELS cpython c_py LINK_NUMPY NOFAST COPY_TO_BIN bindpy_04_module.py)
RUN(NAME bindpy_05 LABELS llvm_py c_py ENABLE_CPYTHON COPY_TO_BIN bindpy_05_module.py)
RUN(NAME bindpy_05 LABELS llvm_py c_py ENABLE_CPYTHON COPY_TO_BIN bindpy_05_module.py REQ_PY_VER 3.10)
RUN(NAME test_generics_01 LABELS cpython llvm c NOFAST)
RUN(NAME test_cmath LABELS cpython llvm c NOFAST)
RUN(NAME test_complex_01 LABELS cpython llvm c wasm wasm_x64)
Expand Down Expand Up @@ -741,7 +753,8 @@ RUN(NAME generics_array_01 LABELS cpython llvm c)
RUN(NAME generics_array_02 LABELS cpython llvm c)
RUN(NAME generics_array_03 LABELS cpython llvm c)
RUN(NAME generics_list_01 LABELS cpython llvm c)
RUN(NAME test_statistics LABELS cpython llvm NOFAST)
RUN(NAME test_statistics_01 LABELS cpython llvm NOFAST)
RUN(NAME test_statistics_02 LABELS cpython llvm NOFAST REQ_PY_VER 3.10)
RUN(NAME test_str_attributes LABELS cpython llvm c)
RUN(NAME kwargs_01 LABELS cpython llvm c NOFAST)

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
DEFAULT_THREADS_TO_USE = args.no_of_threads or DEFAULT_THREADS_TO_USE
fast_tests = "yes" if args.fast else "no"
for backend in args.backends:
python_libs_req = "yes" if backend in ["c_py", "c_sym", "llvm_sym", 'llvm_py'] else "no"
python_libs_req = "yes" if backend in ["cpython", "c_py", "c_sym", "llvm_sym", 'llvm_py'] else "no"
test_backend(backend)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from statistics import (mean, fmean, geometric_mean, harmonic_mean, variance,
stdev, pvariance, pstdev, correlation, covariance,
linear_regression, mode)
from lpython import i32, f64, i64, f32
stdev, pvariance, pstdev, mode)
from lpython import i32, f64, i64


eps: f64
Expand Down Expand Up @@ -126,69 +125,6 @@ def test_pstdev():
k = pstdev(b)
assert abs(k - 0.37537181567080935) < eps


def test_covariance():
a: list[i32]
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
b: list[i32]
b = [1, 2, 3, 1, 2, 3, 1, 2, 3]
j: f64
j = covariance(a, b)
assert abs(j - 0.75) < eps

c: list[f64]
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
d: list[f64]
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]
k: f64
k = covariance(c, d)
assert abs(k + 0.24955999999999934) < eps


def test_correlation():
a: list[i32]
a = [11, 2, 7, 4, 15, 6, 10, 8, 9, 1, 11, 5, 13, 6, 15]
b: list[i32]
b = [2, 5, 17, 6, 10, 8, 13, 4, 6, 9, 11, 2, 5, 4, 7]

j: f64
j = correlation(a, b)
assert abs(j - 0.11521487988958108) < eps

c: list[f64]
c = [2.0, 23.0, 24.55, 64.436, 5403.23]
d: list[f64]
d = [26.9, 75.6, 34.06, 356.89, 759.26]

j = correlation(c, c)
assert abs(j - 1.0) < eps

j = correlation(c, d)
assert abs(j - 0.9057925526720572) < eps

def test_linear_regression():
c: list[f64]
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
d: list[f64]
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]

slope: f64
intercept: f64
slope, intercept = linear_regression(c, d)

assert abs(slope + 0.6098133124816717) < eps
assert abs(intercept - 9.992570618707845) < eps

a: list[i32]
b: list[i32]
a = [12, 24, 2, 1, 43, 53, 23]
b = [2, 13, 14, 63, 49, 7, 3]

slope, intercept = linear_regression(a, b)

assert abs(slope + 0.18514007308160782) < eps
assert abs(intercept - 25.750304506699152) < eps

def test_mode():
a: list[i32]
a = [3, 1, 12, 4, 0]
Expand Down Expand Up @@ -228,9 +164,6 @@ def check():
test_stdev()
test_pvariance()
test_pstdev()
test_linear_regression()
test_correlation()
test_covariance()
test_mode()

check()
77 changes: 77 additions & 0 deletions integration_tests/test_statistics_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from statistics import (covariance, correlation,
linear_regression)
from lpython import i32, f64


eps: f64
eps = 1e-12

def test_covariance():
a: list[i32]
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
b: list[i32]
b = [1, 2, 3, 1, 2, 3, 1, 2, 3]
j: f64
j = covariance(a, b)
assert abs(j - 0.75) < eps

c: list[f64]
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
d: list[f64]
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]
k: f64
k = covariance(c, d)
assert abs(k + 0.24955999999999934) < eps


def test_correlation():
a: list[i32]
a = [11, 2, 7, 4, 15, 6, 10, 8, 9, 1, 11, 5, 13, 6, 15]
b: list[i32]
b = [2, 5, 17, 6, 10, 8, 13, 4, 6, 9, 11, 2, 5, 4, 7]

j: f64
j = correlation(a, b)
assert abs(j - 0.11521487988958108) < eps

c: list[f64]
c = [2.0, 23.0, 24.55, 64.436, 5403.23]
d: list[f64]
d = [26.9, 75.6, 34.06, 356.89, 759.26]

j = correlation(c, c)
assert abs(j - 1.0) < eps

j = correlation(c, d)
assert abs(j - 0.9057925526720572) < eps

def test_linear_regression():
c: list[f64]
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
d: list[f64]
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]

slope: f64
intercept: f64
slope, intercept = linear_regression(c, d)

assert abs(slope + 0.6098133124816717) < eps
assert abs(intercept - 9.992570618707845) < eps

a: list[i32]
b: list[i32]
a = [12, 24, 2, 1, 43, 53, 23]
b = [2, 13, 14, 63, 49, 7, 3]

slope, intercept = linear_regression(a, b)

assert abs(slope + 0.18514007308160782) < eps
assert abs(intercept - 25.750304506699152) < eps


def check():
test_linear_regression()
test_correlation()
test_covariance()

check()

0 comments on commit 615e7e7

Please sign in to comment.