flexfloat 0.1.3__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flexfloat-0.1.3 → flexfloat-0.1.5}/.bumpversion.cfg +1 -1
- {flexfloat-0.1.3 → flexfloat-0.1.5}/.github/workflows/manual-release.yml +1 -4
- {flexfloat-0.1.3 → flexfloat-0.1.5}/.github/workflows/pr-labeler.yml +10 -3
- flexfloat-0.1.5/.github/workflows/release.yml +87 -0
- flexfloat-0.1.5/.github/workflows/version-bump.yml +121 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/.github/workflows/version-check.yml +4 -1
- {flexfloat-0.1.3 → flexfloat-0.1.5}/PKG-INFO +1 -1
- flexfloat-0.1.5/flexfloat/__init__.py +36 -0
- flexfloat-0.1.5/flexfloat/bitarray/__init__.py +31 -0
- flexfloat-0.1.5/flexfloat/bitarray/bitarray.py +298 -0
- flexfloat-0.1.5/flexfloat/bitarray/bitarray_bigint.py +305 -0
- flexfloat-0.1.5/flexfloat/bitarray/bitarray_bool.py +202 -0
- flexfloat-0.1.5/flexfloat/bitarray/bitarray_int64.py +333 -0
- flexfloat-0.1.5/flexfloat/bitarray/bitarray_mixins.py +156 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/flexfloat/core.py +215 -113
- flexfloat-0.1.5/flexfloat/types.py +11 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/flexfloat.egg-info/PKG-INFO +1 -1
- {flexfloat-0.1.3 → flexfloat-0.1.5}/flexfloat.egg-info/SOURCES.txt +5 -2
- {flexfloat-0.1.3 → flexfloat-0.1.5}/pyproject.toml +1 -1
- {flexfloat-0.1.3 → flexfloat-0.1.5}/scripts/validate_cicd.py +2 -1
- {flexfloat-0.1.3 → flexfloat-0.1.5}/scripts/version_manager.py +2 -3
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_addition.py +1 -1
- flexfloat-0.1.5/tests/test_bigint_bitarray.py +409 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_bitarray.py +63 -61
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_bitarray_implementations.py +71 -94
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_conversions.py +31 -31
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_division.py +2 -22
- flexfloat-0.1.3/tests/test_bigfloat.py → flexfloat-0.1.5/tests/test_flexfloat.py +60 -13
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_multiplication.py +3 -3
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_power.py +3 -3
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_str_representation.py +6 -6
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/test_subtraction.py +5 -5
- flexfloat-0.1.3/.github/workflows/release.yml +0 -130
- flexfloat-0.1.3/flexfloat/__init__.py +0 -32
- flexfloat-0.1.3/flexfloat/bitarray/__init__.py +0 -90
- flexfloat-0.1.3/flexfloat/bitarray/bitarray.py +0 -198
- flexfloat-0.1.3/flexfloat/bitarray/bitarray_int64.py +0 -308
- flexfloat-0.1.3/flexfloat/bitarray/bitarray_list.py +0 -187
- flexfloat-0.1.3/flexfloat/bitarray/bitarray_mixins.py +0 -93
- flexfloat-0.1.3/flexfloat/types.py +0 -5
- {flexfloat-0.1.3 → flexfloat-0.1.5}/.github/workflows/build-check.yml +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/.github/workflows/test.yml +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/.gitignore +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/LICENSE +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/MANIFEST.in +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/README.md +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/flexfloat/py.typed +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/flexfloat.egg-info/dependency_links.txt +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/flexfloat.egg-info/requires.txt +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/flexfloat.egg-info/top_level.txt +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/setup.cfg +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/setup.py +0 -0
- {flexfloat-0.1.3 → flexfloat-0.1.5}/tests/__init__.py +0 -0
@@ -70,9 +70,6 @@ jobs:
|
|
70
70
|
- name: Bump or set version
|
71
71
|
id: bump_version
|
72
72
|
run: |
|
73
|
-
# Update current version in .bumpversion.cfg
|
74
|
-
# sed -i "s/current_version = .*/current_version = ${{ steps.current_version.outputs.version }}/" .bumpversion.cfg
|
75
|
-
|
76
73
|
if [ -n "${{ steps.set_new_version.outputs.new_version }}" ]; then
|
77
74
|
# Set version directly
|
78
75
|
bump2version --new-version ${{ steps.set_new_version.outputs.new_version }} patch
|
@@ -97,7 +94,7 @@ jobs:
|
|
97
94
|
|
98
95
|
- name: Commit version bump
|
99
96
|
run: |
|
100
|
-
git add pyproject.toml flexfloat/__init__.py
|
97
|
+
git add pyproject.toml flexfloat/__init__.py .bumpversion.cfg
|
101
98
|
git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }} [skip ci]"
|
102
99
|
git push origin main
|
103
100
|
|
@@ -67,7 +67,7 @@ jobs:
|
|
67
67
|
}
|
68
68
|
}
|
69
69
|
|
70
|
-
// Add the
|
70
|
+
// Add only the version bump label
|
71
71
|
await github.rest.issues.addLabels({
|
72
72
|
owner: context.repo.owner,
|
73
73
|
repo: context.repo.repo,
|
@@ -93,12 +93,19 @@ jobs:
|
|
93
93
|
| minor | New features, non-breaking changes |
|
94
94
|
| major | Breaking changes, major updates |
|
95
95
|
|
96
|
-
|
96
|
+
**🚀 Release Status**: This PR is labeled with the recommended version bump type. To trigger a release:
|
97
|
+
1. **Add the \`release\` label** to this PR when ready
|
98
|
+
2. The version will be automatically bumped when the \`release\` label is added
|
99
|
+
3. When merged, it will create a Git tag, GitHub release, and publish to PyPI
|
100
|
+
|
101
|
+
**To prevent release**: Simply don\'t add the \`release\` label.
|
102
|
+
|
103
|
+
**To change version bump**: You can manually change the version bump label:
|
97
104
|
- Add \`major\` label for breaking changes
|
98
105
|
- Add \`minor\` label for new features
|
99
106
|
- Add \`patch\` label for bug fixes
|
100
107
|
|
101
|
-
The version will be automatically updated
|
108
|
+
The version will be automatically updated when the \`release\` label is added to this PR.`;
|
102
109
|
|
103
110
|
// Check if we already commented
|
104
111
|
const comments = await github.rest.issues.listComments({
|
@@ -0,0 +1,87 @@
|
|
1
|
+
name: Release
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [closed]
|
6
|
+
branches: [main]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
release:
|
10
|
+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
permissions:
|
13
|
+
contents: write
|
14
|
+
id-token: write # For trusted publishing to PyPI
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- name: Checkout code
|
18
|
+
uses: actions/checkout@v4
|
19
|
+
with:
|
20
|
+
fetch-depth: 0
|
21
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
|
23
|
+
- name: Set up Python
|
24
|
+
uses: actions/setup-python@v5
|
25
|
+
with:
|
26
|
+
python-version: "3.11"
|
27
|
+
|
28
|
+
- name: Install dependencies
|
29
|
+
run: |
|
30
|
+
python -m pip install --upgrade pip
|
31
|
+
pip install build twine bump2version
|
32
|
+
|
33
|
+
- name: Configure Git
|
34
|
+
run: |
|
35
|
+
git config --local user.email "action@github.com"
|
36
|
+
git config --local user.name "GitHub Action"
|
37
|
+
|
38
|
+
- name: Get current version
|
39
|
+
id: current_version
|
40
|
+
run: |
|
41
|
+
VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
42
|
+
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
43
|
+
echo "Current version: $VERSION"
|
44
|
+
|
45
|
+
- name: Run tests
|
46
|
+
run: |
|
47
|
+
pip install -e ".[dev]"
|
48
|
+
pytest tests/
|
49
|
+
|
50
|
+
- name: Build package
|
51
|
+
run: |
|
52
|
+
python -m build
|
53
|
+
|
54
|
+
- name: Create Git tag
|
55
|
+
run: |
|
56
|
+
git tag -a "v${{ steps.current_version.outputs.version }}" -m "Release v${{ steps.current_version.outputs.version }}"
|
57
|
+
git push origin "v${{ steps.current_version.outputs.version }}"
|
58
|
+
|
59
|
+
- name: Create GitHub Release
|
60
|
+
id: create_release
|
61
|
+
uses: softprops/action-gh-release@v2
|
62
|
+
with:
|
63
|
+
tag_name: "v${{ steps.current_version.outputs.version }}"
|
64
|
+
name: "Release v${{ steps.current_version.outputs.version }}"
|
65
|
+
body: |
|
66
|
+
## Changes in v${{ steps.current_version.outputs.version }}
|
67
|
+
|
68
|
+
This release was automatically created from PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}
|
69
|
+
|
70
|
+
### Pull Request Details
|
71
|
+
${{ github.event.pull_request.body }}
|
72
|
+
|
73
|
+
### Artifacts
|
74
|
+
- **Python Wheel**: `flexfloat-${{ steps.current_version.outputs.version }}-py3-none-any.whl`
|
75
|
+
- **Source Distribution**: `flexfloat-${{ steps.current_version.outputs.version }}.tar.gz`
|
76
|
+
|
77
|
+
The package has been automatically published to [PyPI](https://pypi.org/project/flexfloat/${{ steps.current_version.outputs.version }}/).
|
78
|
+
draft: false
|
79
|
+
prerelease: false
|
80
|
+
files: |
|
81
|
+
./dist/flexfloat-${{ steps.current_version.outputs.version }}-py3-none-any.whl
|
82
|
+
./dist/flexfloat-${{ steps.current_version.outputs.version }}.tar.gz
|
83
|
+
|
84
|
+
- name: Publish to PyPI
|
85
|
+
uses: pypa/gh-action-pypi-publish@v1.12.4
|
86
|
+
with:
|
87
|
+
verbose: true
|
@@ -0,0 +1,121 @@
|
|
1
|
+
name: Version Bump
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types: [labeled, unlabeled]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
version-bump:
|
9
|
+
if: |
|
10
|
+
github.event.action == 'labeled' &&
|
11
|
+
github.event.label.name == 'release' &&
|
12
|
+
github.event.pull_request.merged == false
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
permissions:
|
15
|
+
contents: write
|
16
|
+
pull-requests: write
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- name: Checkout PR branch
|
20
|
+
uses: actions/checkout@v4
|
21
|
+
with:
|
22
|
+
fetch-depth: 0
|
23
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
24
|
+
ref: ${{ github.event.pull_request.head.ref }}
|
25
|
+
|
26
|
+
- name: Set up Python
|
27
|
+
uses: actions/setup-python@v5
|
28
|
+
with:
|
29
|
+
python-version: "3.11"
|
30
|
+
|
31
|
+
- name: Install dependencies
|
32
|
+
run: |
|
33
|
+
python -m pip install --upgrade pip
|
34
|
+
pip install bump2version
|
35
|
+
|
36
|
+
- name: Configure Git
|
37
|
+
run: |
|
38
|
+
git config --local user.email "action@github.com"
|
39
|
+
git config --local user.name "GitHub Action"
|
40
|
+
|
41
|
+
- name: Determine version bump type
|
42
|
+
id: bump_type
|
43
|
+
run: |
|
44
|
+
BUMP_TYPE="patch"
|
45
|
+
LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}"
|
46
|
+
if echo "$LABELS" | grep -q "major"; then
|
47
|
+
BUMP_TYPE="major"
|
48
|
+
elif echo "$LABELS" | grep -q "minor"; then
|
49
|
+
BUMP_TYPE="minor"
|
50
|
+
elif echo "$LABELS" | grep -q "patch"; then
|
51
|
+
BUMP_TYPE="patch"
|
52
|
+
fi
|
53
|
+
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
|
54
|
+
echo "Version bump type: $BUMP_TYPE"
|
55
|
+
|
56
|
+
- name: Bump version
|
57
|
+
id: bump_version
|
58
|
+
run: |
|
59
|
+
bump2version ${{ steps.bump_type.outputs.bump_type }}
|
60
|
+
NEW_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
61
|
+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
62
|
+
echo "New version: $NEW_VERSION"
|
63
|
+
|
64
|
+
- name: Commit version bump to PR branch
|
65
|
+
run: |
|
66
|
+
git add pyproject.toml flexfloat/__init__.py .bumpversion.cfg
|
67
|
+
git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }} [skip ci]"
|
68
|
+
git push origin ${{ github.event.pull_request.head.ref }}
|
69
|
+
|
70
|
+
revert-version-bump:
|
71
|
+
if: |
|
72
|
+
github.event.action == 'unlabeled' &&
|
73
|
+
github.event.label.name == 'release' &&
|
74
|
+
github.event.pull_request.merged == false
|
75
|
+
runs-on: ubuntu-latest
|
76
|
+
permissions:
|
77
|
+
contents: write
|
78
|
+
pull-requests: write
|
79
|
+
|
80
|
+
steps:
|
81
|
+
- name: Checkout PR branch
|
82
|
+
uses: actions/checkout@v4
|
83
|
+
with:
|
84
|
+
fetch-depth: 0
|
85
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
86
|
+
ref: ${{ github.event.pull_request.head.ref }}
|
87
|
+
|
88
|
+
- name: Configure Git
|
89
|
+
run: |
|
90
|
+
git config --local user.email "action@github.com"
|
91
|
+
git config --local user.name "GitHub Action"
|
92
|
+
|
93
|
+
- name: Revert version bump commit
|
94
|
+
run: |
|
95
|
+
git fetch origin main
|
96
|
+
BASE_COMMIT=$(git merge-base HEAD origin/main)
|
97
|
+
VERSION_BUMP_COMMITS=()
|
98
|
+
for commit in $(git rev-list $BASE_COMMIT..HEAD); do
|
99
|
+
COMMIT_MSG=$(git log -1 --pretty=format:"%s" $commit)
|
100
|
+
if [[ $COMMIT_MSG == *"Bump version to"* ]] && [[ $COMMIT_MSG == *"[skip ci]"* ]]; then
|
101
|
+
VERSION_BUMP_COMMITS+=($commit)
|
102
|
+
fi
|
103
|
+
done
|
104
|
+
if [ ${#VERSION_BUMP_COMMITS[@]} -gt 0 ]; then
|
105
|
+
FIRST_VERSION_BUMP=${VERSION_BUMP_COMMITS[-1]}
|
106
|
+
RESET_TARGET=$(git rev-parse $FIRST_VERSION_BUMP^)
|
107
|
+
git reset --hard $RESET_TARGET
|
108
|
+
git push --force-with-lease origin ${{ github.event.pull_request.head.ref }}
|
109
|
+
echo "Version bump commits reverted"
|
110
|
+
fi
|
111
|
+
|
112
|
+
- name: Comment on PR
|
113
|
+
uses: actions/github-script@v7
|
114
|
+
with:
|
115
|
+
script: |
|
116
|
+
await github.rest.issues.createComment({
|
117
|
+
owner: context.repo.owner,
|
118
|
+
repo: context.repo.repo,
|
119
|
+
issue_number: context.issue.number,
|
120
|
+
body: '🚫 **Release Cancelled**: The `release` label was removed. Version bump commit has been reverted and this PR will not trigger a release when merged.'
|
121
|
+
});
|
@@ -19,15 +19,18 @@ jobs:
|
|
19
19
|
# Extract versions from different files
|
20
20
|
PYPROJECT_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
21
21
|
INIT_VERSION=$(grep -E '^__version__ = ' flexfloat/__init__.py | cut -d'"' -f2)
|
22
|
+
BUMPVERSION_VERSION=$(grep -E '^current_version = ' .bumpversion.cfg | cut -d' ' -f3)
|
22
23
|
|
23
24
|
echo "pyproject.toml version: $PYPROJECT_VERSION"
|
24
25
|
echo "flexfloat/__init__.py version: $INIT_VERSION"
|
26
|
+
echo ".bumpversion.cfg current_version: $BUMPVERSION_VERSION"
|
25
27
|
|
26
28
|
# Check if versions match
|
27
|
-
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
|
29
|
+
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ] || [ "$PYPROJECT_VERSION" != "$BUMPVERSION_VERSION" ]; then
|
28
30
|
echo "[NO] Version mismatch detected!"
|
29
31
|
echo "pyproject.toml has version $PYPROJECT_VERSION"
|
30
32
|
echo "flexfloat/__init__.py has version $INIT_VERSION"
|
33
|
+
echo ".bumpversion.cfg has current_version $BUMPVERSION_VERSION"
|
31
34
|
echo "Please ensure all version references are synchronized."
|
32
35
|
exit 1
|
33
36
|
else
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"""FlexFloat - A library for arbitrary precision floating point arithmetic.
|
2
|
+
|
3
|
+
This package provides the FlexFloat class for handling floating-point numbers with
|
4
|
+
growable exponents and fixed-size fractions. It also provides several BitArray
|
5
|
+
implementations for efficient bit manipulation.
|
6
|
+
|
7
|
+
Example:
|
8
|
+
from flexfloat import FlexFloat
|
9
|
+
x = FlexFloat(1.5, exponent_length=8, fraction_length=23)
|
10
|
+
print(x)
|
11
|
+
# Output: FlexFloat(sign=False, exponent=..., fraction=...)
|
12
|
+
|
13
|
+
Modules:
|
14
|
+
core: Main FlexFloat class implementation
|
15
|
+
bitarray: BitArray implementations (bool, int64, bigint)
|
16
|
+
types: Type definitions
|
17
|
+
"""
|
18
|
+
|
19
|
+
from .bitarray import (
|
20
|
+
BigIntBitArray,
|
21
|
+
BitArray,
|
22
|
+
ListBoolBitArray,
|
23
|
+
ListInt64BitArray,
|
24
|
+
)
|
25
|
+
from .core import FlexFloat
|
26
|
+
|
27
|
+
__version__ = "0.1.5"
|
28
|
+
__author__ = "Ferran Sanchez Llado"
|
29
|
+
|
30
|
+
__all__ = [
|
31
|
+
"FlexFloat",
|
32
|
+
"BitArray",
|
33
|
+
"ListBoolBitArray",
|
34
|
+
"ListInt64BitArray",
|
35
|
+
"BigIntBitArray",
|
36
|
+
]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"""BitArray implementation for the flexfloat package.
|
2
|
+
|
3
|
+
This module provides a factory and utilities for working with different BitArray
|
4
|
+
implementations, including:
|
5
|
+
- ListBoolBitArray: List of booleans (default, flexible, easy to use)
|
6
|
+
- ListInt64BitArray: List of int64 chunks (memory efficient for large arrays)
|
7
|
+
- BigIntBitArray: Single Python int (arbitrary size, efficient for very large
|
8
|
+
arrays)
|
9
|
+
|
10
|
+
Example:
|
11
|
+
from flexfloat.bitarray import create_bitarray
|
12
|
+
ba = create_bitarray('int64', [True, False, True])
|
13
|
+
print(type(ba).__name__)
|
14
|
+
# Output: ListInt64BitArray
|
15
|
+
"""
|
16
|
+
|
17
|
+
from __future__ import annotations
|
18
|
+
|
19
|
+
from .bitarray import BitArray
|
20
|
+
from .bitarray_bigint import BigIntBitArray
|
21
|
+
from .bitarray_bool import ListBoolBitArray
|
22
|
+
from .bitarray_int64 import ListInt64BitArray
|
23
|
+
from .bitarray_mixins import BitArrayCommonMixin
|
24
|
+
|
25
|
+
__all__ = [
|
26
|
+
"BitArray",
|
27
|
+
"ListBoolBitArray",
|
28
|
+
"ListInt64BitArray",
|
29
|
+
"BigIntBitArray",
|
30
|
+
"BitArrayCommonMixin",
|
31
|
+
]
|
@@ -0,0 +1,298 @@
|
|
1
|
+
"""BitArray protocol definition for the flexfloat package.
|
2
|
+
|
3
|
+
This module defines the BitArray protocol, which all BitArray implementations must
|
4
|
+
follow. The protocol ensures a consistent interface for bit manipulation.
|
5
|
+
|
6
|
+
Example:
|
7
|
+
from flexfloat.bitarray import BitArray
|
8
|
+
class MyBitArray(BitArray):
|
9
|
+
...
|
10
|
+
my_bitarray = MyBitArray()
|
11
|
+
isinstance(my_bitarray, BitArray) # True
|
12
|
+
"""
|
13
|
+
|
14
|
+
from __future__ import annotations
|
15
|
+
|
16
|
+
from typing import Iterable, Iterator, Protocol, overload, runtime_checkable
|
17
|
+
|
18
|
+
|
19
|
+
@runtime_checkable
|
20
|
+
class BitArray(Protocol):
|
21
|
+
"""Protocol defining the interface for BitArray implementations.
|
22
|
+
|
23
|
+
This protocol defines all the methods and properties that a BitArray
|
24
|
+
implementation must provide.
|
25
|
+
|
26
|
+
For consistency, all BitArray implementations should order bits as LSB-first,
|
27
|
+
meaning the least significant bit is at index 0 and the most significant bit
|
28
|
+
is at the highest index.
|
29
|
+
"""
|
30
|
+
|
31
|
+
@classmethod
|
32
|
+
def from_bits(cls, bits: list[bool] | None = None) -> "BitArray":
|
33
|
+
"""Creates a BitArray from a list of boolean values.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
bits (list[bool] | None, optional): List of boolean values. Defaults to
|
37
|
+
None, which creates an empty BitArray.
|
38
|
+
|
39
|
+
Returns:
|
40
|
+
BitArray: A BitArray created from the bits.
|
41
|
+
"""
|
42
|
+
...
|
43
|
+
|
44
|
+
@classmethod
|
45
|
+
def from_float(cls, value: float) -> "BitArray":
|
46
|
+
"""Converts a floating-point number to a bit array.
|
47
|
+
|
48
|
+
Args:
|
49
|
+
value (float): The floating-point number to convert.
|
50
|
+
|
51
|
+
Returns:
|
52
|
+
BitArray: A BitArray representing the bits of the floating-point number.
|
53
|
+
"""
|
54
|
+
...
|
55
|
+
|
56
|
+
@classmethod
|
57
|
+
def from_signed_int(cls, value: int, length: int) -> "BitArray":
|
58
|
+
"""Converts a signed integer to a bit array using off-set binary representation.
|
59
|
+
|
60
|
+
Args:
|
61
|
+
value (int): The signed integer to convert.
|
62
|
+
length (int): The length of the resulting bit array.
|
63
|
+
|
64
|
+
Returns:
|
65
|
+
BitArray: A BitArray representing the bits of the signed integer.
|
66
|
+
|
67
|
+
Raises:
|
68
|
+
AssertionError: If the value is out of range for the specified length.
|
69
|
+
"""
|
70
|
+
...
|
71
|
+
|
72
|
+
@classmethod
|
73
|
+
def zeros(cls, length: int) -> "BitArray":
|
74
|
+
"""Creates a BitArray filled with zeros.
|
75
|
+
|
76
|
+
Args:
|
77
|
+
length (int): The length of the bit array.
|
78
|
+
|
79
|
+
Returns:
|
80
|
+
BitArray: A BitArray filled with False values.
|
81
|
+
"""
|
82
|
+
...
|
83
|
+
|
84
|
+
@classmethod
|
85
|
+
def ones(cls, length: int) -> "BitArray":
|
86
|
+
"""Creates a BitArray filled with ones.
|
87
|
+
|
88
|
+
Args:
|
89
|
+
length (int): The length of the bit array.
|
90
|
+
|
91
|
+
Returns:
|
92
|
+
BitArray: A BitArray filled with True values.
|
93
|
+
"""
|
94
|
+
...
|
95
|
+
|
96
|
+
@classmethod
|
97
|
+
def parse_bitarray(cls, bitstring: Iterable[str]) -> "BitArray":
|
98
|
+
"""Parses a string of bits (with optional spaces) into a BitArray instance.
|
99
|
+
Non-valid characters are ignored.
|
100
|
+
|
101
|
+
Args:
|
102
|
+
bitstring (Iterable[str]): A string of bits, e.g., "1010 1100".
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
BitArray: A BitArray instance created from the bit string.
|
106
|
+
"""
|
107
|
+
...
|
108
|
+
|
109
|
+
def to_float(self) -> float:
|
110
|
+
"""Converts a 64-bit array to a floating-point number.
|
111
|
+
|
112
|
+
Returns:
|
113
|
+
float: The floating-point number represented by the bit array.
|
114
|
+
|
115
|
+
Raises:
|
116
|
+
AssertionError: If the bit array is not 64 bits long.
|
117
|
+
"""
|
118
|
+
...
|
119
|
+
|
120
|
+
def to_int(self) -> int:
|
121
|
+
"""Converts the bit array to an unsigned integer.
|
122
|
+
|
123
|
+
Returns:
|
124
|
+
int: The integer represented by the bit array.
|
125
|
+
"""
|
126
|
+
...
|
127
|
+
|
128
|
+
def to_signed_int(self) -> int:
|
129
|
+
"""Converts a bit array into a signed integer using off-set binary
|
130
|
+
representation.
|
131
|
+
|
132
|
+
Returns:
|
133
|
+
int: The signed integer represented by the bit array.
|
134
|
+
|
135
|
+
Raises:
|
136
|
+
AssertionError: If the bit array is empty.
|
137
|
+
"""
|
138
|
+
...
|
139
|
+
|
140
|
+
def shift(self, shift_amount: int, fill: bool = False) -> "BitArray":
|
141
|
+
"""Shifts the bit array left or right by a specified number of bits.
|
142
|
+
|
143
|
+
This function shifts the bits in the array, filling in new bits with the
|
144
|
+
specified fill value.
|
145
|
+
If the value is positive, it shifts left; if negative, it shifts right.
|
146
|
+
Fills the new bits with the specified fill value (default is False).
|
147
|
+
|
148
|
+
Args:
|
149
|
+
shift_amount (int): The number of bits to shift. Positive for left shift,
|
150
|
+
negative for right shift.
|
151
|
+
fill (bool, optional): The value to fill in the new bits created by the
|
152
|
+
shift. Defaults to False.
|
153
|
+
|
154
|
+
Returns:
|
155
|
+
BitArray: A new BitArray with the bits shifted and filled.
|
156
|
+
"""
|
157
|
+
...
|
158
|
+
|
159
|
+
def copy(self) -> "BitArray":
|
160
|
+
"""Creates a copy of the bit array.
|
161
|
+
|
162
|
+
Returns:
|
163
|
+
BitArray: A new BitArray with the same bits.
|
164
|
+
"""
|
165
|
+
...
|
166
|
+
|
167
|
+
def __len__(self) -> int:
|
168
|
+
"""Returns the length of the bit array.
|
169
|
+
|
170
|
+
Returns:
|
171
|
+
int: The number of bits in the array.
|
172
|
+
"""
|
173
|
+
...
|
174
|
+
|
175
|
+
@overload
|
176
|
+
def __getitem__(self, index: int) -> bool: ...
|
177
|
+
@overload
|
178
|
+
def __getitem__(self, index: slice) -> "BitArray": ...
|
179
|
+
|
180
|
+
def __getitem__(self, index: int | slice) -> bool | BitArray:
|
181
|
+
"""Get a bit or a slice of bits as a new BitArray."""
|
182
|
+
...
|
183
|
+
|
184
|
+
@overload
|
185
|
+
def __setitem__(self, index: int, value: bool) -> None: ...
|
186
|
+
@overload
|
187
|
+
def __setitem__(self, index: slice, value: "BitArray" | list[bool]) -> None: ...
|
188
|
+
|
189
|
+
def __setitem__(
|
190
|
+
self, index: int | slice, value: bool | list[bool] | "BitArray"
|
191
|
+
) -> None:
|
192
|
+
"""Sets an item or slice in the bit array.
|
193
|
+
|
194
|
+
Args:
|
195
|
+
index (int or slice): The index or slice to set.
|
196
|
+
value (bool or list[bool] or BitArray): The value(s) to assign.
|
197
|
+
"""
|
198
|
+
...
|
199
|
+
|
200
|
+
def __iter__(self) -> Iterator[bool]:
|
201
|
+
"""Iterates over the bits in the array.
|
202
|
+
|
203
|
+
Yields:
|
204
|
+
bool: The next bit in the array.
|
205
|
+
"""
|
206
|
+
...
|
207
|
+
|
208
|
+
def __add__(self, other: "BitArray" | list[bool]) -> "BitArray":
|
209
|
+
"""Concatenates two bit arrays.
|
210
|
+
|
211
|
+
Args:
|
212
|
+
other (BitArray or list[bool]): The other bit array or list to concatenate.
|
213
|
+
|
214
|
+
Returns:
|
215
|
+
BitArray: The concatenated bit array.
|
216
|
+
"""
|
217
|
+
...
|
218
|
+
|
219
|
+
def __radd__(self, other: list[bool]) -> "BitArray":
|
220
|
+
"""Reverse concatenation with a list.
|
221
|
+
|
222
|
+
Args:
|
223
|
+
other (list[bool]): The list to concatenate before this bit array.
|
224
|
+
|
225
|
+
Returns:
|
226
|
+
BitArray: The concatenated bit array.
|
227
|
+
"""
|
228
|
+
...
|
229
|
+
|
230
|
+
def __eq__(self, other: object) -> bool:
|
231
|
+
"""Checks equality with another BitArray or list.
|
232
|
+
|
233
|
+
Args:
|
234
|
+
other (object): The object to compare with.
|
235
|
+
|
236
|
+
Returns:
|
237
|
+
bool: True if equal, False otherwise.
|
238
|
+
"""
|
239
|
+
...
|
240
|
+
|
241
|
+
def __bool__(self) -> bool:
|
242
|
+
"""Returns True if any bit is set.
|
243
|
+
|
244
|
+
Returns:
|
245
|
+
bool: True if any bit is set, False otherwise.
|
246
|
+
"""
|
247
|
+
...
|
248
|
+
|
249
|
+
def __repr__(self) -> str:
|
250
|
+
"""Returns a string representation of the BitArray.
|
251
|
+
|
252
|
+
Returns:
|
253
|
+
str: String representation of the BitArray.
|
254
|
+
"""
|
255
|
+
...
|
256
|
+
|
257
|
+
def __str__(self) -> str:
|
258
|
+
"""Returns a string representation of the bits.
|
259
|
+
|
260
|
+
Returns:
|
261
|
+
str: String representation of the bits.
|
262
|
+
"""
|
263
|
+
...
|
264
|
+
|
265
|
+
def any(self) -> bool:
|
266
|
+
"""Returns True if any bit is set to True.
|
267
|
+
|
268
|
+
Returns:
|
269
|
+
bool: True if any bit is set to True, False otherwise.
|
270
|
+
"""
|
271
|
+
...
|
272
|
+
|
273
|
+
def all(self) -> bool:
|
274
|
+
"""Returns True if all bits are set to True.
|
275
|
+
|
276
|
+
Returns:
|
277
|
+
bool: True if all bits are set to True, False otherwise.
|
278
|
+
"""
|
279
|
+
...
|
280
|
+
|
281
|
+
def count(self, value: bool = True) -> int:
|
282
|
+
"""Counts the number of bits set to the specified value.
|
283
|
+
|
284
|
+
Args:
|
285
|
+
value (bool, optional): The value to count. Defaults to True.
|
286
|
+
|
287
|
+
Returns:
|
288
|
+
int: The number of bits set to the specified value.
|
289
|
+
"""
|
290
|
+
...
|
291
|
+
|
292
|
+
def reverse(self) -> "BitArray":
|
293
|
+
"""Returns a new BitArray with the bits in reverse order.
|
294
|
+
|
295
|
+
Returns:
|
296
|
+
BitArray: A new BitArray with the bits in reverse order.
|
297
|
+
"""
|
298
|
+
...
|