cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
322 stars 92 forks source link

[API] Fix showing incorrect data types for bit slicing and struct #266

Closed seanlatias closed 4 years ago

seanlatias commented 4 years ago

In this PR, we fix the data types for the following cases.

# 1. Data type of a struct element
stype = hcl.Struct({"fa": hcl.Int(8), "fb": hcl.Fixed(13, 11), "fc": hcl.Float()})
D = hcl.compute(A.shape, lambda x: (x, x, x), dtype=stype)
print(D[0].fa.dtype) # => should be "int8"

# 2. Data type of a bit slice
# 2.1 If the length of the slice can be determined at compile time, we will show the updated data type
A = hcl.compute(..., dtype=hcl.Int(32))
print(A[0][0:2].dtype) # => should be "int2"
print(A[0][A[0]: A[0]+1].dtype) # => should be "int1"

# 2.2 If the length cannot be determined, we return the original data type
print(A[0][A[0] : A[3]].dtype) # => should be "int32"