Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/base/copy.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_COPY_HPP
00002 #define SKYLARK_COPY_HPP
00003 
00004 namespace skylark { namespace base {
00005 
00006 // TODO copy sparse to sparse.
00007 
00008 #if SKYLARK_HAVE_ELEMENTAL
00009 
00013 template<typename T>
00014 inline void DenseCopy(const sparse_matrix_t<T>& A, elem::Matrix<T>& B) {
00015     if (B.Height() != A.height() || B.Width() != A.width())
00016         B.Resize(A.height(), A.width());
00017 
00018     elem::Zero(B);
00019 
00020     const int *indptr = A.indptr();
00021     const int *indices = A.indices();
00022     const double *values = A.locked_values();
00023     for(int col = 0; col < A.width(); col++)
00024         for(int idx = indptr[col]; idx < indptr[col + 1]; idx++)
00025             B.Set(indices[idx], col, values[idx]);
00026 }
00027 
00031 template<typename T>
00032 inline void DenseCopy(const elem::Matrix<T>& A, elem::Matrix<T>& B) {
00033     elem::Copy(A, B);
00034 }
00035 
00036 #endif
00037 
00038 } } // namespace skylark::base
00039 
00040 #endif // SKYLARK_COPY_HPP