コード例 #1
3
ファイル: bfgs_update_test.cpp プロジェクト: actuariat/stan
TEST(OptimizationBfgsUpdate, bfgs_update_secant) {
  typedef stan::optimization::BFGSUpdate_HInv<> QNUpdateT;
  typedef QNUpdateT::VectorT VectorT;

  const unsigned int nDim = 10;
  QNUpdateT bfgsUp;
  VectorT yk(nDim), sk(nDim), sdir(nDim);

  // Construct a set of BFGS update vectors and check that
  // the secant equation H*yk = sk is always satisfied.
  for (unsigned int i = 0; i < nDim; i++) {
    sk.setZero(nDim);
    yk.setZero(nDim);
    sk[i] = 1;
    yk[i] = 1;

    bfgsUp.update(yk,sk,i==0);

    // Because the constructed update vectors are all orthogonal the secant
    // equation should be exactlty satisfied for all nDim updates.
    for (unsigned int j = 0; j <= i; j++) {
      sk.setZero(nDim);
      yk.setZero(nDim);
      sk[i - j] = 1;
      yk[i - j] = 1;

      bfgsUp.search_direction(sdir,yk);
      
      EXPECT_NEAR((sdir + sk).norm(),0.0,1e-10);
    }
  }
}
コード例 #2
0
ファイル: ReservoirMethod.cpp プロジェクト: SmileEric/SEIMS
// set value
void ReservoirMethod::SetValue(const char* key, float value)
{
	string sk(key);
	if (StringMatch(sk,"TimeStep"))
		m_TimeStep = int(value);
	else if (StringMatch(sk, "ThreadNum"))
		omp_set_num_threads((int)value);
	else if (StringMatch(sk,"CellSize"))
		m_nCells = int(value);
	else if (StringMatch(sk,"CellWidth"))
		m_CellWidth = int(value);
	else if (StringMatch(sk,"Kg"))
		m_Kg = value;
	else if (StringMatch(sk,"Base_ex"))
		m_Base_ex = value;
	else if (StringMatch(sk,"df_coef"))
		m_dp_co = value;
	else if (StringMatch(sk,"GW0"))
		m_GW0 = value;
	else if (StringMatch(sk,"GWMAX"))
		m_GWMAX = value;
	//else if(StringMatch(sk, "UpperSoilDepth"))		
	//	m_upSoilDepth = value;
	else
		throw ModelException("GWA_RE","SetValue","Parameter " + sk + " does not exist in GWA_RE module. Please contact the module developer.");
	
}
コード例 #3
0
RegionDesc::Block::Block(const Func* func,
                         bool        resumed,
                         Offset      start,
                         int         length,
                         FPInvOffset initSpOff,
                         uint16_t    inlineLevel)
  : m_id(s_nextId--)
  , m_func(func)
  , m_resumed(resumed)
  , m_start(start)
  , m_last(kInvalidOffset)
  , m_length(length)
  , m_initialSpOffset(initSpOff)
  , m_inlinedCallee(nullptr)
  , m_inlineLevel(inlineLevel)
{
  assertx(length >= 0);
  if (length > 0) {
    SrcKey sk(func, start, resumed);
    for (unsigned i = 1; i < length; ++i) sk.advance();
    m_last = sk.offset();
  }
  checkInstructions();
  checkMetadata();
}
コード例 #4
0
ファイル: PlayerManager.cpp プロジェクト: citic/botNeumann
void PlayerManager::saveLastPlayer()
{
	QSettings settings;
	const QByteArray& playerId = currentPlayer ? currentPlayer->getId() : QByteArray();
	settings.setValue(sk("Players/LastPlayer"), QVariant(playerId));
	if ( currentPlayer) currentPlayer->save();
}
コード例 #5
0
ファイル: ReservoirMethod.cpp プロジェクト: gaohr/SEIMS
void ReservoirMethod::Set1DData(const char *key, int n, float *data)
{
    string sk(key);
    if (StringMatch(sk, VAR_GWNEW))
    {
        m_VgroundwaterFromBankStorage = data;
		return;
    }

    //check the input data
    if (!CheckInputSize(key, n)) return;

    //set the value
    if (StringMatch(sk, VAR_INET))
        m_D_EI = data;
    else if (StringMatch(sk, VAR_DEET))
        m_D_ED = data;
    else if (StringMatch(sk, VAR_SOET))
        m_D_ES = data;
	else if (StringMatch(sk, VAR_AET_PLT))
		m_plantEP = data;
    else if (StringMatch(sk, VAR_PET))
        m_D_PET = data;
    else if (StringMatch(sk, VAR_SLOPE))
        m_Slope = data;
	else if (StringMatch(sk, VAR_SOILLAYERS))
		m_soilLayers = data;
    else
        throw ModelException(MID_GWA_RE, "Set1DData", "Parameter " + sk + " does not exist in current module.");
}
コード例 #6
0
ファイル: DepressionFSDaily.cpp プロジェクト: crazyzlj/SEIMS
void DepressionFSDaily::SetValue(const char* key, const float value) {
    string sk(key);
    if (StringMatch(sk, VAR_DEPREIN)) m_depCo = value;
    else {
        throw ModelException(MID_DEP_LINSLEY, "SetValue", "Parameter " + sk + " does not exist.");
    }
}
コード例 #7
0
ファイル: zsets.cpp プロジェクト: ericcapricorn/ardb
	int Ardb::ZClear(const DBID& db, const Slice& key)
	{
		KeyLockerGuard keyguard(m_key_locker, db, key);
		ZSetMetaValue meta;
		if (0 != GetZSetMetaValue(db, key, meta))
		{
			return 0;
		}
		Slice empty;
		ZSetKeyObject sk(key, empty, meta.min_score, db);

		BatchWriteGuard guard(GetEngine());
		struct ZClearWalk: public WalkHandler
		{
				Ardb* z_db;
				int OnKeyValue(KeyObject* k, ValueObject* value, uint32 cursor)
				{
					ZSetKeyObject* sek = (ZSetKeyObject*) k;
					ZSetScoreKeyObject tmp(sek->key, sek->value, sek->db);
					z_db->DelValue(*sek);
					z_db->DelValue(tmp);
					return 0;
				}
				ZClearWalk(Ardb* db) :
						z_db(db)
				{
				}
		} walk(this);
		Walk(sk, false, &walk);
		KeyObject k(key, ZSET_META, db);
		DelValue(k);
		return 0;
	}
コード例 #8
0
ファイル: ReservoirMethod.cpp プロジェクト: SmileEric/SEIMS
void ReservoirMethod::Get1DData(const char* key, int* nRows, float **data)
{
	string sk(key);
	if (StringMatch(sk,"Revap"))
	{
		*data = m_D_Revap;
		*nRows = m_nCells;
	}
	else if (StringMatch(sk,"RG"))
	{
		*data = m_T_RG;
		*nRows = m_subbasinList.size()+1;
	}
	else if (StringMatch(sk,"SBQG"))
	{
		*data = m_T_QG;
		*nRows = m_subbasinList.size()+1;
	}
	else if (StringMatch(sk,"SBGS"))
	{
		*data = m_gwStore;
		*nRows = m_subbasinList.size()+1;
	}
	else if (StringMatch(sk,"SBPET"))
	{
		*data = m_petSubbasin;
		*nRows = m_subbasinList.size()+1;
	}
	else
	{
		throw ModelException("GWA_RE","getResults","Parameter " + sk + " does not exist in GWA_RE module. Please contact the module developer.");
	}
}
コード例 #9
0
ファイル: ReservoirMethod.cpp プロジェクト: gaohr/SEIMS
void ReservoirMethod::Get1DData(const char *key, int *nRows, float **data)
{
	initialOutputs();
    string sk(key);
    if (StringMatch(sk, VAR_REVAP))
    {
        *data = m_D_Revap;
        *nRows = m_nCells;
    }
    else if (StringMatch(sk, VAR_RG))
    {
        *data = m_T_RG;
        *nRows = m_nSubbasins + 1;
    }
    else if (StringMatch(sk, VAR_SBQG))
    {
        *data = m_T_QG;
        *nRows = m_nSubbasins + 1;
    }
    else if (StringMatch(sk, VAR_SBGS))
    {
        *data = m_gwStore;
        *nRows = m_nSubbasins + 1;
    }
    else if (StringMatch(sk, VAR_SBPET))
    {
        *data = m_petSubbasin;
        *nRows = m_nSubbasins + 1;
    }
    else
        throw ModelException(MID_GWA_RE, "Get1DData", "Parameter " + sk + " does not exist.");
}
コード例 #10
0
int main(int argc, char *argv[]) {
    long m, p, r, L, R;
    ArgMapping argmap;
	MDL::Timer timer;
    argmap.arg("m", m, "m");
    argmap.arg("L", L, "L");
    argmap.arg("p", p, "p");
    argmap.arg("r", r, "r");
    argmap.arg("R", R, "R");
    argmap.parse(argc, argv);
	timer.start();
    FHEcontext context(m, p, r);
    buildModChain(context, L);
    FHESecKey sk(context);
    sk.GenSecKey(64);
    addSome1DMatrices(sk);
    FHEPubKey pk = sk;

    auto G       = context.alMod.getFactorsOverZZ()[0];
    EncryptedArray ea(context, G);
	timer.end();
    printf("slots %ld\n", ea.size());
	printf("Key Gen %f\n", timer.second());
    auto data = load_csv("adult.data", R);
    benchmark(ea, pk, sk, data);
}
コード例 #11
0
ファイル: main.cpp プロジェクト: CCJY/coliru
 // update performs the heart of an iteration:
 // It walks the border path from the active point to the end point
 // and adds the required Transitions brought by the insertion of
 // the string's i-th character.
 //
 // It returns the end point.
 ReferencePoint update(Node *s, MappedSubstring ki) {
     Node *oldr = &tree.root;
     Node *r = nullptr;
     bool is_endpoint = false;
     MappedSubstring ki1 = ki;
     auto ref_str_it = haystack.find(ki.ref_str);
     S w = ref_str_it->second;
     ReferencePoint sk(s, std::pair<int,int>(ki.ref_str, ki.l));
     ki1.r = ki.r-1;
     is_endpoint = test_and_split(s, ki1, w[ki.r], w, &r);
     while (!is_endpoint) {
         Leaf *r_prime = new Leaf();
         r->g.insert(std::pair<C,Transition>(
           w[ki.r], Transition(MappedSubstring(
           ki.ref_str, ki.r, std::numeric_limits<int>::max()), r_prime)));
         if (&tree.root != oldr) {
             oldr->suffix_link = r;
         }
         oldr = r;
         sk = canonize(sk.first->suffix_link, ki1);
         ki1.l = ki.l = sk.second.second;
         is_endpoint = test_and_split(sk.first, ki1, w[ki.r], w, &r); 
     }
     if (&tree.root != oldr) {
         oldr->suffix_link = sk.first;
     }
     return sk;
 }
