im com (slice)

This commit is contained in:
Christian Zimmermann 2018-03-05 21:52:12 +01:00
parent 058d7503d7
commit dcb76cc450
5 changed files with 47 additions and 14 deletions

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
project(multi_array) project(multi_array)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -O3 -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -O3 -g -march=native")
enable_testing() enable_testing()

View file

@ -51,6 +51,14 @@ namespace MultiArrayTools
// multi_array_operation.h // multi_array_operation.h
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
class Contraction; class Contraction;
// slice.h
template <typename T, class... SRanges>
class Slice;
// slice.h
template <typename T, class... SRanges>
class SliceDef;
} }
#endif #endif

View file

@ -51,7 +51,7 @@ namespace MultiArrayHelper
} }
template <class OpTuple, class Expr> template <class OpTuple, class Expr>
static auto mkLoop( const OpTuple& ot, Expr&& exp ) static auto mkLoop( const OpTuple& ot, Expr exp )
-> decltype(std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) )) -> decltype(std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) ))
{ {
return std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) ); return std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) );
@ -92,7 +92,7 @@ namespace MultiArrayHelper
} }
template <class OpTuple, class Expr> template <class OpTuple, class Expr>
static auto mkLoop( const OpTuple& ot, Expr&& exp ) static auto mkLoop( const OpTuple& ot, Expr exp )
-> decltype(std::get<0>(ot).loop( exp )) -> decltype(std::get<0>(ot).loop( exp ))
{ {
return std::get<0>(ot).loop( exp ); return std::get<0>(ot).loop( exp );

View file

@ -35,12 +35,27 @@ namespace MultiArrayTools
template <class... MARanges> template <class... MARanges>
auto define(const std::shared_ptr<typename SRanges::IType>&... inds) auto define(const std::shared_ptr<typename SRanges::IType>&... inds)
-> SliceDef<T,OperationRoot<T,MARanges...> >; -> SliceDef<T,MARanges...>;
private: private:
T* mData; T* mData;
}; };
template <typename T, class... SRanges>
class SliceDef
{
private:
SliceDef() = default;
public:
SliceDef(Slice<T,SRanges...>& sl,
const std::shared_ptr<typename SRanges::IndexType>&... inds);
template <class... ORanges>
SliceDef& operator=(OperationRoot<T,ORanges...>& op);
};
} // end namespace MultiArrayTools } // end namespace MultiArrayTools
/* ========================= * /* ========================= *
@ -122,8 +137,14 @@ namespace MultiArrayTools
//i = std::get<sizeof...(SRanges)>(mBlockSizes); //i = std::get<sizeof...(SRanges)>(mBlockSizes);
return i.setData(data()); return i.setData(data());
} }
/*
SliceDef<T,SRanges...>::
SliceDef(Slice<T,SRanges...>& sl,
const std::shared_ptr<typename SRanges::IndexType>&... inds);
template <class... ORanges>
SliceDef<T,SRanges...>& SliceDef<T,SRanges...>::operator=(OperationRoot<T,ORanges...>& op);
*/
} // end namespace MultiArrayTools } // end namespace MultiArrayTools

View file

@ -174,24 +174,28 @@ namespace {
<< std::endl; << std::endl;
std::vector<double> vres(4*4); std::vector<double> vres(4*4);
std::clock_t begin2 = std::clock();
for(size_t i = 0; i != 1000; ++i){
for(size_t d = 0; d != 4; ++d){ for(size_t d = 0; d != 4; ++d){
for(size_t p = 0; p != 4; ++p){ for(size_t p = 0; p != 4; ++p){
const size_t tidx = d*4 + p; const size_t tidx = d*4 + p;
vres[tidx] = 0.; vres[tidx] = 0.;
for(size_t a = 0; a != 4; ++a){ }
for(size_t b = 0; b != 4; ++b){ }
for(size_t c = 0; c != 4; ++c){ std::clock_t begin2 = std::clock();
const size_t sidx = d*4*4*4*4*4*4*4 + a*5*4*4*4*4*4 + b*5*4*4*4 + + c*5*4 + p; for(size_t i = 0; i != 1000; ++i){
vres[tidx] += data[sidx]; for(size_t a = 0; a != 4; ++a){
for(size_t b = 0; b != 4; ++b){
for(size_t c = 0; c != 4; ++c){
for(size_t d = 0; d != 4; ++d){
for(size_t p = 0; p != 4; ++p){
const size_t tidx = d*4 + p;
const size_t sidx = d*4*4*4*4*4*4*4 + a*5*4*4*4*4*4 + b*5*4*4*4 + + c*5*4 + p;
vres[tidx] += data[sidx];
}
} }
} }
} }
} }
} }
}
std::clock_t end2 = std::clock(); std::clock_t end2 = std::clock();
assert( xround(res1.at(mkts(0,0))) == xround(vres[0]) ); assert( xround(res1.at(mkts(0,0))) == xround(vres[0]) );