This commit is contained in:
Christian Zimmermann 2017-12-18 11:19:04 +01:00
parent 5f319cf1d5
commit 7a716d662d
14 changed files with 257 additions and 255 deletions

View file

@ -22,17 +22,20 @@ endif()
include_directories(src) include_directories(src)
add_executable(iutest src/ranges/tests/index_unit_test.cc src/ranges/range_base.cc) set(INDEX_CC_FILES "${INDEX_CC_FILES}" "src/ranges/range_base.cc")
set(MA_CC_FILES "${MA_CC_FILES}" "${INDEX_CC_FILES}" "src/operation_utils.cc")
add_executable(iutest src/ranges/tests/index_unit_test.cc ${INDEX_CC_FILES})
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES}) target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES})
add_test(NAME iutest COMMAND iutest) add_test(NAME iutest COMMAND iutest)
#add_executable(mautest src/ma_unit_test.cc) add_executable(mautest src/tests/ma_unit_test.cc ${MA_CC_FILES})
#target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES}) target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES})
#add_test(NAME mautest COMMAND mautest) add_test(NAME mautest COMMAND mautest)
#add_executable(oputest src/op_unit_test.cc) add_executable(oputest src/tests/op_unit_test.cc ${MA_CC_FILES})
#target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES}) target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES})
#add_test(NAME oputest COMMAND oputest) add_test(NAME oputest COMMAND oputest)
#install(TARGETS testm DESTINATION install) #install(TARGETS testm DESTINATION install)

60
src/block/bbase_def.h Normal file
View file

@ -0,0 +1,60 @@
#ifndef __bbase_def_h__
#define __bbase_def_h__
namespace MultiArrayHelper
{
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
class BlockBinaryOp;
template <typename T>
class BlockBase;
template <typename T>
class MutableBlockBase;
template <typename T>
class Block;
template <typename T>
class MBlock;
template <typename T>
class BlockValue;
template <typename T>
class MBlockValue;
template <typename T>
class SplitBlock;
template <typename T>
class MSplitBlock;
template <typename T>
class BlockResult;
enum class BlockType {
INDEF = 0,
BLOCK = 1,
VALUE = 2,
SPLIT = 3,
RESULT = 4
};
} // end namespace MultiArrayHelper
#endif

View file

@ -7,59 +7,11 @@
#include <vector> #include <vector>
#include "base_def.h" #include "base_def.h"
#include "block/bbase_def.h"
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
class BlockBinaryOp;
template <typename T>
class BlockBase;
template <typename T>
class MutableBlockBase;
template <typename T>
class Block;
template <typename T>
class MBlock;
template <typename T>
class BlockValue;
template <typename T>
class MBlockValue;
template <typename T>
class SplitBlock;
template <typename T>
class MSplitBlock;
template <typename T>
class BlockResult;
enum class BlockType {
INDEF = 0,
BLOCK = 1,
VALUE = 2,
SPLIT = 3,
RESULT = 4
};
// manage vectorization in the future !! // manage vectorization in the future !!
template <typename T, class OpFunc, class BlockClass1, class BlockClass2> template <typename T, class OpFunc, class BlockClass1, class BlockClass2>

View file

@ -8,73 +8,6 @@ namespace MultiArrayTools
* Provided Types * * Provided Types *
***********************/ ***********************/
// range_base.h
enum class SpaceType;
// range_base.h
class RangeFactoryBase;
// range_base.h
class RangeBase;
// range_base.h
template <class Index>
class RangeInterface;
// index_base.h
class VirtualIndexWrapperBase;
typedef VirtualIndexWrapperBase VIWB;
// index_base.h
template <class I>
class IndexWrapper;
// index_base.h
template <class I, typename MetaType>
class IndexInterface;
// single_range.h
template <typename U, SpaceType TYPE>
class SingleRange;
// single_range.h
template <typename U, SpaceType TYPE>
class SingleRangeFactory;
// single_range.h
template <typename U, SpaceType TYPE>
class SingleIndex;
// multi_range.h
template <class... Ranges>
class MultiRangeFactory;
// multi_range.h
template <class... Ranges>
class MultiRange;
// multi_range.h
template <class... Indices>
class MultiIndex;
// container_range.h
template <class... Ranges>
class ContainerRangeFactory;
// container_range.h
template <class... Ranges>
class ContainerRange;
// container_range.h
template <class... Indices>
class ContainerIndex;
// anonymous_range.h
class AnonymousRangeFactory;
// anonymous_range.h
class AnonymousRange;
// multi_array.h // multi_array.h
template <typename T, class... SRanges> template <typename T, class... SRanges>
class MultiArrayBase; class MultiArrayBase;

