Beispiel #1
0
void add_matrix_to_matrix(double scalar,
                          const fei::Matrix& src_matrix,
                          fei::Matrix& dest_matrix)
{
  fei::SharedPtr<fei::VectorSpace> vspace = src_matrix.getMatrixGraph()->getRowSpace();

  int numRows = vspace->getNumIndices_Owned();
  std::vector<int> rows(numRows);
  vspace->getIndices_Owned(numRows, &rows[0], numRows);

  std::vector<int> indices;
  std::vector<double> coefs;

  for(size_t i=0; i<rows.size(); ++i) {
    int rowlen = 0;
    src_matrix.getRowLength(rows[i], rowlen);

    if ((int)indices.size() < rowlen) {
      indices.resize(rowlen);
      coefs.resize(rowlen);
    }

    src_matrix.copyOutRow(rows[i], rowlen, &coefs[0], &indices[0]);

    for(int j=0; j<rowlen; ++j) {
      coefs[j] *= scalar;
    }

    double* coefPtr = &coefs[0];
    dest_matrix.sumIn(1, &rows[i], rowlen, &indices[0], &coefPtr);
  }
}
bool confirm_matrix_values(const fei::Matrix& mat, double expected_value)
{
    std::vector<int> rows;
    fei::SharedPtr<fei::VectorSpace> rspace = mat.getMatrixGraph()->getRowSpace();
    rspace->getIndices_Owned(rows);
    bool result = true;
    std::vector<int> indices;
    std::vector<double> coefs;
    for(size_t i=0; i<rows.size(); ++i) {
        int rowlength = 0;
        mat.getRowLength(rows[i], rowlength);
        indices.resize(rowlength);
        coefs.resize(rowlength);
        mat.copyOutRow(rows[i], rowlength, &coefs[0], &indices[0]);

        for(size_t j=0; j<indices.size(); ++j) {
            if (std::abs(coefs[j] - expected_value) > 1.e-13) {
                result = false;
                break;
            }
        }
    }
    return result;
}