2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
13 struct isl_vec
*isl_vec_alloc(struct isl_ctx
*ctx
, unsigned size
)
17 vec
= isl_alloc_type(ctx
, struct isl_vec
);
21 vec
->block
= isl_blk_alloc(ctx
, size
);
22 if (isl_blk_is_error(vec
->block
))
29 vec
->el
= vec
->block
.data
;
33 isl_blk_free(ctx
, vec
->block
);
37 struct isl_vec
*isl_vec_copy(struct isl_vec
*vec
)
46 struct isl_vec
*isl_vec_dup(struct isl_vec
*vec
)
52 vec2
= isl_vec_alloc(vec
->ctx
, vec
->size
);
53 isl_seq_cpy(vec2
->el
, vec
->el
, vec
->size
);
57 struct isl_vec
*isl_vec_cow(struct isl_vec
*vec
)
66 vec2
= isl_vec_dup(vec
);
71 void isl_vec_free(struct isl_vec
*vec
)
79 isl_ctx_deref(vec
->ctx
);
80 isl_blk_free(vec
->ctx
, vec
->block
);
84 void isl_vec_dump(struct isl_vec
*vec
, FILE *out
, int indent
)
89 fprintf(out
, "%*snull vec\n", indent
, "");
93 fprintf(out
, "%*s[", indent
, "");
94 for (i
= 0; i
< vec
->size
; ++i
) {
97 isl_int_print(out
, vec
->el
[i
], 0);
102 void isl_vec_lcm(struct isl_vec
*vec
, isl_int
*lcm
)
104 isl_seq_lcm(vec
->block
.data
, vec
->size
, lcm
);
107 /* Given a rational vector, with the denominator in the first element
108 * of the vector, round up all coordinates.
110 struct isl_vec
*isl_vec_ceil(struct isl_vec
*vec
)
112 vec
= isl_vec_cow(vec
);
116 isl_seq_cdiv_q(vec
->el
+ 1, vec
->el
+ 1, vec
->el
[0], vec
->size
- 1);
118 isl_int_set_si(vec
->el
[0], 1);
123 struct isl_vec
*isl_vec_normalize(struct isl_vec
*vec
)
127 isl_seq_normalize(vec
->ctx
, vec
->el
, vec
->size
);