View file

@ -10,10 +10,9 @@
#include <algorithm> #include <algorithm>
#include "base_def.h" #include "base_def.h"
#include "multi_range.h" #include "mbase_def.h"
//#include "multi_array_operation.h"
//#include "manipulator.h" #include "ranges/rheader.h"
//
namespace MultiArrayTools namespace MultiArrayTools
{ {
@ -36,7 +35,6 @@ namespace MultiArrayTools
const_iterator(const MultiArrayBase& ma); const_iterator(const MultiArrayBase& ma);
const_iterator(const MultiArrayBase& ma, const typename CRange::IndexType& index); const_iterator(const MultiArrayBase& ma, const typename CRange::IndexType& index);
virtual ~const_iterator() = default;
// Requirements: // Requirements:
bool operator==(const const_iterator& it) const; bool operator==(const const_iterator& it) const;
@ -127,7 +125,6 @@ namespace MultiArrayTools
iterator(MutableMultiArrayBase& ma); iterator(MutableMultiArrayBase& ma);
iterator(MutableMultiArrayBase& ma, const IndexType& index); iterator(MutableMultiArrayBase& ma, const IndexType& index);
virtual ~iterator() = default;
// Requirements: // Requirements:
bool operator==(const iterator& it) const; bool operator==(const iterator& it) const;

View file

@ -4,13 +4,13 @@
#define __multi_array_header_h__ #define __multi_array_header_h__
#include <cstdlib> #include <cstdlib>
#include "base_def.h" //#include "base_def.h"
#include "range_base.h" //#include "range_base.h"
#include "index_base.h" //#include "index_base.h"
#include "single_range.h" //#include "single_range.h"
#include "multi_range.h" //#include "multi_range.h"
#include "container_range.h" //#include "container_range.h"
#include "block.h" //#include "block.h"
#include "multi_array_operation.h" #include "multi_array_operation.h"
#include "multi_array.h" #include "multi_array.h"
#include "helper_tools.h" #include "helper_tools.h"

View file

@ -10,6 +10,10 @@
#include <utility> #include <utility>
#include "base_def.h" #include "base_def.h"
#include "mbase_def.h"
#include "block/block.h"
#include "operation_utils.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {
@ -32,15 +36,6 @@ namespace MultiArrayTools
* *
*/ */
void seekIndexInst(std::shared_ptr<VIWB> i, std::vector<std::shared_ptr<VIWB> >& ivec);
// <block type, step size within actual instance>
typedef std::pair<BlockType,size_t> BTSS;
BTSS getBlockType(std::shared_ptr<VIWB> i,
std::shared_ptr<VIWB> j,
bool first, size_t higherStepSize = 1);
template <typename T> template <typename T>
Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize); Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize);
@ -48,11 +43,6 @@ namespace MultiArrayTools
template <typename T> template <typename T>
MBlock<T> makeBlock(T* vec, size_t stepSize, size_t blockSize); MBlock<T> makeBlock(T* vec, size_t stepSize, size_t blockSize);
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt);
void minimizeAppearanceOfType(std::map<std::shared_ptr<VIWB>, std::vector<BTSS> >& mp,
BlockType bt);
template <class OpClass> template <class OpClass>
std::shared_ptr<VIWB> seekBlockIndex(std::shared_ptr<VIWB> ownIdx, std::shared_ptr<VIWB> seekBlockIndex(std::shared_ptr<VIWB> ownIdx,
const OpClass& second); const OpClass& second);
@ -233,55 +223,6 @@ namespace MultiArrayTools
using namespace MultiArrayHelper; using namespace MultiArrayHelper;
} }
void seekIndexInst(std::shared_ptr<VIWB> i, std::vector<std::shared_ptr<VIWB> >& ivec)
{
for(size_t inum = 0; inum != i->rangePtr()->dim(); ++inum){
auto ii = i->getPtr(inum);
if(ii->type() == IndexType::MULTI or
ii->type() == IndexType::CONT){
seekIndexInst(ii, ivec);
}
ivec.push_back(ii);
}
}
BTSS getBlockType(std::shared_ptr<VIWB> i,
std::shared_ptr<VIWB> j,
bool first, size_t higherStepSize)
{
// returning BlockType and step size is redundant (change in the future)
// stepSize == 0 => VALUE
// stepSize == 1 => BLOCK
// stepSize > 1 => SPLIT :)
BTSS out(BlockType::VALUE, 0);
size_t lastNum = i->rangePtr()->dim();
for(size_t inum = 0; inum != lastNum; ++inum){
auto ii = i->getPtr(inum);
if(ii->getPtrNum() == j->getPtrNum()){
if(inum == lastNum - 1 and first){
out = BTSS(BlockType::BLOCK, 1);
}
else {
first = false;
out = BTSS(BlockType::SPLIT, i->getStepSize(inum) * higherStepSize + out.second);
}
continue;
}
if(ii->type() == IndexType::MULTI or
ii->type() == IndexType::CONT){
BTSS tmp = getBlockType(ii, j, inum == lastNum - 1, i->getStepSize(inum) * higherStepSize);
if(tmp.first != BlockType::VALUE){
out = tmp;
}
}
}
return out;
}
template <typename T> template <typename T>
Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize) Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize)
{ {
@ -294,40 +235,6 @@ namespace MultiArrayTools
return MBlock<T>(vec, 0, blockSize, stepSize); return MBlock<T>(vec, 0, blockSize, stepSize);
} }
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt)
{
size_t out = 0;
for(auto& xx: mp){
if(xx.first == bt){
++out;
}
}
return out;
}
void minimizeAppearanceOfType(std::map<std::shared_ptr<VIWB>, std::vector<BTSS> >& mp,
BlockType bt)
{
size_t minNum = getBTNum( mp.begin()->second, bt );
for(auto& mm: mp){
size_t tmp = getBTNum( mm.second, bt );
if(tmp < minNum){
minNum = tmp;
}
}
for(auto mit = mp.begin(); mit != mp.end(); ){
size_t tmp = getBTNum( mit->second, bt );
if(tmp > minNum){
mit = mp.erase(mit);
}
else {
++mit;
}
}
}
template <class OpClass> template <class OpClass>
std::shared_ptr<VIWB> seekBlockIndex(std::shared_ptr<VIWB> ownIdx, std::shared_ptr<VIWB> seekBlockIndex(std::shared_ptr<VIWB> ownIdx,
const OpClass& second) const OpClass& second)

