Skip to content

Commit

Permalink
improves memory usage for symmetric matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
rieck committed Jul 24, 2014
1 parent 7ee1ecb commit ddcce3d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/hmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,20 @@ void hmatrix_yrange(hmatrix_t *m, char *y)
*/
float *hmatrix_alloc(hmatrix_t *m)
{
if (m->x.n == m->y.n && m->x.i == m->y.i && m->x.i == 0) {
/* Full matrix -> allocate triangle */
int xl, yl;

/* Compute dimensions of matrix */
xl = m->x.n - m->x.i;
yl = m->y.n - m->y.i;

if (m->x.n == m->y.n && m->x.i == m->y.i) {
/* Symmetric matrix -> allocate triangle */
m->triangular = TRUE;
m->size = (m->x.n * (m->x.n - 1) / 2 + m->x.n);
m->size = xl * (xl - 1) / 2 + xl;
} else {
/* Patrial matrix -> allocate rectangle */
m->triangular = FALSE;
m->size = (m->x.n - m->x.i) * (m->y.n - m->y.i);
m->size = xl * yl;
}

/* Allocate memory */
Expand Down

0 comments on commit ddcce3d

Please sign in to comment.