Skip to content

Commit

Permalink
Merge pull request #25 from ehw-fit/popcount
Browse files Browse the repository at this point in the history
Popcount
  • Loading branch information
honzastor committed Apr 5, 2024
2 parents 1219d7b + 0180735 commit 211dd49
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.x'
Expand All @@ -44,11 +44,11 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install iverilog
run: sudo apt install iverilog
- name: Set up Python 3.x
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.x'
Expand Down Expand Up @@ -90,9 +90,9 @@ jobs:
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
name: Python ${{ matrix.python-version }} test
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand All @@ -107,9 +107,9 @@ jobs:
needs: test
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.x'
Expand All @@ -123,7 +123,7 @@ jobs:
- name: Generate documentation
run: pdoc --html ariths_gen
- name: Upload results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: documentation
path: html
Expand Down
4 changes: 2 additions & 2 deletions ariths_gen/multi_bit_circuits/others/popcount.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
"""
from typing import Union
from typing import Union, Optional

from ariths_gen.wire_components import (
Wire,
Expand Down Expand Up @@ -45,7 +45,7 @@ class UnsignedPopCount(GeneralCircuit):
"""

def __init__(self, a: Bus, adder : Union[ArithmeticCircuit, None] = None, prefix : str = "", name : str = "popcnt", **kwargs):
def __init__(self, a: Bus, adder : Optional[ArithmeticCircuit] = None, prefix : str = "", name : str = "popcnt", **kwargs):
self.N = a.N
self.a = a

Expand Down
19 changes: 19 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,25 @@ def __init__(self, a: Wire, b: Wire, c: Bus, prefix="test_circuit", **kwargs):
assert r.sum() == 1
assert r[-1, -1, -1] == 1

def test_unique():
from ariths_gen.wire_components import Wire, Bus
import pytest
import sys
from ariths_gen.one_bit_circuits.logic_gates import AndGate
from ariths_gen.one_bit_circuits.one_bit_components import TwoOneMultiplexer
from ariths_gen.core.arithmetic_circuits import GeneralCircuit

class test_circuit(GeneralCircuit):
def __init__(self, a: Bus, prefix="test_circuit", **kwargs):
super().__init__(prefix=prefix, name="test_circuit", inputs=[a], out_N=1, **kwargs)
g = self.add_component(AndGate(a[0], a[1], prefix="g2"))
g2 = self.add_component(AndGate(g.out, a[2], prefix="g2"))
g3 = self.add_component(AndGate(g2.out, g.out, prefix="g2"))
self.out[0] = g3.out

with pytest.raises(AssertionError):
circ = test_circuit(Bus("a", 3), "c1")
circ.get_v_code_flat(file_object=sys.stdout)

if __name__ == "__main__":
test_unsigned_approxmul()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_popcnt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from io import StringIO
from ariths_gen.core.cgp_circuit import UnsignedCGPCircuit
from ariths_gen.wire_components import (
Wire,
Expand All @@ -11,6 +12,7 @@
from ariths_gen.multi_bit_circuits.others import (
UnsignedPopCount
)
import numpy as np


def test_popcount():
Expand Down

0 comments on commit 211dd49

Please sign in to comment.