92
src/operation_utils.cc Normal file
View file

@ -0,0 +1,92 @@
#include "operation_utils.h"
namespace MultiArrayTools
{
void seekIndexInst(std::shared_ptr<VIWB> i, std::vector<std::shared_ptr<VIWB> >& ivec)
{
for(size_t inum = 0; inum != i->rangePtr()->dim(); ++inum){
auto ii = i->getPtr(inum);
if(ii->type() == IndexType::MULTI or
ii->type() == IndexType::CONT){
seekIndexInst(ii, ivec);
}
ivec.push_back(ii);
}
}
BTSS getBlockType(std::shared_ptr<VIWB> i,
std::shared_ptr<VIWB> j,
bool first, size_t higherStepSize)
{
// returning BlockType and step size is redundant (change in the future)
// stepSize == 0 => VALUE
// stepSize == 1 => BLOCK
// stepSize > 1 => SPLIT :)
BTSS out(BlockType::VALUE, 0);
size_t lastNum = i->rangePtr()->dim();
for(size_t inum = 0; inum != lastNum; ++inum){
auto ii = i->getPtr(inum);
if(ii->getPtrNum() == j->getPtrNum()){
if(inum == lastNum - 1 and first){
out = BTSS(BlockType::BLOCK, 1);
}
else {
first = false;
out = BTSS(BlockType::SPLIT, i->getStepSize(inum) * higherStepSize + out.second);
}
continue;
}
if(ii->type() == IndexType::MULTI or
ii->type() == IndexType::CONT){
BTSS tmp = getBlockType(ii, j, inum == lastNum - 1, i->getStepSize(inum) * higherStepSize);
if(tmp.first != BlockType::VALUE){
out = tmp;
}
}
}
return out;
}
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt)
{
size_t out = 0;
for(auto& xx: mp){
if(xx.first == bt){
++out;
}
}
return out;
}
void minimizeAppearanceOfType(std::map<std::shared_ptr<VIWB>, std::vector<BTSS> >& mp,
BlockType bt)
{
size_t minNum = getBTNum( mp.begin()->second, bt );
for(auto& mm: mp){
size_t tmp = getBTNum( mm.second, bt );
if(tmp < minNum){
minNum = tmp;
}
}
for(auto mit = mp.begin(); mit != mp.end(); ){
size_t tmp = getBTNum( mit->second, bt );
if(tmp > minNum){
mit = mp.erase(mit);
}
else {
++mit;
}
}
}
} // end namespace MultiArrayTools

