-
-
Save inducer/b293430efb27c50d0048cd278540f038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import islpy as isl | |
dt = isl.dim_type | |
def mat_to_map(mat: isl.Mat, input_space: isl.Space) -> isl.Map: | |
if input_space.dim(dt.set) != mat.cols() - 1: | |
raise ValueError("number of columns must match input space") | |
map_space = (input_space | |
.move_dims(dt.in_, 0, dt.out, 0, input_space.dim(dt.set)) | |
.insert_dims(dt.out, 0, mat.rows() - 1)) | |
for j in range(1, mat.cols()): | |
assert mat.get_element_val(0, j) == 0 | |
result = isl.BasicMap.universe(map_space) | |
for i in range(mat.rows() - 1): | |
cns = ( | |
isl.Constraint.equality_alloc(map_space) | |
.set_coefficient_val(dt.out, i, -1) | |
.set_constant_val( | |
mat.get_element_val(i+1, 0)) | |
) | |
for j in range(mat.cols() - 1): | |
cns = cns.set_coefficient_val(dt.in_, j, | |
mat.get_element_val(i+1, j+1)) | |
result = result.add_constraint(cns) | |
return result | |
def remap(s: isl.BasicSet) -> isl.BasicMap: | |
s_lifted = s.lift() | |
print(s_lifted) | |
s_no_eq, t1, t2 = s_lifted.remove_equalities() | |
print(s_no_eq) | |
t1.dump() | |
t2.dump() | |
# FIXME could assert t2.product(t1) is an identity | |
t2.product(t1).dump() | |
mat_to_map(t1, s.space)) | |
1/0 | |
def main(): | |
s = isl.BasicSet("{ [i, j] : (2i + j) mod 8 = 0 " | |
"and 0<= i < 10 and 0<=j<80" | |
"}") | |
remap(s) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment