获取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
,它返回错误。
"
反复试验"总是对我有用。我在下面提供了一个最小的例子:
#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 = %ldn",(&z.vector)->size);
gsl_matrix_free(y);
}
$ gcc -Wall -pedantic-errors -O0 se.c -lgsl -lgslcblas -lm && ./a.out
size = 6
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中用vector填充一个简单的动态数组
- vector.resize()中的分配错误
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 在某些循环内使用vector.push_back时出现分段错误
- 当vector是tje全局变量时,c++中vector的内存管理
- std::vector的包装器,使数组的结构看起来像结构的数组
- 为什么(-1)%vector::size()总是返回0
- 在C++中将类(带有Vector成员)保存为二进制文件
- 编译器如何区分std::vector的构造函数
- 将 int 数组转换为 std::vector<int*>
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 在std::vector上存储带有模板的类实例
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 为什么std::vector比数组慢
- std::vector::迭代器是否可以合法地作为指针
- gsl::gsl_vector与std::vector的开销和效率
- gsl::array_view<const gsl::cstring_view<>> from std::vector<std::string>