コード例 #1
0
ファイル: CS_Solve.cpp プロジェクト: aghakhani/aero-shock
//---------------------------------------------------------
int CS_Chol::chol(CSd& A, int order, double dummy)
//---------------------------------------------------------
{
  // Perform Cholesky factorization using 
  // appropriate AMD re-ordering mode:
  //---------------------------------------
  // 0: natural: C = A     (no reordering)
  // 1: Chol   : C = A+A'
  // 2: LU     : C = A'*A  (drop dense rows)
  // 3: QR     : C = A'*A
  // 4: Chol#2 : C = A     (A is symmetric)
  //---------------------------------------

  // clear existing system
  if (S) { delete S; S = NULL; }
  if (N) { delete N; N = NULL; }

  // check matrix input
  if (!A.ok())        {umERROR("CS_Chol::chol", "empty matrix"); return 0;}
  if (!A.is_csc())    {umERROR("CS_Chol::chol", "expected csc form"); return 0;}
  if (!A.is_square()) {umERROR("CS_Chol::chol", "matrix must be square"); return 0;}

  umLOG(1, "\nCS_Chol:chol -- starting symbolic phase\n");
  try {
    // ordering and symbolic analysis
    S = CS_schol(order, A);
    if (!S) { umERROR("CS_Chol::chol", "error building symbolic info"); return -1;}
  } catch(...) {
    umERROR("CS_Chol:chol", "exception in symbolic phase"); return -1;
  }
  umLOG(1, "CS_Chol:chol -- symbolic phase complete\n");
  umLOG(1, "CS_Chol:chol -- size of full Cholesky L = %1.0lf\n\n", S->lnz);
  try {
    // numeric Cholesky factorization
    N = CS_chol(A, S, true);  // take ownership of A's data
    if (!N) { umERROR("CS_Chol::chol", "error building numeric data"); return -2;}
  } catch(...) {
    umERROR("CS_Chol:chol", "exception in numeric phase"); return -2;
  }

  return 1;
}
コード例 #2
0
ファイル: CS_Solve.cpp プロジェクト: aghakhani/aero-shock
//---------------------------------------------------------
int CS_LU::lu(const CSd& A, int order, double tol)
//---------------------------------------------------------
{
  // Perform LU factorization using 
  // appropriate AMD re-ordering mode:
  //---------------------------------------
  // 0: natural: C = A     (no reordering)
  // 1: Chol   : C = A+A'
  // 2: LU     : C = A'*A  (drop dense rows)
  // 3: QR     : C = A'*A
  // 4: Chol#2 : C = A     (A is symmetric)
  //---------------------------------------

  // clear existing system
  if (S) { delete S; S = NULL; }
  if (N) { delete N; N = NULL; }

  // check matrix input
  if (!A.ok())        {umERROR("CS_LU::lu", "empty matrix"); return 0;}
  if (!A.is_csc())    {umERROR("CS_LU::lu", "expected csc form"); return 0;}
  if (!A.is_square()) {umERROR("CS_LU::lu", "matrix must be square"); return 0;}

  try {
    // ordering and symbolic analysis
    S = CS_sqr(order, A, 0);
    if (!S) { umERROR("CS_LU::lu", "error building symbolic info"); return -1;}
  } catch(...) {
    umERROR("CS_LU::lu", "exception in symbolic phase"); return -1;
  }

  try {
    // numeric LU factorization
    N = CS_lu(A, S, tol);
    if (!N) { umERROR("CS_LU::lu", "error building numeric data"); return -2;}
  } catch(...) {
    umERROR("CS_LU::lu", "exception in numeric phase"); return -2;
  }

  return 1;
}