コード例 #1
0
ファイル: diis.cpp プロジェクト: Monkey---Brainz/erkale
void rDIIS::update(const arma::mat & F, const arma::mat & P, double E, double & error) {
  // New entry
  diis_unpol_entry_t hlp;
  hlp.F=F;
  hlp.P=P;
  hlp.E=E;

  // Compute error matrix
  arma::mat errmat=F*P*S-S*P*F;
  // and transform it to the orthonormal basis (1982 paper, page 557)
  errmat=arma::trans(Sinvh)*errmat*Sinvh;
  // and store it
  hlp.err=MatToVec(errmat);

  // DIIS error is
  error=max_abs(errmat);

  // Is stack full?
  if(stack.size()==imax) {
    erase_last();
  }
  // Add to stack
  stack.push_back(hlp);

  // Update ADIIS helpers
  PiF_update();
}
コード例 #2
0
ファイル: lru_cache.hpp プロジェクト: bagobor/psychopath
	/*
	 * Adds the given item to the cache and opens it.
	 * Returns the key.
	 */
	LRUKey add_open(T *data_ptr) {
		std::unique_lock<SpinLock> lock(slock);

		typename std::list<LRUPair<T>>::iterator it;
		LRUPair<T> data_pair;

		LRUKey key;
		do {
			key = next_key++;
		} while ((bool)(map.count(key)) || key == 0);

		byte_count += data_ptr->bytes();

		// Remove last element(s) if necessary to make room
		while (byte_count >= max_bytes) {
			if (!erase_last())
				break;
		}

		// Add the new data
		data_pair.key = key;
		data_pair.data_ptr = data_ptr;
		data_pair.active_readers = 1;
		it = elements.begin();
		it = elements.insert(it, data_pair);

		// Log it in the map
		map[key] = it;

		return key;
	}
コード例 #3
0
ファイル: diis.cpp プロジェクト: Monkey---Brainz/erkale
void uDIIS::update(const arma::mat & Fa, const arma::mat & Fb, const arma::mat & Pa, const arma::mat & Pb, double E, double & error) {
  // New entry
  diis_pol_entry_t hlp;
  hlp.Fa=Fa;
  hlp.Fb=Fb;
  hlp.Pa=Pa;
  hlp.Pb=Pb;
  hlp.E=E;

  // Compute error matrices
  arma::mat errmata=Fa*Pa*S-S*Pa*Fa;
  arma::mat errmatb=Fb*Pb*S-S*Pb*Fb;
  // and transform them to the orthonormal basis (1982 paper, page 557)
  arma::mat errmat=arma::trans(Sinvh)*(errmata+errmatb)*Sinvh;
  // and store it
  hlp.err=MatToVec(errmat);

  // DIIS error is
  error=max_abs(errmat);

  // Is stack full?
  if(stack.size()==imax) {
    erase_last();
  }
  // Add to stack
  stack.push_back(hlp);

  // Update ADIIS helpers
  PiF_update();
}
コード例 #4
0
ファイル: version_1.cpp プロジェクト: YinWenAtBIT/LeetCode
 void set(int key, int value) {
     if(dic.find(key) != dic.end())
     {
         dic[key] = value;
         set_front(key);
     }
     else
     {
         dic[key] = value;
         lru.push_front(key);
         erase_last();
     }
 }