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

Can create malformed DitStr's #45

Open
jlbosse opened this issue Nov 22, 2022 · 2 comments
Open

Can create malformed DitStr's #45

jlbosse opened this issue Nov 22, 2022 · 2 comments

Comments

@jlbosse
Copy link
Contributor

jlbosse commented Nov 22, 2022

When explicitly stating the type parameter N of a DitStr it is possible to form a malformed DitStr where
Int(dit_str) > D^N - 1. See the following example:

using BitBasis, Yao

julia> d = DitStr{2,2}(5) 
101 ₍₂₎

julia> length(d)
2

julia> product_state(d)
ERROR: BoundsError: ...

I am not sure if this will ever cause problems, but I am happy to open a PR with a consistency check in the inner constructor of DitStr.

@GiggleLiu
Copy link
Member

Thanks for the issue. I knew this one. I wanted to make some change but I am also worried about it may cause performance issue if we make any type of check since it is such an elementary type. On GPU, throwing an error is even not allowed. It also make sense if we do not make any check because our floating point numbers and integers never throw an error when the number overflows.

But I agree if we can add a checker for certain interface functions like product_state to prevent malformed user input.

@Roger-luo
Copy link
Member

FYI DitStr is technically a "ieee-like integer" so it overflows instead of an error.

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

No branches or pull requests

3 participants