isl_basic_map_drop: properly handle dimensions of type isl_dim_div
[isl.git] / isl_vec.c
blob533cf047bbc32e6122f1429f654f2d68119ab96e
1 #include "isl_vec.h"
3 struct isl_vec *isl_vec_alloc(struct isl_ctx *ctx, unsigned size)
5 struct isl_vec *vec;
7 vec = isl_alloc_type(ctx, struct isl_vec);
8 if (!vec)
9 return NULL;
11 vec->block = isl_blk_alloc(ctx, size);
12 if (isl_blk_is_error(vec->block))
13 goto error;
15 vec->ref = 1;
16 vec->size = size;
18 return vec;
19 error:
20 isl_blk_free(ctx, vec->block);
21 return NULL;
24 struct isl_vec *isl_vec_copy(struct isl_ctx *ctx, struct isl_vec *vec)
26 if (!vec)
27 return NULL;
29 vec->ref++;
30 return vec;
33 struct isl_vec *isl_vec_dup(struct isl_ctx *ctx, struct isl_vec *vec)
35 struct isl_vec *vec2;
37 if (!vec)
38 return NULL;
39 vec2 = isl_vec_alloc(ctx, vec->size);
40 isl_seq_cpy(vec2->block.data, vec->block.data, vec->size);
41 return vec2;
44 struct isl_vec *isl_vec_cow(struct isl_ctx *ctx, struct isl_vec *vec)
46 struct isl_vec *vec2;
47 if (!vec)
48 return NULL;
50 if (vec->ref == 1)
51 return vec;
53 vec2 = isl_vec_dup(ctx, vec);
54 isl_vec_free(ctx, vec);
55 return vec2;
58 void isl_vec_free(struct isl_ctx *ctx, struct isl_vec *vec)
60 if (!vec)
61 return;
63 if (--vec->ref > 0)
64 return;
66 isl_blk_free(ctx, vec->block);
67 free(vec);
70 void isl_vec_dump(struct isl_ctx *ctx, struct isl_vec *vec,
71 FILE *out, int indent)
73 int i;
75 if (!vec) {
76 fprintf(out, "%*snull vec\n", indent, "");
77 return;
80 fprintf(out, "%*s[", indent, "");
81 for (i = 0; i < vec->size; ++i) {
82 if (i)
83 fprintf(out, ",");
84 isl_int_print(out, vec->block.data[i], 0);
86 fprintf(out, "]\n");
89 void isl_vec_lcm(struct isl_ctx *ctx, struct isl_vec *vec, isl_int *lcm)
91 isl_seq_lcm(vec->block.data, vec->size, lcm);