push_union(tab, isl_tab_undo_saved_basis, u);
}
+struct isl_tab *isl_tab_init_samples(struct isl_tab *tab)
+{
+ if (!tab)
+ return NULL;
+
+ tab->n_sample = 0;
+ tab->n_outside = 0;
+ tab->samples = isl_mat_alloc(tab->mat->ctx, 1, 1 + tab->n_var);
+ if (!tab->samples)
+ goto error;
+ return tab;
+error:
+ isl_tab_free(tab);
+ return NULL;
+}
+
+struct isl_tab *isl_tab_add_sample(struct isl_tab *tab,
+ __isl_take isl_vec *sample)
+{
+ if (!tab || !sample)
+ goto error;
+
+ tab->samples = isl_mat_extend(tab->samples,
+ tab->n_sample + 1, tab->samples->n_col);
+ if (!tab->samples)
+ goto error;
+
+ isl_seq_cpy(tab->samples->row[tab->n_sample], sample->el, sample->size);
+ isl_vec_free(sample);
+ tab->n_sample++;
+
+ return tab;
+error:
+ isl_vec_free(sample);
+ isl_tab_free(tab);
+ return NULL;
+}
+
+struct isl_tab *isl_tab_drop_sample(struct isl_tab *tab, int s)
+{
+ if (s != tab->n_outside)
+ isl_mat_swap_rows(tab->samples, tab->n_outside, s);
+ tab->n_outside++;
+ isl_tab_push(tab, isl_tab_undo_drop_sample);
+
+ return tab;
+}
+
/* Mark row with index "row" as being redundant.
* If we may need to undo the operation or if the row represents
* a variable of the original problem, the row is kept,
enum isl_tab_undo_type type, struct isl_tab_var *var);
void isl_tab_push_basis(struct isl_tab *tab);
+struct isl_tab *isl_tab_init_samples(struct isl_tab *tab);
+struct isl_tab *isl_tab_add_sample(struct isl_tab *tab,
+ __isl_take isl_vec *sample);
+struct isl_tab *isl_tab_drop_sample(struct isl_tab *tab, int s);
+
#endif
return NULL;
}
-static struct isl_tab *drop_sample(struct isl_tab *tab, int s)
-{
- if (s != tab->n_outside)
- isl_mat_swap_rows(tab->samples, tab->n_outside, s);
- tab->n_outside++;
- isl_tab_push(tab, isl_tab_undo_drop_sample);
-
- return tab;
-}
-
/* Check whether all the currently active samples also satisfy the inequality
* "ineq" (treated as an equality if eq is set).
* Remove those samples that do not.
sgn = isl_int_sgn(v);
if (eq ? (sgn == 0) : (sgn >= 0))
continue;
- tab = drop_sample(tab, i);
+ tab = isl_tab_drop_sample(tab, i);
if (!tab)
break;
}
if (!tab->empty && sample_is_finite(tab)) {
struct isl_vec *sample;
- tab->samples = isl_mat_extend(tab->samples,
- tab->n_sample + 1, tab->samples->n_col);
- if (!tab->samples)
- goto error;
-
sample = isl_tab_get_sample_value(tab);
- if (!sample)
- goto error;
- isl_seq_cpy(tab->samples->row[tab->n_sample],
- sample->el, sample->size);
- isl_vec_free(sample);
- tab->n_sample++;
+
+ tab = isl_tab_add_sample(tab, sample);
}
feasible = !sol->context_tab->empty;
if (!tab)
goto error;
tab->bset = bset;
- tab->n_sample = 0;
- tab->n_outside = 0;
- tab->samples = isl_mat_alloc(bset->ctx, 1, 1 + tab->n_var);
- if (!tab->samples)
- goto error;
+ tab = isl_tab_init_samples(tab);
return tab;
error:
isl_basic_set_free(bset);