예제 #1
0
파일: ai_measurement.cpp 프로젝트: 8l/rose
 int FPCounters::getCount (fp_operation_kind_enum c_type = e_total)
 {
   switch (c_type)
   {
     case e_total: 
       return getTotalCount();
       break;
     case e_plus:
       return getPlusCount();
       break;
     case e_minus:
       return getMinusCount();
       break;
     case e_multiply:
       return getMultiplyCount();
       break;
     case e_divide:
       return getDivideCount();
       break;
     default:
       assert (false);  
   }
   assert (false);  
   return 0;
 }
예제 #2
0
파일: ai_measurement.cpp 프로젝트: 8l/rose
 string FPCounters::toString(std::string comment)
 {
   stringstream ss; 
   ss<<"----------Floating Point Operation Counts---------------------"<<endl;
   ss<<comment<<endl;
   //cout<<"Floating point operations found for node "<<node->class_name() <<"@" <<endl;
   ss<<node->class_name() <<"@" <<endl;
   ss<< node->get_file_info()->get_filename()<<":"<<node->get_file_info()->get_line() <<endl;
   ss<<"\tfp_plus:"<< plus_count<<endl;
   ss<<"\tfp_minus:"<< minus_count<<endl;
   ss<<"\tfp_multiply:"<< multiply_count<<endl;
   ss<<"\tfp_divide:"<< divide_count<<endl;
   ss<<"\tfp_total:"<< getTotalCount()<<endl;

   return ss.str();
 }
예제 #3
0
파일: ai_measurement.cpp 프로젝트: 8l/rose
 void FPCounters::printInfo(std::string comment/* ="" */)
 {
#if 0   
   cout<<"----------Floating Point Operation Counts---------------------"<<endl;
   cout<<comment<<endl;
   //cout<<"Floating point operations found for node "<<node->class_name() <<"@" <<endl;
   cout<<node->class_name() <<"@" <<endl;
   cout<< node->get_file_info()->get_filename()<<":"<<node->get_file_info()->get_line() <<endl;
   cout<<"\tfp_plus:"<< plus_count<<endl;
   cout<<"\tfp_minus:"<< minus_count<<endl;
   cout<<"\tfp_multiply:"<< multiply_count<<endl;
   cout<<"\tfp_divide:"<< divide_count<<endl;
   cout<<"\tfp_total:"<< getTotalCount()<<endl;
#else
  cout<<toString(comment);
#endif
 }
