Ejemplo n.º 1
0
QPixmap
IconLoader::loadPixmap(QString name)
{
    QColor bg = QApplication::palette().window().color();
    if (bg.red() + bg.green() + bg.blue() > 384) { // light background
        QPixmap pmap(QString(":icons/%1").arg(name));
        if (pmap.isNull()) {
            pmap = QPixmap(QString(":icons/%1.png").arg(name));
        }
        return pmap;
    }

    QPixmap pmap(QString(":icons/%1").arg(name));
    if (pmap.isNull()) {
        pmap = QPixmap(QString(":icons/%1_inverse.png").arg(name));
        if (pmap.isNull()) {
            pmap = QPixmap(QString(":icons/%1.png").arg(name));
        }
    }
    if (pmap.isNull()) return pmap;

    for (int i = 0; i < sizeof(autoInvertExceptions)/
                        sizeof(autoInvertExceptions[0]); ++i) {
        if (autoInvertExceptions[i] == name) {
            return pmap;
        }
    }

    // No suitable inverted icon found for black background; try to
    // auto-invert the default one

    QImage img = pmap.toImage().convertToFormat(QImage::Format_ARGB32);

    for (int y = 0; y < img.height(); ++y) {
        for (int x = 0; x < img.width(); ++x) {

            QRgb rgba = img.pixel(x, y);
            QColor colour = QColor
                (qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));

            int alpha = colour.alpha();
            if (colour.saturation() < 5 && colour.alpha() > 10) {
                colour.setHsv(colour.hue(),
                              colour.saturation(),
                              255 - colour.value());
                colour.setAlpha(alpha);
                img.setPixel(x, y, colour.rgba());
            }
        }
    }

    pmap = QPixmap::fromImage(img);
    return pmap;
}
Ejemplo n.º 2
0
QIcon
IconLoader::load(QString name)
{
    QPixmap pmap(loadPixmap(name));
    if (pmap.isNull()) return QIcon();
    else return QIcon(pmap);
}
Ejemplo n.º 3
0
int
Uconv(Fmt *fp)
{
    char str[STRINGSZ+1];
    char *s, *n;
    int i;

    str[0] = 0;
    s = va_arg(fp->args, char*);

    // strip package name
    n = strrchr(s, '.');
    if(n != nil)
        s = n + 1;

    if(s && *s) {
        if(upper)
            str[0] = toupper(*s);
        else
            str[0] = tolower(*s);
        for(i = 1; i < STRINGSZ && s[i] != 0; i++)
            str[i] = tolower(s[i]);
        str[i] = 0;
    }

    return fmtstrcpy(fp, pmap(str));
}
Ejemplo n.º 4
0
void ShowWidget::DisplayAnswer()
{
    Table t = this->table;

    QLayoutItem *child;
    while((child = gridlayout->takeAt(0)) != 0)
    {
        delete child->widget();
        delete child;
    }

    for(int i=0;i<t.n;i++)
        for(int j=0;j<t.n;j++)
        {
            QLabel *label = new QLabel();
            QPixmap pmap(":/new/prefix1/Back");
            QPainter painter1;
            QFont font1("Arial",13,QFont::Bold,false);
            QFont font2("Arial",9,QFont::Bold,false);
            painter1.begin(&pmap);
            if(t.n<10) painter1.setFont(font1);
            else painter1.setFont(font2);
            painter1.setPen(Qt::blue);
            painter1.drawText(3,3,20,20,Qt::AlignCenter,QString::number(t.data[i][j],10));//将数字转化成输出
            painter1.end();
            label->setPixmap(pmap);
            gridlayout->addWidget(label,i,j);
        }

    this->setWindowTitle(QString::number(t.n,10) + tr("阶魔方阵"));
    this->show();
}
Ejemplo n.º 5
0
  void
  Handler_A_Impl::configure (const ::Deployment::Properties &prop )
  {
    ::DAnCE::Utility::PROPERTY_MAP pmap (prop.length ());

    ::DAnCE::Utility::build_property_map (pmap,
                                          prop);
  }
