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


C++ OoqpVector类代码示例

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


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

示例1: axdzpy

void SimpleVector::axdzpy( double alpha, OoqpVector& xvec,
			       OoqpVector& zvec, OoqpVector& select )
{
  assert( n == xvec.length() &&
	  n == zvec.length() );

  SimpleVector & sxvec = dynamic_cast<SimpleVector &>(xvec);
  double * x = sxvec.v;
  SimpleVector & szvec = dynamic_cast<SimpleVector &>(zvec);
  double * z = szvec.v;
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * s   = sselect.v;
  int i;
  if( alpha == 1.0 ) {
    for( i = 0; i < n; i++ ) {
      if( 0.0 != s[i] ) v[i] += x[i] / z[i];
    }
  } else if ( alpha == -1.0 ) {
    for( i = 0; i < n; i++ ) {
      if( 0.0 != s[i] ) v[i] -= x[i] / z[i];
    }
  } else {
    for( i = 0; i < n; i++ ) {
      if( 0.0 != s[i] ) v[i] += alpha * x[i] / z[i];
    }
  }
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:27,代码来源:SimpleVector.C

示例2: axzpy

void SimpleVector::axzpy( double alpha, OoqpVector& xvec,
			      OoqpVector& zvec )
{
  assert( n == xvec.length() &&
	  n == zvec.length() );

  SimpleVector & sxvec = dynamic_cast<SimpleVector &>(xvec);
  SimpleVector & szvec = dynamic_cast<SimpleVector &>(zvec);

  double * x = sxvec.v;
  double * z = szvec.v;
  double * lx = x + n;
  double * w = v;

  if( alpha == 1.0 ) {
    while( x < lx ) {
      *w += *x * *z;
      w++; x++; z++;
    }
  } else if ( alpha == -1 ) {
    while( x < lx ) {
      *w -= *x * *z;
      w++; x++; z++;
    }
  } else {
    while( x < lx ) {
      *w += alpha * *x * *z;
      w++; x++; z++;
    }
  }
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:31,代码来源:SimpleVector.C

示例3: assert

void PetscVector::copyFrom( OoqpVector& v_in )
{
    assert( n == v_in.length() );

    if( v_in.isKindOf( kPetscVector ) ) {
        PetscVector & pet = (PetscVector &) v_in;
        int ierr = VecCopy( pet.pv, pv );
        assert( ierr  == 0);
    } else if ( v_in.isKindOf( kSimpleVector ) ) {
        SimpleVector & sv = (SimpleVector &) v_in;
        this->copyFromArray( sv.elements() );
    } else {
        assert( 0 && "Can't copy from unknown OoqpVector type" );
    }
}
开发者ID:qiakeyufeiniao,项目名称:PIPS,代码行数:15,代码来源:PetscVector.C

示例4: dotProductWith

double SimpleVector::dotProductWith( OoqpVector& vec )
{
  assert( n == vec.length() );
  SimpleVector & svec = dynamic_cast<SimpleVector &>(vec);
  double * vvec = svec.v;
  
  double dot1 = 0.0;
  double dot2 = 0.0;

  const int size = 8196;
  int kmax       = n / size;
  int i          = 0;

  int k, imax;
  for( k = 0; k < kmax; k++ ) {
    imax = (k + 1) * 8196;
    for( ; i < imax; i++ ) {
      dot1 += v[i] * vvec[i];
    }
    dot2 += dot1;
    dot1  = 0;
  }
  for( ; i < n; i++ ) {
    dot1 += v[i] * vvec[i];
  }
  
  return dot2 + dot1;
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:28,代码来源:SimpleVector.C

示例5: axpy

void SimpleVector::axpy( double alpha, OoqpVector& vec )
{
  assert( n == vec.length() );
  SimpleVector & sv = dynamic_cast<SimpleVector &>(vec);

  int one = 1;
  daxpy_( &n, &alpha, sv.v, &one, v, &one );
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:8,代码来源:SimpleVector.C

示例6: componentMult

void SimpleVector::componentMult( OoqpVector& vec )
{
  assert( n == vec.length() );
  SimpleVector & sv = dynamic_cast<SimpleVector &>(vec);
  double * y = sv.v;
  int i;
  for( i = 0; i < n; i++ ) v[i] *= y[i];
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:8,代码来源:SimpleVector.C

示例7: componentDiv

void SimpleVector::componentDiv ( OoqpVector& vec )
{
  assert( n == vec.length() );
  double * pv = v, *lv = v + n;

  SimpleVector & sv = dynamic_cast<SimpleVector &>(vec);
  double * y = sv.v;

  for( ; pv < lv; pv++, y++ ) *pv /= *y;
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:10,代码来源:SimpleVector.C

示例8: addSomeConstants

void SimpleVector::addSomeConstants( double c, OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  int i;
  assert( n == select.length() );
  for( i = 0; i < n; i++ ) {
    if( map[i] ) v[i] += c;
  }
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:11,代码来源:SimpleVector.C

示例9: selectNonZeros

void SimpleVector::selectNonZeros( OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  assert( n == select.length() );
  int i;
  for( i = 0; i < n; i++ ) {
    if( 0.0 == map[i] ) v[i] = 0.0;
  }
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:11,代码来源:SimpleVector.C

示例10: divideSome

void SimpleVector::divideSome( OoqpVector& div, OoqpVector& select )
{
  if( n == 0 ) return;

  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  SimpleVector & sdiv = dynamic_cast<SimpleVector &>(div);
  double * q   = sdiv.v;
  assert( n == div.length() && n == select.length() );

  double * lmap = map + n;
  double * w = v;
  while( map < lmap ) {
    if( 0 != *map ) {
      *w  /= *q;
    }
    map++;
    w++;
    q++;
  }
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:22,代码来源:SimpleVector.C

示例11: fromGetDiagonal

void DenseStorage::fromGetDiagonal( int idiag, OoqpVector& vec )
{ 
  int k;
  int extent = vec.length();
  
  assert( idiag + extent <= n );
  assert( idiag + extent <= m );

  SimpleVector &  sv = (SimpleVector &) vec;

  for ( k = idiag; k < idiag + extent; k++ ) {
    sv[k] = M[k][k];
  }
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:14,代码来源:DenseStorage.C

示例12: somePositive

int SimpleVector::somePositive( OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  assert( n == select.length() );

  int i;
  for( i = 0; i < n; i++ ) {
    if( 0.0 != map[i] && v[i] <= 0 ) {
      cout << "Element " << i << " is nonpositive: " << v[i] << endl;
      return 0;
    }
  }
  return 1;
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:16,代码来源:SimpleVector.C

示例13: matchesNonZeroPattern

int SimpleVector::matchesNonZeroPattern( OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  double * lmap = map + n;
  assert( n == select.length() );

  double *w = v;
  while( map < lmap ) {
    if( *map == 0.0 && *w != 0.0  ) return 0;
    map++;
    w++;
  }

  return 1;
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:17,代码来源:SimpleVector.C

示例14: setToDiagonal

void DenseStorage::setToDiagonal( OoqpVector& vec )
{ 
  int i,k;

  int extent = vec.length();

  assert( extent <= n );
  assert( extent <= m );

  SimpleVector &  sv = (SimpleVector &) vec;
  for( i = 0; i < m; i++ ) {
    for( k = 0; k < n; k++ ) {
      M[i][k] = 0.0;
    }
  }

  for ( k = 0; k < extent; k++ ) {
    M[k][k] = sv[k];
  }
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:20,代码来源:DenseStorage.C

示例15: stepbound

double SimpleVector::stepbound(OoqpVector & pvec, double maxStep )
{
  assert( n == pvec.length() );

  SimpleVector & spvec = dynamic_cast<SimpleVector &>(pvec);
  double * p = spvec.v;
  double * w = v;
  double bound = maxStep;

  int i;
  for( i = 0; i < n; i++ ) {
    double temp = p[i];
    if( w[i] >= 0 && temp < 0 ) {
      temp = -w[i]/temp;
      if( temp < bound ) {
	bound = temp;
      }
    }
  }
  return bound;
}
开发者ID:aig-lchion,项目名称:OOQP,代码行数:21,代码来源:SimpleVector.C


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