예제 #1
0
void NRLib::WriteMatrixToFile(const std::string            & filename,
                              const NRLib::SymmetricMatrix & matrix,
                              LinalgFileFormat               format)
{
  std::ofstream file;

  if (format == MatrixAscii) {
    NRLib::OpenWrite(file, filename);
    file.precision(8);
    file.setf(std::ios_base::scientific, std::ios_base::floatfield);
    for (int i = 0; i < matrix.dim(); ++i) {
      for (int j = 0; j < matrix.dim(); ++j) {
        file.width(18);
        int I = (matrix.upLo()==flens::Upper) ? std::min(i,j) : std::max(i,j);
        int J = (matrix.upLo()==flens::Upper) ? std::max(i,j) : std::min(i,j);
        file << matrix(I, J);
      }
      file << "\n";
    }
  }
  else if (format == MatrixBinary) {
    NRLib::OpenWrite(file, filename, std::ios::out | std::ios::binary);
    for (int i = 0; i < matrix.dim(); ++i) {
      for (int j = 0; j < matrix.dim(); ++j) {
        int I = (matrix.upLo()==flens::Upper) ? std::min(i,j) : std::max(i,j);
        int J = (matrix.upLo()==flens::Upper) ? std::max(i,j) : std::min(i,j);
        NRLib::WriteBinaryDouble(file, matrix(I, J));
      }
    }
  }
}
예제 #2
0
//-------------------------------------------------------------------
void NRLib::InitializeSymmetricMatrix(NRLib::SymmetricMatrix & A,
                                      double                   value)
//-------------------------------------------------------------------
{
  for (int i=0 ; i < A.dim() ; i++) {
    for (int j=0 ; j <= i ; j++) {
      A(j,i) = value;
    }
  }
}
예제 #3
0
파일: kriging2d.cpp 프로젝트: alfbr/crava
void
Kriging2D::fillKrigingMatrix(NRLib::SymmetricMatrix  & K,
                             const CovGrid2D         & cov,
                             const std::vector<int>  & indexi,
                             const std::vector<int>  & indexj)
{
  int n = K.dim();
  for(int i=0 ; i < n  ; i++) {
    for(int j=0 ; j <= i ; j++) {
      int deltai = indexi[i] - indexi[j];
      int deltaj = indexj[i] - indexj[j];
      K(j,i) = static_cast<double>(cov.getCov(deltai,deltaj));
    }
  }
}