[enhancement][dslx] Consider the best way we might encode one-hot in the type system #1963
Labels
dslx
DSLX (domain specific language) implementation / front-end
enhancement
New feature or request
long-term-enhancement
Issues that are sensible enhancements but XLS devs expect may not be addressed in the near-term
What's hard to do? (limit 100 words)
One hot is a property of underlying data that lends itself nicely to a "witness type"; i.e. imagine you run
one_hot
on a value and then you pass that value to a function, it would have to similarly runone_hot
on the value to know that it was indeed in one hot form. If we had a type that said "this value has been validated to be one hot" we could make the value's invariants more self documenting and avoid the need for redundant checks.Current best alternative workaround (limit 100 words)
As noted above running one_hot on values to ensure they're canonically one hot, and perhaps adding asserts to check this when it is a precondition that it should be given as one hot.
Your view of the "best case XLS enhancement" (limit 100 words)
Perhaps a built-in type like
oN[N]
to complementuN[N]
andsN[N]
? A standard library struct wrapper wouldn't allow built-ins to take or produce the type as easily.The text was updated successfully, but these errors were encountered: