当前位置: 首页>>代码示例>>C++>>正文


C++ vector::assign方法代码示例

本文整理汇总了C++中std::vector::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::assign方法的具体用法?C++ vector::assign怎么用?C++ vector::assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::vector的用法示例。


在下文中一共展示了vector::assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LinearCombinationObjective

 LinearCombinationObjective(const std::vector<Teuchos::RCP<Objective<Real> > > &obj)
   : Objective<Real>(), obj_(obj),
     xdual_(Teuchos::null), initialized_(false) {
   size_ = obj_.size();
   weights_.clear(); weights_.assign(size_,static_cast<Real>(1));
 }
开发者ID:trilinos,项目名称:Trilinos,代码行数:6,代码来源:ROL_LinearCombinationObjective.hpp

示例2: Normals

	GLuint Normals(std::vector<T>& dest) const
	{
		auto n = _normals();
		dest.assign(n.begin(), n.end());
		return 3;
	}
开发者ID:Extrunder,项目名称:oglplus,代码行数:6,代码来源:cage.hpp

示例3: TexCoordinates

	GLuint TexCoordinates(std::vector<T>& dest) const
	{
		auto t = _tex_coords();
		dest.assign(t.begin(), t.end());
		return 3;
	}
开发者ID:Extrunder,项目名称:oglplus,代码行数:6,代码来源:cage.hpp

示例4: filter_matches_by_lis

//FIXME: improve performance
//TODO
void filter_matches_by_lis(const std::vector<cv::KeyPoint> src_keypoints,
		const std::vector<cv::KeyPoint> dst_keypoints,
		const std::vector<cv::DMatch> &matches,
		std::vector<char> &mask) {

	if(matches.size() != mask.size()) return;

	int valid_before = 0;
	for(size_t i=0; i<mask.size(); i++) {
		if(mask[i]) valid_before++;
	}

	std::vector<int> sequence(matches.size());
	//determine horizontal order of matches (with respect to src_keypoints)
	for(size_t i = 0; i < matches.size(); i++) {
		if(mask[i] == 0) {
			continue;
		}
		const float x_min = src_keypoints[matches[i].queryIdx].pt.x; // minimum of current match
		size_t x_min_counter = 0; // how many matches are smaller than current match
		for(size_t j = 0; j < matches.size(); j++) {
			size_t kp_index = matches[j].queryIdx;
			if(src_keypoints[kp_index].pt.x < x_min) {
				x_min_counter++;
			}
		}
		sequence[i] = x_min_counter;
	}

	float last_min = 0.0;
	std::vector<int> sorted_sequence;
	sorted_sequence.reserve(matches.size());
	std::map<int,int> seq2index_map; //maps sequence index to matches index
	//sort matches (with respect to dst_keypoints)
	for(size_t i = 0; i < matches.size(); i++) {
		float x_min = std::numeric_limits<float>::max();
		size_t x_min_index = 0;
		for(size_t j = 0; j < matches.size(); j++) {
			if(mask[j] == 0) continue;
			size_t kp_index = matches[j].trainIdx;
			if(dst_keypoints[kp_index].pt.x < x_min
			&& dst_keypoints[kp_index].pt.x > last_min) {
				x_min = dst_keypoints[kp_index].pt.x;
				x_min_index = j;
			}
		}
		sorted_sequence.push_back(sequence[x_min_index]);
		seq2index_map.insert( std::make_pair(sequence[x_min_index], x_min_index));
		last_min = x_min;
	}

	std::vector<int> lis;
	find_lis(sorted_sequence, lis);
	
	mask.assign(mask.size(), 0);
	for(size_t i = 0; i < lis.size(); i++) {
		mask[ seq2index_map[lis[i]] ] = 1;
	}

	int valid_after = 0;
	for(size_t i=0; i<mask.size(); i++) {
		if(mask[i]) valid_after++;
	}
	dout << "filtered " << valid_before - valid_after << " matches by lis" << std::endl;
}
开发者ID:calihem,项目名称:mavhub,代码行数:67,代码来源:features.cpp

示例5: EvaluateYDerivatives

 void EvaluateYDerivatives(double time, const std::vector<double>& rY, std::vector<double>& rDY)
 {
     rDY.assign(rY.begin(), rY.end());
 }
开发者ID:getshameer,项目名称:Chaste,代码行数:4,代码来源:TwoDimOdeSystem.hpp

示例6: complete_message_callback


//.........这里部分代码省略.........
								
								//std::cout << " n size: " << n[ii].size() << std::endl;
								//std::cout << " n type: " << n[ii].type() << std::endl;
								std::cout << " n value: " << n[ii] << std::endl;
								temp_scalar = temp_scalar*n[ii];
								
								//std::cout << " temp scalar size: " << temp_scalar.size() << std::endl;
								//std::cout << " temp scalar type: " << temp_scalar.type() << std::endl;
								//std::cout << " temp scalar value " << temp_scalar <<std::endl;
								//std::cout << " temp scalar value at 0,0" << temp_scalar.at<double>(0,0) << std::endl;
								
								scalar_value_check.push_back(temp_scalar.at<double>(0,0));
								
								////std::cout << " scalar value check size: " << scalar_value_check.size() << std::endl;
								//std::cout << " \tthe value for the " << jj << " visibility check is: " << scalar_value_check[4*ii+jj] << std::endl;
								
							}
						}
						
						std::cout << " end check for visibility" << std::endl << std::endl;
						
						// restting first solution found and second solution found
						first_solution_found = false;
						second_solution_found = false;
						fc_found = false;
						
						// getting the two solutions or only one if there are not two
						for (int ii = 0; ii < successful_decomp; ii++)
						{
							// getting the values onto the temporary vector
							// getting the start and end of the next solution
							temp_solution_start = scalar_value_check.begin() + 4*ii;
							temp_solution_end = scalar_value_check.begin() + 4*ii+4;
							temp_solution.assign(temp_solution_start,temp_solution_end);
							
							// checking if all the values are positive
							all_positive = true;
							current_temp_index = 0;
							while (all_positive && current_temp_index < 4)
							{
								if (temp_solution[current_temp_index] >= 0)
								{
									current_temp_index++;
								}
								else
								{
									all_positive = false;
								}
							}
							
							// if all the values were positive and a first solution has not been found will assign 
							// to first solution. if all positive and first solution has been found will assign
							// to second solution. if all positive is false then will not do anything
							if (all_positive && first_solution_found && !second_solution_found)
							{
								// setting it to indicate a solution has been found
								second_solution_found = true;
								
								// setting the rotation, translation, and normal to be the second set
								second_R = R[ii];
								second_T = T[ii];
								second_n = n[ii];
								
								// setting the projected values
								second_solution = temp_solution;
							}
开发者ID:bellz867,项目名称:homog_track,代码行数:67,代码来源:homog_decompose_1.cpp

示例7: evaluateCurve

void BsplinesCurveEvaluator::evaluateCurve(const std::vector<Point>& ptvCtrlPts,
                                         std::vector<Point>& ptvEvaluatedCurvePts,
                                         const float& fAniLength,
                                         const bool& bWrap) const
{
    
    if (s_AddNewPt) return; 
    
    int iCtrlPtCount = ptvCtrlPts.size();
    ptvEvaluatedCurvePts.assign(ptvCtrlPts.begin(), ptvCtrlPts.end());
    ptvEvaluatedCurvePts.clear();
    
    float x = 0.0;
    float y1;
    
    // Bezier
    
    if (bWrap) {
        
        for (int i = 0; i < iCtrlPtCount; i++) {
            
            std::cout << "i" << i << std::endl;
            
            int p0 = (i) % iCtrlPtCount;
            int p1 = (i + 1) % iCtrlPtCount;
            int p2 = (i + 2) % iCtrlPtCount;
            int p3 = (i + 3) % iCtrlPtCount;
            
        
            for(float n=0; n < s_iSegCount; n++){
                
                float u = ((float)n)/((float)s_iSegCount-1);
                
                float y = (-1.0 / 6.0 * pow(u, 3) + 1.0 / 2.0 * pow(u, 2) -  1.0 / 2.0 * u + 1.0 / 6.0) * ptvCtrlPts[p0].y + \
                    ( 1.0 / 2.0 * pow(u, 3) -  pow(u, 2) + 2.0 / 3.0) * ptvCtrlPts[p1].y + \
                    (-1.0 / 2.0 * pow(u, 3) + 1.0 / 2.0 * pow(u, 2) +  1.0 / 2.0 * u + 1.0 / 6.0) * ptvCtrlPts[p2].y + \
                    (1.0 / 6.0 * pow(u, 3) ) * ptvCtrlPts[p3].y;
                
                
                float len = ptvCtrlPts[p2].x - ptvCtrlPts[p1].x;
                
                if (len < 0) len += fAniLength;
                
                float x = ptvCtrlPts[p1].x + u * len;
                
                if (x > fAniLength)
                    x = x - fAniLength;
                
                ptvEvaluatedCurvePts.push_back(Point(x,y));
            }
            
        }
        
    } else {
        
    
        std::vector<Point> newPtvCtrlPts;
        
        newPtvCtrlPts.push_back(ptvCtrlPts[0]);
        newPtvCtrlPts.push_back(ptvCtrlPts[0]);
        
        for(int i=0;i<iCtrlPtCount;i++){
            newPtvCtrlPts.push_back(ptvCtrlPts[i]);
        }
        if(iCtrlPtCount>1){
            newPtvCtrlPts.push_back(ptvCtrlPts[iCtrlPtCount-1]);
            newPtvCtrlPts.push_back(ptvCtrlPts[iCtrlPtCount-1]);
        }
        
        int i = 0;
        for(; i < newPtvCtrlPts.size()-3; i++){
            
            for(float n=0; n < s_iSegCount; n++){
                float u = ((float)n)/((float)s_iSegCount-1);
                float x=0.0;
                float y=0.0;
                
                x = (-1.0 / 6.0 * pow(u, 3) + 1.0 / 2.0 * pow(u, 2) -  1.0 / 2.0 * u + 1.0 / 6.0) * newPtvCtrlPts[i].x + \
                    ( 1.0 / 2.0 * pow(u, 3) -  pow(u, 2) + 2.0 / 3.0) * newPtvCtrlPts[i + 1].x + \
                    (-1.0 / 2.0 * pow(u, 3) + 1.0 / 2.0 * pow(u, 2) +  1.0 / 2.0 * u + 1.0 / 6.0) * newPtvCtrlPts[i + 2].x + \
                    (1.0 / 6.0 * pow(u, 3) ) * newPtvCtrlPts[i + 3].x;
                
                y = (-1.0 / 6.0 * pow(u, 3) + 1.0 / 2.0 * pow(u, 2) -  1.0 / 2.0 * u + 1.0 / 6.0) * newPtvCtrlPts[i].y + \
                    ( 1.0 / 2.0 * pow(u, 3) -  pow(u, 2) + 2.0 / 3.0) * newPtvCtrlPts[i + 1].y + \
                    (-1.0 / 2.0 * pow(u, 3) + 1.0 / 2.0 * pow(u, 2) +  1.0 / 2.0 * u + 1.0 / 6.0) * newPtvCtrlPts[i + 2].y + \
                    (1.0 / 6.0 * pow(u, 3) ) * newPtvCtrlPts[i + 3].y;
                
                
                ptvEvaluatedCurvePts.push_back(Point(x,y));
            }
        }
        
        // start
        ptvEvaluatedCurvePts.push_back(Point(0, ptvCtrlPts[0].y));
        // end
        ptvEvaluatedCurvePts.push_back(Point(fAniLength, ptvCtrlPts[iCtrlPtCount-1].y));
    
    }
}
开发者ID:lijia516,项目名称:CG_Final-project,代码行数:99,代码来源:bsplinescurveevaluator.cpp

示例8: _readContentsFromZip


//.........这里部分代码省略.........
		{
			if(zzipFile)zzip_file_close(zzipFile);

			setLastError(AXP_ERR_FILE_ACCESS, "Path=%s, WinErr=%d", szDiskFilePath, ::GetLastError());
			return false;
		}

		//创建该文件
		HANDLE hDiskFile = ::CreateFile(szDiskFileName, 
							GENERIC_READ|GENERIC_WRITE,
							FILE_SHARE_READ|FILE_SHARE_WRITE,
							0,
							CREATE_ALWAYS,
							FILE_ATTRIBUTE_ARCHIVE,
							0);

		if(hDiskFile == INVALID_HANDLE_VALUE)
		{
			if(zzipFile)zzip_file_close(zzipFile);

			setLastError(AXP_ERR_FILE_ACCESS, "File=%s, WinErr=%d", szDiskFileName, ::GetLastError());
			return false;
		}

		if(zstat.st_size > 0)
		{
			const int MAX_BUFFER_SIZE = 4096;
			char buffer[MAX_BUFFER_SIZE] = {0};

			zzip_seek(zzipFile, 0, SEEK_SET);
			zzip_ssize_t zReadSize = zzip_file_read(zzipFile, buffer, sizeof(buffer));
		
			//实际已经写入的尺寸
			unsigned int nActWriteSize = 0;

			//分块读写文件内容
			do
			{
				//文件结束
				if(zReadSize==0) break;

				//写入磁盘文件
				DWORD dwBytesWrite;
				if(!WriteFile(hDiskFile, buffer, (DWORD)zReadSize, &dwBytesWrite, 0) || 
					dwBytesWrite != (DWORD)zReadSize)
				{
					zzip_file_close(zzipFile);
					CloseHandle(hDiskFile);

					setLastError(AXP_ERR_FILE_WRITE, "File=%s, WinErr: %d", szDiskFileName, GetLastError());
					return false;
				}

				//文件结束
				if(zzip_tell(zzipFile) >=zstat.st_size) break;

				zReadSize = zzip_file_read(zzipFile, buffer, sizeof(buffer));
			}while(true);
		}
		//关闭句柄
		CloseHandle(hDiskFile); hDiskFile=0;
	}

	//如果需要读入内存
	if(ppMemoryBuf)
	{
		//所需要的内存
		unsigned int nMemoryNeed = (unsigned int)zstat.st_size+1;
		while(nMemoryNeed%4)nMemoryNeed++;	//upbound 4

		//扩大静态内存大小
		static std::vector< unsigned char > s_autoMemory;
		if(s_autoMemory.size() < nMemoryNeed) 
		{
			s_autoMemory.resize(nMemoryNeed);
		}
		s_autoMemory.assign(s_autoMemory.size(), 0);

		//读入文件内容
		if(zstat.st_size > 0)
		{
			zzip_seek(zzipFile, 0, SEEK_SET);
			zzip_ssize_t nZipSize = zzip_file_read(zzipFile, (char*)&(s_autoMemory[0]), zstat.st_size);
			if(nZipSize != zstat.st_size)
			{
				zzip_file_close(zzipFile);
				setLastError(AXP_ERR_ZIPFILE, "ziperr=%d", mZzipDir->errcode);
				return false;
			}
		}
		//返回内容
		*ppMemoryBuf = (char *)(&(s_autoMemory[0]));
	}

	//关闭句柄
	if(zzipFile)zzip_file_close(zzipFile);	zzipFile=0;

	nFileSize = (unsigned int)zstat.st_size;
	return true;
}
开发者ID:gitrider,项目名称:wxsj2,代码行数:101,代码来源:AxpUpdater.cpp

示例9: resetLightUniformValues

// helpers
static void resetLightUniformValues()
{
    const auto& conf = Configuration::getInstance();
    int maxDirLight = conf->getMaxSupportDirLightInShader();
    int maxPointLight = conf->getMaxSupportPointLightInShader();
    int maxSpotLight = conf->getMaxSupportSpotLightInShader();

    s_dirLightUniformColorValues.assign(maxDirLight, Vec3::ZERO);
    s_dirLightUniformDirValues.assign(maxDirLight, Vec3::ZERO);

    s_pointLightUniformColorValues.assign(maxPointLight, Vec3::ZERO);
    s_pointLightUniformPositionValues.assign(maxPointLight, Vec3::ZERO);
    s_pointLightUniformRangeInverseValues.assign(maxPointLight, 0.0f);

    s_spotLightUniformColorValues.assign(maxSpotLight, Vec3::ZERO);
    s_spotLightUniformPositionValues.assign(maxSpotLight, Vec3::ZERO);
    s_spotLightUniformDirValues.assign(maxSpotLight, Vec3::ZERO);
    s_spotLightUniformInnerAngleCosValues.assign(maxSpotLight, 0.0f);
    s_spotLightUniformOuterAngleCosValues.assign(maxSpotLight, 0.0f);
    s_spotLightUniformRangeInverseValues.assign(maxSpotLight, 0.0f);
}
开发者ID:dabingnn,项目名称:cocosVR,代码行数:22,代码来源:CCMesh.cpp