Ejemplo n.º 6
0
void
ColourNameDialog::fillColourLabel()
{
    QPixmap pmap(20, 20);
    pmap.fill(m_darkBackground->isChecked() ? Qt::black : Qt::white);
    QPainter paint(&pmap);
    paint.setPen(m_colour);
    paint.setBrush(m_colour);
    paint.drawRect(2, 2, 15, 15);
    m_colourLabel->setPixmap(pmap);
}
Ejemplo n.º 7
0
QCursor KxQtHelper::createCursor(const QString &str)
{
    //expect format "cusorName:intHitX,intHixY"
    QStringList cursorElements = str.split(',');
    QString fileName = cursorElements[0];
    int hitX = cursorElements[1].toInt();
    int hitY = cursorElements[2].toInt();
    QPixmap pmap(":/" + fileName); // gets the image file out of the QT resource 
    QCursor cursor(pmap,hitX,hitY);
    return cursor;
}
Ejemplo n.º 8
0
// ######################################################################
void PrefrontalCortexOG::
onSimEventVisualCortexOutput(SimEventQueue& q, rutz::shared_ptr<SimEventVisualCortexOutput>& e)
{
  rutz::shared_ptr<ParamMap> pmap(new ParamMap());
  rutz::shared_ptr<SimReqVCXchanVis> ev(new SimReqOGtrain(this, itsTargetMask, itsDistractorMask, pmap,
                                                          itsFilename.getVal(), itsDoMax.getVal()));
  LINFO("Requesting training STSD data from VCX...");
  q.request(ev);

  // the resulting sT and sD values will be saved to our
  // filename in the form of a ParamMap.
}
Ejemplo n.º 9
0
QPixmap
IconLoader::loadPixmap(QString dir, QString name)
{
/*
    bool light = false;
    QColor bg = QApplication::palette().window().color();
    if (bg.red() + bg.green() + bg.blue() > 384) light = true;
*/    
    bool light = true; // do not invert any icons

    if (light) {
        QPixmap pmap(QString("%1/%2").arg(dir).arg(name));
        if (pmap.isNull()) {
            pmap = QPixmap(QString("%1/%2.png").arg(dir).arg(name));
        }
        if (pmap.isNull()) {
            pmap = QPixmap(QString("%1/%2.xpm").arg(dir).arg(name));
        }
        return pmap;
    }

    QPixmap pmap(QString("%1/%2").arg(dir).arg(name));
    if (pmap.isNull()) {
        pmap = QPixmap(QString("%1/%2_inverse.png").arg(dir).arg(name));
        if (pmap.isNull()) {
            pmap = QPixmap(QString("%1/%2.png").arg(dir).arg(name));
        }
        if (pmap.isNull()) {
            pmap = QPixmap(QString("%1/%2.xpm").arg(dir).arg(name));
        }
    }
    if (pmap.isNull()) return pmap;

    // No suitable inverted icon found for black background; try to
    // auto-invert the default one

    return invert(pmap);
}
Ejemplo n.º 10
0
/*
 * Add a device mapping to the vmap range.
 */
