diff --git a/src/helper_tools.h b/src/helper_tools.h new file mode 100644 index 0000000..13f96d6 --- /dev/null +++ b/src/helper_tools.h @@ -0,0 +1,25 @@ + +#include "base_def.h" + +namespace MultiArrayTools +{ + + template + auto getIndex(std::shared_ptr range) + -> std::shared_ptr; + +} + +// ===================== +// === C O D E === +// ===================== + +namespace MultiArrayTools +{ + template + auto getIndex(std::shared_ptr range) + -> std::shared_ptr + { + return std::dynamic_pointer_cast( range->index() ); + } +} diff --git a/src/multi_array_header.h b/src/multi_array_header.h index 5fde256..e519adc 100644 --- a/src/multi_array_header.h +++ b/src/multi_array_header.h @@ -13,6 +13,7 @@ #include "block.h" #include "multi_array_operation.h" #include "multi_array.h" +#include "helper_tools.h" //#include "slice.h" //#include "manipulator.h" //#include "range_transformer.h" diff --git a/src/op_unit_test.cc b/src/op_unit_test.cc index 8910828..df261e1 100644 --- a/src/op_unit_test.cc +++ b/src/op_unit_test.cc @@ -169,9 +169,9 @@ namespace { MultiArray ma1(sr1ptr, cv1); MultiArray res(mrptr); - auto si1 = std::dynamic_pointer_cast( sr1ptr->index() ); - auto si2 = std::dynamic_pointer_cast( sr2ptr->index() ); - auto mi = std::dynamic_pointer_cast( mrptr->index() ); + auto si1 = MAT::getIndex(sr1ptr); + auto si2 = MAT::getIndex(sr2ptr); + auto mi = MAT::getIndex(mrptr); (*mi)(si2, si1); std::clock_t begin = std::clock(); @@ -208,7 +208,7 @@ namespace { MultiArray ma2(srptr, v2); MultiArray res(srptr); - auto i = std::dynamic_pointer_cast( srptr->index() ); + auto i = MAT::getIndex( srptr ); res(i) = ma1(i) + ma2(i); EXPECT_EQ( fabs( res.at('a') - (2.917+8.870) ) < 0.0001, true); @@ -223,8 +223,8 @@ namespace { const MultiArray ma1(sr2ptr, v1); const MultiArray ma2(sr4ptr, v2); - auto i1 = std::dynamic_pointer_cast( sr2ptr->index() ); - auto i2 = std::dynamic_pointer_cast( sr4ptr->index() ); + auto i1 = MAT::getIndex( sr2ptr ); + auto i2 = MAT::getIndex( sr4ptr ); res(i1,i2) = ma1(i1) * ma2(i2); @@ -245,8 +245,8 @@ namespace { const MultiArray ma1(sr2ptr, v1); const MultiArray ma2(sr4ptr, v2); - auto i1 = std::dynamic_pointer_cast( sr2ptr->index() ); - auto i2 = std::dynamic_pointer_cast( sr4ptr->index() ); + auto i1 = MAT::getIndex( sr2ptr ); + auto i2 = MAT::getIndex( sr4ptr ); res(i1) = (ma1(i1) * ma2(i2)).c(i2); @@ -262,8 +262,8 @@ namespace { MultiArray ma2(sr4ptr, v2); MultiArray ma3(sr4ptr, v4); - auto i1 = std::dynamic_pointer_cast( mr1ptr->index() ); - auto i2 = std::dynamic_pointer_cast( sr4ptr->index() ); + auto i1 = MAT::getIndex( mr1ptr ); + auto i2 = MAT::getIndex( sr4ptr ); res(i1,i2) = ( ma1(i1) + ma2(i2) ) - ma3(i2); @@ -290,10 +290,10 @@ namespace { MultiArray ma2(sr2ptr, v1); MultiArray ma3(sr4ptr, v4); - auto si1 = std::dynamic_pointer_cast( sr2ptr->index() ); - auto si2 = std::dynamic_pointer_cast( sr3ptr->index() ); - auto si3 = std::dynamic_pointer_cast( sr4ptr->index() ); - auto mi = std::dynamic_pointer_cast( mr1ptr->index() ); + auto si1 = MAT::getIndex( sr2ptr ); + auto si2 = MAT::getIndex( sr3ptr ); + auto si3 = MAT::getIndex( sr4ptr ); + auto mi = MAT::getIndex( mr1ptr ); mi->operator()(si1,si2); res(mi,si3) = ma1(mi) + ma2(si1) + ma3(si3);