Skylark (Sketching Library)
0.1
|
00001 #ifndef SKYLARK_VIEWING_HPP 00002 #define SKYLARK_VIEWING_HPP 00003 00004 namespace skylark { namespace base { 00005 00006 #if SKYLARK_HAVE_ELEMENTAL 00007 00008 template<typename T> 00009 inline void ColumnView(elem::Matrix<T>& A, elem::Matrix<T>& B, 00010 int j, int width) { 00011 elem::View(A, B, 0, j, B.Height(), width); 00012 } 00013 00014 template<typename T> 00015 inline 00016 const elem::Matrix<T> ColumnView(const elem::Matrix<T>& B, int j, int width) { 00017 elem::Matrix<T> A; 00018 elem::LockedView(A, B, 0, j, B.Height(), width); 00019 return A; 00020 } 00021 00022 #endif 00023 00024 template<typename T> 00025 inline 00026 void ColumnView(sparse_matrix_t<T>& A, sparse_matrix_t<T>& B, int j, int width) { 00027 const int *bindptr = B.indptr(); 00028 const int *bindices = B.indices(); 00029 double *bvalues = B.values(); 00030 00031 int start = bindptr[j]; 00032 int *indptr = new int[width + 1]; 00033 for (int i = 0; i <= width; i++) 00034 indptr[i] = bindptr[j + i] - start; 00035 const int *indices = bindices + start; 00036 double *values = bvalues + start; 00037 00038 A.attach(indptr, indices, values, indptr[width], A.height(), width, 00039 true, false, false); 00040 } 00041 00042 template<typename T> 00043 inline 00044 sparse_matrix_t<T> ColumnView(const sparse_matrix_t<T>& B, int j, int width) { 00045 sparse_matrix_t<T> A; 00046 ColumnView(A, const_cast<sparse_matrix_t<T>&>(B), j, width); 00047 return A; 00048 } 00049 00050 } } // namespace skylark::base 00051 00052 #endif // SKYLARK_VIEWING_HPP