?? blas2.cpp
字號:
}
if(x.Length() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_ssyr(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
}
void Syr(double alpha, Vector<double>& x, Matrix<double>& A)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(x.Length() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_dsyr(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
}
void Her(float alpha, Vector<ComplexFloat>& x, Matrix<ComplexFloat>& A)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(x.Length() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_cher(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
}
void Her(double alpha, Vector<ComplexDouble>& x, Matrix<ComplexDouble>& A)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(x.Length() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_zher(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
}
/// Rank-two update of a symmetric or hermitian matrix
/// A += alpha*x*transp(y) + alpha*y*transp(x)
/// A += alpha*x*conjug_transp(y) + alpha*y*conjug_transp(x)
void Syr2(float alpha, Vector<float>& x, Vector<float>& y, Matrix<float>& A)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(x.Length() != A.Rows() || y.Length() != A.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_ssyr2(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
}
void Syr2(double alpha, Vector<double>& x, Vector<double>& y, Matrix<double>& A)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(x.Length() != A.Rows() || y.Length() != A.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_dsyr2(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
}
void Her2(ComplexFloat alpha, Vector<ComplexFloat>& x, Vector<ComplexFloat>& y, Matrix<ComplexFloat>& A)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(x.Length() != A.Rows() || y.Length() != A.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_cher2(CblasColMajor, CblasUpper, A.Rows(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
}
void Her2(ComplexDouble alpha, Vector<ComplexDouble>& x, Vector<ComplexDouble>& y, Matrix<ComplexDouble>& A)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(x.Length() != A.Rows() || y.Length() != A.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
}
cblas_zher2(CblasColMajor, CblasUpper, A.Rows(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
}
/// Trmv: m*v for triangular matrix
Vector<float> Trmv(Matrix<float>& A, Vector<float>& x)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Columns() != x.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<float> y = x.Clone();
cblas_strmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
return y;
}
Vector<double> Trmv(Matrix<double>& A, Vector<double>& x)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Columns() != x.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<double> y = x.Clone();
cblas_dtrmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
return y;
}
Vector<ComplexFloat> Trmv(Matrix<ComplexFloat>& A, Vector<ComplexFloat>& x)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Columns() != x.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<ComplexFloat> y = x.Clone();
cblas_ctrmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
return y;
}
Vector<ComplexDouble> Trmv(Matrix<ComplexDouble>& A, Vector<ComplexDouble>& x)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Columns() != x.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<ComplexDouble> y = x.Clone();
cblas_ztrmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
return y;
}
/// Trsv: Solver of a system of linear equations with a triangular matrix
Vector<float> Trsv(Matrix<float>& A, Vector<float>& b)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Rows() != b.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<float> x = b.Clone();
cblas_strsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
return x;
}
Vector<double> Trsv(Matrix<double>& A, Vector<double>& b)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Rows() != b.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<double> x = b.Clone();
cblas_dtrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
return x;
}
Vector<ComplexFloat> Trsv(Matrix<ComplexFloat>& A, Vector<ComplexFloat>& b)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Rows() != b.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<ComplexFloat> x = b.Clone();
cblas_ctrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
return x;
}
Vector<ComplexDouble> Trsv(Matrix<ComplexDouble>& A, Vector<ComplexDouble>& b)
{
if(A.Columns() != A.Rows())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix is not square!");
}
if(A.Rows() != b.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix columns and Vector length are not the same!");
}
Vector<ComplexDouble> x = b.Clone();
cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
return x;
}
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -