Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/[email protected].2
uses: pypa/[email protected].3
env:
CIBW_BUILD: cp3*-*
CIBW_SKIP: pp* *i686* *musllinux* *-macosx_universal2 *-manylinux_ppc64le *-manylinux_s390x
Expand All @@ -31,8 +31,6 @@ jobs:
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_ARCHS_WINDOWS: auto64
CIBW_BEFORE_ALL_LINUX: yum install -y ninja-build python3-devel
CIBW_BEFORE_ALL_WINDOWS: choco install ninja
CIBW_BEFORE_ALL_MACOS: brew install ninja
# Needed on Windows CI to compile with Visual Studio compiler
# otherwise Meson detects a MINGW64 platform and use MINGW64
# toolchain
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- name: Re-install local
run: |
pixi reinstall --frozen fastcan
pixi reinstall -e lint --frozen fastcan

- name: Lint with ruff
run: |
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:

- name: Re-install local
run: |
pixi reinstall --frozen fastcan
# Needed on Windows CI to compile with Visual Studio compiler
# otherwise Meson detects a MINGW64 platform and use MINGW64
# toolchain
pixi reinstall -e dev --frozen fastcan -- -Csetup-args=--vsenv

- name: Test with pytest
run: |
Expand Down
2,321 changes: 1,247 additions & 1,074 deletions pixi.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ mypy = "*"

[tool.pixi.feature.build.dependencies]
python-build = "*"
pip = "*"

[tool.pixi.feature.nogil.dependencies]
python-freethreading = "*"
Expand Down Expand Up @@ -104,6 +105,13 @@ test-coverage = { cmd = "rm -rf .coverage && pytest --cov-report $FMT --cov=$PAC
[tool.pixi.feature.build.tasks]
build-wheel = "rm -rf dist && python -m build -wnx -Cinstall-args=--tags=runtime,python-runtime,devel"
build-sdist = "rm -rf dist && python -m build --sdist"
rebuild = "rm -rf build && pip install --no-deps --force-reinstall -e ."

# Needed on Windows CI to compile with Visual Studio compiler
# otherwise Meson detects a MINGW64 platform and use MINGW64
# toolchain
[tool.pixi.feature.build.target.win-64.tasks]
rebuild = "rm -rf build && pip install --no-deps --force-reinstall -e . -Csetup-args=--vsenv"

[tool.pixi.feature.fmt.tasks]
fmt = { cmd = "black .", cwd = "fastcan" }
Expand Down
Empty file removed tests/__init__.py
Empty file.
42 changes: 40 additions & 2 deletions tests/test_narx.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ def test_narx(nan, multi_output):
y_hat = narx_array_init_msa.predict(X, y_init=y_init)
assert_array_equal(y_hat[:narx_array_init_msa.max_delay_], y_init)

print_narx(narx_array_init_msa)

with pytest.raises(ValueError, match=r"`coef_init` should have the shape of .*"):
narx_array_init_msa.fit(X, y, coef_init=np.zeros(narx_osa_msa_coef.size))

Expand Down Expand Up @@ -492,3 +490,43 @@ def test_tp2fd():
poly_ids[-1][-1] = 5
with pytest.raises(ValueError, match=r"The element x of poly_ids should.*"):
_, _ = tp2fd(time_shift_ids, poly_ids)

def test_print_narx(capsys):
X = np.random.rand(10, 2)
y = np.random.rand(10, 2)
feat_ids = np.array([[0, 1], [1, 2]])
delay_ids = np.array([[1, 0], [2, 2]])

narx = NARX(
feat_ids=feat_ids,
delay_ids=delay_ids,
output_ids=[0, 1],
)
narx.fit(X, y)
print_narx(narx)
captured = capsys.readouterr()
# Check if the header is present in the output
assert "| yid | Term | Coef |" in captured.out
# Check if the intercept line for yid 0 is present
assert "| 0 | Intercept |" in captured.out
# Check if the intercept line for yid 1 is present
assert "| 1 | Intercept |" in captured.out
# Check if the term line for yid 0 is present
assert "| 0 | X[k-1,0]*X[k,1] |" in captured.out
# Check if the term line for yid 1 is present
assert "| 1 |X[k-2,1]*y_hat[k-2,0]|" in captured.out


def test_make_narx_refine_print(capsys):
X = np.random.rand(10, 2)
y = np.random.rand(10, 2)
_ = make_narx(
X,
y,
n_terms_to_select=2,
max_delay=2,
poly_degree=2,
refine_drop=1,
)
captured = capsys.readouterr()
assert "No. of iterations: " in captured.out