/******************************************************************************* * * TRIQS: a Toolbox for Research in Interacting Quantum Systems * * Copyright (C) 2011 by O. Parcollet * * TRIQS is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * TRIQS. If not, see . * ******************************************************************************/ #ifndef TRIQS_ARRAYS_HDF5_ARRAY_PROXY_IMPL_H #define TRIQS_ARRAYS_HDF5_ARRAY_PROXY_IMPL_H //#define TRIQS_ARRAYS_DEBUG_H5_SLICE #include "../indexmaps/cuboid/domain.hpp" #include "./group_or_file.hpp" #include "../impl/sliceable_object.hpp" #include "../impl/tuple_tools.hpp" #include #include namespace triqs { namespace arrays { namespace h5 { template struct array_proxy_option {}; } namespace Option { template struct Im_Opt_2_Opt > { typedef h5::array_proxy_option type;}; } namespace h5 { template class index_system { public : static const unsigned int rank= Rank, rank_full = Rank_full; typedef mini_vector v_type; typedef mini_vector v_type_full; typedef indexmaps::cuboid::domain domain_type; domain_type const & domain() const { return mydomain;} index_system (v_type_full const & total_lengths_) { total_lens_ = total_lengths_; lens_= total_lengths_; for (size_t i =0; i DataSpace dataspace() const { return h5::dataspace_from_LS (total_lens_, lens_,stri_,off_); } size_t size() const { size_t _size = 1; for (size_t i =0; i total_lengths() const { return this->total_lens_;} mini_vector lengths() const { return this->lens_;} mini_vector strides() const { return this->stri_;} private: mini_vector lens_, off_, stri_; v_type dims; v_type_full total_lens_; domain_type mydomain; }; namespace slicer_impl { template inline void _check_BC ( int N, int ind, size_t B) { } template <> inline void _check_BC (int N, int ind, size_t B) { bool cond = (ind >= 0) && (ind < int(B)); // fix this int ... if (!cond) TRIQS_ARRAYS_KEY_ERROR << " index "< struct slice_calc { typedef mini_vector const & i_type; typedef mini_vector & o_type; typedef mini_vector & os_type; template< typename ArgsTuple> static void invoke(i_type li, i_type si, os_type lo_c, o_type lo, o_type so, o_type offset, ArgsTuple const & args ) { const int dP = boost::is_base_of::type, range >::type::value ; one_step(li[N], si[N],lo[N],so[N], offset[N] ,boost::tuples::get(args)); lo_c[P] = lo[N]; slice_calc::invoke(li,si,lo_c,lo,so, offset, args); } static void one_step(size_t li, size_t si, size_t & lo, size_t & so, size_t & offset, size_t R){ _check_BC (N, R, li); offset = R; lo =1; so= 1; } static void one_step(size_t li, size_t si, size_t & lo, size_t & so, size_t & offset, range R){ _check_BC (N, R.first(),li); _check_BC (N, (R.last()==-1 ? li : R.last()) -1 ,li); lo = ((R.last()==-1 ? li : R.last()) - R.first() + R.step()-1 )/R.step() ; // python behaviour so = R.step(); offset = R.first() ; } }; // stop the recursion template struct slice_calc : slice_calc { template static void invoke(T1,T2,T3,T4,T5,T6,T7 ) {} }; }//namespace slicer_impl } // h5 namespace indexmaps { template struct slicer < h5::index_system, ArgsTuple> { static const unsigned int len = boost::tuples::length::value; static_assert(len>=R, "Too few arguments in slice"); static_assert(len<=R, "Too many arguments in slice"); static_assert( (R==Rf), "Can not slice array_proxy twice (not implemented)"); static const unsigned int R2 = R - TupleTools::CountHowManyInt::value; typedef h5::index_system< R2, Rf> return_type; static return_type invoke ( h5::index_system const & X, ArgsTuple args) { mini_vector newdims; mini_vector newoffset, newlengths, newstrides; h5::slicer_impl::slice_calc::invoke(X.lengths(),X.strides(),newdims, newlengths,newstrides, newoffset, args); #ifdef TRIQS_ARRAYS_DEBUG_H5_SLICE std::cerr<<"-----------------------------------------------"< struct slicer < h5::index_system, boost::tuple<> > { typedef h5::index_system< R,Rf> return_type;}; } }} #endif