Beispiel #1
0
void StepNode::AssertMyInputsValid(void) const
{
    unsigned int valSize = GetInputs()[0].GetSize(),
                 threshSize = GetInputs()[1].GetSize();
    Assert(threshSize == 1 || threshSize == valSize,
           "Threshold must be either size 1 or the same size as the value to step");
}
Beispiel #2
0
void DotNode::WriteMyOutputs(std::string & outCode) const
{
    std::string vecType = VectorF(GetInputs()[0].GetSize(), 0).GetGLSLType();

    outCode += "\tfloat " + GetOutputName(0) +
               " = dot(" + GetInputs()[0].GetValue() + ", " +
               GetInputs()[1].GetValue() + ");\n";
}
Beispiel #3
0
    bool Trainer::TrainMinibatch(const std::unordered_map<Variable, MinibatchData>& arguments, std::unordered_map<Variable, ValuePtr>& outputsToFetch, const DeviceDescriptor& computeDevice /*= DeviceDescriptor::UseDefaultDevice()*/)
    {
#ifndef  CNTK_UWP
        auto profMinibatch = Microsoft::MSR::CNTK::ScopeProfile(Microsoft::MSR::CNTK::profilerEvtMainMinibatch);
#endif

        bool result = (!m_distributed) ?
            TrainLocalMinibatch(GetInputs(arguments), outputsToFetch, IsAtSweepEnd(arguments), computeDevice) :
            TrainDistributedMinibatch(GetInputs(arguments), outputsToFetch, IsAtSweepEnd(arguments), computeDevice);

        // TODO: exclude updating progress writers from profiling?
        UpdateTrainingProgress(m_prevMinibatchNumSamples, m_prevMinibatchAggregateTrainingLossValue,
                               m_prevMinibatchAggregateEvalCriterionValue, computeDevice);
        return result;
    }
Beispiel #4
0
void TextureSample2DNode::AssertMyInputsValid(void) const
{
    //Make sure the param name is valid.
    Assert(MaterialConstants::IsValidGLSLName(SamplerName),
           "Parameter name '" + SamplerName + "' isn't a valid GLSL variable name!");

    Assert(GetInputs()[0].GetSize() == 2, "UV input isn't size 2; it's size " + ToString(GetInputs()[0].GetSize()));
}
Beispiel #5
0
CMetaModel* CRegionalSvmModel::CreateMetaModel()
{
	CSvmModel* pModel = new CSvmModel();
	pModel->SetInputs( GetInputs() );
	pModel->SetOutputs( GetOutputs() );

	for( int i=0; i<GetOutputs(); i++ )pModel->SetOptions( m_vcOptions[i], i );
	return pModel;
}
Beispiel #6
0
REAL CMetaModel::Test( const REAL* prInputs, const REAL* prOutputs, int count )
{
	vector<REAL> vcOutputs( GetOutputs() );

	//calculate the error function under the current weight
	REAL rError = 0;
	for( int i=0; i<count; i++ ){
		Predict( prInputs + i*GetInputs(), &vcOutputs[0] );
		rError += inner_product( vcOutputs.begin(), vcOutputs.end(), prOutputs, 0.0,
			plus<REAL>(), minus_pow<REAL>(2.0) ) / GetOutputs();
	}
	return rError/count;
}
Beispiel #7
0
void CRegionalMetaModel::FindTrustRegions( const REAL* prInput, vector<CTrustRegion*>& hitRegions )
{
	ASSERT( !m_vcMetaModels.empty() );
	hitRegions.clear();

	int nInputs = GetInputs();
	vector<REAL> vcInput( prInput, prInput+nInputs );

	remove_copy_if( m_vcRegions.begin()+1, m_vcRegions.end(), back_inserter(hitRegions), op_not_in_region(vcInput) );

	//the first neural net is the global prediction, always available.
	//modifed on 02/12/05. 
	hitRegions.insert( hitRegions.begin(), m_vcRegions.front() );
}
Beispiel #8
0
void CSvmModel::Train( const string& strTrainData, const string& strValidData )
{
	Release();

	for( int i=0; i<GetOutputs(); i++ ){
		TransformToSvmData( strTrainData, GetInputs(), GetOutputs(), i, SVM_TRAIN_FILE );
		string strModelFile = CreateUniqueModelName();
		RunSvmTrain( SVM_TRAIN_FILE, /*parameters*/GetOptions(i), strModelFile );
		m_vcModelFiles.push_back( strModelFile );

		SVM_MODEL* model=svm_load_model( strModelFile.c_str() );
		m_vcModels.push_back( model );
	}
}
Beispiel #9
0
void CSvmModel::Predict( const REAL* prInputs, REAL* prOutputs )
{
	//write the inputs into a temporary test file
/*	{
		ofstream ofg(TEST_FILE);
		vector<REAL> vcInputs( prInputs, prInputs+GetInputs() );
		vector<REAL> vcOutputs;
		TransformSvmLine( ofg, vcInputs, vcOutputs, 0 );
	}*/

	//predict for each model and put each output into prOutputs[i]
	for( int i=0; i<GetOutputs(); i++ ){
		svm_predict( m_vcModels[i], prInputs, GetInputs(), &prOutputs[i] );
//		RunSvmPredict( TEST_FILE, m_vcModelFiles[i], prOutputs[i] );
	}
}
Beispiel #10
0
void CRegionalMetaModel::Train( const string& strTrainData, const string& strValidData )
{
	int nInputs = GetInputs();
	int nOutputs = GetOutputs();

	vector< vector<REAL> > vcInputs;
	vector< vector<REAL> > vcOutputs;
	vector< REAL > vcPtCen = m_vcPtCen;
	dist_pair_vector vcDists;
	vector< vector<int> > vcIdSet;

	Release();

	//read all the data into vcInputs and vcOutputs.
	ReadTrainingData( strTrainData, nInputs, nOutputs, vcInputs, vcOutputs );

	//compute the distance to the center point.
	ComputeDistance( vcInputs, vcPtCen, vcDists );

	//subdivid the training data into clusters.
	SubdividTrainingData( vcDists, vcIdSet, m_nMinCutPts );

	//create the training set for each hierarch.
	for( int i=0; i<vcIdSet.size(); i++ ){
		sort( vcIdSet[i].begin(), vcIdSet[i].end() );
		//write a training set to files and run the matlab trainer
		WriteTrainingFile( REG_TRAIN_FILE, REG_VALID_FILE, vcInputs, vcOutputs, vcIdSet[i] );
		CMetaModel* pModel = CreateMetaModel();
		pModel->Train( REG_TRAIN_FILE, REG_VALID_FILE );

		CTrustRegion* pRegion = new CTrustRegion();
		ComputeTrustRegion( pRegion, vcInputs, vcIdSet[i] );

		m_vcMetaModels.push_back( pModel );
		
		pRegion->SetModelId( m_vcMetaModels.size()-1 );
		m_vcRegions.push_back( pRegion );
	}

	cdump<<"training finsihed:"<<vcIdSet.size()<<" nets were trained!"<<endl;
}
Beispiel #11
0
void ReflectNode::AssertMyInputsValid(void) const
{
    Assert(GetInputs()[0].GetSize() == 3, "'toReflect' input isn't size 3!");
    Assert(GetInputs()[1].GetSize() == 3, "'reflectNormal' input isn't size 3!");
}
Beispiel #12
0
void ReflectNode::WriteMyOutputs(std::string & outCode) const
{
    outCode += "\t" + VectorF(GetOutputSize(0), 0).GetGLSLType() + " " + GetOutputName(0) +
        " = reflect(" + GetInputs()[0].GetValue() + ", " + GetInputs()[1].GetValue() + ");\n";
}
Beispiel #13
0
void TextureSample2DNode::WriteMyOutputs(std::string & outCode) const
{
    outCode += "\tvec4 " + GetSampleOutputName() + " = texture2D(" + SamplerName + ", " + GetInputs()[0].GetValue() + ");\n";
}
Beispiel #14
0
 double Evaluator::TestMinibatch(const std::unordered_map<Variable, MinibatchData>& arguments, const DeviceDescriptor& computeDevice /*= DeviceDescriptor::UseDefaultDevice()*/)
 {
     std::unordered_map<Variable, ValuePtr> outputsToFetch = {};
     return TestMinibatch(GetInputs(arguments), outputsToFetch, computeDevice);
 }
