Skip to content
Open
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
15 changes: 15 additions & 0 deletions .covdbg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Windows C++ coverage for run_coverage.yml (windows_msvc): the extension module
# (*_apytypes*.pyd), with the sources in this checkout, the same selection as before.
version: 1
source_root: "."
coverage:
default:
files:
include:
- "src/**"
- "lib/**"
- "subprojects/**"
- "build/**"
modules:
include:
- "*_apytypes*.pyd"
59 changes: 23 additions & 36 deletions .github/workflows/run_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ jobs:
if: ${{ !cancelled()}}
run: |
lcov --rc branch_coverage=1 --rc geninfo_unexecuted_blocks=1 \
--ignore-errors mismatch,mismatch --ignore-errors unused \
--ignore-errors mismatch,mismatch,inconsistent --ignore-errors unused \
--ignore-errors mismatch --capture --directory . \
--output-file coverage.info
lcov --rc branch_coverage=1 --rc geninfo_unexecuted_blocks=1 \
--ignore-errors mismatch,mismatch --ignore-errors unused \
--ignore-errors mismatch,mismatch,inconsistent --ignore-errors unused \
--ignore-errors mismatch --extract coverage.info $PWD/src/'*'
lcov --rc branch_coverage=1 --rc geninfo_unexecuted_blocks=1 \
--ignore-errors mismatch,mismatch --ignore-errors unused \
--ignore-errors mismatch,mismatch,inconsistent --ignore-errors unused \
--ignore-errors mismatch --list coverage.info
find . -name '*.gc*' -delete
# gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o cobertura.xml --root $PWD
Expand All @@ -129,6 +129,9 @@ jobs:
os: ["windows-latest"]