コード例 #12
0
ファイル: GameMenuScene.cpp プロジェクト: citic/botNeumann
GameMenuScene::GameMenuScene(Stage* stage, QGraphicsItem* parent)
	: Scene(mapSceneName(sceneGameMenu), stage, parent)
{
	setBackground("gm_background");

	LinearLayout* leftLayout = new LinearLayout(Qt::Vertical);
	Actor* gameTitle = new Actor("ge_game_title", this);
	gameTitle->setPaddings(0.1);
	leftLayout->addItem(gameTitle, 0.2);

	LinearLayout* centralLayout = new LinearLayout(Qt::Horizontal);
	leftLayout->addLayout(centralLayout, 0.8);
	Actor* robot = new Actor("ge_robot", this);
	robot->setPaddings(0.2);
	centralLayout->addItem(robot, 0.5);
	robot->alignCenter();
	centralLayout->addStretch(0.5);

	LinearLayout* rightLayout = new LinearLayout(Qt::Vertical);
	setupButtons(rightLayout);

	LinearLayout* globalLayout = new LinearLayout(Qt::Horizontal);
	globalLayout->addLayout(leftLayout, 0.7);
	globalLayout->addLayout(rightLayout, 0.3);
	setLayout(globalLayout);

	// This is the last scene loaded
	QSettings settings;
	settings.setValue( sk("Application/LastScene"), sceneName );
}
コード例 #13
0
ファイル: listbox.cpp プロジェクト: gitrider/wxsj2
int wxListBox::DoAppend(const wxString& item)
{
    wxSizeKeeper sk( this );
    Widget listBox = (Widget) m_mainWidget;

    bool managed = XtIsManaged(listBox);

    if (managed)
        XtUnmanageChild (listBox);
    int n;
    XtVaGetValues (listBox, XmNitemCount, &n, NULL);
    wxXmString text( item );
    //  XmListAddItem(listBox, text, n + 1);
    XmListAddItemUnselected (listBox, text(), 0);

    // It seems that if the list is cleared, we must re-ask for
    // selection policy!!
    SetSelectionPolicy();

    if (managed)
        XtManageChild (listBox);

    sk.Restore();
    m_noItems ++;

    return GetCount() - 1;
}
コード例 #14
0
ファイル: SUR_GA.cpp プロジェクト: Shenfang1993/SEIMS
void SUR_GA::SetValue(const char *key, float value)
{
    string sk(key);

    if (StringMatch(sk, "ThreadNum"))
    {
        omp_set_num_threads((int) value);
    }
    else if (StringMatch(sk, "TimeStep"))
    {
        m_TimeStep = value * 60; //hour -> mimute
    }
    else if (StringMatch(sk, "T_snow"))
    {
        m_Tsnow = value;
    }
    else if (StringMatch(sk, "t_soil"))
    {
        m_Tsoil = value;
    }
    else if (StringMatch(sk, "T0"))
    {
        m_T0 = value;
    }
    else if (StringMatch(sk, "s_frozen"))
    {
        this->m_Sfrozen = value;
    }
    else
        throw ModelException("SUR_GA", "SetValue", "Parameter " + sk
                                                   +
                                                   " does not exist in SUR_GA method. Please contact the module developer.");

}
コード例 #15
0
void DepressionFSDaily::SetValue(const char *key, float data)
{
    string sk(key);
    if (StringMatch(sk, VAR_DEPREIN)) m_depCo = data;
    else if (StringMatch(sk, VAR_OMP_THREADNUM))omp_set_num_threads((int) data); 
    else
        throw ModelException(MID_DEP_LINSLEY, "SetValue", "Parameter " + sk + " does not exist.");
}
コード例 #16
0
ファイル: statbox.cpp プロジェクト: beanhome/dev
void wxStaticBox::SetLabel( const wxString& label )
{
    wxXmSizeKeeper sk( (Widget)GetMainWidget() );

    wxStaticBoxBase::SetLabel( label );

    sk.Restore();
}
コード例 #17
0
ファイル: IUH_OL.cpp プロジェクト: crazyzlj/SEIMS
void IUH_OL::Set1DData(const char* key, const int n, float* data) {
    CheckInputSize(key, n);
    string sk(key);
    if (StringMatch(sk, VAR_SUBBSN)) m_subbsnID = data;
    else if (StringMatch(sk, VAR_SURU)) m_surfRf = data;
    else {
        throw ModelException(MID_IUH_OL, "Set1DData", "Parameter " + sk + " does not exist.");
    }
}
コード例 #18
0
ファイル: MainWindow.cpp プロジェクト: citic/botNeumann
void MainWindow::resetSettings()
{
	const QString& text = tr("Do you want to reset the configuration. All players' progress will be deleted");
	if ( QMessageBox::question(this, tr("Settings reset?"), text, QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes )
	{
		QSettings().setValue(sk("Application/SettingsReset"), true);
		QMessageBox::warning(this, tr("Settings reset"), tr("Please restart botNeumann++ for the changes to take effect"));
	}
}
コード例 #19
0
ファイル: IUH_OL.cpp プロジェクト: crazyzlj/SEIMS
void IUH_OL::GetValue(const char* key, float* value) {
    InitialOutputs();
    string sk(key);
    if (StringMatch(sk, VAR_SBOF) && m_inputSubbsnID > 0) {
        /// For MPI version to transfer data across subbasins
        *value = m_Q_SBOF[m_inputSubbsnID];
    } else {
        throw ModelException(MID_IUH_OL, "GetValue", "Result " + sk + " does not exist.");
    }
}
コード例 #20
0
ファイル: PER_PI.cpp プロジェクト: fannq/SEIMS
void PER_PI::Get2DData(const char* key, int *nRows, int *nCols, float*** data)
{
	string sk(key);
	*nRows = m_nCells;
	*nCols = m_nSoilLayers;
	if (StringMatch(sk, VAR_PERCO))   *data = m_perc;
	else
		throw ModelException(MID_PER_PI, "Get2DData", "Output " + sk 
		+ " does not exist. Please contact the module developer.");
}
コード例 #21
0
ファイル: IUH_OL.cpp プロジェクト: crazyzlj/SEIMS
void IUH_OL::Set2DData(const char* key, const int nRows, const int nCols, float** data) {
    string sk(key);
    if (StringMatch(sk, VAR_OL_IUH)) {
        CheckInputSize(VAR_OL_IUH, nRows);
        m_iuhCell = data;
        m_iuhCols = nCols;
    } else {
        throw ModelException(MID_IUH_OL, "Set2DData", "Parameter " + sk + " does not exist.");
    }
}
コード例 #22
0
ファイル: IUH_OL.cpp プロジェクト: crazyzlj/SEIMS
void IUH_OL::SetValue(const char* key, const float value) {
    string sk(key);
    if (StringMatch(sk, Tag_TimeStep)) m_TimeStep = CVT_INT(value);
    else if (StringMatch(sk, Tag_CellSize)) m_nCells = CVT_INT(value);
    else if (StringMatch(sk, Tag_CellWidth)) m_CellWth = value;
    else if (StringMatch(sk, VAR_SUBBSNID_NUM)) m_nSubbsns = CVT_INT(value);
    else if (StringMatch(sk, Tag_SubbasinId)) m_inputSubbsnID = CVT_INT(value);
    else {
        throw ModelException(MID_IUH_OL, "SetValue", "Parameter " + sk + " does not exist.");
    }
}
コード例 #23
0
ファイル: async_functions.cpp プロジェクト: m2osw/turnwatcher
FILE *open_output(const char *filename, long len, const char *ext)
{
	FILE	*f;
	size_t	l, o;
	char	buf[256];

	l = strlen(ext);
	o = strlen(g_output);	// already include '/' at the end
	//
	char *name = new char[o + len + l + 1];
	str_keeper sk( name );
	memcpy(name, g_output, o);
	memcpy(name + o, filename, len);
	memcpy(name + o + len, ext, l);
	name[o + len + l] = '\0';
	if(!g_force) {
		f = fopen(name, "rb");
		if(f != 0) {
			// the file already exists, let's make sure we're not
			// overwriting some random user file
			l = fread(buf, 1, sizeof(g_auto_generated) - 1, f);
			fclose(f);
			if(l != sizeof(g_auto_generated) - 1
			|| memcmp(buf, g_auto_generated, sizeof(g_auto_generated) - 1) != 0) {
				fprintf(stderr, "%s:1: error: cannot overwrite file; it does not look like an auto-generated file\n", name);
				g_errcnt++;
				return 0;
			}
		}
	}

	f = fopen(name, "wb");
	if(f == 0) {
		fprintf(stderr, "%s:0: error: cannot open file\n", name);
		g_errcnt++;
	}
	else {
		// always write that at the very beginning
		l = fprintf(f, "%s\n", g_auto_generated);
		// TODO: working under Mingw?! fprintf() does not return count, right?
		if(l < sizeof(g_auto_generated)) {
			fclose(f);
			remove(name);
			fprintf(stderr, "%s:1: error: cannot write into output file\n", name);
			g_errcnt++;
			f = 0;
		}
		else {
			fflush(f);
		}
	}

	return f;
}
コード例 #24
0
ファイル: test_network.cpp プロジェクト: fionser/MDLHELib
void act_client(int socket) {
    FHEcontext context(gM, gP, gR);
    buildModChain(context, gL);
    FHESecKey sk(context);
    sk.GenSecKey(64);
    FHEPubKey &pk = sk;
    send_pk(socket, pk);

    std::vector<Ctxt> ctxts;
    receive_ctxt(socket, pk, ctxts);
    nn_close(socket);
}
コード例 #25
0
ファイル: ReservoirMethod.cpp プロジェクト: SmileEric/SEIMS
void ReservoirMethod::Set1DData(const char* key, int n, float *data)
{
	string sk(key);

	//if (StringMatch(sk,"subbasinSelected"))
	//{
	//	m_subbasinSelected = data;
	//	m_subbasinSelectedCount = n;
	//}

	if (StringMatch(sk,"T_GWNEW"))
	{
		m_VgroundwaterFromBankStorage = data;
	}

	//check the input data
	if (!CheckInputSize(key,n)) return;

	//set the value	
	if (StringMatch(sk,"D_INET"))
	{
		m_D_EI = data;
	}
	else if (StringMatch(sk, "D_DEET"))
	{
		m_D_ED = data;
	}
	else if (StringMatch(sk, "D_SOET"))
	{
		m_D_ES = data;
	}
	else if (StringMatch(sk, "D_PET"))
	{
		m_D_PET = data;
	}
	else if (StringMatch(sk,"Subbasin"))
	{
		m_subbasin = data;
	}
	else if (StringMatch(sk,"Slope"))
	{
		m_Slope = data;
	}	
	else if (StringMatch(sk,"Rootdepth"))
	{
		m_rootDepth = data;
	}	
	else
	{
		throw ModelException("GWA_RE","Set1DData","Parameter " + sk + " does not exist in GWA_RE module. Please contact the module developer.");
	}
}
コード例 #26
0
ファイル: ReservoirMethod.cpp プロジェクト: gaohr/SEIMS
void ReservoirMethod::Get2DData(const char *key, int *nRows, int *nCols, float ***data)
{
	initialOutputs();
    string sk(key);
	if (StringMatch(sk, VAR_GWWB))
	{
		*data = m_T_GWWB;
		*nRows = m_nSubbasins + 1;
		*nCols = 6;
	}
    else
        throw ModelException(MID_GWA_RE, "Get2DData", "Parameter " + sk + " does not exist in current module.");
}
コード例 #27
0
ファイル: IUH_OL.cpp プロジェクト: crazyzlj/SEIMS
void IUH_OL::Get1DData(const char* key, int* n, float** data) {
    InitialOutputs();
    string sk(key);
    if (StringMatch(sk, VAR_SBOF)) {
        *data = m_Q_SBOF;
        *n = m_nSubbsns + 1;
    } else if (StringMatch(sk, VAR_OLFLOW)) {
        *data = m_OL_Flow;
        *n = m_nCells;
    } else {
        throw ModelException(MID_IUH_OL, "Get1DData", "Result " + sk + " does not exist.");
    }
}
コード例 #28
0
ファイル: ReservoirMethod.cpp プロジェクト: SmileEric/SEIMS
void ReservoirMethod::Set2DData(const char* key, int nrows, int ncols, float** data)
{
	string sk(key);
	CheckInputSize(key, nrows);
	m_nSoilLayers = ncols;

	if (StringMatch(sk,"D_Percolation_2D"))
		m_perc = data;
	else if(StringMatch(sk, "D_SOMO_2D"))		
		m_soilMoisture = data;
	else
		throw ModelException("PER_PI", "Set2DData", 
		    "Parameter " + sk + " does not exist. Please contact the module developer.");
}
コード例 #29
0
ファイル: ReservoirMethod.cpp プロジェクト: SmileEric/SEIMS
void ReservoirMethod::Get2DData(const char* key, int* nRows, int* nCols, float ***data)
{
	string sk(key);
	if (StringMatch(sk,"GWWB"))
	{
		*data = m_T_GWWB;
		*nRows = m_subbasinSelectedCount;
		*nCols = 6;
	}
	else
	{
		throw ModelException("GWA_RE","getResults","Parameter " + sk + " does not exist in GWA_RE module. Please contact the module developer.");
	}
}
コード例 #30
0
ファイル: DepressionFSDaily.cpp プロジェクト: crazyzlj/SEIMS
void DepressionFSDaily::Get1DData(const char* key, int* n, float** data) {
    InitialOutputs();
    string sk(key);
    *n = m_nCells;
    if (StringMatch(sk, VAR_DPST)) {
        *data = m_sd;
    } else if (StringMatch(sk, VAR_DEET)) {
        *data = m_ed;
    } else if (StringMatch(sk, VAR_SURU)) {
        *data = m_sr;
    } else {
        throw ModelException(MID_DEP_LINSLEY, "Get1DData", "Output " + sk + " does not exist.");
    }
}