cblas ライブラリの cblas_chpr() 関数を使用して float 複素数ベクトルの相関行列を計算しようとしたときに問題が発生しました。
Lapack v3.10.0 ライブラリを netLib.org からダウンロードした後、コンパイルしてlibcblas.a 、 liblapack.a 、 liblapacke.a 、 librefblas.a 、およびlibtmglib.aファイルをプロジェクトにコピーし、ライブラリがリンクされていることを確認しました。正しく。
説明によると、cblas_chpr 関数は alpha * x * conjg(x') + A を計算し、結果を A に格納します。
関数は次のように定義されます。
void cblas_chpr(CBLAS_LAYOUT layout, CBLAS_UPLO Uplo,
const CBLAS_INDEX N, const float alpha, const void *X,
const CBLAS_INDEX incX, void *A);
パラメータは次のとおりです。
- レイアウト - これは emun であり、可能な 2 つの入力は CblasRowMajor と CblasColMajor です。
- Uplo - これは列挙型で、可能な 2 つの入力は CblasUpper と CblasLower です。
- N - 行列 A の次数とベクトル x の要素数。
- alpha - ベクトル X に乗算される倍率。
- X - ベクトル X。
- incX - X 内のストライド。たとえば、incX が 7 の場合、7 番目ごとの要素が使用されます。
- A - 行列 A。返された結果によって上書きされます。
私の関数の本体は次のとおりです。
/* Number of elements */
int Ne = 10;
/* Set the parameters */
CBLAS_LAYOUT layout = CblasColMajor; /* Layout is column major */
CBLAS_UPLO Uplo = CblasUpper; /* Upper triangle of the matrix */
CBLAS_INDEX N = Ne; /* Number of elements in vector X */
float alpha = 1.0; /* No scaling, alpha = 1.0 */
/* The vector X */
float complex * X = malloc(Ne * sizeof(* X));
/* Set values of X - for illustration purpose only */
for(int i = 0; i < Ne; i++)
{
X[i] = CMPLXF(i, i + 1.0);
}
CBLAS_INDEX incX = 1; /* Use data from every element */
/* The correlation matrix is a Ne x Ne matrix */
float complex ** A = malloc(Ne * sizeof(*A));
for(int i = 0; i < Ne; i++)
{
A[i] = malloc(Ne * sizeof(*A[i]));
}
cblas_chpr(layout, Uplo, N, alpha, X, incX, A);
float complex print_val = A[0][0];
printf("%+.10f %+.10f", crealf(print_val), cimagf(print_val));
ただし、「chpr_() at 0x55555555e70b」エラーでプログラムがクラッシュしました。
入力パラメータが正しくないと思います。CBLAS は、Fortran BLAS ライブラリのラッパーです。
以前にこのエラーに遭遇し、解決方法を知っている人はいますか?