Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Types] Represent boolean type as uint1 #216

Merged
merged 1 commit into from
Oct 4, 2024
Merged

[Types] Represent boolean type as uint1 #216

merged 1 commit into from
Oct 4, 2024

Conversation

chhzh123
Copy link
Member

@chhzh123 chhzh123 commented Oct 4, 2024

Description

This PR fixes the incorrect representation of the boolean type in Allo. Boolean type should be represented as uint1 instead of int1. Notice 1 in int1 is actually -1 since the highest bit is represented as the sign bit.

Examples

def test_boolean():
    def kernel(A: bool[16]) -> bool[16]:
        B: bool[16] = 0
        for i in range(16):
            if A[i]:
                B[i] = 1
            else:
                B[i] = 0
        return B

    s = allo.customize(kernel)
    print(s.module)
    mod = s.build()
    np_A = np.random.randint(0, 2, size=(16)).astype(np.bool)
    np_B = mod(np_A)
    np.testing.assert_array_equal(np_A, np_B)

Checklist

  • PR's title starts with a category (e.g. [Bugfix], [IR], [Builder], etc)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage (It would be better to provide ~2 different test cases to test the robustness of your code)
  • Code is well-documented

@chhzh123 chhzh123 merged commit 29b663f into main Oct 4, 2024
1 check passed
@chhzh123 chhzh123 deleted the fix_bool branch November 6, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant