示例#1
0
 //PROTOTYPE IMPL!!!!!!!!
 //BUG BUG Result ought to be dense/sparse/diag according as M is....
 matrix apply(RingHom phi, ConstMatrixView M)
 {
   CoCoA_ASSERT(domain(phi) == RingOf(M));
   matrix NewM(NewDenseMat(codomain(phi), NumRows(M), NumCols(M)));
   for (long i=0; i < NumRows(M); ++i)
     for (long j=0; j < NumCols(M); ++j)
       SetEntry(NewM, i, j, phi(M(i,j)));
   return NewM;
 }
示例#2
0
/// Change number of rows, either by inserting or removing them
void c4_Sequence::Resize(int newSize_, int) {
  if (NumHandlers() > 0) {
    int diff = newSize_ - NumRows();

    if (diff > 0) {
      c4_Row empty; // make sure this doesn't recurse, see below
      InsertAt(NumRows(), &empty, diff);
    } else if (diff < 0)
      RemoveAt(newSize_,  - diff);
  } else
  // need special case to avoid recursion for c4_Row allocations
    SetNumRows(newSize_);
}
示例#3
0
文件: handler.cpp 项目: KDE/kdepim
void c4_HandlerSeq::DetachFromStorage(bool full_)
{
    if (_persist != 0) {
        int limit = full_ ? 0 : NumFields();

        // get rid of all handlers which might do I/O
        for (int c = NumHandlers(); --c >= 0;) {
            c4_Handler &h = NthHandler(c);

            // all nested fields are detached recursively
            if (IsNested(c))
                for (int r = 0; r < NumRows(); ++r)
                    if (h.HasSubview(r)) {
                        SubEntry(c, r).DetachFromStorage(full_);
                    }

            if (c >= limit) {
                if (h.IsPersistent()) {
                    delete  &h;
                    _handlers.RemoveAt(c);
                    ClearCache();
                }
            }
        }

        if (full_) {
            //UnmappedAll();
            _persist = 0;
        }
    }
}
示例#4
0
void QueueListBox::ItemRightClicked(GG::ListBox::iterator it, const GG::Pt& pt) {
    // Create popup menu with a Delete Item command to provide same functionality as
    // DoubleClick since under laggy conditions it DoubleClick can have trouble
    // being interpreted correctly (can instead be treated as simply two unrelated left clicks)

    GG::MenuItem menu_contents;
    menu_contents.next_level.push_back(GG::MenuItem(UserString("MOVE_UP_QUEUE_ITEM"),   1, false, false));
    menu_contents.next_level.push_back(GG::MenuItem(UserString("MOVE_DOWN_QUEUE_ITEM"), 2, false, false));
    menu_contents.next_level.push_back(GG::MenuItem(UserString("DELETE_QUEUE_ITEM"),    3, false, false));

    GG::PopupMenu popup(pt.x, pt.y, ClientUI::GetFont(), menu_contents, ClientUI::TextColor(),
                        ClientUI::WndOuterBorderColor(), ClientUI::WndColor(), ClientUI::EditHiliteColor());

    if (popup.Run()) {
        switch (popup.MenuID()) {
        case 1: { // move item to top
            if (GG::ListBox::Row* row = *it)
                QueueItemMovedSignal(row, 0);
            break;
        }
        case 2: { // move item to bottom
            if (GG::ListBox::Row* row = *it)
                QueueItemMovedSignal(row, NumRows());
            break;
        }
        case 3: { // delete item
            DoubleClickedSignal(it);
            break;
        }

        default:
            break;
        }
    }
}
示例#5
0
void QueueListBox::ItemRightClicked(GG::ListBox::iterator it, const GG::Pt& pt, const GG::Flags<GG::ModKey>& modkeys) {
    GG::MenuItem menu_contents;
    menu_contents.next_level.push_back(GG::MenuItem(UserString("MOVE_UP_QUEUE_ITEM"),   1, false, false));
    menu_contents.next_level.push_back(GG::MenuItem(UserString("MOVE_DOWN_QUEUE_ITEM"), 2, false, false));
    menu_contents.next_level.push_back(GG::MenuItem(UserString("DELETE_QUEUE_ITEM"),    3, false, false));

    GG::PopupMenu popup(pt.x, pt.y, ClientUI::GetFont(), menu_contents, ClientUI::TextColor(),
                        ClientUI::WndOuterBorderColor(), ClientUI::WndColor(), ClientUI::EditHiliteColor());

    if (popup.Run()) {
        switch (popup.MenuID()) {
        case 1: { // move item to top
            if (GG::ListBox::Row* row = *it)
                QueueItemMovedSignal(row, 0);
            break;
        }
        case 2: { // move item to bottom
            if (GG::ListBox::Row* row = *it)
                QueueItemMovedSignal(row, NumRows());
            break;
        }
        case 3: { // delete item
            QueueItemDeletedSignal(it);
            break;
        }

        default:
            break;
        }
    }
}
示例#6
0
文件: NumVec.cpp 项目: IEDB/smmpmbec
void CNumMat::operator-=(const CNumMat &m)
{
	assert(NumCols()==m.NumCols());
	assert(NumRows()==m.NumRows());
	if(gsl_matrix_sub(m_mat,m.m_mat))
		throw BPException("gsl_matrix_sub");
}
示例#7
0
文件: NumVec.cpp 项目: IEDB/smmpmbec
const double &CNumMat::operator()(unsigned row, unsigned col) const
{
	assert(m_mat!=NULL);
	assert(row<NumRows());
	assert(col<NumCols());
	return(*gsl_matrix_ptr(m_mat,row, col));
}
示例#8
0
文件: viewx.cpp 项目: KDE/kdepim
/// Insert one or more rows into this sequence
void c4_Sequence::InsertAt(int index_, c4_Cursor newElem_, int count_)
{
    d4_assert(newElem_._seq != 0);

    c4_Notifier change(this);
    if (GetDependencies()) {
        change.StartInsertAt(index_, newElem_, count_);
    }

    SetNumRows(NumRows() + count_);

    c4_Bytes data;

    for (int i = 0; i < newElem_._seq->NumHandlers(); ++i) {
        c4_Handler &h = newElem_._seq->NthHandler(i);

        // added 06-12-1999 to do index remapping for derived seq's
        const c4_Sequence *hc = newElem_._seq->HandlerContext(i);
        int ri = newElem_._seq->RemapIndex(newElem_._index, hc);

        int colNum = PropIndex(h.Property());
        d4_assert(colNum >= 0);

        if (h.Property().Type() == 'V') {
            // If inserting from self: Make sure we get a copy of the bytes,
            // so we don't get an invalid pointer if the memory get realloc'ed
            h.GetBytes(ri, data, newElem_._seq == this);

            // special treatment for subviews, insert empty, then overwrite
            // changed 19990904 - probably fixes a long-standing limitation
            c4_Bytes temp;
            h.ClearBytes(temp);

            c4_Handler &h2 = NthHandler(colNum);
            h2.Insert(index_, temp, count_);

            for (int j = 0; j < count_; ++j) {
                h2.Set(index_ + j, data);
            }
        } else {
            h.GetBytes(ri, data);
            NthHandler(colNum).Insert(index_, data, count_);
        }
    }

    // if number of props in dest is larger after adding, clear the rest
    // this way, new props get copied and undefined props get cleared
    if (newElem_._seq->NumHandlers() < NumHandlers()) {
        for (int j = 0; j < NumHandlers(); ++j) {
            c4_Handler &h = NthHandler(j);

            // if the property does not appear in the source
            if (newElem_._seq->PropIndex(h.PropId()) < 0) {
                h.ClearBytes(data);
                h.Insert(index_, data, count_);
            }
        }
    }
}
示例#9
0
bool ctlSQLResult::ToFile(frmExport *frm)
{
	if (NumRows() > 0)
	{
		return frm->Export(thread->DataSet());
	}
	return false;
}
示例#10
0
/* EXPORT->IsTriMat: True if matrix is lower triangular */
Boolean IsTriMat(Matrix m)
{
   int i,n;

   n=NumRows(m);
   for(i=1;i<=n;i++)
      if (VectorSize(m[i])!=i) return(FALSE);
   return(TRUE);
}
示例#11
0
  // Simple rather than efficient (esp. the call to eval)
  std::vector<RingElem> BM_generic(const SparsePolyRing& P, const ConstMatrixView& pts)
  {
    if (CoeffRing(P) != RingOf(pts)) CoCoA_ERROR(ERR::MixedRings, "Buchberger-Moeller");
    if (NumIndets(P) < NumCols(pts)) CoCoA_ERROR(ERR::IncompatDims, "Buchberger-Moeller");

    const long NumPts = NumRows(pts);
    const long dim = NumCols(pts);
    const ring k = CoeffRing(P);

    vector<RingElem> GB;
    const PPMonoid TT = PPM(P);
    QBGenerator QBG(TT);
    QBG.myCornerPPIntoQB(one(TT));
    matrix M = NewDenseMat(k, 1, NumPts);
    // Fill first row with 1:
    for (int i=0; i<NumPts; ++i) SetEntry(M,0,i, 1);

    // The next loop removes the last indets from consideration.
    for (int i=dim; i < NumIndets(TT); ++i)
      QBG.myCornerPPIntoAvoidSet(indet(TT,i));

    while (!QBG.myCorners().empty())
    {
      const PPMonoidElem t = QBG.myCorners().front();
      const vector<RingElem> v = eval(t, pts);
      ConstMatrixView NewRow = RowMat(v);
      const matrix a = LinSolve(transpose(M), transpose(NewRow));
      if (IsValidSolution(a))
      {
        QBG.myCornerPPIntoAvoidSet(t);
        RingElem NewGBElem = monomial(P, one(k), t);
        const vector<PPMonoidElem>& QB =  QBG.myQB();
        for (int i=0; i < NumRows(M); ++i)
          NewGBElem -= monomial(P, a(i,0), QB[i]);
        GB.push_back(NewGBElem);
      }
      else
      {
        QBG.myCornerPPIntoQB(t);
        M = NewDenseMat(ConcatVer(M, NewRow));
      }
    }
    return GB;
  }
示例#12
0
bool ctlSQLResult::Export()
{
	if (NumRows() > 0)
	{
		frmExport dlg(this);
		if (dlg.ShowModal() == wxID_OK)
			return dlg.Export(NULL);
	}
	return false;
}
示例#13
0
 // I bet this makes lots of wasteful copies...
 matrix NewDenseMat(ConstMatrixView M)
 {
   const long r = NumRows(M);
   const long c = NumCols(M);
   matrix ans(new DenseMatImpl(RingOf(M), r, c));
   for (long i=0; i < r; ++i)
     for (long j=0; j < c; ++j)
       SetEntry(ans, i, j, M(i, j));
   return ans;
 }
示例#14
0
bool ctlSQLResult::ToFile()
{
	if (NumRows() > 0)
	{
		frmExport dlg(this);
		if (dlg.ShowModal() == wxID_OK)
			return dlg.Export(thread->DataSet());
	}
	return false;
}
示例#15
0
/// Remove one or more rows from this sequence
void c4_Sequence::RemoveAt(int index_, int count_) {
  c4_Notifier change(this);
  if (GetDependencies())
    change.StartRemoveAt(index_, count_);

  SetNumRows(NumRows() - count_);

  //! careful, this does no index remapping, wrong for derived seq's
  for (int i = 0; i < NumHandlers(); ++i)
    NthHandler(i).Remove(index_, count_);
}
示例#16
0
文件: NumVec.cpp 项目: IEDB/smmpmbec
void CNumMat::resize(unsigned rows, unsigned cols)
{
	assert(rows>0 && cols>0);
	if(m_mat!=NULL)
	{
		if(NumRows()==rows && NumCols()==cols)
			return;
		gsl_matrix_free(m_mat);
	}
	m_mat=gsl_matrix_alloc(rows,cols);
}
示例#17
0
文件: handler.cpp 项目: KDE/kdepim
void c4_HandlerSeq::DetermineSpaceUsage()
{
    for (int c = 0; c < NumFields(); ++c)
        if (IsNested(c)) {
            c4_Handler &h = NthHandler(c);
            for (int r = 0; r < NumRows(); ++r)
                if (h.HasSubview(r)) {
                    SubEntry(c, r).DetermineSpaceUsage();
                }
        }
}
示例#18
0
/* CloneSMatrix: return a clone of given Matrix */
SMatrix CloneSMatrix(MemHeap *hmem, SMatrix s, Boolean sharing)
{
   SMatrix t;  /* the target */

   if (s==NULL) return NULL;
   if (GetUse(s)>0 && sharing) {
      IncUse(s);
      return s;
   }
   t = CreateSMatrix(hmem,NumRows(s),NumCols(s));
   CopyMatrix(s,t);
   return t;
}
示例#19
0
 bool DuplicateRows(const ConstMatrixView& M)
 {
   const long nrows = NumRows(M);
   const long ncols = NumCols(M);
   for (long i1=0; i1 < nrows; ++i1)
     for (long i2=i1+1; i2 < nrows; ++i2)
     {
       bool NoDifference = true;
       for (long j=0; NoDifference && j < ncols; ++j)
         NoDifference = (M(i1,j) == M(i2,j));
       if (NoDifference) return true;
     }
   return false;
 }
示例#20
0
PODVector<CubeTerrain*>* Terrain::GetColumnCubes(CubeTerrain *cube, DIR dir)
{
    const int dRow[8] = { 0, -1, -1, -1, 0, 1, 1,  1};
    const int dCol[8] = {-1, -1,  0,  1, 1, 1, 0, -1};

    uint row = (uint)((int)cube->row + dRow[dir]);
    uint col = (uint)((int)cube->col + dCol[dir]);

    if(row > NumRows() - 1 || col > NumCols() - 1)
    {
        return nullptr;
    }

    return &columnsCubes[row][col];
}
示例#21
0
    double KMeansTrainer::assignClosestCenter(math::ConstMatrixReference<double, math::MatrixLayout::columnMajor> X, math::VectorReference<size_t, math::VectorOrientation::column> clusterAssignment)
    {
        auto D = pairwiseDistance(X, _means);

        double totalDist = 0;
        for (int i = 0; i < D.NumRows(); ++i)
        {
            auto dist = D.GetRow(i);
            auto minElement = std::min_element(dist.GetDataPointer(), dist.GetDataPointer() + dist.Size());
            clusterAssignment[i] = minElement - dist.GetDataPointer();
            totalDist += *minElement;
        }

        return totalDist;
    }
int Ifpack2_SparseContainer<T>::
SetMatrixElement(const int row, const int col, const double value)
{
    if (!IsInitialized())
        IFPACK2_CHK_ERR(-3); // problem not shaped yet

    if ((row < 0) || (row >= NumRows())) {
        IFPACK2_CHK_ERR(-2); // not in range
    }

    if ((col < 0) || (col >= NumRows())) {
        IFPACK2_CHK_ERR(-2); // not in range
    }

    int ierr = Matrix_->InsertGlobalValues((int)row,1,(double*)&value,(int*)&col);
    if (ierr < 0) {
        ierr = Matrix_->SumIntoGlobalValues((int)row,1,(double*)&value,(int*)&col);
        if (ierr < 0)
            IFPACK2_CHK_ERR(-1);
    }

    return(0);

}
ostream& Ifpack2_SparseContainer<T>::Print(ostream & os) const
{
    os << "================================================================================" << endl;
    os << "Ifpack2_SparseContainer" << endl;
    os << "Number of rows          = " << NumRows() << endl;
    os << "Number of vectors       = " << NumVectors() << endl;
    os << "IsInitialized()         = " << IsInitialized() << endl;
    os << "IsComputed()            = " << IsComputed() << endl;
    os << "Flops in Initialize()   = " << InitializeFlops() << endl;
    os << "Flops in Compute()      = " << ComputeFlops() << endl;
    os << "Flops in ApplyInverse() = " << ApplyInverseFlops() << endl;
    os << "================================================================================" << endl;
    os << endl;

    return(os);
}
示例#24
0
  std::vector<RingElem> BM_modp(const SparsePolyRing& P, const ConstMatrixView& pts)
  {
    ring Fp = CoeffRing(P);

    const int NumPts = NumRows(pts);
    const int NumVars = NumCols(pts);
    const long p = ConvertTo<long>(characteristic(Fp));
    FF FFp = FFctor(p);
    FFselect(FFp);
    FFelem** points_p = (FFelem**)malloc(NumPts*sizeof(FFelem*));
    for (int i=0; i < NumPts; ++i)
    {
      points_p[i] = (FFelem*)malloc(NumVars*sizeof(FFelem));
      for (int j=0; j < NumVars; ++j)
      {
        points_p[i][j] = ConvertTo<FFelem>(LeastNNegRemainder(ConvertTo<BigInt>(pts(i,j)), p));
      }
    }
    pp_cmp_PPM = &PPM(P);
    const BM modp = BM_affine_mod_p(NumVars, NumPts, points_p, pp_cmp);
    if (modp == NULL) return std::vector<RingElem>(); // empty list means error

    const int GBsize = modp->GBsize;
    std::vector<RingElem> GB(GBsize);
    vector<long> expv(NumVars);
    for (int i=0; i < GBsize; ++i)
    {
      for (int var = 0; var < NumVars; ++var)
        expv[var] = modp->pp[modp->GB[i]][var];
      RingElem GBelem = monomial(P, 1, expv);
      for (int j=0; j < NumPts; ++j)
      {
        const int c = modp->M[modp->GB[i]][j+NumPts];
        if (c == 0) continue;
        for (int var = 0; var < NumVars; ++var)
          expv[var] = modp->pp[modp->sep[j]][var];
        GBelem += monomial(P, c, expv);
      }
      GB[i] = GBelem;
    }
    BM_dtor(modp);
    return GB;
  }
