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


C++ DataVector::resize方法代码示例

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


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

示例1: Validate

// -----------------------------------------------------------------------------
// Validation of a constraint violation data file.
// The validation is done using the specified norm type and tolerance. The
// function returns true if the norms of all columns, excluding the first one,
// are below the given tolerance and false otherwise.
// It is assumed that the input file is TAB-delimited.
// -----------------------------------------------------------------------------
bool Validate(const std::string& sim_filename,
              ChNormType         norm_type,
              double             tolerance,
              DataVector&        norms)
{
  ChValidation validator;

  if (!validator.Process(sim_filename))
    return false;

  size_t num_cols = validator.GetNumColumns() - 1;
  norms.resize(num_cols);

  switch (norm_type) {
  case L2_NORM:  norms = validator.GetL2norms(); break;
  case RMS_NORM: norms = validator.GetRMSnorms(); break;
  case INF_NORM: norms = validator.GetINFnorms(); break;
  }

  for (size_t col = 0; col < num_cols; col++) {
    if (norms[col] > tolerance)
      return false;
  }

  return true;
}
开发者ID:amelmquist,项目名称:ChronoProjects,代码行数:33,代码来源:ChUtilsValidation.cpp

示例2: evalGradient

float_t OperationNaiveEvalGradientWavelet::evalGradient(
  const DataVector& alpha, const DataVector& point, DataVector& gradient) {
  const size_t n = storage->size();
  const size_t d = storage->dim();
  float_t result = 0.0;

  gradient.resize(storage->dim());
  gradient.setAll(0.0);

  DataVector curGradient(d);

  for (size_t i = 0; i < n; i++) {
    const GridIndex& gp = *(*storage)[i];
    float_t curValue = 1.0;
    curGradient.setAll(alpha[i]);

    for (size_t t = 0; t < d; t++) {
      const float_t val1d = base.eval(gp.getLevel(t), gp.getIndex(t), point[t]);
      const float_t dx1d = base.evalDx(gp.getLevel(t), gp.getIndex(t),
                                       point[t]);

      curValue *= val1d;

      for (size_t t2 = 0; t2 < d; t2++) {
        if (t2 == t) {
          curGradient[t2] *= dx1d;
        } else {
          curGradient[t2] *= val1d;
        }
      }
    }

    result += alpha[i] * curValue;
    gradient.add(curGradient);
  }

  return result;
}
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:38,代码来源:OperationNaiveEvalGradientWavelet.cpp

示例3: render

void OutputBufferPlugin::render( const OFX::RenderArguments& args )
{
    TUTTLE_LOG_INFO( "        --> Output Buffer ");
    typedef std::vector<char, OfxAllocator<char> > DataVector;
    DataVector rawImage;
    char* rawImagePtrLink;

    boost::scoped_ptr<OFX::Image> src( _clipSrc->fetchImage( args.time ) );
    boost::scoped_ptr<OFX::Image> dst( _clipDst->fetchImage( args.time ) );

    // Get Image info
    const OfxRectI bounds = dst->getBounds();
    const OFX::EBitDepth depth = dst->getPixelDepth();
    const OFX::EPixelComponent components = dst->getPixelComponents();
    const OFX::EField field = dst->getField();

    // User parameters
    OutputBufferProcessParams params = getProcessParams();

    const std::size_t imageDataBytes = dst->getBoundsImageDataBytes();
    const std::size_t rowBytesToCopy = dst->getBoundsRowDataBytes();

    if( src->isLinearBuffer() && dst->isLinearBuffer() )
    {
        // Two linear buffers. No copy needed.
        if( imageDataBytes )
        {
            void* dataSrcPtr = src->getPixelAddress( bounds.x1, bounds.y1 );
            void* dataDstPtr = dst->getPixelAddress( bounds.x1, bounds.y1 );
            memcpy( dataDstPtr, dataSrcPtr, imageDataBytes );

            // No image copy
            rawImagePtrLink = (char *)dataDstPtr;
        }
    }
    else
    {
        // Non-linear buffer. Line by line copy.
        for( int y = bounds.y1; y < bounds.y2; ++y )
        {
            void* dataSrcPtr = src->getPixelAddress( bounds.x1, y );
            void* dataDstPtr = dst->getPixelAddress( bounds.x1, y );
            memcpy( dataDstPtr, dataSrcPtr, rowBytesToCopy );
        }
        if( params._callbackPtr != NULL )
        {
            // need a temporary buffer copy to give a linear buffer to the callback
            rawImage.resize( imageDataBytes );
            rawImagePtrLink = &rawImage.front();
            for( int y = bounds.y1; y < bounds.y2; ++y )
            {
                void* dataSrcPtr = src->getPixelAddress( bounds.x1, y );
                void* dataDstPtr = rawImagePtrLink + rowBytesToCopy*(y-bounds.y1);
                memcpy( dataDstPtr, dataSrcPtr, rowBytesToCopy );
            }
        }
    }

    if( params._callbackPtr != NULL )
    {
        params._callbackPtr(
            args.time, params._customDataPtr, rawImagePtrLink,
            bounds.x2-bounds.x1, bounds.y2-bounds.y1, rowBytesToCopy,
            depth, components, field );
    }
}
开发者ID:EfestoLab,项目名称:TuttleOFX,代码行数:66,代码来源:OutputBufferPlugin.cpp

示例4: evalHessian

float_t OperationNaiveEvalHessianModFundamentalSpline::evalHessian(
  const DataVector& alpha, const DataVector& point,
  DataVector& gradient, DataMatrix& hessian) {
  const size_t n = storage->size();
  const size_t d = storage->dim();
  float_t result = 0.0;

  gradient.resize(storage->dim());
  gradient.setAll(0.0);

  hessian = DataMatrix(d, d);
  hessian.setAll(0.0);

  DataVector curGradient(d);
  DataMatrix curHessian(d, d);

  for (size_t i = 0; i < n; i++) {
    const GridIndex& gp = *(*storage)[i];
    float_t curValue = 1.0;
    curGradient.setAll(alpha[i]);
    curHessian.setAll(alpha[i]);

    for (size_t t = 0; t < d; t++) {
      const float_t val1d = base.eval(gp.getLevel(t), gp.getIndex(t), point[t]);
      const float_t dx1d = base.evalDx(gp.getLevel(t), gp.getIndex(t),
                                       point[t]);
      const float_t dxdx1d = base.evalDxDx(gp.getLevel(t), gp.getIndex(t), point[t]);

      curValue *= val1d;

      for (size_t t2 = 0; t2 < d; t2++) {
        if (t2 == t) {
          curGradient[t2] *= dx1d;

          for (size_t t3 = 0; t3 < d; t3++) {
            if (t3 == t) {
              curHessian(t2, t3) *= dxdx1d;
            } else {
              curHessian(t2, t3) *= dx1d;
            }
          }
        } else {
          curGradient[t2] *= val1d;

          for (size_t t3 = 0; t3 < d; t3++) {
            if (t3 == t) {
              curHessian(t2, t3) *= dx1d;
            } else {
              curHessian(t2, t3) *= val1d;
            }
          }
        }
      }
    }

    result += alpha[i] * curValue;
    gradient.add(curGradient);
    hessian.add(curHessian);
  }

  return result;
}
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:62,代码来源:OperationNaiveEvalHessianModFundamentalSpline.cpp


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