示例10: cos

void PHG4HoughTransform::projectToRadius(const SvtxTrackState* state,
					 int charge,
					 double B,
					 double radius,
					 std::vector<double>& intersection) {
  intersection.clear();
  intersection.assign(3,NAN);
  
  // find 2d intersections in x,y plane
  std::set<std::vector<double> > intersections;
  if (B != 0.0) {
    // magentic field present, project track as a circle leaving the state position
    
    // compute the center of rotation and the helix parameters
    // x(u) = r*cos(q*u+cphi) + cx
    // y(u) = r*sin(q*u+cphi) + cy
    // z(u) = b*u + posz;
    
    double cr = state->get_pt() * 333.6 / B;                                  // radius of curvature
    double cx = state->get_x() - (state->get_py()*cr)/charge/state->get_pt(); // center of rotation, x
    double cy = (state->get_px()*cr)/charge/state->get_pt() + state->get_y(); // center of rotation, y
    double cphi = atan2(state->get_y()-cy,state->get_x()-cx);                 // phase of state position
    double b = state->get_pz()/state->get_pt()*cr;                            // pitch along z

    if (!circle_circle_intersections(0.0,0.0,radius,
				     cx,cy,cr,
				     &intersections)) {
      return;
    }

    if (intersections.empty()) return;
    
    // downselect solutions based on track direction
    // we want the solution where the state vector would exit the cylinder
    // this can be determined by the direction that the track circulates in

    // rotate the px,py to the postion of the solution
    // then ask if the dot product of the displacement vector between the solution
    // and the cylinder center with the rotated momentum vector is positive
    std::set<std::vector<double> >::iterator remove_iter = intersections.end();
    double intersection_z = 0.0;
    for (std::set<std::vector<double> >::iterator iter = intersections.begin();
	 iter != intersections.end();
	 ++iter) {
      double x = iter->at(0);
      double y = iter->at(1);

      // find the azimuthal rotation about the center of rotation between the state vector and the solution

      // displacement between center of rotation and solution
      double dx = x - cx;
      double dy = y - cy;
      double dphi = atan2(dy,dx);
       
      // displacement between center of rotation and state position
      double state_dx = state->get_x() - cx;
      double state_dy = state->get_y() - cy;
      double state_dphi = atan2(state_dy,state_dx);

      // relative rotation angle
      double rotphi = (dphi-state_dphi);
        
      // rotated momentum at the solution
      double rotpx = cos(rotphi)*state->get_px() - sin(rotphi)*state->get_py();
      double rotpy = sin(rotphi)*state->get_px() + cos(rotphi)*state->get_py();
    
      // assumes cylinder is centered at 0,0
      double dot = rotpx*x + rotpy*y;

      // our solution will have a momentum vector leaving the cylinder surface
      if (dot >= 0.0) {
	// find the solution for z
	double u = (dphi - cphi)/charge;
	
	// look only along the projection (not backward)
	if (u > 2.0*M_PI) {
	  u = u - 2.0*M_PI;
	} else if (u < 0.0) {
	  u = u + 2.0*M_PI;
	}

	intersection_z = b*u+state->get_z();      
      } else {
	remove_iter = iter;
      }
    }

    if (remove_iter != intersections.end()) {
      intersections.erase(remove_iter);
    }

    if (intersections.empty()) return;
    
    intersection[0] = intersections.begin()->at(0);
    intersection[1] = intersections.begin()->at(1);
    intersection[2] = intersection_z;

    return;
    
  } else {
//.........这里部分代码省略.........
开发者ID:pinkenburg,项目名称:coresoftware,代码行数:101,代码来源:PHG4HoughTransform.C

示例11: spec

bool
ICOOutput::write_scanline(int y, int z, TypeDesc format, const void* data,
                          stride_t xstride)
{
    m_spec.auto_stride(xstride, format, spec().nchannels);
    const void* origdata = data;
    data = to_native_scanline(format, data, xstride, m_scratch, m_dither, y, z);
    if (data == origdata) {
        m_scratch.assign((unsigned char*)data,
                         (unsigned char*)data + m_spec.scanline_bytes());
        data = &m_scratch[0];
    }

    if (m_want_png) {
        if (!PNG_pvt::write_row(m_png, (png_byte*)data)) {
            error("PNG library error");
            return false;
        }
    } else {
        unsigned char* bdata = (unsigned char*)data;
        unsigned char buf[4];

        fseek(m_file,
              m_offset + sizeof(ico_bitmapinfo)
                  + (m_spec.height - y - 1) * m_xor_slb,
              SEEK_SET);
        // write the XOR mask
        size_t buff_size = 0;
        for (int x = 0; x < m_spec.width; x++) {
            switch (m_color_type) {
                // reuse PNG constants
            case PNG_COLOR_TYPE_GRAY:
                buf[0] = buf[1] = buf[2] = bdata[x];
                buff_size                = 3;
                break;
            case PNG_COLOR_TYPE_GRAY_ALPHA:
                buf[0] = buf[1] = buf[2] = bdata[x * 2 + 0];
                buf[3]                   = bdata[x * 2 + 1];
                buff_size                = 4;
                break;
            case PNG_COLOR_TYPE_RGB:
                buf[0]    = bdata[x * 3 + 2];
                buf[1]    = bdata[x * 3 + 1];
                buf[2]    = bdata[x * 3 + 0];
                buff_size = 3;
                break;
            case PNG_COLOR_TYPE_RGB_ALPHA:
                buf[0]    = bdata[x * 4 + 2];
                buf[1]    = bdata[x * 4 + 1];
                buf[2]    = bdata[x * 4 + 0];
                buf[3]    = bdata[x * 4 + 3];
                buff_size = 4;
                break;
            }

            if (!fwrite(buf, 1, buff_size)) {
                return false;
            }
        }

        fseek(m_file,
              m_offset + sizeof(ico_bitmapinfo) + m_spec.height * m_xor_slb
                  + (m_spec.height - y - 1) * m_and_slb,
              SEEK_SET);
        // write the AND mask
        // It's required even for 32-bit images because it can be used when
        // drawing at colour depths lower than 24-bit. If it's not present,
        // Windows will read out-of-bounds, treating any data that it
        // encounters as the AND mask, resulting in ugly transparency effects.
        // Only need to do this for images with alpha, becasue 0 is opaque,
        // and we've already filled the file with zeros.
        if (m_color_type != PNG_COLOR_TYPE_GRAY
            && m_color_type != PNG_COLOR_TYPE_RGB) {
            for (int x = 0; x < m_spec.width; x += 8) {
                buf[0] = 0;
                for (int b = 0; b < 8 && x + b < m_spec.width; b++) {
                    switch (m_color_type) {
                    case PNG_COLOR_TYPE_GRAY_ALPHA:
                        buf[0] |= bdata[(x + b) * 2 + 1] <= 127 ? (1 << (7 - b))
                                                                : 0;
                        break;
                    case PNG_COLOR_TYPE_RGB_ALPHA:
                        buf[0] |= bdata[(x + b) * 4 + 3] <= 127 ? (1 << (7 - b))
                                                                : 0;
                        break;
                    }
                }

                if (!fwrite(&buf[0], 1, 1)) {
                    return false;
                }
            }
        }
    }

    return true;
}
开发者ID:OpenImageIO,项目名称:oiio,代码行数:97,代码来源:icooutput.cpp

示例12: write

bool IOStub::write(const uint8_t* buff, size_t bytes)
{
  if(bytes == 0)
  {
    return true;
  }

  size_t last_index = _input.size();
  _input.insert(_input.end(), buff, buff + bytes);

  auto start = _input.begin() + last_index;
  auto match = std::find(start, _input.end(), '\n');

  if(match == _input.end())
  {
    return true;
  }

  std::string data = std::string(start, match);
  _input.clear();

  bool is_query = false;
  switch(data[0])
  {
    case '?':
      is_query = true;
    break;
    case '=':
      is_query = false;
    break;
    default:
      return false;
  }
  std::string cmd;
  std::string args;

  if(is_query)
  {
    cmd = data.substr(1);
  }
  else
  {
    size_t end = data.find(',');
    cmd = data.substr(1, end - 1);
    //apparent fencepost error here is to remove the newline
    args = data.substr(end + 1);
  }

  boost::to_upper(cmd);
  boost::to_upper(args);

  const auto& processor = _processors.find(cmd);

  std::string resp = "";
  if(processor != _processors.end())
  {
    resp = processor->second(processor->first, args);
  }

  if(!resp.empty())
  {
    _response_data.assign(resp.begin(), resp.end());
  }
  return true;
}
开发者ID:TRECVT,项目名称:ros_kvh1750,代码行数:65,代码来源:utest.cpp

示例13: Train

		void Train(mxnet::NDArray data_array, mxnet::NDArray label_array,
			int max_epoches, int val_fold, float start_learning_rate, std::vector<mxnet::NDArray> &argsl) {
			/*prepare ndarray*/
			learning_rate = start_learning_rate;
			size_t data_count = data_array.shape()[0];
			size_t val_data_count = data_count * val_fold / 10;
			size_t train_data_count = data_count - val_data_count;
			train_data = data_array.Slice(0, train_data_count);
			train_label = label_array.Slice(0, train_data_count);
			val_data = data_array.Slice(train_data_count, data_count);
			val_label = label_array.Slice(train_data_count, data_count);
			size_t batch_size = in_args[0].shape()[0];

			/*start the training*/
			for (int iter = 0; iter < max_epoches; ++iter) {
				CHECK(optimizer);
				size_t start_index = 0;
				in_args[0] =
					train_data.Slice(start_index, start_index + batch_size).Copy(ctx_dev);
				in_args[in_args.size() - 1] =
					train_label.Slice(start_index, start_index + batch_size)
					.Copy(ctx_dev);
				in_args[0].WaitToRead();
				in_args[in_args.size() - 1].WaitToRead();
				while (start_index < train_data_count) {
					/*rebind the excutor*/
					delete exe;
					exe = mxnet::Executor::Bind(net, ctx_dev, g2c, in_args, arg_grad_store,
						grad_req_type, aux_states);

					CHECK(exe);

					exe->Forward(true);
					exe->Backward(std::vector<mxnet::NDArray>());

					start_index += batch_size;
					if (start_index < train_data_count) {
						if (start_index + batch_size >= train_data_count)
							start_index = train_data_count - batch_size;
						in_args[0] = train_data.Slice(start_index, start_index + batch_size)
							.Copy(ctx_dev);
						in_args[in_args.size() - 1] =
							train_label.Slice(start_index, start_index + batch_size)
							.Copy(ctx_dev);
					}

					for (size_t i = 1; i < in_args.size() - 1; ++i) {
						optimizer->Update(i, &in_args[i], &arg_grad_store[i], learning_rate);
					}
					for (size_t i = 1; i < in_args.size() - 1; ++i) {
						in_args[i].WaitToRead();
					}
					in_args[0].WaitToRead();
					in_args[in_args.size() - 1].WaitToRead();
				}

				/*call every iter*/
				TrainingCallBack(iter, exe);
			}
		
			argsl.assign(in_args.begin(), in_args.end());
		
		}
开发者ID:caomw,项目名称:MXNet-Learning-Note,代码行数:63,代码来源:cpp_net.hpp

示例14: getMinMax

/**get vector of minimal and maximal values from the class */
void MDWSDescription::getMinMax(std::vector<double> &min,
                                std::vector<double> &max) const {
  min.assign(m_DimMin.begin(), m_DimMin.end());
  max.assign(m_DimMax.begin(), m_DimMax.end());
}
开发者ID:liyulun,项目名称:mantid,代码行数:6,代码来源:MDWSDescription.cpp

示例15: Bitangents

	GLuint Bitangents(std::vector<T>& dest) const
	{
		auto v = _bitangents();
		dest.assign(v.begin(), v.end());
		return 3;
	}
开发者ID:Simmesimme,项目名称:oglplus,代码行数:6,代码来源:wicker_torus.hpp


注:本文中的std::vector::assign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。