示例#25
0
文件: HLVRec.c 项目: didw/HTS
/* CheckLRTransP

     determine wheter transition matrix is left-to-right, i.e. no backward transitions
*/
static Boolean CheckLRTransP (SMatrix transP)
{
   int r,c,N;

   N = NumCols (transP);
   assert (N == NumRows (transP));

   for (r = 1; r <= N; ++r) {
      for (c = 1; c < r; ++c) {
         if (transP[r][c] > LSMALL)
            return FALSE;
      }
      for (c = r+2; c < r; ++c) {
         if (transP[r][c] > LSMALL)
            return FALSE;
      }
   }

   return TRUE;   
}
/*-------------------------------------------------------------------------*\
 -  private                                                                 -
\*-------------------------------------------------------------------------*/
void GenericFieldContainerEditor::updateFieldsPanel(FieldContainer* fc)
{
    _FieldsContainer->clearChildren();

    UInt32 NumFields(fc->getType().getNumFieldDescs());
    FieldDescriptionBase* Desc;
    FieldEditorComponentUnrecPtr TheEditor;
    LabelUnrecPtr TheLabel;
    ComponentRecPtr TheToolTip;
    GridBagLayoutConstraintsRefPtr LayoutConstraints;
    PanelRefPtr FieldPanel;
    UInt32 NumRows(0),NumRowsForField(1);

    BorderLayoutRefPtr TheBorderLayout = BorderLayout::create();
    BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create();
    WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST);
    BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create();
    CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER);

    //Backgrounds
    ColorLayerRefPtr HeaderBgLayer = ColorLayer::create();
    HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f));

    ColorLayerRefPtr LightBgLayer = ColorLayer::create();
    LightBgLayer->setColor(Color4f(0.9f,0.9f,0.9f,1.0f));
    ColorLayerRefPtr DarkBgLayer = ColorLayer::create();
    DarkBgLayer->setColor(Color4f(0.8f,0.8f,0.8f,1.0f));

    LayoutConstraints = GridBagLayoutConstraints::create();
    LayoutConstraints->setGridX(0);
    LayoutConstraints->setGridY(NumRows);
    LayoutConstraints->setGridHeight(1);
    LayoutConstraints->setGridWidth(2);
    LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);

    LabelRecPtr FieldsLabel = Label::create();
    FieldsLabel->setAlignment(Vec2f(0.5f,0.5f));
    FieldsLabel->setText("Fields");
    FieldsLabel->setBackgrounds(HeaderBgLayer);
    FieldsLabel->setConstraints(LayoutConstraints);
    FieldsLabel->setFont(_BoldFont);

    _FieldsContainer->pushToChildren(FieldsLabel);
    ++NumRows;

    if(_GenericNameAttachmentEditor->isTypeEditable(fc->getType()))
    {
        //Create the Label
        TheLabel = Label::create();
        TheLabel->setText("Name");
        TheLabel->setBackgrounds(NULL);
        TheLabel->setConstraints(WestConstraint);
        TheLabel->setPreferredSize(Vec2f(160.0f,22.0f));

        //Attach the Generic Name Editor
        _GenericNameAttachmentEditor->setCommandManager(_CmdManager);
        _GenericNameAttachmentEditor->attachContainer(fc);
        _GenericNameAttachmentEditor->setConstraints(CenterConstraint);

        //Create the Panel
        LayoutConstraints = GridBagLayoutConstraints::create();
        LayoutConstraints->setGridX(0);
        LayoutConstraints->setGridY(NumRows);
        LayoutConstraints->setGridHeight(1);
        LayoutConstraints->setGridWidth(1);
        LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);

        FieldPanel = Panel::createEmpty();
        FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f));
        FieldPanel->pushToChildren(TheLabel);
        FieldPanel->pushToChildren(_GenericNameAttachmentEditor);
        FieldPanel->setLayout(TheBorderLayout);
        FieldPanel->setConstraints(LayoutConstraints);
        FieldPanel->setBackgrounds(LightBgLayer);

        _FieldsContainer->pushToChildren(FieldPanel);
        ++NumRows;
    }

    UInt32 UsedFieldCount(0);
    for(UInt32 i(1) ; i<=NumFields ; ++i)
    {
        Desc = fc->getFieldDescription(i);
        if(Desc != NULL &&
           !Desc->isInternal() &&
           Desc->getFieldType().getClass() != FieldType::ParentPtrField &&
           //HACK: Stop the pixel field from being editable on Images
           !(fc->getType().isDerivedFrom(Image::getClassType()) &&
             Desc->getFieldId() == Image::PixelFieldId))
        {
            //Create the Editor
            TheEditor = FieldEditorFactory::the()->createDefaultEditor(fc, Desc->getFieldId(), _CmdManager);
            if(TheEditor != NULL)
            {
                NumRowsForField = TheEditor->getNumRequestedRows();
                pushToEditors(TheEditor);
                TheEditor->setConstraints(CenterConstraint);

                //Create the Label
                TheLabel = Label::create();
                TheLabel->setText(Desc->getCName());
                TheLabel->setBackgrounds(NULL);
                TheLabel->setConstraints(WestConstraint);
                TheLabel->setPreferredSize(Vec2f(160.0f,22.0f));
                TheToolTip = createFieldToolTip(Desc);
                TheLabel->setToolTip(TheToolTip);

                //Create the Panel
                LayoutConstraints = GridBagLayoutConstraints::create();
                LayoutConstraints->setGridX(0);
                LayoutConstraints->setGridY(NumRows);
                LayoutConstraints->setGridHeight(NumRowsForField);
                LayoutConstraints->setGridWidth(1);
                LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);


                FieldPanel = Panel::createEmpty();
                FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f));
                FieldPanel->pushToChildren(TheLabel);
                FieldPanel->pushToChildren(TheEditor);
                FieldPanel->setLayout(TheBorderLayout);
                FieldPanel->setConstraints(LayoutConstraints);
                if((UsedFieldCount%2) == 0)
                {
                    FieldPanel->setBackgrounds(DarkBgLayer);
                }
                else
                {
                    FieldPanel->setBackgrounds(LightBgLayer);
                }

                _FieldsContainer->pushToChildren(FieldPanel);
                NumRows += NumRowsForField;
                TheEditor->setPreferredSize(Vec2f(50.0f,22.0f * NumRowsForField));
                ++UsedFieldCount;
            }
        }
    }

    //Set the number of rows for the grid layout
    dynamic_cast<GridBagLayout*>(_FieldsContainer->getLayout())->setRows(NumRows);
    _FieldsContainer->setPreferredSize(Vec2f(400.0f, NumRows*24.0f));
}
示例#27
0
void ctlSQLResult::DisplayData(bool single)
{
	if (!thread || !thread->DataValid())
		return;

	if (thread->ReturnCode() != PGRES_TUPLES_OK)
		return;

	rowcountSuppressed = single;
	Freeze();

	/*
	 * Resize and repopulate by informing it to delete all the rows and
	 * columns, then append the correct number of them. Probably is a
	 * better way to do this.
	 */
	wxGridTableMessage *msg;
	sqlResultTable *table = (sqlResultTable *)GetTable();
	msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, GetNumberRows());
	ProcessTableMessage(*msg);
	delete msg;
	msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_COLS_DELETED, 0, GetNumberCols());
	ProcessTableMessage(*msg);
	delete msg;
	msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, NumRows());
	ProcessTableMessage(*msg);
	delete msg;
	msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_COLS_APPENDED, thread->DataSet()->NumCols());
	ProcessTableMessage(*msg);
	delete msg;

	if (single)
	{
		int w, h;
		if (colSizes.GetCount() == 1)
			w = colSizes.Item(0);
		else
			GetSize(&w, &h);

		colNames.Add(thread->DataSet()->ColName(0));
		colTypes.Add(wxT(""));
		colTypClasses.Add(0L);

		SetColSize(0, w);
	}
	else
	{
		wxString colName, colType;
		int w;

		size_t hdrIndex = 0;
		long col, nCols = thread->DataSet()->NumCols();

		for (col = 0 ; col < nCols ; col++)
		{
			colName = thread->DataSet()->ColName(col);
			colType = thread->DataSet()->ColFullType(col);
			colNames.Add(colName);
			colTypes.Add(colType);
			colTypClasses.Add(thread->DataSet()->ColTypClass(col));

			wxString colHeader = colName + wxT("\n") + colType;

			if (hdrIndex < colHeaders.GetCount() && colHeaders.Item(hdrIndex) == colHeader)
				w = colSizes.Item(hdrIndex++);
			else
				w = -1;

			SetColSize(col, w);
			if (thread->DataSet()->ColTypClass(col) == PGTYPCLASS_NUMERIC)
			{
				/*
				 * For numeric columns, set alignment to right.
				 */
				wxGridCellAttr *attr = new wxGridCellAttr();
				attr->SetAlignment(wxALIGN_RIGHT, wxALIGN_TOP);
				SetColAttr(col, attr);
			}
		}
	}
	Thaw();
}
示例#28
0
  std::vector<RingElem> BM_QQ(const SparsePolyRing& P, const ConstMatrixView& pts_in)
  {
    const long NumPts = NumRows(pts_in);
    const long dim = NumCols(pts_in);
    matrix pts = NewDenseMat(RingQQ(), NumPts, dim);
    for (long i=0; i < NumPts; ++i)
      for (long j=0; j < dim; ++j)
      {
        BigRat q;
        if (!IsRational(q, pts_in(i,j))) throw 999;
        SetEntry(pts,i,j, q);
      }

    // Ensure input pts have integer coords by using
    // scale factors for each indet.
    vector<BigInt> ScaleFactor(dim, BigInt(1));
    for (long j=0; j < dim; ++j)
      for (long i=0; i < NumPts; ++i)
        ScaleFactor[j] = lcm(ScaleFactor[j], ConvertTo<BigInt>(den(pts(i,j))));

    mpz_t **points = (mpz_t**)malloc(NumPts*sizeof(mpz_t*));
    for (long i=0; i < NumPts; ++i)
    {
      points[i] = (mpz_t*)malloc(dim*sizeof(mpz_t));
      for (long j=0; j < dim; ++j) mpz_init(points[i][j]);
      for (long j=0; j < dim; ++j)
      {
        mpz_set(points[i][j], mpzref(ConvertTo<BigInt>(ScaleFactor[j]*pts(i,j))));
      }
    }


    BMGB char0; // these will be "filled in" by BM_affine below
    BM modp;    //
            
    pp_cmp_PPM = &PPM(P); // not threadsafe!
    BM_affine(&char0, &modp, dim, NumPts, points, pp_cmp); // THIS CALL DOES THE REAL WORK!!!
    pp_cmp_PPM = NULL;
    for (long i=NumPts-1; i >=0 ; --i)
    {
      for (long j=0; j < dim; ++j) mpz_clear(points[i][j]);
      free(points[i]);
    }
    free(points);

    if (modp == NULL) { if (char0 != NULL) BMGB_dtor(char0); CoCoA_ERROR("Something went wrong", "BM_QQ"); }

    // Now extract the answer...
    const int GBsize = char0->GBsize;
    std::vector<RingElem> GB(GBsize);
    const long NumVars = dim;
    vector<long> expv(NumVars); // buffer for creating monomials
    for (int i=0; i < GBsize; ++i)
    {
      BigInt denom(1); // scale factor needed to make GB elem monic.
      for (int var = 0; var < NumVars; ++var)
      {
        expv[var] = modp->pp[modp->GB[i]][var];
        denom *= power(ScaleFactor[var], expv[var]);
      }
      RingElem GBelem = monomial(P, 1, expv);

      for (int j=0; j < NumPts; ++j)
      {
        if (mpq_sgn(char0->GB[i][j])==0) continue;
        BigRat c(char0->GB[i][j]);
        for (int var = 0; var < NumVars; ++var)
        {
          expv[var] = modp->pp[modp->sep[j]][var];
          c *= power(ScaleFactor[var], expv[var]);
        }
        GBelem += monomial(P, c/denom, expv);
      }
      GB[i] = GBelem;
    }
    BMGB_dtor(char0);
    BM_dtor(modp);
    return GB;
    // ignoring separators for the moment
  }
