C中结构体中使用的尖点稀疏矩阵

标签 c cuda sparse-matrix cusp-library

我正在使用cusp带有 CUDA 的库来使用稀疏矩阵。我不能在 C 中的 struct 中使用它吗,例如:

  #include <cusp/coo_matrix.h>
  #include <cusp/multiply.h>
  #include <cusp/print.h>
  #include <cusp/transpose.h>
  struct Cat{
         int id;
         cusp::coo_matrix<int, double, cusp::host_memory> A(2,100,10);
  };
  int main(){
  }

我收到错误:

try.cu(7): error: expected a type specifier
try.cu(7): error: expected a type specifier
try.cu(7): error: expected a type specifier

struct中使用它的正确方法是什么,以便我可以拥有此类结构的数组?

最佳答案

那段代码coo_matrix看起来很像C++模板。 如果是这样,请为您的 Cat struct 提供构造函数并在那里初始化 A:

struct Cat {
  int id;
  cusp::coo_matrix<int, double, cusp::host_memory> A;
  Cat(): id(0), A(2,100,10) {}
}

关于C中结构体中使用的尖点稀疏矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12406231/

相关文章:

c - C 中不一致的求和

c++ - 如果将本地数组乘以零,为什么计时会下降?

c++ - 如何在 Cuda 中使用 struct inside struct

c++ - CUDA编译错误

c++ - 从一个稀疏矩阵中提取一个 block 作为另一个稀疏矩阵

c - 如何将 POSIX 系统调用 fork() 和 wait() 移植到 Visual Studio 2010 Express?

c++ - 使用指针交换整数

c++ - Eigen 用三元组填充稀疏 RowMajor 矩阵

c - 为什么 b 的值为 100?

python - Scipy 相当于 numpy where 对于稀疏矩阵