7 pbqp_matrix *pbqp_matrix_alloc(pbqp *pbqp, unsigned rows, unsigned cols)
12 unsigned length = rows * cols;
14 pbqp_matrix *mat = obstack_alloc(&pbqp->obstack, sizeof(*mat) + sizeof(*mat->entries) * length);
19 memset(mat->entries, 0, sizeof(*mat->entries) * length);
24 pbqp_matrix *pbqp_matrix_copy(pbqp *pbqp, pbqp_matrix *m)
26 unsigned len = m->rows * m->cols;
27 pbqp_matrix *copy = obstack_copy(&pbqp->obstack, m, sizeof(*copy) + sizeof(*copy->entries) * len);
33 void pbqp_matrix_add(pbqp_matrix *sum, pbqp_matrix *summand)
40 assert(sum->cols == summand->cols);
41 assert(sum->rows == summand->rows);
43 len = sum->rows * sum->cols;
45 for (i = 0; i < len; ++i) {
46 sum->entries[i] += summand->entries[i];
50 void pbqp_matrix_set(pbqp_matrix *mat, unsigned row, unsigned col, num value)
53 assert(col < mat->cols);
54 assert(row < mat->rows);
56 mat->entries[row * mat->cols + col] = value;