inline
const DMatrixSlice DMatrix::operator()(size_type i1, size_type i2, size_type j1
  , size_type j2) const
{
  return DMatrixSlice( const_cast<value_type*>(col_ptr(1)) + (i1 - 1) + (j1 - 1) * rows()
    , max_rows() * cols(), max_rows(), i2 - i1 + 1, j2 - j1 + 1 );
}
inline
DMatrixSlice DMatrix::operator()(size_type i1, size_type i2, size_type j1
  , size_type j2)
{
  return DMatrixSlice( col_ptr(1) + (i1 - 1) + (j1 - 1) * rows()
    , max_rows() * cols(), max_rows(), i2 - i1 + 1, j2 - j1 + 1 );
}
inline
const DMatrixSlice DMatrix::operator()(const Range1D& I, const Range1D& J) const
{
  Range1D Ix = RangePack::full_range(I,1,rows()), Jx = RangePack::full_range(J,1,cols());
  return DMatrixSlice( const_cast<value_type*>(col_ptr(1)) + (Ix.lbound() - 1) + (Jx.lbound() - 1) * rows()
    , max_rows() * cols(), max_rows(), Ix.size(), Jx.size() );
}
Example #4
0
static void cursor_down(struct hexedit *buf)
{
	size_t space;
	bool need_refresh = false;

	space = buf->offset + (buf->cursor_y + 1) * BYTES_PER_LINE;
	if (space > buf->len) {
		return;
	}

	if (buf->cursor_y + 1 == max_rows(buf->win)) {
		buf->offset += BYTES_PER_LINE;
		need_refresh = true;
	} else {
		buf->cursor_y++;
	}

	if (buf->cursor_offset + BYTES_PER_LINE > buf->len) {
		buf->nibble = 0;
		buf->cursor_offset = buf->len;
		buf->cursor_line_offset = buf->len - space;
		if (buf->cursor_x >= ASCII_COL) {
			buf->cursor_x = ASCII_COL + buf->cursor_line_offset;
		} else {
			buf->cursor_x = offset_to_hex_col(buf->cursor_line_offset);
		}
	}
	if (need_refresh) {
		hexedit_refresh(buf);
	}
	calc_cursor_offset(buf);
}
inline
const DMatrix::value_type* DMatrix::col_ptr(size_type j) const 
{
  if( v_.size() ) {
    validate_col_subscript(j);
    return &const_cast<valarray&>(v_)[ (j-1) * max_rows() ];
  }
  else {
    return 0;
  }
}
inline
DMatrix::value_type* DMatrix::col_ptr(size_type j)
{
  if( v_.size() ) {
    validate_col_subscript(j);
    return &v_[ (j-1) * max_rows() ];
  }
  else {
    return 0;
  }
}
Example #7
0
void hexedit_set_cursor(struct hexedit *buf)
{
	wmove(buf->win, max_rows(buf->win), 0);
	wattron(buf->win, A_REVERSE | A_STANDOUT);
	wclrtoeol(buf->win);
	if (buf->cursor_offset < buf->len) {
		wprintw(buf->win, "Len:%lu Off:%lu Val:0x%X", buf->len,
			buf->cursor_offset, buf->data[buf->cursor_offset]);
	} else {
		wprintw(buf->win, "Len:%lu Off:%lu", buf->len,
			buf->cursor_offset);
	}
	wattroff(buf->win, A_REVERSE | A_STANDOUT);
	wmove(buf->win, buf->cursor_y, buf->cursor_x);
	wcursyncup(buf->win);
	wsyncup(buf->win);
	untouchwin(buf->win);
}
Example #8
0
void use_ruiz_equilibration(pwork *w)
{
    idxint i, j, ind, iter;
    idxint num_cols = w->A ? w->A->n : w->G->n;
    idxint num_A_rows = w->A ? w->A->m : 0;
    idxint num_G_rows = w->G->m;
    pfloat *xtmp = calloc(num_cols, sizeof(pfloat));
    pfloat *Atmp = calloc(num_A_rows, sizeof(pfloat));
    pfloat *Gtmp = calloc(num_G_rows, sizeof(pfloat));
    pfloat total;

    /* initialize equilibration vector to 1 */
    for(i = 0; i < num_cols; i++) {
        w->xequil[i] = 1.0;
    }
    for(i = 0; i < num_A_rows; i++) {
        w->Aequil[i] = 1.0;
    }
    for(i = 0; i < num_G_rows; i++) {
        w->Gequil[i] = 1.0;
    }

    /* iterative equilibration */
    for(iter = 0; iter < EQUIL_ITERS; iter++) {
        /* each iteration updates w->A and w->G */

        /* zero out the temp vectors */
        for(i = 0; i < num_cols; i++) {
            xtmp[i] = 0.0;
        }
        for(i = 0; i < num_A_rows; i++) {
            Atmp[i] = 0.0;
        }
        for(i = 0; i < num_G_rows; i++) {
            Gtmp[i] = 0.0;
        }

        /* compute norm across columns of A, G */
        if(w->A)
            max_cols(xtmp, w->A);
        if(num_G_rows > 0)
            max_cols(xtmp, w->G);

        /* compute norm across rows of A */
        if(w->A)
            max_rows(Atmp, w->A);

        /* compute norm across rows of G */
        if(num_G_rows > 0)
            max_rows(Gtmp, w->G);

        /* now collapse cones together by using total over the group */
        /* ECHU: not sure what the right thing to do here is */
        ind = w->C->lpc->p;
        for(i = 0; i < w->C->nsoc; i++) {
          total = 0.0;
          for(j = 0; j < w->C->soc[i].p; j++) {
            total += Gtmp[ind + j];
          }
          for(j = 0; j < w->C->soc[i].p; j++) {
            Gtmp[ind + j] = total;
          }
          ind += w->C->soc[i].p;
        }

        /* take the sqrt */
        for(i = 0; i < num_cols; i++) {
          xtmp[i] = fabs(xtmp[i]) < 1e-6 ? 1.0 : sqrt(xtmp[i]);
        }
        for(i = 0; i < num_A_rows; i++) {
          Atmp[i] = fabs(Atmp[i]) < 1e-6 ? 1.0 : sqrt(Atmp[i]);
        }
        for(i = 0; i < num_G_rows; i++) {
          Gtmp[i] = fabs(Gtmp[i]) < 1e-6 ? 1.0 : sqrt(Gtmp[i]);
        }

        /* equilibrate the matrices */
        if(w->A)
            equilibrate_rows(Atmp, w->A);
        if(num_G_rows > 0)
            equilibrate_rows(Gtmp, w->G);

        if(w->A)
            equilibrate_cols(xtmp, w->A);
        if(num_G_rows > 0)
            equilibrate_cols(xtmp, w->G);

        /* update the equilibration matrix */
        for(i = 0; i < num_cols; i++) {
          w->xequil[i] *= xtmp[i];
        }
        for(i = 0; i < num_A_rows; i++) {
          w->Aequil[i] *= Atmp[i];
        }
        for(i = 0; i < num_G_rows; i++) {
          w->Gequil[i] *= Gtmp[i];
        }
    }

    /* equilibrate the c vector 
    for(i = 0; i < num_cols; i++) {
        w->c[i] /= w->xequil[i];
    } */

    /* equilibrate the b vector */
    for(i = 0; i < num_A_rows; i++) {
        w->b[i] /= w->Aequil[i];
    }
    /* equilibrate the h vector */
    for(i = 0; i < num_G_rows; i++) {
        w->h[i] /= w->Gequil[i];
    }

    free(xtmp);
    free(Atmp);
    free(Gtmp);
}
Example #9
0
static size_t bytes_per_screen(WINDOW *win)
{
	return max_rows(win) * BYTES_PER_LINE;
}
inline
const DMatrixSlice::value_type* DMatrixSlice::col_ptr(size_type j) const {
  if( ptr_ )
    validate_col_subscript(j);
  return ptr_ + (j-1) * max_rows();	// will be 0 if not bound to a view.
}
inline
const DVectorSlice DMatrixSlice::col(size_type j) const {
  validate_col_subscript(j);
  return DVectorSlice( const_cast<value_type*>(ptr_) + (j-1)*max_rows(), rows(), 1 );
} 
inline
DVectorSlice	DMatrixSlice::col(size_type j) {
  validate_col_subscript(j);
  return DVectorSlice( ptr_ + (j-1)*max_rows(), rows(), 1 );
} 
inline
const DVectorSlice DMatrixSlice::row(size_type i) const {
  validate_row_subscript(i);
  return DVectorSlice( const_cast<value_type*>(ptr_) + (i-1), cols(), max_rows() );
} 
inline
DVectorSlice  DMatrixSlice::row(size_type i) {
  validate_row_subscript(i);
  return DVectorSlice( ptr_ + (i-1), cols(), max_rows() );
} 
inline
const DMatrixSlice DMatrix::operator()() const
{
  return DMatrixSlice( const_cast<value_type*>(col_ptr(1)), max_rows() * cols(), max_rows()
    , rows(), cols() );
}
inline
DMatrixSlice DMatrix::operator()()
{
  return DMatrixSlice( col_ptr(1), max_rows() * cols(), max_rows(), rows(), cols() );
}