35
src/operation_utils.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef __operation_utils_h__
#define __operation_utils_h__
#include <utility>
#include <vector>
#include <memory>
#include <map>
#include "block/block.h"
#include "ranges/vindex_base.h"
namespace MultiArrayTools
{
// <block type, step size within actual instance>
typedef std::pair<BlockType,size_t> BTSS;
void seekIndexInst(std::shared_ptr<VIWB> i, std::vector<std::shared_ptr<VIWB> >& ivec);
BTSS getBlockType(std::shared_ptr<VIWB> i,
std::shared_ptr<VIWB> j,
bool first, size_t higherStepSize = 1);
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt);
void minimizeAppearanceOfType(std::map<std::shared_ptr<VIWB>, std::vector<BTSS> >& mp,
BlockType bt);
} // end namespace MultiArrayTools
#endif

View file

@ -4,18 +4,14 @@
#define __pack_num_h__ #define __pack_num_h__
#include <cstdlib> #include <cstdlib>
#include <type_traits> //#include <type_traits>
#include <tuple> #include <tuple>
#include <memory> #include <ostream>
#include "base_def.h" #include "base_def.h"
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
using namespace MultiArrayTools;
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp);
template <size_t N> template <size_t N>
struct PackNum struct PackNum
@ -28,13 +24,13 @@ namespace MultiArrayHelper
{ {
auto subvec = std::move( std::get<N>(ops).block(idxPtr) ); auto subvec = std::move( std::get<N>(ops).block(idxPtr) );
btv.insert(btv.end(), subvec.begin(), subvec.end() ); btv.insert(btv.end(), subvec.begin(), subvec.end() );
PackNum<N-1>::makeBlockTypeVec(btv, ops, idxPtr); BPackNum<N-1>::makeBlockTypeVec(btv, ops, idxPtr);
} }
template <typename T, class Func, class ArgTuple, class... Args> template <typename T, class Func, class ArgTuple, class... Args>
static BlockResult<T> unpackArgs(const ArgTuple& tp, const Args&... args) static BlockResult<T> unpackArgs(const ArgTuple& tp, const Args&... args)
{ {
return PackNum<N-1>::template unpackArgs<T,Func>(tp, std::get<N>(tp).get(), args...); return BPackNum<N-1>::template unpackArgs<T,Func>(tp, std::get<N>(tp).get(), args...);
} }
template <typename... T> template <typename... T>
@ -74,12 +70,6 @@ namespace MultiArrayHelper
}; };
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp)
{
PackNum<sizeof...(T)-1>::printTuple(out, tp);
return out;
}
} // end namespace MultiArrayHelper } // end namespace MultiArrayHelper

View file

@ -14,12 +14,6 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
size_t indexId()
{
static size_t id = 0;
++id;
return id;
}
template <class I, typename MetaType> template <class I, typename MetaType>
class IndexInterface class IndexInterface

View file

@ -4,6 +4,13 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
size_t indexId()
{
static size_t id = 0;
++id;
return id;
}
/************************* /*************************
* RangeFactoryBase * * RangeFactoryBase *
*************************/ *************************/

View file

@ -19,6 +19,8 @@ namespace MultiArrayTools
namespace MultiArrayTools namespace MultiArrayTools
{ {
size_t indexId();
enum class SpaceType enum class SpaceType
{ {
NONE = 0, NONE = 0,

30
src/utils.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef __utils_h__
#define __utils_h__
#include <ostream>
#include "pack_num.h"
namespace MultiArrayHelper
{
using namespace MultiArrayTools;
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp);
/*==================*
* TEMPLATE CODE *
*==================*/
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp)
{
PackNum<sizeof...(T)-1>::printTuple(out, tp);
return out;
}
} // end namespace MultiArrayHelper
#endif