⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cholesky.cpp

📁 强大的C++库
💻 CPP
字号:
/*! * \file * \brief Implementation of Cholesky factorisation functions * \author Tony Ottosson * * ------------------------------------------------------------------------- * * IT++ - C++ library of mathematical, signal processing, speech processing, *        and communications classes and functions * * Copyright (C) 1995-2008  (see AUTHORS file for a list of contributors) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * ------------------------------------------------------------------------- */#ifndef _MSC_VER#  include <itpp/config.h>#else#  include <itpp/config_msvc.h>#endif#if defined(HAVE_LAPACK)#  include <itpp/base/algebra/lapack.h>#endif#include <itpp/base/algebra/cholesky.h>namespace itpp {#if defined(HAVE_LAPACK)  bool chol(const mat &X, mat &F)  {    char uplo='U';    int n, lda, info;    n = lda = X.rows();    F = X; // input matrix is overwritten    dpotrf_(&uplo, &n, F._data(), &lda, &info);    // Set lower part to zero    for (int i=0; i<n; i++)      for(int j=i+1; j<n; j++)	F(j,i) = 0;    return (info==0);  }  bool chol(const cmat &X, cmat &F)  {    char uplo='U';    int n, lda, info;    n = lda = X.rows();    F = X; // input matrix is overwritten    zpotrf_(&uplo, &n, F._data(), &lda, &info);    // Set lower part to zero    for (int i=0; i<n; i++)      for(int j=i+1; j<n; j++)	F(j,i) = 0;    return (info==0);  }#else // HAVE_LAPACK  bool chol(const mat &X, mat &F)  {    it_error("LAPACK library is needed to use chol() function");    return false;  }  bool chol(const cmat &X, cmat &F)  {    it_error("LAPACK library is needed to use chol() function");    return false;  }#endif // HAVE_LAPACK  cmat chol(const cmat &X)  {    cmat F;    if (!chol(X, F)) {      it_warning("cholesky factorization didn't succeed");    }    return F;  }  mat chol(const mat &X)  {    mat F;    if (!chol(X, F)) {      it_warning("cholesky factorization didn't succeed");    }    return F;  }} // namespace itpp

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -