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
106 changes: 106 additions & 0 deletions .github/workflows/build-hmmlearn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# SPDX-FileCopyrightText: 2026 The RISE Project
# SPDX-License-Identifier: MIT
---
# This workflow is based on: https://github.com/hmmlearn/hmmlearn/blob/0.3.3/.github/workflows/build.yml
name: Build hmmlearn wheels (riscv64)

on:
workflow_dispatch:
inputs:
version:
description: 'hmmlearn version to build (git tag, e.g. 0.3.3)'
required: true
default: '0.3.3'
pull_request:
paths:
- '.github/workflows/build-hmmlearn.yml'
- 'patches/hmmlearn/**'

concurrency:
group: ${{ github.workflow }}-${{ inputs.version || '0.3.3' }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read # to fetch code (actions/checkout)

env:
# `inputs.version` is empty on pull_request events; default to 0.3.3 there.
HMMLEARN_VERSION: ${{ inputs.version || '0.3.3' }}
MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64

jobs:
setup:
uses: $/.github/workflows/_setup.yml

build_wheels:
needs: [setup]
name: Build hmmlearn ${{ inputs.version || '0.3.3' }} ${{ matrix.python }}-manylinux_riscv64
runs-on: ubuntu-24.04-riscv
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
# Per-interpreter (not abi3): the pybind11 extension links the version-specific
# ABI. cp38-cp311 dropped from upstream's cp38-cp313 (gotcha 67/84): hmmlearn's
# hard runtime dependency scikit-learn>=0.16 only has riscv64 wheels on
# pypi.riseproject.dev for cp312/cp313/cp314/cp314t, so older interpreters would
# fall back to a from-source scikit-learn build during the test-install step.
python:
- "cp312"
- "cp313"
- "cp314"
- "cp314t"

steps:
- name: Checkout hmmlearn ${{ env.HMMLEARN_VERSION }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: hmmlearn/hmmlearn
ref: ${{ env.HMMLEARN_VERSION }}
persist-credentials: false

- name: Checkout python-wheels
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: python-wheels
persist-credentials: false

- name: Patch hmmlearn source
run: git apply python-wheels/patches/hmmlearn/${{ env.HMMLEARN_VERSION }}/*.patch

- name: Build wheels
uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0
with:
output-dir: wheelhouse/
only: ${{ matrix.python }}-manylinux_riscv64
env:
CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }}
CIBW_ENVIRONMENT: >-
PIP_EXTRA_INDEX_URL=https://pypi.riseproject.dev/simple/
PIP_ONLY_BINARY=numpy,scipy,scikit-learn
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_HMMLEARN=${{ env.HMMLEARN_VERSION }}
CIBW_TEST_REQUIRES: pytest
# Mirrors upstream's own test invocation (build.yml's CIBW_TEST_COMMAND), plus
# -X gil=1: _hmmc has no Py_mod_gil slot, so cp314t re-enables the GIL at
# import and warns; hmmlearn's own filterwarnings=["error", ...] turns that
# into a collection error. CIBW_TEST_ENVIRONMENT's PYTHON_GIL=1 would be the
# usual fix, but -I (already used here) ignores all PYTHON* env vars, so it
# has to be the -X flag instead; a no-op on the non-free-threaded builds.
CIBW_TEST_COMMAND: >-
python -I -X gil=1 -mpytest --pyargs hmmlearn.tests {project}/doc

- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: hmmlearn-${{ env.HMMLEARN_VERSION }}-${{ matrix.python }}-manylinux_riscv64
path: wheelhouse/*.whl
if-no-files-found: error

publish:
name: Publish hmmlearn ${{ inputs.version || '0.3.3' }}
needs: [setup, build_wheels]
permissions:
contents: write
pull-requests: write
uses: $/.github/workflows/_publish-wheel.yml
with:
artifact-pattern: hmmlearn-${{ inputs.version || '0.3.3' }}-*-manylinux_riscv64
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From e775ca339d48d2383d849f38b4d7ff1324e5664a Mon Sep 17 00:00:00 2001
From: Ludovic Henry <git@ludovic.dev>
Date: Tue, 8 Sep 2026 06:20:37 +0200
Subject: [PATCH] Replace deprecated in-place ndarray.shape assignment with
reshape

Upstream-Status: To upstream [not yet submitted; this port workflow does not open upstream issues or PRs]

NumPy 2.5 deprecates assigning to ndarray.shape in place (only reshapes
that need a copy are still rejected outright; a plain reshape is always
the documented replacement). normalize() and GaussianHMM/GMMHMM's single-
feature covariance init hit this on every array they reshape this way,
turning `DeprecationWarning: Setting the shape on a NumPy array has been
deprecated in NumPy 2.5.` into a hard test failure wherever
`filterwarnings = ["error::DeprecationWarning:hmmlearn", ...]` (this
project's own pytest config) applies. Reproduces with numpy>=2.5 on any
architecture, not just riscv64.

Signed-off-by: Ludovic Henry <git@ludovic.dev>
---
src/hmmlearn/hmm.py | 4 ++--
src/hmmlearn/utils.py | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/hmmlearn/hmm.py b/src/hmmlearn/hmm.py
index fec0a13..59b3a64 100644
--- a/src/hmmlearn/hmm.py
+++ b/src/hmmlearn/hmm.py
@@ -316,7 +316,7 @@ class GaussianHMM(_emissions.BaseGaussianHMM, BaseHMM):
if self._needs_init("c", "covars_"):
cv = np.cov(X.T) + self.min_covar * np.eye(X.shape[1])
if not cv.shape:
- cv.shape = (1, 1)
+ cv = cv.reshape(1, 1)
self.covars_ = \
_utils.distribute_covar_matrix_to_match_covariance_type(
cv, self.covariance_type, self.n_components).copy()
@@ -576,7 +576,7 @@ class GMMHMM(_emissions.BaseGMMHMM):
if cv is None:
cv = compute_cv()
if not cv.shape:
- cv.shape = (1, 1)
+ cv = cv.reshape(1, 1)
if self.covariance_type == 'tied':
self.covars_ = np.zeros((nc, nf, nf))
self.covars_[:] = cv
diff --git a/src/hmmlearn/utils.py b/src/hmmlearn/utils.py
index a080e56..751339f 100644
--- a/src/hmmlearn/utils.py
+++ b/src/hmmlearn/utils.py
@@ -24,7 +24,7 @@ def normalize(a, axis=None):
a_sum[a_sum == 0] = 1
shape = list(a.shape)
shape[axis] = 1
- a_sum.shape = shape
+ a_sum = a_sum.reshape(shape)

a /= a_sum

--
2.50.1 (Apple Git-155)