Beispiel #15
0
/* finds the value of every led saves it in data structure and in Array (used for drawing screen) */
void findOutput(){ 
	int i, n1, n2, value;
	output * optr;
	node * nptr;
	for(i = 0; i < c.li; i++) {
		init(&s);		
		MakeStack(i);
		while(!empty(&s)) {
			nptr = pop(&s);
			switch(nptr->type) {
				case INPUT :
					PutValue(nptr, value);
					break;
			
				case OUTPUT :	
					GetInputs(&n1, &n2, nptr->ptr);
					/* Calculating Output */
					optr = nptr->ptr;
					switch(optr->type) {
						case NAND :
							value = nand(n1, n2);
							break;
	
						case XNOR :
							value = xnor(n1, n2);
							break;

						case NOR :
							value = nor(n1, n2);
							break;

						case AND :
							value = and(n1, n2);
							break;

						case OR :
							value = or(n1, n2);
							break;
					
						case XOR :
							value = xor(n1, n2);
							break;

						case NOT :
							value = not(n1);
							break;

						default :
						break;
						
					PutValue(nptr, value);
					}
					break;
		
				case SWITCH :
					value = GetValue(nptr->ptr); 
					break;

				case LED :
					PutValue(nptr, value);
					break;
			}
		}
	}
	ChangeOnscreen();	
}
Beispiel #16
0
unsigned int StepNode::GetOutputSize(unsigned int outputIndex) const
{
    return Mathf::Max(GetInputs()[0].GetSize(), GetInputs()[1].GetSize());
}
Beispiel #17
0
void CRegionalMetaModel::Predict( const REAL* prInputs, REAL* prOutputs )
{
	vector< CTrustRegion* >hitRegions;

	//best region or multiple region?
	FindTrustRegions( prInputs, hitRegions );
//	FindBestRegion( prInputs, hitRegions );

	int nOutputs = GetOutputs();
	int nHitRegions = hitRegions.size();
	//for each trusted regional model, predict the result to vcOutputs[i][1...nOutputs]
	vector< vector<REAL> > vcOutputs(nHitRegions);
	for( int i=0; i<nHitRegions; i++ ){
		vcOutputs[i].resize( nOutputs );
		CMetaModel* pModel = m_vcMetaModels[ hitRegions[i]->GetModelId() ];
		pModel->Predict( prInputs, &vcOutputs[i][0] );
	}

	int nInputs = GetInputs();
	REAL rSumWeights = 0;
	vector< REAL > vcSum( nOutputs, 0.0 );
	//modified on 02/012/05 using trust probability
	for( i=0; i<nHitRegions; i++ ){
		ASSERT( nInputs==hitRegions[i]->m_ptCen.size() );
		vector<REAL> vcDistSqr(nInputs, 0.0);
		vector<REAL> vcRadSqr(nInputs, 0.0);
		vector<REAL> vcProbs(nInputs,0.0);
		transform( prInputs, prInputs+nInputs, hitRegions[i]->m_ptCen.begin(), vcDistSqr.begin(), diff_sqr<REAL>() );
//		cout<<"dist sqr:";
//		copy( vcDistSqr.begin(), vcDistSqr.end(), ostream_iterator<REAL>(cout, " ") ); cout<<endl;
		transform( hitRegions[i]->m_vcRadius.begin(), hitRegions[i]->m_vcRadius.end(), hitRegions[i]->m_vcRadius.begin(), vcRadSqr.begin(), multiplies<REAL>() );
//		cout<<"radius sqr:";
//		copy( vcRadSqr.begin(), vcRadSqr.end(), ostream_iterator<REAL>(cout, " ") ); cout<<endl;
		transform( vcDistSqr.begin(), vcDistSqr.end(), vcRadSqr.begin(), vcProbs.begin(), divides<REAL>() );
//		cout<<"probs :";
//		copy( vcProbs.begin(), vcProbs.end(), ostream_iterator<REAL>(cout, " ") ); cout<<endl;
		REAL rProb = accumulate( vcProbs.begin(), vcProbs.end(), 0.0) / nInputs;
		rProb = max( 1-rProb, 0.0 );

		//the first global model is always trusted.
		if( i==0 && rProb<=0 )rProb = max( rProb, 1e-3 );

		cdump<<"prob "<<i<<" "<<rProb<<"\t";

//		REAL rWeight = rProb / hitRegions[i]->GetSphereRadius();
		REAL rWeight = rProb;
		for( int j=0; j<nOutputs; j++ ){
			vcSum[j] += vcOutputs[i][j]*rWeight;
		}
		rSumWeights += rWeight;
	}
	if( rSumWeights > 0 ){
		transform( vcSum.begin(), vcSum.end(), vcSum.begin(), bind2nd(divides<REAL>(), rSumWeights) );
		copy( vcSum.begin(), vcSum.end(), prOutputs );
	}else{
		copy( vcOutputs[0].begin(), vcOutputs[0].end(), prOutputs );
	}

	//compute the average outputs according to inverse sphere radius
/*	vector< REAL > vcSum( nOutputs, 0.0 );
	REAL rSumInvRadius = 0;
	for( i=0; i<nHitRegions; i++ ){
		REAL rInvRadius = 1.0 / hitRegions[i]->GetSphereRadius();
		for( int j=0; j<nOutputs; j++ ){
			vcSum[j] += vcOutputs[i][j]*rInvRadius;
		}
		rSumInvRadius += rInvRadius;
	}
	transform( vcSum.begin(), vcSum.end(), vcSum.begin(), bind2nd(divides<REAL>(), rSumInvRadius) );
	copy( vcSum.begin(), vcSum.end(), prOutputs );
*/
	cdump<<"pred..."<<nHitRegions<<" nets"<<endl;
}
Beispiel #18
0
void NewMode(int selectedmode) {
  struct UnitNode *unit = NULL;
  struct ModeNode *mode = NULL;
  ULONG id = AHI_INVALID_ID;
  Fixed MinOutVol = 0, MaxOutVol = 0, MinMonVol = 0, MaxMonVol = 0;
  Fixed MinGain = 0, MaxGain = 0;
  double Min, Max, Current;
  int offset;

  state.ModeSelected = selectedmode;

  unit = (struct UnitNode *) GetNode(state.UnitSelected, UnitList);

  if( selectedmode != ~0 )
  {
    mode = (struct ModeNode *) GetNode(selectedmode, ModeList);
  }

  if( mode != NULL )
  {
    id = mode->ID;
    
    AHI_GetAudioAttrs(id, NULL,
		      AHIDB_IndexArg,         unit->prefs.ahiup_Frequency,
		      AHIDB_Index,            (ULONG) &state.FreqSelected,
		      AHIDB_Frequencies,      (ULONG) &state.Frequencies,
		      AHIDB_MaxChannels,      (ULONG) &state.Channels,
		      AHIDB_Inputs,           (ULONG) &state.Inputs,
		      AHIDB_Outputs,          (ULONG) &state.Outputs,
		      AHIDB_MinOutputVolume,  (ULONG) &MinOutVol,
		      AHIDB_MaxOutputVolume,  (ULONG) &MaxOutVol,
		      AHIDB_MinMonitorVolume, (ULONG) &MinMonVol,
		      AHIDB_MaxMonitorVolume, (ULONG) &MaxMonVol,
		      AHIDB_MinInputGain,     (ULONG) &MinGain,
		      AHIDB_MaxInputGain,     (ULONG) &MaxGain,

		      AHIDB_BufferLen,        128,
		      AHIDB_Author,           (ULONG) authorBuffer,
		      AHIDB_Copyright,        (ULONG) copyrightBuffer,
		      AHIDB_Driver,           (ULONG) driverBuffer,
		      AHIDB_Version,          (ULONG) versionBuffer,
		      AHIDB_Annotation,       (ULONG) annotationBuffer,
		      TAG_DONE);
  }

  state.ChannelsSelected = unit->prefs.ahiup_Channels;
  state.ScaleModeSelected = unit->prefs.ahiup_ScaleMode;
  state.InputSelected    = unit->prefs.ahiup_Input;
  state.OutputSelected   = unit->prefs.ahiup_Output;

  // Limit channels
  state.Channels = min(state.Channels, 32);

  if(unit->prefs.ahiup_Unit == AHI_NO_UNIT) {
    state.ChannelsDisabled = TRUE;
  }
  else {
    state.ChannelsDisabled = FALSE;
  }

  if(MinOutVol == 0) {
    MinOutVol = 1;
    state.OutVolMute = TRUE;
    state.OutVols    = 1;
  }
  else {
    state.OutVolMute = FALSE;
    state.OutVols    = 0;
  }

  if(MinMonVol == 0) {
    MinMonVol = 1;
    state.MonVolMute = TRUE;
    state.MonVols    = 1;
  }
  else {
    state.MonVolMute = FALSE;
    state.MonVols    = 0;
  }


  if(MinGain == 0) {
    MinGain = 1;
    state.GainMute = TRUE;
    state.Gains    = 1;
  }
  else {
    state.GainMute = FALSE;
    state.Gains    = 0;
  }

  if(MaxOutVol == 0) {
    state.OutVolSelected = 0;
    state.OutVolOffset   = 0;
  }
  else {
    Current = 20 * log10( unit->prefs.ahiup_OutputVolume / 65536.0 );
    Min = floor(20 * log10( MinOutVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP;
    Max = floor(20 * log10( MaxOutVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP;
    state.OutVolSelected = (Current - Min) / DBSTEP + 0.5 + state.OutVols;
    state.OutVols += ((Max - Min) / DBSTEP) + 1;
    state.OutVolOffset = Min;
  }

  if(MaxMonVol == 0) {
    state.MonVolSelected = 0;
    state.MonVolOffset   = 0;
  }
  else {
    Current = 20 * log10( unit->prefs.ahiup_MonitorVolume / 65536.0 );
    Min = floor(20 * log10( MinMonVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP;
    Max = floor(20 * log10( MaxMonVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP;
    state.MonVolSelected = (Current - Min) / DBSTEP + 0.5 + state.MonVols;
    state.MonVols += ((Max - Min) / DBSTEP) + 1;
    state.MonVolOffset = Min;
  }

  if(MaxGain == 0) {
    state.GainSelected = 0;
    state.GainOffset   = 0;
  }
  else {
    Current = 20 * log10( unit->prefs.ahiup_InputGain / 65536.0 );
    Min = floor(20 * log10( MinGain / 65536.0 ) / DBSTEP + 0.5) * DBSTEP;
    Max = floor(20 * log10( MaxGain / 65536.0 ) / DBSTEP + 0.5) * DBSTEP;
    state.GainSelected = (Current - Min) / DBSTEP + 0.5 + state.Gains;
    state.Gains += ((Max - Min) / DBSTEP) + 1;
    state.GainOffset = Min;
  }

  // Make sure everything is within bounds!

  state.FreqSelected = max(state.FreqSelected, 0);  
  state.FreqSelected = min(state.FreqSelected, state.Frequencies);

  state.ChannelsSelected = max(state.ChannelsSelected, 1);
  state.ChannelsSelected = min(state.ChannelsSelected, state.Channels);
  
  state.ScaleModeSelected = max(state.ScaleModeSelected, 0);
  state.ScaleModeSelected = min(state.ScaleModeSelected, AHI_SCALE_FIXED_6_DB);
  
  state.OutVolSelected = max(state.OutVolSelected, 0);
  state.OutVolSelected = min(state.OutVolSelected, state.OutVols);
  
  state.MonVolSelected = max(state.MonVolSelected, 0);
  state.MonVolSelected = min(state.MonVolSelected, state.MonVols);
  
  state.GainSelected = max(state.GainSelected, 0);
  state.GainSelected = min(state.GainSelected, state.Gains);

  state.InputSelected = max(state.InputSelected, 0);
  state.InputSelected = min(state.InputSelected, state.Inputs);

  state.OutputSelected = max(state.OutputSelected, 0);
  state.OutputSelected = min(state.OutputSelected, state.Outputs);

  // Remove any \r's or \n's from version string

  offset = strlen(versionBuffer);
  while((offset > 0) &&
        ((versionBuffer[offset-1] == '\r') ||
         (versionBuffer[offset-1] == '\n'))) {
    versionBuffer[offset-1] = '\0';
    offset--;
  }

  FreeVec(Inputs);
  FreeVec(Outputs);
  Inputs   = GetInputs(id);
  Outputs  = GetOutputs(id);
}
// Commit
//------------------------------------------------------------------------------
/*virtual*/ bool FunctionObjectList::Commit( const BFFIterator & funcStartIter ) const
{
	// make sure all required variables are defined
	const BFFVariable * compiler;
	const BFFVariable * compilerOptions;
	AStackString<> compilerOptionsDeoptimized;
	AStackString<> compilerOutputPath;
    AStackString<> compilerOutputPrefix;
	const BFFVariable * compilerOutputExtension;
	if ( !GetString( funcStartIter, compiler, ".Compiler", true ) ||
		 !GetString( funcStartIter, compilerOptions, ".CompilerOptions", true ) ||
		 !GetString( funcStartIter, compilerOptionsDeoptimized, ".CompilerOptionsDeoptimized", false ) ||
		 !GetString( funcStartIter, compilerOutputPath, ".CompilerOutputPath", true ) ||
		 !GetString( funcStartIter, compilerOutputPrefix, ".CompilerOutputPrefix", false ) ||
		 !GetString( funcStartIter, compilerOutputExtension, ".CompilerOutputExtension", false ) )
	{
		return false;
	}

    PathUtils::FixupFolderPath( compilerOutputPath );

	NodeGraph & ng = FBuild::Get().GetDependencyGraph();

	// find or create the compiler node
	CompilerNode * compilerNode = nullptr;
	if ( !FunctionObjectList::GetCompilerNode( funcStartIter, compiler->GetString(), compilerNode ) )
	{
		return false; // GetCompilerNode will have emitted error
	}

	// Sanity check compile flags
	uint32_t objFlags = ObjectNode::DetermineFlags( compilerNode, compilerOptions->GetString() );
	if ( ( objFlags & ObjectNode::FLAG_MSVC ) && ( objFlags & ObjectNode::FLAG_CREATING_PCH ) )
	{
		// must not specify use of precompiled header (must use the PCH specific options)
		Error::Error_1303_PCHCreateOptionOnlyAllowedOnPCH( funcStartIter, this, "/Yc", "CompilerOptions" );
		return false;
	}

	// Check input/output for Compiler
	{
		const AString & args = compilerOptions->GetString();
		bool hasInputToken = ( args.Find( "%1" ) || args.Find( "\"%1\"" ) );
		if ( hasInputToken == false )
		{
			Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "%1" );
			return false;
		}
		bool hasOutputToken = ( args.Find( "%2" ) || args.Find( "\"%2\"" ) );
		if ( hasOutputToken == false )
		{
			Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "%2" );
			return false;
		}

        // check /c or -c
        if ( objFlags & ObjectNode::FLAG_MSVC )
        {
            if ( args.Find( "/c" ) == nullptr &&
				args.Find( "-c" ) == nullptr)
            {
		        Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "/c or -c" );
			    return false;
		    }
        }
        else if ( objFlags & ( ObjectNode::FLAG_SNC | ObjectNode::FLAG_GCC | ObjectNode::FLAG_CLANG ) )
        {
            if ( args.Find( "-c" ) == nullptr )
            {
		        Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "-c" );
			    return false;
		    }
        }
	}

	// Compiler Force Using
	Dependencies compilerForceUsing;
	if ( !GetNodeList( funcStartIter, ".CompilerForceUsing", compilerForceUsing, false ) )
	{
		return false; // GetNodeList will have emitted an error
	}

	// Get the (optional) Preprocessor & PreprocessorOptions
	const BFFVariable * preprocessor = nullptr;
	const BFFVariable * preprocessorOptions = nullptr;
    CompilerNode * preprocessorNode = nullptr;
	if ( !GetString( funcStartIter, preprocessor, ".Preprocessor", false ) )
	{
		return false; // GetString will have emitted an error
	}
	if ( preprocessor )
    {
		// get the preprocessor executable
        if ( !FunctionObjectList::GetCompilerNode( funcStartIter, preprocessor->GetString(), preprocessorNode ) )
        {
            return false; // GetCompilerNode will have emitted an error
        }

		// get the command line args for the preprocessor
        if ( !GetString( funcStartIter, preprocessorOptions, ".PreprocessorOptions", true ) ) // required
		{
			return false; // GetString will have emitted an error
		}
    }

	// Pre-build dependencies
	Dependencies preBuildDependencies;
	if ( !GetNodeList( funcStartIter, ".PreBuildDependencies", preBuildDependencies, false ) )
	{
		return false; // GetNodeList will have emitted an error
	}

	// de-optimization setting
	bool deoptimizeWritableFiles = false;
	bool deoptimizeWritableFilesWithToken = false;
	if ( !GetBool( funcStartIter, deoptimizeWritableFiles, ".DeoptimizeWritableFiles", false, false ) )
	{
		return false; // GetBool will have emitted error
	}
	if ( !GetBool( funcStartIter, deoptimizeWritableFilesWithToken, ".DeoptimizeWritableFilesWithToken", false, false ) )
	{
		return false; // GetBool will have emitted error
	}
	if ( ( deoptimizeWritableFiles || deoptimizeWritableFilesWithToken ) && compilerOptionsDeoptimized.IsEmpty() )
	{
		Error::Error_1101_MissingProperty( funcStartIter, this, AStackString<>( ".CompilerOptionsDeoptimized" ) );
		return false;
	}

	// Precompiled Header support
	ObjectNode * precompiledHeaderNode = nullptr;
	if ( !GetPrecompiledHeaderNode( funcStartIter, compilerNode, objFlags, compilerOptions, compilerForceUsing, precompiledHeaderNode, deoptimizeWritableFiles, deoptimizeWritableFilesWithToken ) )
	{
		return false; // GetPrecompiledHeaderNode will have emitted error
	}

	Dependencies staticDeps( 32, true );
	if ( !GetInputs( funcStartIter, staticDeps ) )
	{
		return false; // GetStaticDeps will gave emitted error
	}

	if ( staticDeps.IsEmpty() )
	{
		Error::Error_1006_NothingToBuild( funcStartIter, this );
		return false;
	}

	// parsing logic should guarantee we have a string for our name
	ASSERT( m_AliasForFunction.IsEmpty() == false );

	// Check for existing node
	if ( ng.FindNode( m_AliasForFunction ) )
	{
		Error::Error_1100_AlreadyDefined( funcStartIter, this, m_AliasForFunction );
		return false;
	}

	// Create library node which depends on the single file or list
	ObjectListNode * o = ng.CreateObjectListNode( m_AliasForFunction,
												  staticDeps,
												  compilerNode,
												  compilerOptions->GetString(),
												  compilerOptionsDeoptimized,
												  compilerOutputPath,
												  precompiledHeaderNode,
												  compilerForceUsing,
												  preBuildDependencies,
												  deoptimizeWritableFiles,
												  deoptimizeWritableFilesWithToken,
                                                  preprocessorNode,
                                                  preprocessorOptions ? preprocessorOptions->GetString() : AString::GetEmpty() );
	if ( compilerOutputExtension )
	{
		o->m_ObjExtensionOverride = compilerOutputExtension->GetString();
	}
    o->m_CompilerOutputPrefix = compilerOutputPrefix;

	return true;
}
Beispiel #20
0
void StepNode::WriteMyOutputs(std::string& outCode) const
{
    outCode += "\t" + VectorF::GetGLSLType(GetOutputSize(0)) + " " + GetOutputName(0) +
                   " = step(" + GetInputs()[1].GetValue() + ", " + GetInputs()[0].GetValue() + ");\n";
}
ribi::kalman::KalmanFilterExperiment::KalmanFilterExperiment(
  const int time,
  const std::vector<std::string>& input_functions,
  const boost::shared_ptr<KalmanFilter> m_kalman_filter,
  const std::vector<std::string>& state_names,
  const boost::shared_ptr<WhiteNoiseSystem>& m_white_noise_system,
  const std::string& context
  )
  : m_calculation_elements{},
    m_context{context},
    m_inputs{ribi::kalman::KalmanFilterExperiment::ParseInput(input_functions,time)},
    m_kalman_filter{m_kalman_filter},
    m_real_states{},
    m_state_names{state_names},
    m_white_noise_system{m_white_noise_system}
{
  assert(m_kalman_filter);
  assert(this->GetKalmanFilter());
  assert(this->GetKalmanFilter()->GetParameters());
  assert(m_white_noise_system);
  assert(this->GetWhiteNoiseSystem());
  assert(this->GetWhiteNoiseSystem()->GetParameters());
  #ifndef NDEBUG
  {
    const std::size_t sz = state_names.size();
    assert(sz == state_names.size());
    assert(sz == this->GetKalmanFilter()->GetParameters()->GetControl().size1());
    assert(sz == this->GetKalmanFilter()->GetParameters()->GetControl().size2());
    assert(sz == this->GetKalmanFilter()->GetParameters()->GetInitialStateEstimate().size());
    assert(sz == this->GetKalmanFilter()->GetParameters()->GetObservation().size1());
    assert(sz == this->GetKalmanFilter()->GetParameters()->GetObservation().size2());
    assert(sz == this->GetKalmanFilter()->GetParameters()->GetStateTransition().size1());
    assert(sz == this->GetKalmanFilter()->GetParameters()->GetStateTransition().size2());
    assert(sz == GetWhiteNoiseSystem()->GetParameters()->GetControl().size1());
    assert(sz == GetWhiteNoiseSystem()->GetParameters()->GetControl().size2());
    assert(sz == GetWhiteNoiseSystem()->GetParameters()->GetInitialState().size());
    assert(sz == GetWhiteNoiseSystem()->GetParameters()->GetMeasurementNoise().size());
    assert(sz == GetWhiteNoiseSystem()->GetParameters()->GetProcessNoise().size());
    assert(sz == GetWhiteNoiseSystem()->GetParameters()->GetStateTransition().size1());
    assert(sz == GetWhiteNoiseSystem()->PeekAtRealState().size());
    assert(sz == input_functions.size());
  }
  #endif

  

  assert(Matrix::MatricesAreAboutEqual(
    m_kalman_filter->GetParameters()->GetControl(),
    m_white_noise_system->GetParameters()->GetControl()));
  assert(Matrix::MatricesAreAboutEqual(
    m_kalman_filter->GetParameters()->GetStateTransition(),
    m_white_noise_system->GetParameters()->GetStateTransition()));

  
  for (int i=0;i!=time;++i)
  {
    //Update reality, that is, let the real system (i.e. reality) go to its next state
    assert(i < boost::numeric_cast<int>(GetInputs().size()));
    const boost::numeric::ublas::vector<double>& input = GetInputs()[i];

    //assert(m_white_noise_system->GetCurrentState().size() == input.size());

    
    m_white_noise_system->GoToNextState(input);
    

    //Perform a noisy measurement
    const boost::numeric::ublas::vector<double> z_measured = m_white_noise_system->Measure();
    

    //Pass this measurement to the filter
    try
    {
      
      m_kalman_filter->SupplyMeasurementAndInput(z_measured,input);
      
    }
    catch (std::runtime_error& e)
    {
      //Happens when innovation covariance becomes degenerate
      //(that is, its determinant is zero)
      assert(this->IsValid() && "The experiment must end in a valid state");
      return;
    }
    catch (...)
    {
      assert(!"Should never get here");
    }

    this->AppendRealState(m_white_noise_system->PeekAtRealState());

    //Store
    const boost::shared_ptr<KalmanFilterCalculationElements> last_calculation
      = KalmanFilterCalculationElementsFactory::DeepCopy(m_kalman_filter->GetLastCalculation());
    m_calculation_elements.push_back(last_calculation);
  }
  assert(time == boost::numeric_cast<int>(m_calculation_elements.size()));
  assert(this->IsValid() && "The experiment must end in a valid state");
}
Beispiel #22
0
//////////////////////////////////////////////////////////////////////////////
// This is top-level function which generates the PIC code for pages of 
// the algorithm. 
//////////////////////////////////////////////////////////////////////////////
void DrawPic(CSV_INPUT *csv_input, int nLn)
{

	char pages[MAXPAGES][32];	// array for the list of UNIQE album page IDs	
	int nUniq = 1;
	bool foundPage = false;

	static BOX box[MAXBOX];

	CSV_INPUT thisPage[MAXCOMPPPAGE]; // buffer for parsed initial data portion for this specific album page
	
	memset((char*)pages, '\x0', sizeof(pages));
	memset(thisPage, '\x0', sizeof(thisPage));
	memset(box, '\x0', sizeof(box));

	////////////////////////////////////////////////////////////////////////////////////////
	// Since we're trying to restore box-and-arrows view of the initial data on page basis
	// the 1st thing we need is a list of uniq pages IDs present in the album
	// The Following code makes uniq list of album pages.
	////////////////////////////////////////////////////////////////////////////////////////
	
	// Fill the 1st element skipping the header (start at 1)
	strcpy(pages[0], (csv_input + 1)->page_alg);

	for (int i = 1; i < nLn; i++)	// Start at 1 to skip the header
	{
		foundPage = false;
		for (int j = 0; j < nUniq; j++)
		{
			if ( !strcmp( (csv_input + i)->page_alg, pages[j]) )
			{
				foundPage = true;
				break;
			}
		}

		if (!foundPage)
		{
			strcpy(pages[nUniq], (csv_input + i)->page_alg);
			nUniq++;
		}
	}

	fprintf(stderr, "DrawPic: nUniq = %d\n", nUniq);
	 	
	for (int i = 0; i < nUniq; i++)
		fprintf(stderr, "%d: %s\n", i, pages[i]);

	
	////////////////////////////////////////////////////////////////////////////////////
	// OK. We have a list of uniq page IDs. 
	// Now: 
	// 1. Go page by page. Select rows from csv_input for each page ID
	// 2. Build connection table for all components (aka boxes) sitting on the page 
	////////////////////////////////////////////////////////////////////////////////////
	 	
	int nCmp = 0;

	FILE *flp;
	char fname[1024] = "";
	
	for (int i = 0; i < nUniq; i++) // go page by page on the uniq page names list
	{


		// Open PIC file in the directory defined in configuration
		memset(fname, '\x0', sizeof(fname));
		sprintf(fname, "%s/%s.pic", conf.picdir, pages[i]); 
		flp = fopen(fname, "w");

		memset(box, '\x0', sizeof(box));

		if (!flp)
		{
			fprintf(stderr, "DrawPic Error: Can not open file %s\n", fname);
			continue;
		}

		nCmp = 0;
		int n1 = 0;


		// We're looking for boxes on the page pages[i], we'll go through the whole data set and pick up
		// all matching records, storing them into thisPage buffer (restricted by MAXCOMPPPAGE = 128 boxes per page)
		// thisPage is CSV_INPUT buffer, that is we just store parsed CSV data into it for further analysis

		for (int j = 0; j < nLn; j++) // Go through the whole PTC and pick components for the specific page
		{
			if ( !strcmp( (csv_input + j)->page_alg, pages[i]) )
			{
				memcpy((char*)&thisPage[nCmp], (char*)(csv_input + j), sizeof(CSV_INPUT));

				// OK. Let's start filling BOX structures with the data we can immediately get from CSV
			
				// Fill box structire with CSV_INPUT data
				// actually collected earlier by the parser
				
				box[nCmp].n = thisPage[nCmp].nom_row; 			// Row number (aka box number)
				strcpy( box[nCmp].type, thisPage[nCmp].run_compon);	// Component type

                        	n1 = 0;
                        	while (strlen(thisPage[nCmp].inputs[n1]))		// Input names
                        	{
					strcpy( box[nCmp].inputs[n1].name, thisPage[nCmp].inputs[n1]);
                                	n1++;
                        	}

				box[nCmp].nInp = n1;					// This is how we know how many inputs the has

                        	n1 = 0;
                        	while (strlen(thisPage[nCmp].outputs[n1]))		// Output names (same way as for inputs)
                        	{
					strcpy( box[nCmp].outputs[n1].name, thisPage[nCmp].outputs[n1]);
                                	n1++;
                        	}

				box[nCmp].nOut = n1;					// Number of outputs

				nCmp++;

			}
		}

		fprintf(stderr, "Page %s: %d components\n", pages[i], nCmp);

		///////////////////////////////////////////////////////////////////////////////////////////////////
		// Done. We have here complete box[] structure array + number of components on this specific 
		// album page known as nCmp
		// Now we need to fill in to/from data
		// Logic: 
		// Input is some boxe's output or direct page input 
		// We go box by box, checking each input against outputs of other boxes 
		// If it's found then we put boxe's number to 'from' structire member 
		// Otherwise we put _PAGE_INPUT instead. 
		///////////////////////////////////////////////////////////////////////////////////////////////////
	
		// Collect inputs and outputs, set cross-references
		for (int i = 0; i < nCmp; i++)	 // box by box loop
		{
				GetInputs(box, i, nCmp);
				GetOutputs(box, i, nCmp);
		}

		// Print out thisPage and box arrays to stderr 
		// normally redirected to a log file
		LogDwgData(thisPage, box, nCmp);

		// Now try to generate PIC code for the page
		
		fprintf(flp, ".PS %g\n", conf.scale); // Scale 

		// This is where the PIC code is actually made up and written to a file
		GeneratePICsrc(flp, box, nCmp);

		fprintf(flp, ".PE\n");
		 	
		if (flp)
		{
			fclose(flp);
			flp = NULL;
		}
	}
	

	return;
}
Beispiel #23
0
//------------------------------------------------------------------------------
bool Msise90Atmosphere::Density(Real *pos, Real *density, Real epoch, 
                                Integer count)
{
   #ifdef DEBUG_FIRSTCALL
      static bool firstcall = true;
   #endif

   Integer i, i6;

   #ifdef DEBUG_GEODETICS
      Real    alt;
   #endif

   Real    lst;     // Local apparent solar time (Hrs)
   Real    den[8], temp[2];
   
   #ifdef DEBUG_MSISE90_ATMOSPHERE
   logFile = fopen("GMAT-MSISE90.txt", "w");
   #endif
   
   if (mCentralBody == NULL)
      throw AtmosphereException(
         "Central body pointer not set in MSISE90 model.");

   Real utcEpoch = TimeConverterUtil::Convert(epoch, TimeConverterUtil::A1MJD,
		   TimeConverterUtil::UTCMJD, GmatTimeConstants::JD_JAN_5_1941);

   GetInputs(utcEpoch);


   #ifdef DUMP_FLUX_DATA
      MessageInterface::ShowMessage("%.12lf  %lf  %lf  [%lf  %lf  %lf  %lf  %lf  %lf  %lf]\n",
         epoch, f107, f107a, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]);
   #endif

   int xyd    = yd;
   float xsod = (float)sod;
   float xalt; //alt;
   float xlat; // Geodetic Latitude
   float xlon; //lon;
   float xlst;
   float xf107a = (float)f107a;
   float xf107  = (float)f107;
   int xmass;
   float xap[7];
   float xden[8];
   float xtemp[2];

   Integer j;
   for (j = 0; j < 7; j++)  
      xap[j]   = (float)ap[j];
   for (j = 0; j < 8; j++)  
   {
      den[j]  = 0.0;
      xden[j] = (float)den[j];
   }
   for (j = 0; j < 2; j++)
   {
      temp[j]  = 0.0;
      xtemp[j] = (float)temp[j];
   }
   for (i = 0; i < count; ++i) 
   {
      i6 = i*6;
      mass = 48;

      #ifdef DEBUG_GEODETICS
         alt =
      #endif
      CalculateGeodetics(&pos[i6], epoch, true);
      lst = sod/3600.0 + geoLong/15.0;

      #ifdef DEBUG_GEODETICS
         MessageInterface::ShowMessage("Diffs:\n");
         MessageInterface::ShowMessage("   Height:    %.12lf vs %.12lf\n", geoHeight, alt);
         MessageInterface::ShowMessage("   Latitude:  %.12lf vs %.12lf\n", geoLat, geolat);
         MessageInterface::ShowMessage("   Longitude: %.12lf vs %.12lf\n", geoLong, lon);
      #endif

      #ifdef DEBUG_MSISE90_ATMOSPHERE
         MessageInterface::ShowMessage(
               "   GeodeticLat = %lf\n", geoLat);
      #endif
      
      #ifdef DEBUG_MSISE90_ATMOSPHERE
         MessageInterface::ShowMessage(
            "Calculating MSISE90 Density from parameters:\n   "
            "yd = %d\n   sod = %.12lf\n   alt = %.12lf\n   lat = %.12lf\n   "
            "lon = %.12lf\n   lst = %.12lf\n   f107a = %.12lf\n   "
            "f107 = %.12lf\n   ap = [%.12lf %.12lf %.12lf %.12lf %.12lf "
            "%.12lf %.12lf]\n   w = [%.12le %.12le %.12le]\n", yd, sod,
            geoHeight, geoLat, geoLong, lst, f107a, f107, ap[0], ap[1], ap[2],
            ap[3], ap[4], ap[5], ap[6], angVel[0], angVel[1], angVel[2]);
      #endif
      
      xalt = (float)geoHeight;
      xlat = (float)geoLat;
      xlon = (float)geoLong;
      xlst = (float)lst;
      xmass = mass;

      #ifdef DEBUG_MSISE90_ATMOSPHERE
      MessageInterface::ShowMessage("Writing Pre-GTDS6 MSISE90 data to log file ...\n");
      fprintf(logFile, "Pre-GTDS6() \n");
      fprintf(logFile, "=========== \n");
      fprintf(logFile, "Epoch                  = %le \n", epoch);
      fprintf(logFile, "Year & Days            = %d \n", xyd);
      fprintf(logFile, "Seconds                = %le \n", xsod);
      fprintf(logFile, "Altitude               = %le \n", xalt);
      fprintf(logFile, "Latitude               = %le \n", xlat);
      fprintf(logFile, "Longitude              = %le \n", xlon);
      fprintf(logFile, "Solar Time             = %le \n", xlst);
      fprintf(logFile, "F107 Average           = %le \n", xf107a);
      fprintf(logFile, "F107                   = %le \n", xf107);
      fprintf(logFile, "Geomagnetic index[0]   = %le \n", xap[0]);
      fprintf(logFile, "Geomagnetic index[1]   = %le \n", xap[1]);
      fprintf(logFile, "Geomagnetic index[2]   = %le \n", xap[2]);
      fprintf(logFile, "Geomagnetic index[3]   = %le \n", xap[3]);
      fprintf(logFile, "Geomagnetic index[4]   = %le \n", xap[4]);
      fprintf(logFile, "Geomagnetic index[5]   = %le \n", xap[5]);
      fprintf(logFile, "Geomagnetic index[6]   = %le \n", xap[6]);
      fprintf(logFile, "Mass                   = %d \n", xmass);
      fprintf(logFile, "HE Number Density      = %le \n", xden[0]);
      fprintf(logFile, "O Number Density       = %le \n", xden[1]);
      fprintf(logFile, "N2 Number Density      = %le \n", xden[2]);
      fprintf(logFile, "O2 Number Density      = %le \n", xden[3]);
      fprintf(logFile, "AR Number Density      = %le \n", xden[4]);
      fprintf(logFile, "Total Mass Density     = %le \n", xden[5]);
      fprintf(logFile, "H Number Density       = %le \n", xden[7]);
      fprintf(logFile, "EXOSPHERIC Temperature = %le \n", xtemp[0]);
      fprintf(logFile, "Temperature at Alt     = %le \n", xtemp[1]);
      fprintf(logFile, "\n");
      fprintf(logFile, "\n");
      MessageInterface::ShowMessage("DONE Writing Pre-GTDS6 MSISE90 data to log file ...\n");
      #endif
      
      #ifndef __SKIP_MSISE90__
         #ifdef DEBUG_MSISE90_ATMOSPHERE
            MessageInterface::ShowMessage("About to call gtd6_ ...\n");
         #endif
         #ifdef USE_64_BIT_LONGS
            long int xydLong = (long int) xyd;
            long int xmassLong = (long int) xmass;
            gtd6_(&xydLong,&xsod,&xalt,&xlat,&xlon,&xlst,&xf107a,&xf107,&xap[0],&xmassLong,
                  &xden[0],&xtemp[0]);
         #else
            gtd6_(&xyd,&xsod,&xalt,&xlat,&xlon,&xlst,&xf107a,&xf107,&xap[0],&xmass,
                  &xden[0],&xtemp[0]);
         #endif
         #ifdef DEBUG_MSISE90_ATMOSPHERE
            MessageInterface::ShowMessage("DONE calling gtd6_ ...\n");
         #endif
      #endif
      
      #ifdef DEBUG_MSISE90_ATMOSPHERE
      fprintf(logFile, "Post-GTDS6() \n");
      fprintf(logFile, "=========== \n");
      fprintf(logFile, "Epoch                  = %le \n", epoch);
      fprintf(logFile, "Year & Days            = %d \n", xyd);
      fprintf(logFile, "Seconds                = %le \n", xsod);
      fprintf(logFile, "Altitude               = %le \n", xalt);
      fprintf(logFile, "Latitude               = %le \n", xlat);
      fprintf(logFile, "Longitude              = %le \n", xlon);
      fprintf(logFile, "Solar Time             = %le \n", xlst);
      fprintf(logFile, "F107 Average           = %le \n", xf107a);
      fprintf(logFile, "F107                   = %le \n", xf107);
      fprintf(logFile, "Geomagnetic index[0]   = %le \n", xap[0]);
      fprintf(logFile, "Geomagnetic index[1]   = %le \n", xap[1]);
      fprintf(logFile, "Geomagnetic index[2]   = %le \n", xap[2]);
      fprintf(logFile, "Geomagnetic index[3]   = %le \n", xap[3]);
      fprintf(logFile, "Geomagnetic index[4]   = %le \n", xap[4]);
      fprintf(logFile, "Geomagnetic index[5]   = %le \n", xap[5]);
      fprintf(logFile, "Geomagnetic index[6]   = %le \n", xap[6]);
      fprintf(logFile, "Mass                   = %d \n", xmass);
      fprintf(logFile, "HE Number Density      = %le \n", xden[0]);
      fprintf(logFile, "O Number Density       = %le \n", xden[1]);
      fprintf(logFile, "N2 Number Density      = %le \n", xden[2]);
      fprintf(logFile, "O2 Number Density      = %le \n", xden[3]);
      fprintf(logFile, "AR Number Density      = %le \n", xden[4]);
      fprintf(logFile, "Total Mass Density     = %le \n", xden[5]);
      fprintf(logFile, "H Number Density       = %le \n", xden[6]);
      fprintf(logFile, "N Number Density       = %le \n", xden[7]);
      fprintf(logFile, "EXOSPHERIC Temperature = %le \n", xtemp[0]);
      fprintf(logFile, "Temperature at Alt     = %le \n", xtemp[1]);
      fprintf(logFile, "\n");
      fprintf(logFile, "\n");
      #endif
      
      density[i] = xden[5] * 1000.0;

      #ifdef DEBUG_FIRSTCALL
         if (firstcall)
         {
            MessageInterface::ShowMessage("==================================\n");
            MessageInterface::ShowMessage("MSISE90 Model, First call data:\n");
            MessageInterface::ShowMessage("   Year/DOY:    %d\n", xyd);
            MessageInterface::ShowMessage("   SOD:         %.12lf\n", xsod);
            MessageInterface::ShowMessage("   MJD:         %.12lf\n", epoch);
            MessageInterface::ShowMessage("   Altitude:    %.12lf\n", xalt);
            MessageInterface::ShowMessage("   Density:     %.12le\n", density[0]*1e9);
            MessageInterface::ShowMessage("   F10.7:       %.12lf\n", xf107);
            MessageInterface::ShowMessage("   F10.7a:      %.12lf\n", xf107a);
            MessageInterface::ShowMessage("   Ap:          [%lf %lf %lf %lf "
                  "%lf %lf %lf]\n", xap[0], xap[1], xap[2], xap[3], xap[4],
                  xap[5], xap[6]);
            MessageInterface::ShowMessage("==================================\n");

            firstcall = false;
         }
      #endif

      #ifdef DEBUG_MSISE90_ATMOSPHERE
         MessageInterface::ShowMessage(
            "   Altitude = %15.9lf  Density = %15.9le\n", alt, density[i]);
      #endif

      #ifdef DEBUG_NAN_CONDITIONS
         if (GmatMathUtil::IsNaN(xden[5]))
         {
            MessageInterface::ShowMessage("NAN found in MSISE90 "
                  "density element %d, Value is %lf at epoch %.12lf\n", j,
                  xden[5], epoch);
            MessageInterface::ShowMessage(
               "   Position:   %16.9le  %16.9le  %16.9le\n",
               pos[i6], pos[i6+1], pos[i6+2]);
            MessageInterface::ShowMessage("   Epoch                  = %le \n", epoch);
            MessageInterface::ShowMessage("   Year & Days            = %d \n", xyd);
            MessageInterface::ShowMessage("   Seconds                = %le \n", xsod);
            MessageInterface::ShowMessage("   Altitude               = %le \n", xalt);
            MessageInterface::ShowMessage("   Latitude               = %le \n", xlat);
            MessageInterface::ShowMessage("   Longitude              = %le \n", xlon);
            MessageInterface::ShowMessage("   Solar Time             = %le \n", xlst);
            MessageInterface::ShowMessage("   F107 Average           = %le \n", xf107a);
            MessageInterface::ShowMessage("   F107                   = %le \n", xf107);
            MessageInterface::ShowMessage("   Geomagnetic index[0]   = %le \n", xap[0]);
            MessageInterface::ShowMessage("   Geomagnetic index[1]   = %le \n", xap[1]);
            MessageInterface::ShowMessage("   Geomagnetic index[2]   = %le \n", xap[2]);
            MessageInterface::ShowMessage("   Geomagnetic index[3]   = %le \n", xap[3]);
            MessageInterface::ShowMessage("   Geomagnetic index[4]   = %le \n", xap[4]);
            MessageInterface::ShowMessage("   Geomagnetic index[5]   = %le \n", xap[5]);
            MessageInterface::ShowMessage("   Geomagnetic index[6]   = %le \n", xap[6]);
            MessageInterface::ShowMessage("   Mass                   = %d \n", xmass);
            MessageInterface::ShowMessage("   HE Number Density      = %le \n", xden[0]);
            MessageInterface::ShowMessage("   O Number Density       = %le \n", xden[1]);
            MessageInterface::ShowMessage("   N2 Number Density      = %le \n", xden[2]);
            MessageInterface::ShowMessage("   O2 Number Density      = %le \n", xden[3]);
            MessageInterface::ShowMessage("   AR Number Density      = %le \n", xden[4]);
            MessageInterface::ShowMessage("   Total Mass Density     = %le \n", xden[5]);
            MessageInterface::ShowMessage("   H Number Density       = %le \n", xden[6]);
            MessageInterface::ShowMessage("   N Number Density       = %le \n", xden[7]);
            MessageInterface::ShowMessage("   EXOSPHERIC Temperature = %le \n", xtemp[0]);
            MessageInterface::ShowMessage("   Temperature at Alt     = %le \n", xtemp[1]);
            MessageInterface::ShowMessage("\n");
         }
      #endif
   }
   
   #ifdef DEBUG_MSISE90_ATMOSPHERE
   fflush(logFile);
   fclose(logFile);
   #endif
   
   return true;
}
Beispiel #24
0
void DotNode::AssertMyInputsValid(void) const
{
    Assert(GetInputs()[0].GetSize() == GetInputs()[1].GetSize(), "The two inputs must be the same size!");
}
Beispiel #25
0
// Commit
//------------------------------------------------------------------------------
/*virtual*/ bool FunctionLibrary::Commit( NodeGraph & nodeGraph, const BFFIterator & funcStartIter ) const
{
    // make sure all required variables are defined
    const BFFVariable * outputLib;
    const BFFVariable * compiler;
    const BFFVariable * compilerOptions;
    AStackString<> compilerOptionsDeoptimized;
    AStackString<> compilerOutputPath;
    AStackString<> compilerOutputPrefix;
    const BFFVariable * compilerOutputExtension;
    const BFFVariable * librarian;
    const BFFVariable * librarianOptions;
    if ( !GetString( funcStartIter, outputLib, ".LibrarianOutput", true ) ||
         !GetString( funcStartIter, compiler, ".Compiler", true ) ||
         !GetString( funcStartIter, compilerOptions, ".CompilerOptions", true ) ||
         !GetString( funcStartIter, compilerOptionsDeoptimized, ".CompilerOptionsDeoptimized", false ) ||
         !GetString( funcStartIter, compilerOutputPath, ".CompilerOutputPath", true ) ||
         !GetString( funcStartIter, compilerOutputPrefix, ".CompilerOutputPrefix", false ) ||
         !GetString( funcStartIter, compilerOutputExtension, ".CompilerOutputExtension", false ) ||
         !GetString( funcStartIter, librarian, ".Librarian", true ) ||
         !GetString( funcStartIter, librarianOptions, ".LibrarianOptions", true ) )
    {
        return false;
    }

    PathUtils::FixupFolderPath( compilerOutputPath );

    // find or create the compiler node
    CompilerNode * compilerNode = nullptr;
    if ( !FunctionObjectList::GetCompilerNode( nodeGraph, funcStartIter, compiler->GetString(), compilerNode ) )
    {
        return false; // GetCompilerNode will have emitted error
    }

    // Compiler Force Using
    Dependencies compilerForceUsing;
    if ( !GetNodeList( nodeGraph, funcStartIter, ".CompilerForceUsing", compilerForceUsing, false ) )
    {
        return false; // GetNodeList will have emitted an error
    }

    // de-optimization setting
    bool deoptimizeWritableFiles = false;
    bool deoptimizeWritableFilesWithToken = false;
    if ( !GetBool( funcStartIter, deoptimizeWritableFiles, ".DeoptimizeWritableFiles", false, false ) )
    {
        return false; // GetBool will have emitted error
    }
    if ( !GetBool( funcStartIter, deoptimizeWritableFilesWithToken, ".DeoptimizeWritableFilesWithToken", false, false ) )
    {
        return false; // GetBool will have emitted error
    }
    if ( ( deoptimizeWritableFiles || deoptimizeWritableFilesWithToken ) && compilerOptionsDeoptimized.IsEmpty() )
    {
        Error::Error_1101_MissingProperty( funcStartIter, this, AStackString<>( ".CompilerOptionsDeoptimized" ) );
        return false;
    }

    // cache & distribution control
    bool allowDistribution( true );
    bool allowCaching( true );
    if ( !GetBool( funcStartIter, allowDistribution, ".AllowDistribution", true ) ||
         !GetBool( funcStartIter, allowCaching, ".AllowCaching", true ) )
    {
        return false; // GetBool will have emitted error
    }

    // Precompiled Header support
    ObjectNode * precompiledHeaderNode = nullptr;
    AStackString<> compilerOutputExtensionStr( compilerOutputExtension ? compilerOutputExtension->GetString().Get() : ".obj" );
    if ( !GetPrecompiledHeaderNode( nodeGraph, funcStartIter, compilerNode, compilerOptions, compilerForceUsing, precompiledHeaderNode, deoptimizeWritableFiles, deoptimizeWritableFilesWithToken, allowDistribution, allowCaching, compilerOutputExtensionStr ) )
    {
        return false; // GetPrecompiledHeaderNode will have emitted error
    }

    // Sanity check compile flags
    const bool usingPCH = ( precompiledHeaderNode != nullptr );
    uint32_t objFlags = ObjectNode::DetermineFlags( compilerNode, compilerOptions->GetString(), false, usingPCH );
    if ( ( objFlags & ObjectNode::FLAG_MSVC ) && ( objFlags & ObjectNode::FLAG_CREATING_PCH ) )
    {
        // must not specify use of precompiled header (must use the PCH specific options)
        Error::Error_1303_PCHCreateOptionOnlyAllowedOnPCH( funcStartIter, this, "Yc", "CompilerOptions" );
        return false;
    }

    // Check input/output for Compiler
    {
        bool hasInputToken = false;
        bool hasOutputToken = false;
        bool hasCompileToken = false;

        const AString & args = compilerOptions->GetString();
        Array< AString > tokens;
        args.Tokenize( tokens );
        for ( const AString & token : tokens )
        {
            if ( token.Find( "%1" ) )
            {
                hasInputToken = true;
            }
            else if ( token.Find( "%2" ) )
            {
                hasOutputToken = true;
            }
            else
            {
                if ( objFlags & ObjectNode::FLAG_MSVC )
                {
                    if ( ( token == "/c" ) || ( token == "-c" ) )
                    {
                        hasCompileToken = true;
                    }
                }
                else
                {
                    if ( token == "-c" )
                    {
                        hasCompileToken = true;
                    }
                }
            }
        }

        if ( hasInputToken == false )
        {
            Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "%1" );
            return false;
        }
        if ( hasOutputToken == false )
        {
            Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "%2" );
            return false;
        }

        // check /c or -c
        if ( objFlags & ObjectNode::FLAG_MSVC )
        {
            if ( hasCompileToken == false )
            {
                Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "/c or -c" );
                return false;
            }
        }
        else if ( objFlags & ( ObjectNode::FLAG_SNC | ObjectNode::FLAG_GCC | ObjectNode::FLAG_CLANG ) )
        {
            if ( hasCompileToken == false )
            {
                Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".CompilerOptions", "-c" );
                return false;
            }
        }
    }

    // Check input/output for Librarian
    {
        const AString & args = librarianOptions->GetString();
        bool hasInputToken = ( args.Find( "%1" ) || args.Find( "\"%1\"" ) );
        if ( hasInputToken == false )
        {
            Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".LibrarianOptions", "%1" );
            return false;
        }
        bool hasOutputToken = ( args.Find( "%2" ) || args.Find( "\"%2\"" ) );
        if ( hasOutputToken == false )
        {
            Error::Error_1106_MissingRequiredToken( funcStartIter, this, ".LibrarianOptions", "%2" );
            return false;
        }
    }

    // Get the (optional) Preprocessor & PreprocessorOptions
    const BFFVariable * preprocessor = nullptr;
    const BFFVariable * preprocessorOptions = nullptr;
    CompilerNode * preprocessorNode = nullptr;
    if ( !GetString( funcStartIter, preprocessor, ".Preprocessor", false ) )
    {
        return false; // GetString will have emitted an error
    }
    if ( preprocessor )
    {
        // get the preprocessor executable
        if ( !FunctionObjectList::GetCompilerNode( nodeGraph, funcStartIter, preprocessor->GetString(), preprocessorNode ) )
        {
            return false; // GetCompilerNode will have emitted an error
        }

        // get the command line args for the preprocessor
        if ( !GetString( funcStartIter, preprocessorOptions, ".PreprocessorOptions", true ) ) // required
        {
            return false; // GetString will have emitted an error
        }
    }

    // Pre-build dependencies
    Dependencies preBuildDependencies;
    if ( !GetNodeList( nodeGraph, funcStartIter, ".PreBuildDependencies", preBuildDependencies, false ) )
    {
        return false; // GetNodeList will have emitted an error
    }

    Dependencies staticDeps( 32, true );
    if ( !GetInputs( nodeGraph, funcStartIter, staticDeps ) )
    {
        return false; // GetStaticDeps will gave emitted error
    }

    // are the additional inputs to merge into the libaray?
    Dependencies additionalInputs;
    if ( !GetNodeList( nodeGraph, funcStartIter, ".LibrarianAdditionalInputs", additionalInputs, false ) )
    {
        return false;// helper will emit error
    }

    if ( staticDeps.IsEmpty() && additionalInputs.IsEmpty() )
    {
        Error::Error_1006_NothingToBuild( funcStartIter, this );
        return false;
    }

    uint32_t flags = LibraryNode::DetermineFlags( librarian->GetString() );

    // Create library node which depends on the single file or list
    if ( nodeGraph.FindNode( outputLib->GetString() ) )
    {
        Error::Error_1100_AlreadyDefined( funcStartIter, this, outputLib->GetString() );
        return false;
    }

    AStackString<> baseDirectory;
    if ( !GetBaseDirectory( funcStartIter, baseDirectory ) )
    {
        return false; // GetBaseDirectory will have emitted error
    }

    AStackString<> extraPDBPath, extraASMPath;
    GetExtraOutputPaths( compilerOptions->GetString(), extraPDBPath, extraASMPath );

    LibraryNode * libNode = nodeGraph.CreateLibraryNode( outputLib->GetString(),
                          staticDeps,
                          compilerNode,
                          compilerOptions->GetString(),
                          compilerOptionsDeoptimized,
                          compilerOutputPath,
                          librarian->GetString(),
                          librarianOptions->GetString(),
                          flags,
                          precompiledHeaderNode,
                          compilerForceUsing,
                          preBuildDependencies,
                          additionalInputs,
                          deoptimizeWritableFiles,
                          deoptimizeWritableFilesWithToken,
                          allowDistribution,
                          allowCaching,
                          preprocessorNode,
                          preprocessorOptions ? preprocessorOptions->GetString() : AString::GetEmpty(),
                          baseDirectory );
    if ( compilerOutputExtension )
    {
        libNode->m_ObjExtensionOverride = compilerOutputExtension->GetString();
    }
    libNode->m_CompilerOutputPrefix = compilerOutputPrefix;
    libNode->m_ExtraPDBPath = extraPDBPath;
    libNode->m_ExtraASMPath = extraASMPath;

    return ProcessAlias( nodeGraph, funcStartIter, libNode );
}
Beispiel #26
0
 double Evaluator::TestMinibatch(const std::unordered_map<Variable, MinibatchData>& arguments, std::unordered_map<Variable, ValuePtr>& outputsToFetch, const DeviceDescriptor& computeDevice)
 {
     return TestMinibatch(GetInputs(arguments), outputsToFetch, computeDevice);
 }