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
22 changes: 11 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
os: [ubuntu-latest, macos-11, windows-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'

- name: Install dependencies
run: |
Expand All @@ -26,26 +26,26 @@ jobs:
pip install -r requirements.txt

- name: Build wheels
uses: pypa/cibuildwheel@v2.11.2
uses: pypa/cibuildwheel@v2.23.3
env:
CIBW_BUILD: "cp38* cp39* cp310* cp311*"
CIBW_BUILD: "cp310* cp311* cp312* cp313"
CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux*"
CIBW_ARCHS_MACOS: x86_64 arm64

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'

- name: Install dependencies
run: |
Expand All @@ -57,7 +57,7 @@ jobs:
- name: Build sdist
run: python setup.py sdist

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
path: dist/*.tar.gz

Expand All @@ -69,7 +69,7 @@ jobs:
# alternatively, to publish when a GitHub Release is created, use the following rule:
#if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: artifact
path: dist
Expand Down
24 changes: 7 additions & 17 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,27 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: '${{ matrix.python-version }}'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
pip install flake8 pytest
- if: matrix.python-version == '3.7'
run: pip install numpy==1.17.5

- if: matrix.python-version == '3.8'
run: pip install numpy==1.17.5

- if: matrix.python-version == '3.9'
run: pip install numpy==1.21.0
pip install numpy==2.2.5

# install cpu versions of torch for CI
- if: matrix.os == 'macos-latest'
run: pip install torch==1.8.0 torchvision==0.9.0
run: pip install torch==2.7.0 torchvision==0.22.0

- if: matrix.os == 'ubuntu-latest'
run: pip install --find-links https://download.pytorch.org/whl/torch_stable.html torch==1.8.0+cpu torchvision==0.9.0+cpu

- if: matrix.os == 'windows-latest'
run: pip install --find-links https://download.pytorch.org/whl/torch_stable.html torch==1.8.0+cpu torchvision==0.9.0+cpu
run: pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cpu

- name: Lint with flake8
run: |
Expand Down
4 changes: 2 additions & 2 deletions pymde/experiment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def _is_discrete(dtype):
for other in (
np.integer,
np.bool_,
np.string_,
np.unicode_,
np.bytes_,
np.str_,
np.object_,
)
]
Expand Down
4 changes: 2 additions & 2 deletions pymde/functions/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.. math::

f_k(d_k) = \\ell(d_k, \delta_k), \\quad k=1, \\ldots, p,
f_k(d_k) = \\ell(d_k, \\delta_k), \\quad k=1, \\ldots, p,

where
:math:`\\ell` is a loss function, :math:`\\delta_k` is a nonnegative deviation
Expand Down Expand Up @@ -102,7 +102,7 @@ class Huber(Function):
"""
.. math::

\ell(d, \\delta) = \\begin{cases}
\\ell(d, \\delta) = \\begin{cases}
\\cdot (d - \\delta)^2 & d < \\text{threshold} \\\\
\\text{threshold}(2(d - \\delta) - \\cdot \\text{threshold})
& d \\geq \\text{threshold}
Expand Down
4 changes: 2 additions & 2 deletions pymde/functions/penalties.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def forward(self, distances):


class Log1p(Function):
""":math:`p(d) = \log(1 + d^{\\text{exponent}})`"""
""":math:`p(d) = \\log(1 + d^{\\text{exponent}})`"""

def __init__(self, weights, exponent=1.5):
super(Log1p, self).__init__()
Expand All @@ -322,7 +322,7 @@ def forward(self, distances):


class Log(Function):
""":math:`p(d) = \log(1 - \\exp(-d^\\text{exponent}))`"""
""":math:`p(d) = \\log(1 - \\exp(-d^\\text{exponent}))`"""

def __init__(self, weights, exponent=1.0):
super(Log, self).__init__()
Expand Down
6 changes: 3 additions & 3 deletions pymde/preprocess/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _shortest_paths(shape, node, max_length, unweighted, sample_prob):


def __init_process(data, indptr, indices):
global __this_module
global __this_module # noqa: F824
__this_module.__data = data
__this_module.__indptr = indptr
__this_module.__indices = indices
Expand Down Expand Up @@ -395,7 +395,7 @@ def shortest_paths(
if verbose:
LOGGER.info(
f"Computing shortest path distances (retaining "
f"{100*retain_fraction:.2f} percent with "
f"{100 * retain_fraction:.2f} percent with "
f"max_distance={max_length}) ..."
)

Expand All @@ -419,7 +419,7 @@ def to_shared_memory(array):
array = np.ctypeslib.as_ctypes(array)
return sharedctypes.RawArray(array._type_, array)

global __this_module
global __this_module # noqa: F824
data = __this_module.__data = to_shared_memory(graph.A.data)
indptr = __this_module.__indptr = to_shared_memory(graph.A.indptr)
indices = __this_module.__indices = to_shared_memory(graph.A.indices)
Expand Down
11 changes: 5 additions & 6 deletions pymde/quadratic.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def _spectral(
which="SM",
ncv=num_lanczos_vectors,
tol=1e-4,
v0=np.ones(L.shape[0]),
maxiter=L.shape[0] * 5,
)
order = np.argsort(eigenvalues)[1:k]
Expand Down Expand Up @@ -123,17 +122,17 @@ def _spectral(
def spectral(
n_items, embedding_dim, edges, weights, cg=False, max_iter=40, device="cpu"
):
"""Compute a spectral embedding
r"""Compute a spectral embedding


Solves the quadratic MDE problem

.. math::

\\begin{array}{ll}
\\mbox{minimize} & \\sum_{(i, j) in \\text{edges}} w_{ij} d_{ij}^2 \\\\
\\mbox{subject to} & (1/n) X^T X = I, \quad d_{ij} = |x_i - x_j|_2.
\\end{array}
\begin{array}{ll}
\mbox{minimize} & \sum_{(i, j) in \text{edges}} w_{ij} d_{ij}^2 \\
\mbox{subject to} & (1/n) X^T X = I, \quad d_{ij} = |x_i - x_j|_2.
\end{array}

By default, the problem is solved using a Lanczos method. If cg=True,
LOBPCG is used; LOBPCG is warm-started by running a projected quasi-newton
Expand Down
47 changes: 8 additions & 39 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,14 @@
[build-system]
requires = [
# NumPy dependencies copied from SciPy:
# https://github.com/scipy/scipy/blob/3df34d96123678e4b1b03aba83b84d8ff08817e5/pyproject.toml
# NumPy dependencies - to update these, sync from
# https://github.com/scipy/oldest-supported-numpy/, and then
# update minimum version to match our install_requires min version
# ----------------------------------------------------------------

# now matches minimum supported version, keep here as separate requirement
# to be able to sync more easily with oldest-supported-numpy
"numpy==1.19.5; python_version=='3.8' and platform_machine=='aarch64' and platform_python_implementation != 'PyPy'",

# arm64 on Darwin supports Python 3.8 and above requires numpy>=1.21.0
# (first version with arm64 wheels available)
"numpy==1.21.0; python_version=='3.8' and platform_machine=='arm64' and platform_system=='Darwin'",
"numpy==1.21.0; python_version=='3.9' and platform_machine=='arm64' and platform_system=='Darwin'",

# loongarch64 requires numpy>=1.22.0
"numpy==1.22.0; platform_machine=='loongarch64'",

# On Windows we need to avoid 1.21.6, 1.22.0 and 1.22.1 because they were
# built with vc142. 1.22.3 is the first version that has 32-bit Windows
# wheels *and* was built with vc141. So use that:
"numpy==1.22.3; python_version=='3.10' and platform_system=='Windows' and platform_python_implementation != 'PyPy'",

# default numpy requirements
"numpy==1.19.5; python_version=='3.8' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_machine!='aarch64' and platform_machine!='loongarch64' and platform_python_implementation != 'PyPy'",
"numpy==1.19.5; python_version=='3.9' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_machine!='loongarch64' and platform_python_implementation != 'PyPy'",
# Note that 1.21.3 was the first version with a complete set of 3.10 wheels,
# however macOS was broken and it's safe C API/ABI-wise to build against 1.21.6
# (see oldest-supported-numpy issues gh-28 and gh-45)
"numpy==1.21.6; python_version=='3.10' and (platform_system!='Windows' and platform_machine!='loongarch64') and platform_python_implementation != 'PyPy'",
"numpy==1.23.2; python_version=='3.11' and platform_python_implementation != 'PyPy'",

# For Python versions which aren't yet officially supported,
# we specify an unpinned NumPy which allows source distributions
# to be used and allows wheels to be used as soon as they
# become available.
"numpy; python_version>='3.12'",
"numpy; python_version>='3.8' and platform_python_implementation=='PyPy'",

# https://github.com/scipy/scipy/blob/55cae814e23208354bf16b84be47b5070b4c1c89/pyproject.toml#L25-L31
# numpy requirement for wheel builds for distribution on PyPI - building
# against 2.x yields wheels that are also compatible with numpy 1.x at
# runtime.
# Note that building against numpy 1.x works fine too - users and
# redistributors can do this by installing the numpy version they like and
# disabling build isolation.
"numpy>=2.0.0",
"scipy >= 1.6",
"setuptools",
"wheel",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_version(rel_path):
setup_requires=["setuptools>=18.0", "cython"],
install_requires=[
"matplotlib",
"numpy >= 1.17.5",
"numpy >= 2.0",
"pynndescent",
"scipy",
"torch >= 1.7.1",
Expand Down
Loading