示例#29
0
文件: handler.cpp 项目: KDE/kdepim
void c4_HandlerSeq::Restructure(c4_Field &field_, bool remove_)
{
    //d4_assert(_field != 0);

    // all nested fields must be set up, before we shuffle them around
    for (int k = 0; k < NumHandlers(); ++k)
        if (IsNested(k)) {
            c4_Handler &h = NthHandler(k);
            for (int n = 0; n < NumRows(); ++n)
                if (h.HasSubview(n)) {
                    SubEntry(k, n);
                }
        }

    for (int i = 0; i < field_.NumSubFields(); ++i) {
        c4_Field &nf = field_.SubField(i);
        c4_Property prop(nf.Type(), nf.Name());

        int n = PropIndex(prop.GetId());
        if (n == i) {
            continue;
        }

        if (n < 0) {
            _handlers.InsertAt(i, f4_CreateFormat(prop,  *this));
            NthHandler(i).Define(NumRows(), 0);
        } else {
            // move the handler to the front
            d4_assert(n > i);
            _handlers.InsertAt(i, _handlers.GetAt(n));
            _handlers.RemoveAt(++n);
        }

        ClearCache(); // we mess with the order of handler, keep clearing it

        d4_assert(PropIndex(prop.GetId()) == i);
    }

    c4_Field *ofld = _field;
    // special case if we're "restructuring a view out of persistence", see below

    _field = remove_ ? 0 : &field_;

    // let handler do additional init once all have been prepared
    //for (int n = 0; n < NumHandlers(); ++n)
    //    NthHandler(n).Define(NumRows(), 0);

    const char *desc = "[]";
    c4_Field temp(desc);

    // all nested fields are restructured recursively
    for (int j = 0; j < NumHandlers(); ++j)
        if (IsNested(j)) {
            c4_Handler &h = NthHandler(j);
            for (int n = 0; n < NumRows(); ++n)
                if (h.HasSubview(n)) {
                    c4_HandlerSeq &seq = SubEntry(j, n);
                    if (j < NumFields()) {
                        seq.Restructure(field_.SubField(j), false);
                    } else if (seq._field != 0) {
                        seq.Restructure(temp, true);
                    }
                }
        }

    if (_parent == this) {
        delete ofld;
    }
    // the root table owns its field structure tree
}
void GenericFieldContainerEditor::updateProducedEventsPanel(FieldContainer* fc)
{
    _ProducedEventsContainer->clearChildren();

    UInt32 NumEvents(fc->getNumEvents());
    const EventDescription * Desc;
    LabelUnrecPtr TheLabel;
    ComponentRecPtr TheToolTip;
    GridBagLayoutConstraintsRefPtr LayoutConstraints;
    UInt32 NumRows(0);

    if(NumEvents != 0)
    {
        BorderLayoutRefPtr TheBorderLayout = BorderLayout::create();
        BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create();
        WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST);
        BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create();
        CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER);

        //Backgrounds
        ColorLayerRefPtr HeaderBgLayer = ColorLayer::create();
        HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f));

        ColorLayerRefPtr LightBgLayer = ColorLayer::create();
        LightBgLayer->setColor(Color4f(0.9f,0.9f,0.9f,1.0f));
        ColorLayerRefPtr DarkBgLayer = ColorLayer::create();
        DarkBgLayer->setColor(Color4f(0.8f,0.8f,0.8f,1.0f));

        LabelRecPtr EventsLabel = Label::create();
        EventsLabel->setAlignment(Vec2f(0.5f,0.5f));
        EventsLabel->setText("Events");
        EventsLabel->setBackgrounds(HeaderBgLayer);
        EventsLabel->setFont(_BoldFont);

        _ProducedEventsContainer->pushToChildren(EventsLabel);
        ++NumRows;

        for(UInt32 i(1) ; i<=NumEvents ; ++i)
        {
            Desc = fc->getProducerType().getEventDescription(i);
            if(Desc != NULL)
            {
                //Create the Label
                TheLabel = Label::create();
                TheLabel->setText(Desc->getCName());
                TheToolTip = createEventToolTip(Desc);
                TheLabel->setToolTip(TheToolTip);
                if((i%2) == 0)
                {
                    TheLabel->setBackgrounds(DarkBgLayer);
                }
                else
                {
                    TheLabel->setBackgrounds(LightBgLayer);
                }

                _ProducedEventsContainer->pushToChildren(TheLabel);
                ++NumRows;
            }
        }
    }

    //Set the number of rows for the grid layout
    dynamic_cast<GridLayout*>(_ProducedEventsContainer->getLayout())->setRows(NumRows);
    _ProducedEventsContainer->setPreferredSize(Vec2f(400.0f,
                                                     NumRows*24.0f
                                                     + _ProducedEventsContainer->getTopInset()));
}