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
60 changes: 60 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SPDX-License-Identifier: MPL-2.0
name: Documentation

on:
push:
branches: [master]
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: documentation-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: '3.12'
cache: pip
cache-dependency-path: requirements-docs.txt
- uses: haskell-actions/setup@7fd2bb5ca789761088fbc831406b2910e47e56f1 # v2
with:
ghc-version: '9.10.3'
cabal-version: '3.16.1.0'
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: build-docs/cabal
key: docs-haddock-${{ hashFiles('hmath.cabal', 'cabal.project', 'src/**', 'cbits/**') }}
restore-keys: docs-haddock-
- name: Build documentation and Haskell reference
run: |
python -m pip install -r requirements-docs.txt
python tools/build_docs.py
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
with:
path: site

deploy:
if: github.repository == 'wavefnd/hmath' && github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-24.04
concurrency:
group: documentation-pages
cancel-in-progress: false
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4
47 changes: 1 addition & 46 deletions .github/workflows/publish-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,7 @@ concurrency:
jobs:
build:
if: github.repository == 'wavefnd/hmath' && github.ref == 'refs/heads/master'
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: '3.12'
- uses: haskell-actions/setup@7fd2bb5ca789761088fbc831406b2910e47e56f1 # v2
with:
ghc-version: '9.10.3'
cabal-version: '3.16.1.0'
- name: Read package version
id: version
run: |
python - <<'PY'
import os
import pathlib
import tomllib
metadata = tomllib.loads(pathlib.Path('pyproject.toml').read_text())
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
print('version=' + metadata['project']['version'], file=output)
PY
- name: Build and validate the distributions
run: |
python -m pip install build twine numpy cffi
python -m build --outdir dist
python -m twine check --strict dist/*
cabal update
python meson-build.py . build-python/libhmath.so build-python/libhmath.so.1 --builddir build-python/cabal
python -m pip install dist/*.whl
HMATH_LIBRARY="$PWD/build-python/libhmath.so" python - <<'PY'
import pathlib
import runpy
import hmath
if 'site-packages' not in pathlib.Path(hmath.__file__).parts:
raise SystemExit('Validation must import the installed wheel')
runpy.run_path('bindings/python/test_bindings.py', run_name='__main__')
PY
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: python-distributions
path: dist/*
if-no-files-found: error
uses: ./.github/workflows/python-wheels.yml

publish:
needs: build
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/python-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-License-Identifier: MPL-2.0
name: Python wheels

on:
push:
branches: [master]
paths-ignore: ['docs/**', 'mkdocs.yml', 'requirements-docs.txt', 'tools/build_docs.py', 'README.md']
pull_request:
paths-ignore: ['docs/**', 'mkdocs.yml', 'requirements-docs.txt', 'tools/build_docs.py', 'README.md']
workflow_call:
outputs:
version:
description: Version read from the built package metadata
value: ${{ jobs.build.outputs.version }}

permissions:
contents: read

concurrency:
group: python-wheels-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name != 'workflow_dispatch' }}

jobs:
build:
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- name: Read package version
id: version
run: |
python - <<'PY'
import os, pathlib, tomllib
version = tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version']
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
print('version=' + version, file=output)
PY
- name: Build self-contained manylinux wheel and source distribution
run: |
docker run --rm --volume "$PWD:/io" \
quay.io/pypa/manylinux_2_28_x86_64@sha256:e0adf18521ad35192df733a6c62d35df7801957d24e0470238aacecfab2188a3 \
bash /io/tools/build_python_wheel.sh
python -m pip install twine
python -m twine check --strict dist/*
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: python-distributions
path: dist/*
if-no-files-found: error

test:
needs: build
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
python: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
container: python:${{ matrix.python }}-slim-bookworm
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: python-distributions
path: /tmp/hmath-distributions
- name: Verify installation without GHC or a system HMath library
run: |
python -m pip install /tmp/hmath-distributions/*.whl
cd "$RUNNER_TEMP"
python "$GITHUB_WORKSPACE/tools/check_python_wheel.py"
python -m pip install numpy cffi
python "$GITHUB_WORKSPACE/tools/check_python_wheel.py" "$GITHUB_WORKSPACE/bindings/python/test_bindings.py"
python "$GITHUB_WORKSPACE/tools/check_docs_examples.py"
58 changes: 38 additions & 20 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ name: Validate

on:
push:
branches: [master]
paths-ignore: ['docs/**', 'mkdocs.yml', 'requirements-docs.txt', 'tools/build_docs.py', 'README.md']
pull_request:
paths-ignore: ['docs/**', 'mkdocs.yml', 'requirements-docs.txt', 'tools/build_docs.py', 'README.md']
workflow_dispatch:

permissions:
contents: read

concurrency:
group: validate-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
linux:
strategy:
Expand All @@ -20,17 +27,34 @@ jobs:
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: haskell-actions/setup@7fd2bb5ca789761088fbc831406b2910e47e56f1 # v2
id: haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: '3.16.1.0'
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
~/.cabal/packages
${{ steps.haskell.outputs.cabal-store }}
dist-newstyle
build-ci/cabal
build-interchange/cabal
key: cabal-${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.buildtype }}-${{ hashFiles('hmath.cabal', 'cabal.project', 'src/**', 'cbits/**', 'test/**', 'bench/**') }}
restore-keys: cabal-${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.buildtype }}-
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: '3.12'
cache: pip
cache-dependency-path: pyproject.toml
- name: Dependencies
run: |
sudo apt-get update
sudo apt-get install -y liblapacke-dev libopenblas-dev zlib1g-dev cmake ninja-build clang
python -m pip install meson==1.8.5 numpy scipy cffi h5py pyarrow onnx
python -m pip install meson==1.8.5 numpy cffi
- name: Differential validation dependencies
if: matrix.ghc == '9.10.3' && matrix.buildtype == 'release'
run: |
python -m pip install scipy h5py pyarrow onnx
cabal update
- name: Wave compiler
if: matrix.ghc == '9.10.3' && matrix.buildtype == 'release'
Expand All @@ -50,37 +74,24 @@ jobs:
if [ '${{ matrix.ghc }}' = '9.10.3' ] && [ '${{ matrix.buildtype }}' = release ]; then
wave_tests=enabled
fi
meson setup build-ci --buildtype=${{ matrix.buildtype }} -Dwerror=true -Dpython_bindings=enabled -Dwave_bindings="$wave_tests" -Dbenchmarks=true
meson setup build-ci --buildtype=${{ matrix.buildtype }} -Doffline=true -Dwerror=true -Dpython_bindings=enabled -Dwave_bindings="$wave_tests" -Dbenchmarks=true
meson compile -C build-ci
meson test -C build-ci --print-errorlogs
python tools/check_install.py build-ci
python tools/check_abi.py build-ci/libhmath.so
- name: Properties and interchange
if: matrix.ghc == '9.10.3' && matrix.buildtype == 'release'
run: |
cabal test hmath-properties -fvalidation-frameworks --test-show-details=direct
cabal test hmath-properties -fvalidation-frameworks -fcriterion-benchmarks --test-show-details=direct
python tools/check_interchange.py --builddir=build-interchange --require-optional
- name: Sanitized metadata and DLPack fuzzing
if: matrix.ghc == '9.10.3' && matrix.buildtype == 'release'
run: python tools/run_fuzz.py --runs=100000 --output=build-ci/fuzz.log
- name: Criterion fixture and native benchmark smoke
if: matrix.ghc == '9.10.3' && matrix.buildtype == 'release'
run: |
cabal bench hmath-criterion -fcriterion-benchmarks --benchmark-options='--iters 1'
cabal bench hmath-criterion -fvalidation-frameworks -fcriterion-benchmarks --benchmark-options='--iters 1'
python tools/benchmark.py --library=build-ci/libhmath.so --native=build-ci/hmath-native-benchmark --iterations=10 --output=build-ci/benchmark.json
- name: Python distribution validation
if: matrix.ghc == '9.10.3' && matrix.buildtype == 'release'
run: |
python -m pip install build twine
python -m build --outdir dist
python -m twine check --strict dist/*
python -m pip install dist/*.whl
HMATH_LIBRARY="$PWD/build-ci/libhmath.so" python - <<'PY'
import pathlib
import runpy
import hmath
assert 'site-packages' in pathlib.Path(hmath.__file__).parts
runpy.run_path('bindings/python/test_bindings.py', run_name='__main__')
PY
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
Expand All @@ -101,8 +112,15 @@ jobs:
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: haskell-actions/setup@7fd2bb5ca789761088fbc831406b2910e47e56f1 # v2
id: haskell
with:
ghc-version: '9.10.3'
cabal-version: '3.16.1.0'
- run: cabal update
- run: cabal build lib:hmath flib:hmath -f-interchange-zlib --ghc-options="-Wall -Werror"
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
${{ steps.haskell.outputs.cabal-store }}
dist-newstyle
key: cabal-portability-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('hmath.cabal', 'cabal.project', 'src/**', 'cbits/**') }}
restore-keys: cabal-portability-${{ runner.os }}-${{ runner.arch }}-
- run: cabal build --offline lib:hmath flib:hmath -f-interchange-zlib --ghc-options="-Wall -Werror"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ __pycache__/
# Local Cabal overrides
/cabal.project.local
/cabal.project.local~
/docs/
/site/
/*.egg-info/
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## 1.0.0 — Unreleased
## 1.0.1

- Bundle the native HMath library and required runtime dependencies in the Linux x86-64 Python wheel, fixing import failures after a normal pip installation.
- Validate the same release wheel in clean CPython 3.9–3.14 environments without a system HMath library, GHC, or native-library environment overrides.
- Add a searchable documentation site with installation, guides, language references, and generated Haskell API documentation.
- Cache Haskell builds and dependencies; run differential validation once rather than repeating it across the compiler/build-type matrix.

## 1.0.0

- Add checked native tensors, ownership and cancellation contracts, and CPU DLPack exchange.
- Establish C, Python, and Wave as the officially maintained external interfaces.
Expand All @@ -9,8 +16,9 @@
- Add integrated validation, benchmarks, native installation checks, and build metadata.

The first release covers the implemented Haskell numerical modules and the
C, Python, and Wave interfaces on Linux x86-64. Python distributions contain
bindings and require a separately installed HMath shared library.
C, Python, and Wave interfaces on Linux x86-64. Python distributions in 1.0.0
contain only bindings and require a separately installed HMath shared library.
Upgrade to 1.0.1 or newer for a self-contained Linux x86-64 Python wheel.

Package versions follow SemVer: compatible fixes increment the patch, compatible
features increment the minor, and breaking public API changes increment the major.
Expand Down
15 changes: 15 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include LICENSE README.md CHANGELOG.md ROADMAP.md hmath.cabal cabal.project meson-build.py
include meson.build meson_options.txt mkdocs.yml requirements-docs.txt fourmolu.yaml .clang-format
recursive-include src *.hs
recursive-include cbits *.c *.h
recursive-include include *.h
recursive-include bindings/python/_hmath_native/licenses *
recursive-include bindings/python *.py LICENSE
recursive-include bindings/wave *.wave
recursive-include docs *.md
recursive-include tools *.py *.sh
recursive-include test *.hs *.c *.py *.txt
recursive-include examples *.hs *.c *.py
recursive-include bench *.hs *.c
recursive-include meson *.in
recursive-include .github/workflows *.yml
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

HMath is a mathematics and numerical computing library with Python bindings, written in Haskell. It also provides native Haskell, C, and Wave interfaces.

The 1.0.0 release targets Linux x86-64. The Python distribution is named **hmath-python** and is imported as `hmath`.
HMath targets Linux x86-64. The Python distribution is named **hmath-python** and is imported as `hmath`. Version 1.0.1 includes the native library and runtime; GHC is not needed to use its Python wheel.

## Python quick start

Install the Python package on Linux x86-64:

```sh
pip install hmath-python
python -m pip install --upgrade --only-binary=:all: "hmath-python>=1.0.1"
```

```python
Expand All @@ -24,6 +24,8 @@ with Tensor.matrix([1, 2, 3, 4], 2, 2) as matrix:

Use `with` to release native resources automatically. Invalid operations raise `HMathError`. Install `hmath-python[numpy,cffi]` for optional NumPy and cffi support.

See the [documentation](https://wavefnd.github.io/hmath/) for installation requirements, tutorials, API reference, and C/Wave integration.

## Features

- **Core math:** checked scalar operations, numeric types, constants, units, number theory, and polynomials.
Expand Down
Loading
Loading