6 pbqp_matrix *pbqp_matrix_alloc(pbqp *pbqp, unsigned rows, unsigned cols)
14 unsigned length = rows * cols;
16 mat = obstack_alloc(&pbqp->obstack, sizeof(*mat) + sizeof(num) * (length - 1));
21 for (index = 0; index < length; ++index) {
22 mat->entries[index] = 0;
28 pbqp_matrix *pbqp_matrix_copy(pbqp *pbqp, pbqp_matrix *m)
32 pbqp_matrix *copy = obstack_alloc(&pbqp->obstack, sizeof(*copy));
36 len = m->rows * m->cols;
38 for (i = 0; i < len; ++i) {
39 copy->entries[i] = m->entries[i];
45 void pbqp_matrix_add(pbqp_matrix *sum, pbqp_matrix *summand)
52 assert(sum->cols == summand->cols);
53 assert(sum->rows == summand->rows);
55 len = sum->rows * sum->cols;
57 for (i = 0; i < len; ++i) {
58 sum->entries[i] += summand->entries[i];
62 void pbqp_matrix_set(pbqp_matrix *mat, unsigned row, unsigned col, num value)
65 assert(col < mat->cols);
66 assert(row < mat->rows);
68 mat->entries[row * mat->cols + col] = value;