示例#1
0
template <typename T, typename MemoryBlock> void save(
    archive& ar
    , std::string const& path
    , alps::numeric::matrix<T, MemoryBlock> const& m
    , std::vector<std::size_t> size   = std::vector<std::size_t>()
                                        , std::vector<std::size_t> chunk  = std::vector<std::size_t>()
                                                , std::vector<std::size_t> offset = std::vector<std::size_t>()
) {
    using std::copy;
    using std::fill_n;
    using alps::cast;
    typedef typename alps::numeric::matrix<T,MemoryBlock>::const_col_element_iterator col_iterator;
    if (is_continuous<T>::value && m.empty())
        ar.write(path, static_cast<typename scalar_type<alps::numeric::matrix<T, MemoryBlock> >::type const *>(NULL), std::vector<std::size_t>());
    else if (is_continuous<T>::value) {
        std::vector<std::size_t> extent(get_extent(m));
        copy(extent.begin(),extent.end(), std::back_inserter(size));
        // We want to write one column:
        chunk.push_back(1);
        // How much memory does the column and the elements it contains need?
        copy(extent.begin()+1,extent.end(), std::back_inserter(chunk));
        std::size_t const offset_col_index = offset.size();
        fill_n(std::back_inserter(offset), extent.size(), 0);
        // Write column by column
        for(std::size_t j=0; j < num_cols(m); ++j) {
            offset[offset_col_index] = j;
            ar.write(path, get_pointer(*(col(m, j).first)), size, chunk, offset);
        }
    } else if (m.empty())
        ar.write(path, static_cast<int const *>(NULL), std::vector<std::size_t>());
    else if (is_vectorizable(m)) {
        size.push_back(num_cols(m));
        size.push_back(num_rows(m));
        // We want to write element by element:
        chunk.push_back(1);
        chunk.push_back(1);
        std::size_t const offset_col_index = offset.size();
        std::size_t const offset_row_index = offset.size()+1;
        offset.push_back(0);
        offset.push_back(0);
        for(std::size_t j=0; j < num_cols(m); ++j) {
            offset[offset_col_index] = j;
            for(std::size_t i=0; i< num_rows(m); ++i) {
                offset[offset_row_index] = i;
                save(ar, path, m(i,j), size, chunk, offset);
            }
        }
    } else {
        if( ar.is_data(path) )
            ar.delete_data(path);
        for(std::size_t j=0; j < num_cols(m); ++j)
            for(std::size_t i=0; i < num_rows(m); ++i)
                save(ar, ar.complete_path(path) + "/" + cast<std::string>(j) + "/" + cast<std::string>(i), m(i,j) );
    }
}
示例#2
0
文件: BaseString.hpp 项目: yliu120/K3
 void serialize(archive& a) const {
   std::size_t len = length();
   a & len;
   if ( buffer ) {
     a.write(buffer, len);
   }
 }