/* ------------------------------------------------------ create and return a subtree metric DV object input : vmetricDV -- a metric defined on the vertices return : tmetricDV -- a metric defined on the subtrees created -- 96jun23, cca ------------------------------------------------------ */ DV * Tree_setSubtreeDmetric ( Tree *tree, DV *vmetricDV ) { int u, v ; double *tmetric, *vmetric ; DV *tmetricDV ; /* --------------- check the input --------------- */ if ( tree == NULL || tree->n <= 0 || vmetricDV == NULL || tree->n != DV_size(vmetricDV) || (vmetric = DV_entries(vmetricDV)) == NULL ) { fprintf(stderr, "\n fatal error in Tree_setSubtreeImetric(%p,%p)" "\n bad input\n", tree, vmetricDV) ; exit(-1) ; } tmetricDV = DV_new() ; DV_init(tmetricDV, tree->n, NULL) ; tmetric = DV_entries(tmetricDV) ; for ( v = Tree_postOTfirst(tree) ; v != -1 ; v = Tree_postOTnext(tree, v) ) { tmetric[v] = vmetric[v] ; for ( u = tree->fch[v] ; u != -1 ; u = tree->sib[u] ) { tmetric[v] += tmetric[u] ; } } return(tmetricDV) ; }
/* ------------------------------------------------------------------ create and return a height metric DV object input : vmetricDV -- a metric defined on the vertices output : dmetricDV -- a depth metric defined on the vertices hmetric[v] = vmetric[v] + max{p(u) = v} hmetric[u] if fch[v] != -1 = vmetric[v] if fch[v] == -1 created -- 96jun23, cca ------------------------------------------------------------------ */ DV * Tree_setHeightDmetric ( Tree *tree, DV *vmetricDV ) { int u, v, val ; double *hmetric, *vmetric ; DV *hmetricDV ; /* --------------- check the input --------------- */ if ( tree == NULL || tree->n < 1 || vmetricDV == NULL || tree->n != DV_size(vmetricDV) || (vmetric = DV_entries(vmetricDV)) == NULL ) { fprintf(stderr, "\n fatal error in Tree_setHeightDmetric(%p,%p)" "\n bad input\n", tree, vmetricDV) ; exit(-1) ; } hmetricDV = DV_new() ; DV_init(hmetricDV, tree->n, NULL) ; hmetric = DV_entries(hmetricDV) ; for ( v = Tree_postOTfirst(tree) ; v != -1 ; v = Tree_postOTnext(tree, v) ) { for ( u = tree->fch[v], val = 0 ; u != -1 ; u = tree->sib[u] ) { if ( val < hmetric[u] ) { val = hmetric[u] ; } } hmetric[v] = val + vmetric[v] ; } return(hmetricDV) ; }
/* ------------------------------------------------------------ create and return a depth metric DV object input : vmetricDV -- a metric defined on the vertices output : dmetricDV -- a depth metric defined on the vertices dmetric[u] = vmetric[u] + dmetric[par[u]] if par[u] != -1 = vmetric[u] if par[u] == -1 created -- 96jun23, cca ------------------------------------------------------------ */ DV * Tree_setDepthDmetric ( Tree *tree, DV *vmetricDV ) { int u, v ; double *dmetric, *vmetric ; DV *dmetricDV ; /* --------------- check the input --------------- */ if ( tree == NULL || tree->n < 1 || vmetricDV == NULL || tree->n != DV_size(vmetricDV) || (vmetric = DV_entries(vmetricDV)) == NULL ) { fprintf(stderr, "\n fatal error in Tree_setDepthDmetric(%p,%p)" "\n bad input\n", tree, vmetricDV) ; exit(-1) ; } dmetricDV = DV_new() ; DV_init(dmetricDV, tree->n, NULL) ; dmetric = DV_entries(dmetricDV) ; for ( u = Tree_preOTfirst(tree) ; u != -1 ; u = Tree_preOTnext(tree, u) ) { dmetric[u] = vmetric[u] ; if ( (v = tree->par[u]) != -1 ) { dmetric[u] += dmetric[v] ; } } return(dmetricDV) ; }
/* ----------------------- set mtx(*,jcol) = y[*] created -- 98may01, cca ----------------------- */ void A2_setColumnDV ( A2 *mtx, DV *colDV, int jcol ) { double *col, *entries ; int inc1, i, k, n1 ; /* --------------- check the input --------------- */ if ( mtx == NULL || colDV == NULL || DV_size(colDV) != (n1 = mtx->n1) || jcol < 0 || jcol >= mtx->n2 ) { fprintf(stderr, "\n fatal error in A2_setColumnDV(%p,%p,%d)" "\n bad input\n", mtx, colDV, jcol) ; exit(-1) ; } if ( ! A2_IS_REAL(mtx) ) { fprintf(stderr, "\n fatal error in A2_setColumnDV(%p,%p,%d)" "\n bad type %d, must be SPOOLES_REAL\n", mtx, colDV, jcol, mtx->type) ; exit(-1) ; } k = jcol * mtx->inc2 ; inc1 = mtx->inc1 ; entries = mtx->entries ; col = DV_entries(colDV) ; for ( i = 0 ; i < n1 ; i++, k += inc1 ) { entries[k] = col[i] ; } return ; }
/* ----------------------- set mtx(irow,*) = y[*] created -- 98may01, cca ----------------------- */ void A2_setRowDV ( A2 *mtx, DV *rowDV, int irow ) { double *entries, *row ; int inc2, j, k, n2 ; /* --------------- check the input --------------- */ if ( mtx == NULL || rowDV == NULL || DV_size(rowDV) != (n2 = mtx->n2) || irow < 0 || irow >= mtx->n1 ) { fprintf(stderr, "\n fatal error in A2_setRowDV(%p,%p,%d)" "\n bad input\n", mtx, rowDV, irow) ; exit(-1) ; } if ( ! A2_IS_REAL(mtx) ) { fprintf(stderr, "\n fatal error in A2_setRowDV(%p,%p,%d)" "\n bad type %d, must be SPOOLES_REAL\n", mtx, rowDV, irow, mtx->type) ; exit(-1) ; } k = irow * mtx->inc1 ; inc2 = mtx->inc2 ; entries = mtx->entries ; row = DV_entries(rowDV) ; for ( j = 0 ; j < n2 ; j++, k += inc2 ) { entries[k] = row[j] ; } return ; }
/* ------------------------------------ return the number of bytes in use in the workspace owned by this object created -- 98may01, cca ------------------------------------ */ int SubMtx_nbytesInUse ( SubMtx *mtx ) { if ( mtx == NULL ) { fprintf(stderr, "\n fatal error in SubMtx_nbytesInUse(%p)" "\n bad input\n", mtx) ; exit(-1) ; } return(sizeof(double)*DV_size(&mtx->wrkDV)) ; }