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: 2 additions & 2 deletions .github/workflows/asv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
git branch main origin/main

- uses: prefix-dev/setup-pixi@v0.9.0
- uses: prefix-dev/setup-pixi@v0.9.3
with:
environments: dev
cache: true
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
cp -r "$d"/* "asv_benchmarks/results/"
done

- uses: prefix-dev/setup-pixi@v0.9.0
- uses: prefix-dev/setup-pixi@v0.9.3
with:
environments: dev
cache: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

steps:
- uses: actions/checkout@v5
- uses: prefix-dev/setup-pixi@v0.9.0
- uses: prefix-dev/setup-pixi@v0.9.3
with:
environments: static
cache: true
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ jobs:

steps:
- uses: actions/checkout@v5
- uses: prefix-dev/setup-pixi@v0.9.0
- uses: prefix-dev/setup-pixi@v0.9.3
with:
environments: >-
dev
docs
nogil
py39
cache: true

- name: Re-install local
run: |
pixi reinstall -e dev --frozen fastcan
pixi reinstall -e docs --frozen fastcan
pixi reinstall -e nogil --frozen fastcan
pixi reinstall -e py39 --frozen fastcan

- name: Test with pytest
run: |
pixi run -e dev test
pixi run -e py39 test
- name: Test with doctest
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: prefix-dev/setup-pixi@v0.9.0
- uses: prefix-dev/setup-pixi@v0.9.3
with:
environments: dev
cache: true
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
uses: pypa/cibuildwheel@v3.2.1
env:
CIBW_SKIP: "*_i686 *_ppc64le *_s390x *_universal2 *-musllinux_* cp314t*"
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.10"
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9"
CIBW_ARCHS_LINUX: auto
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_ARCHS_WINDOWS: AMD64
Expand Down
22 changes: 12 additions & 10 deletions fastcan/_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _beam_search(
X, V, n_features_to_select, beam_width, indices_include, mask_exclude, tol, verbose
):
"""
Perform beam search to find the best subset of features.
Beam search with SSC.

Parameters:
X : np.ndarray
Expand Down Expand Up @@ -48,12 +48,16 @@ def _beam_search(
X_support, X_selected = _prepare_candidates(
X, mask_exclude, indices_include
)
if X_selected.shape[1] == 0:
beams_scores = np.sum((X.T @ V) ** 2, axis=1)
beams_scores[~X_support] = 0
else:
W_selected = orth(X_selected)
selected_score = np.sum((W_selected.T @ V) ** 2)
beams_scores = _gram_schmidt(
X, X_support, X_selected, selected_score, V, tol
)
beams_selected_ids = [indices_include for _ in range(beam_width)]
W_selected = orth(X_selected)
selected_score = np.sum((W_selected.T @ V) ** 2)
beams_scores = _gram_schmidt(
X, X_support, X_selected, selected_score, V, tol
)
beams_selected_ids, top_k_scores = _select_top_k(
beams_scores[None, :],
beams_selected_ids,
Expand Down Expand Up @@ -123,11 +127,9 @@ def _select_top_k(
return new_ids_selected, top_k_scores


def _gram_schmidt(X, X_support, X_selected, selected_score, V, tol, modified=True):
def _gram_schmidt(X, X_support, X_selected, selected_score, V, tol):
X = np.copy(X)
if modified:
# Change to Modified Gram-Schmidt
W_selected = orth(X_selected)
W_selected = orth(X_selected) # Change to Modified Gram-Schmidt
scores = np.zeros(X.shape[1])
for i, support in enumerate(X_support):
if not support:
Expand Down
15,375 changes: 9,634 additions & 5,741 deletions pixi.lock

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ channels = ["conda-forge"]
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64", "linux-aarch64"]

[dependencies]
python = ">=3.10"
scikit-learn = ">=1.7.0,!=1.7.1"
cython = ">=3.1.0" # build dependencies
meson-python = ">=0.18.0" # build dependencies
python = ">=3.9"
scikit-learn = ">=1.6.0"
cython = ">=3.0.10" # build dependencies
meson-python = ">=0.16.0" # build dependencies

[target.osx-64.dependencies]
compilers = "*" # build dependencies
Expand Down Expand Up @@ -74,12 +74,13 @@ python-build = "*"
pip = "*"

[feature.nogil.dependencies]
python = "<3.14"
python-freethreading = "*"
cython = ">=3.1.0" # build dependencies
meson-python = ">=0.18.0" # build dependencies

[feature.nogil.pypi-dependencies]
scikit-learn = ">=1.7.0,!=1.7.1"
scikit-learn = ">=1.6.0"
fastcan = { path = ".", editable = true }

[tasks]
Expand Down Expand Up @@ -138,9 +139,16 @@ pyodide-build-recipe = { cmd = "rm -rf dist && bash -c 'source emsdk/emsdk_env.s
pyodide-download = '''bash -c "[ -d pyodide ] || (LATEST_TAG=$(curl -s https://api.github.com/repos/pyodide/pyodide/releases/latest | grep \"tag_name\" | cut -d \" -f4) && curl -L https://github.com/pyodide/pyodide/releases/download/${LATEST_TAG}/pyodide-${LATEST_TAG}.tar.bz2 | tar -xjf -)"'''
pyodide-test-recipe = { cmd = "mv ../dist/* . && python -m http.server --directory .", cwd = "pyodide", depends-on = ["pyodide-download", "pyodide-build-recipe"] }

[feature.py39.dependencies]
python = "==3.9.0"
scikit-learn = "==1.6.0"
meson-python = "==0.16.0"
cython = "==3.0.10"

[environments]
dev = ["test", "build", "jupyter", "asv"]
docs = ["docs"]
static = { features = ["static"], no-default-feature = true }
nogil = { features = ["nogil"], no-default-feature = true }
wasm = { features = ["wasm"], no-default-feature = true }
wasm = { features = ["wasm"], no-default-feature = true }
py39 = { features = ["py39", "test"] }
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ description = "A fast canonical-correlation-based greedy search algorithm"
authors = [
{ name = "Matthew Sikai Zhang", email = "matthew.szhang91@gmail.com" },
]
requires-python = ">=3.10"
requires-python = ">=3.9"
readme = "README.rst"
license = { file = "LICENSE" }

dependencies = ["scikit-learn>=1.7.0,!=1.7.1"]
dependencies = ["scikit-learn>=1.6.0"]

classifiers = [
"Development Status :: 4 - Beta",
Expand All @@ -19,6 +19,7 @@ classifiers = [
"Operating System :: Unix",
"Operating System :: MacOS",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -33,7 +34,13 @@ download = "https://pypi.org/project/fastcan/#files"
tracker = "https://github.com/scikit-learn-contrib/fastcan/issues"

[build-system]
requires = ["meson-python>=0.18.0", "Cython>=3.1.0", "scikit-learn>=1.7.0"]
requires = [
"scikit-learn>=1.6.0",
"meson-python>=0.18.0; python_version > '3.9'",
"Cython>=3.1.0; python_version > '3.9'",
"meson-python==0.16.0; python_version == '3.9'",
"Cython==3.0.10; python_version == '3.9'",
]
build-backend = "mesonpy"

# Needed on Windows CI to compile with Visual Studio compiler
Expand Down