예제 #4
0
void CSyncSource::processServerData(const char* szData)
{
    PROF_START("Parse");
    CJSONArrayIterator oJsonArr(szData);
    PROF_STOP("Parse");
    PROF_START("Data1");
    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("error") )
    {
        m_strError = oJsonArr.getCurItem().getString("error");
        m_nErrCode = RhoRuby.ERR_CUSTOMSYNCSERVER;
        getSync().stopSync();
        return;
    }

    if ( !oJsonArr.isEnd() )
    {
        setCurPageCount(oJsonArr.getCurItem().getInt("count"));
        oJsonArr.next();
    }
    int nVersion = 0;
    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version") )
    {
        nVersion = oJsonArr.getCurItem().getInt("version");
        oJsonArr.next();
    }

    if ( nVersion != getSync().SYNC_VERSION() )
    {
        LOG(ERROR) + "Sync server send data with incompatible version. Client version: " + convertToStringA(getSync().SYNC_VERSION()) +
            "; Server response version: " + convertToStringA(nVersion) + ". Source name: " + getName();
        getSync().stopSync();
        m_nErrCode = RhoRuby.ERR_SYNCVERSION;
        return;
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("rt") )
    {
        setRefreshTime(oJsonArr.getCurItem().getInt("rt"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count") )
    {
        setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
        oJsonArr.next();
    }
    //if ( getServerObjectsCount() == 0 )
    //    getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");

    if ( !oJsonArr.isEnd() )
    {
        processToken(oJsonArr.getCurItem().getUInt64("token"));
        oJsonArr.next();
    }else if ( getCurPageCount() == 0 )
    {
        //oo conflicts
        getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID() );
        //
        processToken(0);
    }

	LOG(INFO) + "Got " + getCurPageCount() + "(Processed: " +  getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
         + ". Version: " + nVersion;

    PROF_STOP("Data1");
    if ( !oJsonArr.isEnd() && getSync().isContinueSync() )
    {
        PROF_START("Data");
        //TODO: support DBExceptions
        getDB().startTransaction();

        int nSavedPos = oJsonArr.getCurPos();
        setSyncServerDataPass(edpNone);
        processServerData_Ver1(oJsonArr);

        setSyncServerDataPass(edpDeleteObjects);
        oJsonArr.reset(nSavedPos);
        processServerData_Ver1(oJsonArr);

	    PROF_STOP("Data");		    
    	PROF_START("DB");
        getDB().endTransaction();
	    PROF_STOP("DB");

        getNotify().fireObjectsNotification();
    }

	PROF_START("Data1");
    if ( getCurPageCount() > 0 )
        getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
	PROF_STOP("Data1");
}
예제 #5
0
QList<double> Skeleton::vectorization(int type) {
    QList<double> result;

    int count = getDim(type);
    int endCount = getEndCount(type);
    int junctionCount = getJunctionCount(type);
    int holeCount = getHoleCount(type);
    int massCenterCount = getMassCenterCount(type);
    int totalCount = getTotalCount(type);
    int partCount = getPartCount(type);

    int index = 0;

    for (int i = 0; i < count; i++){
        result.push_back(0.0001);
    }



    for (int i = 0; i < listLineEnds.size() && i < endCount; i++){
        result[index] = (listLineEnds[i].x);
        index++;

        result[index] = (listLineEnds[i].y);
        index++;
    }

    for (int i = 0; i < listJunctions.size() && i < junctionCount; i++){
        result[index] = (listJunctions[i].x);
        index++;

        result[index] = (listJunctions[i].y);
        index++;
    }

    for (int i = 0; i < listHoles.size() && i < holeCount; i++){
        result[index] = (listHoles[i].x);
        index++;

        result[index] = (listHoles[i].y);
        index++;
    }

    for (int i = 0; i < massCenterCount; i++){
        result[index] = (massCenter.x);
        index++;

        result[index] = (massCenter.y);
        index++;
    }



    for (int i = 0; i < totalCount; i++){
        result[index] = (total);
        index++;
    }

    for (int i = 0; i < partCount; i++){
        for (int x = 0; x < PART_X; x++){
            for (int y = 0; y < PART_Y; y++){
                result[index] = parts[x][y];
                index++;
            }
        }
    }

    return result;
}
예제 #6
0
void CSyncSource::processServerResponse_ver3(CJSONArrayIterator& oJsonArr)
{
    PROF_START("Data1");

    int nVersion = 0;
    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version") )
    {
        nVersion = oJsonArr.getCurItem().getInt("version");
        oJsonArr.next();
    }

    if ( nVersion != getProtocol().getVersion() )
    {
        LOG(ERROR) + "Sync server send data with incompatible version. Client version: " + convertToStringA(getProtocol().getVersion()) +
            "; Server response version: " + convertToStringA(nVersion) + ". Source name: " + getName();
        getSync().stopSync();
        m_nErrCode = RhoAppAdapter.ERR_SYNCVERSION;
        return;
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("token"))
    {
        processToken(oJsonArr.getCurItem().getUInt64("token"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("source") )
    {
        //skip it. it uses in search only
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("count") )
    {
        setCurPageCount(oJsonArr.getCurItem().getInt("count"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("refresh_time") )
    {
        setRefreshTime(oJsonArr.getCurItem().getInt("refresh_time"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("progress_count") )
    {
        //TODO: progress_count
        //setTotalCount(oJsonArr.getCurItem().getInt("progress_count"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count") )
    {
        setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
        oJsonArr.next();
    }

    //if ( getServerObjectsCount() == 0 )
    //    getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");

    if ( getToken() == 0 )
    {
        //oo conflicts
        getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID() );
        //

    }

	LOG(INFO) + "Got " + getCurPageCount() + "(Processed: " +  getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
         + ". Version: " + nVersion;

    PROF_STOP("Data1");
    if ( !oJsonArr.isEnd() && getSync().isContinueSync() )
    {
        CJSONEntry oCmds = oJsonArr.getCurItem();
        PROF_START("Data");
        //TODO: use isUIWaitDB inside processSyncCommand
        //    if ( getDB().isUIWaitDB() )
        //    {
		//        LOG(INFO) + "Commit transaction because of UI request.";
        //        getDB().endTransaction();
        //        getDB().startTransaction();
        //    }

        if ( oCmds.hasName("schema-changed") )
        {
            getSync().setSchemaChanged(true);
        }else if ( oCmds.hasName("source-error") )
        {
            CJSONEntry errSrc = oCmds.getEntry("source-error");
            CJSONStructIterator errIter(errSrc);
            for( ; !errIter.isEnd(); errIter.next() )
            {
                m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
                m_strError = errIter.getCurValue().getString("message");
                m_strErrorType = errIter.getCurKey();
            }
        }else if ( oCmds.hasName("search-error") )
        {
            CJSONEntry errSrc = oCmds.getEntry("search-error");
            CJSONStructIterator errIter(errSrc);
            for( ; !errIter.isEnd(); errIter.next() )
            {
                m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
                m_strError = errIter.getCurValue().getString("message");
                m_strErrorType = errIter.getCurKey();
            }
        }else if ( oCmds.hasName("create-error") )
        {
            m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
            m_strErrorType = "create-error";
        }else if ( oCmds.hasName("update-error") )
        {
            m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
            m_strErrorType = "update-error";
        }else if ( oCmds.hasName("delete-error") )
        {
            m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
            m_strErrorType = "delete-error";
        }else
        {
            getDB().startTransaction();

            if (getSync().getSourceOptions().getBoolProperty(getID(), "pass_through"))
            {
                if ( m_bSchemaSource )
                    getDB().executeSQL( (String("DELETE FROM ") + getName()).c_str() );
                else
                    getDB().executeSQL("DELETE FROM object_values WHERE source_id=?", getID() );
            }

            if ( oCmds.hasName("metadata") && getSync().isContinueSync() )
            {
                String strMetadata = oCmds.getString("metadata");
                getDB().executeSQL("UPDATE sources SET metadata=? WHERE source_id=?", strMetadata, getID() );
            }
            if ( oCmds.hasName("links") && getSync().isContinueSync() )
                processSyncCommand("links", oCmds.getEntry("links") );
            if ( oCmds.hasName("delete") && getSync().isContinueSync() )
                processSyncCommand("delete", oCmds.getEntry("delete") );
            if ( oCmds.hasName("insert") && getSync().isContinueSync() )
                processSyncCommand("insert", oCmds.getEntry("insert") );

            PROF_STOP("Data");

	        PROF_START("DB");
            getDB().endTransaction();
            PROF_STOP("DB");

            getNotify().fireObjectsNotification();
        }
    }

	PROF_START("Data1");
    if ( getCurPageCount() > 0 )
        getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
	PROF_STOP("Data1");
}
	/// Get the probability of the action at \c actionIdx
	double getActionProbability(const size_t& actionIdx) {
		double actionCount = static_cast<double>(getActionCount(actionIdx));
		double totalCount = static_cast<double>(getTotalCount());

		return (actionCount / totalCount);
	}
	/// Get the probability of the object at \c objectIdx
	double getObjectProbability(const size_t& objectIdx) {
		double objectCount = static_cast<double>(getObjectCount(objectIdx));
		double totalCount = static_cast<double>(getTotalCount());

		return (objectCount / totalCount);
	}