Reputation: 4318
How can I get the size of gsl_vector_view
? I have the following function for sampling multivariate Gaussian vector
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);
}
In order to pass vectors and matrices I am doing following:
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);
but I get this error:
gsl: ./oper_source.c:27: ERROR: vectors must have same length
Default GSL error handler invoked.
So I would like to print the gsl_vector_view
. What is the way to do it?
I used & vecH_view.vector->size
and it returns error.
Upvotes: 1
Views: 1127
Reputation: 332
"Trial and error" always works for me. I provide a minimal example below:
#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
Upvotes: 1