diff --git a/CMakeLists.txt b/CMakeLists.txt index d801d32..9d0fd38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,17 +22,20 @@ endif() 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}) add_test(NAME iutest COMMAND iutest) -#add_executable(mautest src/ma_unit_test.cc) -#target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES}) -#add_test(NAME mautest COMMAND mautest) +add_executable(mautest src/tests/ma_unit_test.cc ${MA_CC_FILES}) +target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES}) +add_test(NAME mautest COMMAND mautest) -#add_executable(oputest src/op_unit_test.cc) -#target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES}) -#add_test(NAME oputest COMMAND oputest) +add_executable(oputest src/tests/op_unit_test.cc ${MA_CC_FILES}) +target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES}) +add_test(NAME oputest COMMAND oputest) #install(TARGETS testm DESTINATION install) diff --git a/src/block/bbase_def.h b/src/block/bbase_def.h new file mode 100644 index 0000000..129dcd2 --- /dev/null +++ b/src/block/bbase_def.h @@ -0,0 +1,60 @@ + + +#ifndef __bbase_def_h__ +#define __bbase_def_h__ + +namespace MultiArrayHelper +{ + + template + class BlockBinaryOp; + + + template + class BlockBase; + + + template + class MutableBlockBase; + + + template + class Block; + + + template + class MBlock; + + + template + class BlockValue; + + + template + class MBlockValue; + + + template + class SplitBlock; + + + template + class MSplitBlock; + + + template + class BlockResult; + + + enum class BlockType { + INDEF = 0, + BLOCK = 1, + VALUE = 2, + SPLIT = 3, + RESULT = 4 + }; + + +} // end namespace MultiArrayHelper + +#endif diff --git a/src/block.h b/src/block/block.h similarity index 91% rename from src/block.h rename to src/block/block.h index 80957a4..032fdf2 100644 --- a/src/block.h +++ b/src/block/block.h @@ -7,58 +7,10 @@ #include #include "base_def.h" +#include "block/bbase_def.h" namespace MultiArrayHelper { - - - template - class BlockBinaryOp; - - - template - class BlockBase; - - - template - class MutableBlockBase; - - - template - class Block; - - - template - class MBlock; - - - template - class BlockValue; - - - template - class MBlockValue; - - - template - class SplitBlock; - - - template - class MSplitBlock; - - - template - class BlockResult; - - - enum class BlockType { - INDEF = 0, - BLOCK = 1, - VALUE = 2, - SPLIT = 3, - RESULT = 4 - }; // manage vectorization in the future !! diff --git a/src/mbase_def.h b/src/mbase_def.h index 23f4379..f3fb0bb 100644 --- a/src/mbase_def.h +++ b/src/mbase_def.h @@ -8,73 +8,6 @@ namespace MultiArrayTools * Provided Types * ***********************/ - // range_base.h - enum class SpaceType; - - // range_base.h - class RangeFactoryBase; - - // range_base.h - class RangeBase; - - // range_base.h - template - class RangeInterface; - - // index_base.h - class VirtualIndexWrapperBase; - typedef VirtualIndexWrapperBase VIWB; - - // index_base.h - template - class IndexWrapper; - - // index_base.h - template - class IndexInterface; - - // single_range.h - template - class SingleRange; - - // single_range.h - template - class SingleRangeFactory; - - // single_range.h - template - class SingleIndex; - - // multi_range.h - template - class MultiRangeFactory; - - // multi_range.h - template - class MultiRange; - - // multi_range.h - template - class MultiIndex; - - // container_range.h - template - class ContainerRangeFactory; - - // container_range.h - template - class ContainerRange; - - // container_range.h - template - class ContainerIndex; - - // anonymous_range.h - class AnonymousRangeFactory; - - // anonymous_range.h - class AnonymousRange; - // multi_array.h template class MultiArrayBase; diff --git a/src/multi_array.h b/src/multi_array.h index bbb6733..79ae408 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -10,10 +10,9 @@ #include #include "base_def.h" -#include "multi_range.h" -//#include "multi_array_operation.h" -//#include "manipulator.h" -// +#include "mbase_def.h" + +#include "ranges/rheader.h" namespace MultiArrayTools { @@ -36,7 +35,6 @@ namespace MultiArrayTools const_iterator(const MultiArrayBase& ma); const_iterator(const MultiArrayBase& ma, const typename CRange::IndexType& index); - virtual ~const_iterator() = default; // Requirements: bool operator==(const const_iterator& it) const; @@ -127,7 +125,6 @@ namespace MultiArrayTools iterator(MutableMultiArrayBase& ma); iterator(MutableMultiArrayBase& ma, const IndexType& index); - virtual ~iterator() = default; // Requirements: bool operator==(const iterator& it) const; diff --git a/src/multi_array_header.h b/src/multi_array_header.h index e519adc..9dd1e2b 100644 --- a/src/multi_array_header.h +++ b/src/multi_array_header.h @@ -4,13 +4,13 @@ #define __multi_array_header_h__ #include -#include "base_def.h" -#include "range_base.h" -#include "index_base.h" -#include "single_range.h" -#include "multi_range.h" -#include "container_range.h" -#include "block.h" +//#include "base_def.h" +//#include "range_base.h" +//#include "index_base.h" +//#include "single_range.h" +//#include "multi_range.h" +//#include "container_range.h" +//#include "block.h" #include "multi_array_operation.h" #include "multi_array.h" #include "helper_tools.h" diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 314258c..6af8a1c 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -10,6 +10,10 @@ #include #include "base_def.h" +#include "mbase_def.h" + +#include "block/block.h" +#include "operation_utils.h" namespace MultiArrayTools { @@ -32,15 +36,6 @@ namespace MultiArrayTools * */ - void seekIndexInst(std::shared_ptr i, std::vector >& ivec); - - - // - typedef std::pair BTSS; - - BTSS getBlockType(std::shared_ptr i, - std::shared_ptr j, - bool first, size_t higherStepSize = 1); template Block makeBlock(const T* vec, size_t stepSize, size_t blockSize); @@ -48,11 +43,6 @@ namespace MultiArrayTools template MBlock makeBlock(T* vec, size_t stepSize, size_t blockSize); - size_t getBTNum(const std::vector& mp, BlockType bt); - - void minimizeAppearanceOfType(std::map, std::vector >& mp, - BlockType bt); - template std::shared_ptr seekBlockIndex(std::shared_ptr ownIdx, const OpClass& second); @@ -233,55 +223,6 @@ namespace MultiArrayTools using namespace MultiArrayHelper; } - void seekIndexInst(std::shared_ptr i, std::vector >& 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 i, - std::shared_ptr 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 Block makeBlock(const T* vec, size_t stepSize, size_t blockSize) { @@ -294,40 +235,6 @@ namespace MultiArrayTools return MBlock(vec, 0, blockSize, stepSize); } - size_t getBTNum(const std::vector& mp, BlockType bt) - { - size_t out = 0; - for(auto& xx: mp){ - if(xx.first == bt){ - ++out; - } - } - return out; - } - - void minimizeAppearanceOfType(std::map, std::vector >& 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 std::shared_ptr seekBlockIndex(std::shared_ptr ownIdx, const OpClass& second) diff --git a/src/operation_utils.cc b/src/operation_utils.cc new file mode 100644 index 0000000..ccb608f --- /dev/null +++ b/src/operation_utils.cc @@ -0,0 +1,92 @@ + +#include "operation_utils.h" + +namespace MultiArrayTools +{ + + void seekIndexInst(std::shared_ptr i, std::vector >& 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 i, + std::shared_ptr 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& mp, BlockType bt) + { + size_t out = 0; + for(auto& xx: mp){ + if(xx.first == bt){ + ++out; + } + } + return out; + } + + void minimizeAppearanceOfType(std::map, std::vector >& 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 diff --git a/src/operation_utils.h b/src/operation_utils.h new file mode 100644 index 0000000..ff87684 --- /dev/null +++ b/src/operation_utils.h @@ -0,0 +1,35 @@ + +#ifndef __operation_utils_h__ +#define __operation_utils_h__ + +#include +#include +#include +#include + +#include "block/block.h" +#include "ranges/vindex_base.h" + +namespace MultiArrayTools +{ + + // + typedef std::pair BTSS; + + + void seekIndexInst(std::shared_ptr i, std::vector >& ivec); + + BTSS getBlockType(std::shared_ptr i, + std::shared_ptr j, + bool first, size_t higherStepSize = 1); + + + size_t getBTNum(const std::vector& mp, BlockType bt); + + void minimizeAppearanceOfType(std::map, std::vector >& mp, + BlockType bt); + + +} // end namespace MultiArrayTools + +#endif diff --git a/src/pack_num.h b/src/pack_num.h index e9100ad..80ec310 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -4,23 +4,19 @@ #define __pack_num_h__ #include -#include +//#include #include -#include +#include #include "base_def.h" namespace MultiArrayHelper { - using namespace MultiArrayTools; - - template - std::ostream& operator<<(std::ostream& out, const std::tuple& tp); template struct PackNum { - + template static void makeBlockTypeVec(std::vector >& btv, const std::tuple& ops, @@ -28,13 +24,13 @@ namespace MultiArrayHelper { auto subvec = std::move( std::get(ops).block(idxPtr) ); btv.insert(btv.end(), subvec.begin(), subvec.end() ); - PackNum::makeBlockTypeVec(btv, ops, idxPtr); + BPackNum::makeBlockTypeVec(btv, ops, idxPtr); } template static BlockResult unpackArgs(const ArgTuple& tp, const Args&... args) { - return PackNum::template unpackArgs(tp, std::get(tp).get(), args...); + return BPackNum::template unpackArgs(tp, std::get(tp).get(), args...); } template @@ -66,7 +62,7 @@ namespace MultiArrayHelper auto subvec = std::move( std::get<0>(ops).block(idxPtr) ); btv.insert(btv.end(), subvec.begin(), subvec.end() ); } - + template static void printTuple(std::ostream& out, const std::tuple& tp){ out << std::get(tp); @@ -74,12 +70,6 @@ namespace MultiArrayHelper }; - template - std::ostream& operator<<(std::ostream& out, const std::tuple& tp) - { - PackNum::printTuple(out, tp); - return out; - } } // end namespace MultiArrayHelper diff --git a/src/ranges/index_base.h b/src/ranges/index_base.h index 3cf3537..5439b1f 100644 --- a/src/ranges/index_base.h +++ b/src/ranges/index_base.h @@ -14,12 +14,6 @@ namespace MultiArrayTools { - size_t indexId() - { - static size_t id = 0; - ++id; - return id; - } template class IndexInterface diff --git a/src/ranges/range_base.cc b/src/ranges/range_base.cc index fc2b7fb..07e6289 100644 --- a/src/ranges/range_base.cc +++ b/src/ranges/range_base.cc @@ -4,6 +4,13 @@ namespace MultiArrayTools { + size_t indexId() + { + static size_t id = 0; + ++id; + return id; + } + /************************* * RangeFactoryBase * *************************/ diff --git a/src/ranges/range_base.h b/src/ranges/range_base.h index 4f13724..dafaacb 100644 --- a/src/ranges/range_base.h +++ b/src/ranges/range_base.h @@ -18,6 +18,8 @@ namespace MultiArrayTools namespace MultiArrayTools { + + size_t indexId(); enum class SpaceType { diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..6e1344c --- /dev/null +++ b/src/utils.h @@ -0,0 +1,30 @@ + +#ifndef __utils_h__ +#define __utils_h__ + +#include +#include "pack_num.h" + +namespace MultiArrayHelper +{ + + using namespace MultiArrayTools; + + template + std::ostream& operator<<(std::ostream& out, const std::tuple& tp); + + /*==================* + * TEMPLATE CODE * + *==================*/ + + template + std::ostream& operator<<(std::ostream& out, const std::tuple& tp) + { + PackNum::printTuple(out, tp); + return out; + } + + +} // end namespace MultiArrayHelper + +#endif