| 12 | // some sparse matrix utilities -> should go to linalg |
| 13 | |
| 14 | shared_ptr<SparseMatrixTM<double>> ToSparseMatrix( const Embedding & e ) |
| 15 | { |
| 16 | auto r = e.GetRange(); |
| 17 | auto h = e.Height(); |
| 18 | auto w = e.Width(); |
| 19 | |
| 20 | Array<int> cnt(h); |
| 21 | cnt = 0; |
| 22 | cnt.Range(r) = 1; |
| 23 | |
| 24 | shared_ptr<SparseMatrixTM<double>> sp_mat; |
| 25 | if(e.IsComplex()) |
| 26 | sp_mat = make_shared<SparseMatrix<double, Complex, Complex>>( cnt, w ); |
| 27 | else |
| 28 | sp_mat = make_shared<SparseMatrix<double, double, double>>( cnt, w ); |
| 29 | |
| 30 | auto & mat = *sp_mat; |
| 31 | |
| 32 | for(auto i : Range(r.Size())) |
| 33 | mat(r[i], i) = 1.0; |
| 34 | |
| 35 | return sp_mat; |
| 36 | } |
| 37 | |
| 38 | shared_ptr<SparseMatrixTM<double>> ToSparseMatrix( const EmbeddingTranspose & e ) |
| 39 | { |