runs-on: ${{ matrix.os }}
permissions:
contents: read
id-token: write # covdbg identifies this repository by the job's OIDC token
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -145,48 +148,32 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install pytest-cov ninja "meson>=1.10.1" meson-python numpy setuptools_scm
choco install opencppcoverage --no-progress -y
- name: Install APyTypes
shell: pwsh
run: |
git fetch --tags
python -m pip install --no-deps --no-build-isolation -v --editable . -Csetup-args=-Dbuildtype=release -Csetup-args=-Ddebug=true -Csetup-args=-Db_lto=false -Csetup-args=-Doptimization=1
# GitHub issues no OIDC token to pull requests from forks, so C++ coverage is measured on
# pushes and on pull requests from branches of this repository; fork pull requests run the tests only.
- name: Set up covdbg
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: liasoft/setup-covdbg@08409fcb6447e0a1473b61701443fc2453c87380 # v1.1.1
with:
version: 'latest'
- name: Test with pytest and collect C++ coverage
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
shell: pwsh
run: |
$openCppCoverage = $null
$cmd = Get-Command OpenCppCoverage -ErrorAction SilentlyContinue
if ($cmd) {
$openCppCoverage = $cmd.Source
}
if (-not $openCppCoverage) {
$chocoRoot = if ($env:ChocolateyInstall) { $env:ChocolateyInstall } else { 'C:\\ProgramData\\chocolatey' }
$candidates = @(
(Join-Path $chocoRoot 'bin\\OpenCppCoverage.exe'),
(Join-Path $chocoRoot 'lib\\opencppcoverage\\tools\\OpenCppCoverage.exe'),
(Join-Path $chocoRoot 'lib\\OpenCppCoverage\\tools\\OpenCppCoverage.exe'),
(Join-Path ${env:ProgramFiles} 'OpenCppCoverage\\OpenCppCoverage.exe'),
(Join-Path ${env:ProgramFiles(x86)} 'OpenCppCoverage\\OpenCppCoverage.exe')
)
foreach ($candidate in $candidates) {
if ($candidate -and (Test-Path $candidate)) {
$openCppCoverage = $candidate
break
}
}
}
if (-not $openCppCoverage) {
throw 'OpenCppCoverage executable not found in expected Chocolatey/Program Files locations.'
}
& $openCppCoverage --quiet --cover_children --sources "${{ github.workspace }}" --modules "*_apytypes*.pyd" --export_type cobertura:coverage-windows-msvc.xml -- python -m pytest lib/test --log-level=DEBUG --color=yes
if (!(Test-Path 'coverage-windows-msvc.xml')) {
throw 'OpenCppCoverage did not produce coverage-windows-msvc.xml'
}
if ((Get-Item 'coverage-windows-msvc.xml').Length -lt 200) {
throw 'coverage-windows-msvc.xml was generated but appears empty'
}
covdbg --config .covdbg.yaml --follow-children --propagate-exit-code --output coverage-windows-msvc.covdb python -m pytest lib/test --log-level=DEBUG --color=yes
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
covdbg convert --input coverage-windows-msvc.covdb --format COBERTURA --output coverage-windows-msvc.xml
- name: Test with pytest
if: ${{ !(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
shell: pwsh
run: |
python -m pytest lib/test --log-level=DEBUG --color=yes
- name: Upload coverage reports to Codecov
if: ${{ !cancelled()}}
if: ${{ !cancelled() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
files: coverage-windows-msvc.xml
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
hooks:
- id: clang-format
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.49.1
rev: v0.50.0
hooks:
- id: markdownlint
- repo: https://github.com/pre-commit/pygrep-hooks
Expand All @@ -34,7 +34,7 @@ repos:
- id: text-unicode-replacement-char
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.17.1
rev: v0.17.2
hooks:
# Run the linter.
- id: ruff
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SIMD for single-limb fixed-point complex array multiplication and division.
- Many creation functions have a `spec` argument where one can provide an `APy*`
object that the new object will inherit all properties (number of bits etc) from.
- `next_up` and `next_down` for real fixed-point scalars and real arrays.
- Utility function `nextafter` for real arrays.

### Fixed

Expand All @@ -35,8 +37,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `APyFixedArray.to_bits` for 64-bit NumPy arrays on 32-bit systems.
- `prod` and `cumprod` are using fewer bits for fixed-point arrays, see the
documentation for exact expressions.
- Bug in floating-point cast for values between the largest subnormal and
- Floating-point cast for values between the largest subnormal and
the smallest normal value of the destination format.
- Floating-point addition with mixed formats.
- Floating-point addition when subnormals are rounded to normals for large mantissas.
- Overflow handling for floating-point addition with Jamming.

### Changed

Expand Down
4 changes: 4 additions & 0 deletions docs/api/apyfixed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@

.. automethod:: copy

.. automethod:: next_up

.. automethod:: next_down

Properties
----------

Expand Down
4 changes: 4 additions & 0 deletions docs/api/apyfixedarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@

.. automethod:: min

.. automethod:: next_up

.. automethod:: next_down

.. automethod:: outer

Broadcasting
Expand Down
2 changes: 2 additions & 0 deletions docs/api/arrayfunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ Array utility functions
.. autofunction:: apytypes.outer

.. autofunction:: apytypes.shape

.. autofunction:: apytypes.nextafter
4 changes: 2 additions & 2 deletions docs/comparison.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Comparison matrix
.. [#mpmathfootnote] ``mpmath`` can use ``gmpy`` as a backend to do faster arithmetic, but uses Python integers by default.


Performance Comparison
Performance comparison
----------------------

This benchmark compares relevant fixed-point libraries from the list above.
Expand All @@ -199,7 +199,7 @@ It is updated every documentation build and may vary over time as the code is fu
.. image:: _static/comparison_relative.png
:alt: Benchmark relative to APyTypes for different fixed-point libraries.

Feature Comparison
Feature comparison
------------------

.. image:: _static/comparison_matrix.png
Expand Down
15 changes: 15 additions & 0 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,18 @@ You can then see example usage of the script by running
python run_berkeley_cases.py -h

These are intended to more long running tests. If any bugs or deviations are found, dedicated tests should be added to the regular test suite.

Build the documentation
-----------------------

First, Doxygen must be installed separately.

Then, install the documentation dependencies and build the HTML documentation
from the repository root:

.. code-block:: bash

python -m pip install .[docs]
make -C docs html

Open ``docs/_build/html/index.html`` in a browser to view the result.
2 changes: 1 addition & 1 deletion docs/playground.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
APyTypes Playground
===================

Welcomde to APyTypes Playground! This is an interactive console with Python and APyTypes
Welcome to APyTypes Playground! This is an interactive console with Python and APyTypes
in the web browser based on the `Pyodide <https://pyodide.org/>`_ v0.28.2 terminal
emulator 🐍.

Expand Down
2 changes: 2 additions & 0 deletions lib/apytypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import_csv,
meshgrid,
moveaxis,
nextafter,
ones,
ones_like,
outer,
Expand Down Expand Up @@ -101,6 +102,7 @@
"meshgrid",
"moveaxis",
"n_threads",
"nextafter",
"ones",
"ones_like",
"outer",
Expand Down
58 changes: 58 additions & 0 deletions lib/apytypes/_apytypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4810,6 +4810,34 @@ class APyFixed:
"""

def __abs__(self) -> APyFixed: ...
def next_up(self) -> APyFixed:
"""
Return the next representable fixed-point number in the same format.

The word length is not increased. At the maximum representable value,
the result is unchanged: the operation saturates instead of wrapping.

.. versionadded:: 0.6

Returns
-------
:class:`APyFixed`
"""

def next_down(self) -> APyFixed:
"""
Return the previous representable fixed-point number in the same format.

The word length is not increased. At the minimum representable value,
the result is unchanged: the operation saturates instead of wrapping.

.. versionadded:: 0.6

Returns
-------
:class:`APyFixed`
"""

def __float__(self) -> float: ...
def __repr__(self) -> str: ...
def __str__(self, base: int = 10) -> str: ...
Expand Down Expand Up @@ -6341,6 +6369,34 @@ class APyFixedArray:
def __matmul__(self, rhs: APyCFixedArray) -> APyCFixedArray | APyCFixed: ...
def __repr__(self) -> str: ...
def __abs__(self) -> APyFixedArray: ...
def next_up(self) -> APyFixedArray:
"""
Return the next representable value of each element in the same format.

The word length is not increased. Elements at the maximum representable
value remain unchanged: the operation saturates instead of wrapping.

.. versionadded:: 0.6

Returns
-------
:class:`APyFixedArray`
"""

def next_down(self) -> APyFixedArray:
"""
Return the previous representable value of each element in the same format.

The word length is not increased. Elements at the minimum representable
value remain unchanged: the operation saturates instead of wrapping.

.. versionadded:: 0.6

Returns
-------
:class:`APyFixedArray`
"""

def __str__(self, base: int = 10) -> str: ...
def __getitem__(
self,
Expand Down Expand Up @@ -7451,6 +7507,8 @@ class APyFloatArray:
@overload
def __ge__(self, arg: APyFloat, /) -> NDArray[numpy.bool]: ...
def __abs__(self) -> APyFloatArray: ...
def next_up(self) -> APyFloatArray: ...
def next_down(self) -> APyFloatArray: ...
@overload
def __radd__(self, arg: int, /) -> APyFloatArray: ...
@overload
Expand Down
50 changes: 50 additions & 0 deletions lib/apytypes/_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,56 @@ def outer(a: APyArray, b: APyArray) -> APyArray:
return outer(b)


@overload
def nextafter(x1: APyFloatArray, x2: APyFloatArray | APyFloat) -> APyFloatArray: ...
@overload
def nextafter(x1: APyFixedArray, x2: APyFixedArray | APyFixed) -> APyFixedArray: ...


def nextafter(
x1: APyFloatArray | APyFixedArray,
x2: APyFloatArray | APyFixedArray | APyFloat | APyFixed,
) -> APyFloatArray | APyFixedArray:
"""
Return the next representable value of `x1` in the direction of `x2`, element-wise.
If `x1.shape` != `x2.shape`, they must be broadcastable to a common shape
(which becomes the shape of the output).

.. versionadded:: 0.6

Parameters
----------
x1 : :class:`APyFloatArray` or :class:`APyFixedArray`
Values to get the next representable value of.
x2 : :class:`APyFloatArray`, :class:`APyFixedArray`, :class:`APyFixed`, or :class:`APyFloat`
Direction in which to get the next representable value.

Returns
-------
:class:`APyArray`
Same type as `x1`.
"""
if not isinstance(x1, APyFloatArray | APyFixedArray):
raise TypeError(f"nextafter: x1 must be a real APyArray, got {type(x1)}")

if isinstance(x1, APyFixedArray):
if not isinstance(x2, APyFixedArray | APyFixed):
raise TypeError(
"nextafter: x2 must be APyFixedArray or APyFixed when x1 is "
f"APyFixedArray, got {type(x2)}"
)
elif not isinstance(x2, APyFloatArray | APyFloat):
raise TypeError(
"nextafter: x2 must be APyFloatArray or APyFloat when x1 is "
f"APyFloatArray, got {type(x2)}"
)

if isinstance(x2, APyFixed | APyFloat):
x2 = type(x1).from_float([x2], spec=x2)

return x1._nextafter(x1, x2)


# =============================================================================
# Helpers
# =============================================================================
Expand Down
Loading