void*
vmap(uintptr pa, int size)
{
	uintptr va;
	int o;

	va = pa+VMAP;
	/*
	 * might be asking for less than a page.
	 */
	o = pa & (BY2PG-1);
	pa -= o;
	va -= o;
	size += o;
	pmap(m->pml4, pa | PTEUNCACHED|PTEWRITE|PTEVALID, va, size);
	return (void*)(va+o);
}
Ejemplo n.º 11
0
// ######################################################################
void NeoBrain::saveSpeechFile(const TokenMap& tokenMap,
                              const std::string& fname)
{
  rutz::shared_ptr<ParamMap> pmap(new ParamMap);

  int numTokenTypes = 0;
  for (TokenMap::const_iterator
         itr = tokenMap.begin(), stop = tokenMap.end();
       itr != stop; ++itr)
    {
      rutz::shared_ptr<ParamMap> submap(new ParamMap);

      submap->putStringParam("NAME", (*itr).first);

      int numTokens = 0;
      for (size_t j = 0; j < (*itr).second.tokens.size(); ++j)
        {
          rutz::shared_ptr<ParamMap> subsubmap(new ParamMap);

          subsubmap->putIntParam("LOW", (*itr).second.tokens[j].low);
          subsubmap->putIntParam("HIGH", (*itr).second.tokens[j].high);
          int numTextItems = 0;
          for (size_t i = 0; i < (*itr).second.tokens[j].textList.size(); ++i)
            {
              subsubmap->putStringParam(sformat("TEXT_ITEM_%d", numTextItems),
                                        (*itr).second.tokens[j].textList[i]);
              ++numTextItems;
            }
          subsubmap->putIntParam("NUM_TEXT_ITEMS", numTextItems);

          submap->putSubpmap(sformat("TOKEN_%d", numTokens), subsubmap);

          ++numTokens;
        }

      submap->putIntParam("NUM_TOKENS", numTokens);

      pmap->putSubpmap(sformat("TOKEN_TYPE_%d", numTokenTypes), submap);

      ++numTokenTypes;
    }
  pmap->putIntParam("NUM_TOKEN_TYPES", numTokenTypes);

  pmap->format(fname);
}
Ejemplo n.º 12
0
// std::string persistent test.
void StlAdvancedFeaturesExample::storing_std_strings()
{	
	string kstring = "hello world", *sstring = new string("hi there");
	if (explicit_txn)
		begin_txn(0, penv);

	db_map<string, string> pmap(dmstringdb, NULL);

	pmap[kstring] = *sstring + "!";
	*sstring = pmap[kstring];
	map<string, string> spmap;
	spmap.insert(make_pair(kstring, *sstring));
	cout<<"sstring append ! is : "<<pmap[kstring]
	    <<" ; *sstring is : "<<*sstring;
	delete sstring;
	for (db_map<string, string>::iterator ii = pmap.begin();
	    ii != pmap.end();
	    ++ii) {
		cout << (*ii).first << ": " << (*ii).second << endl;
	} 
	close_db(dmstringdb);
	
	dmstringdb = dbstl::open_db(penv, "db_map_stringdb.db", 
	    dbtype, DB_CREATE | dboflags, 0);
	db_map<string, string> pmap2(dmstringdb, NULL);
	for (db_map<string, string>::iterator ii = pmap2.begin();
	    ii != pmap2.end(); ++ii) {
		cout << (*ii).first << ": " << (*ii).second << endl;
		// assert key/data pair set equal
		check_expr((spmap.count(ii->first) == 1) && 
		    (spmap[ii->first] == ii->second));
	} 
	if (explicit_txn)
		commit_txn(penv);

	db_vector<string> strvctor(10);
	vector<string> sstrvctor(10);
	for (int i = 0; i < 10; i++) {
		strvctor[i] = "abc";
		sstrvctor[i] = strvctor[i];
	}
	check_expr(is_equal(strvctor, sstrvctor));
}
Ejemplo n.º 13
0
int mixture::discount(ngram ng_,int size,double& fstar,double& lambda,int /* unused parameter: cv */)
{

  ngram ng(dict);
  ng.trans(ng_);
	
  double lambda2,fstar2;
  fstar=0.0;
  lambda=0.0;
  int p=pmap(ng,size);
  assert(p <= pmax);
  double lsum=0;


  for (int i=0; i<numslm; i++) {
    sublm[i]->discount(ng,size,fstar2,lambda2,0);

    ngram ngslm(sublm[i]->dict);
    ngslm.trans(ng);

    if (dict->dub() > sublm[i]->dict->size()){
      if (*ngslm.wordp(1) == sublm[i]->dict->oovcode()) {
        fstar2/=(double)(sublm[i]->dict->dub() - sublm[i]->dict->size()+1);
      }
		}


    fstar+=(l[size][p][i]*fstar2);
    lambda+=(l[size][p][i]*lambda2);
    lsum+=l[size][p][i];
  }

  if (dict->dub() > dict->size())
    if (*ng.wordp(1) == dict->oovcode()) {
      fstar*=(double)(dict->dub() - dict->size()+1);
    }
	
  assert((lsum>LOWER_DOUBLE_PRECISION_OF_1) && (lsum<=UPPER_DOUBLE_PRECISION_OF_1));
  return 1;
}
Ejemplo n.º 14
0
/**************************************************************************
  Mark tile terrain as not placed.
**************************************************************************/
void map_unset_placed(struct tile *ptile)
{
  pmap(ptile) = FALSE;
}
Ejemplo n.º 15
0
/**************************************************************************
  Mark tile terrain as placed.
**************************************************************************/
void map_set_placed(struct tile *ptile)
{
  pmap(ptile) = TRUE;
}
Ejemplo n.º 16
0
/**************************************************************************
  Checks if land has not yet been placed on pmap at (x, y)
**************************************************************************/
bool not_placed(const struct tile *ptile)
{
  return !pmap(ptile);
}
Ejemplo n.º 17
0
int mixture::train()
{

  double zf;

  srand(1333);

  genpmap();

  if (dub()<dict->size()) {
		std::stringstream ss_msg;
    ss_msg << "\nERROR: DUB value is too small: the LM will possibly compute wrong probabilities if sub-LMs have different vocabularies!\n";
		ss_msg << "This exception should already have been handled before!!!\n";
		exit_error(IRSTLM_ERROR_MODEL, ss_msg.str());
  }

  cerr << "mixlm --> DUB: " << dub() << endl;
  for (int i=0; i<numslm; i++) {
    cerr << i << " sublm --> DUB: " << sublm[i]->dub()  << endl;
    cerr << "eventually generate OOV code ";
    cerr << sublm[i]->dict->encode(sublm[i]->dict->OOV()) << "\n";
    sublm[i]->train();
  }

  //initialize parameters

  for (int i=0; i<=lmsize(); i++) {
    l[i]=new double*[pmax];
    for (int j=0; j<pmax; j++) {
      l[i][j]=new double[numslm];
      for (int k=0; k<numslm; k++)
        l[i][j][k]=1.0/(double)numslm;
    }
  }

  if (ipfname) {
    //load parameters from file
    loadpar(ipfname);
  } else {
    //start training of mixture model

    double oldl[pmax][numslm];
    char alive[pmax],used[pmax];
    int totalive;

    ngram ng(sublm[0]->dict);

    for (int lev=1; lev<=lmsize(); lev++) {

      zf=sublm[0]->zerofreq(lev);

      cerr << "Starting training at lev:" << lev << "\n";

      for (int i=0; i<pmax; i++) {
        alive[i]=1;
        used[i]=0;
      }
      totalive=1;
      int iter=0;
      while (totalive && (iter < 20) ) {

        iter++;

        for (int i=0; i<pmax; i++)
          if (alive[i])
            for (int j=0; j<numslm; j++) {
              oldl[i][j]=l[lev][i][j];
              l[lev][i][j]=1.0/(double)numslm;
            }

        sublm[0]->scan(ng,INIT,lev);
        while(sublm[0]->scan(ng,CONT,lev)) {

          //do not include oov for unigrams
          if ((lev==1) && (*ng.wordp(1)==sublm[0]->dict->oovcode()))
            continue;

          int par=pmap(ng,lev);
          used[par]=1;

          //controllo se aggiornare il parametro
          if (alive[par]) {

            double backoff=(lev>1?prob(ng,lev-1):1); //backoff
            double denom=0.0;
            double* numer = new double[numslm];
						double fstar,lambda;

            //int cv=(int)floor(zf * (double)ng.freq + rand01());
            //int cv=1; //old version of leaving-one-out
            int cv=(int)floor(zf * (double)ng.freq)+1;
            //int cv=1; //old version of leaving-one-out
            //if (lev==3)q

            //if (iter>10)
            // cout << ng
            // << " backoff " << backoff
            // << " level " << lev
            // << "\n";

            for (int i=0; i<numslm; i++) {

              //use cv if i=0

              sublm[i]->discount(ng,lev,fstar,lambda,(i==0)*(cv));
              numer[i]=oldl[par][i]*(fstar + lambda * backoff);

              ngram ngslm(sublm[i]->dict);
              ngslm.trans(ng);
              if ((*ngslm.wordp(1)==sublm[i]->dict->oovcode()) &&
                  (dict->dub() > sublm[i]->dict->size()))
                numer[i]/=(double)(dict->dub() - sublm[i]->dict->size());

              denom+=numer[i];
            }

            for (int i=0; i<numslm; i++) {
              l[lev][par][i]+=(ng.freq * (numer[i]/denom));
              //if (iter>10)
              //cout << ng << " l: " << l[lev][par][i] << "\n";
            }
						delete []numer;
          }
        }

        //normalize all parameters
        totalive=0;
        for (int i=0; i<pmax; i++) {
          double tot=0;
          if (alive[i]) {
            for (int j=0; j<numslm; j++) tot+=(l[lev][i][j]);
            for (int j=0; j<numslm; j++) l[lev][i][j]/=tot;

            //decide if to continue to update
            if (!used[i] || (reldist(l[lev][i],oldl[i],numslm)<=0.05))
              alive[i]=0;
          }
          totalive+=alive[i];
        }

        cerr << "Lev " << lev << " iter " << iter << " tot alive " << totalive << "\n";

      }
    }
  }

  if (opfname) savepar(opfname);


  return 1;
}
Ejemplo n.º 18
0
void tensor_contract_444(TA::DistArray<Tile, Policy>& tv,
                         const TA::DistArray<Tile, Policy>& t,
                         const TA::DistArray<Tile, Policy>& v) {

  // for convenience, obtain the tiled ranges for the two kinds of dimensions used to define t, v, and tv
  auto trange_occ = t.trange().dim(0);  // the first dimension of t is occ
  auto trange_uocc = v.trange().dim(0); // every dimension of v is uocc
  auto ntiles_occ = trange_occ.tile_extent();
  auto ntiles_uocc = trange_uocc.tile_extent();
  auto n_occ = trange_occ.extent();
  auto n_uocc = trange_occ.extent();

  // compute the 2-d grid of processors for the SUMMA
  // note that the result is (occ occ|uocc uocc), hence the row dimension is occ x occ, etc.
  auto& world = t.world();
  auto nrowtiles = ntiles_occ * ntiles_occ;
  auto ncoltiles = ntiles_uocc * ntiles_uocc;
  auto ninttiles = ntiles_uocc * ntiles_uocc; // contraction is over uocc x uocc
  auto nrows = n_occ * n_occ;
  auto ncols = n_uocc * n_uocc;
  TA::detail::ProcGrid proc_grid(world,
                                 nrowtiles, ncoltiles,
                                 nrows, ncols);
  std::shared_ptr<TA::Pmap> pmap;
  auto t_eval = make_array_eval(t, t.world(), TA::DenseShape(),
      proc_grid.make_row_phase_pmap(ninttiles),
      TA::Permutation(), make_array_noop<Tile>());
  auto v_eval = make_array_eval(v, v.world(), TA::DenseShape(),
      proc_grid.make_col_phase_pmap(ninttiles),
      TA::Permutation(), make_array_noop<Tile>());

  //
  // make the result metadata
  //

  // result shape
  TA::TiledRange trange_tv({trange_occ, trange_occ, trange_uocc, trange_uocc});
  //
  pmap.reset(new TA::detail::BlockedPmap(world, trange_tv.tiles_range().volume()));
  // 'contract' object is of type
  // PaRSEC's PTG object will do the job here:
  // 1. it will use t_eval and v_eval's Futures as input
  // 2. there will be a dummy output ArrayEval, its Futures will be set by the PTG
  auto contract = make_contract_eval(
      t_eval, v_eval, world, TA::DenseShape(), pmap, TA::Permutation(),
      make_contract<Tile>(4u, 4u, 4u)
      );

  // eval() just schedules the Summa task and proceeds
  // in expressions evaluation is lazy ... you could just use contract tiles
  // immediately to compose further (in principle even before eval()!)
  contract.eval();

  // since the intent of this function is to return result as a named DistArray
  // migrate contract's futures to tv here

  // Create a temporary result array
  TA::DistArray<Tile,Policy> result(contract.world(), contract.trange(),
           contract.shape(), contract.pmap());

  // Move the data from dist_eval into the result array. There is no
  // communication in this step.
  for(const auto index : *contract.pmap()) {
    if(! contract.is_zero(index))
      result.set(index, contract.get(index));
  }

  // uncomment this to block until Summa is complete .. but no need to wait
  //contract.wait();

  // Swap the new array with the result array object.
  result.swap(tv);

}