获取 gsl_vector_view 的大小
getting the size of gsl_vector_view
如何获取 gsl_vector_view
的大小?我有以下函数用于采样多元高斯向量
void mvnrnd(gsl_vector *x, gsl_matrix *Sigma,gsl_vector *Mu, int K, const gsl_rng *seed){
gsl_matrix *A = gsl_matrix_alloc(K, K);
gsl_matrix_memcpy(A, Sigma);
gsl_linalg_cholesky_decomp (A);
for (int k=0; k<K; k++){
gsl_vector_set (x, k, gsl_ran_ugaussian (seed));
}
gsl_blas_dtrmv (CblasLower, CblasNoTrans, CblasNonUnit, A, x);
gsl_vector_add (x, Mu);
}
为了传递向量和矩阵,我正在执行以下操作:
gsl_matrix *MuH = gsl_matrix_calloc(Kest*Kest,1);
gsl_matrix *vecH = gsl_matrix_calloc(Kest*Kest,1);
gsl_matrix *SigmaH = gsl_matrix_calloc(Kest*Kest,Kest*Kest);
gsl_matrix_memcpy (SigmaH, &Q_view.matrix);
gsl_vector_view vecH_view = gsl_matrix_subcolumn (vecH, 0, 0, Kest*Kest);
gsl_vector_view MuH_view = gsl_matrix_column (MuB, 0);
mvnrnd(&vecH_view.vector, SigmaH , &MuH_view.vector, Kest*Kest, seed);
但我收到此错误:
gsl: ./oper_source.c:27: ERROR: vectors must have same length
Default GSL error handler invoked.
所以我想打印 gsl_vector_view
。有什么方法可以做到?
我使用 & vecH_view.vector->size
并且它 returns 错误。
"Trial and error" 总是适合我。我在下面提供了一个最小的例子:
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
int main()
{
gsl_matrix * y = gsl_matrix_calloc(6,6);
gsl_vector_view z = gsl_matrix_column(y,0);
printf("size = %ld\n",(&z.vector)->size);
gsl_matrix_free(y);
}
$ gcc -Wall -pedantic-errors -O0 se.c -lgsl -lgslcblas -lm && ./a.out
size = 6
如何获取 gsl_vector_view
的大小?我有以下函数用于采样多元高斯向量
void mvnrnd(gsl_vector *x, gsl_matrix *Sigma,gsl_vector *Mu, int K, const gsl_rng *seed){
gsl_matrix *A = gsl_matrix_alloc(K, K);
gsl_matrix_memcpy(A, Sigma);
gsl_linalg_cholesky_decomp (A);
for (int k=0; k<K; k++){
gsl_vector_set (x, k, gsl_ran_ugaussian (seed));
}
gsl_blas_dtrmv (CblasLower, CblasNoTrans, CblasNonUnit, A, x);
gsl_vector_add (x, Mu);
}
为了传递向量和矩阵,我正在执行以下操作:
gsl_matrix *MuH = gsl_matrix_calloc(Kest*Kest,1);
gsl_matrix *vecH = gsl_matrix_calloc(Kest*Kest,1);
gsl_matrix *SigmaH = gsl_matrix_calloc(Kest*Kest,Kest*Kest);
gsl_matrix_memcpy (SigmaH, &Q_view.matrix);
gsl_vector_view vecH_view = gsl_matrix_subcolumn (vecH, 0, 0, Kest*Kest);
gsl_vector_view MuH_view = gsl_matrix_column (MuB, 0);
mvnrnd(&vecH_view.vector, SigmaH , &MuH_view.vector, Kest*Kest, seed);
但我收到此错误:
gsl: ./oper_source.c:27: ERROR: vectors must have same length
Default GSL error handler invoked.
所以我想打印 gsl_vector_view
。有什么方法可以做到?
我使用 & vecH_view.vector->size
并且它 returns 错误。
"Trial and error" 总是适合我。我在下面提供了一个最小的例子:
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
int main()
{
gsl_matrix * y = gsl_matrix_calloc(6,6);
gsl_vector_view z = gsl_matrix_column(y,0);
printf("size = %ld\n",(&z.vector)->size);
gsl_matrix_free(y);
}
$ gcc -Wall -pedantic-errors -O0 se.c -lgsl -lgslcblas -lm && ./a.out
size = 6