2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ViennaCL::compressed_matrixに直接データを指定する方法

Last updated at Posted at 2012-10-20

uBLAS版に引き続き、ViennaCL版も書いておくと、こんな感じです。
(というか、これがしたくてuBLAS版頑張った)

viennacl_crs.cpp
// 行列の次元数
const int COUNT = 5;

// 非ゼロ要素数
const int NONZERO_COUNT = 15;

// 要素値
double elements[NONZERO_COUNT] ={
6, 2,    1, 4,
2, 7,       2,
      6, 3,   
1,    3, 9,   
4, 2,       8, 
};
// 列番号
unsigned int columnIndeces[NONZERO_COUNT] ={
0, 1,    3, 4,
0, 1,       4,
      2, 3,   
1,    2, 3,   
0, 1,       4, 
};
// 各行先頭の位置
unsigned int rowOffsets[COUNT+1] ={
0,
4,
7,
9,
12,
15 //=非ゼロ要素数 ※ここ忘れがち
};


// 行列の生成
viennacl::compressed_matrix<double> mat(count, count);

// データの指定
mat.set(rowOffsets, columnIndeces, elements, COUNT, COUNT, NONZERO_COUNT);

あまり解説することもなく、単にsetを使うだけです
コンストラクタでuBLASのcompressed_matrixとかstd::vector>とかも指定できますが、生データがあるならこれが一番速いです。
これでuBLASとデータ共有できますしね!

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?