示例#1
0
int main(int argc, char *argv[]) {
  Vector Y;
  Matrix X;
  Matrix Cov;
  LoadVector("input.linear.mvt.y", Y);
  LoadMatrix("input.linear.mvt.x", X);
  LoadMatrix("input.linear.mvt.cov", Cov);

  {
    Matrix x;
    Vector y;
    x = X;
    y = Y;

    LinearRegressionVT linear;
    if (!linear.FitNullModel(Cov, Y)) {
      fprintf(stderr, "Fitting failed! - step 1!\n");
      return -1;
    }
    if (!linear.TestCovariate(Cov, Y, X)) {
      fprintf(stderr, "Fitting failed - step 2!\n");
      return -1;
    }

    dumpToFile(linear.GetU(), stdout);
    dumpToFile(linear.GetV(), stdout);
    dumpToFile(linear.GetT(), stdout);
    dumpToFile(linear.GetCov(), stdout);
    fprintf(stdout, "%g\t0\n", linear.GetPvalue(), 0);
  }
  return 0;
};
示例#2
0
int Generator::generatePackets(string inFileName, string outFileName)
{
	pcap_t *p;
	pcap_dumper_t *out_file;
	int packetsSize, amount;

	
	if (!parseXmlAndCreateObjects(inFileName))
		return 0;
	
	packetsSize = (int)packets.size();
	
	p = pcap_open_dead(1, 65536);
	out_file = pcap_dump_open(p, outFileName.c_str());

	for (int i = 0; i < packetsSize; i++)
	{
		amount = makeBytesVector(i); //funkcia vrati pocet, kolko ma byt podla xml vygenerovanych paketov (ch)
		bytesVector2BytesArray();
		dumpToFile(p,out_file, amount);
				
		bytesVector.clear();
		delete[] bytes;
	}
	
	return 1;
}
示例#3
0
	void LoggerFile::run()
	{
		bRunning=true;
		while(bRunning)
		{
			pendingMsgEvent.wait();
			dumpToFile();
		}
	}
示例#4
0
文件: foo.c 项目: pranavrc/PDoS
int main()
{
int j, k;
int noteArray[10];
for (j = 0; j < 10; j++) {
	noteArray[j] = (j + 1) * 100;
}

dumpToFile(noteArray, sizeof(noteArray), 10, "foo.wav");

return 1;
}
示例#5
0
void TreeWidget::displayMenu(const QPoint &pos)
{
    QModelIndex current = view->currentIndex();
    if(current.isValid())
    {
        QMenu menu(this);

        QAction *copyAction = nullptr;
        if(!currentItem().clipboardValue().isNull()) {
            copyAction = menu.addAction("Copy Value");
        }

        QAction *followLinkAction = nullptr;
        if (currentItem().hasLinkTo()) {
            followLinkAction = menu.addAction("Follow link");
        }

        QAction *openStreamAction = nullptr, *dumpStreamAction = nullptr;
        if(currentItem().hasStream()) {
            openStreamAction = menu.addAction("Open Stream");
            dumpStreamAction = menu.addAction("Dump Stream");
        }

        QAction *dumpToFileAction = menu.addAction("Dump to File");

        QAction *closeFileAction = menu.addAction("Close File");

        QAction *trigeredAction = menu.exec(view->viewport()->mapToGlobal(pos));

        if (!trigeredAction) {
            return;
        }

        if (trigeredAction == copyAction) {
            copy();
        } else if (trigeredAction == followLinkAction) {
            emit positionChanged(currentItem().linkTo(), 1);
            //model->updateByFilePosition(currentItem().linkTo()/8);
        } else if (trigeredAction == openStreamAction) {
            openStream();
        } else if (trigeredAction == dumpStreamAction) {
            dumpStreamToFile();
        } else if (trigeredAction == closeFileAction) {
            closeFile();
        } else if (trigeredAction == dumpToFileAction) {
            dumpToFile();
        }
    }
}
示例#6
0
void MvQueryRewriteHandler::dumpAnalysisToFile(QueryAnalysis* qa, RelExpr* expr)
{
  // Dump the QueryAnalysis data to a file.
  NAString analysisFileName = fileNamePrefix_ + ".analysis";
  NAString str;
  expr->unparse(str, OPTIMIZER_PHASE, MVINFO_FORMAT);
  str += "\n";
  str += qa->getText();

  // Add in some stuff to look at join predicates for the JBBCs.
  str += "Join Predicates\n";
  str += "===============";
  char buffer[20];
  ARRAY(JBB*) jbbs = qa->getJBBs();
  for (CollIndex jbbInx = 0; jbbInx < jbbs.entries(); jbbInx++)
    {
      JBB* jbb = jbbs[jbbInx];
      str_itoa(jbbInx, buffer);
      ((str += "\nJBB #") += NAString(buffer)) += ":\n";
      CANodeIdSet jbbcs = jbb->getJBBCs();
      for (CANodeId jbbcId=jbbcs.init();  jbbcs.next(jbbcId); jbbcs.advance(jbbcId) )
      {
        str_itoa(jbbcId, buffer);
        ((str += "\nJBBC with CANodeId ") += NAString(buffer)) += ":\n";
        ValueIdSet joinPreds = jbbcId.getNodeAnalysis()->getJBBC()->getJoinPreds();
        str += valueIdSetGetText(joinPreds);
        if (joinPreds.entries() > 0)
          {
            str.append("\n(value ids of predicates are ");
            NABoolean first = true;
            for (ValueId jpVid=joinPreds.init(); joinPreds.next(jpVid); joinPreds.advance(jpVid))
              {
                if (first)
                  first = FALSE;
                else
                  str.append(", ");
                str_itoa(jpVid, buffer);
                str.append(buffer);
              }
            str.append(")\n");
          }
      }
      str += '\n';
    }

  dumpToFile(analysisFileName.data(), str.data());
}  // dumpAnalysisToFile()
示例#7
0
void DumpRenderTree::dump()
{
    if (testDone)
        return;

    invalidateAnyPreviousWaitToDumpWatchdog();

    String dumpFile = m_resultsDir + *m_currentTest + ".dump";

    String resultMimeType = "text/plain";
    String responseMimeType = mainFrame->loader()->documentLoader()->responseMIMEType();

    bool dumpAsText = gTestRunner->dumpAsText() || responseMimeType == "text/plain";
    String data = dumpAsText ? dumpFramesAsText(mainFrame) : renderTreeDump();

    if (gTestRunner->dumpBackForwardList())
        data = data + dumpBackForwardListForWebView();

    String result = "Content-Type: " + resultMimeType + "\n" + data;

    dumpToFile(result);

    if (!runFromCommandLine) {
        // There are two scenarios for dumping pixels:
        // 1. When the test case explicitly asks for it by calling dumpAsText(true) with that extra true passed as a parameter value, from JavaScript
        bool explicitPixelResults = gTestRunner->dumpAsText() && gTestRunner->generatePixelResults();
        // 2. When the test case implicitly allows it by not calling dumpAsText() at all (with no parameters).
        bool implicitPixelResults = !gTestRunner->dumpAsText();

        // But only if m_enablePixelTests is set, to say that the user wants to run pixel tests at all.
        bool generatePixelResults = m_enablePixelTests && (explicitPixelResults || implicitPixelResults);
        if (generatePixelResults) {
            // signal end of text block
            fputs("#EOF\n", stdout);
            dumpWebViewAsPixelsAndCompareWithExpected(gTestRunner->expectedPixelHash());
        }

        String crashFile = dumpFile + ".crash";
        unlink(crashFile.utf8().data());

        String doneFile =  m_resultsDir + *m_currentTest + ".done";
        createFile(doneFile);
    }
    testDone = true;
    runRemainingTests();
}
示例#8
0
void dumpParams(symbol* sym, astree* root) {
    for(size_t i = 0; i<sym->parameters->size(); i++) {
        symbol* param = sym->parameters->at(i);
        if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
            symbol_table* tab = new symbol_table();
            tab->insert(symbol_entry(root->children[i]->children[0]->
                                     lexinfo,param));
            symbol_stack.pop_back();
            symbol_stack.push_back(tab);
        } else {
            symbol_stack.back()->insert(symbol_entry(root->children[i]->
                                        children[0]->lexinfo,param));
        }
        dumpToFile(file_sym, param, root->children[i]->children[0]);
    }
    fprintf(file_sym, "\n");
}
示例#9
0
int *bubbleSort(int list[], int length, float lengthOfBeat)
{
	int i, j, temp;
	int eachNote = 0;
	int *noteList;

	noteList = (int*) malloc(sizeof(int));

	while(!eachNote) {
		for (j = 0; j < length - 1; j++) {
			for (i = 0; i < length - j - 1; i++) {
				if (list[i] > list[i + 1]) {
					temp = list[i];
					list[i] = list[i + 1];
					list[i + 1] = temp;
					
					noteList = realloc(noteList, (eachNote + 1) * sizeof(int));
					
					noteList[eachNote] = list[i] * SCALING_FACTOR;
					noteList[eachNote + 1] = list[i + 1] * SCALING_FACTOR;

					eachNote = eachNote + 2;
	
					playNote(list[i] * SCALING_FACTOR, lengthOfBeat);
					playNote(list[i + 1] * SCALING_FACTOR, lengthOfBeat);
				}
			}
		}

		break;
	}

	int note;

	for (note = 0; note < eachNote; note++) {
		printf("%d\n", noteList[note]);
	}

	dumpToFile(noteList, eachNote * sizeof(int), lengthOfBeat, "sounds/bubbleSort.wav");

	int *listptr;

	listptr = &list[0];

	return listptr;
}
示例#10
0
void PointwiseRecorder::record(int tstep, double t) {
    if (tstep % mRecordInterval != 0) {
        return;
    }
    
    // time
    mBufferTime(mBufferLine) = t;
    
    // get disp
    static RRow3 gm;
    for (int irec = 0; irec < mPointwiseInfo.size(); irec++) {
        // compute from element, in SPZ
        mPointwiseInfo[irec].mElement->computeGroundMotion(mPointwiseInfo[irec].mPhi, 
            mPointwiseInfo[irec].mWeights, gm);
        if (mComponents != "SPZ") {
            // transform
            Real cost = cos(mPointwiseInfo[irec].mTheta);
            Real sint = sin(mPointwiseInfo[irec].mTheta);
            Real ur = gm(0) * sint + gm(2) * cost; 
            Real ut = gm(0) * cost - gm(2) * sint;
            if (mComponents == "ENZ") {
                Real cosbaz = cos(mPointwiseInfo[irec].mBAz);
                Real sinbaz = sin(mPointwiseInfo[irec].mBAz);
                gm(0) = -ut * sinbaz + gm(1) * cosbaz;
                gm(1) = -ut * cosbaz - gm(1) * sinbaz;
                gm(2) = ur;
            } else { 
                // RTZ
                gm(0) = ut;
                gm(2) = ur;
            }
        }    
        // write to buffer
        mBufferDisp.block(mBufferLine, irec * 3, 1, 3) = gm;
    }
    
    // get strain
    static RRow6 strain;
    int istrain = 0;
    for (int irec = 0; irec < mPointwiseInfo.size(); irec++) {
        if (mPointwiseInfo[irec].mDumpStrain) {
            // compute from element, in RTZ
            mPointwiseInfo[irec].mElement->computeStrain(mPointwiseInfo[irec].mPhi, 
                mPointwiseInfo[irec].mWeights, strain);
            // write to buffer
            mBufferStrain.block(mBufferLine, istrain * 6, 1, 6) = strain;
            istrain++;
        }
    }
    
    // get curl
    static RRow3 curl;
    int icurl = 0;
    for (int irec = 0; irec < mPointwiseInfo.size(); irec++) {
        if (mPointwiseInfo[irec].mDumpCurl) {
            // compute from element, in RTZ
            mPointwiseInfo[irec].mElement->computeCurl(mPointwiseInfo[irec].mPhi, 
                mPointwiseInfo[irec].mWeights, curl);
            if (mComponents == "ENZ") {
                // transform
                Real ur = curl(2);
                Real ut = curl(0);
                Real up = curl(1);
                Real cosbaz = cos(mPointwiseInfo[irec].mBAz);
                Real sinbaz = sin(mPointwiseInfo[irec].mBAz);
                curl(0) = -ut * sinbaz + up * cosbaz;
                curl(1) = -ut * cosbaz - up * sinbaz;
                curl(2) = ur;
            }        
            // write to buffer
            mBufferCurl.block(mBufferLine, icurl * 3, 1, 3) = curl;
            icurl++;
        }
    }
    
    // increment buffer line
    mBufferLine++;
    
    // dump and clear buffer
    if (mBufferLine == mBufferSize) {
        dumpToFile();
    }
}
示例#11
0
void travVardecl(astree* root) {
    astree* node = root->children[0];
    astree* node1 = root->children[1];
    root->block = blockcount;
    int sym = node->symbol;
    int otherSym = getReturnType(node1);
    switch(sym) {
    case TOK_INT:
        checkDecl(node);
        if(otherSym==TOK_INTCON || otherSym==TOK_NULL) {
            symbol *newSym = create_symbol(node->children[0]);
            newSym->attributes.set(ATTR_int);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[0]->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[0]->
                                            lexinfo,newSym));
            }
            dumpToFile(file_sym, newSym, node->children[0]);
        } else if(otherSym == TOK_NEWARRAY) {
            insertArr(node, node1);
        }
        break;

    case TOK_CHAR:
        checkDecl(node);
        if(otherSym==TOK_CHARCON || otherSym==TOK_NULL) {
            symbol *newSym = create_symbol(node->children[0]);
            newSym->attributes.set(ATTR_char);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[0]->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[0]->
                                            lexinfo,newSym));
            }
            dumpToFile(file_sym, newSym, node->children[0]);
        } else if(otherSym == TOK_NEWARRAY) {
            insertArr(node, node1);
        }
        break;

    case TOK_BOOL:
        checkDecl(node);
        if(otherSym==TOK_TRUE ||
                otherSym==TOK_FALSE || otherSym==TOK_NULL) {
            symbol *newSym = create_symbol(node->children[0]);
            newSym->attributes.set(ATTR_bool);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[0]->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[0]->
                                            lexinfo,newSym));
            }
            dumpToFile(file_sym, newSym, node->children[0]);
        } else if (otherSym == TOK_NEWARRAY) {
            insertArr(node, node1);
        }
        break;
    case TOK_STRING:
        checkDecl(node);
        if(otherSym == TOK_NEWSTRING) {
            if(node1->children[0]->symbol == TOK_INTCON ||
                    otherSym==TOK_NULL) {
                symbol *newSym = create_symbol(node->children[0]);
                newSym->attributes.set(ATTR_string);
                newSym->attributes.set(ATTR_lval);
                newSym->attributes.set(ATTR_variable);
                if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                    symbol_table* tab = new symbol_table();
                    tab->insert(symbol_entry(node->children[0]
                                             ->lexinfo,newSym));
                    symbol_stack.pop_back();
                    symbol_stack.push_back(tab);
                } else {
                    symbol_stack.back()->insert(symbol_entry(node->children[0]->
                                                lexinfo,newSym));
                }
                dumpToFile(file_sym, newSym, node->children[0]);
            } else {
                errprintf("%zu.%zu.%zu String size allocator not of "
                          "type int.\n",
                          node1->children[1]->filenr, node1->children[1]->linenr,
                          node1->children[1]->offset);
            }
        } else if (otherSym == TOK_STRINGCON || otherSym==TOK_NULL) {
            if(otherSym!=TOK_NULL)
                strvec.push_back(node1->lexinfo);
            symbol *newSym = create_symbol(node->children[0]);
            newSym->attributes.set(ATTR_string);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[0]->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[0]->
                                            lexinfo,newSym));
            }

            dumpToFile(file_sym, newSym, node->children[0]);
        } else if(otherSym == TOK_NEWARRAY) {
            insertArr(node, node1);
        }
        break;
    case TOK_TYPEID:
        if(otherSym == TOK_TYPEID || otherSym==TOK_NULL
                || otherSym == TOK_STRUCT) {
            if(node1->symbol != TOK_CALL) {
                string leftStr = *node->lexinfo;
                string rightStr = *node1->children[0]->lexinfo;
                if(leftStr != rightStr) {
                    errprintf("%zu.%zu.%zu Type mismatch between constructor "
                              "and declaration.\n",
                              node1->children[1]->filenr, node1->children[1]->linenr,
                              node1->children[1]->offset);
                }
            } else {
                if(lookup(node1->children[0]->lexinfo)) {
                    symbol* funcSym = lookupSym(node1->children[0]->lexinfo);
                    string leftStr = *node->lexinfo;
                    string rightStr = funcSym->type_id;
                    if(leftStr != rightStr) {
                        errprintf("%zu.%zu.%zu Type mismatch between constructor "
                                  "and declaration.\n",
                                  node1->children[1]->filenr, node1->children[1]->linenr,
                                  node1->children[1]->offset);
                    }
                }
            }
            symbol *newSym = create_symbol(node->children[0]);
            newSym->attributes.set(ATTR_struct);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_variable);
            newSym->type_id = *node->lexinfo;
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[0]->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[0]->
                                            lexinfo,newSym));
            }

            dumpToFile(file_sym, newSym, node->children[0]);
        } else {
            errprintf("%zu.%zu.%zu Variable not allocated correctly.\n",
                      node1->children[1]->filenr, node1->children[1]->linenr,
                      node1->children[1]->offset);
        }
        break;
    case TOK_IDENT:
        if(lookup(node->lexinfo)) {
            symbol* newSym = lookupSym(node->lexinfo);
            int type = getIdentReturn(newSym);
            if(type==TOK_STRUCT&&otherSym==TOK_TYPEID) {
                if(newSym->type_id!=*node1->children[0]->lexinfo) {
                    errprintf("%zu.%zu.%zu Variable being reassigned wrong "
                              "type",node->filenr,node->linenr,node->offset);
                }
            }
        } else {
            errprintf("%zu.%zu.%zu"
                      " Variable being referenced is undefined\n",node->filenr,
                      node->linenr,node->offset);
        }
    }
}
示例#12
0
void traverseAstree(astree* root) {
    if( flag == 0 ) {
        symbol_stack.push_back(nullptr);
        flag++;
    }
    for (size_t a = 0; a < root->children.size(); ++a) {
        int sym = root->children[a]->symbol;
        astree* curr = root->children[a];
        switch(sym) {
        case TOK_VARDECL:
        case '=':
            travVardecl(curr);
            break;
        case TOK_IF:
        case TOK_WHILE:
            validCompare(curr);
            symbol_stack.push_back(nullptr);
            blockcount++;
            traverseAstree(curr->children[1]);
            blockcount--;
            symbol_stack.pop_back();
            break;
        case TOK_IFELSE:
            validCompare(curr);
            for(size_t i = 0; i<curr->children.size(); i++) {
                symbol_stack.push_back(nullptr);
                blockcount++;
                traverseAstree(curr->children[i]);
                blockcount--;
                symbol_stack.pop_back();
            }
            break;
        case TOK_FUNCTION:
        {
            root->children[a]->children[1]->block = blockcount+1;
            symbol* newFunc = create_symbol(root->children[a]);
            blockcount++;
            newFunc->attributes.set(ATTR_function);
            switch(curr->children[0]->symbol) {
            case TOK_INT:
                newFunc->attributes.set(ATTR_int);
                break;
            case TOK_STRING:
                newFunc->attributes.set(ATTR_string);
                break;
            case TOK_CHAR:
                newFunc->attributes.set(ATTR_char);
                break;
            case TOK_BOOL:
                newFunc->attributes.set(ATTR_bool);
                break;
            case TOK_TYPEID:
                newFunc->attributes.set(ATTR_struct);
                newFunc->attributes.set(ATTR_typeid);
                newFunc->type_id =*root->children[a]->children[0]->lexinfo;
                break;
            }
            newFunc->parameters = new vector<symbol*>;
            for(size_t i = 0; i<curr->children[1]->children.size(); i++) {
                astree* param_node = curr->children[1]->children[i];
                symbol* param = create_symbol(param_node->children[0]);
                param->attributes.set(ATTR_variable);
                param->attributes.set(ATTR_lval);
                param->attributes.set(ATTR_param);
                int paramSym = param_node->symbol;
                switch(paramSym) {
                case TOK_INT:
                    param->attributes.set(ATTR_int);
                    break;
                case TOK_CHAR:
                    param->attributes.set(ATTR_char);
                    break;
                case TOK_STRING:
                    param->attributes.set(ATTR_string);
                    break;
                case TOK_BOOL:
                    param->attributes.set(ATTR_bool);
                    break;
                }
                newFunc->parameters->push_back(param);
            }
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(curr->children[0]->children[0]->
                                         lexinfo,newFunc));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(curr->children[0]->
                                            children[0]->lexinfo,newFunc));
            }
            dumpToFile(file_sym, newFunc, curr->children[0]->children[0]);
            symbol_stack.push_back(nullptr);
            if (curr->children[1]->children.size() != 0) {
                dumpParams(newFunc, curr->children[1]);
            }
            int funcSym;
            switch (curr->children[0]->symbol) {
            case TOK_INT:
                funcSym = TOK_INTCON;
                break;
            case TOK_CHAR:
                funcSym = TOK_CHARCON;
                break;
            case TOK_STRING:
                funcSym = TOK_STRINGCON;
                break;
            case TOK_BOOL:
                funcSym = TOK_BOOL;
                break;
            }
            traverseFunc(curr->children[2], funcSym);
            blockcount--;
            symbol_stack.pop_back();
            break;
        }
        case TOK_STRUCT:
        {
            astree *temp = root->children[a];
            symbol *newSym = create_symbol(temp->children[0]);
            newSym->attributes.set(ATTR_struct);
            newSym->attributes.set(ATTR_typeid);
            newSym->type_id = *temp->children[0]->lexinfo;
            dumpToFile(file_sym,newSym,temp->children[0]);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(temp->children[0]->lexinfo,newSym));
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(temp->children[0]->
                                            lexinfo,newSym));
            }
            newSym->fields = new symbol_table();
            for(size_t i = 1; i<temp->children.size(); i++) {
                symbol *tempSym = create_symbol(temp->children[i]->
                                                children[0]);
                tempSym->attributes.set(ATTR_field);
                switch(temp->children[i]->symbol) {
                case TOK_INT:
                    tempSym->attributes.set(ATTR_int);
                    break;
                case TOK_CHAR:
                    tempSym->attributes.set(ATTR_char);
                    break;
                case TOK_BOOL:
                    tempSym->attributes.set(ATTR_bool);
                    break;
                case TOK_STRING:
                    tempSym->attributes.set(ATTR_string);
                    break;
                case TOK_TYPEID:
                    tempSym->attributes.set(ATTR_typeid);
                    tempSym->attributes.set(ATTR_struct);
                    break;
                }
                newSym->fields->insert(symbol_entry(temp->children[i]->
                                                    children[0]->lexinfo,tempSym));
            }
            dumpFields(newSym,temp);
            break;
        }
        case TOK_CALL:
            checkCall(curr);
            break;
        case TOK_PROTOTYPE:
        {
            symbol* newFunc = create_symbol(root->children[a]);
            blockcount++;
            newFunc->attributes.set(ATTR_function);
            switch(curr->children[0]->symbol) {
            case TOK_INT:
                newFunc->attributes.set(ATTR_int);
                break;
            case TOK_STRING:
                newFunc->attributes.set(ATTR_string);
                break;
            case TOK_CHAR:
                newFunc->attributes.set(ATTR_char);
                break;
            case TOK_BOOL:
                newFunc->attributes.set(ATTR_bool);
                break;
            case TOK_TYPEID:
                newFunc->attributes.set(ATTR_struct);
                newFunc->attributes.set(ATTR_typeid);
                newFunc->type_id =*root->children[a]->children[0]->lexinfo;
                break;
            }
            newFunc->parameters = new vector<symbol*>;
            for(size_t i = 0; i<curr->children[1]->children.size(); i++) {
                astree* param_node = curr->children[1]->children[i];
                symbol* param = create_symbol(param_node->children[0]);
                param->attributes.set(ATTR_variable);
                param->attributes.set(ATTR_lval);
                param->attributes.set(ATTR_param);
                int paramSym = param_node->symbol;
                switch(paramSym) {
                case TOK_INT:
                    param->attributes.set(ATTR_int);
                    break;
                case TOK_CHAR:
                    param->attributes.set(ATTR_char);
                    break;
                case TOK_STRING:
                    param->attributes.set(ATTR_string);
                    break;
                case TOK_BOOL:
                    param->attributes.set(ATTR_bool);
                    break;
                }
                newFunc->parameters->push_back(param);
            }
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(curr->children[0]->children[0]->
                                         lexinfo,newFunc));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(curr->children[0]->
                                            children[0]->lexinfo,newFunc));
            }
            dumpToFile(file_sym, newFunc, curr->children[0]->children[0]);
            symbol_stack.push_back(nullptr);
            if (curr->children[1]->children.size() != 0) {
                dumpParams(newFunc, curr->children[1]);
            }
            int funcSym;
            switch (curr->children[0]->symbol) {
            case TOK_INT:
                funcSym = TOK_INTCON;
                break;
            case TOK_CHAR:
                funcSym = TOK_CHARCON;
                break;
            case TOK_STRING:
                funcSym = TOK_STRINGCON;
                break;
            case TOK_BOOL:
                funcSym = TOK_BOOL;
                break;
            }
            blockcount--;
            break;
        }
        }
    }
}
示例#13
0
int MultivariateVT::compute(Vector& freq, Matrix& U, Matrix& V) {
  if (freq.Length() != U.rows || freq.Length() != V.rows || U.cols != 1 ||
      V.rows != V.cols) {
    return -1;
  }

  const int numFreq = freq.Length();
  int numKeep = 0;
  std::set<int> skip;
  std::set<int>
      freqTable;  // to avoid float numeric comparison, store maf * 1e6
  maf.Dimension(numFreq);
  for (int i = 0; i < numFreq; ++i) {
    maf[i] = freq[i] < 0.5 ? freq[i] : 1.0 - freq[i];
    if (maf[i] < 1e-10) {
      skip.insert(i);
      continue;
    }
    if (V[i][i] < 1e-10) {
      skip.insert(i);
      continue;
    }
    int mafInt = ceil(maf[i] * 1000000);
    if (freqTable.count(mafInt)) {
      continue;
    }
    freqTable.insert(mafInt);
    numKeep++;
  }

#ifdef DEBUG
  fprintf(stderr, "numFreq = %d\n", numFreq);
  fprintf(stderr, "numKeep = %d\n", numKeep);
#endif

  if (numKeep == 0) {
    return -1;
  }

  cutoff.Dimension(numKeep);
  // phi[i][j] = 1 means at maf[i] < cutoff[j]
  phi.Dimension(numFreq, numKeep);

  int j = 0;
  for (std::set<int>::const_iterator it = freqTable.begin();
       it != freqTable.end(); ++it) {
    cutoff[j++] = 1.0 * (*it) / 1000000;
  }

  for (int i = 0; i < numFreq; ++i) {
    for (int j = 0; j < numKeep; ++j) {
      if (skip.count(i) > 0) {
        phi[i][j] = 0.;
        continue;
      }
      if (maf[i] <= cutoff[j]) {
        phi[i][j] = 1.;
      } else {
        phi[i][j] = 0.;
      }
    }
  }

  // u_phi = t(U) * phi
  Matrix tmp;
  tmp.Transpose(U);
  this->u_phi.Product(tmp, phi);

  // v_phi = t(phi) * v * phi
  Matrix phiT;
  phiT.Transpose(phi);
  tmp.Product(phiT, V);
  this->v_phi.Product(tmp, phi);

  int maxIdx = -1;
  double maxVal = -DBL_MAX;
  for (int i = 0; i < numKeep; ++i) {
    double t = fabs(u_phi[0][i] / sqrt(v_phi[i][i]));
    if (t > maxVal) {
      maxIdx = i;
      maxVal = t;
    }
  }

#ifdef DEBUG
  dumpToFile(freq, "freq");
  dumpToFile(cutoff, "cutoff");
  dumpToFile(U, "U");
  dumpToFile(V, "V");
  dumpToFile(phi, "phi");
  dumpToFile(u_phi, "u.phi");
  dumpToFile(v_phi, "v.phi");
#endif

  this->minMAF = maf.Min();
  this->maxMAF = maf.Max();
  this->optimalMAF = cutoff[maxIdx];
  this->optimalU = u_phi[0][maxIdx];
  this->optimalV = v_phi[maxIdx][maxIdx];
  this->stat = maxVal;

  this->optimalNumVar = 0;
  for (int i = 0; i < numFreq; ++i) {
    if (phi[i][maxIdx] > 0) ++this->optimalNumVar;
  }

  if (this->mvn.getBandProbFromCov(-maxVal, maxVal, this->v_phi,
                                   &this->pvalue)) {
    this->pvalue = -1;  // failed
    return -1;
  }
  this->pvalue = 1.0 - this->pvalue;
  return 0;
}
示例#14
0
int SaddlePointApproximation::calculatePvalue(const Eigen::MatrixXf& g_tilde,
                                              float* newPvalue) {
  // find root
  // 1. find boundary of the root
  //    first try [0, 5] or [0, -5]
  const float s = (g_tilde.array() * resid_.array()).sum();
  const float var_s =
      (g_tilde.array().square() * (mu_.array() * (1.0 - mu_.array())).abs())
          .sum();
  // if (fabs(s) < 2.0 * sqrt(var_s) &&
  // !std::getenv("BOLTLMM_FORCE_SADDLEPOINT")) {
  //   fprintf(stderr, "Skip saddle point approximation (far from mean, |%g| >
  //   2.0 * sqrt(%g) )!\n", s, var_s);
  //   return -2;
  // }
  float t_grid[2];
  float y_grid[2];
  if (s > 0) {  // \hat{t} > 0
    t_grid[0] = -0.01;
    t_grid[1] = std::min(s / K_prime2_function(0, g_tilde, mu_), (float)5.);

  } else {
    t_grid[0] = 0.01;
    t_grid[1] = std::max(s / K_prime2_function(0, g_tilde, mu_), (float)-5.);
  }
  y_grid[0] = CGF_equation(t_grid[0], g_tilde, mu_, y_);
  y_grid[1] = CGF_equation(t_grid[1], g_tilde, mu_, y_);

  int iter = 0;
  // extend boundary
  // e.g. [0, 5] => [5, 15] => [15, 60]...
  while (y_grid[0] * y_grid[1] > 0) {
    t_grid[0] = t_grid[1];
    y_grid[0] = y_grid[1];
    t_grid[1] *= 4;
    y_grid[1] = CGF_equation(t_grid[1], g_tilde, mu_, y_);

    ++iter;
    fprintf(stderr, "iter %d, %g -> %g \n", iter, t_grid[1], y_grid[1]);

    if (iter > 10) {
      fprintf(stderr,
              "after 10 iteration, still cannot find boundary conditions\n");
      dumpToFile(y_, "tmp.y");
      dumpToFile(g_tilde, "tmp.g_tilde");
      dumpToFile(mu_, "tmp.mu");
      dumpToFile(resid_, "tmp.resid");
      return 1;  // exit(1);
    }
  }
  if (t_grid[0] > t_grid[1]) {
    std::swap(t_grid[0], t_grid[1]);
    std::swap(y_grid[0], y_grid[1]);
  }
  assert(y_grid[0] < 0 && y_grid[1] > 0);  // TODO: make this more robust
  if (y_grid[0] * y_grid[1] > 0) {
    fprintf(stderr, "Wrong boundary conditions!\n");
    // dumpToFile(covEffect, "tmp.covEffect");
    // dumpToFile(xbeta, "tmp.xbeta");
    dumpToFile(g_tilde, "tmp.g_tilde");
    dumpToFile(mu_, "tmp.mu");
    dumpToFile(resid_, "tmp.resid");
    // exit(1);
    return 1;
  }
  float t_new = t_grid[0];
  float y_new;
  iter = 0;
  // stop condition:
  // 1. secant method narrows to a small enough region
  // 2. new propose point has the differnt sign of statistic s. Usually they
  // have the same sign. Unless numerical issue arises.
  while (fabs(t_grid[1] - t_grid[0]) > 1e-3 || t_new * s < 0) {
    t_new = t_grid[0] +
            (t_grid[1] - t_grid[0]) * (-y_grid[0]) / (y_grid[1] - y_grid[0]);

    // switch to bisect?
    const float dist = t_grid[1] - t_grid[0];
    if (t_grid[1] - t_new < 0.1 * dist) {
      t_new = t_grid[0] + (t_grid[1] - t_grid[0]) * 0.8;
    }
    if (t_new - t_grid[0] < 0.1 * dist) {
      t_new = t_grid[0] + (t_grid[1] - t_grid[0]) * 0.2;
    }

    y_new = CGF_equation(t_new, g_tilde, mu_, y_);
    if (y_new == 0) {
      break;
    } else if (y_new > 0) {
      t_grid[1] = t_new;
      y_grid[1] = y_new;
    } else if (y_new < 0) {
      t_grid[0] = t_new;
      y_grid[0] = y_new;
    }
    ++iter;
    fprintf(stderr, "%g -> %g, %g -> %g \n", t_grid[0], y_grid[0], t_grid[1],
            y_grid[1]);

    if (iter > 10) {
      fprintf(stderr,
              "after 10 iteration, secant method still cannot find solution\n");
      dumpToFile(y_, "tmp.y");
      dumpToFile(g_tilde, "tmp.g_tilde");
      dumpToFile(mu_, "tmp.mu");
      dumpToFile(resid_, "tmp.resid");
      break;
    }
  }
  if (fabs(t_new) < 1e-4 && !std::getenv("BOLTLMM_FORCE_SADDLEPOINT")) {
    fprintf(stderr, "Skip saddle point approximation (t is too small: %g)\n",
            t_new);
    return -3;
  }

  // calculate new p_value
  const float K = K_function(t_new, g_tilde, mu_);
  const float K_prime2 = K_prime2_function(t_new, g_tilde, mu_);
  float w = sqrt(2 * (t_new * s - K));
  if (t_new < 0) {
    w = -w;
  }
  const float v = t_new * sqrt(K_prime2);
  assert(v / w > 0);

  float stat = w + log(v / w) / w;
  stat = stat * stat;

  if (t_new * s < K) {
    fprintf(stderr, "Wrong sqrt operand!\n");
    fprintf(stderr,
            "K = %g, K_prime2 = %g, s = %g, t_new = %g, w = %g, v = %g, stat "
            "= %g\n",
            K, K_prime2, s, t_new, w, v, stat);

    dumpToFile(g_tilde, "tmp.g_tilde");
    dumpToFile(mu_, "tmp.mu");
    dumpToFile(resid_, "tmp.resid");
    return 1;
    // exit(1);
  }
  if (std::getenv("BOLTLMM_DUMP_SADDLEPOINT")) {
    fprintf(stderr, "%s:%d dump saddlepoint\n", __FILE__, __LINE__);
    dumpToFile(g_tilde, "tmp.g_tilde");
    dumpToFile(mu_, "tmp.mu");
    dumpToFile(resid_, "tmp.resid");
  }
  fprintf(stderr,
          "K = %g, K_prime2 = %g, s = %g, t = %g, w = %g, v = %g, stat = %g\n",
          K, K_prime2, s, t_new, w, v, stat);
  float& pvalue_ = *newPvalue;
  pvalue_ = gsl_cdf_chisq_Q(stat, 1.0);
  return 0;
}
示例#15
0
文件: main.c 项目: Linhu86/mempool
int main()
{
  UComInt32 res;
  MemParam_t params;

  MemoryPool_t mem;
  MemoryPool_t *p_mem = &mem;
  MemoryPool_t ** pmem = &p_mem;

  MemoryPool_t mem2;
  MemoryPool_t *p_mem2 = &mem2;
  MemoryPool_t ** pmem2 = &p_mem2;


  UComUInt32 *ptr = NULL;
  UComUInt32 *ptr2 = NULL;


  UCOM_OSMEM_ALLOC_POOL_MEMAREA_STATIC(test1, 1024);
  UCOM_OSMEM_ALLOC_POOL_MEMAREA_STATIC(test2, 10240);

  UComOsMemCreatePool(pmem, test1, 1024);

  UComOsMemAlloc(*pmem, 200, (void **)&(ptr));

  UComOsMemAlloc(*pmem, 200, (void **)&(ptr2));

  memory_pool_info(*pmem);

  UComOsMemFree(ptr);

  UComOsMemAlloc(*pmem, 100, (void **)&(ptr));

  memory_pool_info(*pmem);

  UComOsMemFree(ptr);

  memory_pool_info(*pmem);

  dumpToFile("dump.txt", *pmem, 8, DUMP_HEX);


  /* test pool 2 */
  UComOsMemCreatePool(pmem2, test2, 10240);

  UComOsMemAlloc(*pmem2, 200, (void **)&(ptr2));

  memory_pool_info(*pmem2);

  UComOsMemFree(ptr2);

  UComOsMemAlloc(*pmem2, 100, (void **)&(ptr2));

  memory_pool_info(*pmem2);

  UComOsMemFree(ptr2);

  memory_pool_info(*pmem2);

  dumpToFile("dump2.txt", *pmem2, 8, DUMP_HEX);

  UComOsMemDeletePool(*pmem);

  UComOsMemDeletePool(*pmem2);

  return 0;
}
示例#16
0
void XmlElement::dump() const {
	dumpToFile(stdout);
} // dump
示例#17
0
void insertArr(astree* node, astree* node1) {
    if(typechkArr(node, node1)) {
        int arrSym = node->symbol;
        switch (arrSym) {
        case TOK_INT:
        {
            symbol *newSym = create_symbol(node->children[1]);

            newSym->attributes.set(ATTR_int);
            newSym->attributes.set(ATTR_array);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[1]
                                         ->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[1]->
                                            lexinfo,newSym));
            }
            dumpToFile(file_sym, newSym, node->children[1]);
            break;
        }
        case TOK_CHAR:
        {
            symbol *newSym = create_symbol(node->children[1]);
            newSym->attributes.set(ATTR_char);
            newSym->attributes.set(ATTR_array);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[1]
                                         ->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[1]->
                                            lexinfo,newSym));
            }
            dumpToFile(file_sym, newSym, node->children[1]);
            break;
        }

        case TOK_BOOL:
        {
            symbol *newSym = create_symbol(node->children[1]);
            newSym->attributes.set(ATTR_bool);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_array);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[1]
                                         ->lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[1]->
                                            lexinfo,newSym));
            }
            dumpToFile(file_sym, newSym, node->children[1]);
            break;
        }
        case TOK_STRING:
        {
            symbol *newSym = create_symbol(node->children[1]);
            newSym->attributes.set(ATTR_string);
            newSym->attributes.set(ATTR_lval);
            newSym->attributes.set(ATTR_array);
            newSym->attributes.set(ATTR_variable);
            if(symbol_stack.back() == nullptr || symbol_stack.empty()) {
                symbol_table* tab = new symbol_table();
                tab->insert(symbol_entry(node->children[1]->
                                         lexinfo,newSym));
                symbol_stack.pop_back();
                symbol_stack.push_back(tab);
            } else {
                symbol_stack.back()->insert(symbol_entry(node->children[1]->
                                            lexinfo,newSym));
            }
            dumpToFile(file_sym, newSym, node->children[1]);
        }
        }
    }
}