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


C++ SparseMatrix::MultiplyVector方法代码示例

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


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

示例1: DefaultMultiplicator

void CGSolver::DefaultMultiplicator(const void * data, const double * x, double * Ax)
{
  SparseMatrix * A = (SparseMatrix*)data;
  A->MultiplyVector(x, Ax);
}
开发者ID:jonntd,项目名称:LocoSoftMayaPlugin,代码行数:5,代码来源:CGSolver.cpp

示例2: malloc

void * MyFrame::NonLinearModesWorker(int * code, int dataOrigin, int numNonLinearModes, double ** modes_ )
{
  int n3 = 3 * precomputationState.simulationMesh->getNumVertices();
  int numDataVectors = 0;

  // compute the lumped mass matrix
  SparseMatrix * massMatrix; // will be sparse n3 x n3
  GenerateMassMatrix::computeMassMatrix( precomputationState.simulationMesh, &massMatrix, true); // exitCode will always be 0

  // mass-normalize modal derivatives
  double * modalDerivatives = precomputationState.modalDerivativesMatrix->GetMatrix();
  double * normalizedModalDerivatives = (double*) malloc (sizeof(double) * n3 * precomputationState.numDeriv);
  memcpy(normalizedModalDerivatives, modalDerivatives, sizeof(double) * n3 * precomputationState.numDeriv);

  for(int i=0; i < precomputationState.numDeriv; i++)
    massMatrix->NormalizeVector(&(normalizedModalDerivatives[n3 * i]));

  double * dataMatrix;
  if (dataOrigin == 0)
  {
    // use linear modes and derivatives
    // construct PCA data matrix:
    int numUsedLinearModes = precomputationState.rLin - precomputationState.numRigidModes;
    numDataVectors = numUsedLinearModes + numUsedLinearModes * (numUsedLinearModes + 1) / 2;
    printf("Number of PCA datamatrix columns: %d.\n", numDataVectors);
    dataMatrix = (double*) malloc (sizeof(double) * n3 * numDataVectors);

    printf("Generating datamatrix for SVD...\n");

    double lambda0 = precomputationState.frequencies[precomputationState.numRigidModes] * precomputationState.frequencies[precomputationState.numRigidModes];

    // scale linear modes 
    double * Ulin = precomputationState.linearModalMatrix->GetMatrix();
    for(int i=0; i<numUsedLinearModes; i++)
    {
      double lambda = precomputationState.frequencies[precomputationState.numRigidModes + i] * precomputationState.frequencies[precomputationState.numRigidModes + i];
      double factor = lambda0 / lambda;
      for(int vertex=0; vertex< n3; vertex++)
        dataMatrix[ELT(n3,vertex,i)] = factor * Ulin[ELT(n3,vertex,precomputationState.numRigidModes + i)];
    } 

    // scale modal derivatives
    int pos = 0;
    for(int i=0; i<numUsedLinearModes; i++)
    {
      for(int j=i; j<numUsedLinearModes; j++)
      {
        double lambdai = precomputationState.frequencies[precomputationState.numRigidModes + i] * precomputationState.frequencies[precomputationState.numRigidModes + i];
        double lambdaj = precomputationState.frequencies[precomputationState.numRigidModes + j] * precomputationState.frequencies[precomputationState.numRigidModes + j];
        double factor = lambda0 * lambda0 / (lambdai * lambdaj);

        for(int vertex=0; vertex < n3; vertex++)
          dataMatrix[ELT(n3, vertex, numUsedLinearModes + pos)] = 
            factor * normalizedModalDerivatives[ELT(n3, vertex, pos)];
        pos++;
      }
    }
  }
  else
  {
    // data from external simulation
    numDataVectors = precomputationState.sketchDataMatrix->Getr();
    dataMatrix = (double*) malloc (sizeof(double) * n3 * numDataVectors);
    memcpy(dataMatrix, precomputationState.sketchDataMatrix->GetMatrix(), sizeof(double) * n3 * numDataVectors);
  }

  free(normalizedModalDerivatives);

  // do lumped-mass-PCA on dataMatrix ( n3 x numDataVectors )
  
  double * ones = (double*) malloc (sizeof(double) * n3);
  for(int i=0; i<n3; i++)
    ones[i] = 1.0;

  double * LTDiagonal = (double*) malloc (sizeof(double) * n3);
  massMatrix->MultiplyVector(ones, LTDiagonal);
  free(ones);
  delete(massMatrix);

  // sqrt
  for(int i=0; i<n3; i++)
    LTDiagonal[i] = sqrt(LTDiagonal[i]);

  // number of retained dimensions can't be more than num linear modes + num derivatives
  if (uiState.numComputedNonLinearModes > numDataVectors)
    uiState.numComputedNonLinearModes = numDataVectors;

  // premultiply by LT
  for(int i=0; i<n3; i++)
    for(int j=0; j < numDataVectors; j++)
      dataMatrix[ELT(n3, i, j)] *= LTDiagonal[i];

  // do SVD on dataMatrix ( n3 x numDataVectors ), retain uiState.numComputedNonLinearModes modes

  ThresholdingSpecification thresholdingSpecification;
  thresholdingSpecification.tresholdingType = ThresholdingSpecification::numberOfModesBased;
  thresholdingSpecification.rDesired = uiState.numComputedNonLinearModes;

  int outputr;
  int matrixPCACode = 0;
//.........这里部分代码省略.........
开发者ID:ricortiz,项目名称:VegaFEM-cmake,代码行数:101,代码来源:nonlinearModes.cpp


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