From f8daec171be16175fd31e1986cff3fd9c1f7f74b Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Fri, 9 Dec 2022 08:20:50 -0500 Subject: [PATCH 01/25] Implemented AlignedAllocator --- include/DataFrame/Utils/AlignedAllocator.h | 169 +++++++++++++++++++++ src/CommonMakefile.mk | 9 +- test/CMakeLists.txt | 4 + test/allocator_tester.cc | 133 ++++++++++++++++ 4 files changed, 313 insertions(+), 2 deletions(-) create mode 100644 include/DataFrame/Utils/AlignedAllocator.h create mode 100644 test/allocator_tester.cc diff --git a/include/DataFrame/Utils/AlignedAllocator.h b/include/DataFrame/Utils/AlignedAllocator.h new file mode 100644 index 000000000..891580dab --- /dev/null +++ b/include/DataFrame/Utils/AlignedAllocator.h @@ -0,0 +1,169 @@ +// Hossein Moein +// December 8 2022 +/* +Copyright (c) 2019-2026, Hossein Moein +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +* Neither the name of Hossein Moein and/or the DataFrame nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include + +// ---------------------------------------------------------------------------- + +namespace hmdf +{ + +// Returns aligned pointers when allocations are requested. Default alignment +// is 64B = 512b, sufficient for AVX-512 and most cache line sizes. +// +template +class AlignedAllocator { + +private: + + static_assert(AS >= alignof(T), + "ERROR: The requested alignment must be bigger or equal " + "to Type alignment"); + +public: + + static constexpr std::align_val_t align_value { AS }; + + // std::allocator_traits stuff + // + using value_type = T; + using pointer = T *; + using const_pointer = const T *; + using void_pointer = void *; + using const_void_pointer = const void *; + using reference = T &; + using const_reference = const T &; + using size_type = std::size_t; + using difference_type = ptrdiff_t; + using propagate_on_container_copy_assignment = std::false_type; + using propagate_on_container_move_assignment = std::false_type; + using propagate_on_container_swap = std::false_type; + using is_always_equal = std::true_type; + + // This is only necessary because AlignedAllocator has a second template + // argument for the alignment that will make the default + // std::allocator_traits implementation fail during compilation. + // + template + struct rebind { using other = AlignedAllocator; }; + + [[nodiscard]] inline pointer address(reference r) const { return (&r); } + [[nodiscard]] inline const_pointer + address(const_reference cr) const { return (&cr); } + + [[nodiscard]] constexpr size_type max_size() const { + + return (std::numeric_limits::max() / sizeof(value_type)); + } + +public: + + AlignedAllocator() noexcept = default; + AlignedAllocator(const AlignedAllocator &) noexcept = default; + AlignedAllocator(AlignedAllocator &&) noexcept = default; + ~AlignedAllocator() noexcept = default; + + AlignedAllocator &operator=(AlignedAllocator &&) = default; + AlignedAllocator &operator=(const AlignedAllocator &) = delete; + + template + AlignedAllocator(AlignedAllocator const &) noexcept { } + + // Always return true for stateless allocators. + // + [[nodiscard]] constexpr bool + operator == (const AlignedAllocator &) const { return (true); } + [[nodiscard]] constexpr bool + operator != (const AlignedAllocator &) const { return (false); } + +public: + + inline void construct(pointer p, const_reference val) const { + + new (static_cast(p)) T(val); + } + inline void construct(pointer p) const { + + new (static_cast(p)) T(); + } + + template + inline void construct(U *p, Ts && ... args) const { + + new (static_cast(p)) U(std::forward(args) ...); + } + + inline void destroy(pointer p) const { p->~T(); } + + template + inline void destroy(U *p) const { p->~U(); } + + [[nodiscard]] inline pointer allocate(size_type n_items) const { + + if (n_items == 0) return (nullptr); + if (n_items >= max_size()) + throw std::bad_array_new_length(); + + const auto bytes = n_items * sizeof(value_type); + + return(reinterpret_cast(::operator new[](bytes, align_value))); + } + + // This is the same for all allocators that ignore hints. + // + [[nodiscard]] inline pointer + allocate(size_type n_items, [[maybe_unused]] const void *hint) const { + + return (allocate(n_items)); + } + + inline constexpr void + deallocate(pointer ptr, [[maybe_unused]] size_type n_items) const { + + // According to the C++20 the delete operator must be called with the + // same alignment argument as the new expression. + // The size argument can be omitted but if present must also be equal + // to the one used in new + // + ::operator delete[](ptr, align_value); + } +}; + +} // namespace std + +// ---------------------------------------------------------------------------- + +// Local Variables: +// mode:C++ +// tab-width:4 +// c-basic-offset:4 +// End: diff --git a/src/CommonMakefile.mk b/src/CommonMakefile.mk index 377ae853d..676467416 100644 --- a/src/CommonMakefile.mk +++ b/src/CommonMakefile.mk @@ -82,6 +82,7 @@ TARGETS += $(TARGET_LIB) \ $(LOCAL_BIN_DIR)/dataframe_performance \ $(LOCAL_BIN_DIR)/dataframe_performance_2 \ $(LOCAL_BIN_DIR)/vectors_tester \ + $(LOCAL_BIN_DIR)/allocator_tester \ $(LOCAL_BIN_DIR)/vector_ptr_view_tester \ $(LOCAL_BIN_DIR)/date_time_tester \ $(LOCAL_BIN_DIR)/gen_rand_tester @@ -178,6 +179,10 @@ VECTORS_TESTER_OBJ = $(LOCAL_OBJ_DIR)/vectors_tester.o $(LOCAL_BIN_DIR)/vectors_tester: $(TARGET_LIB) $(VECTORS_TESTER_OBJ) $(CXX) -o $@ $(VECTORS_TESTER_OBJ) $(LIBS) +ALLOCATOR_TESTER_OBJ = $(LOCAL_OBJ_DIR)/allocator_tester.o +$(LOCAL_BIN_DIR)/allocator_tester: $(TARGET_LIB) $(ALLOCATOR_TESTER_OBJ) + $(CXX) -o $@ $(ALLOCATOR_TESTER_OBJ) $(LIBS) + VECTOR_PTR_VIEW_TESTER_OBJ = $(LOCAL_OBJ_DIR)/vector_ptr_view_tester.o $(LOCAL_BIN_DIR)/vector_ptr_view_tester: $(TARGET_LIB) $(VECTOR_PTR_VIEW_TESTER_OBJ) $(CXX) -o $@ $(VECTOR_PTR_VIEW_TESTER_OBJ) $(LIBS) @@ -202,7 +207,7 @@ clean: $(DATAFRAME_PERFORMANCE_OBJ) $(DATAFRAME_TESTER_OBJ_2) \ $(DATAFRAME_TESTER_OBJ_3) $(HELLO_WORLD_OBJ) \ $(DATAFRAME_PERFORMANCE_2_OBJ) $(DATAFRAME_THREAD_SAFTY_OBJ) \ - $(DATAFRAME_TESTER_SCHEMA_OBJ) + $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) clobber: rm -f $(LIB_OBJS) $(TARGETS) $(DATAFRAME_TESTER_OBJ) $(VECTORS_TESTER_OBJ) \ @@ -210,7 +215,7 @@ clobber: $(GEN_RAND_TESTER_OBJ) $(DATAFRAME_PERFORMACE_OBJ) \ $(DATAFRAME_TESTER_OBJ_2) $(DATAFRAME_THREAD_SAFTY_OBJ) \ $(DATAFRAME_TESTER_OBJ_3) $(HELLO_WORLD_OBJ) \ - $(DATAFRAME_TESTER_SCHEMA_OBJ) + $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) install_lib: cp -pf $(TARGET_LIB) $(PROJECT_LIB_DIR)/. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fe85c0820..04f94ddd5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -55,6 +55,10 @@ if(MSVC) set_tests_properties(vectors_tester PROPERTIES DISABLED TRUE) endif() +add_executable(allocator_tester allocator_tester.cc) +target_link_libraries(allocator_tester PRIVATE DataFrame) +add_test(NAME allocator_tester COMMAND allocator_tester) + add_executable(vector_ptr_view_tester vector_ptr_view_tester.cc) target_link_libraries(vector_ptr_view_tester PRIVATE DataFrame) add_test(NAME vector_ptr_view_tester COMMAND vector_ptr_view_tester) diff --git a/test/allocator_tester.cc b/test/allocator_tester.cc new file mode 100644 index 000000000..f29d6ff16 --- /dev/null +++ b/test/allocator_tester.cc @@ -0,0 +1,133 @@ +/* +Copyright (c) 2019-2026, Hossein Moein +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +* Neither the name of Hossein Moein and/or the DataFrame nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#include +#include + +using namespace hmdf; + +struct MyData { + + MyData() { std::cout << "Printing from constructor" << std::endl; } + ~MyData() { std::cout << "Printing from destructor" << std::endl; } + + int i { 101 }; +}; + +const std::size_t NUM = 5; + +// ----------------------------------------------------------------------------- + +int main(int, char *[]) { + + { + std::vector> vec; + + vec.reserve(NUM - 1); + for (std::size_t i = 0; i < NUM; ++i) + vec.push_back(double(i)); + for (auto citer : vec) + std::cout << citer << ", "; + std::cout << std::endl; + } + { + std::vector> vec; + + vec.reserve(NUM - 1); + for (std::size_t i = 0; i < NUM; ++i) + vec.push_back(int(i)); + for (auto citer : vec) + std::cout << citer << ", "; + std::cout << std::endl; + } + { + std::vector> vec; + + vec.reserve(NUM - 1); + for (std::size_t i = 0; i < NUM; ++i) + vec.push_back(int(i + 1024)); + for (auto citer : vec) + std::cout << citer << ", "; + std::cout << std::endl; + } + { + std::vector> vec; + + vec.reserve(NUM - 1); + for (std::size_t i = 101; i < 101 + NUM; ++i) + vec.push_back(char(i)); + for (auto citer : vec) + std::cout << citer << ", "; + std::cout << std::endl; + } + { + std::vector> vec; + + vec.reserve(NUM); + for (std::size_t i = 0; i < NUM; ++i) + vec.push_back(static_cast(i)); + for (auto citer : vec) + std::cout << citer << ", "; + std::cout << std::endl; + } + { + std::vector> vec(NUM); + + vec[1].i = 1001; + vec[3].i = 3001; + for (auto &citer : vec) + std::cout << citer.i << ", "; + std::cout << std::endl; + } + + // This must fail to compile + // + /* + { + std::vector> vec; + + vec.reserve(NUM); + for (std::size_t i = 0; i < NUM; ++i) + vec.push_back(static_cast(i)); + for (auto citer : vec) + std::cout << citer << ", "; + std::cout << std::endl; + } + */ + + return (0); +} + +// ----------------------------------------------------------------------------- + +// Local Variables: +// mode:C++ +// tab-width:4 +// c-basic-offset:4 +// End: From 67845e33cd19ac66d82168025177fe0cd3582a7c Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sat, 10 Dec 2022 11:16:12 -0500 Subject: [PATCH 02/25] Changed default alignment value for AlignedAllocator --- include/DataFrame/Utils/AlignedAllocator.h | 46 ++++++++++++++-------- test/allocator_tester.cc | 42 ++++++++++++++++++-- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/include/DataFrame/Utils/AlignedAllocator.h b/include/DataFrame/Utils/AlignedAllocator.h index 891580dab..5545fe3d4 100644 --- a/include/DataFrame/Utils/AlignedAllocator.h +++ b/include/DataFrame/Utils/AlignedAllocator.h @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once #include +#include #include // ---------------------------------------------------------------------------- @@ -37,22 +38,31 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -// Returns aligned pointers when allocations are requested. Default alignment -// is 64B = 512b, sufficient for AVX-512 and most cache line sizes. -// -template -class AlignedAllocator { +template +struct AlignedValue { + + static constexpr std::align_val_t align_value { AS }; +}; + +template +struct AlignedValue { + + static constexpr std::align_val_t align_value { alignof(T) }; +}; + +// ---------------------------------------------------------------------------- -private: +// By default the alignment is system defined alignment for the type +// +template +class AlignedAllocator : public AlignedValue { - static_assert(AS >= alignof(T), + static_assert(AS == 0 || AS >= alignof(T), "ERROR: The requested alignment must be bigger or equal " "to Type alignment"); public: - static constexpr std::align_val_t align_value { AS }; - // std::allocator_traits stuff // using value_type = T; @@ -76,9 +86,10 @@ class AlignedAllocator { template struct rebind { using other = AlignedAllocator; }; - [[nodiscard]] inline pointer address(reference r) const { return (&r); } - [[nodiscard]] inline const_pointer - address(const_reference cr) const { return (&cr); } + [[nodiscard]] inline constexpr pointer + address(reference r) const { return (std::addressof(r)); } + [[nodiscard]] inline constexpr const_pointer + address(const_reference cr) const { return (std::addressof(cr)); } [[nodiscard]] constexpr size_type max_size() const { @@ -109,11 +120,11 @@ class AlignedAllocator { inline void construct(pointer p, const_reference val) const { - new (static_cast(p)) T(val); + new (static_cast(p)) value_type(val); } inline void construct(pointer p) const { - new (static_cast(p)) T(); + new (static_cast(p)) value_type(); } template @@ -122,7 +133,7 @@ class AlignedAllocator { new (static_cast(p)) U(std::forward(args) ...); } - inline void destroy(pointer p) const { p->~T(); } + inline void destroy(pointer p) const { p->~value_type(); } template inline void destroy(U *p) const { p->~U(); } @@ -135,7 +146,8 @@ class AlignedAllocator { const auto bytes = n_items * sizeof(value_type); - return(reinterpret_cast(::operator new[](bytes, align_value))); + return(reinterpret_cast( + ::operator new[](bytes, AlignedValue::align_value))); } // This is the same for all allocators that ignore hints. @@ -154,7 +166,7 @@ class AlignedAllocator { // The size argument can be omitted but if present must also be equal // to the one used in new // - ::operator delete[](ptr, align_value); + ::operator delete[](ptr, AlignedValue::align_value); } }; diff --git a/test/allocator_tester.cc b/test/allocator_tester.cc index f29d6ff16..5982afd04 100644 --- a/test/allocator_tester.cc +++ b/test/allocator_tester.cc @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include #include #include @@ -47,7 +48,18 @@ const std::size_t NUM = 5; int main(int, char *[]) { { - std::vector> vec; + AlignedAllocator a1; + AlignedAllocator a2; + AlignedAllocator a3; + AlignedAllocator a4; + + std::cout << "ai1 value: " << std::size_t(a1.align_value) << std::endl; + std::cout << "ai2 value: " << std::size_t(a2.align_value) << std::endl; + std::cout << "ai3 value: " << std::size_t(a3.align_value) << std::endl; + std::cout << "ai4 value: " << std::size_t(a4.align_value) << std::endl; + } + { + std::vector> vec; vec.reserve(NUM - 1); for (std::size_t i = 0; i < NUM; ++i) @@ -56,6 +68,16 @@ int main(int, char *[]) { std::cout << citer << ", "; std::cout << std::endl; } + { + std::vector> vec; + + vec.reserve(NUM - 1); + for (std::size_t i = 0; i < NUM; ++i) + vec.push_back(int(i)); + for (auto citer : vec) + std::cout << citer << ", "; + std::cout << std::endl; + } { std::vector> vec; @@ -77,7 +99,7 @@ int main(int, char *[]) { std::cout << std::endl; } { - std::vector> vec; + std::vector> vec; vec.reserve(NUM - 1); for (std::size_t i = 101; i < 101 + NUM; ++i) @@ -87,7 +109,7 @@ int main(int, char *[]) { std::cout << std::endl; } { - std::vector> vec; + std::vector> vec; vec.reserve(NUM); for (std::size_t i = 0; i < NUM; ++i) @@ -97,7 +119,7 @@ int main(int, char *[]) { std::cout << std::endl; } { - std::vector> vec(NUM); + std::vector> vec(NUM); vec[1].i = 1001; vec[3].i = 3001; @@ -105,6 +127,18 @@ int main(int, char *[]) { std::cout << citer.i << ", "; std::cout << std::endl; } + { + std::vector> vec1; + std::vector> vec2; + + vec1.reserve(NUM); + for (std::size_t i = 0; i < NUM; ++i) { + vec1.push_back(int(i)); + vec2.push_back(int(i)); + } + for (std::size_t i = 0; i < NUM; ++i) + assert(vec1[i] == vec2[i]); + } // This must fail to compile // From 1304d86d6df315c0d2b3ecd9d9f4cdcfa5264225 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sat, 10 Dec 2022 11:20:11 -0500 Subject: [PATCH 03/25] minor change --- include/DataFrame/Utils/AlignedAllocator.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/DataFrame/Utils/AlignedAllocator.h b/include/DataFrame/Utils/AlignedAllocator.h index 5545fe3d4..8c16e76d2 100644 --- a/include/DataFrame/Utils/AlignedAllocator.h +++ b/include/DataFrame/Utils/AlignedAllocator.h @@ -147,7 +147,8 @@ class AlignedAllocator : public AlignedValue { const auto bytes = n_items * sizeof(value_type); return(reinterpret_cast( - ::operator new[](bytes, AlignedValue::align_value))); + ::operator new[](bytes, + AlignedAllocator::align_value))); } // This is the same for all allocators that ignore hints. @@ -166,7 +167,7 @@ class AlignedAllocator : public AlignedValue { // The size argument can be omitted but if present must also be equal // to the one used in new // - ::operator delete[](ptr, AlignedValue::align_value); + ::operator delete[](ptr, AlignedAllocator::align_value); } }; From 269aa5fa31d276f35000a45705f0aef28b1f8099 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 11 Dec 2022 13:03:48 -0500 Subject: [PATCH 04/25] Toward aligned memory 1 -- not building yet --- include/DataFrame/DataFrame.h | 47 ++-- include/DataFrame/DataFrameTypes.h | 14 +- include/DataFrame/Internals/DataFrame.tcc | 211 +++++++++--------- .../Internals/DataFrame_private_decl.h | 26 +-- include/DataFrame/Utils/AlignedAllocator.h | 5 +- 5 files changed, 155 insertions(+), 148 deletions(-) diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index 2efd1ac45..ab180ce75 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ namespace hmdf // A DataFrame may contain one index and any number of columns of any built-in // or user-defined types // -template +template class DataFrame : public ThreadGranularity { static_assert(std::is_base_of::value || @@ -87,6 +88,18 @@ class DataFrame : public ThreadGranularity { using IndexVecType = typename type_declare::type; using ColNameType = String64; + template + using DataFrameView = DataFrame; + + template + using DataFrameConstView = DataFrame; + + template + using DataFramePtrView = DataFrame; + + template + using DataFrameConstPtrView = DataFrame; + template using ColumnVecType = typename type_declare::type; @@ -280,12 +293,12 @@ class DataFrame : public ThreadGranularity { size_type interval, bool start_from_beginning, const T &null_value = hmdf::get_nan(), - std::function::size_type ( - const typename DataFrame::IndexType &, - const typename DataFrame::IndexType &)> diff_func = - [](const typename DataFrame::IndexType &t_1, - const typename DataFrame::IndexType &t) -> - typename DataFrame::size_type { + std::function::IndexType &, + const typename DataFrame::IndexType &)> diff_func = + [](const typename DataFrame::IndexType &t_1, + const typename DataFrame::IndexType &t) -> + typename DataFrame::size_type { return (static_cast(t - t_1)); }); @@ -1188,11 +1201,11 @@ class DataFrame : public ThreadGranularity { // Name of the column // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame value_counts(const char *col_name) const; template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame value_counts(size_type index) const; // It bucketizes the data and index into intervals, based on index values @@ -1287,7 +1300,7 @@ class DataFrame : public ThreadGranularity { // (See join_policy definition) // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame join_by_index(const RHS_T &rhs, join_policy jp) const; // It joins the data between self (lhs) and rhs and returns the joined data @@ -1320,7 +1333,7 @@ class DataFrame : public ThreadGranularity { // (See join_policy definition) // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame join_by_column(const RHS_T &rhs, const char *name, join_policy jp) const; // It concatenates rhs to the end of self and returns the result as @@ -1344,7 +1357,7 @@ class DataFrame : public ThreadGranularity { // concatenated // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame concat(const RHS_T &rhs, concat_policy cp = concat_policy::all_columns) const; @@ -1424,7 +1437,7 @@ class DataFrame : public ThreadGranularity { // and returns a new DataFrame with columns shifted. // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame shift(size_type periods, shift_policy sp) const; // This copies the named column into another vector and shifts it up or down @@ -1467,7 +1480,7 @@ class DataFrame : public ThreadGranularity { // and returns a new DataFrame with columns rotated. // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame rotate(size_type periods, shift_policy sp) const; public: // Read/access and slicing interfaces @@ -2386,7 +2399,7 @@ class DataFrame : public ThreadGranularity { // the result as a column. // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame get_reindexed(const char *col_to_be_index, const char *old_index_name = nullptr) const; @@ -2439,7 +2452,7 @@ class DataFrame : public ThreadGranularity { // the list only once. // template - [[nodiscard]] StdDataFrame + [[nodiscard]] DataFrame describe() const; // This method combines the content of column col_name between self and @@ -3751,7 +3764,7 @@ class DataFrame : public ThreadGranularity { private: - template + template friend class DataFrame; using ColNameDict = diff --git a/include/DataFrame/DataFrameTypes.h b/include/DataFrame/DataFrameTypes.h index 92a1edac6..69c43cc0a 100644 --- a/include/DataFrame/DataFrameTypes.h +++ b/include/DataFrame/DataFrameTypes.h @@ -486,23 +486,17 @@ template struct is_complex> { // H stands for a heterogeneous vector // -template +template class DataFrame; template -using StdDataFrame = DataFrame; +using StdDataFrame = DataFrame; template -using DataFrameView = DataFrame; +using StdDataFrame64 = DataFrame; template -using DataFrameConstView = DataFrame; - -template -using DataFramePtrView = DataFrame; - -template -using DataFrameConstPtrView = DataFrame; +using StdDataFrame512 = DataFrame; // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index f1d81e865..a35fe950f 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -42,17 +42,17 @@ namespace hmdf // Notice memeber variables are initialized twice, but that's cheap // -template -DataFrame::DataFrame(const DataFrame &that) { *this = that; } +template +DataFrame::DataFrame(const DataFrame &that) { *this = that; } -template -DataFrame::DataFrame(DataFrame &&that) { *this = std::move(that); } +template +DataFrame::DataFrame(DataFrame &&that) { *this = std::move(that); } // ---------------------------------------------------------------------------- -template -DataFrame & -DataFrame::operator= (const DataFrame &that) { +template +DataFrame & +DataFrame::operator= (const DataFrame &that) { if (this != &that) { indices_ = that.indices_; @@ -68,9 +68,9 @@ DataFrame::operator= (const DataFrame &that) { // ---------------------------------------------------------------------------- -template -DataFrame & -DataFrame::operator= (DataFrame &&that) { +template +DataFrame & +DataFrame::operator= (DataFrame &&that) { if (this != &that) { indices_ = std::exchange(that.indices_, IndexVecType { }); @@ -86,8 +86,8 @@ DataFrame::operator= (DataFrame &&that) { // ---------------------------------------------------------------------------- -template -DataFrame::~DataFrame() { +template +DataFrame::~DataFrame() { const SpinGuard guard(lock_); @@ -96,31 +96,31 @@ DataFrame::~DataFrame() { // ---------------------------------------------------------------------------- -template -bool DataFrame::empty() const noexcept { return (indices_.empty()); } +template +bool DataFrame::empty() const noexcept { return (indices_.empty()); } // ---------------------------------------------------------------------------- -template -bool DataFrame:: +template +bool DataFrame:: shapeless() const noexcept { return (empty() && column_list_.empty()); } // ---------------------------------------------------------------------------- -template -void DataFrame::set_lock (SpinLock *sl) { lock_ = sl; } +template +void DataFrame::set_lock (SpinLock *sl) { lock_ = sl; } // ---------------------------------------------------------------------------- -template -void DataFrame::remove_lock () { lock_ = nullptr; } +template +void DataFrame::remove_lock () { lock_ = nullptr; } // ---------------------------------------------------------------------------- -template +template template -void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { +void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { const size_type idx_s = df.indices_.size(); std::vector sorting_idxs(idx_s, 0); @@ -140,10 +140,10 @@ void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { // ---------------------------------------------------------------------------- -template +template template void -DataFrame::shuffle(const std::vector &col_names, +DataFrame::shuffle(const std::vector &col_names, bool also_shuffle_index) { if (also_shuffle_index) { @@ -175,9 +175,9 @@ DataFrame::shuffle(const std::vector &col_names, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing_value_(ColumnVecType &vec, const T &value, int limit, @@ -204,9 +204,9 @@ fill_missing_value_(ColumnVecType &vec, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num) { const size_type vec_size = vec.size(); @@ -240,11 +240,11 @@ fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num) { // ---------------------------------------------------------------------------- -template +template template::value || ! std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_midpoint_(ColumnVecType &, int, size_type) { throw NotFeasible("fill_missing_midpoint_(): ERROR: Mid-point filling is " @@ -253,11 +253,11 @@ fill_missing_midpoint_(ColumnVecType &, int, size_type) { // ---------------------------------------------------------------------------- -template +template template::value && std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type) { const size_type vec_size = vec.size(); @@ -288,9 +288,9 @@ fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing_bfill_(ColumnVecType &vec, int limit) { const long vec_size = static_cast(vec.size()); @@ -313,11 +313,11 @@ fill_missing_bfill_(ColumnVecType &vec, int limit) { // ---------------------------------------------------------------------------- -template +template template::value || ! std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_linter_(ColumnVecType &, const IndexVecType &, int) { throw NotFeasible("fill_missing_linter_(): ERROR: Interpolation is " @@ -326,11 +326,11 @@ fill_missing_linter_(ColumnVecType &, const IndexVecType &, int) { // ---------------------------------------------------------------------------- -template +template template::value && std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_linter_(ColumnVecType &vec, const IndexVecType &index, int limit) { @@ -391,9 +391,9 @@ fill_missing_linter_(ColumnVecType &vec, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing(const std::vector &col_names, fill_policy fp, const std::vector &values, @@ -489,9 +489,9 @@ fill_missing(const std::vector &col_names, // ---------------------------------------------------------------------------- -template +template template -void DataFrame::fill_missing (const DF &rhs) { +void DataFrame::fill_missing (const DF &rhs) { const auto &self_idx = get_index(); const auto &rhs_idx = rhs.get_index(); @@ -509,9 +509,9 @@ void DataFrame::fill_missing (const DF &rhs) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: drop_missing_rows_(T &vec, const DropRowMap missing_row_map, drop_policy policy, @@ -546,9 +546,9 @@ drop_missing_rows_(T &vec, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: drop_missing(drop_policy policy, size_type threshold) { DropRowMap missing_row_map; @@ -577,9 +577,9 @@ drop_missing(drop_policy policy, size_type threshold) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type DataFrame:: +typename DataFrame::size_type DataFrame:: replace(const char *col_name, const std::vector &old_values, const std::vector &new_values, @@ -596,8 +596,8 @@ replace(const char *col_name, // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type DataFrame:: +template +typename DataFrame::size_type DataFrame:: replace_index(const std::vector &old_values, const std::vector &new_values, int limit) { @@ -612,9 +612,9 @@ replace_index(const std::vector &old_values, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: replace(const char *col_name, F &functor) { ColumnVecType &vec = get_column(col_name); @@ -628,9 +628,9 @@ replace(const char *col_name, F &functor) { // ---------------------------------------------------------------------------- -template +template template -std::future::size_type> DataFrame:: +std::future::size_type> DataFrame:: replace_async(const char *col_name, const std::vector &old_values, const std::vector &new_values, @@ -647,9 +647,9 @@ replace_async(const char *col_name, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: replace_async(const char *col_name, F &functor) { return (std::async(std::launch::async, @@ -661,9 +661,9 @@ replace_async(const char *col_name, F &functor) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::make_consistent () { +void DataFrame::make_consistent () { static_assert(std::is_base_of::value, "Only a StdDataFrame can call make_consistent()"); @@ -678,9 +678,9 @@ void DataFrame::make_consistent () { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::shrink_to_fit () { +void DataFrame::shrink_to_fit () { indices_.shrink_to_fit(); @@ -695,9 +695,9 @@ void DataFrame::shrink_to_fit () { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::sort(const char *name, sort_spec dir) { +void DataFrame::sort(const char *name, sort_spec dir) { make_consistent(); @@ -736,9 +736,9 @@ void DataFrame::sort(const char *name, sort_spec dir) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { make_consistent(); @@ -782,9 +782,9 @@ sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3) { @@ -849,9 +849,9 @@ sort(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -935,10 +935,10 @@ sort(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -1041,10 +1041,10 @@ sort(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame::sort_async(const char *name, sort_spec dir) { +DataFrame::sort_async(const char *name, sort_spec dir) { return (std::async(std::launch::async, [name, dir, this] () -> void { @@ -1054,10 +1054,10 @@ DataFrame::sort_async(const char *name, sort_spec dir) { // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { @@ -1070,10 +1070,10 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3) { @@ -1089,10 +1089,10 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -1110,11 +1110,11 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -1134,9 +1134,9 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { const ColumnVecType *gb_vec { nullptr }; @@ -1179,9 +1179,9 @@ groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: groupby2(const char *col_name1, const char *col_name2, I_V &&idx_visitor, @@ -1246,9 +1246,9 @@ groupby2(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: groupby3(const char *col_name1, const char *col_name2, const char *col_name3, @@ -1331,9 +1331,9 @@ groupby3(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -std::future> DataFrame:: +std::future> DataFrame:: groupby1_async(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { return (std::async(std::launch::async, @@ -1346,9 +1346,9 @@ groupby1_async(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { // ---------------------------------------------------------------------------- -template +template template -std::future> DataFrame:: +std::future> DataFrame:: groupby2_async(const char *col_name1, const char *col_name2, I_V &&idx_visitor, @@ -1365,9 +1365,9 @@ groupby2_async(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -std::future> DataFrame:: +std::future> DataFrame:: groupby3_async(const char *col_name1, const char *col_name2, const char *col_name3, @@ -1386,10 +1386,10 @@ groupby3_async(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -StdDataFrame -DataFrame::value_counts (const char *col_name) const { +DataFrame +DataFrame::value_counts (const char *col_name) const { const ColumnVecType &vec = get_column(col_name); auto hash_func = @@ -1437,7 +1437,7 @@ DataFrame::value_counts (const char *col_name) const { counts.emplace_back(nan_count); } - StdDataFrame result_df; + DataFrame result_df; result_df.load_index(std::move(res_indices)); result_df.load_column("counts", std::move(counts)); @@ -1447,18 +1447,19 @@ DataFrame::value_counts (const char *col_name) const { // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame::value_counts(size_type index) const { +DataFrame +DataFrame::value_counts(size_type index) const { return (value_counts(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: bucketize(bucket_type bt, const V &value, I_V &&idx_visitor, @@ -1484,10 +1485,10 @@ bucketize(bucket_type bt, // ---------------------------------------------------------------------------- -template +template template -std::future> -DataFrame:: +std::future> +DataFrame:: bucketize_async(bucket_type bt, const V &value, I_V &&idx_visitor, @@ -1504,9 +1505,9 @@ bucketize_async(bucket_type bt, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: transpose(IndexVecType &&indices, const V &new_col_names) const { const size_type num_cols = column_list_.size(); diff --git a/include/DataFrame/Internals/DataFrame_private_decl.h b/include/DataFrame/Internals/DataFrame_private_decl.h index e8cbc1240..ccfdbaf52 100644 --- a/include/DataFrame/Internals/DataFrame_private_decl.h +++ b/include/DataFrame/Internals/DataFrame_private_decl.h @@ -55,7 +55,7 @@ void read_csv2_(std::istream &file, bool columns_only); template static void -sort_common_(DataFrame &df, CF &&comp_func); +sort_common_(DataFrame &df, CF &&comp_func); template static void @@ -126,17 +126,17 @@ static void join_helper_common_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx, - StdDataFrame &result, + DataFrame &result, const char *skip_col_name = nullptr); template -static StdDataFrame +static DataFrame index_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx); template -static StdDataFrame +static DataFrame column_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -149,14 +149,14 @@ get_inner_index_idx_vector_( const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame index_inner_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -170,14 +170,14 @@ get_left_index_idx_vector_( const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame index_left_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -191,14 +191,14 @@ get_right_index_idx_vector_( const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame index_right_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -206,7 +206,7 @@ column_right_join_(const LHS_T &lhs, const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame remove_dups_common_(const DataFrame &s_df, remove_dup_spec rds, const MAP &row_table, @@ -223,14 +223,14 @@ get_left_right_index_idx_vector_( const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static StdDataFrame +static DataFrame column_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, diff --git a/include/DataFrame/Utils/AlignedAllocator.h b/include/DataFrame/Utils/AlignedAllocator.h index 8c16e76d2..2c03b5ab4 100644 --- a/include/DataFrame/Utils/AlignedAllocator.h +++ b/include/DataFrame/Utils/AlignedAllocator.h @@ -147,8 +147,7 @@ class AlignedAllocator : public AlignedValue { const auto bytes = n_items * sizeof(value_type); return(reinterpret_cast( - ::operator new[](bytes, - AlignedAllocator::align_value))); + ::operator new[](bytes, AlignedAllocator::align_value))); } // This is the same for all allocators that ignore hints. @@ -167,7 +166,7 @@ class AlignedAllocator : public AlignedValue { // The size argument can be omitted but if present must also be equal // to the one used in new // - ::operator delete[](ptr, AlignedAllocator::align_value); + ::operator delete[](ptr, AlignedAllocator::align_value); } }; From 5f9fc9b2e5dd8b257c02f68ecf7c54c3acbbd3e3 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 11 Dec 2022 16:45:18 -0500 Subject: [PATCH 05/25] Toward aligned memory 2 -- not building yet --- include/DataFrame/DataFrame.h | 4 +- include/DataFrame/Internals/DataFrame_get.tcc | 312 +++++++++--------- .../DataFrame/Internals/DataFrame_join.tcc | 196 +++++------ .../Internals/DataFrame_private_decl.h | 10 +- 4 files changed, 271 insertions(+), 251 deletions(-) diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index ab180ce75..40d43b593 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -1300,7 +1300,7 @@ class DataFrame : public ThreadGranularity { // (See join_policy definition) // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame join_by_index(const RHS_T &rhs, join_policy jp) const; // It joins the data between self (lhs) and rhs and returns the joined data @@ -1357,7 +1357,7 @@ class DataFrame : public ThreadGranularity { // concatenated // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame concat(const RHS_T &rhs, concat_policy cp = concat_policy::all_columns) const; diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index 9c7eb1442..7cec7c3f2 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -40,19 +40,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template -std::pair::size_type, - typename DataFrame::size_type> -DataFrame::shape() const { +template +std::pair::size_type, + typename DataFrame::size_type> +DataFrame::shape() const { return (std::make_pair(indices_.size(), column_list_.size())); } // ---------------------------------------------------------------------------- -template +template template -MemUsage DataFrame::get_memory_usage(const char *col_name) const { +MemUsage DataFrame::get_memory_usage(const char *col_name) const { MemUsage result; @@ -68,9 +68,9 @@ MemUsage DataFrame::get_memory_usage(const char *col_name) const { // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type -DataFrame::col_name_to_idx (const char *col_name) const { +template +typename DataFrame::size_type +DataFrame::col_name_to_idx (const char *col_name) const { for (const auto &citer : column_list_) if (citer.first == col_name) @@ -86,9 +86,9 @@ DataFrame::col_name_to_idx (const char *col_name) const { // ---------------------------------------------------------------------------- -template +template const char * -DataFrame::col_idx_to_name (size_type col_idx) const { +DataFrame::col_idx_to_name (size_type col_idx) const { for (const auto &citer : column_list_) if (citer.second == col_idx) @@ -109,10 +109,10 @@ DataFrame::col_idx_to_name (size_type col_idx) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::template ColumnVecType & -DataFrame::get_column (const char *name) { +typename DataFrame::template ColumnVecType & +DataFrame::get_column (const char *name) { auto iter = column_tb_.find (name); @@ -134,28 +134,28 @@ DataFrame::get_column (const char *name) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::template ColumnVecType & -DataFrame::get_column () { +typename DataFrame::template ColumnVecType & +DataFrame::get_column () { return (get_column(T::name)); } // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::template ColumnVecType & -DataFrame::get_column(size_type index) { +typename DataFrame::template ColumnVecType & +DataFrame::get_column(size_type index) { return (get_column(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template -bool DataFrame::has_column (const char *name) const { +template +bool DataFrame::has_column (const char *name) const { auto iter = column_tb_.find (name); @@ -164,26 +164,26 @@ bool DataFrame::has_column (const char *name) const { // ---------------------------------------------------------------------------- -template -bool DataFrame:: +template +bool DataFrame:: has_column(size_type index) const { return (index < column_list_.size()); } // ---------------------------------------------------------------------------- -template +template template -const typename DataFrame::template ColumnVecType & -DataFrame::get_column (const char *name) const { +const typename DataFrame::template ColumnVecType & +DataFrame::get_column (const char *name) const { return (const_cast(this)->get_column(name)); } // ---------------------------------------------------------------------------- -template +template template -const typename DataFrame::template ColumnVecType & -DataFrame::get_column () const { +const typename DataFrame::template ColumnVecType & +DataFrame::get_column () const { return (const_cast(this)->get_column( T::name)); @@ -191,31 +191,31 @@ DataFrame::get_column () const { // ---------------------------------------------------------------------------- -template +template template -const typename DataFrame::template ColumnVecType & -DataFrame::get_column(size_type index) const { +const typename DataFrame::template ColumnVecType & +DataFrame::get_column(size_type index) const { return (get_column(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template -const typename DataFrame::IndexVecType & -DataFrame::get_index() const { return (indices_); } +template +const typename DataFrame::IndexVecType & +DataFrame::get_index() const { return (indices_); } // ---------------------------------------------------------------------------- -template -typename DataFrame::IndexVecType & -DataFrame::get_index() { return (indices_); } +template +typename DataFrame::IndexVecType & +DataFrame::get_index() { return (indices_); } // ---------------------------------------------------------------------------- -template +template template -HeteroVector DataFrame:: +HeteroVector DataFrame:: get_row(size_type row_num, const std::vector &col_names) const { if (row_num >= indices_.size()) { @@ -260,9 +260,9 @@ get_row(size_type row_num, const std::vector &col_names) const { // ---------------------------------------------------------------------------- -template +template template -HeteroVector DataFrame:: +HeteroVector DataFrame:: get_row(size_type row_num) const { if (row_num >= indices_.size()) { @@ -295,9 +295,9 @@ get_row(size_type row_num) const { // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: get_col_unique_values(const char *name) const { const ColumnVecType &vec = get_column(name); @@ -337,10 +337,10 @@ get_col_unique_values(const char *name) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::get_data_by_idx (Index2D range) const { +DataFrame +DataFrame::get_data_by_idx (Index2D range) const { const auto &lower = std::lower_bound (indices_.begin(), indices_.end(), range.begin); @@ -373,10 +373,10 @@ DataFrame::get_data_by_idx (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::get_data_by_idx(const std::vector &values) const { +DataFrame DataFrame:: +get_data_by_idx(const std::vector &values) const { const std::unordered_set val_table(values.begin(), values.end()); IndexVecType new_index; @@ -411,10 +411,10 @@ DataFrame::get_data_by_idx(const std::vector &values) const { // ---------------------------------------------------------------------------- -template +template template -DataFrameView -DataFrame::get_view_by_idx (Index2D range) { +typename DataFrame::template DataFrameView +DataFrame::get_view_by_idx (Index2D range) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_idx()"); @@ -457,10 +457,10 @@ DataFrame::get_view_by_idx (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstView -DataFrame::get_view_by_idx (Index2D range) const { +typename DataFrame::template DataFrameConstView +DataFrame::get_view_by_idx (Index2D range) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_idx()"); @@ -504,9 +504,9 @@ DataFrame::get_view_by_idx (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView DataFrame:: +typename DataFrame::template DataFramePtrView DataFrame:: get_view_by_idx(const std::vector &values) { static_assert(std::is_base_of::value, @@ -551,9 +551,10 @@ get_view_by_idx(const std::vector &values) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView DataFrame:: +typename DataFrame::template DataFrameConstPtrView +DataFrame:: get_view_by_idx(const std::vector &values) const { static_assert(std::is_base_of::value, @@ -598,10 +599,10 @@ get_view_by_idx(const std::vector &values) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::get_data_by_loc (Index2D range) const { +DataFrame +DataFrame::get_data_by_loc (Index2D range) const { if (range.begin < 0) range.begin = static_cast(indices_.size()) + range.begin; @@ -640,10 +641,10 @@ DataFrame::get_data_by_loc (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::get_data_by_loc (const std::vector &locations) const { +DataFrame DataFrame:: +get_data_by_loc (const std::vector &locations) const { const size_type idx_s = indices_.size(); DataFrame df; @@ -674,10 +675,10 @@ DataFrame::get_data_by_loc (const std::vector &locations) const { // ---------------------------------------------------------------------------- -template +template template -DataFrameView -DataFrame::get_view_by_loc (Index2D range) { +typename DataFrame::template DataFrameView +DataFrame::get_view_by_loc (Index2D range) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -721,10 +722,10 @@ DataFrame::get_view_by_loc (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstView -DataFrame::get_view_by_loc (Index2D range) const { +typename DataFrame::template DataFrameConstView +DataFrame::get_view_by_loc (Index2D range) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -768,10 +769,10 @@ DataFrame::get_view_by_loc (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView -DataFrame::get_view_by_loc (const std::vector &locations) { +typename DataFrame::template DataFramePtrView +DataFrame::get_view_by_loc (const std::vector &locations) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -808,10 +809,11 @@ DataFrame::get_view_by_loc (const std::vector &locations) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView -DataFrame::get_view_by_loc (const std::vector &locations) const { +typename DataFrame::template DataFrameConstPtrView +DataFrame:: +get_view_by_loc (const std::vector &locations) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -848,9 +850,9 @@ DataFrame::get_view_by_loc (const std::vector &locations) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (const char *name, F &sel_functor) const { const ColumnVecType &vec = get_column(name); @@ -887,9 +889,9 @@ get_data_by_sel (const char *name, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView DataFrame:: +typename DataFrame::template DataFramePtrView DataFrame:: get_view_by_sel (const char *name, F &sel_functor) { static_assert(std::is_base_of::value, @@ -931,9 +933,10 @@ get_view_by_sel (const char *name, F &sel_functor) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView DataFrame:: +typename DataFrame::template DataFrameConstPtrView +DataFrame:: get_view_by_sel (const char *name, F &sel_functor) const { static_assert(std::is_base_of::value, @@ -975,9 +978,9 @@ get_view_by_sel (const char *name, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { const size_type idx_s = indices_.size(); @@ -1022,9 +1025,9 @@ get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView DataFrame:: +typename DataFrame::template DataFramePtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { static_assert(std::is_base_of::value, @@ -1074,9 +1077,10 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView DataFrame:: +typename DataFrame::template DataFrameConstPtrView +DataFrame:: get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { static_assert(std::is_base_of::value, @@ -1126,9 +1130,9 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (const char *name1, const char *name2, const char *name3, @@ -1179,9 +1183,9 @@ get_data_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (F &sel_functor) const { const size_type idx_s = indices_.size(); @@ -1244,9 +1248,9 @@ get_data_by_sel (F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { const size_type idx_s = indices_.size(); @@ -1307,9 +1311,9 @@ get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView DataFrame:: +typename DataFrame::template DataFramePtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, const char *name3, @@ -1365,9 +1369,10 @@ get_view_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView DataFrame:: +typename DataFrame::template DataFrameConstPtrView +DataFrame:: get_view_by_sel (const char *name1, const char *name2, const char *name3, @@ -1423,10 +1428,10 @@ get_view_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel(const char *name1, const char *name2, const char *name3, @@ -1482,10 +1487,10 @@ get_data_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView DataFrame:: +typename DataFrame::template DataFramePtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1546,10 +1551,11 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView DataFrame:: +typename DataFrame::template DataFrameConstPtrView +DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1610,10 +1616,10 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel(const char *name1, const char *name2, const char *name3, @@ -1674,10 +1680,10 @@ get_data_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView DataFrame:: +typename DataFrame::template DataFramePtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1743,10 +1749,11 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView DataFrame:: +typename DataFrame::template DataFrameConstPtrView +DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1812,9 +1819,9 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_rand(random_policy spec, double n, size_type seed) const { bool use_seed = false; @@ -1886,9 +1893,9 @@ get_data_by_rand(random_policy spec, double n, size_type seed) const { // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView DataFrame:: +typename DataFrame::template DataFramePtrView DataFrame:: get_view_by_rand (random_policy spec, double n, size_type seed) { bool use_seed = false; @@ -1960,9 +1967,10 @@ get_view_by_rand (random_policy spec, double n, size_type seed) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView DataFrame:: +typename DataFrame::template DataFrameConstPtrView +DataFrame:: get_view_by_rand (random_policy spec, double n, size_type seed) const { bool use_seed = false; @@ -2035,9 +2043,9 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data(const std::vector &col_names) const { DataFrame df; @@ -2067,9 +2075,9 @@ get_data(const std::vector &col_names) const { // ---------------------------------------------------------------------------- -template +template template -DataFrameView DataFrame:: +typename DataFrame::template DataFrameView DataFrame:: get_view(const std::vector &col_names) { static_assert(std::is_base_of::value, @@ -2109,9 +2117,10 @@ get_view(const std::vector &col_names) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstView DataFrame:: +typename DataFrame::template DataFrameConstView +DataFrame:: get_view(const std::vector &col_names) const { static_assert(std::is_base_of::value, @@ -2152,14 +2161,14 @@ get_view(const std::vector &col_names) const { // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: get_reindexed(const char *col_to_be_index, const char *old_index_name) const { - StdDataFrame result; - const auto &new_idx = get_column(col_to_be_index); - const size_type new_idx_s = + DataFrame result; + const auto &new_idx = get_column(col_to_be_index); + const size_type new_idx_s = result.load_index(new_idx.begin(), new_idx.end()); if (old_index_name) { @@ -2174,7 +2183,7 @@ get_reindexed(const char *col_to_be_index, const char *old_index_name) const { for (const auto &citer : column_list_) { if (citer.first == col_to_be_index) continue; - load_functor_, Ts ...> functor ( + load_functor_, Ts ...> functor ( citer.first.c_str(), 0, new_idx_s, @@ -2190,9 +2199,9 @@ get_reindexed(const char *col_to_be_index, const char *old_index_name) const { // ---------------------------------------------------------------------------- -template +template template -DataFrameView DataFrame:: +typename DataFrame::template DataFrameView DataFrame:: get_reindexed_view(const char *col_to_be_index, const char *old_index_name) { static_assert(std::is_base_of::value, @@ -2233,9 +2242,10 @@ get_reindexed_view(const char *col_to_be_index, const char *old_index_name) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstView DataFrame:: +typename DataFrame::template DataFrameConstView +DataFrame:: get_reindexed_view(const char *col_to_be_index, const char *old_index_name) const { @@ -2278,12 +2288,12 @@ get_reindexed_view(const char *col_to_be_index, // ---------------------------------------------------------------------------- -template +template template -std::vector::ColNameType, - typename DataFrame::size_type, +std::vector::ColNameType, + typename DataFrame::size_type, std::type_index>> -DataFrame::get_columns_info () const { +DataFrame::get_columns_info () const { std::vector> result; @@ -2302,12 +2312,12 @@ DataFrame::get_columns_info () const { // ---------------------------------------------------------------------------- -template +template template -StdDataFrame -DataFrame::describe() const { +DataFrame +DataFrame::describe() const { - StdDataFrame result; + DataFrame result; result.load_index(describe_index_col.begin(), describe_index_col.end()); @@ -2323,9 +2333,9 @@ DataFrame::describe() const { // ---------------------------------------------------------------------------- -template +template template -bool DataFrame:: +bool DataFrame:: pattern_match(const char *col_name, pattern_spec pattern, double epsilon) const { @@ -2355,9 +2365,9 @@ pattern_match(const char *col_name, // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: combine(const char *col_name, const DF &rhs, F &functor) const { const auto &lhs_col = get_column(col_name); @@ -2374,9 +2384,9 @@ combine(const char *col_name, const DF &rhs, F &functor) const { // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2399,9 +2409,9 @@ combine(const char *col_name, // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index a3396c375..312f36eca 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -36,16 +36,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: join_by_index (const RHS_T &rhs, join_policy mp) const { - static_assert(std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value, - "The rhs argument to join_by_index() can only be " - "StdDataFrame or DataFrame[Ptr]View"); + static_assert( + std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value, + "The rhs argument to join_by_index() can only be " + "StdDataFrame or DataFrame[Ptr]View"); const auto &lhs_idx = get_index(); const auto &rhs_idx = rhs.get_index(); @@ -92,16 +93,17 @@ join_by_index (const RHS_T &rhs, join_policy mp) const { // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { - static_assert(std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value, - "The rhs argument to join_by_column() can only be " - "StdDataFrame or DataFrame[Ptr]View"); + static_assert( + std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value, + "The rhs argument to join_by_column() can only be " + "StdDataFrame or DataFrame[Ptr]View"); const auto &lhs_vec = get_column(name); const auto &rhs_vec = rhs.template get_column(name); @@ -149,13 +151,13 @@ join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: join_helper_common_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx, - StdDataFrame &result, + DataFrame &result, const char *skip_col_name) { // Load the common and lhs columns @@ -205,15 +207,15 @@ join_helper_common_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: index_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx) { - StdDataFrame result; - std::vector result_index; + DataFrame result; + std::vector result_index; // Load the index result_index.reserve(joined_index_idx.size()); @@ -233,9 +235,9 @@ index_join_helper_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: column_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -244,13 +246,13 @@ column_join_helper_(const LHS_T &lhs, using left_idx_t = typename std::remove_reference::type::IndexType; using right_idx_t = typename std::remove_reference::type::IndexType; - const size_type jii_s = joined_index_idx.size(); - StdDataFrame result; + const size_type jii_s = joined_index_idx.size(); + DataFrame result; // Load the new result index result.load_index( - StdDataFrame::gen_sequence_index( - 0, static_cast(jii_s), 1)); + DataFrame::gen_sequence_index( + 0, static_cast(jii_s), 1)); // Load the lhs and rhs indices into two columns in the result // Also load the unified named column @@ -298,10 +300,10 @@ column_join_helper_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_inner_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_inner_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -331,9 +333,9 @@ DataFrame::get_inner_index_idx_vector_( // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: index_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -345,9 +347,9 @@ index_inner_join_(const LHS_T &lhs, const RHS_T &rhs, // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -361,10 +363,10 @@ column_inner_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_left_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_left_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -402,9 +404,9 @@ DataFrame::get_left_index_idx_vector_( } // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: index_left_join_(const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -416,9 +418,9 @@ index_left_join_(const LHS_T &lhs, const RHS_T &rhs, // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -432,10 +434,10 @@ column_left_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_right_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_right_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -477,9 +479,9 @@ DataFrame::get_right_index_idx_vector_( // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: index_right_join_(const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -491,9 +493,9 @@ index_right_join_(const LHS_T &lhs, const RHS_T &rhs, // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -507,10 +509,10 @@ column_right_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_left_right_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_left_right_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -559,9 +561,9 @@ DataFrame::get_left_right_index_idx_vector_( // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, @@ -575,9 +577,9 @@ index_left_right_join_( // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: column_left_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -591,9 +593,9 @@ column_left_right_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns) { const size_type orig_index_s = lhs.get_index().size(); @@ -635,38 +637,42 @@ concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns) { // ---------------------------------------------------------------------------- -template +template template void -DataFrame::self_concat(const RHS_T &rhs, bool add_new_columns) { - - static_assert((std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value) && - ! std::is_base_of, decltype(*this)>::value, - "The rhs argument to self_concat() can only be " - "StdDataFrame or DataFrame[Ptr]View. " - "Self must be StdDataFrame"); +DataFrame::self_concat(const RHS_T &rhs, bool add_new_columns) { + + static_assert( + (std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value) && + ! std::is_base_of, + decltype(*this)>::value, + "The rhs argument to self_concat() can only be " + "StdDataFrame or DataFrame[Ptr]View. " + "Self must be StdDataFrame"); concat_helper_(*this, rhs, add_new_columns); } // ---------------------------------------------------------------------------- -template +template template -StdDataFrame -DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { +DataFrame +DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { - static_assert((std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value) && - ! std::is_base_of, decltype(*this)>::value, - "The rhs argument to concat() can only be " - "StdDataFrame or DataFrame[Ptr]View. " - "Self must be StdDataFrame"); + static_assert( + (std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value || + std::is_base_of, RHS_T>::value) && + ! std::is_base_of, + decltype(*this)>::value, + "The rhs argument to concat() can only be " + "StdDataFrame or DataFrame[Ptr]View. " + "Self must be StdDataFrame"); - StdDataFrame result; + DataFrame result; if (cp == concat_policy::all_columns || cp == concat_policy::lhs_and_common_columns) { @@ -694,15 +700,17 @@ DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { // ---------------------------------------------------------------------------- -template +template template -DataFramePtrView -DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { +typename DataFrame::template DataFramePtrView +DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { - static_assert(! std::is_base_of, RHS_T>::value || - ! std::is_base_of, decltype(*this)>::value, - "Currently, arguments to concat_view() can only be " - "StdDataFrame."); + static_assert( + ! std::is_base_of, RHS_T>::value || + ! std::is_base_of, + decltype(*this)>::value, + "Currently, arguments to concat_view() can only be " + "StdDataFrame."); DataFramePtrView result; @@ -766,15 +774,17 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { // ---------------------------------------------------------------------------- -template +template template -DataFrameConstPtrView -DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { - - static_assert(! std::is_base_of, RHS_T>::value || - ! std::is_base_of, decltype(*this)>::value, - "Currently, arguments to concat_view() can only be " - "StdDataFrame."); +typename DataFrame::template DataFrameConstPtrView +DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { + + static_assert( + ! std::is_base_of, RHS_T>::value || + ! std::is_base_of, + decltype(*this)>::value, + "Currently, arguments to concat_view() can only be " + "StdDataFrame."); DataFrameConstPtrView result; diff --git a/include/DataFrame/Internals/DataFrame_private_decl.h b/include/DataFrame/Internals/DataFrame_private_decl.h index ccfdbaf52..fa5dda69b 100644 --- a/include/DataFrame/Internals/DataFrame_private_decl.h +++ b/include/DataFrame/Internals/DataFrame_private_decl.h @@ -130,7 +130,7 @@ join_helper_common_(const LHS_T &lhs, const char *skip_col_name = nullptr); template -static DataFrame +static DataFrame index_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx); @@ -149,7 +149,7 @@ get_inner_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame index_inner_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, @@ -170,7 +170,7 @@ get_left_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame index_left_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, @@ -191,7 +191,7 @@ get_right_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame index_right_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, @@ -223,7 +223,7 @@ get_left_right_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, From 28bddef4583c66eea8286823632de2eedcd15fd2 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Tue, 13 Dec 2022 08:59:05 -0500 Subject: [PATCH 06/25] Finished a lot of boilerplate crap -- it builds now --- include/DataFrame/DataFrame.h | 4 +- include/DataFrame/DataFrameTypes.h | 12 +- .../DataFrame/Internals/DataFrame_misc.tcc | 136 ++++++------ include/DataFrame/Internals/DataFrame_opt.tcc | 8 +- .../DataFrame/Internals/DataFrame_read.tcc | 36 ++-- include/DataFrame/Internals/DataFrame_set.tcc | 200 +++++++++--------- .../DataFrame/Internals/DataFrame_shift.tcc | 22 +- .../DataFrame/Internals/DataFrame_visit.tcc | 168 +++++++-------- .../DataFrame/Internals/DataFrame_write.tcc | 24 +-- include/DataFrame/Utils/AlignedAllocator.h | 11 +- test/dataframe_tester.cc | 3 +- test/dataframe_tester_2.cc | 24 ++- 12 files changed, 334 insertions(+), 314 deletions(-) diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index 40d43b593..620b2f513 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -81,7 +81,7 @@ class DataFrame : public ThreadGranularity { using DataVec = H; using DataVecVec = std::vector; - public: // Construction +public: // Construction using size_type = typename std::vector::size_type; using IndexType = I; @@ -298,7 +298,7 @@ class DataFrame : public ThreadGranularity { const typename DataFrame::IndexType &)> diff_func = [](const typename DataFrame::IndexType &t_1, const typename DataFrame::IndexType &t) -> - typename DataFrame::size_type { + typename std::size_t { return (static_cast(t - t_1)); }); diff --git a/include/DataFrame/DataFrameTypes.h b/include/DataFrame/DataFrameTypes.h index 69c43cc0a..518b10e98 100644 --- a/include/DataFrame/DataFrameTypes.h +++ b/include/DataFrame/DataFrameTypes.h @@ -484,7 +484,9 @@ template struct is_complex> { // ---------------------------------------------------------------------------- -// H stands for a heterogeneous vector +// I stands for Index type +// H stands for Heterogeneous vector +// A stands for memory Alignment // template class DataFrame; @@ -492,9 +494,17 @@ class DataFrame; template using StdDataFrame = DataFrame; +// Convenient typedefs to facilitate SIMD operations +// template using StdDataFrame64 = DataFrame; +template +using StdDataFrame128 = DataFrame; + +template +using StdDataFrame256 = DataFrame; + template using StdDataFrame512 = DataFrame; diff --git a/include/DataFrame/Internals/DataFrame_misc.tcc b/include/DataFrame/Internals/DataFrame_misc.tcc index 101a46629..8e90e3233 100644 --- a/include/DataFrame/Internals/DataFrame_misc.tcc +++ b/include/DataFrame/Internals/DataFrame_misc.tcc @@ -39,11 +39,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template template void -DataFrame::consistent_functor_::operator() (T &vec) const { +DataFrame::consistent_functor_::operator() (T &vec) const { using ValueType = typename std::remove_reference::type::value_type; @@ -53,11 +53,11 @@ DataFrame::consistent_functor_::operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::shrink_to_fit_functor_::operator() (T &vec) const { +DataFrame::shrink_to_fit_functor_::operator() (T &vec) const { using value_type = typename T::value_type; @@ -71,11 +71,11 @@ DataFrame::shrink_to_fit_functor_::operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::sort_functor_::operator() (T2 &vec) { +DataFrame::sort_functor_::operator() (T2 &vec) { sorted_idxs_copy = sorted_idxs; _sort_by_sorted_index_(vec, sorted_idxs_copy, idx_s); @@ -84,11 +84,11 @@ DataFrame::sort_functor_::operator() (T2 &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::load_functor_::operator() (const T &vec) { +DataFrame::load_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -103,11 +103,11 @@ DataFrame::load_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::load_all_functor_::operator() (const T &vec) { +DataFrame::load_all_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -119,11 +119,11 @@ DataFrame::load_all_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::remove_functor_::operator() (T &vec) { +DataFrame::remove_functor_::operator() (T &vec) { vec.erase(vec.begin() + begin, vec.begin() + end); return; @@ -131,11 +131,11 @@ DataFrame::remove_functor_::operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::view_setup_functor_:: +DataFrame::view_setup_functor_:: operator() (T &vec) { using VecType = typename std::remove_reference::type; @@ -151,11 +151,11 @@ operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::add_col_functor_::operator() (const T &) { +DataFrame::add_col_functor_::operator() (const T &) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -166,11 +166,11 @@ DataFrame::add_col_functor_::operator() (const T &) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::print_csv_functor_::operator() (const T &vec) { +DataFrame::print_csv_functor_::operator() (const T &vec) { if (vec.empty()) return; @@ -222,11 +222,11 @@ DataFrame::print_csv_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::print_json_functor_::operator() (const T &vec) { +DataFrame::print_json_functor_::operator() (const T &vec) { if (vec.empty()) return; @@ -285,10 +285,10 @@ DataFrame::print_json_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame:: +void DataFrame:: print_csv2_header_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; @@ -302,10 +302,10 @@ print_csv2_header_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame:: +void DataFrame:: print_csv2_data_functor_::operator() (const T &vec) { if (vec.size() > index) os << vec[index]; @@ -314,11 +314,11 @@ print_csv2_data_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: equal_functor_::operator() (const T &lhs_vec) { using VecType = typename std::remove_reference::type; @@ -342,11 +342,11 @@ equal_functor_::operator() (const T &lhs_vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: mod_by_idx_functor_::operator() (T &lhs_vec) const { using VecType = typename std::remove_reference::type; @@ -364,11 +364,11 @@ mod_by_idx_functor_::operator() (T &lhs_vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: index_join_functor_common_::operator()(const T &lhs_vec) { using VecType = typename std::remove_reference::type; @@ -403,10 +403,10 @@ index_join_functor_common_::operator()(const T &lhs_vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::index_join_functor_oneside_:: +void DataFrame::index_join_functor_oneside_:: operator()(const T &vec) { using VecType = typename std::remove_reference::type; @@ -428,10 +428,10 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::concat_functor_:: +void DataFrame::concat_functor_:: operator()(const T &vec) { using VecType = typename std::remove_reference::type; @@ -454,10 +454,10 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::vertical_shift_functor_:: +void DataFrame::vertical_shift_functor_:: operator() (T &vec) const { if (sp == shift_policy::up) @@ -468,10 +468,10 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::rotate_functor_:: +void DataFrame::rotate_functor_:: operator() (T &vec) const { if (sp == shift_policy::up) // Rotate left @@ -484,11 +484,11 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template class OPT, typename ... Ts> template void -DataFrame:: +DataFrame:: operator_functor_:: operator()(const T &lhs_vec) { @@ -536,11 +536,11 @@ operator()(const T &lhs_vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: map_missing_rows_functor_:: operator()(const T &vec) { @@ -559,11 +559,11 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: drop_missing_rows_functor_:: operator()(T &vec) { @@ -573,11 +573,11 @@ operator()(T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: get_row_functor_:: operator()(const T &vec) { @@ -591,11 +591,11 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: sel_load_functor_:: operator() (const T &vec) { @@ -622,11 +622,11 @@ operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: sel_load_view_functor_:: operator() (T &vec) { @@ -661,11 +661,11 @@ operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: concat_load_view_functor_:: operator() (const T &vec) { @@ -699,11 +699,11 @@ operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: sel_remove_functor_:: operator() (T &vec) const { @@ -721,11 +721,11 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: shuffle_functor_:: operator() (T &vec) const { @@ -738,11 +738,11 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: random_load_data_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; @@ -772,10 +772,10 @@ random_load_data_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame:: +void DataFrame:: random_load_view_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; @@ -812,11 +812,11 @@ random_load_view_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::columns_info_functor_::operator() (const T &vec) { +DataFrame::columns_info_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -826,11 +826,11 @@ DataFrame::columns_info_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::copy_remove_functor_::operator() (const T &vec) { +DataFrame::copy_remove_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -850,11 +850,11 @@ DataFrame::copy_remove_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::fill_missing_functor_::operator() (T &vec) { +DataFrame::fill_missing_functor_::operator() (T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -873,11 +873,11 @@ DataFrame::fill_missing_functor_::operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::describe_functor_::operator() (const T &vec) { +DataFrame::describe_functor_::operator() (const T &vec) { const size_type vec_s = vec.size(); diff --git a/include/DataFrame/Internals/DataFrame_opt.tcc b/include/DataFrame/Internals/DataFrame_opt.tcc index a51adb06c..b2081f753 100644 --- a/include/DataFrame/Internals/DataFrame_opt.tcc +++ b/include/DataFrame/Internals/DataFrame_opt.tcc @@ -36,9 +36,9 @@ namespace hmdf // ---------------------------------------------------------------------------- -template +template template -bool DataFrame::is_equal (const DataFrame &rhs) const { +bool DataFrame::is_equal (const DataFrame &rhs) const { if (column_list_.size() != rhs.column_list_.size()) return (false); @@ -63,9 +63,9 @@ bool DataFrame::is_equal (const DataFrame &rhs) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame &DataFrame:: +DataFrame &DataFrame:: modify_by_idx (DataFrame &rhs, sort_state already_sorted) { if (already_sorted == sort_state::not_sorted) { diff --git a/include/DataFrame/Internals/DataFrame_read.tcc b/include/DataFrame/Internals/DataFrame_read.tcc index aff0289b7..0e8556357 100644 --- a/include/DataFrame/Internals/DataFrame_read.tcc +++ b/include/DataFrame/Internals/DataFrame_read.tcc @@ -46,8 +46,8 @@ namespace hmdf // ---------------------------------------------------------------------------- -template -void DataFrame::read_json_(std::istream &stream, bool columns_only) { +template +void DataFrame::read_json_(std::istream &stream, bool columns_only) { char c { '\0' }; char col_name[256]; @@ -293,8 +293,8 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { // ---------------------------------------------------------------------------- -template -void DataFrame::read_csv_(std::istream &stream, bool columns_only) { +template +void DataFrame::read_csv_(std::istream &stream, bool columns_only) { char col_name[256]; char value[32]; @@ -445,8 +445,8 @@ struct _col_data_spec_ { // -------------------------------------- -template -void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { +template +void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { char value[8192]; char c; @@ -741,8 +741,8 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { // ---------------------------------------------------------------------------- -template -bool DataFrame:: +template +bool DataFrame:: read (const char *file_name, io_format iof, bool columns_only) { std::ifstream stream; @@ -762,9 +762,9 @@ read (const char *file_name, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template template -bool DataFrame::read (S &in_s, io_format iof, bool columns_only) { +bool DataFrame::read (S &in_s, io_format iof, bool columns_only) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call read()"); @@ -783,9 +783,9 @@ bool DataFrame::read (S &in_s, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template bool -DataFrame::from_string (const char *data_frame) { +DataFrame::from_string (const char *data_frame) { std::stringstream ss (std::string(data_frame), std::ios_base::in); @@ -795,8 +795,8 @@ DataFrame::from_string (const char *data_frame) { // ---------------------------------------------------------------------------- -template -std::future DataFrame:: +template +std::future DataFrame:: read_async(const char *file_name, io_format iof, bool columns_only) { return (std::async(std::launch::async, @@ -807,9 +807,9 @@ read_async(const char *file_name, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: read_async(S &in_s, io_format iof, bool columns_only) { return (std::async(std::launch::async, @@ -820,9 +820,9 @@ read_async(S &in_s, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template std::future -DataFrame::from_string_async(const char *data_frame) { +DataFrame::from_string_async(const char *data_frame) { return (std::async(std::launch::async, &DataFrame::from_string, this, data_frame)); diff --git a/include/DataFrame/Internals/DataFrame_set.tcc b/include/DataFrame/Internals/DataFrame_set.tcc index ff80bea74..f057823d0 100644 --- a/include/DataFrame/Internals/DataFrame_set.tcc +++ b/include/DataFrame/Internals/DataFrame_set.tcc @@ -38,9 +38,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -std::vector &DataFrame::create_column (const char *name) { +std::vector &DataFrame::create_column (const char *name) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call create_column()"); @@ -69,8 +69,8 @@ std::vector &DataFrame::create_column (const char *name) { // ---------------------------------------------------------------------------- -template -void DataFrame::remove_column (const char *name) { +template +void DataFrame::remove_column (const char *name) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call remove_column()"); @@ -106,16 +106,16 @@ void DataFrame::remove_column (const char *name) { // ---------------------------------------------------------------------------- -template -void DataFrame::remove_column(size_type index) { +template +void DataFrame::remove_column(size_type index) { return (remove_column(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template -void DataFrame::rename_column (const char *from, const char *to) { +template +void DataFrame::rename_column (const char *from, const char *to) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call rename_column()"); @@ -153,9 +153,9 @@ void DataFrame::rename_column (const char *from, const char *to) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: retype_column (const char *name, std::function convert_func) { @@ -179,10 +179,10 @@ retype_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::load_data (IndexVecType &&indices, Ts&& ... args) { +typename DataFrame::size_type +DataFrame::load_data (IndexVecType &&indices, Ts&& ... args) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call load_data()"); @@ -204,10 +204,10 @@ DataFrame::load_data (IndexVecType &&indices, Ts&& ... args) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::load_index(const ITR &begin, const ITR &end) { +typename DataFrame::size_type +DataFrame::load_index(const ITR &begin, const ITR &end) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call load_index()"); @@ -219,9 +219,9 @@ DataFrame::load_index(const ITR &begin, const ITR &end) { // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type -DataFrame::load_index(IndexVecType &&idx) { +template +typename DataFrame::size_type +DataFrame::load_index(IndexVecType &&idx) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call load_index()"); @@ -232,8 +232,8 @@ DataFrame::load_index(IndexVecType &&idx) { // ---------------------------------------------------------------------------- -template -std::vector DataFrame:: +template +std::vector DataFrame:: gen_datetime_index(const char *start_datetime, const char *end_datetime, time_frequency t_freq, @@ -290,8 +290,8 @@ gen_datetime_index(const char *start_datetime, // ---------------------------------------------------------------------------- -template -std::vector DataFrame:: +template +std::vector DataFrame:: gen_sequence_index (const IndexType &start_value, const IndexType &end_value, long increment) { @@ -308,10 +308,10 @@ gen_sequence_index (const IndexType &start_value, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::append_index(Index2D range) { +typename DataFrame::size_type +DataFrame::append_index(Index2D range) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call append_index()"); @@ -324,9 +324,9 @@ DataFrame::append_index(Index2D range) { // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type -DataFrame::append_index(const IndexType &val) { +template +typename DataFrame::size_type +DataFrame::append_index(const IndexType &val) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call append_index()"); @@ -337,10 +337,10 @@ DataFrame::append_index(const IndexType &val) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_column (const char *name, Index2D range, nan_policy padding) { @@ -392,10 +392,10 @@ load_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_result_as_column(V &visitor, const char *name, nan_policy padding) { const size_type idx_s = indices_.size(); @@ -444,10 +444,10 @@ load_result_as_column(V &visitor, const char *name, nan_policy padding) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_indicators(const char *cat_col_name, const char *numeric_cols_prefix) { using map_t = std::unordered_map *>; @@ -482,10 +482,10 @@ load_indicators(const char *cat_col_name, const char *numeric_cols_prefix) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: from_indicators(const std::vector &ind_col_names, const char *cat_col_name, const char *numeric_cols_prefixg) { @@ -515,9 +515,9 @@ from_indicators(const std::vector &ind_col_names, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: setup_view_column_ (const char *name, Index2D range) { static_assert(std::is_base_of::value || @@ -542,10 +542,10 @@ setup_view_column_ (const char *name, Index2D range) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_column (const char *name, std::vector &&column, nan_policy padding) { const size_type idx_s = indices_.size(); @@ -592,17 +592,17 @@ load_column (const char *name, std::vector &&column, nan_policy padding) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_align_column( const char *name, std::vector &&column, size_type interval, bool start_from_beginning, const T &null_value, - std::function diff_func) { @@ -650,10 +650,10 @@ load_align_column( // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_column (const char *name, const std::vector &data, nan_policy padding) { @@ -663,10 +663,10 @@ load_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::load_pair_(std::pair &col_name_data) { +typename DataFrame::size_type +DataFrame::load_pair_(std::pair &col_name_data) { return (load_column( col_name_data.first, // column name @@ -676,10 +676,10 @@ DataFrame::load_pair_(std::pair &col_name_data) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: append_column (const char *name, Index2D range, nan_policy padding) { @@ -719,10 +719,10 @@ append_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: append_column (const char *name, const T &val, nan_policy padding) { std::vector &vec = get_column(name); @@ -760,10 +760,10 @@ append_column (const char *name, const T &val, nan_policy padding) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::append_row_(std::pair &row_name_data) { +typename DataFrame::size_type +DataFrame::append_row_(std::pair &row_name_data) { return (append_column(row_name_data.first, // column name std::forward(row_name_data.second), @@ -772,10 +772,10 @@ DataFrame::append_row_(std::pair &row_name_data) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::append_row (IndexType *idx_val, Ts&& ... args) { +typename DataFrame::size_type +DataFrame::append_row (IndexType *idx_val, Ts&& ... args) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call append_row()"); @@ -798,9 +798,9 @@ DataFrame::append_row (IndexType *idx_val, Ts&& ... args) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::remove_data_by_idx (Index2D range) { +void DataFrame::remove_data_by_idx (Index2D range) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call remove_data_by_idx()"); @@ -831,9 +831,9 @@ void DataFrame::remove_data_by_idx (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::remove_data_by_loc (Index2D range) { +void DataFrame::remove_data_by_loc (Index2D range) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call remove_data_by_loc()"); @@ -871,9 +871,9 @@ void DataFrame::remove_data_by_loc (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) { +void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call remove_data_by_loc()"); @@ -905,9 +905,9 @@ void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: remove_data_by_sel (const char *name1, const char *name2, F &sel_functor) { const ColumnVecType &vec1 = get_column(name1); @@ -946,9 +946,9 @@ remove_data_by_sel (const char *name1, const char *name2, F &sel_functor) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: remove_data_by_sel (const char *name1, const char *name2, const char *name3, @@ -993,9 +993,9 @@ remove_data_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: remove_dups_common_(const DataFrame &s_df, remove_dup_spec rds, const MAP &row_table, @@ -1056,9 +1056,9 @@ remove_dups_common_(const DataFrame &s_df, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name, bool include_index, remove_dup_spec rds) const { @@ -1091,9 +1091,9 @@ remove_duplicates (const char *name, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, bool include_index, @@ -1129,9 +1129,9 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1171,9 +1171,9 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1217,10 +1217,10 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1267,11 +1267,11 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1322,9 +1322,9 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *new_col_name, @@ -1351,10 +1351,10 @@ consolidate(const char *old_col_name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, @@ -1385,10 +1385,10 @@ consolidate(const char *old_col_name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, @@ -1423,11 +1423,11 @@ consolidate(const char *old_col_name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, diff --git a/include/DataFrame/Internals/DataFrame_shift.tcc b/include/DataFrame/Internals/DataFrame_shift.tcc index 5992a4bb3..c3f10e205 100644 --- a/include/DataFrame/Internals/DataFrame_shift.tcc +++ b/include/DataFrame/Internals/DataFrame_shift.tcc @@ -37,9 +37,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -void DataFrame::self_shift(size_type periods, shift_policy sp) { +void DataFrame::self_shift(size_type periods, shift_policy sp) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call self_shift()"); @@ -87,15 +87,15 @@ void DataFrame::self_shift(size_type periods, shift_policy sp) { // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: shift(size_type periods, shift_policy sp) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call shift()"); - StdDataFrame slug = *this; + DataFrame slug = *this; slug.template self_shift(periods, sp); return (slug); @@ -103,9 +103,9 @@ shift(size_type periods, shift_policy sp) const { // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: shift(const char *col_name, size_type periods, shift_policy sp) const { static_assert(std::is_base_of::value, @@ -120,9 +120,9 @@ shift(const char *col_name, size_type periods, shift_policy sp) const { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::self_rotate(size_type periods, shift_policy sp) { +void DataFrame::self_rotate(size_type periods, shift_policy sp) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call self_rotate()"); @@ -171,9 +171,9 @@ void DataFrame::self_rotate(size_type periods, shift_policy sp) { // ---------------------------------------------------------------------------- -template +template template -StdDataFrame DataFrame:: +DataFrame DataFrame:: rotate(size_type periods, shift_policy sp) const { static_assert(std::is_base_of::value, diff --git a/include/DataFrame/Internals/DataFrame_visit.tcc b/include/DataFrame/Internals/DataFrame_visit.tcc index c93fccddc..e33a6c4ec 100644 --- a/include/DataFrame/Internals/DataFrame_visit.tcc +++ b/include/DataFrame/Internals/DataFrame_visit.tcc @@ -35,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -void DataFrame::multi_visit (Ts ... args) { +void DataFrame::multi_visit (Ts ... args) { auto args_tuple = std::tuple(args ...); auto fc = [this](auto &pa) mutable -> void { @@ -59,18 +59,18 @@ void DataFrame::multi_visit (Ts ... args) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::multi_visit(Ts ... args) const { +void DataFrame::multi_visit(Ts ... args) const { const_cast(this)->multi_visit(args ...); } // ---------------------------------------------------------------------------- -template +template template -V &DataFrame::visit (const char *name, V &visitor, bool in_reverse) { +V &DataFrame::visit (const char *name, V &visitor, bool in_reverse) { auto &vec = get_column(name); const size_type idx_s = indices_.size(); @@ -101,9 +101,9 @@ V &DataFrame::visit (const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name, V &visitor, bool in_reverse) const { return (const_cast(this)->visit @@ -112,9 +112,9 @@ visit (const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name, V &visitor, bool in_reverse) { return (std::async(std::launch::async, @@ -128,9 +128,9 @@ visit_async(const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name, V &visitor, bool in_reverse) const { return (std::async(std::launch::async, @@ -146,9 +146,9 @@ visit_async(const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, V &visitor, bool in_reverse) { auto &vec1 = get_column(name1); @@ -190,9 +190,9 @@ visit (const char *name1, const char *name2, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, V &visitor, @@ -204,9 +204,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, V &visitor, @@ -225,9 +225,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, V &visitor, @@ -249,9 +249,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -304,9 +304,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -319,9 +319,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -346,9 +346,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -373,9 +373,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -435,9 +435,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -451,9 +451,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -481,9 +481,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -511,10 +511,10 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -582,10 +582,10 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -600,10 +600,10 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -634,10 +634,10 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -668,9 +668,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name, V &visitor, bool in_reverse) { auto &vec = get_column(name); @@ -687,9 +687,9 @@ single_act_visit (const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name, V &visitor, bool in_reverse) const { return (const_cast(this)->single_act_visit @@ -698,9 +698,9 @@ single_act_visit (const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name, V &visitor, bool in_reverse) { return (std::async( @@ -715,9 +715,9 @@ single_act_visit_async(const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name, V &visitor, bool in_reverse) const { return (std::async( @@ -732,9 +732,9 @@ single_act_visit_async(const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, V &visitor, @@ -759,9 +759,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, V &visitor, @@ -780,9 +780,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, V &visitor, @@ -794,9 +794,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, V &visitor, @@ -818,9 +818,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -849,9 +849,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -864,9 +864,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -891,9 +891,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -918,9 +918,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -953,9 +953,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -969,9 +969,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -999,9 +999,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -1029,10 +1029,10 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -1069,10 +1069,10 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -1088,10 +1088,10 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -1122,10 +1122,10 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, diff --git a/include/DataFrame/Internals/DataFrame_write.tcc b/include/DataFrame/Internals/DataFrame_write.tcc index 4449f4ddf..62880a719 100644 --- a/include/DataFrame/Internals/DataFrame_write.tcc +++ b/include/DataFrame/Internals/DataFrame_write.tcc @@ -36,9 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -bool DataFrame:: +bool DataFrame:: write(const char *file_name, io_format iof, std::streamsize precision, @@ -62,10 +62,10 @@ write(const char *file_name, // ---------------------------------------------------------------------------- -template +template template std::string -DataFrame::to_string(std::streamsize precision) const { +DataFrame::to_string(std::streamsize precision) const { std::stringstream ss (std::ios_base::out); @@ -75,9 +75,9 @@ DataFrame::to_string(std::streamsize precision) const { // ---------------------------------------------------------------------------- -template +template template -bool DataFrame:: +bool DataFrame:: write(S &o, io_format iof, std::streamsize precision, @@ -205,9 +205,9 @@ write(S &o, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: write_async (const char *file_name, io_format iof, std::streamsize precision, @@ -231,9 +231,9 @@ write_async (const char *file_name, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: write_async (S &o, io_format iof, std::streamsize precision, @@ -257,9 +257,9 @@ write_async (S &o, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: to_string_async (std::streamsize precision) const { return (std::async(std::launch::async, diff --git a/include/DataFrame/Utils/AlignedAllocator.h b/include/DataFrame/Utils/AlignedAllocator.h index 2c03b5ab4..ff1294184 100644 --- a/include/DataFrame/Utils/AlignedAllocator.h +++ b/include/DataFrame/Utils/AlignedAllocator.h @@ -103,11 +103,11 @@ class AlignedAllocator : public AlignedValue { AlignedAllocator(AlignedAllocator &&) noexcept = default; ~AlignedAllocator() noexcept = default; - AlignedAllocator &operator=(AlignedAllocator &&) = default; + AlignedAllocator &operator=(AlignedAllocator &&) noexcept = default; AlignedAllocator &operator=(const AlignedAllocator &) = delete; template - AlignedAllocator(AlignedAllocator const &) noexcept { } + inline AlignedAllocator(AlignedAllocator const &) noexcept { } // Always return true for stateless allocators. // @@ -141,13 +141,12 @@ class AlignedAllocator : public AlignedValue { [[nodiscard]] inline pointer allocate(size_type n_items) const { if (n_items == 0) return (nullptr); - if (n_items >= max_size()) + if (n_items > max_size()) throw std::bad_array_new_length(); - const auto bytes = n_items * sizeof(value_type); - return(reinterpret_cast( - ::operator new[](bytes, AlignedAllocator::align_value))); + ::operator new[](n_items * sizeof(value_type), + AlignedAllocator::align_value))); } // This is the same for all allocators that ignore hints. diff --git a/test/dataframe_tester.cc b/test/dataframe_tester.cc index e0c169f88..aca6cf2a6 100644 --- a/test/dataframe_tester.cc +++ b/test/dataframe_tester.cc @@ -3596,7 +3596,8 @@ static void test_view_visitors() { std::make_pair("dbl_col5", dblvec5), std::make_pair("dbl_col6", dblvec6)); - typedef DataFrameView MyDataFrameView; + typedef StdDataFrame::DataFrameView + MyDataFrameView; MyDataFrameView dfv = df.get_view_by_idx(Index2D { 2, 4 }); diff --git a/test/dataframe_tester_2.cc b/test/dataframe_tester_2.cc index fc3386ea4..aa545707b 100644 --- a/test/dataframe_tester_2.cc +++ b/test/dataframe_tester_2.cc @@ -4163,8 +4163,11 @@ static void test_get_view_by_loc() { std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl; - typedef DataFrameView MyDataFrameView; - typedef DataFrameConstView MyDataFrameConstView; + typedef StdDataFrame::DataFrameView + MyDataFrameView; + typedef StdDataFrame::DataFrameConstView + MyDataFrameConstView; + const MyDataFrame &const_df = df; MyDataFrameView dfv = @@ -4215,8 +4218,10 @@ static void test_get_view_by_idx_slicing() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - typedef DataFrameView MyDataFrameView; - typedef DataFrameConstView MyDataFrameConstView; + typedef StdDataFrame::DataFrameView + MyDataFrameView; + typedef StdDataFrame::DataFrameConstView + MyDataFrameConstView; const MyDataFrame &const_df = df; @@ -4276,10 +4281,15 @@ static void test_get_data() { assert((df2.get_column("col_4")[8] == 2)); assert((df2.get_index()[3] == 123453)); - const MyDataFrame &const_df = df; - DataFrameView df3 = + typedef StdDataFrame::DataFrameView + MyDataFrameView; + typedef StdDataFrame::DataFrameConstView + MyDataFrameConstView; + + const MyDataFrame &const_df = df; + MyDataFrameView df3 = df.get_view({ "col_1", "col_4"}); - DataFrameConstView const_df3 = + MyDataFrameConstView const_df3 = const_df.get_view({ "col_1", "col_4"}); assert((! df3.has_column("col_2"))); From 4067a64dd9fb7f3bfa4a7757964b75b2fefd1bac Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Tue, 13 Dec 2022 15:59:14 -0500 Subject: [PATCH 07/25] Tweaked the boilerplate crap further --- include/DataFrame/DataFrame.h | 101 ++++---- include/DataFrame/Internals/DataFrame_get.tcc | 240 +++++++++--------- .../DataFrame/Internals/DataFrame_join.tcc | 44 ++-- test/dataframe_tester.cc | 3 +- test/dataframe_tester_2.cc | 18 +- 5 files changed, 199 insertions(+), 207 deletions(-) diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index 620b2f513..23584c732 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -58,10 +58,10 @@ namespace hmdf // necessarily represent time, it could be any built-in or user-defined type // H: See the static assert below. It can only be either // a HeteroVector (typedef'ed to StdDataFrame) or -// a HeteroView (typedef'ed to DataFrameView) or -// a HeteroConstView (typedef'ed to DataFrameConstView) or -// a HeteroPtrView (typedef'ed to DataFramePtrView) -// a HeteroConstPtrView (typedef'ed to DataFrameConstPtrView) +// a HeteroView (typedef'ed to View) or +// a HeteroConstView (typedef'ed to ConstView) or +// a HeteroPtrView (typedef'ed to PtrView) +// a HeteroConstPtrView (typedef'ed to ConstPtrView) // // A DataFrame may contain one index and any number of columns of any built-in // or user-defined types @@ -88,17 +88,22 @@ class DataFrame : public ThreadGranularity { using IndexVecType = typename type_declare::type; using ColNameType = String64; - template - using DataFrameView = DataFrame; - - template - using DataFrameConstView = DataFrame; - - template - using DataFramePtrView = DataFrame; - - template - using DataFrameConstPtrView = DataFrame; + using View = + typename std::conditional::value, + DataFrame, + void>::type; + using ConstView = + typename std::conditional::value, + DataFrame, + void>::type; + using PtrView = + typename std::conditional::value, + DataFrame, + void>::type; + using ConstPtrView = + typename std::conditional::value, + DataFrame, + void>::type; template using ColumnVecType = typename type_declare::type; @@ -1385,12 +1390,12 @@ class DataFrame : public ThreadGranularity { // through views. // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView concat_view(RHS_T &rhs, concat_policy cp = concat_policy::common_columns); template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView concat_view(RHS_T &rhs, concat_policy cp = concat_policy::common_columns) const; @@ -1665,7 +1670,7 @@ class DataFrame : public ThreadGranularity { [[nodiscard]] DataFrame get_data_by_idx(const std::vector &values) const; - // It behaves like get_data_by_idx(range), but it returns a DataFrameView. + // It behaves like get_data_by_idx(range), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. // So if you modify anything in the view the original DataFrame will // also be modified. @@ -1682,15 +1687,14 @@ class DataFrame : public ThreadGranularity { // The begin and end iterators for index specified with index values // template - [[nodiscard]] DataFrameView + [[nodiscard]] View get_view_by_idx(Index2D range); template - [[nodiscard]] DataFrameConstView + [[nodiscard]] ConstView get_view_by_idx(Index2D range) const; - // It behaves like get_data_by_idx(values), but it returns a - // DataFramePtrView. + // It behaves like get_data_by_idx(values), but it returns a PtrView. // A view is a DataFrame that is a reference to the original DataFrame. // So if you modify anything in the view the original DataFrame will // also be modified. @@ -1707,11 +1711,11 @@ class DataFrame : public ThreadGranularity { // List of indices to copy data from // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_idx(const std::vector &values); template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_idx(const std::vector &values) const; // It returns a DataFrame (including the index and data columns) @@ -1747,7 +1751,7 @@ class DataFrame : public ThreadGranularity { [[nodiscard]] DataFrame get_data_by_loc(const std::vector &locations) const; - // It behaves like get_data_by_loc(range), but it returns a DataFrameView. + // It behaves like get_data_by_loc(range), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. // So if you modify anything in the view the original DataFrame will // also be modified. @@ -1764,15 +1768,14 @@ class DataFrame : public ThreadGranularity { // The begin and end iterators for data // template - [[nodiscard]] DataFrameView + [[nodiscard]] View get_view_by_loc(Index2D range); template - [[nodiscard]] DataFrameConstView + [[nodiscard]] ConstView get_view_by_loc(Index2D range) const; - // It behaves like get_data_by_loc(locations), but it returns a - // DataFramePtrView. + // It behaves like get_data_by_loc(locations), but it returns a PtrView. // A view is a DataFrame that is a reference to the original DataFrame. // So if you modify anything in the view the original DataFrame will // also be modified. @@ -1789,11 +1792,11 @@ class DataFrame : public ThreadGranularity { // List of indices into the index column to copy data // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_loc(const std::vector &locations); template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_loc(const std::vector &locations) const; // This method does boolean filtering selection via the sel_functor @@ -1847,11 +1850,11 @@ class DataFrame : public ThreadGranularity { // A reference to the selecting functor // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_sel(const char *name, F &sel_functor); template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_sel(const char *name, F &sel_functor) const; // This does the same function as above get_data_by_sel() but operating @@ -1906,11 +1909,11 @@ class DataFrame : public ThreadGranularity { // A reference to the selecting functor // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_sel(const char *name1, const char *name2, F &sel_functor); template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_sel(const char *name1, const char *name2, F &sel_functor) const; // This does the same function as above get_data_by_sel() but operating @@ -1976,7 +1979,7 @@ class DataFrame : public ThreadGranularity { // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1984,7 +1987,7 @@ class DataFrame : public ThreadGranularity { template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -2063,7 +2066,7 @@ class DataFrame : public ThreadGranularity { // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -2072,7 +2075,7 @@ class DataFrame : public ThreadGranularity { template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -2161,7 +2164,7 @@ class DataFrame : public ThreadGranularity { // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -2171,7 +2174,7 @@ class DataFrame : public ThreadGranularity { template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -2282,7 +2285,7 @@ class DataFrame : public ThreadGranularity { [[nodiscard]] DataFrame get_data_by_rand(random_policy spec, double n, size_type seed = 0) const; - // It behaves like get_data_by_rand(), but it returns a DataFramePtrView. + // It behaves like get_data_by_rand(), but it returns a PtrView. // A view is a DataFrame that is a reference to the original DataFrame. // So if you modify anything in the view the original DataFrame will // also be modified. @@ -2308,11 +2311,11 @@ class DataFrame : public ThreadGranularity { // seed should always produce the same random selection. // template - [[nodiscard]] DataFramePtrView + [[nodiscard]] PtrView get_view_by_rand(random_policy spec, double n, size_type seed = 0); template - [[nodiscard]] DataFrameConstPtrView + [[nodiscard]] ConstPtrView get_view_by_rand(random_policy spec, double n, size_type seed = 0) const; // This returns a DataFrame with index and col_names copied from the @@ -2327,7 +2330,7 @@ class DataFrame : public ThreadGranularity { [[nodiscard]] DataFrame get_data(const std::vector &col_names) const; - // It behaves like get_data(), but it returns a DataFrameView. + // It behaves like get_data(), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. // So if you modify anything in the view the original DataFrame will // also be modified. @@ -2343,11 +2346,11 @@ class DataFrame : public ThreadGranularity { // List of column names // template - [[nodiscard]] DataFrameView + [[nodiscard]] View get_view(const std::vector &col_names); template - [[nodiscard]] DataFrameConstView + [[nodiscard]] ConstView get_view(const std::vector &col_names) const; // It returns a const reference to the index container @@ -2425,12 +2428,12 @@ class DataFrame : public ThreadGranularity { // the result as a column. // template - [[nodiscard]] DataFrameView + [[nodiscard]] typename DataFrame::View get_reindexed_view(const char *col_to_be_index, const char *old_index_name = nullptr); template - [[nodiscard]] DataFrameConstView + [[nodiscard]] typename DataFrame::ConstView get_reindexed_view(const char *col_to_be_index, const char *old_index_name = nullptr) const; diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index 7cec7c3f2..c2f3f574e 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -79,8 +79,8 @@ DataFrame::col_name_to_idx (const char *col_name) const { char buffer [512]; snprintf (buffer, sizeof(buffer) - 1, - "DataFrame::col_name_to_idx(): ERROR: Cannot find column '%s'", - col_name); + "DataFrame::col_name_to_idx(): ERROR: Cannot find column '%s'", + col_name); throw ColNotFound (buffer); } @@ -103,7 +103,7 @@ DataFrame::col_idx_to_name (size_type col_idx) const { #else "Cannot find column index %lu", #endif // _MSC_VER - col_idx); + col_idx); throw ColNotFound (buffer); } @@ -121,7 +121,7 @@ DataFrame::get_column (const char *name) { snprintf (buffer, sizeof(buffer) - 1, "DataFrame::get_column(): ERROR: Cannot find column '%s'", - name); + name); throw ColNotFound (buffer); } @@ -228,7 +228,7 @@ get_row(size_type row_num, const std::vector &col_names) const { snprintf(buffer, sizeof(buffer) - 1, "DataFrame::get_row(): ERROR: There aren't %lu rows", #endif // _MSC_VER - row_num); + row_num); throw BadRange(buffer); } @@ -247,8 +247,8 @@ get_row(size_type row_num, const std::vector &col_names) const { char buffer [512]; snprintf(buffer, sizeof(buffer) - 1, - "DataFrame::get_row(): ERROR: Cannot find column '%s'", - name_citer); + "DataFrame::get_row(): ERROR: Cannot find column '%s'", + name_citer); throw ColNotFound(buffer); } @@ -275,7 +275,7 @@ get_row(size_type row_num) const { snprintf(buffer, sizeof(buffer) - 1, "DataFrame::get_row(): ERROR: There aren't %lu rows", #endif // _MSC_VER - row_num); + row_num); throw BadRange(buffer); } @@ -413,17 +413,17 @@ get_data_by_idx(const std::vector &values) const { template template -typename DataFrame::template DataFrameView +typename DataFrame::View DataFrame::get_view_by_idx (Index2D range) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_idx()"); - auto lower = + auto lower = std::lower_bound (indices_.begin(), indices_.end(), range.begin); - auto upper = + auto upper = std::upper_bound (indices_.begin(), indices_.end(), range.end); - DataFrameView dfv; + View dfv; if (lower != indices_.end() && (upper != indices_.end() || indices_.back() == range.end)) { @@ -435,18 +435,15 @@ DataFrame::get_view_by_idx (Index2D range) { upper_address = &*upper; else upper_address = &(indices_.front()) + e_dist; - dfv.indices_ = - typename DataFrameView::IndexVecType(&*lower, - upper_address); + dfv.indices_ = typename View::IndexVecType(&*lower, upper_address); const SpinGuard guard(lock_); for (const auto &iter : column_list_) { - view_setup_functor_, Ts ...> functor ( - iter.first.c_str(), - b_dist, - e_dist, - dfv); + view_setup_functor_ functor (iter.first.c_str(), + b_dist, + e_dist, + dfv); data_[iter.second].change(functor); } @@ -459,17 +456,17 @@ DataFrame::get_view_by_idx (Index2D range) { template template -typename DataFrame::template DataFrameConstView +typename DataFrame::ConstView DataFrame::get_view_by_idx (Index2D range) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_idx()"); - auto lower = + auto lower = std::lower_bound (indices_.begin(), indices_.end(), range.begin); - auto upper = + auto upper = std::upper_bound (indices_.begin(), indices_.end(), range.end); - DataFrameConstView dfcv; + ConstView dfcv; if (lower != indices_.end() && (upper != indices_.end() || indices_.back() == range.end)) { @@ -482,18 +479,15 @@ DataFrame::get_view_by_idx (Index2D range) const { else upper_address = &(indices_.front()) + e_dist; dfcv.indices_ = - typename DataFrameConstView::IndexVecType( - &*lower, - upper_address); + typename ConstView::IndexVecType(&*lower, upper_address); const SpinGuard guard(lock_); for (const auto &iter : column_list_) { - view_setup_functor_, Ts ...> - functor (iter.first.c_str(), - b_dist, - e_dist, - dfcv); + view_setup_functor_ functor (iter.first.c_str(), + b_dist, + e_dist, + dfcv); data_[iter.second].change(functor); } @@ -506,13 +500,13 @@ DataFrame::get_view_by_idx (Index2D range) const { template template -typename DataFrame::template DataFramePtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_idx(const std::vector &values) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_idx()"); - using TheView = DataFramePtrView; + using TheView = PtrView; const std::unordered_set val_table(values.begin(), values.end()); @@ -553,14 +547,14 @@ get_view_by_idx(const std::vector &values) { template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_idx(const std::vector &values) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_idx()"); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; const std::unordered_set val_table(values.begin(), values.end()); @@ -677,7 +671,7 @@ get_data_by_loc (const std::vector &locations) const { template template -typename DataFrame::template DataFrameView +typename DataFrame::View DataFrame::get_view_by_loc (Index2D range) { static_assert(std::is_base_of::value, @@ -691,19 +685,20 @@ DataFrame::get_view_by_loc (Index2D range) { range.end = idx_s + range.end + 1; if (range.end <= idx_s && range.begin <= range.end && range.begin >= 0) { - DataFrameView dfv; + View dfv; dfv.indices_ = - typename DataFrameView::IndexVecType( - &(indices_[0]) + range.begin, - &(indices_[0]) + range.end); + typename View::IndexVecType(&(indices_[0]) + range.begin, + &(indices_[0]) + range.end); + + const SpinGuard guard(lock_); + for (const auto &iter : column_list_) { - view_setup_functor_, Ts ...> functor ( + view_setup_functor_ functor ( iter.first.c_str(), static_cast(range.begin), static_cast(range.end), dfv); - const SpinGuard guard(lock_); data_[iter.second].change(functor); } @@ -724,7 +719,7 @@ DataFrame::get_view_by_loc (Index2D range) { template template -typename DataFrame::template DataFrameConstView +typename DataFrame::ConstView DataFrame::get_view_by_loc (Index2D range) const { static_assert(std::is_base_of::value, @@ -738,19 +733,20 @@ DataFrame::get_view_by_loc (Index2D range) const { range.end = idx_s + range.end + 1; if (range.end <= idx_s && range.begin <= range.end && range.begin >= 0) { - DataFrameConstView dfcv; + ConstView dfcv; dfcv.indices_ = - typename DataFrameConstView::IndexVecType( - &(indices_[0]) + range.begin, - &(indices_[0]) + range.end); + typename ConstView::IndexVecType(&(indices_[0]) + range.begin, + &(indices_[0]) + range.end); + + const SpinGuard guard(lock_); + for (const auto &iter : column_list_) { - view_setup_functor_, Ts ...> - functor (iter.first.c_str(), - static_cast(range.begin), - static_cast(range.end), - dfcv); - const SpinGuard guard(lock_); + view_setup_functor_ functor( + iter.first.c_str(), + static_cast(range.begin), + static_cast(range.end), + dfcv); data_[iter.second].change(functor); } @@ -771,13 +767,13 @@ DataFrame::get_view_by_loc (Index2D range) const { template template -typename DataFrame::template DataFramePtrView +typename DataFrame::PtrView DataFrame::get_view_by_loc (const std::vector &locations) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_loc()"); - using TheView = DataFramePtrView; + using TheView = PtrView; TheView dfv; const size_type idx_s = indices_.size(); @@ -811,14 +807,14 @@ DataFrame::get_view_by_loc (const std::vector &locations) { template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_loc (const std::vector &locations) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view_by_loc()"); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; TheView dfv; const size_type idx_s = indices_.size(); @@ -891,7 +887,7 @@ get_data_by_sel (const char *name, F &sel_functor) const { template template -typename DataFrame::template DataFramePtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel (const char *name, F &sel_functor) { static_assert(std::is_base_of::value, @@ -907,7 +903,7 @@ get_view_by_sel (const char *name, F &sel_functor) { if (sel_functor (indices_[i], vec[i])) col_indices.push_back(i); - using TheView = DataFramePtrView; + using TheView = PtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -935,7 +931,7 @@ get_view_by_sel (const char *name, F &sel_functor) { template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_sel (const char *name, F &sel_functor) const { @@ -952,7 +948,7 @@ get_view_by_sel (const char *name, F &sel_functor) const { if (sel_functor (indices_[i], vec[i])) col_indices.push_back(i); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1027,7 +1023,7 @@ get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { template template -typename DataFrame::template DataFramePtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { static_assert(std::is_base_of::value, @@ -1051,7 +1047,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { i < col_s2 ? vec2[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFramePtrView; + using TheView = PtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1079,7 +1075,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { @@ -1104,7 +1100,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { i < col_s2 ? vec2[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1313,7 +1309,7 @@ get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { template template -typename DataFrame::template DataFramePtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, const char *name3, @@ -1343,7 +1339,7 @@ get_view_by_sel (const char *name1, i < col_s3 ? vec3[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFramePtrView; + using TheView = PtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1371,7 +1367,7 @@ get_view_by_sel (const char *name1, template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, @@ -1402,7 +1398,7 @@ get_view_by_sel (const char *name1, i < col_s3 ? vec3[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1490,7 +1486,7 @@ get_data_by_sel(const char *name1, template template -typename DataFrame::template DataFramePtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1525,7 +1521,7 @@ get_view_by_sel(const char *name1, i < col_s4 ? vec4[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFramePtrView; + using TheView = PtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1554,7 +1550,7 @@ get_view_by_sel(const char *name1, template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, @@ -1590,7 +1586,7 @@ get_view_by_sel(const char *name1, i < col_s4 ? vec4[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1683,7 +1679,7 @@ get_data_by_sel(const char *name1, template template -typename DataFrame::template DataFramePtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1723,7 +1719,7 @@ get_view_by_sel(const char *name1, i < col_s5 ? vec5[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFramePtrView; + using TheView = PtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1752,7 +1748,7 @@ get_view_by_sel(const char *name1, template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, @@ -1793,7 +1789,7 @@ get_view_by_sel(const char *name1, i < col_s5 ? vec5[i] : get_nan())) col_indices.push_back(i); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; TheView dfv; typename TheView::IndexVecType new_index; @@ -1887,7 +1883,7 @@ get_data_by_rand(random_policy spec, double n, size_type seed) const { #else "Number of rows requested %lu is more than available rows %lu", #endif // _MSC_VER - n_rows, index_s); + n_rows, index_s); throw BadRange (buffer); } @@ -1895,7 +1891,7 @@ get_data_by_rand(random_policy spec, double n, size_type seed) const { template template -typename DataFrame::template DataFramePtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_rand (random_policy spec, double n, size_type seed) { bool use_seed = false; @@ -1926,7 +1922,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) { rand_indices[i] = dis(gen); std::sort(rand_indices.begin(), rand_indices.end()); - using TheView = DataFramePtrView; + using TheView = PtrView; typename TheView::IndexVecType new_index; size_type prev_value; @@ -1961,7 +1957,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) { #else "Number of rows requested %lu is more than available rows %lu", #endif // _MSC_VER - n_rows, index_s); + n_rows, index_s); throw BadRange (buffer); } @@ -1969,7 +1965,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) { template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame:: get_view_by_rand (random_policy spec, double n, size_type seed) const { @@ -2001,7 +1997,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { rand_indices[i] = dis(gen); std::sort(rand_indices.begin(), rand_indices.end()); - using TheView = DataFrameConstPtrView; + using TheView = ConstPtrView; typename TheView::IndexVecType new_index; size_type prev_value; @@ -2037,7 +2033,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { #else "Number of rows requested %lu is more than available rows %lu", #endif // _MSC_VER - n_rows, index_s); + n_rows, index_s); throw BadRange (buffer); } @@ -2077,18 +2073,17 @@ get_data(const std::vector &col_names) const { template template -typename DataFrame::template DataFrameView DataFrame:: +typename DataFrame::View DataFrame:: get_view(const std::vector &col_names) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view()"); - DataFrameView dfv; - const size_type idx_size = indices_.size(); + View dfv; + const size_type idx_size = indices_.size(); dfv.indices_ = - typename DataFrameView::IndexVecType(&(indices_[0]), - &(indices_[0]) + idx_size); + typename View::IndexVecType(&(indices_[0]), &(indices_[0]) + idx_size); for (const auto &name_citer : col_names) { const auto citer = column_tb_.find (name_citer); @@ -2102,12 +2097,11 @@ get_view(const std::vector &col_names) { throw ColNotFound(buffer); } - view_setup_functor_, Ts ...> functor ( - citer->first.c_str(), - 0, - idx_size, - dfv); - const SpinGuard guard(lock_); + view_setup_functor_ functor (citer->first.c_str(), + 0, + idx_size, + dfv); + const SpinGuard guard(lock_); data_[citer->second].change(functor); } @@ -2119,20 +2113,19 @@ get_view(const std::vector &col_names) { template template -typename DataFrame::template DataFrameConstView +typename DataFrame::ConstView DataFrame:: get_view(const std::vector &col_names) const { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_view()"); - DataFrameConstView dfcv; - const size_type idx_size = indices_.size(); + ConstView dfcv; + const size_type idx_size = indices_.size(); dfcv.indices_ = - typename DataFrameConstView::IndexVecType( - &(indices_[0]), - &(indices_[0]) + idx_size); + typename ConstView::IndexVecType(&(indices_[0]), + &(indices_[0]) + idx_size); for (const auto &name_citer : col_names) { const auto citer = column_tb_.find (name_citer); @@ -2146,12 +2139,11 @@ get_view(const std::vector &col_names) const { throw ColNotFound(buffer); } - view_setup_functor_, Ts ...> functor ( - citer->first.c_str(), - 0, - idx_size, - dfcv); - const SpinGuard guard(lock_); + view_setup_functor_ functor (citer->first.c_str(), + 0, + idx_size, + dfcv); + const SpinGuard guard(lock_); data_[citer->second].change(functor); } @@ -2201,17 +2193,19 @@ get_reindexed(const char *col_to_be_index, const char *old_index_name) const { template template -typename DataFrame::template DataFrameView DataFrame:: +typename DataFrame::View DataFrame:: get_reindexed_view(const char *col_to_be_index, const char *old_index_name) { static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_reindexed_view()"); - DataFrameView result; - auto &new_idx = get_column(col_to_be_index); - const size_type new_idx_s = new_idx.size(); + using TheView = typename DataFrame::View; + + TheView result; + auto &new_idx = get_column(col_to_be_index); + const size_type new_idx_s = new_idx.size(); - result.indices_ = typename DataFrameView::IndexVecType(); + result.indices_ = typename TheView::IndexVecType(); result.indices_.set_begin_end_special(&(new_idx.front()), &(new_idx.back())); if (old_index_name) { @@ -2227,12 +2221,12 @@ get_reindexed_view(const char *col_to_be_index, const char *old_index_name) { for (const auto &citer : column_list_) { if (citer.first == col_to_be_index) continue; - view_setup_functor_, Ts ...> functor ( + view_setup_functor_ functor ( citer.first.c_str(), 0, new_idx_s, result); - const SpinGuard guard(lock_); + const SpinGuard guard(lock_); data_[citer.second].change(functor); } @@ -2244,7 +2238,7 @@ get_reindexed_view(const char *col_to_be_index, const char *old_index_name) { template template -typename DataFrame::template DataFrameConstView +typename DataFrame::ConstView DataFrame:: get_reindexed_view(const char *col_to_be_index, const char *old_index_name) const { @@ -2252,11 +2246,13 @@ get_reindexed_view(const char *col_to_be_index, static_assert(std::is_base_of::value, "Only a StdDataFrame can call get_reindexed_view()"); - DataFrameConstView result; - const auto &new_idx = get_column(col_to_be_index); - const size_type new_idx_s = new_idx.size(); + using TheView = typename DataFrame::ConstView; - result.indices_ = typename DataFrameConstView::IndexVecType(); + TheView result; + const auto &new_idx = get_column(col_to_be_index); + const size_type new_idx_s = new_idx.size(); + + result.indices_ = typename TheView::IndexVecType(); result.indices_.set_begin_end_special(&(new_idx.front()), &(new_idx.back())); if (old_index_name) { @@ -2273,12 +2269,12 @@ get_reindexed_view(const char *col_to_be_index, for (const auto &citer : column_list_) { if (citer.first == col_to_be_index) continue; - view_setup_functor_, Ts ...> functor ( + view_setup_functor_ functor ( citer.first.c_str(), 0, new_idx_s, result); - const SpinGuard guard(lock_); + const SpinGuard guard(lock_); data_[citer.second].change(functor); } diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index 312f36eca..8eee26cb0 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -43,8 +43,8 @@ join_by_index (const RHS_T &rhs, join_policy mp) const { static_assert( std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value, + std::is_base_of::value || + std::is_base_of::value, "The rhs argument to join_by_index() can only be " "StdDataFrame or DataFrame[Ptr]View"); @@ -100,8 +100,8 @@ join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { static_assert( std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value, + std::is_base_of::value || + std::is_base_of::value, "The rhs argument to join_by_column() can only be " "StdDataFrame or DataFrame[Ptr]View"); @@ -644,8 +644,8 @@ DataFrame::self_concat(const RHS_T &rhs, bool add_new_columns) { static_assert( (std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value) && + std::is_base_of::value || + std::is_base_of::value) && ! std::is_base_of, decltype(*this)>::value, "The rhs argument to self_concat() can only be " @@ -664,8 +664,8 @@ DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { static_assert( (std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value || - std::is_base_of, RHS_T>::value) && + std::is_base_of::value || + std::is_base_of::value) && ! std::is_base_of, decltype(*this)>::value, "The rhs argument to concat() can only be " @@ -702,7 +702,7 @@ DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { template template -typename DataFrame::template DataFramePtrView +typename DataFrame::PtrView DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { static_assert( @@ -712,9 +712,9 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { "Currently, arguments to concat_view() can only be " "StdDataFrame."); - DataFramePtrView result; + PtrView result; - using idxvec_t = typename DataFramePtrView::IndexVecType; + using idxvec_t = typename PtrView::IndexVecType; const size_type idx_s = get_index().size(); const size_type rhs_idx_s = rhs.get_index().size(); @@ -729,13 +729,13 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { if (cp == concat_policy::all_columns) { for (const auto &lhs_citer : column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); data_[lhs_citer.second].change(functor); } for (const auto &rhs_citer : rhs.column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( rhs_citer.first.c_str(), result); rhs.data_[rhs_citer.second].change(functor); @@ -743,7 +743,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { } else if (cp == concat_policy::lhs_and_common_columns) { for (const auto &lhs_citer : column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); data_[lhs_citer.second].change(functor); @@ -756,7 +756,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { } else if (cp == concat_policy::common_columns) { for (const auto &lhs_citer : column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); @@ -776,7 +776,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { template template -typename DataFrame::template DataFrameConstPtrView +typename DataFrame::ConstPtrView DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { static_assert( @@ -786,9 +786,9 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { "Currently, arguments to concat_view() can only be " "StdDataFrame."); - DataFrameConstPtrView result; + ConstPtrView result; - using idxvec_t = typename DataFrameConstPtrView::IndexVecType; + using idxvec_t = typename ConstPtrView::IndexVecType; const size_type idx_s = get_index().size(); const size_type rhs_idx_s = rhs.get_index().size(); @@ -803,13 +803,13 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { if (cp == concat_policy::all_columns) { for (const auto &lhs_citer : column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); data_[lhs_citer.second].change(functor); } for (const auto &rhs_citer : rhs.column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( rhs_citer.first.c_str(), result); rhs.data_[rhs_citer.second].change(functor); @@ -817,7 +817,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { } else if (cp == concat_policy::lhs_and_common_columns) { for (const auto &lhs_citer : column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); data_[lhs_citer.second].change(functor); @@ -830,7 +830,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { } else if (cp == concat_policy::common_columns) { for (const auto &lhs_citer : column_list_) { - concat_load_view_functor_, Ts ...> functor( + concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); diff --git a/test/dataframe_tester.cc b/test/dataframe_tester.cc index aca6cf2a6..40ff14d6d 100644 --- a/test/dataframe_tester.cc +++ b/test/dataframe_tester.cc @@ -3596,8 +3596,7 @@ static void test_view_visitors() { std::make_pair("dbl_col5", dblvec5), std::make_pair("dbl_col6", dblvec6)); - typedef StdDataFrame::DataFrameView - MyDataFrameView; + typedef StdDataFrame::View MyDataFrameView; MyDataFrameView dfv = df.get_view_by_idx(Index2D { 2, 4 }); diff --git a/test/dataframe_tester_2.cc b/test/dataframe_tester_2.cc index aa545707b..7f8590a76 100644 --- a/test/dataframe_tester_2.cc +++ b/test/dataframe_tester_2.cc @@ -4163,10 +4163,8 @@ static void test_get_view_by_loc() { std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl; - typedef StdDataFrame::DataFrameView - MyDataFrameView; - typedef StdDataFrame::DataFrameConstView - MyDataFrameConstView; + typedef StdDataFrame::View MyDataFrameView; + typedef StdDataFrame::ConstView MyDataFrameConstView; const MyDataFrame &const_df = df; @@ -4218,10 +4216,8 @@ static void test_get_view_by_idx_slicing() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - typedef StdDataFrame::DataFrameView - MyDataFrameView; - typedef StdDataFrame::DataFrameConstView - MyDataFrameConstView; + typedef StdDataFrame::View MyDataFrameView; + typedef StdDataFrame::ConstView MyDataFrameConstView; const MyDataFrame &const_df = df; @@ -4281,10 +4277,8 @@ static void test_get_data() { assert((df2.get_column("col_4")[8] == 2)); assert((df2.get_index()[3] == 123453)); - typedef StdDataFrame::DataFrameView - MyDataFrameView; - typedef StdDataFrame::DataFrameConstView - MyDataFrameConstView; + typedef StdDataFrame::View MyDataFrameView; + typedef StdDataFrame::ConstView MyDataFrameConstView; const MyDataFrame &const_df = df; MyDataFrameView df3 = From d4960904615cbc4d59ae523de73d7886e37a6313 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 18 Dec 2022 10:52:44 -0500 Subject: [PATCH 08/25] Introduced the AlignAllocator to the code. all gen function have to be converted too --- CMakeLists.txt | 5 - include/DataFrame/DataFrame.h | 85 ++-- include/DataFrame/DataFrameTypes.h | 43 +- include/DataFrame/Internals/DataFrame.tcc | 214 +++++----- .../DataFrame/Internals/DataFrame_functors.h | 6 +- include/DataFrame/Internals/DataFrame_get.tcc | 383 +++++++++--------- .../DataFrame/Internals/DataFrame_join.tcc | 173 ++++---- .../DataFrame/Internals/DataFrame_misc.tcc | 138 +++---- include/DataFrame/Internals/DataFrame_opt.tcc | 8 +- .../Internals/DataFrame_private_decl.h | 26 +- .../DataFrame/Internals/DataFrame_read.tcc | 38 +- include/DataFrame/Internals/DataFrame_set.tcc | 245 +++++------ .../DataFrame/Internals/DataFrame_shift.tcc | 30 +- .../DataFrame/Internals/DataFrame_visit.tcc | 168 ++++---- .../DataFrame/Internals/DataFrame_write.tcc | 24 +- include/DataFrame/Utils/AlignedAllocator.h | 12 + .../DataFrame/Vectors/HeteroConstPtrView.h | 18 +- .../DataFrame/Vectors/HeteroConstPtrView.tcc | 107 ++++- include/DataFrame/Vectors/HeteroConstView.h | 15 +- include/DataFrame/Vectors/HeteroConstView.tcc | 115 +++++- include/DataFrame/Vectors/HeteroPtrView.h | 16 +- include/DataFrame/Vectors/HeteroPtrView.tcc | 125 ++++-- include/DataFrame/Vectors/HeteroVector.h | 46 ++- include/DataFrame/Vectors/HeteroVector.tcc | 183 +++++++-- include/DataFrame/Vectors/HeteroView.h | 20 +- include/DataFrame/Vectors/HeteroView.tcc | 159 ++++++-- include/DataFrame/Vectors/VectorPtrView.h | 16 +- include/DataFrame/Vectors/VectorView.h | 9 +- src/CommonMakefile.mk | 17 +- src/Vectors/HeteroConstPtrView.cc | 97 ----- src/Vectors/HeteroConstView.cc | 91 ----- src/Vectors/HeteroPtrView.cc | 91 ----- src/Vectors/HeteroVector.cc | 101 ----- src/Vectors/HeteroView.cc | 91 ----- test/vectors_tester.cc | 29 +- 35 files changed, 1487 insertions(+), 1457 deletions(-) delete mode 100644 src/Vectors/HeteroConstPtrView.cc delete mode 100644 src/Vectors/HeteroConstView.cc delete mode 100644 src/Vectors/HeteroPtrView.cc delete mode 100644 src/Vectors/HeteroVector.cc delete mode 100644 src/Vectors/HeteroView.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index dd9505987..0032fb5f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,11 +38,6 @@ add_library(DataFrame::DataFrame ALIAS DataFrame) target_sources(DataFrame PRIVATE src/Utils/DateTime.cc - src/Vectors/HeteroVector.cc - src/Vectors/HeteroView.cc - src/Vectors/HeteroConstView.cc - src/Vectors/HeteroPtrView.cc - src/Vectors/HeteroConstPtrView.cc ) target_compile_features(DataFrame PUBLIC cxx_std_17) diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index 23584c732..2cedfd3d7 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -66,47 +66,50 @@ namespace hmdf // A DataFrame may contain one index and any number of columns of any built-in // or user-defined types // -template +template class DataFrame : public ThreadGranularity { - static_assert(std::is_base_of::value || - std::is_base_of::value || - std::is_base_of::value || - std::is_base_of::value || - std::is_base_of::value, - "H argument can only be either of " - "HeteroVector, HeteroView, HeteroConstView, " - "HeteroPtrView, HeteroConstPtrView or their derived types"); - using DataVec = H; using DataVecVec = std::vector; public: // Construction + + static constexpr std::size_t align_value { std::size_t(H::align_value) }; + + template + using AllocatorType = typename allocator_declare::type; + using size_type = typename std::vector::size_type; using IndexType = I; - using IndexVecType = typename type_declare::type; + using IndexVecType = + typename type_declare::type; using ColNameType = String64; using View = - typename std::conditional::value, - DataFrame, - void>::type; + typename std::conditional< + std::is_base_of, H>::value, + DataFrame>, + void>::type; using ConstView = - typename std::conditional::value, - DataFrame, - void>::type; + typename std::conditional< + std::is_base_of, H>::value, + DataFrame>, + void>::type; using PtrView = - typename std::conditional::value, - DataFrame, - void>::type; + typename std::conditional< + std::is_base_of, H>::value, + DataFrame>, + void>::type; using ConstPtrView = - typename std::conditional::value, - DataFrame, - void>::type; + typename std::conditional< + std::is_base_of, H>::value, + DataFrame>, + void>::type; template - using ColumnVecType = typename type_declare::type; + using ColumnVecType = + typename type_declare::type; DataFrame() = default; @@ -299,10 +302,10 @@ class DataFrame : public ThreadGranularity { bool start_from_beginning, const T &null_value = hmdf::get_nan(), std::function::IndexType &, - const typename DataFrame::IndexType &)> diff_func = - [](const typename DataFrame::IndexType &t_1, - const typename DataFrame::IndexType &t) -> + const typename DataFrame::IndexType &, + const typename DataFrame::IndexType &)> diff_func = + [](const typename DataFrame::IndexType &t_1, + const typename DataFrame::IndexType &t) -> typename std::size_t { return (static_cast(t - t_1)); }); @@ -1206,11 +1209,11 @@ class DataFrame : public ThreadGranularity { // Name of the column // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame> value_counts(const char *col_name) const; template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame> value_counts(size_type index) const; // It bucketizes the data and index into intervals, based on index values @@ -1305,7 +1308,7 @@ class DataFrame : public ThreadGranularity { // (See join_policy definition) // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame> join_by_index(const RHS_T &rhs, join_policy jp) const; // It joins the data between self (lhs) and rhs and returns the joined data @@ -1338,7 +1341,8 @@ class DataFrame : public ThreadGranularity { // (See join_policy definition) // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame> join_by_column(const RHS_T &rhs, const char *name, join_policy jp) const; // It concatenates rhs to the end of self and returns the result as @@ -1362,7 +1366,7 @@ class DataFrame : public ThreadGranularity { // concatenated // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame> concat(const RHS_T &rhs, concat_policy cp = concat_policy::all_columns) const; @@ -1602,7 +1606,7 @@ class DataFrame : public ThreadGranularity { // in the returned vector // template - [[nodiscard]] HeteroVector + [[nodiscard]] HeteroVector get_row(size_type row_num, const std::vector &col_names) const; @@ -1618,7 +1622,7 @@ class DataFrame : public ThreadGranularity { // The row number // template - [[nodiscard]] HeteroVector + [[nodiscard]] HeteroVector get_row(size_type row_num) const; // It returns a vector of unique values in the named column in the same @@ -2402,7 +2406,7 @@ class DataFrame : public ThreadGranularity { // the result as a column. // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame> get_reindexed(const char *col_to_be_index, const char *old_index_name = nullptr) const; @@ -2428,12 +2432,12 @@ class DataFrame : public ThreadGranularity { // the result as a column. // template - [[nodiscard]] typename DataFrame::View + [[nodiscard]] typename DataFrame::View get_reindexed_view(const char *col_to_be_index, const char *old_index_name = nullptr); template - [[nodiscard]] typename DataFrame::ConstView + [[nodiscard]] typename DataFrame::ConstView get_reindexed_view(const char *col_to_be_index, const char *old_index_name = nullptr) const; @@ -2455,7 +2459,8 @@ class DataFrame : public ThreadGranularity { // the list only once. // template - [[nodiscard]] DataFrame + [[nodiscard]] DataFrame> describe() const; // This method combines the content of column col_name between self and @@ -3767,7 +3772,7 @@ class DataFrame : public ThreadGranularity { private: - template + template friend class DataFrame; using ColNameDict = diff --git a/include/DataFrame/DataFrameTypes.h b/include/DataFrame/DataFrameTypes.h index 518b10e98..e15cfc655 100644 --- a/include/DataFrame/DataFrameTypes.h +++ b/include/DataFrame/DataFrameTypes.h @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include #include @@ -453,24 +454,30 @@ struct template_switch> { using type = C; }; // ---------------------------------------------------------------------------- -template +template struct type_declare; -template -struct type_declare { using type = std::vector; }; +template +struct type_declare, U, A> { + using type = std::vector::type>; +}; -template -struct type_declare { using type = VectorView; }; +template +struct type_declare, U, A> { using type = VectorView; }; -template -struct type_declare { using type = VectorConstView; }; +template +struct type_declare, U, A> { + using type = VectorConstView; +}; -template -struct type_declare { using type = VectorPtrView; }; +template +struct type_declare, U, A> { + using type = VectorPtrView; +}; -template -struct type_declare { - using type = VectorConstPtrView; +template +struct type_declare, U, A> { + using type = VectorConstPtrView; }; // ---------------------------------------------------------------------------- @@ -488,25 +495,25 @@ template struct is_complex> { // H stands for Heterogeneous vector // A stands for memory Alignment // -template +template class DataFrame; template -using StdDataFrame = DataFrame; +using StdDataFrame = DataFrame>; // Convenient typedefs to facilitate SIMD operations // template -using StdDataFrame64 = DataFrame; +using StdDataFrame64 = DataFrame>; template -using StdDataFrame128 = DataFrame; +using StdDataFrame128 = DataFrame>; template -using StdDataFrame256 = DataFrame; +using StdDataFrame256 = DataFrame>; template -using StdDataFrame512 = DataFrame; +using StdDataFrame512 = DataFrame>; // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index a35fe950f..f00f41656 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -42,17 +42,17 @@ namespace hmdf // Notice memeber variables are initialized twice, but that's cheap // -template -DataFrame::DataFrame(const DataFrame &that) { *this = that; } +template +DataFrame::DataFrame(const DataFrame &that) { *this = that; } -template -DataFrame::DataFrame(DataFrame &&that) { *this = std::move(that); } +template +DataFrame::DataFrame(DataFrame &&that) { *this = std::move(that); } // ---------------------------------------------------------------------------- -template -DataFrame & -DataFrame::operator= (const DataFrame &that) { +template +DataFrame & +DataFrame::operator= (const DataFrame &that) { if (this != &that) { indices_ = that.indices_; @@ -68,9 +68,9 @@ DataFrame::operator= (const DataFrame &that) { // ---------------------------------------------------------------------------- -template -DataFrame & -DataFrame::operator= (DataFrame &&that) { +template +DataFrame & +DataFrame::operator= (DataFrame &&that) { if (this != &that) { indices_ = std::exchange(that.indices_, IndexVecType { }); @@ -86,8 +86,8 @@ DataFrame::operator= (DataFrame &&that) { // ---------------------------------------------------------------------------- -template -DataFrame::~DataFrame() { +template +DataFrame::~DataFrame() { const SpinGuard guard(lock_); @@ -96,31 +96,31 @@ DataFrame::~DataFrame() { // ---------------------------------------------------------------------------- -template -bool DataFrame::empty() const noexcept { return (indices_.empty()); } +template +bool DataFrame::empty() const noexcept { return (indices_.empty()); } // ---------------------------------------------------------------------------- -template -bool DataFrame:: +template +bool DataFrame:: shapeless() const noexcept { return (empty() && column_list_.empty()); } // ---------------------------------------------------------------------------- -template -void DataFrame::set_lock (SpinLock *sl) { lock_ = sl; } +template +void DataFrame::set_lock (SpinLock *sl) { lock_ = sl; } // ---------------------------------------------------------------------------- -template -void DataFrame::remove_lock () { lock_ = nullptr; } +template +void DataFrame::remove_lock () { lock_ = nullptr; } // ---------------------------------------------------------------------------- -template +template template -void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { +void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { const size_type idx_s = df.indices_.size(); std::vector sorting_idxs(idx_s, 0); @@ -140,10 +140,10 @@ void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { // ---------------------------------------------------------------------------- -template +template template void -DataFrame::shuffle(const std::vector &col_names, +DataFrame::shuffle(const std::vector &col_names, bool also_shuffle_index) { if (also_shuffle_index) { @@ -175,9 +175,9 @@ DataFrame::shuffle(const std::vector &col_names, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing_value_(ColumnVecType &vec, const T &value, int limit, @@ -204,9 +204,9 @@ fill_missing_value_(ColumnVecType &vec, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num) { const size_type vec_size = vec.size(); @@ -240,11 +240,11 @@ fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num) { // ---------------------------------------------------------------------------- -template +template template::value || ! std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_midpoint_(ColumnVecType &, int, size_type) { throw NotFeasible("fill_missing_midpoint_(): ERROR: Mid-point filling is " @@ -253,11 +253,11 @@ fill_missing_midpoint_(ColumnVecType &, int, size_type) { // ---------------------------------------------------------------------------- -template +template template::value && std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type) { const size_type vec_size = vec.size(); @@ -288,9 +288,9 @@ fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing_bfill_(ColumnVecType &vec, int limit) { const long vec_size = static_cast(vec.size()); @@ -313,11 +313,11 @@ fill_missing_bfill_(ColumnVecType &vec, int limit) { // ---------------------------------------------------------------------------- -template +template template::value || ! std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_linter_(ColumnVecType &, const IndexVecType &, int) { throw NotFeasible("fill_missing_linter_(): ERROR: Interpolation is " @@ -326,11 +326,11 @@ fill_missing_linter_(ColumnVecType &, const IndexVecType &, int) { // ---------------------------------------------------------------------------- -template +template template::value && std::is_arithmetic::value>::type*> -void DataFrame:: +void DataFrame:: fill_missing_linter_(ColumnVecType &vec, const IndexVecType &index, int limit) { @@ -391,9 +391,9 @@ fill_missing_linter_(ColumnVecType &vec, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: fill_missing(const std::vector &col_names, fill_policy fp, const std::vector &values, @@ -489,9 +489,9 @@ fill_missing(const std::vector &col_names, // ---------------------------------------------------------------------------- -template +template template -void DataFrame::fill_missing (const DF &rhs) { +void DataFrame::fill_missing (const DF &rhs) { const auto &self_idx = get_index(); const auto &rhs_idx = rhs.get_index(); @@ -509,9 +509,9 @@ void DataFrame::fill_missing (const DF &rhs) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: drop_missing_rows_(T &vec, const DropRowMap missing_row_map, drop_policy policy, @@ -546,9 +546,9 @@ drop_missing_rows_(T &vec, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: drop_missing(drop_policy policy, size_type threshold) { DropRowMap missing_row_map; @@ -577,9 +577,9 @@ drop_missing(drop_policy policy, size_type threshold) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type DataFrame:: +typename DataFrame::size_type DataFrame:: replace(const char *col_name, const std::vector &old_values, const std::vector &new_values, @@ -596,8 +596,8 @@ replace(const char *col_name, // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type DataFrame:: +template +typename DataFrame::size_type DataFrame:: replace_index(const std::vector &old_values, const std::vector &new_values, int limit) { @@ -612,9 +612,9 @@ replace_index(const std::vector &old_values, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: replace(const char *col_name, F &functor) { ColumnVecType &vec = get_column(col_name); @@ -628,9 +628,9 @@ replace(const char *col_name, F &functor) { // ---------------------------------------------------------------------------- -template +template template -std::future::size_type> DataFrame:: +std::future::size_type> DataFrame:: replace_async(const char *col_name, const std::vector &old_values, const std::vector &new_values, @@ -647,9 +647,9 @@ replace_async(const char *col_name, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: replace_async(const char *col_name, F &functor) { return (std::async(std::launch::async, @@ -661,11 +661,11 @@ replace_async(const char *col_name, F &functor) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::make_consistent () { +void DataFrame::make_consistent () { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call make_consistent()"); const size_type idx_s = indices_.size(); @@ -678,9 +678,9 @@ void DataFrame::make_consistent () { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::shrink_to_fit () { +void DataFrame::shrink_to_fit () { indices_.shrink_to_fit(); @@ -695,9 +695,9 @@ void DataFrame::shrink_to_fit () { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::sort(const char *name, sort_spec dir) { +void DataFrame::sort(const char *name, sort_spec dir) { make_consistent(); @@ -736,9 +736,9 @@ void DataFrame::sort(const char *name, sort_spec dir) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { make_consistent(); @@ -782,9 +782,9 @@ sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3) { @@ -849,9 +849,9 @@ sort(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -935,10 +935,10 @@ sort(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -1041,10 +1041,10 @@ sort(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame::sort_async(const char *name, sort_spec dir) { +DataFrame::sort_async(const char *name, sort_spec dir) { return (std::async(std::launch::async, [name, dir, this] () -> void { @@ -1054,10 +1054,10 @@ DataFrame::sort_async(const char *name, sort_spec dir) { // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { @@ -1070,10 +1070,10 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3) { @@ -1089,10 +1089,10 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -1110,11 +1110,11 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template std::future -DataFrame:: +DataFrame:: sort_async(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, const char *name3, sort_spec dir3, @@ -1134,9 +1134,9 @@ sort_async(const char *name1, sort_spec dir1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { const ColumnVecType *gb_vec { nullptr }; @@ -1179,9 +1179,9 @@ groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: groupby2(const char *col_name1, const char *col_name2, I_V &&idx_visitor, @@ -1246,9 +1246,9 @@ groupby2(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: groupby3(const char *col_name1, const char *col_name2, const char *col_name3, @@ -1331,9 +1331,9 @@ groupby3(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -std::future> DataFrame:: +std::future> DataFrame:: groupby1_async(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { return (std::async(std::launch::async, @@ -1346,9 +1346,9 @@ groupby1_async(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { // ---------------------------------------------------------------------------- -template +template template -std::future> DataFrame:: +std::future> DataFrame:: groupby2_async(const char *col_name1, const char *col_name2, I_V &&idx_visitor, @@ -1365,9 +1365,9 @@ groupby2_async(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -std::future> DataFrame:: +std::future> DataFrame:: groupby3_async(const char *col_name1, const char *col_name2, const char *col_name3, @@ -1386,10 +1386,10 @@ groupby3_async(const char *col_name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::value_counts (const char *col_name) const { +DataFrame> +DataFrame::value_counts (const char *col_name) const { const ColumnVecType &vec = get_column(col_name); auto hash_func = @@ -1437,7 +1437,7 @@ DataFrame::value_counts (const char *col_name) const { counts.emplace_back(nan_count); } - DataFrame result_df; + DataFrame> result_df; result_df.load_index(std::move(res_indices)); result_df.load_column("counts", std::move(counts)); @@ -1447,19 +1447,19 @@ DataFrame::value_counts (const char *col_name) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::value_counts(size_type index) const { +DataFrame> +DataFrame::value_counts(size_type index) const { return (value_counts(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: bucketize(bucket_type bt, const V &value, I_V &&idx_visitor, @@ -1485,10 +1485,10 @@ bucketize(bucket_type bt, // ---------------------------------------------------------------------------- -template +template template -std::future> -DataFrame:: +std::future> +DataFrame:: bucketize_async(bucket_type bt, const V &value, I_V &&idx_visitor, @@ -1505,9 +1505,9 @@ bucketize_async(bucket_type bt, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: transpose(IndexVecType &&indices, const V &new_col_names) const { const size_type num_cols = column_list_.size(); diff --git a/include/DataFrame/Internals/DataFrame_functors.h b/include/DataFrame/Internals/DataFrame_functors.h index 580135841..32609b7d4 100644 --- a/include/DataFrame/Internals/DataFrame_functors.h +++ b/include/DataFrame/Internals/DataFrame_functors.h @@ -442,11 +442,11 @@ struct drop_missing_rows_functor_ : template struct get_row_functor_ : DataVec::template visitor_base { - inline get_row_functor_ (HeteroVector &r, size_type rn) + inline get_row_functor_ (HeteroVector &r, size_type rn) : result(r), row_num(rn) { } - HeteroVector &result; - const size_type row_num; + HeteroVector &result; + const size_type row_num; template void operator() (const T &vec); diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index c2f3f574e..e18f6f082 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -40,19 +40,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template -std::pair::size_type, - typename DataFrame::size_type> -DataFrame::shape() const { +template +std::pair::size_type, + typename DataFrame::size_type> +DataFrame::shape() const { return (std::make_pair(indices_.size(), column_list_.size())); } // ---------------------------------------------------------------------------- -template +template template -MemUsage DataFrame::get_memory_usage(const char *col_name) const { +MemUsage DataFrame::get_memory_usage(const char *col_name) const { MemUsage result; @@ -68,9 +68,9 @@ MemUsage DataFrame::get_memory_usage(const char *col_name) const { // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type -DataFrame::col_name_to_idx (const char *col_name) const { +template +typename DataFrame::size_type +DataFrame::col_name_to_idx (const char *col_name) const { for (const auto &citer : column_list_) if (citer.first == col_name) @@ -86,9 +86,9 @@ DataFrame::col_name_to_idx (const char *col_name) const { // ---------------------------------------------------------------------------- -template +template const char * -DataFrame::col_idx_to_name (size_type col_idx) const { +DataFrame::col_idx_to_name (size_type col_idx) const { for (const auto &citer : column_list_) if (citer.second == col_idx) @@ -109,10 +109,10 @@ DataFrame::col_idx_to_name (size_type col_idx) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::template ColumnVecType & -DataFrame::get_column (const char *name) { +typename DataFrame::template ColumnVecType & +DataFrame::get_column (const char *name) { auto iter = column_tb_.find (name); @@ -134,28 +134,28 @@ DataFrame::get_column (const char *name) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::template ColumnVecType & -DataFrame::get_column () { +typename DataFrame::template ColumnVecType & +DataFrame::get_column () { return (get_column(T::name)); } // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::template ColumnVecType & -DataFrame::get_column(size_type index) { +typename DataFrame::template ColumnVecType & +DataFrame::get_column(size_type index) { return (get_column(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template -bool DataFrame::has_column (const char *name) const { +template +bool DataFrame::has_column (const char *name) const { auto iter = column_tb_.find (name); @@ -164,26 +164,26 @@ bool DataFrame::has_column (const char *name) const { // ---------------------------------------------------------------------------- -template -bool DataFrame:: +template +bool DataFrame:: has_column(size_type index) const { return (index < column_list_.size()); } // ---------------------------------------------------------------------------- -template +template template -const typename DataFrame::template ColumnVecType & -DataFrame::get_column (const char *name) const { +const typename DataFrame::template ColumnVecType & +DataFrame::get_column (const char *name) const { return (const_cast(this)->get_column(name)); } // ---------------------------------------------------------------------------- -template +template template -const typename DataFrame::template ColumnVecType & -DataFrame::get_column () const { +const typename DataFrame::template ColumnVecType & +DataFrame::get_column () const { return (const_cast(this)->get_column( T::name)); @@ -191,31 +191,31 @@ DataFrame::get_column () const { // ---------------------------------------------------------------------------- -template +template template -const typename DataFrame::template ColumnVecType & -DataFrame::get_column(size_type index) const { +const typename DataFrame::template ColumnVecType & +DataFrame::get_column(size_type index) const { return (get_column(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template -const typename DataFrame::IndexVecType & -DataFrame::get_index() const { return (indices_); } +template +const typename DataFrame::IndexVecType & +DataFrame::get_index() const { return (indices_); } // ---------------------------------------------------------------------------- -template -typename DataFrame::IndexVecType & -DataFrame::get_index() { return (indices_); } +template +typename DataFrame::IndexVecType & +DataFrame::get_index() { return (indices_); } // ---------------------------------------------------------------------------- -template +template template -HeteroVector DataFrame:: +HeteroVector DataFrame:: get_row(size_type row_num, const std::vector &col_names) const { if (row_num >= indices_.size()) { @@ -232,9 +232,9 @@ get_row(size_type row_num, const std::vector &col_names) const { throw BadRange(buffer); } - HeteroVector ret_vec; + HeteroVector ret_vec; - ret_vec.reserve(1); + ret_vec.template reserve(1); ret_vec.push_back(indices_[row_num]); get_row_functor_ functor(ret_vec, row_num); @@ -260,9 +260,9 @@ get_row(size_type row_num, const std::vector &col_names) const { // ---------------------------------------------------------------------------- -template +template template -HeteroVector DataFrame:: +HeteroVector DataFrame:: get_row(size_type row_num) const { if (row_num >= indices_.size()) { @@ -279,9 +279,9 @@ get_row(size_type row_num) const { throw BadRange(buffer); } - HeteroVector ret_vec; + HeteroVector ret_vec; - ret_vec.reserve(1); + ret_vec.template reserve(1); ret_vec.push_back(indices_[row_num]); get_row_functor_ functor(ret_vec, row_num); @@ -295,9 +295,9 @@ get_row(size_type row_num) const { // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: get_col_unique_values(const char *name) const { const ColumnVecType &vec = get_column(name); @@ -337,10 +337,10 @@ get_col_unique_values(const char *name) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::get_data_by_idx (Index2D range) const { +DataFrame +DataFrame::get_data_by_idx (Index2D range) const { const auto &lower = std::lower_bound (indices_.begin(), indices_.end(), range.begin); @@ -373,9 +373,9 @@ DataFrame::get_data_by_idx (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_idx(const std::vector &values) const { const std::unordered_set val_table(values.begin(), values.end()); @@ -411,12 +411,12 @@ get_data_by_idx(const std::vector &values) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::View -DataFrame::get_view_by_idx (Index2D range) { +typename DataFrame::View +DataFrame::get_view_by_idx (Index2D range) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); auto lower = @@ -454,12 +454,12 @@ DataFrame::get_view_by_idx (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstView -DataFrame::get_view_by_idx (Index2D range) const { +typename DataFrame::ConstView +DataFrame::get_view_by_idx (Index2D range) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); auto lower = @@ -498,12 +498,12 @@ DataFrame::get_view_by_idx (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_idx(const std::vector &values) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); using TheView = PtrView; @@ -545,13 +545,13 @@ get_view_by_idx(const std::vector &values) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_idx(const std::vector &values) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); using TheView = ConstPtrView; @@ -593,10 +593,10 @@ get_view_by_idx(const std::vector &values) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::get_data_by_loc (Index2D range) const { +DataFrame +DataFrame::get_data_by_loc (Index2D range) const { if (range.begin < 0) range.begin = static_cast(indices_.size()) + range.begin; @@ -635,9 +635,9 @@ DataFrame::get_data_by_loc (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_loc (const std::vector &locations) const { const size_type idx_s = indices_.size(); @@ -669,12 +669,12 @@ get_data_by_loc (const std::vector &locations) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::View -DataFrame::get_view_by_loc (Index2D range) { +typename DataFrame::View +DataFrame::get_view_by_loc (Index2D range) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); const long idx_s = static_cast(indices_.size()); @@ -717,12 +717,12 @@ DataFrame::get_view_by_loc (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstView -DataFrame::get_view_by_loc (Index2D range) const { +typename DataFrame::ConstView +DataFrame::get_view_by_loc (Index2D range) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); const long idx_s = static_cast(indices_.size()); @@ -765,12 +765,12 @@ DataFrame::get_view_by_loc (Index2D range) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView -DataFrame::get_view_by_loc (const std::vector &locations) { +typename DataFrame::PtrView +DataFrame::get_view_by_loc (const std::vector &locations) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); using TheView = PtrView; @@ -805,13 +805,13 @@ DataFrame::get_view_by_loc (const std::vector &locations) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_loc (const std::vector &locations) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); using TheView = ConstPtrView; @@ -846,9 +846,9 @@ get_view_by_loc (const std::vector &locations) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (const char *name, F &sel_functor) const { const ColumnVecType &vec = get_column(name); @@ -885,12 +885,12 @@ get_data_by_sel (const char *name, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel (const char *name, F &sel_functor) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec = get_column(name); @@ -929,13 +929,13 @@ get_view_by_sel (const char *name, F &sel_functor) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_sel (const char *name, F &sel_functor) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec = get_column(name); @@ -974,9 +974,9 @@ get_view_by_sel (const char *name, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { const size_type idx_s = indices_.size(); @@ -1021,12 +1021,12 @@ get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1073,13 +1073,13 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1126,9 +1126,9 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (const char *name1, const char *name2, const char *name3, @@ -1179,9 +1179,9 @@ get_data_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (F &sel_functor) const { const size_type idx_s = indices_.size(); @@ -1244,9 +1244,9 @@ get_data_by_sel (F &sel_functor) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { const size_type idx_s = indices_.size(); @@ -1307,15 +1307,15 @@ get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel (const char *name1, const char *name2, const char *name3, F &sel_functor) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1365,16 +1365,16 @@ get_view_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_sel (const char *name1, const char *name2, const char *name3, F &sel_functor) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1424,10 +1424,10 @@ get_view_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel(const char *name1, const char *name2, const char *name3, @@ -1483,17 +1483,17 @@ get_data_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, const char *name4, F &sel_functor) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1547,18 +1547,18 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, const char *name4, F &sel_functor) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1612,10 +1612,10 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_sel(const char *name1, const char *name2, const char *name3, @@ -1676,10 +1676,10 @@ get_data_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1687,7 +1687,7 @@ get_view_by_sel(const char *name1, const char *name5, F &sel_functor) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1745,11 +1745,11 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_sel(const char *name1, const char *name2, const char *name3, @@ -1757,7 +1757,7 @@ get_view_by_sel(const char *name1, const char *name5, F &sel_functor) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_sel()"); const ColumnVecType &vec1 = get_column(name1); @@ -1815,9 +1815,9 @@ get_view_by_sel(const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data_by_rand(random_policy spec, double n, size_type seed) const { bool use_seed = false; @@ -1889,9 +1889,9 @@ get_data_by_rand(random_policy spec, double n, size_type seed) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView DataFrame:: +typename DataFrame::PtrView DataFrame:: get_view_by_rand (random_policy spec, double n, size_type seed) { bool use_seed = false; @@ -1963,10 +1963,10 @@ get_view_by_rand (random_policy spec, double n, size_type seed) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame:: +typename DataFrame::ConstPtrView +DataFrame:: get_view_by_rand (random_policy spec, double n, size_type seed) const { bool use_seed = false; @@ -2039,9 +2039,9 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: get_data(const std::vector &col_names) const { DataFrame df; @@ -2071,12 +2071,12 @@ get_data(const std::vector &col_names) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::View DataFrame:: +typename DataFrame::View DataFrame:: get_view(const std::vector &col_names) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view()"); View dfv; @@ -2111,13 +2111,13 @@ get_view(const std::vector &col_names) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstView -DataFrame:: +typename DataFrame::ConstView +DataFrame:: get_view(const std::vector &col_names) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view()"); ConstView dfcv; @@ -2153,14 +2153,15 @@ get_view(const std::vector &col_names) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> DataFrame:: get_reindexed(const char *col_to_be_index, const char *old_index_name) const { - DataFrame result; - const auto &new_idx = get_column(col_to_be_index); - const size_type new_idx_s = + DataFrame> result; + const auto &new_idx = + get_column(col_to_be_index); + const size_type new_idx_s = result.load_index(new_idx.begin(), new_idx.end()); if (old_index_name) { @@ -2175,12 +2176,12 @@ get_reindexed(const char *col_to_be_index, const char *old_index_name) const { for (const auto &citer : column_list_) { if (citer.first == col_to_be_index) continue; - load_functor_, Ts ...> functor ( - citer.first.c_str(), - 0, - new_idx_s, - result, - nan_policy::dont_pad_with_nans); + load_functor_>, Ts ...> + functor (citer.first.c_str(), + 0, + new_idx_s, + result, + nan_policy::dont_pad_with_nans); const SpinGuard guard(lock_); data_[citer.second].change(functor); @@ -2191,15 +2192,15 @@ get_reindexed(const char *col_to_be_index, const char *old_index_name) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::View DataFrame:: +typename DataFrame::View DataFrame:: get_reindexed_view(const char *col_to_be_index, const char *old_index_name) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_reindexed_view()"); - using TheView = typename DataFrame::View; + using TheView = typename DataFrame::View; TheView result; auto &new_idx = get_column(col_to_be_index); @@ -2236,17 +2237,17 @@ get_reindexed_view(const char *col_to_be_index, const char *old_index_name) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstView -DataFrame:: +typename DataFrame::ConstView +DataFrame:: get_reindexed_view(const char *col_to_be_index, const char *old_index_name) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_reindexed_view()"); - using TheView = typename DataFrame::ConstView; + using TheView = typename DataFrame::ConstView; TheView result; const auto &new_idx = get_column(col_to_be_index); @@ -2284,12 +2285,12 @@ get_reindexed_view(const char *col_to_be_index, // ---------------------------------------------------------------------------- -template +template template -std::vector::ColNameType, - typename DataFrame::size_type, +std::vector::ColNameType, + typename DataFrame::size_type, std::type_index>> -DataFrame::get_columns_info () const { +DataFrame::get_columns_info () const { std::vector> result; @@ -2308,12 +2309,12 @@ DataFrame::get_columns_info () const { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::describe() const { +DataFrame> +DataFrame::describe() const { - DataFrame result; + DataFrame> result; result.load_index(describe_index_col.begin(), describe_index_col.end()); @@ -2329,9 +2330,9 @@ DataFrame::describe() const { // ---------------------------------------------------------------------------- -template +template template -bool DataFrame:: +bool DataFrame:: pattern_match(const char *col_name, pattern_spec pattern, double epsilon) const { @@ -2361,9 +2362,9 @@ pattern_match(const char *col_name, // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: combine(const char *col_name, const DF &rhs, F &functor) const { const auto &lhs_col = get_column(col_name); @@ -2380,9 +2381,9 @@ combine(const char *col_name, const DF &rhs, F &functor) const { // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2405,9 +2406,9 @@ combine(const char *col_name, // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index 8eee26cb0..9fdf4f9e4 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -36,13 +36,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -DataFrame DataFrame:: +DataFrame> +DataFrame:: join_by_index (const RHS_T &rhs, join_policy mp) const { static_assert( - std::is_base_of, RHS_T>::value || + std::is_base_of>, + RHS_T>::value || std::is_base_of::value || std::is_base_of::value, "The rhs argument to join_by_index() can only be " @@ -93,13 +95,17 @@ join_by_index (const RHS_T &rhs, join_policy mp) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> +DataFrame:: join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { static_assert( - std::is_base_of, RHS_T>::value || + std::is_base_of< + DataFrame>, + RHS_T>::value || std::is_base_of::value || std::is_base_of::value, "The rhs argument to join_by_column() can only be " @@ -151,14 +157,15 @@ join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: -join_helper_common_(const LHS_T &lhs, - const RHS_T &rhs, - const IndexIdxVector &joined_index_idx, - DataFrame &result, - const char *skip_col_name) { +void DataFrame:: +join_helper_common_( + const LHS_T &lhs, + const RHS_T &rhs, + const IndexIdxVector &joined_index_idx, + DataFrame> &result, + const char *skip_col_name) { // Load the common and lhs columns for (const auto &iter : lhs.column_list_) { @@ -207,15 +214,15 @@ join_helper_common_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> DataFrame:: index_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx) { - DataFrame result; - std::vector result_index; + DataFrame> result; + std::vector result_index; // Load the index result_index.reserve(joined_index_idx.size()); @@ -235,9 +242,10 @@ index_join_helper_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> +DataFrame:: column_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -246,12 +254,14 @@ column_join_helper_(const LHS_T &lhs, using left_idx_t = typename std::remove_reference::type::IndexType; using right_idx_t = typename std::remove_reference::type::IndexType; - const size_type jii_s = joined_index_idx.size(); - DataFrame result; + const size_type jii_s = + joined_index_idx.size(); + DataFrame> result; // Load the new result index result.load_index( - DataFrame::gen_sequence_index( + DataFrame>::gen_sequence_index( 0, static_cast(jii_s), 1)); // Load the lhs and rhs indices into two columns in the result @@ -300,10 +310,10 @@ column_join_helper_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_inner_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_inner_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -333,9 +343,9 @@ DataFrame::get_inner_index_idx_vector_( // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> DataFrame:: index_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -347,9 +357,10 @@ index_inner_join_(const LHS_T &lhs, const RHS_T &rhs, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> +DataFrame:: column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -363,10 +374,10 @@ column_inner_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_left_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_left_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -404,9 +415,9 @@ DataFrame::get_left_index_idx_vector_( } // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> DataFrame:: index_left_join_(const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -418,9 +429,10 @@ index_left_join_(const LHS_T &lhs, const RHS_T &rhs, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> +DataFrame:: column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -434,10 +446,10 @@ column_left_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_right_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_right_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -479,9 +491,9 @@ DataFrame::get_right_index_idx_vector_( // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> DataFrame:: index_right_join_(const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -493,9 +505,9 @@ index_right_join_(const LHS_T &lhs, const RHS_T &rhs, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> DataFrame:: column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -509,10 +521,10 @@ column_right_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::IndexIdxVector -DataFrame::get_left_right_index_idx_vector_( +typename DataFrame::IndexIdxVector +DataFrame::get_left_right_index_idx_vector_( const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs) { @@ -561,9 +573,9 @@ DataFrame::get_left_right_index_idx_vector_( // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> DataFrame:: index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, @@ -577,9 +589,10 @@ index_left_right_join_( // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame> +DataFrame:: column_left_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -593,9 +606,9 @@ column_left_right_join_(const LHS_T &lhs, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns) { const size_type orig_index_s = lhs.get_index().size(); @@ -637,16 +650,20 @@ concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns) { // ---------------------------------------------------------------------------- -template +template template void -DataFrame::self_concat(const RHS_T &rhs, bool add_new_columns) { +DataFrame::self_concat(const RHS_T &rhs, bool add_new_columns) { static_assert( - (std::is_base_of, RHS_T>::value || + (std::is_base_of< + DataFrame>, + RHS_T>::value || std::is_base_of::value || std::is_base_of::value) && - ! std::is_base_of, + ! std::is_base_of>, decltype(*this)>::value, "The rhs argument to self_concat() can only be " "StdDataFrame or DataFrame[Ptr]View. " @@ -657,22 +674,26 @@ DataFrame::self_concat(const RHS_T &rhs, bool add_new_columns) { // ---------------------------------------------------------------------------- -template +template template -DataFrame -DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { +DataFrame> +DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { static_assert( - (std::is_base_of, RHS_T>::value || + (std::is_base_of< + DataFrame>, + RHS_T>::value || std::is_base_of::value || std::is_base_of::value) && - ! std::is_base_of, + ! std::is_base_of>, decltype(*this)>::value, "The rhs argument to concat() can only be " "StdDataFrame or DataFrame[Ptr]View. " "Self must be StdDataFrame"); - DataFrame result; + DataFrame> result; if (cp == concat_policy::all_columns || cp == concat_policy::lhs_and_common_columns) { @@ -700,14 +721,18 @@ DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::PtrView -DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { +typename DataFrame::PtrView +DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { static_assert( - ! std::is_base_of, RHS_T>::value || - ! std::is_base_of, + ! std::is_base_of< + DataFrame>, + RHS_T>::value || + ! std::is_base_of>, decltype(*this)>::value, "Currently, arguments to concat_view() can only be " "StdDataFrame."); @@ -774,14 +799,18 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::ConstPtrView -DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { +typename DataFrame::ConstPtrView +DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { static_assert( - ! std::is_base_of, RHS_T>::value || - ! std::is_base_of, + ! std::is_base_of< + DataFrame>, + RHS_T>::value || + ! std::is_base_of>, decltype(*this)>::value, "Currently, arguments to concat_view() can only be " "StdDataFrame."); diff --git a/include/DataFrame/Internals/DataFrame_misc.tcc b/include/DataFrame/Internals/DataFrame_misc.tcc index 8e90e3233..b8b1bd3a2 100644 --- a/include/DataFrame/Internals/DataFrame_misc.tcc +++ b/include/DataFrame/Internals/DataFrame_misc.tcc @@ -39,11 +39,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template template void -DataFrame::consistent_functor_::operator() (T &vec) const { +DataFrame::consistent_functor_::operator() (T &vec) const { using ValueType = typename std::remove_reference::type::value_type; @@ -53,11 +53,11 @@ DataFrame::consistent_functor_::operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::shrink_to_fit_functor_::operator() (T &vec) const { +DataFrame::shrink_to_fit_functor_::operator() (T &vec) const { using value_type = typename T::value_type; @@ -71,11 +71,11 @@ DataFrame::shrink_to_fit_functor_::operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::sort_functor_::operator() (T2 &vec) { +DataFrame::sort_functor_::operator() (T2 &vec) { sorted_idxs_copy = sorted_idxs; _sort_by_sorted_index_(vec, sorted_idxs_copy, idx_s); @@ -84,11 +84,11 @@ DataFrame::sort_functor_::operator() (T2 &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::load_functor_::operator() (const T &vec) { +DataFrame::load_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -103,11 +103,11 @@ DataFrame::load_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::load_all_functor_::operator() (const T &vec) { +DataFrame::load_all_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -119,11 +119,11 @@ DataFrame::load_all_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::remove_functor_::operator() (T &vec) { +DataFrame::remove_functor_::operator() (T &vec) { vec.erase(vec.begin() + begin, vec.begin() + end); return; @@ -131,11 +131,11 @@ DataFrame::remove_functor_::operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::view_setup_functor_:: +DataFrame::view_setup_functor_:: operator() (T &vec) { using VecType = typename std::remove_reference::type; @@ -151,11 +151,11 @@ operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::add_col_functor_::operator() (const T &) { +DataFrame::add_col_functor_::operator() (const T &) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -166,11 +166,11 @@ DataFrame::add_col_functor_::operator() (const T &) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::print_csv_functor_::operator() (const T &vec) { +DataFrame::print_csv_functor_::operator() (const T &vec) { if (vec.empty()) return; @@ -222,11 +222,11 @@ DataFrame::print_csv_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::print_json_functor_::operator() (const T &vec) { +DataFrame::print_json_functor_::operator() (const T &vec) { if (vec.empty()) return; @@ -285,10 +285,10 @@ DataFrame::print_json_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame:: +void DataFrame:: print_csv2_header_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; @@ -302,10 +302,10 @@ print_csv2_header_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame:: +void DataFrame:: print_csv2_data_functor_::operator() (const T &vec) { if (vec.size() > index) os << vec[index]; @@ -314,11 +314,11 @@ print_csv2_data_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: equal_functor_::operator() (const T &lhs_vec) { using VecType = typename std::remove_reference::type; @@ -342,11 +342,11 @@ equal_functor_::operator() (const T &lhs_vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: mod_by_idx_functor_::operator() (T &lhs_vec) const { using VecType = typename std::remove_reference::type; @@ -364,11 +364,11 @@ mod_by_idx_functor_::operator() (T &lhs_vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: index_join_functor_common_::operator()(const T &lhs_vec) { using VecType = typename std::remove_reference::type; @@ -403,10 +403,10 @@ index_join_functor_common_::operator()(const T &lhs_vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::index_join_functor_oneside_:: +void DataFrame::index_join_functor_oneside_:: operator()(const T &vec) { using VecType = typename std::remove_reference::type; @@ -428,10 +428,10 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::concat_functor_:: +void DataFrame::concat_functor_:: operator()(const T &vec) { using VecType = typename std::remove_reference::type; @@ -454,10 +454,10 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::vertical_shift_functor_:: +void DataFrame::vertical_shift_functor_:: operator() (T &vec) const { if (sp == shift_policy::up) @@ -468,10 +468,10 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame::rotate_functor_:: +void DataFrame::rotate_functor_:: operator() (T &vec) const { if (sp == shift_policy::up) // Rotate left @@ -484,11 +484,11 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template class OPT, typename ... Ts> template void -DataFrame:: +DataFrame:: operator_functor_:: operator()(const T &lhs_vec) { @@ -536,11 +536,11 @@ operator()(const T &lhs_vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: map_missing_rows_functor_:: operator()(const T &vec) { @@ -559,11 +559,11 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: drop_missing_rows_functor_:: operator()(T &vec) { @@ -573,15 +573,15 @@ operator()(T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: get_row_functor_:: operator()(const T &vec) { - result.reserve(1); + result.template reserve(1); if (row_num < vec.size()) result.push_back(vec[row_num]); else @@ -591,11 +591,11 @@ operator()(const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: sel_load_functor_:: operator() (const T &vec) { @@ -622,11 +622,11 @@ operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: sel_load_view_functor_:: operator() (T &vec) { @@ -661,11 +661,11 @@ operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: concat_load_view_functor_:: operator() (const T &vec) { @@ -699,11 +699,11 @@ operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: sel_remove_functor_:: operator() (T &vec) const { @@ -721,11 +721,11 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: shuffle_functor_:: operator() (T &vec) const { @@ -738,11 +738,11 @@ operator() (T &vec) const { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame:: +DataFrame:: random_load_data_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; @@ -772,10 +772,10 @@ random_load_data_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template -void DataFrame:: +void DataFrame:: random_load_view_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; @@ -812,11 +812,11 @@ random_load_view_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::columns_info_functor_::operator() (const T &vec) { +DataFrame::columns_info_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -826,11 +826,11 @@ DataFrame::columns_info_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::copy_remove_functor_::operator() (const T &vec) { +DataFrame::copy_remove_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -850,11 +850,11 @@ DataFrame::copy_remove_functor_::operator() (const T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::fill_missing_functor_::operator() (T &vec) { +DataFrame::fill_missing_functor_::operator() (T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; @@ -873,11 +873,11 @@ DataFrame::fill_missing_functor_::operator() (T &vec) { // ---------------------------------------------------------------------------- -template +template template template void -DataFrame::describe_functor_::operator() (const T &vec) { +DataFrame::describe_functor_::operator() (const T &vec) { const size_type vec_s = vec.size(); diff --git a/include/DataFrame/Internals/DataFrame_opt.tcc b/include/DataFrame/Internals/DataFrame_opt.tcc index b2081f753..df52f9e8d 100644 --- a/include/DataFrame/Internals/DataFrame_opt.tcc +++ b/include/DataFrame/Internals/DataFrame_opt.tcc @@ -36,9 +36,9 @@ namespace hmdf // ---------------------------------------------------------------------------- -template +template template -bool DataFrame::is_equal (const DataFrame &rhs) const { +bool DataFrame::is_equal (const DataFrame &rhs) const { if (column_list_.size() != rhs.column_list_.size()) return (false); @@ -63,9 +63,9 @@ bool DataFrame::is_equal (const DataFrame &rhs) const { // ---------------------------------------------------------------------------- -template +template template -DataFrame &DataFrame:: +DataFrame &DataFrame:: modify_by_idx (DataFrame &rhs, sort_state already_sorted) { if (already_sorted == sort_state::not_sorted) { diff --git a/include/DataFrame/Internals/DataFrame_private_decl.h b/include/DataFrame/Internals/DataFrame_private_decl.h index fa5dda69b..bfd5316c2 100644 --- a/include/DataFrame/Internals/DataFrame_private_decl.h +++ b/include/DataFrame/Internals/DataFrame_private_decl.h @@ -55,7 +55,7 @@ void read_csv2_(std::istream &file, bool columns_only); template static void -sort_common_(DataFrame &df, CF &&comp_func); +sort_common_(DataFrame &df, CF &&comp_func); template static void @@ -126,17 +126,19 @@ static void join_helper_common_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx, - DataFrame &result, + DataFrame< + IDX_T, + HeteroVector> &result, const char *skip_col_name = nullptr); template -static DataFrame +static DataFrame> index_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const IndexIdxVector &joined_index_idx); template -static DataFrame +static DataFrame> column_join_helper_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -149,14 +151,14 @@ get_inner_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> index_inner_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -170,14 +172,14 @@ get_left_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> index_left_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -191,14 +193,14 @@ get_right_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> index_right_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, @@ -223,14 +225,14 @@ get_left_right_index_idx_vector_( const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, const std::vector> &col_vec_lhs, const std::vector> &col_vec_rhs); template -static DataFrame +static DataFrame> column_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, diff --git a/include/DataFrame/Internals/DataFrame_read.tcc b/include/DataFrame/Internals/DataFrame_read.tcc index 0e8556357..1b35feb24 100644 --- a/include/DataFrame/Internals/DataFrame_read.tcc +++ b/include/DataFrame/Internals/DataFrame_read.tcc @@ -46,8 +46,8 @@ namespace hmdf // ---------------------------------------------------------------------------- -template -void DataFrame::read_json_(std::istream &stream, bool columns_only) { +template +void DataFrame::read_json_(std::istream &stream, bool columns_only) { char c { '\0' }; char col_name[256]; @@ -293,8 +293,8 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { // ---------------------------------------------------------------------------- -template -void DataFrame::read_csv_(std::istream &stream, bool columns_only) { +template +void DataFrame::read_csv_(std::istream &stream, bool columns_only) { char col_name[256]; char value[32]; @@ -445,8 +445,8 @@ struct _col_data_spec_ { // -------------------------------------- -template -void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { +template +void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { char value[8192]; char c; @@ -741,8 +741,8 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { // ---------------------------------------------------------------------------- -template -bool DataFrame:: +template +bool DataFrame:: read (const char *file_name, io_format iof, bool columns_only) { std::ifstream stream; @@ -762,11 +762,11 @@ read (const char *file_name, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template template -bool DataFrame::read (S &in_s, io_format iof, bool columns_only) { +bool DataFrame::read (S &in_s, io_format iof, bool columns_only) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call read()"); if (iof == io_format::csv) @@ -783,9 +783,9 @@ bool DataFrame::read (S &in_s, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template bool -DataFrame::from_string (const char *data_frame) { +DataFrame::from_string (const char *data_frame) { std::stringstream ss (std::string(data_frame), std::ios_base::in); @@ -795,8 +795,8 @@ DataFrame::from_string (const char *data_frame) { // ---------------------------------------------------------------------------- -template -std::future DataFrame:: +template +std::future DataFrame:: read_async(const char *file_name, io_format iof, bool columns_only) { return (std::async(std::launch::async, @@ -807,9 +807,9 @@ read_async(const char *file_name, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: read_async(S &in_s, io_format iof, bool columns_only) { return (std::async(std::launch::async, @@ -820,9 +820,9 @@ read_async(S &in_s, io_format iof, bool columns_only) { // ---------------------------------------------------------------------------- -template +template std::future -DataFrame::from_string_async(const char *data_frame) { +DataFrame::from_string_async(const char *data_frame) { return (std::async(std::launch::async, &DataFrame::from_string, this, data_frame)); diff --git a/include/DataFrame/Internals/DataFrame_set.tcc b/include/DataFrame/Internals/DataFrame_set.tcc index f057823d0..687799b9e 100644 --- a/include/DataFrame/Internals/DataFrame_set.tcc +++ b/include/DataFrame/Internals/DataFrame_set.tcc @@ -38,11 +38,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -std::vector &DataFrame::create_column (const char *name) { +std::vector &DataFrame::create_column (const char *name) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call create_column()"); if (! ::strcmp(name, DF_INDEX_COL_NAME)) @@ -69,10 +69,10 @@ std::vector &DataFrame::create_column (const char *name) { // ---------------------------------------------------------------------------- -template -void DataFrame::remove_column (const char *name) { +template +void DataFrame::remove_column (const char *name) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call remove_column()"); if (! ::strcmp(name, DF_INDEX_COL_NAME)) @@ -106,18 +106,18 @@ void DataFrame::remove_column (const char *name) { // ---------------------------------------------------------------------------- -template -void DataFrame::remove_column(size_type index) { +template +void DataFrame::remove_column(size_type index) { return (remove_column(column_list_[index].first.c_str())); } // ---------------------------------------------------------------------------- -template -void DataFrame::rename_column (const char *from, const char *to) { +template +void DataFrame::rename_column (const char *from, const char *to) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call rename_column()"); if (! ::strcmp(from, DF_INDEX_COL_NAME) || @@ -153,13 +153,13 @@ void DataFrame::rename_column (const char *from, const char *to) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: retype_column (const char *name, std::function convert_func) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call retype_column()"); if (! ::strcmp(name, DF_INDEX_COL_NAME)) @@ -179,12 +179,12 @@ retype_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::load_data (IndexVecType &&indices, Ts&& ... args) { +typename DataFrame::size_type +DataFrame::load_data (IndexVecType &&indices, Ts&& ... args) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call load_data()"); size_type cnt = load_index(std::forward(indices)); @@ -204,12 +204,12 @@ DataFrame::load_data (IndexVecType &&indices, Ts&& ... args) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::load_index(const ITR &begin, const ITR &end) { +typename DataFrame::size_type +DataFrame::load_index(const ITR &begin, const ITR &end) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call load_index()"); indices_.clear(); @@ -219,11 +219,11 @@ DataFrame::load_index(const ITR &begin, const ITR &end) { // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type -DataFrame::load_index(IndexVecType &&idx) { +template +typename DataFrame::size_type +DataFrame::load_index(IndexVecType &&idx) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call load_index()"); indices_ = idx; @@ -232,8 +232,8 @@ DataFrame::load_index(IndexVecType &&idx) { // ---------------------------------------------------------------------------- -template -std::vector DataFrame:: +template +std::vector DataFrame:: gen_datetime_index(const char *start_datetime, const char *end_datetime, time_frequency t_freq, @@ -290,8 +290,8 @@ gen_datetime_index(const char *start_datetime, // ---------------------------------------------------------------------------- -template -std::vector DataFrame:: +template +std::vector DataFrame:: gen_sequence_index (const IndexType &start_value, const IndexType &end_value, long increment) { @@ -308,12 +308,12 @@ gen_sequence_index (const IndexType &start_value, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::append_index(Index2D range) { +typename DataFrame::size_type +DataFrame::append_index(Index2D range) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call append_index()"); const size_type s = std::distance(range.begin, range.end); @@ -324,11 +324,11 @@ DataFrame::append_index(Index2D range) { // ---------------------------------------------------------------------------- -template -typename DataFrame::size_type -DataFrame::append_index(const IndexType &val) { +template +typename DataFrame::size_type +DataFrame::append_index(const IndexType &val) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call append_index()"); indices_.push_back (val); @@ -337,10 +337,10 @@ DataFrame::append_index(const IndexType &val) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_column (const char *name, Index2D range, nan_policy padding) { @@ -392,10 +392,10 @@ load_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_result_as_column(V &visitor, const char *name, nan_policy padding) { const size_type idx_s = indices_.size(); @@ -444,10 +444,10 @@ load_result_as_column(V &visitor, const char *name, nan_policy padding) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_indicators(const char *cat_col_name, const char *numeric_cols_prefix) { using map_t = std::unordered_map *>; @@ -482,10 +482,10 @@ load_indicators(const char *cat_col_name, const char *numeric_cols_prefix) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: from_indicators(const std::vector &ind_col_names, const char *cat_col_name, const char *numeric_cols_prefixg) { @@ -515,17 +515,18 @@ from_indicators(const std::vector &ind_col_names, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: setup_view_column_ (const char *name, Index2D range) { - static_assert(std::is_base_of::value || - std::is_base_of::value || - std::is_base_of::value || - std::is_base_of::value, - "Only a DataFrameView or DataFramePtrView can " - "call setup_view_column_()"); + static_assert( + std::is_base_of, DataVec>::value || + std::is_base_of, DataVec>::value || + std::is_base_of, DataVec>::value || + std::is_base_of, DataVec>::value, + "Only a DataFrameView or DataFramePtrView can " + "call setup_view_column_()"); DataVec dv; @@ -542,10 +543,10 @@ setup_view_column_ (const char *name, Index2D range) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_column (const char *name, std::vector &&column, nan_policy padding) { const size_type idx_s = indices_.size(); @@ -592,10 +593,10 @@ load_column (const char *name, std::vector &&column, nan_policy padding) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_align_column( const char *name, std::vector &&column, @@ -650,10 +651,10 @@ load_align_column( // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: load_column (const char *name, const std::vector &data, nan_policy padding) { @@ -663,10 +664,10 @@ load_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::load_pair_(std::pair &col_name_data) { +typename DataFrame::size_type +DataFrame::load_pair_(std::pair &col_name_data) { return (load_column( col_name_data.first, // column name @@ -676,10 +677,10 @@ DataFrame::load_pair_(std::pair &col_name_data) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: append_column (const char *name, Index2D range, nan_policy padding) { @@ -719,10 +720,10 @@ append_column (const char *name, // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame:: +typename DataFrame::size_type +DataFrame:: append_column (const char *name, const T &val, nan_policy padding) { std::vector &vec = get_column(name); @@ -760,10 +761,10 @@ append_column (const char *name, const T &val, nan_policy padding) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::append_row_(std::pair &row_name_data) { +typename DataFrame::size_type +DataFrame::append_row_(std::pair &row_name_data) { return (append_column(row_name_data.first, // column name std::forward(row_name_data.second), @@ -772,12 +773,12 @@ DataFrame::append_row_(std::pair &row_name_data) { // ---------------------------------------------------------------------------- -template +template template -typename DataFrame::size_type -DataFrame::append_row (IndexType *idx_val, Ts&& ... args) { +typename DataFrame::size_type +DataFrame::append_row (IndexType *idx_val, Ts&& ... args) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call append_row()"); if (idx_val) @@ -798,11 +799,11 @@ DataFrame::append_row (IndexType *idx_val, Ts&& ... args) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::remove_data_by_idx (Index2D range) { +void DataFrame::remove_data_by_idx (Index2D range) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call remove_data_by_idx()"); const auto &lower = @@ -831,11 +832,11 @@ void DataFrame::remove_data_by_idx (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::remove_data_by_loc (Index2D range) { +void DataFrame::remove_data_by_loc (Index2D range) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call remove_data_by_loc()"); if (range.begin < 0) @@ -871,11 +872,11 @@ void DataFrame::remove_data_by_loc (Index2D range) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) { +void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call remove_data_by_loc()"); const ColumnVecType &vec = get_column(name); @@ -905,9 +906,9 @@ void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: remove_data_by_sel (const char *name1, const char *name2, F &sel_functor) { const ColumnVecType &vec1 = get_column(name1); @@ -946,9 +947,9 @@ remove_data_by_sel (const char *name1, const char *name2, F &sel_functor) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: remove_data_by_sel (const char *name1, const char *name2, const char *name3, @@ -993,9 +994,9 @@ remove_data_by_sel (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_dups_common_(const DataFrame &s_df, remove_dup_spec rds, const MAP &row_table, @@ -1056,9 +1057,9 @@ remove_dups_common_(const DataFrame &s_df, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name, bool include_index, remove_dup_spec rds) const { @@ -1091,9 +1092,9 @@ remove_duplicates (const char *name, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, bool include_index, @@ -1129,9 +1130,9 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1171,9 +1172,9 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1217,10 +1218,10 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1267,11 +1268,11 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: remove_duplicates (const char *name1, const char *name2, const char *name3, @@ -1322,16 +1323,16 @@ remove_duplicates (const char *name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *new_col_name, F &functor, bool delete_old_cols) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call consolidate()"); const ColumnVecType &vec1 = get_column(old_col_name1); @@ -1351,10 +1352,10 @@ consolidate(const char *old_col_name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, @@ -1362,7 +1363,7 @@ consolidate(const char *old_col_name1, F &functor, bool delete_old_cols) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call consolidate()"); const ColumnVecType &vec1 = get_column(old_col_name1); @@ -1385,10 +1386,10 @@ consolidate(const char *old_col_name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, @@ -1397,7 +1398,7 @@ consolidate(const char *old_col_name1, F &functor, bool delete_old_cols) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call consolidate()"); const ColumnVecType &vec1 = get_column(old_col_name1); @@ -1423,11 +1424,11 @@ consolidate(const char *old_col_name1, // ---------------------------------------------------------------------------- -template +template template -void DataFrame:: +void DataFrame:: consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, @@ -1437,7 +1438,7 @@ consolidate(const char *old_col_name1, F &functor, bool delete_old_cols) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call consolidate()"); const ColumnVecType &vec1 = get_column(old_col_name1); diff --git a/include/DataFrame/Internals/DataFrame_shift.tcc b/include/DataFrame/Internals/DataFrame_shift.tcc index c3f10e205..e79e5f43f 100644 --- a/include/DataFrame/Internals/DataFrame_shift.tcc +++ b/include/DataFrame/Internals/DataFrame_shift.tcc @@ -37,11 +37,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -void DataFrame::self_shift(size_type periods, shift_policy sp) { +void DataFrame::self_shift(size_type periods, shift_policy sp) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call self_shift()"); if (periods > 0) { @@ -87,12 +87,12 @@ void DataFrame::self_shift(size_type periods, shift_policy sp) { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: shift(size_type periods, shift_policy sp) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call shift()"); DataFrame slug = *this; @@ -103,12 +103,12 @@ shift(size_type periods, shift_policy sp) const { // ---------------------------------------------------------------------------- -template +template template -std::vector DataFrame:: +std::vector DataFrame:: shift(const char *col_name, size_type periods, shift_policy sp) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call shift()"); std::vector result = get_column(col_name); @@ -120,11 +120,11 @@ shift(const char *col_name, size_type periods, shift_policy sp) const { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::self_rotate(size_type periods, shift_policy sp) { +void DataFrame::self_rotate(size_type periods, shift_policy sp) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call self_rotate()"); if (periods > 0) { @@ -171,12 +171,12 @@ void DataFrame::self_rotate(size_type periods, shift_policy sp) { // ---------------------------------------------------------------------------- -template +template template -DataFrame DataFrame:: +DataFrame DataFrame:: rotate(size_type periods, shift_policy sp) const { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call rotate()"); StdDataFrame slug = *this; diff --git a/include/DataFrame/Internals/DataFrame_visit.tcc b/include/DataFrame/Internals/DataFrame_visit.tcc index e33a6c4ec..24c70a3da 100644 --- a/include/DataFrame/Internals/DataFrame_visit.tcc +++ b/include/DataFrame/Internals/DataFrame_visit.tcc @@ -35,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -void DataFrame::multi_visit (Ts ... args) { +void DataFrame::multi_visit (Ts ... args) { auto args_tuple = std::tuple(args ...); auto fc = [this](auto &pa) mutable -> void { @@ -59,18 +59,18 @@ void DataFrame::multi_visit (Ts ... args) { // ---------------------------------------------------------------------------- -template +template template -void DataFrame::multi_visit(Ts ... args) const { +void DataFrame::multi_visit(Ts ... args) const { const_cast(this)->multi_visit(args ...); } // ---------------------------------------------------------------------------- -template +template template -V &DataFrame::visit (const char *name, V &visitor, bool in_reverse) { +V &DataFrame::visit (const char *name, V &visitor, bool in_reverse) { auto &vec = get_column(name); const size_type idx_s = indices_.size(); @@ -101,9 +101,9 @@ V &DataFrame::visit (const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name, V &visitor, bool in_reverse) const { return (const_cast(this)->visit @@ -112,9 +112,9 @@ visit (const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name, V &visitor, bool in_reverse) { return (std::async(std::launch::async, @@ -128,9 +128,9 @@ visit_async(const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name, V &visitor, bool in_reverse) const { return (std::async(std::launch::async, @@ -146,9 +146,9 @@ visit_async(const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, V &visitor, bool in_reverse) { auto &vec1 = get_column(name1); @@ -190,9 +190,9 @@ visit (const char *name1, const char *name2, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, V &visitor, @@ -204,9 +204,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, V &visitor, @@ -225,9 +225,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, V &visitor, @@ -249,9 +249,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -304,9 +304,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -319,9 +319,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -346,9 +346,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -373,9 +373,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -435,9 +435,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -451,9 +451,9 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -481,9 +481,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -511,10 +511,10 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -582,10 +582,10 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: visit (const char *name1, const char *name2, const char *name3, @@ -600,10 +600,10 @@ visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -634,10 +634,10 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: visit_async(const char *name1, const char *name2, const char *name3, @@ -668,9 +668,9 @@ visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name, V &visitor, bool in_reverse) { auto &vec = get_column(name); @@ -687,9 +687,9 @@ single_act_visit (const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name, V &visitor, bool in_reverse) const { return (const_cast(this)->single_act_visit @@ -698,9 +698,9 @@ single_act_visit (const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name, V &visitor, bool in_reverse) { return (std::async( @@ -715,9 +715,9 @@ single_act_visit_async(const char *name, V &visitor, bool in_reverse) { // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name, V &visitor, bool in_reverse) const { return (std::async( @@ -732,9 +732,9 @@ single_act_visit_async(const char *name, V &visitor, bool in_reverse) const { // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, V &visitor, @@ -759,9 +759,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, V &visitor, @@ -780,9 +780,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, V &visitor, @@ -794,9 +794,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, V &visitor, @@ -818,9 +818,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -849,9 +849,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -864,9 +864,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -891,9 +891,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -918,9 +918,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -953,9 +953,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -969,9 +969,9 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -999,9 +999,9 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -1029,10 +1029,10 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -1069,10 +1069,10 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -V &DataFrame:: +V &DataFrame:: single_act_visit (const char *name1, const char *name2, const char *name3, @@ -1088,10 +1088,10 @@ single_act_visit (const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, @@ -1122,10 +1122,10 @@ single_act_visit_async(const char *name1, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: single_act_visit_async(const char *name1, const char *name2, const char *name3, diff --git a/include/DataFrame/Internals/DataFrame_write.tcc b/include/DataFrame/Internals/DataFrame_write.tcc index 62880a719..4449f4ddf 100644 --- a/include/DataFrame/Internals/DataFrame_write.tcc +++ b/include/DataFrame/Internals/DataFrame_write.tcc @@ -36,9 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template template -bool DataFrame:: +bool DataFrame:: write(const char *file_name, io_format iof, std::streamsize precision, @@ -62,10 +62,10 @@ write(const char *file_name, // ---------------------------------------------------------------------------- -template +template template std::string -DataFrame::to_string(std::streamsize precision) const { +DataFrame::to_string(std::streamsize precision) const { std::stringstream ss (std::ios_base::out); @@ -75,9 +75,9 @@ DataFrame::to_string(std::streamsize precision) const { // ---------------------------------------------------------------------------- -template +template template -bool DataFrame:: +bool DataFrame:: write(S &o, io_format iof, std::streamsize precision, @@ -205,9 +205,9 @@ write(S &o, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: write_async (const char *file_name, io_format iof, std::streamsize precision, @@ -231,9 +231,9 @@ write_async (const char *file_name, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: write_async (S &o, io_format iof, std::streamsize precision, @@ -257,9 +257,9 @@ write_async (S &o, // ---------------------------------------------------------------------------- -template +template template -std::future DataFrame:: +std::future DataFrame:: to_string_async (std::streamsize precision) const { return (std::async(std::launch::async, diff --git a/include/DataFrame/Utils/AlignedAllocator.h b/include/DataFrame/Utils/AlignedAllocator.h index ff1294184..64fd209ef 100644 --- a/include/DataFrame/Utils/AlignedAllocator.h +++ b/include/DataFrame/Utils/AlignedAllocator.h @@ -169,6 +169,18 @@ class AlignedAllocator : public AlignedValue { } }; +// ---------------------------------------------------------------------------- + +template +struct allocator_declare { + using type = AlignedAllocator; +}; + +template +struct allocator_declare { + using type = std::allocator; +}; + } // namespace std // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Vectors/HeteroConstPtrView.h b/include/DataFrame/Vectors/HeteroConstPtrView.h index 28ab3a40d..c1fb827b6 100644 --- a/include/DataFrame/Vectors/HeteroConstPtrView.h +++ b/include/DataFrame/Vectors/HeteroConstPtrView.h @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include @@ -41,7 +42,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -struct HeteroConstPtrView { +template +struct HeteroConstPtrView { + + static constexpr std::align_val_t align_value { A }; using size_type = size_t; @@ -62,9 +66,9 @@ struct HeteroConstPtrView { void set_begin_end_special(const T *bp, const T *ep_1); template - HeteroConstPtrView(VectorConstPtrView &vec); + HeteroConstPtrView(VectorConstPtrView &vec); template - HeteroConstPtrView(VectorConstPtrView &&vec); + HeteroConstPtrView(VectorConstPtrView &&vec); HMDF_API HeteroConstPtrView(const HeteroConstPtrView &that); HMDF_API HeteroConstPtrView(HeteroConstPtrView &&that); @@ -74,12 +78,12 @@ struct HeteroConstPtrView { HMDF_API HeteroConstPtrView &operator= (HeteroConstPtrView &&rhs); template - VectorConstPtrView &get_vector(); + VectorConstPtrView &get_vector(); template - const VectorConstPtrView &get_vector() const; + const VectorConstPtrView &get_vector() const; template - typename VectorConstPtrView::size_type + typename VectorConstPtrView::size_type size () const { return (get_vector().size()); } HMDF_API void clear(); @@ -117,7 +121,7 @@ struct HeteroConstPtrView { template inline static - std::unordered_map> + std::unordered_map> views_ { }; std::function diff --git a/include/DataFrame/Vectors/HeteroConstPtrView.tcc b/include/DataFrame/Vectors/HeteroConstPtrView.tcc index c1dba7686..08bf954e9 100644 --- a/include/DataFrame/Vectors/HeteroConstPtrView.tcc +++ b/include/DataFrame/Vectors/HeteroConstPtrView.tcc @@ -35,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { - +template template -HeteroConstPtrView::HeteroConstPtrView(const T *begin_ptr, const T *end_ptr) +HeteroConstPtrView::HeteroConstPtrView(const T *begin_ptr, const T *end_ptr) : clear_function_([](HeteroConstPtrView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroConstPtrView &from, HeteroConstPtrView &to) { @@ -45,13 +45,14 @@ HeteroConstPtrView::HeteroConstPtrView(const T *begin_ptr, const T *end_ptr) move_function_([](HeteroConstPtrView &from, HeteroConstPtrView &to) { views_[&to] = std::move(views_[&from]); }) { - views_.emplace(this, VectorConstPtrView(begin_ptr, end_ptr)); + views_.emplace(this, VectorConstPtrView(begin_ptr, end_ptr)); } // ---------------------------------------------------------------------------- +template template -void HeteroConstPtrView::set_begin_end_special(const T *bp, const T *ep_1) { +void HeteroConstPtrView::set_begin_end_special(const T *bp, const T *ep_1) { clear_function_ = [](HeteroConstPtrView &hv) { views_.erase(&hv); }; copy_function_ = [](const HeteroConstPtrView &from, @@ -62,7 +63,7 @@ void HeteroConstPtrView::set_begin_end_special(const T *bp, const T *ep_1) { views_[&to] = std::move(views_[&from]); }; - VectorConstPtrView vv; + VectorConstPtrView vv; vv.set_begin_end_special(bp, ep_1); views_.emplace(this, vv); @@ -70,8 +71,9 @@ void HeteroConstPtrView::set_begin_end_special(const T *bp, const T *ep_1) { // ---------------------------------------------------------------------------- +template template -HeteroConstPtrView::HeteroConstPtrView(VectorConstPtrView &vec) +HeteroConstPtrView::HeteroConstPtrView(VectorConstPtrView &vec) : clear_function_([](HeteroConstPtrView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroConstPtrView &from, HeteroConstPtrView &to) { @@ -84,8 +86,9 @@ HeteroConstPtrView::HeteroConstPtrView(VectorConstPtrView &vec) // ---------------------------------------------------------------------------- +template template -HeteroConstPtrView::HeteroConstPtrView(VectorConstPtrView &&vec) +HeteroConstPtrView::HeteroConstPtrView(VectorConstPtrView &&vec) : clear_function_([](HeteroConstPtrView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroConstPtrView &from, HeteroConstPtrView &to) { @@ -98,8 +101,9 @@ HeteroConstPtrView::HeteroConstPtrView(VectorConstPtrView &&vec) // ---------------------------------------------------------------------------- +template template -VectorConstPtrView &HeteroConstPtrView::get_vector() { +VectorConstPtrView &HeteroConstPtrView::get_vector() { auto iter = views_.find (this); @@ -112,8 +116,9 @@ VectorConstPtrView &HeteroConstPtrView::get_vector() { // ---------------------------------------------------------------------------- +template template -const VectorConstPtrView &HeteroConstPtrView::get_vector() const { +const VectorConstPtrView &HeteroConstPtrView::get_vector() const { const auto iter = views_.find (this); @@ -126,8 +131,9 @@ const VectorConstPtrView &HeteroConstPtrView::get_vector() const { // ---------------------------------------------------------------------------- +template template -void HeteroConstPtrView::visit_impl_help_ (T &visitor) const { +void HeteroConstPtrView::visit_impl_help_ (T &visitor) const { const auto citer = views_.find (this); @@ -146,8 +152,9 @@ void HeteroConstPtrView::visit_impl_help_ (T &visitor) const { // ---------------------------------------------------------------------------- +template template -void HeteroConstPtrView::change_impl_help_ (T &functor) const { +void HeteroConstPtrView::change_impl_help_ (T &functor) const { const auto citer = views_.find (this); @@ -157,8 +164,9 @@ void HeteroConstPtrView::change_impl_help_ (T &functor) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroConstPtrView::visit_impl_ (T &&visitor, TLIST) const { +void HeteroConstPtrView::visit_impl_ (T &&visitor, TLIST) const { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -167,8 +175,9 @@ void HeteroConstPtrView::visit_impl_ (T &&visitor, TLIST) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroConstPtrView::change_impl_ (T &&functor, TLIST) const { +void HeteroConstPtrView::change_impl_ (T &&functor, TLIST) const { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -176,33 +185,97 @@ void HeteroConstPtrView::change_impl_ (T &&functor, TLIST) const { // ---------------------------------------------------------------------------- +template template -bool HeteroConstPtrView::empty() const noexcept { +bool HeteroConstPtrView::empty() const noexcept { return (get_vector().empty ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroConstPtrView::at(size_type idx) const { +const T &HeteroConstPtrView::at(size_type idx) const { return (get_vector()[idx]); } // ---------------------------------------------------------------------------- +template template -const T &HeteroConstPtrView::back() const { return (get_vector().back ()); } +const T &HeteroConstPtrView:: +back() const { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroConstPtrView::front() const { +const T &HeteroConstPtrView::front() const { return (get_vector().front ()); } +// ---------------------------------------------------------------------------- + +template +HeteroConstPtrView::HeteroConstPtrView() = default; + +template +HeteroConstPtrView::HeteroConstPtrView (const HeteroConstPtrView &that) { + + *this = that; +} +template +HeteroConstPtrView::HeteroConstPtrView (HeteroConstPtrView &&that) { + *this = that; +} + +// ---------------------------------------------------------------------------- + +template +HeteroConstPtrView &HeteroConstPtrView:: +operator= (const HeteroConstPtrView &rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = rhs.clear_function_; + copy_function_ = rhs.copy_function_; + move_function_ = rhs.move_function_; + + copy_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +HeteroConstPtrView &HeteroConstPtrView:: +operator= (HeteroConstPtrView &&rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = std::move(rhs.clear_function_); + copy_function_ = std::move(rhs.copy_function_); + move_function_ = std::move(rhs.move_function_); + + move_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +void HeteroConstPtrView::clear() { + + clear_function_(*this); +} + } // namespace hmdf // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Vectors/HeteroConstView.h b/include/DataFrame/Vectors/HeteroConstView.h index 72c3a7385..d8c20b0d1 100644 --- a/include/DataFrame/Vectors/HeteroConstView.h +++ b/include/DataFrame/Vectors/HeteroConstView.h @@ -41,8 +41,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { +template struct HeteroConstView { + static constexpr std::align_val_t align_value { A }; + using size_type = size_t; HMDF_API HeteroConstView(); @@ -71,12 +74,12 @@ struct HeteroConstView { HMDF_API HeteroConstView &operator= (HeteroConstView &&rhs); template - VectorConstView &get_vector(); + VectorConstView &get_vector(); template - const VectorConstView &get_vector() const; + const VectorConstView &get_vector() const; template - typename VectorConstView::size_type + typename VectorConstView::size_type size () const { return (get_vector().size()); } HMDF_API void clear(); @@ -94,10 +97,10 @@ struct HeteroConstView { const T &front() const; template - using const_iterator = typename VectorConstView::const_iterator; + using const_iterator = typename VectorConstView::const_iterator; template using const_reverse_iterator = - typename VectorConstView::const_reverse_iterator; + typename VectorConstView::const_reverse_iterator; template const_iterator begin() const; @@ -129,7 +132,7 @@ struct HeteroConstView { template inline static - std::unordered_map> + std::unordered_map> views_ { }; std::function diff --git a/include/DataFrame/Vectors/HeteroConstView.tcc b/include/DataFrame/Vectors/HeteroConstView.tcc index e65b4233f..b29ce5349 100644 --- a/include/DataFrame/Vectors/HeteroConstView.tcc +++ b/include/DataFrame/Vectors/HeteroConstView.tcc @@ -38,21 +38,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { +template template -HeteroConstView::HeteroConstView(const T *begin_ptr, const T *end_ptr) +HeteroConstView::HeteroConstView(const T *begin_ptr, const T *end_ptr) : clear_function_([](HeteroConstView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroConstView &from, HeteroConstView &to) { views_[&to] = views_[&from]; }), move_function_([](HeteroConstView &from, HeteroConstView &to) { views_[&to] = std::move(views_[&from]); }) { - views_.emplace(this, VectorConstView(begin_ptr, end_ptr)); + views_.emplace(this, VectorConstView(begin_ptr, end_ptr)); } // ---------------------------------------------------------------------------- +template template -void HeteroConstView::set_begin_end_special(const T *bp, const T *ep_1) { +void HeteroConstView::set_begin_end_special(const T *bp, const T *ep_1) { clear_function_ = [](HeteroConstView &hv) { views_.erase(&hv); }; copy_function_ = [](const HeteroConstView &from, HeteroConstView &to) { @@ -62,7 +64,7 @@ void HeteroConstView::set_begin_end_special(const T *bp, const T *ep_1) { views_[&to] = std::move(views_[&from]); }; - VectorConstView vcv; + VectorConstView vcv; vcv.set_begin_end_special(bp, ep_1); views_.emplace(this, vcv); @@ -70,8 +72,9 @@ void HeteroConstView::set_begin_end_special(const T *bp, const T *ep_1) { // ---------------------------------------------------------------------------- +template template -VectorConstView &HeteroConstView::get_vector() { +VectorConstView &HeteroConstView::get_vector() { auto iter = views_.find (this); @@ -84,8 +87,9 @@ VectorConstView &HeteroConstView::get_vector() { // ---------------------------------------------------------------------------- +template template -const VectorConstView &HeteroConstView::get_vector() const { +const VectorConstView &HeteroConstView::get_vector() const { const auto citer = views_.find (this); @@ -98,8 +102,9 @@ const VectorConstView &HeteroConstView::get_vector() const { // ---------------------------------------------------------------------------- +template template -void HeteroConstView::visit_impl_help_ (T &visitor) const { +void HeteroConstView::visit_impl_help_ (T &visitor) const { const auto citer = views_.find (this); @@ -110,8 +115,9 @@ void HeteroConstView::visit_impl_help_ (T &visitor) const { // ---------------------------------------------------------------------------- +template template -void HeteroConstView::change_impl_help_ (T &functor) const { +void HeteroConstView::change_impl_help_ (T &functor) const { const auto citer = views_.find (this); @@ -121,8 +127,9 @@ void HeteroConstView::change_impl_help_ (T &functor) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroConstView::visit_impl_ (T &&visitor, TLIST) const { +void HeteroConstView::visit_impl_ (T &&visitor, TLIST) const { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -131,8 +138,9 @@ void HeteroConstView::visit_impl_ (T &&visitor, TLIST) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroConstView::change_impl_ (T &&functor, TLIST) const { +void HeteroConstView::change_impl_ (T &&functor, TLIST) const { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -140,54 +148,117 @@ void HeteroConstView::change_impl_ (T &&functor, TLIST) const { // ---------------------------------------------------------------------------- +template template -bool HeteroConstView::empty() const noexcept { +bool HeteroConstView::empty() const noexcept { return (get_vector().empty ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroConstView::at(size_type idx) const { +const T &HeteroConstView::at(size_type idx) const { return (get_vector()[idx]); } // ---------------------------------------------------------------------------- +template template -const T &HeteroConstView::back() const { return (get_vector().back ()); } +const T &HeteroConstView::back() const { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroConstView::front() const { return (get_vector().front ()); } +const T &HeteroConstView:: +front() const { return (get_vector().front ()); } // ---------------------------------------------------------------------------- +template template -HeteroConstView::const_iterator -HeteroConstView::begin() const { return (get_vector().begin ()); } +typename HeteroConstView::template const_iterator +HeteroConstView::begin() const { return (get_vector().begin ()); } // ---------------------------------------------------------------------------- +template template -HeteroConstView::const_iterator -HeteroConstView::end() const { return (get_vector().end ()); } +typename HeteroConstView::template const_iterator +HeteroConstView::end() const { return (get_vector().end ()); } // ---------------------------------------------------------------------------- +template template -HeteroConstView::const_reverse_iterator -HeteroConstView::rbegin() const { return (get_vector().rbegin ()); } +typename HeteroConstView::template const_reverse_iterator +HeteroConstView::rbegin() const { return (get_vector().rbegin ()); } // ---------------------------------------------------------------------------- +template template -HeteroConstView::const_reverse_iterator -HeteroConstView::rend() const { return (get_vector().rend ()); } +typename HeteroConstView::template const_reverse_iterator +HeteroConstView::rend() const { return (get_vector().rend ()); } + +// ---------------------------------------------------------------------------- + +template +HeteroConstView::HeteroConstView() = default; + +template +HeteroConstView:: +HeteroConstView(const HeteroConstView &that) { *this = that; } +template +HeteroConstView::HeteroConstView(HeteroConstView &&that) { *this = that; } + +// ---------------------------------------------------------------------------- + +template +HeteroConstView &HeteroConstView:: +operator= (const HeteroConstView &rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = rhs.clear_function_; + copy_function_ = rhs.copy_function_; + move_function_ = rhs.move_function_; + + copy_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +HeteroConstView &HeteroConstView::operator= (HeteroConstView &&rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = std::move(rhs.clear_function_); + copy_function_ = std::move(rhs.copy_function_); + move_function_ = std::move(rhs.move_function_); + + move_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +void HeteroConstView::clear() { + + clear_function_(*this); +} } // namespace hmdf diff --git a/include/DataFrame/Vectors/HeteroPtrView.h b/include/DataFrame/Vectors/HeteroPtrView.h index d479e78dc..4c5850f9f 100644 --- a/include/DataFrame/Vectors/HeteroPtrView.h +++ b/include/DataFrame/Vectors/HeteroPtrView.h @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include @@ -41,8 +42,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { +template struct HeteroPtrView { + static constexpr std::align_val_t align_value { A }; + using size_type = size_t; HMDF_API HeteroPtrView(); @@ -62,9 +66,9 @@ struct HeteroPtrView { void set_begin_end_special(T *bp, T *ep_1); template - HeteroPtrView(VectorPtrView &vec); + HeteroPtrView(VectorPtrView &vec); template - HeteroPtrView(VectorPtrView &&vec); + HeteroPtrView(VectorPtrView &&vec); HMDF_API HeteroPtrView(const HeteroPtrView &that); HMDF_API HeteroPtrView(HeteroPtrView &&that); @@ -74,9 +78,9 @@ struct HeteroPtrView { HMDF_API HeteroPtrView &operator= (HeteroPtrView &&rhs); template - VectorPtrView &get_vector(); + VectorPtrView &get_vector(); template - const VectorPtrView &get_vector() const; + const VectorPtrView &get_vector() const; template void reserve (size_type r) { get_vector().reserve (r); } @@ -84,7 +88,7 @@ struct HeteroPtrView { void shrink_to_fit () { get_vector().shrink_to_fit (); } template - typename VectorPtrView:: + typename VectorPtrView:: size_type size () const { return (get_vector().size()); } HMDF_API void clear(); @@ -142,7 +146,7 @@ struct HeteroPtrView { private: template - inline static std::unordered_map> + inline static std::unordered_map> views_ { }; std::function diff --git a/include/DataFrame/Vectors/HeteroPtrView.tcc b/include/DataFrame/Vectors/HeteroPtrView.tcc index a9bd75bdc..18c3436c3 100644 --- a/include/DataFrame/Vectors/HeteroPtrView.tcc +++ b/include/DataFrame/Vectors/HeteroPtrView.tcc @@ -36,21 +36,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { +template template -HeteroPtrView::HeteroPtrView(T *begin_ptr, T *end_ptr) +HeteroPtrView::HeteroPtrView(T *begin_ptr, T *end_ptr) : clear_function_([](HeteroPtrView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroPtrView &from, HeteroPtrView &to) { views_[&to] = views_[&from]; }), move_function_([](HeteroPtrView &from, HeteroPtrView &to) { views_[&to] = std::move(views_[&from]); }) { - views_.emplace(this, VectorPtrView(begin_ptr, end_ptr)); + views_.emplace(this, VectorPtrView(begin_ptr, end_ptr)); } // ---------------------------------------------------------------------------- +template template -void HeteroPtrView::set_begin_end_special(T *bp, T *ep_1) { +void HeteroPtrView::set_begin_end_special(T *bp, T *ep_1) { clear_function_ = [](HeteroPtrView &hv) { views_.erase(&hv); }; copy_function_ = [](const HeteroPtrView &from, HeteroPtrView &to) { @@ -60,7 +62,7 @@ void HeteroPtrView::set_begin_end_special(T *bp, T *ep_1) { views_[&to] = std::move(views_[&from]); }; - VectorPtrView vv; + VectorPtrView vv; vv.set_begin_end_special(bp, ep_1); views_.emplace(this, vv); @@ -68,8 +70,9 @@ void HeteroPtrView::set_begin_end_special(T *bp, T *ep_1) { // ---------------------------------------------------------------------------- +template template -HeteroPtrView::HeteroPtrView(VectorPtrView &vec) +HeteroPtrView::HeteroPtrView(VectorPtrView &vec) : clear_function_([](HeteroPtrView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroPtrView &from, HeteroPtrView &to) { views_[&to] = views_[&from]; }), @@ -81,8 +84,9 @@ HeteroPtrView::HeteroPtrView(VectorPtrView &vec) // ---------------------------------------------------------------------------- +template template -HeteroPtrView::HeteroPtrView(VectorPtrView &&vec) +HeteroPtrView::HeteroPtrView(VectorPtrView &&vec) : clear_function_([](HeteroPtrView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroPtrView &from, HeteroPtrView &to) { views_[&to] = views_[&from]; }), @@ -94,8 +98,9 @@ HeteroPtrView::HeteroPtrView(VectorPtrView &&vec) // ---------------------------------------------------------------------------- +template template -VectorPtrView &HeteroPtrView::get_vector() { +VectorPtrView &HeteroPtrView::get_vector() { auto iter = views_.find (this); @@ -108,16 +113,18 @@ VectorPtrView &HeteroPtrView::get_vector() { // ---------------------------------------------------------------------------- +template template -const VectorPtrView &HeteroPtrView::get_vector() const { +const VectorPtrView &HeteroPtrView::get_vector() const { return (const_cast(this)->get_vector()); } // ---------------------------------------------------------------------------- +template template -void HeteroPtrView::visit_impl_help_ (T &visitor) { +void HeteroPtrView::visit_impl_help_ (T &visitor) { auto iter = views_.find (this); @@ -136,8 +143,9 @@ void HeteroPtrView::visit_impl_help_ (T &visitor) { // ---------------------------------------------------------------------------- +template template -void HeteroPtrView::visit_impl_help_ (T &visitor) const { +void HeteroPtrView::visit_impl_help_ (T &visitor) const { const auto citer = views_.find (this); @@ -156,8 +164,9 @@ void HeteroPtrView::visit_impl_help_ (T &visitor) const { // ---------------------------------------------------------------------------- +template template -void HeteroPtrView::sort_impl_help_ (T &functor) { +void HeteroPtrView::sort_impl_help_ (T &functor) { auto iter = views_.find (this); @@ -167,8 +176,9 @@ void HeteroPtrView::sort_impl_help_ (T &functor) { // ---------------------------------------------------------------------------- +template template -void HeteroPtrView::change_impl_help_ (T &functor) { +void HeteroPtrView::change_impl_help_ (T &functor) { auto iter = views_.find (this); @@ -178,8 +188,9 @@ void HeteroPtrView::change_impl_help_ (T &functor) { // ---------------------------------------------------------------------------- +template template -void HeteroPtrView::change_impl_help_ (T &functor) const { +void HeteroPtrView::change_impl_help_ (T &functor) const { const auto citer = views_.find (this); @@ -189,8 +200,9 @@ void HeteroPtrView::change_impl_help_ (T &functor) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroPtrView::visit_impl_ (T &&visitor, TLIST) { +void HeteroPtrView::visit_impl_ (T &&visitor, TLIST) { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -199,8 +211,9 @@ void HeteroPtrView::visit_impl_ (T &&visitor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroPtrView::visit_impl_ (T &&visitor, TLIST) const { +void HeteroPtrView::visit_impl_ (T &&visitor, TLIST) const { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -209,8 +222,9 @@ void HeteroPtrView::visit_impl_ (T &&visitor, TLIST) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroPtrView::sort_impl_ (T &&functor, TLIST) { +void HeteroPtrView::sort_impl_ (T &&functor, TLIST) { using expander = int[]; (void) expander { 0, (sort_impl_help_(functor), 0) ... }; @@ -218,8 +232,9 @@ void HeteroPtrView::sort_impl_ (T &&functor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroPtrView::change_impl_ (T &&functor, TLIST) { +void HeteroPtrView::change_impl_ (T &&functor, TLIST) { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -227,8 +242,9 @@ void HeteroPtrView::change_impl_ (T &&functor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroPtrView::change_impl_ (T &&functor, TLIST) const { +void HeteroPtrView::change_impl_ (T &&functor, TLIST) const { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -236,47 +252,106 @@ void HeteroPtrView::change_impl_ (T &&functor, TLIST) const { // ---------------------------------------------------------------------------- +template template -bool HeteroPtrView::empty() const noexcept { +bool HeteroPtrView::empty() const noexcept { return (get_vector().empty ()); } // ---------------------------------------------------------------------------- +template template -T &HeteroPtrView::at(size_type idx) { +T &HeteroPtrView::at(size_type idx) { return (get_vector()[idx]); } // ---------------------------------------------------------------------------- +template template -const T &HeteroPtrView::at(size_type idx) const { +const T &HeteroPtrView::at(size_type idx) const { return (get_vector()[idx]); } // ---------------------------------------------------------------------------- +template template -T &HeteroPtrView::back() { return (get_vector().back ()); } +T &HeteroPtrView::back() { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroPtrView::back() const { return (get_vector().back ()); } +const T &HeteroPtrView::back() const { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -T &HeteroPtrView::front() { return (get_vector().front ()); } +T &HeteroPtrView::front() { return (get_vector().front ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroPtrView::front() const { return (get_vector().front ()); } +const T &HeteroPtrView::front() const { return (get_vector().front ()); } + +// ---------------------------------------------------------------------------- + +template +HeteroPtrView::HeteroPtrView() = default; + +template +HeteroPtrView::HeteroPtrView (const HeteroPtrView &that) { *this = that; } +template +HeteroPtrView::HeteroPtrView (HeteroPtrView &&that) { *this = that; } + +// ---------------------------------------------------------------------------- + +template +HeteroPtrView &HeteroPtrView::operator= (const HeteroPtrView &rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = rhs.clear_function_; + copy_function_ = rhs.copy_function_; + move_function_ = rhs.move_function_; + + copy_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +HeteroPtrView &HeteroPtrView::operator= (HeteroPtrView &&rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = std::move(rhs.clear_function_); + copy_function_ = std::move(rhs.copy_function_); + move_function_ = std::move(rhs.move_function_); + + move_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +void HeteroPtrView::clear() { + + clear_function_(*this); +} } // namespace hmdf diff --git a/include/DataFrame/Vectors/HeteroVector.h b/include/DataFrame/Vectors/HeteroVector.h index 3a556ec83..5d2b46d6e 100644 --- a/include/DataFrame/Vectors/HeteroVector.h +++ b/include/DataFrame/Vectors/HeteroVector.h @@ -29,13 +29,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once +#include +#include #include #include #include #include -#include #include +#include #include #include #include @@ -49,8 +51,11 @@ namespace hmdf // are partly inspired by Andy G's Blog at: // https://gieseanw.wordpress.com/2017/05/03/a-true-heterogeneous-container/ // +template struct HeteroVector { + static constexpr std::align_val_t align_value { A }; + using size_type = size_t; HMDF_API HeteroVector(); @@ -63,9 +68,10 @@ struct HeteroVector { HMDF_API HeteroVector &operator= (HeteroVector &&rhs); template - std::vector &get_vector(); + std::vector::type> &get_vector(); template - const std::vector &get_vector() const; + const std::vector::type> & + get_vector() const; // It returns a view of the underlying vector. // NOTE: One can modify the vector through the view. But the vector @@ -73,14 +79,14 @@ struct HeteroVector { // There is no const version of this method // template - HeteroView get_view(size_type begin = 0, size_type end = -1); + HeteroView get_view(size_type begin = 0, size_type end = -1); template - HeteroConstView get_view(size_type begin = 0, size_type end = -1) const; + HeteroConstView get_view(size_type begin = 0, size_type end = -1) const; template - HeteroPtrView get_ptr_view(size_type begin = 0, size_type end = -1); + HeteroPtrView get_ptr_view(size_type begin = 0, size_type end = -1); template - HeteroConstPtrView + HeteroConstPtrView get_ptr_view(size_type begin = 0, size_type end = -1) const; template @@ -130,14 +136,27 @@ struct HeteroVector { const T &front() const; template - using iterator = typename std::vector::iterator; + using iterator = + typename + std::vector::type>::iterator; template - using const_iterator = typename std::vector::const_iterator; + using const_iterator = + typename + std::vector< + T, + typename allocator_declare::type>::const_iterator; template - using reverse_iterator = typename std::vector::reverse_iterator; + using reverse_iterator = + typename + std::vector< + T, + typename allocator_declare::type >::reverse_iterator; template using const_reverse_iterator = - typename std::vector::const_reverse_iterator; + typename + std::vector< + T, + typename allocator_declare::type>::const_reverse_iterator; template inline iterator @@ -211,7 +230,10 @@ struct HeteroVector { private: template - inline static std::unordered_map> + inline static std::unordered_map< + const HeteroVector *, + std::vector::type>> vectors_ { }; std::vector> clear_functions_; diff --git a/include/DataFrame/Vectors/HeteroVector.tcc b/include/DataFrame/Vectors/HeteroVector.tcc index 56c5dd652..30938a441 100644 --- a/include/DataFrame/Vectors/HeteroVector.tcc +++ b/include/DataFrame/Vectors/HeteroVector.tcc @@ -37,8 +37,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { +template template -std::vector &HeteroVector::get_vector() { +std::vector::type> &HeteroVector:: +get_vector() { auto iter = vectors_.find (this); @@ -59,7 +61,11 @@ std::vector &HeteroVector::get_vector() { vectors_[&to] = std::move(vectors_[&from]); }); - iter = vectors_.emplace (this, std::vector()).first; + iter = vectors_.emplace ( + this, + std::vector< + T, + typename allocator_declare::type>()).first; } return (iter->second); @@ -67,84 +73,100 @@ std::vector &HeteroVector::get_vector() { // ---------------------------------------------------------------------------- +template template -HeteroView HeteroVector::get_view(size_type begin, size_type end) { +HeteroView HeteroVector::get_view(size_type begin, size_type end) { - std::vector &vec = get_vector(); + std::vector::type> &vec = + get_vector(); - return (HeteroView( + return (HeteroView( &(vec[begin]), end == size_t(-1) ? &(vec.back()) : &(vec[end]))); } // ---------------------------------------------------------------------------- +template template -HeteroConstView HeteroVector::get_view(size_type begin, size_type end) const { +HeteroConstView HeteroVector:: +get_view(size_type begin, size_type end) const { - const std::vector &vec = get_vector(); + const std::vector::type> &vec = + get_vector(); - return (HeteroConstView( + return (HeteroConstView( &(vec[begin]), end == size_t(-1) ? &(vec.back()) : &(vec[end]))); } // ---------------------------------------------------------------------------- +template template -HeteroPtrView HeteroVector::get_ptr_view(size_type begin, size_type end) { +HeteroPtrView HeteroVector:: +get_ptr_view(size_type begin, size_type end) { - std::vector &vec = get_vector(); + std::vector::type> &vec = + get_vector(); - return (HeteroPtrView( + return (HeteroPtrView( &(*(vec.begin() + begin)), end == size_type(-1) ? &(vec.back()) + 1 : &(*(vec.begin() + end)))); } // ---------------------------------------------------------------------------- +template template -HeteroConstPtrView HeteroVector:: +HeteroConstPtrView HeteroVector:: get_ptr_view(size_type begin, size_type end) const { - const std::vector &vec = get_vector(); + const std::vector::type> &vec = + get_vector(); - return (HeteroConstPtrView( + return (HeteroConstPtrView( &(*(vec.begin() + begin)), end == size_type(-1) ? &(vec.back()) + 1 : &(*(vec.begin() + end)))); } // ---------------------------------------------------------------------------- +template template -const std::vector &HeteroVector::get_vector() const { +const std::vector::type> & +HeteroVector::get_vector() const { return (const_cast(this)->get_vector()); } // ---------------------------------------------------------------------------- +template template -void HeteroVector::push_back(const T &v) { get_vector().push_back (v); } +void HeteroVector::push_back(const T &v) { get_vector().push_back (v); } // ---------------------------------------------------------------------------- +template template -void HeteroVector::emplace_back (Args &&... args) { +void HeteroVector::emplace_back (Args &&... args) { get_vector().emplace_back (std::forward(args)...); } // ---------------------------------------------------------------------------- +template template -void HeteroVector::emplace (ITR pos, Args &&... args) { +void HeteroVector::emplace (ITR pos, Args &&... args) { get_vector().emplace (pos, std::forward(args)...); } // ---------------------------------------------------------------------------- +template template -void HeteroVector::visit_impl_help_ (T &visitor) { +void HeteroVector::visit_impl_help_ (T &visitor) { auto iter = vectors_.find (this); @@ -155,8 +177,9 @@ void HeteroVector::visit_impl_help_ (T &visitor) { // ---------------------------------------------------------------------------- +template template -void HeteroVector::visit_impl_help_ (T &visitor) const { +void HeteroVector::visit_impl_help_ (T &visitor) const { const auto citer = vectors_.find (this); @@ -167,8 +190,9 @@ void HeteroVector::visit_impl_help_ (T &visitor) const { // ---------------------------------------------------------------------------- +template template -void HeteroVector::sort_impl_help_ (T &functor) { +void HeteroVector::sort_impl_help_ (T &functor) { auto iter = vectors_.find (this); @@ -178,8 +202,9 @@ void HeteroVector::sort_impl_help_ (T &functor) { // ---------------------------------------------------------------------------- +template template -void HeteroVector::change_impl_help_ (T &functor) { +void HeteroVector::change_impl_help_ (T &functor) { auto iter = vectors_.find (this); @@ -189,8 +214,9 @@ void HeteroVector::change_impl_help_ (T &functor) { // ---------------------------------------------------------------------------- +template template -void HeteroVector::change_impl_help_ (T &functor) const { +void HeteroVector::change_impl_help_ (T &functor) const { const auto citer = vectors_.find (this); @@ -200,8 +226,9 @@ void HeteroVector::change_impl_help_ (T &functor) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroVector::visit_impl_ (T &&visitor, TLIST) { +void HeteroVector::visit_impl_ (T &&visitor, TLIST) { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -210,8 +237,9 @@ void HeteroVector::visit_impl_ (T &&visitor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroVector::visit_impl_ (T &&visitor, TLIST) const { +void HeteroVector::visit_impl_ (T &&visitor, TLIST) const { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -220,8 +248,9 @@ void HeteroVector::visit_impl_ (T &&visitor, TLIST) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroVector::sort_impl_ (T &&functor, TLIST) { +void HeteroVector::sort_impl_ (T &&functor, TLIST) { using expander = int[]; (void) expander { 0, (sort_impl_help_(functor), 0) ... }; @@ -229,8 +258,9 @@ void HeteroVector::sort_impl_ (T &&functor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroVector::change_impl_ (T &&functor, TLIST) { +void HeteroVector::change_impl_ (T &&functor, TLIST) { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -238,8 +268,9 @@ void HeteroVector::change_impl_ (T &&functor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroVector::change_impl_ (T &&functor, TLIST) const { +void HeteroVector::change_impl_ (T &&functor, TLIST) const { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -247,8 +278,9 @@ void HeteroVector::change_impl_ (T &&functor, TLIST) const { // ---------------------------------------------------------------------------- +template template -void HeteroVector::erase(size_type pos) { +void HeteroVector::erase(size_type pos) { auto &vec = get_vector(); @@ -257,68 +289,141 @@ void HeteroVector::erase(size_type pos) { // ---------------------------------------------------------------------------- +template template -void HeteroVector::resize(size_type count) { +void HeteroVector::resize(size_type count) { get_vector().resize (count); } // ---------------------------------------------------------------------------- +template template -void HeteroVector::resize(size_type count, const T &v) { +void HeteroVector::resize(size_type count, const T &v) { get_vector().resize (count, v); } // ---------------------------------------------------------------------------- +template template -void HeteroVector::pop_back() { get_vector().pop_back (); } +void HeteroVector::pop_back() { get_vector().pop_back (); } // ---------------------------------------------------------------------------- +template template -bool HeteroVector::empty() const noexcept { +bool HeteroVector::empty() const noexcept { return (get_vector().empty ()); } // ---------------------------------------------------------------------------- +template template -T &HeteroVector::at(size_type idx) { +T &HeteroVector::at(size_type idx) { return (get_vector().at (idx)); } // ---------------------------------------------------------------------------- +template template -const T &HeteroVector::at(size_type idx) const { +const T &HeteroVector::at(size_type idx) const { return (get_vector().at (idx)); } // ---------------------------------------------------------------------------- +template template -T &HeteroVector::back() { return (get_vector().back ()); } +T &HeteroVector::back() { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroVector::back() const { return (get_vector().back ()); } +const T &HeteroVector::back() const { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -T &HeteroVector::front() { return (get_vector().front ()); } +T &HeteroVector::front() { return (get_vector().front ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroVector::front() const { return (get_vector().front ()); } +const T &HeteroVector::front() const { return (get_vector().front ()); } + + +// ---------------------------------------------------------------------------- + +template +HeteroVector::HeteroVector () { + + clear_functions_.reserve(2); + copy_functions_.reserve(2); + move_functions_.reserve(2); +} + +// ---------------------------------------------------------------------------- + +template +HeteroVector::HeteroVector (const HeteroVector &that) { *this = that; } +template +HeteroVector::HeteroVector (HeteroVector &&that) { *this = that; } + +// ---------------------------------------------------------------------------- + +template +HeteroVector &HeteroVector::operator= (const HeteroVector &rhs) { + + if (&rhs != this) { + clear(); + clear_functions_ = rhs.clear_functions_; + copy_functions_ = rhs.copy_functions_; + move_functions_ = rhs.move_functions_; + + for (auto &©_function : copy_functions_) + copy_function(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +HeteroVector &HeteroVector::operator= (HeteroVector &&rhs) { + + if (&rhs != this) { + clear(); + clear_functions_ = std::move(rhs.clear_functions_); + copy_functions_ = std::move(rhs.copy_functions_); + move_functions_ = std::move(rhs.move_functions_); + + for (auto &&move_function : move_functions_) + move_function(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +void HeteroVector::clear() { + + for (auto &&clear_func : clear_functions_) + clear_func (*this); +} } // namespace hmdf diff --git a/include/DataFrame/Vectors/HeteroView.h b/include/DataFrame/Vectors/HeteroView.h index bb6351e10..755c8fd03 100644 --- a/include/DataFrame/Vectors/HeteroView.h +++ b/include/DataFrame/Vectors/HeteroView.h @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include @@ -41,8 +42,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { +template struct HeteroView { + static constexpr std::align_val_t align_value { A }; + using size_type = size_t; HMDF_API HeteroView(); @@ -70,12 +74,12 @@ struct HeteroView { HMDF_API HeteroView &operator= (HeteroView &&rhs); template - VectorView &get_vector(); + VectorView &get_vector(); template - const VectorView &get_vector() const; + const VectorView &get_vector() const; template - typename VectorView:: + typename VectorView:: size_type size () const { return (get_vector().size()); } HMDF_API void clear(); @@ -99,14 +103,14 @@ struct HeteroView { const T &front() const; template - using iterator = typename VectorView::iterator; + using iterator = typename VectorView::iterator; template - using const_iterator = typename VectorView::const_iterator; + using const_iterator = typename VectorView::const_iterator; template - using reverse_iterator = typename VectorView::reverse_iterator; + using reverse_iterator = typename VectorView::reverse_iterator; template using const_reverse_iterator = - typename VectorView::const_reverse_iterator; + typename VectorView::const_reverse_iterator; template iterator begin(); @@ -164,7 +168,7 @@ struct HeteroView { template inline static - std::unordered_map> views_ { }; + std::unordered_map> views_ { }; std::function clear_function_ { [](HeteroView &) { return; } diff --git a/include/DataFrame/Vectors/HeteroView.tcc b/include/DataFrame/Vectors/HeteroView.tcc index 3636acfad..246a1db11 100644 --- a/include/DataFrame/Vectors/HeteroView.tcc +++ b/include/DataFrame/Vectors/HeteroView.tcc @@ -38,21 +38,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { +template template -HeteroView::HeteroView(T *begin_ptr, T *end_ptr) +HeteroView::HeteroView(T *begin_ptr, T *end_ptr) : clear_function_([](HeteroView &hv) { views_.erase(&hv); }), copy_function_([](const HeteroView &from, HeteroView &to) { views_[&to] = views_[&from]; }), move_function_([](HeteroView &from, HeteroView &to) { views_[&to] = std::move(views_[&from]); }) { - views_.emplace(this, VectorView(begin_ptr, end_ptr)); + views_.emplace(this, VectorView(begin_ptr, end_ptr)); } // ---------------------------------------------------------------------------- +template template -void HeteroView::set_begin_end_special(T *bp, T *ep_1) { +void HeteroView::set_begin_end_special(T *bp, T *ep_1) { clear_function_ = [](HeteroView &hv) { views_.erase(&hv); }; copy_function_ = [](const HeteroView &from, HeteroView &to) { @@ -62,7 +64,7 @@ void HeteroView::set_begin_end_special(T *bp, T *ep_1) { views_[&to] = std::move(views_[&from]); }; - VectorView vv; + VectorView vv; vv.set_begin_end_special(bp, ep_1); views_.emplace(this, vv); @@ -70,8 +72,9 @@ void HeteroView::set_begin_end_special(T *bp, T *ep_1) { // ---------------------------------------------------------------------------- +template template -VectorView &HeteroView::get_vector() { +VectorView &HeteroView::get_vector() { auto iter = views_.find (this); @@ -84,16 +87,18 @@ VectorView &HeteroView::get_vector() { // ---------------------------------------------------------------------------- +template template -const VectorView &HeteroView::get_vector() const { +const VectorView &HeteroView::get_vector() const { return (const_cast(this)->get_vector()); } // ---------------------------------------------------------------------------- +template template -void HeteroView::visit_impl_help_ (T &visitor) { +void HeteroView::visit_impl_help_ (T &visitor) { auto iter = views_.find (this); @@ -104,8 +109,9 @@ void HeteroView::visit_impl_help_ (T &visitor) { // ---------------------------------------------------------------------------- +template template -void HeteroView::visit_impl_help_ (T &visitor) const { +void HeteroView::visit_impl_help_ (T &visitor) const { const auto citer = views_.find (this); @@ -116,8 +122,9 @@ void HeteroView::visit_impl_help_ (T &visitor) const { // ---------------------------------------------------------------------------- +template template -void HeteroView::sort_impl_help_ (T &functor) { +void HeteroView::sort_impl_help_ (T &functor) { auto iter = views_.find (this); @@ -127,8 +134,9 @@ void HeteroView::sort_impl_help_ (T &functor) { // ---------------------------------------------------------------------------- +template template -void HeteroView::change_impl_help_ (T &functor) { +void HeteroView::change_impl_help_ (T &functor) { auto iter = views_.find (this); @@ -138,8 +146,9 @@ void HeteroView::change_impl_help_ (T &functor) { // ---------------------------------------------------------------------------- +template template -void HeteroView::change_impl_help_ (T &functor) const { +void HeteroView::change_impl_help_ (T &functor) const { const auto citer = views_.find (this); @@ -149,8 +158,9 @@ void HeteroView::change_impl_help_ (T &functor) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroView::visit_impl_ (T &&visitor, TLIST) { +void HeteroView::visit_impl_ (T &&visitor, TLIST) { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -159,8 +169,9 @@ void HeteroView::visit_impl_ (T &&visitor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroView::visit_impl_ (T &&visitor, TLIST) const { +void HeteroView::visit_impl_ (T &&visitor, TLIST) const { // (..., visit_impl_help_, TYPES>(visitor)); // C++17 using expander = int[]; @@ -169,8 +180,9 @@ void HeteroView::visit_impl_ (T &&visitor, TLIST) const { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroView::sort_impl_ (T &&functor, TLIST) { +void HeteroView::sort_impl_ (T &&functor, TLIST) { using expander = int[]; (void) expander { 0, (sort_impl_help_(functor), 0) ... }; @@ -178,8 +190,9 @@ void HeteroView::sort_impl_ (T &&functor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroView::change_impl_ (T &&functor, TLIST) { +void HeteroView::change_impl_ (T &&functor, TLIST) { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -187,8 +200,9 @@ void HeteroView::change_impl_ (T &&functor, TLIST) { // ---------------------------------------------------------------------------- +template template class TLIST, class... TYPES> -void HeteroView::change_impl_ (T &&functor, TLIST) const { +void HeteroView::change_impl_ (T &&functor, TLIST) const { using expander = int[]; (void) expander { 0, (change_impl_help_(functor), 0) ... }; @@ -196,96 +210,163 @@ void HeteroView::change_impl_ (T &&functor, TLIST) const { // ---------------------------------------------------------------------------- +template template -bool HeteroView::empty() const noexcept { +bool HeteroView::empty() const noexcept { return (get_vector().empty ()); } // ---------------------------------------------------------------------------- +template template -T &HeteroView::at(size_type idx) { +T &HeteroView::at(size_type idx) { return (get_vector()[idx]); } // ---------------------------------------------------------------------------- +template template -const T &HeteroView::at(size_type idx) const { +const T &HeteroView::at(size_type idx) const { return (get_vector()[idx]); } // ---------------------------------------------------------------------------- +template template -T &HeteroView::back() { return (get_vector().back ()); } +T &HeteroView::back() { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroView::back() const { return (get_vector().back ()); } +const T &HeteroView::back() const { return (get_vector().back ()); } // ---------------------------------------------------------------------------- +template template -T &HeteroView::front() { return (get_vector().front ()); } +T &HeteroView::front() { return (get_vector().front ()); } // ---------------------------------------------------------------------------- +template template -const T &HeteroView::front() const { return (get_vector().front ()); } +const T &HeteroView::front() const { return (get_vector().front ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::iterator -HeteroView::begin() { return (get_vector().begin ()); } +typename HeteroView::template iterator +HeteroView::begin() { return (get_vector().begin ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::const_iterator -HeteroView::begin() const { return (get_vector().begin ()); } +typename HeteroView::template const_iterator +HeteroView::begin() const { return (get_vector().begin ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::iterator -HeteroView::end() { return (get_vector().end ()); } +typename HeteroView::template iterator +HeteroView::end() { return (get_vector().end ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::const_iterator -HeteroView::end() const { return (get_vector().end ()); } +typename HeteroView::template const_iterator +HeteroView::end() const { return (get_vector().end ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::reverse_iterator -HeteroView::rbegin() { return (get_vector().rbegin ()); } +typename HeteroView::template reverse_iterator +HeteroView::rbegin() { return (get_vector().rbegin ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::const_reverse_iterator -HeteroView::rbegin() const { return (get_vector().rbegin ()); } +typename HeteroView::template const_reverse_iterator +HeteroView::rbegin() const { return (get_vector().rbegin ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::reverse_iterator -HeteroView::rend() { return (get_vector().rend ()); } +typename HeteroView::template reverse_iterator +HeteroView::rend() { return (get_vector().rend ()); } // ---------------------------------------------------------------------------- +template template -HeteroView::const_reverse_iterator -HeteroView::rend() const { return (get_vector().rend ()); } +typename HeteroView::template const_reverse_iterator +HeteroView::rend() const { return (get_vector().rend ()); } + +// ---------------------------------------------------------------------------- + +template +HeteroView::HeteroView() = default; + +template +HeteroView::HeteroView (const HeteroView &that) { *this = that; } +template +HeteroView::HeteroView (HeteroView &&that) { *this = that; } + +// ---------------------------------------------------------------------------- + +template +HeteroView &HeteroView::operator= (const HeteroView &rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = rhs.clear_function_; + copy_function_ = rhs.copy_function_; + move_function_ = rhs.move_function_; + + copy_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +HeteroView &HeteroView::operator= (HeteroView &&rhs) { + + if (&rhs != this) { + clear(); + clear_function_ = std::move(rhs.clear_function_); + copy_function_ = std::move(rhs.copy_function_); + move_function_ = std::move(rhs.move_function_); + + move_function_(rhs, *this); + } + + return (*this); +} + +// ---------------------------------------------------------------------------- + +template +void HeteroView::clear() { + + clear_function_(*this); +} } // namespace hmdf diff --git a/include/DataFrame/Vectors/VectorPtrView.h b/include/DataFrame/Vectors/VectorPtrView.h index 99bec2dd4..414b6f817 100644 --- a/include/DataFrame/Vectors/VectorPtrView.h +++ b/include/DataFrame/Vectors/VectorPtrView.h @@ -29,6 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once +#include + #include #include #include @@ -39,13 +41,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template +template class VectorPtrView { - using vector_type = std::vector; + using vector_type = + std::vector::type>; public: + static constexpr std::align_val_t align_value { A }; + using value_type = T; using pointer = T *; using const_pointer = const T *; @@ -501,13 +506,16 @@ class VectorPtrView { // ---------------------------------------------------------------------------- -template +template class VectorConstPtrView { - using vector_type = std::vector; + using vector_type = + std::vector::type>; public: + static constexpr std::align_val_t align_value { A }; + using value_type = T; using pointer = const T *; using const_pointer = const T *; diff --git a/include/DataFrame/Vectors/VectorView.h b/include/DataFrame/Vectors/VectorView.h index cd1932c53..d9c0c055c 100644 --- a/include/DataFrame/Vectors/VectorView.h +++ b/include/DataFrame/Vectors/VectorView.h @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once #include +#include #include #include @@ -42,11 +43,13 @@ namespace hmdf // continuous memory look like an STL vector. // It also gives you STL conformant iterators. // -template +template class VectorView { public: + static constexpr std::align_val_t align_value { A }; + using value_type = T; using size_type = unsigned long long int; using pointer = value_type *; @@ -404,11 +407,13 @@ class VectorView { // ---------------------------------------------------------------------------- -template +template class VectorConstView { public: + static constexpr std::align_val_t align_value { A }; + using value_type = T; using size_type = unsigned long long int; using pointer = const value_type *; diff --git a/src/CommonMakefile.mk b/src/CommonMakefile.mk index 676467416..8bf1fdaf8 100644 --- a/src/CommonMakefile.mk +++ b/src/CommonMakefile.mk @@ -10,8 +10,7 @@ PROJECT_INCLUDE_DIR = ../../include # ----------------------------------------------------------------------------- -SRCS = Vectors/HeteroVector.cc \ - ../test/dataframe_tester.cc \ +SRCS = ../test/dataframe_tester.cc \ ../test/dataframe_tester_2.cc \ ../test/dataframe_tester_3.cc \ ../examples/hello_world.cc \ @@ -19,10 +18,6 @@ SRCS = Vectors/HeteroVector.cc \ ../test/dataframe_tester_schema.cc \ ../benchmarks/dataframe_performance.cc \ ../benchmarks/dataframe_performance_2.cc \ - Vectors/HeteroView.cc \ - Vectors/HeteroConstView.cc \ - Vectors/HeteroPtrView.cc \ - Vectors/HeteroConstPtrView.cc \ ../test/vectors_tester.cc \ ../test/vector_ptr_view_tester.cc \ ../test/date_time_tester.cc \ @@ -100,12 +95,7 @@ DEFINES = -Wall -D_REENTRANT -DHMDF_HAVE_CLOCK_GETTIME \ # object file # -LIB_OBJS = $(LOCAL_OBJ_DIR)/HeteroVector.o \ - $(LOCAL_OBJ_DIR)/HeteroView.o \ - $(LOCAL_OBJ_DIR)/HeteroConstView.o \ - $(LOCAL_OBJ_DIR)/HeteroPtrView.o \ - $(LOCAL_OBJ_DIR)/HeteroConstPtrView.o \ - $(LOCAL_OBJ_DIR)/DateTime.o +LIB_OBJS = $(LOCAL_OBJ_DIR)/DateTime.o # ----------------------------------------------------------------------------- @@ -215,7 +205,8 @@ clobber: $(GEN_RAND_TESTER_OBJ) $(DATAFRAME_PERFORMACE_OBJ) \ $(DATAFRAME_TESTER_OBJ_2) $(DATAFRAME_THREAD_SAFTY_OBJ) \ $(DATAFRAME_TESTER_OBJ_3) $(HELLO_WORLD_OBJ) \ - $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) + $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) \ + $(DATAFRAME_PERFORMANCE_OBJ) $(DATAFRAME_PERFORMANCE_2_OBJ) install_lib: cp -pf $(TARGET_LIB) $(PROJECT_LIB_DIR)/. diff --git a/src/Vectors/HeteroConstPtrView.cc b/src/Vectors/HeteroConstPtrView.cc deleted file mode 100644 index 8d1a4d1d7..000000000 --- a/src/Vectors/HeteroConstPtrView.cc +++ /dev/null @@ -1,97 +0,0 @@ -// Hossein Moein -// November 4, 2022 -/* -Copyright (c) 2019-2026, Hossein Moein -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of Hossein Moein and/or the DataFrame nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include - -// ---------------------------------------------------------------------------- - -namespace hmdf -{ - -HeteroConstPtrView::HeteroConstPtrView() = default; - -HeteroConstPtrView::HeteroConstPtrView (const HeteroConstPtrView &that) { - - *this = that; -} -HeteroConstPtrView::HeteroConstPtrView (HeteroConstPtrView &&that) { - *this = that; -} - -// ---------------------------------------------------------------------------- - -HeteroConstPtrView &HeteroConstPtrView:: -operator= (const HeteroConstPtrView &rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = rhs.clear_function_; - copy_function_ = rhs.copy_function_; - move_function_ = rhs.move_function_; - - copy_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -HeteroConstPtrView &HeteroConstPtrView::operator= (HeteroConstPtrView &&rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = std::move(rhs.clear_function_); - copy_function_ = std::move(rhs.copy_function_); - move_function_ = std::move(rhs.move_function_); - - move_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -void HeteroConstPtrView::clear() { - - clear_function_(*this); -} - -} // namespace hmdf - -// ---------------------------------------------------------------------------- - -// Local Variables: -// mode:C++ -// tab-width:4 -// c-basic-offset:4 -// End diff --git a/src/Vectors/HeteroConstView.cc b/src/Vectors/HeteroConstView.cc deleted file mode 100644 index b9f3513b6..000000000 --- a/src/Vectors/HeteroConstView.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Hossein Moein -// November 3, 2022 -/* -Copyright (c) 2019-2026, Hossein Moein -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of Hossein Moein and/or the DataFrame nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include - -// ---------------------------------------------------------------------------- - -namespace hmdf -{ - -HeteroConstView::HeteroConstView() = default; - -HeteroConstView::HeteroConstView(const HeteroConstView &that) { *this = that; } -HeteroConstView::HeteroConstView(HeteroConstView &&that) { *this = that; } - -// ---------------------------------------------------------------------------- - -HeteroConstView &HeteroConstView::operator= (const HeteroConstView &rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = rhs.clear_function_; - copy_function_ = rhs.copy_function_; - move_function_ = rhs.move_function_; - - copy_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -HeteroConstView &HeteroConstView::operator= (HeteroConstView &&rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = std::move(rhs.clear_function_); - copy_function_ = std::move(rhs.copy_function_); - move_function_ = std::move(rhs.move_function_); - - move_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -void HeteroConstView::clear() { - - clear_function_(*this); -} - -} // namespace hmdf - -// ---------------------------------------------------------------------------- - -// Local Variables: -// mode:C++ -// tab-width:4 -// c-basic-offset:4 -// End diff --git a/src/Vectors/HeteroPtrView.cc b/src/Vectors/HeteroPtrView.cc deleted file mode 100644 index 2d198c310..000000000 --- a/src/Vectors/HeteroPtrView.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Hossein Moein -// June 24, 2019 -/* -Copyright (c) 2019-2026, Hossein Moein -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of Hossein Moein and/or the DataFrame nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include - -// ---------------------------------------------------------------------------- - -namespace hmdf -{ - -HeteroPtrView::HeteroPtrView() = default; - -HeteroPtrView::HeteroPtrView (const HeteroPtrView &that) { *this = that; } -HeteroPtrView::HeteroPtrView (HeteroPtrView &&that) { *this = that; } - -// ---------------------------------------------------------------------------- - -HeteroPtrView &HeteroPtrView::operator= (const HeteroPtrView &rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = rhs.clear_function_; - copy_function_ = rhs.copy_function_; - move_function_ = rhs.move_function_; - - copy_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -HeteroPtrView &HeteroPtrView::operator= (HeteroPtrView &&rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = std::move(rhs.clear_function_); - copy_function_ = std::move(rhs.copy_function_); - move_function_ = std::move(rhs.move_function_); - - move_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -void HeteroPtrView::clear() { - - clear_function_(*this); -} - -} // namespace hmdf - -// ---------------------------------------------------------------------------- - -// Local Variables: -// mode:C++ -// tab-width:4 -// c-basic-offset:4 -// End diff --git a/src/Vectors/HeteroVector.cc b/src/Vectors/HeteroVector.cc deleted file mode 100644 index 0f7481230..000000000 --- a/src/Vectors/HeteroVector.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Hossein Moein -// September 13, 2017 -/* -Copyright (c) 2019-2026, Hossein Moein -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of Hossein Moein and/or the DataFrame nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include - -// ---------------------------------------------------------------------------- - -namespace hmdf -{ - -HeteroVector::HeteroVector () { - - clear_functions_.reserve(2); - copy_functions_.reserve(2); - move_functions_.reserve(2); -} - -// ---------------------------------------------------------------------------- - -HeteroVector::HeteroVector (const HeteroVector &that) { *this = that; } -HeteroVector::HeteroVector (HeteroVector &&that) { *this = that; } - -// ---------------------------------------------------------------------------- - -HeteroVector &HeteroVector::operator= (const HeteroVector &rhs) { - - if (&rhs != this) { - clear(); - clear_functions_ = rhs.clear_functions_; - copy_functions_ = rhs.copy_functions_; - move_functions_ = rhs.move_functions_; - - for (auto &©_function : copy_functions_) - copy_function(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -HeteroVector &HeteroVector::operator= (HeteroVector &&rhs) { - - if (&rhs != this) { - clear(); - clear_functions_ = std::move(rhs.clear_functions_); - copy_functions_ = std::move(rhs.copy_functions_); - move_functions_ = std::move(rhs.move_functions_); - - for (auto &&move_function : move_functions_) - move_function(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -void HeteroVector::clear() { - - for (auto &&clear_func : clear_functions_) - clear_func (*this); -} - -} // namespace hmdf - -// ---------------------------------------------------------------------------- - -// Local Variables: -// mode:C++ -// tab-width:4 -// c-basic-offset:4 -// End diff --git a/src/Vectors/HeteroView.cc b/src/Vectors/HeteroView.cc deleted file mode 100644 index c24695369..000000000 --- a/src/Vectors/HeteroView.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Hossein Moein -// October 25, 2018 -/* -Copyright (c) 2019-2026, Hossein Moein -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of Hossein Moein and/or the DataFrame nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include - -// ---------------------------------------------------------------------------- - -namespace hmdf -{ - -HeteroView::HeteroView() = default; - -HeteroView::HeteroView (const HeteroView &that) { *this = that; } -HeteroView::HeteroView (HeteroView &&that) { *this = that; } - -// ---------------------------------------------------------------------------- - -HeteroView &HeteroView::operator= (const HeteroView &rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = rhs.clear_function_; - copy_function_ = rhs.copy_function_; - move_function_ = rhs.move_function_; - - copy_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -HeteroView &HeteroView::operator= (HeteroView &&rhs) { - - if (&rhs != this) { - clear(); - clear_function_ = std::move(rhs.clear_function_); - copy_function_ = std::move(rhs.copy_function_); - move_function_ = std::move(rhs.move_function_); - - move_function_(rhs, *this); - } - - return (*this); -} - -// ---------------------------------------------------------------------------- - -void HeteroView::clear() { - - clear_function_(*this); -} - -} // namespace hmdf - -// ---------------------------------------------------------------------------- - -// Local Variables: -// mode:C++ -// tab-width:4 -// c-basic-offset:4 -// End diff --git a/test/vectors_tester.cc b/test/vectors_tester.cc index 032c60fdb..569d6afc7 100644 --- a/test/vectors_tester.cc +++ b/test/vectors_tester.cc @@ -36,7 +36,8 @@ using namespace hmdf; // ----------------------------------------------------------------------------- -struct my_visitor : HeteroVector::visitor_base { +struct my_visitor : + HeteroVector<512>::visitor_base { template void operator() (T &i) { i += i; std::cout << "-- " << i << std::endl;} @@ -44,7 +45,8 @@ struct my_visitor : HeteroVector::visitor_base { // ----------------------------------------------------------------------------- -struct sort_functor : HeteroVector::visitor_base { +struct sort_functor : + HeteroVector<512>::visitor_base { template bool operator() (const T &lhs, const T &rhs) { @@ -55,7 +57,8 @@ struct sort_functor : HeteroVector::visitor_base { // ----------------------------------------------------------------------------- -struct change_functor : HeteroVector::visitor_base { +struct change_functor : + HeteroVector<512>::visitor_base { template void operator() (T &val) { @@ -69,11 +72,11 @@ struct change_functor : HeteroVector::visitor_base { int main(int, char *[]) { - HeteroVector hv; - HeteroVector hv2; - HeteroVector hv3; + HeteroVector<512> hv; + HeteroVector<512> hv2; + HeteroVector<512> hv3; - const std::vector &int_vec = hv.get_vector(); + const auto &int_vec = hv.get_vector(); hv.push_back (3); hv.emplace_back (4); @@ -102,8 +105,8 @@ int main(int, char *[]) { assert(v.at(3) == 1.05); - const HeteroVector &const_hv = hv; - HeteroConstView const_v = const_hv.get_view(); + const HeteroVector<512> &const_hv = hv; + HeteroConstView const_v = const_hv.get_view(); assert(const_v.at(3) == 1.05); @@ -121,8 +124,8 @@ int main(int, char *[]) { assert(v.at(3) == 1.05); - const HeteroVector &const_hv = hv; - HeteroConstPtrView const_v = const_hv.get_ptr_view(); + const HeteroVector<512> &const_hv = hv; + HeteroConstPtrView const_v = const_hv.get_ptr_view(); assert(const_v.at(3) == 1.05); @@ -140,7 +143,7 @@ int main(int, char *[]) { hv2 = hv; hv3 = std::move(hv2); - const std::vector &dbl_vec = hv3.get_vector(); + const auto &dbl_vec = hv3.get_vector(); for (const auto &iter : int_vec) std::cout << iter << std::endl; @@ -190,7 +193,7 @@ int main(int, char *[]) { vec_view[5] = 100; assert(vec_view[5] == 100); - VectorView::const_iterator item = vec_view.begin(); + VectorView::const_iterator item = vec_view.begin(); assert(*item == 1); assert(*(item++) == 1); From 852780e57405253b2da3c89fe77a6b1b09de3c01 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Mon, 19 Dec 2022 12:30:58 -0500 Subject: [PATCH 09/25] Lot of boilerplate clean ups --- benchmarks/dataframe_performance.cc | 15 +- include/DataFrame/DataFrame.h | 90 ++++----- include/DataFrame/Internals/DataFrame.tcc | 40 ++-- .../DataFrame/Internals/DataFrame_functors.h | 44 ++--- include/DataFrame/Internals/DataFrame_get.tcc | 91 ++++----- .../DataFrame/Internals/DataFrame_join.tcc | 73 +++---- .../DataFrame/Internals/DataFrame_misc.tcc | 16 +- .../Internals/DataFrame_private_decl.h | 50 ++--- .../DataFrame/Internals/DataFrame_read.tcc | 179 +++++++++--------- include/DataFrame/Internals/DataFrame_set.tcc | 61 +++--- .../DataFrame/Internals/DataFrame_shift.tcc | 8 +- .../Internals/DataFrame_standalone.tcc | 57 +++--- include/DataFrame/Internals/RandGen.tcc | 147 +++++++------- include/DataFrame/RandGen.h | 84 ++++---- test/dataframe_tester.cc | 60 ++++-- 15 files changed, 534 insertions(+), 481 deletions(-) diff --git a/benchmarks/dataframe_performance.cc b/benchmarks/dataframe_performance.cc index b63ad0372..91488ec3e 100644 --- a/benchmarks/dataframe_performance.cc +++ b/benchmarks/dataframe_performance.cc @@ -33,7 +33,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace hmdf; -typedef StdDataFrame MyDataFrame; +constexpr std::size_t ALIGNMENT = 64; + +typedef StdDataFrame64 MyDataFrame; // ----------------------------------------------------------------------------- @@ -43,15 +45,16 @@ int main(int, char *[]) { const auto first = time(nullptr); auto index_vec = - MyDataFrame::gen_datetime_index("01/01/1970", "08/15/2019", + MyDataFrame::gen_datetime_index("01/01/1980", "08/15/2019", time_frequency::secondly, 1); const auto index_sz = index_vec.size(); MyDataFrame df; - df.load_data(std::move(index_vec), - std::make_pair("normal", gen_normal_dist(index_sz)), - std::make_pair("log_normal", gen_lognormal_dist(index_sz)), - std::make_pair("exponential", gen_exponential_dist(index_sz))); + df.load_data( + std::move(index_vec), + std::make_pair("normal", gen_normal_dist(index_sz)), + std::make_pair("log_normal", gen_lognormal_dist(index_sz)), + std::make_pair("exponential", gen_exponential_dist(index_sz))); const auto second = time(nullptr); diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index 2cedfd3d7..45237104c 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -70,7 +70,9 @@ template class DataFrame : public ThreadGranularity { using DataVec = H; - using DataVecVec = std::vector; + using DataVecVec = + std::vector::type>; public: // Construction @@ -80,7 +82,7 @@ class DataFrame : public ThreadGranularity { template using AllocatorType = typename allocator_declare::type; - using size_type = typename std::vector::size_type; + using size_type = std::size_t; using IndexType = I; using IndexVecType = typename type_declare::type; @@ -140,7 +142,7 @@ class DataFrame : public ThreadGranularity { // Type of column being added // template - std::vector & + ColumnVecType & create_column(const char *name); // It removes a column named name. @@ -251,13 +253,13 @@ class DataFrame : public ThreadGranularity { template size_type load_column(const char *name, - std::vector &&data, + ColumnVecType &&data, nan_policy padding = nan_policy::pad_with_nans); template size_type load_column(const char *name, - const std::vector &data, + const ColumnVecType &data, nan_policy padding = nan_policy::pad_with_nans); // This method creates a column similar to above, but assumes data is @@ -297,7 +299,7 @@ class DataFrame : public ThreadGranularity { size_type load_align_column( const char *name, - std::vector &&data, + ColumnVecType &&data, size_type interval, bool start_from_beginning, const T &null_value = hmdf::get_nan(), @@ -375,7 +377,7 @@ class DataFrame : public ThreadGranularity { // template size_type - from_indicators(const std::vector &ind_col_names, + from_indicators(const ColumnVecType &ind_col_names, const char *cat_col_name, const char *numeric_cols_prefix = nullptr); @@ -795,7 +797,7 @@ class DataFrame : public ThreadGranularity { // template void - shuffle(const std::vector &col_names, + shuffle(const ColumnVecType &col_names, bool also_shuffle_index); // It fills all the "missing values" with the given values, and/or using @@ -822,9 +824,9 @@ class DataFrame : public ThreadGranularity { // template void - fill_missing(const std::vector &col_names, + fill_missing(const ColumnVecType &col_names, fill_policy policy, - const std::vector &values = { }, + const ColumnVecType &values = { }, int limit = -1); // It fills the missing values in all columns in self by investigating the @@ -887,8 +889,8 @@ class DataFrame : public ThreadGranularity { template size_type replace(const char *col_name, - const std::vector &old_values, - const std::vector &new_values, + const ColumnVecType &old_values, + const ColumnVecType &new_values, int limit = -1); // Same as replace() above, but executed asynchronously @@ -899,8 +901,8 @@ class DataFrame : public ThreadGranularity { template [[nodiscard]] std::future replace_async(const char *col_name, - const std::vector &old_values, - const std::vector &new_values, + const ColumnVecType &old_values, + const ColumnVecType &new_values, int limit = -1); // This is similar to replace() above but it lets a functor replace the @@ -946,8 +948,8 @@ class DataFrame : public ThreadGranularity { // Limit of how many items to replace. Default is to replace all. // size_type - replace_index(const std::vector &old_values, - const std::vector &new_values, + replace_index(const ColumnVecType &old_values, + const ColumnVecType &new_values, int limit = -1); // Sort the DataFrame by the named column. If name equals "INDEX" or @@ -1464,7 +1466,7 @@ class DataFrame : public ThreadGranularity { // Specifies the direction. In this case it is only up or down. // template - [[nodiscard]] std::vector + [[nodiscard]] ColumnVecType shift(const char *col_name, size_type periods, shift_policy sp) const; // It rotates all the columns in self up, down, left, or right based on @@ -1608,7 +1610,7 @@ class DataFrame : public ThreadGranularity { template [[nodiscard]] HeteroVector get_row(size_type row_num, - const std::vector &col_names) const; + const ColumnVecType &col_names) const; // This is same as get_row() above. But it always includes all the columns // in the returned row. The order is the column creation order. If you @@ -1639,7 +1641,7 @@ class DataFrame : public ThreadGranularity { // Data type of the named column // template - [[nodiscard]] std::vector + [[nodiscard]] ColumnVecType get_col_unique_values(const char *name) const; // It returns a DataFrame (including the index and data columns) @@ -1672,7 +1674,7 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] DataFrame - get_data_by_idx(const std::vector &values) const; + get_data_by_idx(const ColumnVecType &values) const; // It behaves like get_data_by_idx(range), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. @@ -1716,11 +1718,11 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] PtrView - get_view_by_idx(const std::vector &values); + get_view_by_idx(const ColumnVecType &values); template [[nodiscard]] ConstPtrView - get_view_by_idx(const std::vector &values) const; + get_view_by_idx(const ColumnVecType &values) const; // It returns a DataFrame (including the index and data columns) // containing the data from location begin to location end within range. @@ -1753,7 +1755,7 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] DataFrame - get_data_by_loc(const std::vector &locations) const; + get_data_by_loc(const ColumnVecType &locations) const; // It behaves like get_data_by_loc(range), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. @@ -1797,11 +1799,11 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] PtrView - get_view_by_loc(const std::vector &locations); + get_view_by_loc(const ColumnVecType &locations); template [[nodiscard]] ConstPtrView - get_view_by_loc(const std::vector &locations) const; + get_view_by_loc(const ColumnVecType &locations) const; // This method does boolean filtering selection via the sel_functor // (e.g. a functor, function, or lambda). It returns a new DataFrame. @@ -2332,7 +2334,7 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] DataFrame - get_data(const std::vector &col_names) const; + get_data(const ColumnVecType &col_names) const; // It behaves like get_data(), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. @@ -2351,11 +2353,11 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] View - get_view(const std::vector &col_names); + get_view(const ColumnVecType &col_names); template [[nodiscard]] ConstView - get_view(const std::vector &col_names) const; + get_view(const ColumnVecType &col_names) const; // It returns a const reference to the index container // @@ -2490,7 +2492,7 @@ class DataFrame : public ThreadGranularity { // T func(const T &self_data, const T &rhs_data) // template - [[nodiscard]] std::vector + [[nodiscard]] ColumnVecType combine(const char *col_name, const DF &rhs, F &functor) const; // Same as the combine() above but it combines 3 columns. @@ -2517,7 +2519,7 @@ class DataFrame : public ThreadGranularity { // T func(const T &self_data, const T &df1_data, const T &df2_data) // template - [[nodiscard]] std::vector + [[nodiscard]] ColumnVecType combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2555,7 +2557,7 @@ class DataFrame : public ThreadGranularity { // const T &df3_data) // template - [[nodiscard]] std::vector + [[nodiscard]] ColumnVecType combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2563,18 +2565,18 @@ class DataFrame : public ThreadGranularity { F &functor) const; // This method feeds old_col_name1 and old_col_name2 of types OLD_T1 and - // OLD_T2 to functor which returns a std::vector which will be + // OLD_T2 to functor which returns a ColumnVecType which will be // loaded into self as column new_col_name. Both old columns will be // removed, if delete_old_cols is true // Functor "functor" should implement the logic of consolidating two // columns into one. Functor signature is: // template - // std::vector (IndexVecType::const_iterator idx_begin, + // ColumnVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end); // Where ITR[12] are iterators for columns 1 and 2. They are iterators - // of std::vector. + // of ColumnVecType. // // NOTE: This method could not be called from views. // @@ -2610,13 +2612,13 @@ class DataFrame : public ThreadGranularity { // into one. // Functor signature is: // template - // std::vector (IndexVecType::const_iterator idx_begin, + // ColumnVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end, // ITR3 col3_begin, ITR3 col3_end); // Where ITR[123] are iterators for columns 1, 2 and 3. They are - // iterators of std::vector. + // iterators of ColumnVecType. // // NOTE: This method could not be called from views. // @@ -2659,14 +2661,14 @@ class DataFrame : public ThreadGranularity { // Functor signature is: // template - // std::vector (IndexVecType::const_iterator idx_begin, + // ColumnVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end, // ITR3 col3_begin, ITR3 col3_end, // ITR4 col4_begin, ITR4 col4_end); // Where ITR[1234] are iterators for columns 1, 2, 3, and 4. They are - // iterators of std::vector. + // iterators of ColumnVecType. // // NOTE: This method could not be called from views. // @@ -2715,7 +2717,7 @@ class DataFrame : public ThreadGranularity { // Functor signature is: // template - // std::vector (IndexVecType::const_iterator idx_begin, + // ColumnVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end, @@ -2723,7 +2725,7 @@ class DataFrame : public ThreadGranularity { // ITR4 col4_begin, ITR4 col4_end, // ITR5 col5_begin, ITR5 col5_end); // Where ITR[12345] are iterators for columns 1, 2, 3, 4, and 5. - // They are iterators of std::vector. + // They are iterators of ColumnVecType. // // NOTE: This method could not be called from views. // @@ -3495,7 +3497,7 @@ class DataFrame : public ThreadGranularity { // the list only once. // template - [[nodiscard]] std::vector> get_columns_info() const; @@ -3563,7 +3565,7 @@ class DataFrame : public ThreadGranularity { // NOTE: It is the responsibility of the programmer to make sure // IndexType type is big enough to contain the frequency. // - static std::vector + static ColumnVecType gen_datetime_index(const char *start_datetime, const char *end_datetime, time_frequency t_freq, @@ -3584,7 +3586,7 @@ class DataFrame : public ThreadGranularity { // increment: // Increment by value // - static std::vector + static ColumnVecType gen_sequence_index(const IndexType &start_value, const IndexType &end_value, long increment = 1); @@ -3777,7 +3779,7 @@ class DataFrame : public ThreadGranularity { using ColNameDict = std::unordered_map>; - using ColNameList = std::vector>; + using ColNameList = ColumnVecType>; // Data fields // diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index f00f41656..d45f9c604 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -123,7 +123,7 @@ template void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { const size_type idx_s = df.indices_.size(); - std::vector sorting_idxs(idx_s, 0); + ColumnVecType sorting_idxs(idx_s, 0); std::iota(sorting_idxs.begin(), sorting_idxs.end(), 0); std::sort(sorting_idxs.begin(), sorting_idxs.end(), comp_func); @@ -143,7 +143,7 @@ void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { template template void -DataFrame::shuffle(const std::vector &col_names, +DataFrame::shuffle(const ColumnVecType &col_names, bool also_shuffle_index) { if (also_shuffle_index) { @@ -394,13 +394,13 @@ fill_missing_linter_(ColumnVecType &vec, template template void DataFrame:: -fill_missing(const std::vector &col_names, +fill_missing(const ColumnVecType &col_names, fill_policy fp, - const std::vector &values, + const ColumnVecType &values, int limit) { const size_type count = col_names.size(); - std::vector> futures(get_thread_level()); + ColumnVecType> futures(get_thread_level()); size_type thread_count = 0; for (size_type i = 0; i < count; ++i) { @@ -581,8 +581,8 @@ template template typename DataFrame::size_type DataFrame:: replace(const char *col_name, - const std::vector &old_values, - const std::vector &new_values, + const ColumnVecType &old_values, + const ColumnVecType &new_values, int limit) { ColumnVecType &vec = get_column(col_name); @@ -598,8 +598,8 @@ replace(const char *col_name, template typename DataFrame::size_type DataFrame:: -replace_index(const std::vector &old_values, - const std::vector &new_values, +replace_index(const ColumnVecType &old_values, + const ColumnVecType &new_values, int limit) { size_type count = 0; @@ -632,16 +632,16 @@ template template std::future::size_type> DataFrame:: replace_async(const char *col_name, - const std::vector &old_values, - const std::vector &new_values, + const ColumnVecType &old_values, + const ColumnVecType &new_values, int limit) { return (std::async(std::launch::async, &DataFrame::replace, this, col_name, - std::forward>(old_values), - std::forward>(new_values), + std::forward>(old_values), + std::forward>(new_values), limit)); } @@ -1146,7 +1146,7 @@ groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { else gb_vec = (const ColumnVecType *) &(get_column(col_name)); - std::vector sort_v (gb_vec->size(), 0); + ColumnVecType sort_v (gb_vec->size(), 0); std::iota(sort_v.begin(), sort_v.end(), 0); std::sort(sort_v.begin(), sort_v.end(), @@ -1203,7 +1203,7 @@ groupby2(const char *col_name1, gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); } - std::vector sort_v (std::min(gb_vec1->size(), + ColumnVecType sort_v (std::min(gb_vec1->size(), gb_vec2->size()), 0); @@ -1280,7 +1280,7 @@ groupby3(const char *col_name1, gb_vec3 = (const ColumnVecType *) &(get_column(col_name3)); } - std::vector sort_v( + ColumnVecType sort_v( std::min({ gb_vec1->size(), gb_vec2->size(), gb_vec3->size() }), 0); std::iota(sort_v.begin(), sort_v.end(), 0); @@ -1422,8 +1422,8 @@ DataFrame::value_counts (const char *col_name) const { insert_result.first->second += 1; } - std::vector res_indices; - std::vector counts; + ColumnVecType res_indices; + ColumnVecType counts; counts.reserve(values_map.size()); res_indices.reserve(values_map.size()); @@ -1517,13 +1517,13 @@ transpose(IndexVecType &&indices, const V &new_col_names) const { "Length of new_col_names is not equal " "to number of rows"); - std::vector *> current_cols; + ColumnVecType *> current_cols; current_cols.reserve(num_cols); for (const auto &citer : column_list_) current_cols.push_back(&(get_column(citer.first.c_str()))); - std::vector> trans_cols(indices_.size()); + ColumnVecType> trans_cols(indices_.size()); DataFrame df; for (size_type i = 0; i < indices_.size(); ++i) { diff --git a/include/DataFrame/Internals/DataFrame_functors.h b/include/DataFrame/Internals/DataFrame_functors.h index 32609b7d4..bdd951e01 100644 --- a/include/DataFrame/Internals/DataFrame_functors.h +++ b/include/DataFrame/Internals/DataFrame_functors.h @@ -63,11 +63,11 @@ struct shrink_to_fit_functor_ : DataVec::template visitor_base { template struct sort_functor_ : DataVec::template visitor_base { - inline sort_functor_ (const std::vector &si, size_t is) + inline sort_functor_ (const ColumnVecType &si, size_t is) : sorted_idxs(si), idx_s(is) { } - const std::vector &sorted_idxs; - std::vector sorted_idxs_copy; + const ColumnVecType &sorted_idxs; + ColumnVecType sorted_idxs_copy; const size_t idx_s; template @@ -373,9 +373,9 @@ friend struct rotate_functor_; template class OPT, typename ... Ts> struct operator_functor_ : DataVec::template visitor_base { - inline operator_functor_ (const std::vector &lhsidx, - const std::vector &rhsidx, - const std::vector &newidx, + inline operator_functor_ (const ColumnVecType &lhsidx, + const ColumnVecType &rhsidx, + const ColumnVecType &newidx, const StdDataFrame &rhsdf, const char *colname, StdDataFrame &resultdf) @@ -386,9 +386,9 @@ struct operator_functor_ : DataVec::template visitor_base { col_name(colname), result_df(resultdf) { } - const std::vector &lhs_idx; - const std::vector &rhs_idx; - const std::vector &new_idx; + const ColumnVecType &lhs_idx; + const ColumnVecType &rhs_idx; + const ColumnVecType &new_idx; const StdDataFrame &rhs_df; const char *col_name; StdDataFrame &result_df; @@ -458,13 +458,13 @@ template struct sel_load_functor_ : DataVec::template visitor_base { inline sel_load_functor_ (const char *n, - const std::vector &si, + const ColumnVecType &si, size_type is, DataFrame &d) : name (n), sel_indices (si), indices_size(is), df(d) { } const char *name; - const std::vector &sel_indices; + const ColumnVecType &sel_indices; const size_type indices_size; DataFrame &df; @@ -478,13 +478,13 @@ template struct sel_load_view_functor_ : DataVec::template visitor_base { inline sel_load_view_functor_ (const char *n, - const std::vector &si, + const ColumnVecType &si, size_type is, DF &d) : name (n), sel_indices (si), indices_size(is), dfv(d) { } const char *name; - const std::vector &sel_indices; + const ColumnVecType &sel_indices; const size_type indices_size; DF &dfv; @@ -512,10 +512,10 @@ struct concat_load_view_functor_ : DataVec::template visitor_base { template struct sel_remove_functor_ : DataVec::template visitor_base { - inline sel_remove_functor_ (const std::vector &si) + inline sel_remove_functor_ (const ColumnVecType &si) : sel_indices (si) { } - const std::vector &sel_indices; + const ColumnVecType &sel_indices; template void operator() (T &vec) const; @@ -539,12 +539,12 @@ struct random_load_data_functor_ : DataVec::template visitor_base { inline random_load_data_functor_ ( const char *n, - const std::vector &ri, + const ColumnVecType &ri, DataFrame &d) : name (n), rand_indices (ri), df(d) { } const char *name; - const std::vector &rand_indices; + const ColumnVecType &rand_indices; DataFrame &df; template @@ -558,12 +558,12 @@ struct random_load_view_functor_ : DataVec::template visitor_base { inline random_load_view_functor_ ( const char *n, - const std::vector &ri, + const ColumnVecType &ri, DF &d) : name (n), rand_indices (ri), dfv(d) { } const char *name; - const std::vector &rand_indices; + const ColumnVecType &rand_indices; DF &dfv; template @@ -576,7 +576,7 @@ template struct columns_info_functor_ : DataVec::template visitor_base { using result_t = - std::vector>; + ColumnVecType>; inline columns_info_functor_ (result_t &r, const char *n) : result(r), name(n) { } @@ -594,12 +594,12 @@ template struct copy_remove_functor_ : DataVec::template visitor_base { inline copy_remove_functor_ (const char *n, - const std::vector &td, + const ColumnVecType &td, DataFrame &d) : name(n), to_delete (td), df(d) { } const char *name; - const std::vector &to_delete; + const ColumnVecType &to_delete; DataFrame &df; template diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index e18f6f082..fabb400fe 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -216,7 +216,7 @@ DataFrame::get_index() { return (indices_); } template template HeteroVector DataFrame:: -get_row(size_type row_num, const std::vector &col_names) const { +get_row(size_type row_num, const ColumnVecType &col_names) const { if (row_num >= indices_.size()) { char buffer [512]; @@ -297,7 +297,7 @@ get_row(size_type row_num) const { template template -std::vector DataFrame:: +typename DataFrame::template ColumnVecType DataFrame:: get_col_unique_values(const char *name) const { const ColumnVecType &vec = get_column(name); @@ -316,7 +316,7 @@ get_col_unique_values(const char *name) const { decltype(hash_func), decltype(equal_func)> table(vec.size(), hash_func, equal_func); bool counted_nan = false; - std::vector result; + ColumnVecType result; result.reserve(vec.size()); for (const auto &citer : vec) { @@ -376,11 +376,11 @@ DataFrame::get_data_by_idx (Index2D range) const { template template DataFrame DataFrame:: -get_data_by_idx(const std::vector &values) const { +get_data_by_idx(const ColumnVecType &values) const { const std::unordered_set val_table(values.begin(), values.end()); IndexVecType new_index; - std::vector locations; + ColumnVecType locations; const size_type values_s = values.size(); const size_type idx_s = indices_.size(); @@ -501,7 +501,7 @@ DataFrame::get_view_by_idx (Index2D range) const { template template typename DataFrame::PtrView DataFrame:: -get_view_by_idx(const std::vector &values) { +get_view_by_idx(const ColumnVecType &values) { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); @@ -511,7 +511,7 @@ get_view_by_idx(const std::vector &values) { const std::unordered_set val_table(values.begin(), values.end()); typename TheView::IndexVecType new_index; - std::vector locations; + ColumnVecType locations; const size_type values_s = values.size(); const size_type idx_s = indices_.size(); @@ -549,7 +549,7 @@ template template typename DataFrame::ConstPtrView DataFrame:: -get_view_by_idx(const std::vector &values) const { +get_view_by_idx(const ColumnVecType &values) const { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); @@ -559,7 +559,7 @@ get_view_by_idx(const std::vector &values) const { const std::unordered_set val_table(values.begin(), values.end()); typename TheView::IndexVecType new_index; - std::vector locations; + ColumnVecType locations; const size_type values_s = values.size(); const size_type idx_s = indices_.size(); @@ -638,7 +638,7 @@ DataFrame::get_data_by_loc (Index2D range) const { template template DataFrame DataFrame:: -get_data_by_loc (const std::vector &locations) const { +get_data_by_loc (const ColumnVecType &locations) const { const size_type idx_s = indices_.size(); DataFrame df; @@ -768,7 +768,7 @@ DataFrame::get_view_by_loc (Index2D range) const { template template typename DataFrame::PtrView -DataFrame::get_view_by_loc (const std::vector &locations) { +DataFrame::get_view_by_loc (const ColumnVecType &locations) { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -809,7 +809,7 @@ template template typename DataFrame::ConstPtrView DataFrame:: -get_view_by_loc (const std::vector &locations) const { +get_view_by_loc (const ColumnVecType &locations) const { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -854,7 +854,7 @@ get_data_by_sel (const char *name, F &sel_functor) const { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) @@ -896,7 +896,7 @@ get_view_by_sel (const char *name, F &sel_functor) { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) @@ -941,7 +941,7 @@ get_view_by_sel (const char *name, F &sel_functor) const { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) @@ -985,7 +985,7 @@ get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1035,7 +1035,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1088,7 +1088,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1142,7 +1142,7 @@ get_data_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1201,7 +1201,7 @@ get_data_by_sel (F &sel_functor) const { cols_for_filter); // Get the index of all records that meet the filters - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) { @@ -1266,7 +1266,7 @@ get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { cols_for_filter); // Get the index of all records that meet the filters - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) { @@ -1326,7 +1326,7 @@ get_view_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1385,7 +1385,7 @@ get_view_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1445,7 +1445,7 @@ get_data_by_sel(const char *name1, const size_type col_s4 = vec4.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1507,7 +1507,7 @@ get_view_by_sel(const char *name1, const size_type col_s4 = vec4.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1572,7 +1572,7 @@ get_view_by_sel(const char *name1, const size_type col_s4 = vec4.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1636,7 +1636,7 @@ get_data_by_sel(const char *name1, const size_type col_s5 = vec5.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4, col_s5 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1703,7 +1703,7 @@ get_view_by_sel(const char *name1, const size_type col_s5 = vec5.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4, col_s5 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1773,7 +1773,7 @@ get_view_by_sel(const char *name1, const size_type col_s5 = vec5.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4, col_s5 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1842,7 +1842,7 @@ get_data_by_rand(random_policy spec, double n, size_type seed) const { if (use_seed) gen.seed(static_cast(seed)); std::uniform_int_distribution dis(0, index_s - 1); - std::vector rand_indices(n_rows); + ColumnVecType rand_indices(n_rows); for (size_type i = 0; i < n_rows; ++i) rand_indices[i] = dis(gen); @@ -1916,7 +1916,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) { if (use_seed) gen.seed(static_cast(seed)); std::uniform_int_distribution dis(0, index_s - 1); - std::vector rand_indices(n_rows); + ColumnVecType rand_indices(n_rows); for (size_type i = 0; i < n_rows; ++i) rand_indices[i] = dis(gen); @@ -1991,7 +1991,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { if (use_seed) gen.seed(static_cast(seed)); std::uniform_int_distribution dis(0, index_s - 1); - std::vector rand_indices(n_rows); + ColumnVecType rand_indices(n_rows); for (size_type i = 0; i < n_rows; ++i) rand_indices[i] = dis(gen); @@ -2042,7 +2042,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { template template DataFrame DataFrame:: -get_data(const std::vector &col_names) const { +get_data(const ColumnVecType &col_names) const { DataFrame df; @@ -2074,7 +2074,7 @@ get_data(const std::vector &col_names) const { template template typename DataFrame::View DataFrame:: -get_view(const std::vector &col_names) { +get_view(const ColumnVecType &col_names) { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view()"); @@ -2115,7 +2115,7 @@ template template typename DataFrame::ConstView DataFrame:: -get_view(const std::vector &col_names) const { +get_view(const ColumnVecType &col_names) const { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view()"); @@ -2287,12 +2287,13 @@ get_reindexed_view(const char *col_to_be_index, template template -std::vector::ColNameType, - typename DataFrame::size_type, - std::type_index>> +typename DataFrame::template ColumnVecType< + std::tuple::ColNameType, + typename DataFrame::size_type, + std::type_index>> DataFrame::get_columns_info () const { - std::vector> result; + ColumnVecType> result; result.reserve(column_list_.size()); @@ -2364,13 +2365,13 @@ pattern_match(const char *col_name, template template -std::vector DataFrame:: +typename DataFrame::template ColumnVecType DataFrame:: combine(const char *col_name, const DF &rhs, F &functor) const { const auto &lhs_col = get_column(col_name); const auto &rhs_col = rhs.template get_column(col_name); const size_type col_s = std::min(lhs_col.size(), rhs_col.size()); - std::vector result; + ColumnVecType result; result.reserve(col_s); for (size_type i = 0; i < col_s; ++i) @@ -2383,7 +2384,7 @@ combine(const char *col_name, const DF &rhs, F &functor) const { template template -std::vector DataFrame:: +typename DataFrame::template ColumnVecType DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2394,7 +2395,7 @@ combine(const char *col_name, const auto &df2_col = df2.template get_column(col_name); const size_type col_s = std::min({ lhs_col.size(), df1_col.size(), df2_col.size() }); - std::vector result; + ColumnVecType result; result.reserve(col_s); for (size_type i = 0; i < col_s; ++i) @@ -2408,7 +2409,7 @@ combine(const char *col_name, template template -std::vector DataFrame:: +typename DataFrame::template ColumnVecType DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2421,7 +2422,7 @@ combine(const char *col_name, const auto &df3_col = df3.template get_column(col_name); const size_type col_s = std::min( { lhs_col.size(), df1_col.size(), df2_col.size(), df3_col.size() }); - std::vector result; + ColumnVecType result; result.reserve(col_s); for (size_type i = 0; i < col_s; ++i) diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index 9fdf4f9e4..ffd2866aa 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -54,8 +54,8 @@ join_by_index (const RHS_T &rhs, join_policy mp) const { const auto &rhs_idx = rhs.get_index(); const size_type lhs_idx_s = lhs_idx.size(); const size_type rhs_idx_s = rhs_idx.size(); - std::vector> idx_vec_lhs; - std::vector> idx_vec_rhs; + ColumnVecType> idx_vec_lhs; + ColumnVecType> idx_vec_rhs; idx_vec_lhs.reserve(lhs_idx_s); for (size_type i = 0; i < lhs_idx_s; ++i) @@ -116,8 +116,8 @@ join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { const size_type lhs_vec_s = lhs_vec.size(); const size_type rhs_vec_s = rhs_vec.size(); - std::vector> col_vec_lhs; - std::vector> col_vec_rhs; + ColumnVecType> col_vec_lhs; + ColumnVecType> col_vec_rhs; col_vec_lhs.reserve(lhs_vec_s); for (size_type i = 0; i < lhs_vec_s; ++i) @@ -222,7 +222,7 @@ index_join_helper_(const LHS_T &lhs, const IndexIdxVector &joined_index_idx) { DataFrame> result; - std::vector result_index; + ColumnVecType result_index; // Load the index result_index.reserve(joined_index_idx.size()); @@ -266,9 +266,9 @@ column_join_helper_(const LHS_T &lhs, // Load the lhs and rhs indices into two columns in the result // Also load the unified named column - std::vector lhs_index; - std::vector rhs_index; - std::vector named_col_vec; + ColumnVecType lhs_index; + ColumnVecType rhs_index; + ColumnVecType named_col_vec; const ColumnVecType &lhs_named_col_vec = lhs.template get_column(col_name); const ColumnVecType &rhs_named_col_vec = @@ -314,8 +314,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_inner_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -346,9 +346,10 @@ DataFrame::get_inner_index_idx_vector_( template template DataFrame> DataFrame:: -index_inner_join_(const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { +index_inner_join_( + const LHS_T &lhs, const RHS_T &rhs, + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (index_join_helper_ (lhs, rhs, @@ -364,8 +365,8 @@ DataFrame:: column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, @@ -378,8 +379,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_left_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -419,8 +420,8 @@ template template DataFrame> DataFrame:: index_left_join_(const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (index_join_helper_ (lhs, rhs, @@ -436,8 +437,8 @@ DataFrame:: column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, @@ -450,8 +451,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_right_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -494,9 +495,10 @@ DataFrame::get_right_index_idx_vector_( template template DataFrame> DataFrame:: -index_right_join_(const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { +index_right_join_( + const LHS_T &lhs, const RHS_T &rhs, + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (index_join_helper_ (lhs, rhs, @@ -507,12 +509,13 @@ index_right_join_(const LHS_T &lhs, const RHS_T &rhs, template template -DataFrame> DataFrame:: +DataFrame> +DataFrame:: column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, @@ -525,8 +528,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_left_right_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -579,8 +582,8 @@ DataFrame> DataFrame:: index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (index_join_helper_ (lhs, rhs, @@ -596,8 +599,8 @@ DataFrame:: column_left_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs) { + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, diff --git a/include/DataFrame/Internals/DataFrame_misc.tcc b/include/DataFrame/Internals/DataFrame_misc.tcc index b8b1bd3a2..7c80e5c01 100644 --- a/include/DataFrame/Internals/DataFrame_misc.tcc +++ b/include/DataFrame/Internals/DataFrame_misc.tcc @@ -375,8 +375,8 @@ index_join_functor_common_::operator()(const T &lhs_vec) { using ValueType = typename VecType::value_type; const ColumnVecType &rhs_vec = rhs.get_column(name); - std::vector lhs_result_col; - std::vector rhs_result_col; + ColumnVecType lhs_result_col; + ColumnVecType rhs_result_col; lhs_result_col.reserve(joined_index_idx.size()); rhs_result_col.reserve(joined_index_idx.size()); @@ -412,7 +412,7 @@ operator()(const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; - std::vector result_col; + ColumnVecType result_col; result_col.reserve(joined_index_idx.size()); for (const auto &citer : joined_index_idx) { @@ -438,14 +438,14 @@ operator()(const T &vec) { using ValueType = typename VecType::value_type; if (insert_col) { - std::vector res_vec(original_index_s + vec.size(), + ColumnVecType res_vec(original_index_s + vec.size(), get_nan()); std::copy(vec.begin(), vec.end(), res_vec.begin() + original_index_s); result.load_column(name, res_vec); } else { - std::vector &res_vec = + ColumnVecType &res_vec = result.template get_column(name); res_vec.insert(res_vec.end(), vec.begin(), vec.end()); @@ -507,7 +507,7 @@ operator()(const T &lhs_vec) { const size_type new_col_size = std::min(std::min(lhs_vec.size(), rhs_vec.size()), new_idx.size()); - std::vector new_col; + ColumnVecType new_col; auto Operator = OPT(); size_type lcounter = 0; size_type rcounter = 0; @@ -602,7 +602,7 @@ operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; - std::vector new_col; + ColumnVecType new_col; const size_type vec_size = vec.size(); new_col.reserve(std::min(sel_indices.size(), vec_size)); @@ -886,7 +886,7 @@ DataFrame::describe_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; - std::vector col_to_load; + ColumnVecType col_to_load; col_to_load.reserve(describe_index_col.size()); col_to_load.push_back(double(vec_s)); diff --git a/include/DataFrame/Internals/DataFrame_private_decl.h b/include/DataFrame/Internals/DataFrame_private_decl.h index bfd5316c2..fd5c5ea36 100644 --- a/include/DataFrame/Internals/DataFrame_private_decl.h +++ b/include/DataFrame/Internals/DataFrame_private_decl.h @@ -117,7 +117,7 @@ template void setup_view_column_(const char *name, Index2D range); -using IndexIdxVector = std::vector>; +using IndexIdxVector = ColumnVecType>; template using JoinSortingPair = std::pair; @@ -147,65 +147,65 @@ column_join_helper_(const LHS_T &lhs, template static IndexIdxVector get_inner_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> index_inner_join_( const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static IndexIdxVector get_left_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> index_left_join_( const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static IndexIdxVector get_right_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> index_right_join_( const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame @@ -221,15 +221,15 @@ concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns); template static IndexIdxVector get_left_right_index_idx_vector_( - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); template static DataFrame> @@ -237,8 +237,8 @@ column_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const std::vector> &col_vec_lhs, - const std::vector> &col_vec_rhs); + const ColumnVecType> &col_vec_lhs, + const ColumnVecType> &col_vec_rhs); // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Internals/DataFrame_read.tcc b/include/DataFrame/Internals/DataFrame_read.tcc index 1b35feb24..166afd6ad 100644 --- a/include/DataFrame/Internals/DataFrame_read.tcc +++ b/include/DataFrame/Internals/DataFrame_read.tcc @@ -171,19 +171,19 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { } else { if (! ::strcmp(col_type, "float")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtof, io_format::json); } else if (! ::strcmp(col_type, "double")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtod, io_format::json); } else if (! ::strcmp(col_type, "longdouble")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -193,13 +193,13 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "int")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtol, io_format::json); } else if (! ::strcmp(col_type, "uint")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -209,13 +209,13 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "long")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtol, io_format::json); } else if (! ::strcmp(col_type, "longlong")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -225,7 +225,7 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "ulong")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -235,7 +235,7 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "ulonglong")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -243,24 +243,24 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { (vec, stream, &::strtoull, io_format::json); } else if (! ::strcmp(col_type, "string")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); _json_str_col_vector_push_back_(vec, stream); } else if (! ::strcmp(col_type, "DateTime")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); auto converter = [](const char *, char **)-> DateTime { return DateTime(); }; vec.reserve(col_size); - _col_vector_push_back_> + _col_vector_push_back_> (vec, stream, converter, io_format::json); } else if (! ::strcmp(col_type, "bool")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtol, io_format::json); @@ -333,86 +333,86 @@ void DataFrame::read_csv_(std::istream &stream, bool columns_only) { } else { if (! ::strcmp(type_str, "float")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtof); } else if (! ::strcmp(type_str, "double")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtod); } else if (! ::strcmp(type_str, "longdouble")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtold); } else if (! ::strcmp(type_str, "int")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtol); } else if (! ::strcmp(type_str, "uint")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoul); } else if (! ::strcmp(type_str, "long")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtol); } else if (! ::strcmp(type_str, "longlong")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoll); } else if (! ::strcmp(type_str, "ulong")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoul); } else if (! ::strcmp(type_str, "ulonglong")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoull); } else if (! ::strcmp(type_str, "string")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); auto converter = [](const char *s, char **)-> const char * { return s; }; vec.reserve(::atoi(value)); - _col_vector_push_back_> + _col_vector_push_back_> (vec, stream, converter); } else if (! ::strcmp(type_str, "DateTime")) { - std::vector &vec = + ColumnVecType &vec = create_column(col_name); auto converter = [](const char *, char **)-> DateTime { return DateTime(); }; vec.reserve(::atoi(value)); - _col_vector_push_back_> + _col_vector_push_back_> (vec, stream, converter); } else if (! ::strcmp(type_str, "bool")) { - std::vector &vec = create_column(col_name); + ColumnVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtol); @@ -432,14 +432,14 @@ struct _col_data_spec_ { String32 type_spec { }; String64 col_name { }; - template - inline _col_data_spec_(std::vector cv, + template class V> + inline _col_data_spec_(V cv, const char *ts, const char *cn, std::size_t rs) : col_vec(cv), type_spec(ts), col_name(cn) { - std::any_cast &>(col_vec).reserve(rs); + std::any_cast &>(col_vec).reserve(rs); } }; @@ -450,7 +450,7 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { char value[8192]; char c; - std::vector<_col_data_spec_> spec_vec; + ColumnVecType<_col_data_spec_> spec_vec; bool header_read = false; size_type col_index = 0; @@ -484,63 +484,63 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { if (c == '\n' || c == '\r') header_read = true; if (! ::strcmp(type_str, "float")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "double")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "longdouble")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "int")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "uint")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "long")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "longlong")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "ulong")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "ulonglong")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "string")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); // This includes DateTime, DateTimeAME, DateTimeEUR, DateTimeISO else if (! ::strncmp(type_str, "DateTime", 8)) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "bool")) - spec_vec.emplace_back(std::vector(), + spec_vec.emplace_back(ColumnVecType(), type_str, col_name, ::atoi(value)); @@ -555,48 +555,48 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { if (col_spec.type_spec == "float") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back(strtof(value, nullptr)); } else if (col_spec.type_spec == "double") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back(strtod(value, nullptr)); } else if (col_spec.type_spec == "longdouble") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back(strtold(value, nullptr)); } else if (col_spec.type_spec == "int") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( (int) strtol(value, nullptr, 0)); } else if (col_spec.type_spec == "uint") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( (unsigned int) strtoul(value, nullptr, 0)); } else if (col_spec.type_spec == "long") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( strtol(value, nullptr, 0)); } else if (col_spec.type_spec == "longlong") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( strtoll(value, nullptr, 0)); } else if (col_spec.type_spec == "ulong") { if (value[0] != '\0') { const unsigned long v = strtoul(value, nullptr, 0); - std::vector &vec = - std::any_cast &> + ColumnVecType &vec = + std::any_cast &> (col_spec.col_vec); vec.push_back(v); @@ -604,12 +604,12 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { } else if (col_spec.type_spec == "ulonglong") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( strtoull(value, nullptr, 0)); } else if (col_spec.type_spec == "string") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back(value); } else if (col_spec.type_spec == "DateTime") { @@ -624,23 +624,23 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { ::sscanf(value, "%ld.%d", &t, &n); #endif // _MSC_VER dt.set_time(t, n); - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( std::move(dt)); } } else if (col_spec.type_spec == "DateTimeAME") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( value, DT_DATE_STYLE::AME_STYLE); } else if (col_spec.type_spec == "DateTimeEUR") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( value, DT_DATE_STYLE::EUR_STYLE); } else if (col_spec.type_spec == "DateTimeISO") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( value, DT_DATE_STYLE::ISO_STYLE); } @@ -648,8 +648,8 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { if (value[0] != '\0') { const bool v = static_cast(strtoul(value, nullptr, 0)); - std::vector &vec = - std::any_cast &>(col_spec.col_vec); + ColumnVecType &vec = + std::any_cast &>(col_spec.col_vec); vec.push_back(v); } @@ -675,64 +675,69 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { _col_data_spec_ col_spec = spec_vec[i]; if (col_spec.type_spec == "float") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "double") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "longdouble") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> - (col_spec.col_vec)), + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast< + ColumnVecType &> + (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "int") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "uint") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> - (col_spec.col_vec)), + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast< + ColumnVecType &> + (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "long") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "longlong") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "ulong") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast&> - (col_spec.col_vec)), + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast< + ColumnVecType&> + (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "ulonglong") - load_column(col_spec.col_name.c_str(), + load_column(col_spec.col_name.c_str(), std::move( - std::any_cast &> + std::any_cast< + ColumnVecType &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "string") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast< + ColumnVecType &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (! ::strncmp(col_spec.type_spec.c_str(), "DateTime", 8)) - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "bool") - load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + load_column(col_spec.col_name.c_str(), + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); } diff --git a/include/DataFrame/Internals/DataFrame_set.tcc b/include/DataFrame/Internals/DataFrame_set.tcc index 687799b9e..b5d5f9217 100644 --- a/include/DataFrame/Internals/DataFrame_set.tcc +++ b/include/DataFrame/Internals/DataFrame_set.tcc @@ -40,7 +40,8 @@ namespace hmdf template template -std::vector &DataFrame::create_column (const char *name) { +typename DataFrame::template ColumnVecType & +DataFrame::create_column (const char *name) { static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call create_column()"); @@ -167,7 +168,7 @@ retype_column (const char *name, "Data column name cannot be 'INDEX'"); const ColumnVecType &old_vec = get_column(name); - std::vector new_vec; + ColumnVecType new_vec; new_vec.reserve(old_vec.size()); for (const auto &citer : old_vec) @@ -233,7 +234,8 @@ DataFrame::load_index(IndexVecType &&idx) { // ---------------------------------------------------------------------------- template -std::vector DataFrame:: +typename DataFrame::template ColumnVecType +DataFrame:: gen_datetime_index(const char *start_datetime, const char *end_datetime, time_frequency t_freq, @@ -244,7 +246,7 @@ gen_datetime_index(const char *start_datetime, DT_DATE_STYLE::AME_STYLE, tz); const DateTime end_di(end_datetime, DT_DATE_STYLE::AME_STYLE, tz); const double diff = end_di.diff_seconds(start_di); - std::vector index_vec; + ColumnVecType index_vec; switch(t_freq) { case time_frequency::annual: @@ -291,12 +293,13 @@ gen_datetime_index(const char *start_datetime, // ---------------------------------------------------------------------------- template -std::vector DataFrame:: +typename DataFrame::template ColumnVecType +DataFrame:: gen_sequence_index (const IndexType &start_value, const IndexType &end_value, long increment) { - std::vector index_vec; + ColumnVecType index_vec; IndexType sv = start_value; while (sv < end_value) { @@ -363,7 +366,7 @@ load_column (const char *name, } const auto iter = column_tb_.find (name); - std::vector *vec_ptr = nullptr; + ColumnVecType *vec_ptr = nullptr; if (iter == column_tb_.end()) vec_ptr = &(create_column(name)); @@ -427,7 +430,7 @@ load_result_as_column(V &visitor, const char *name, nan_policy padding) { } const auto iter = column_tb_.find (name); - std::vector *vec_ptr = nullptr; + ColumnVecType *vec_ptr = nullptr; if (iter == column_tb_.end()) vec_ptr = &(create_column(name)); @@ -450,7 +453,7 @@ typename DataFrame::size_type DataFrame:: load_indicators(const char *cat_col_name, const char *numeric_cols_prefix) { - using map_t = std::unordered_map *>; + using map_t = std::unordered_map *>; const auto &cat_col = get_column(cat_col_name); const auto col_s = cat_col.size(); @@ -486,12 +489,12 @@ template template typename DataFrame::size_type DataFrame:: -from_indicators(const std::vector &ind_col_names, +from_indicators(const ColumnVecType &ind_col_names, const char *cat_col_name, const char *numeric_cols_prefixg) { const size_type ind_col_s = ind_col_names.size(); - std::vector *> ind_cols(ind_col_s, nullptr); + ColumnVecType *> ind_cols(ind_col_s, nullptr); for (size_type i = 0; i < ind_col_s; ++i) ind_cols[i] = &(get_column(ind_col_names[i])); @@ -547,7 +550,9 @@ template template typename DataFrame::size_type DataFrame:: -load_column (const char *name, std::vector &&column, nan_policy padding) { +load_column (const char *name, + ColumnVecType &&column, + nan_policy padding) { const size_type idx_s = indices_.size(); const size_type data_s = column.size(); @@ -576,7 +581,7 @@ load_column (const char *name, std::vector &&column, nan_policy padding) { } const auto iter = column_tb_.find (name); - std::vector *vec_ptr = nullptr; + ColumnVecType *vec_ptr = nullptr; if (iter == column_tb_.end()) vec_ptr = &(create_column(name)); @@ -599,7 +604,7 @@ typename DataFrame::size_type DataFrame:: load_align_column( const char *name, - std::vector &&column, + ColumnVecType &&column, size_type interval, bool start_from_beginning, const T &null_value, @@ -624,7 +629,7 @@ load_align_column( throw InconsistentData (buffer); } - std::vector new_col(idx_s, null_value); + ColumnVecType new_col(idx_s, null_value); size_type idx_idx { 0 }; if (start_from_beginning) { @@ -656,7 +661,7 @@ template typename DataFrame::size_type DataFrame:: load_column (const char *name, - const std::vector &data, + const ColumnVecType &data, nan_policy padding) { return (load_column(name, { data.begin(), data.end() }, padding)); @@ -685,7 +690,7 @@ append_column (const char *name, Index2D range, nan_policy padding) { - std::vector &vec = get_column(name); + ColumnVecType &vec = get_column(name); size_type s = std::distance(range.begin, range.end) + vec.size (); const size_type idx_s = indices_.size(); @@ -726,7 +731,7 @@ typename DataFrame::size_type DataFrame:: append_column (const char *name, const T &val, nan_policy padding) { - std::vector &vec = get_column(name); + ColumnVecType &vec = get_column(name); size_type s = 1; const size_type idx_s = indices_.size(); @@ -881,7 +886,7 @@ void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) { const ColumnVecType &vec = get_column(name); const size_type col_s = vec.size(); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(indices_.size() / 2); for (size_type i = 0; i < col_s; ++i) @@ -917,7 +922,7 @@ remove_data_by_sel (const char *name1, const char *name2, F &sel_functor) { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -963,7 +968,7 @@ remove_data_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - std::vector col_indices; + ColumnVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1002,7 +1007,7 @@ remove_dups_common_(const DataFrame &s_df, const MAP &row_table, const IndexVecType &index) { - using count_vec = std::vector; + using count_vec = ColumnVecType; count_vec rows_to_del; @@ -1065,7 +1070,7 @@ remove_duplicates (const char *name, remove_dup_spec rds) const { using data_tuple = std::tuple; - using count_vec = std::vector; + using count_vec = ColumnVecType; using data_map = std::unordered_map; const ColumnVecType &vec = get_column(name); @@ -1101,7 +1106,7 @@ remove_duplicates (const char *name1, remove_dup_spec rds) const { using data_tuple = std::tuple; - using count_vec = std::vector; + using count_vec = ColumnVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1141,7 +1146,7 @@ remove_duplicates (const char *name1, using data_tuple = std::tuple; - using count_vec = std::vector; + using count_vec = ColumnVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1185,7 +1190,7 @@ remove_duplicates (const char *name1, using data_tuple = std::tuple; - using count_vec = std::vector; + using count_vec = ColumnVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1233,7 +1238,7 @@ remove_duplicates (const char *name1, using data_tuple = std::tuple; - using count_vec = std::vector; + using count_vec = ColumnVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1286,7 +1291,7 @@ remove_duplicates (const char *name1, const T3 &, const T4 &, const T5 &, const T6 &, const IndexType &>; - using count_vec = std::vector; + using count_vec = ColumnVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); diff --git a/include/DataFrame/Internals/DataFrame_shift.tcc b/include/DataFrame/Internals/DataFrame_shift.tcc index e79e5f43f..626825bea 100644 --- a/include/DataFrame/Internals/DataFrame_shift.tcc +++ b/include/DataFrame/Internals/DataFrame_shift.tcc @@ -47,7 +47,7 @@ void DataFrame::self_shift(size_type periods, shift_policy sp) { if (periods > 0) { if (sp == shift_policy::down || sp == shift_policy::up) { vertical_shift_functor_ functor(periods, sp); - std::vector> futures(get_thread_level()); + ColumnVecType> futures(get_thread_level()); size_type thread_count = 0; const size_type data_size = data_.size(); @@ -105,13 +105,13 @@ shift(size_type periods, shift_policy sp) const { template template -std::vector DataFrame:: +typename DataFrame::template ColumnVecType DataFrame:: shift(const char *col_name, size_type periods, shift_policy sp) const { static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call shift()"); - std::vector result = get_column(col_name); + ColumnVecType result = get_column(col_name); vertical_shift_functor_ functor(periods, sp); functor (result); @@ -130,7 +130,7 @@ void DataFrame::self_rotate(size_type periods, shift_policy sp) { if (periods > 0) { if (sp == shift_policy::down || sp == shift_policy::up) { rotate_functor_ functor(periods, sp); - std::vector> futures(get_thread_level()); + ColumnVecType> futures(get_thread_level()); size_type thread_count = 0; const size_type data_size = data_.size(); diff --git a/include/DataFrame/Internals/DataFrame_standalone.tcc b/include/DataFrame/Internals/DataFrame_standalone.tcc index 42f6bdfac..911edb4e6 100644 --- a/include/DataFrame/Internals/DataFrame_standalone.tcc +++ b/include/DataFrame/Internals/DataFrame_standalone.tcc @@ -56,13 +56,14 @@ _create_column_from_triple_(DF &df, T &triple) { template static inline void -_load_groupby_data_1_(const DF &source, - DF &dest, - T &triple, - I_V &&idx_visitor, - const V &input_v, - const std::vector &sort_v, - const char *col_name) { +_load_groupby_data_1_( + const DF &source, + DF &dest, + T &triple, + I_V &&idx_visitor, + const V &input_v, + const typename DF::template ColumnVecType &sort_v, + const char *col_name) { std::size_t marker = 0; auto &dst_idx = dest.get_index(); @@ -139,15 +140,16 @@ _load_groupby_data_1_(const DF &source, template static inline void -_load_groupby_data_2_(const DF &source, - DF &dest, - T &triple, - I_V &&idx_visitor, - const V1 &input_v1, - const V2 &input_v2, - const std::vector &sort_v, - const char *col_name1, - const char *col_name2) { +_load_groupby_data_2_( + const DF &source, + DF &dest, + T &triple, + I_V &&idx_visitor, + const V1 &input_v1, + const V2 &input_v2, + const typename DF::template ColumnVecType &sort_v, + const char *col_name1, + const char *col_name2) { std::size_t marker = 0; auto &dst_idx = dest.get_index(); @@ -235,17 +237,18 @@ _load_groupby_data_2_(const DF &source, template static inline void -_load_groupby_data_3_(const DF &source, - DF &dest, - T &triple, - I_V &&idx_visitor, - const V1 &input_v1, - const V2 &input_v2, - const V3 &input_v3, - const std::vector &sort_v, - const char *col_name1, - const char *col_name2, - const char *col_name3) { +_load_groupby_data_3_( + const DF &source, + DF &dest, + T &triple, + I_V &&idx_visitor, + const V1 &input_v1, + const V2 &input_v2, + const V3 &input_v3, + const typename DF::template ColumnVecType &sort_v, + const char *col_name1, + const char *col_name2, + const char *col_name3) { std::size_t marker = 0; auto &dst_idx = dest.get_index(); diff --git a/include/DataFrame/Internals/RandGen.tcc b/include/DataFrame/Internals/RandGen.tcc index 43295f525..5fe587e0a 100644 --- a/include/DataFrame/Internals/RandGen.tcc +++ b/include/DataFrame/Internals/RandGen.tcc @@ -39,8 +39,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template -static inline std::vector +template +static inline std::vector::type> _gen_rand_(std::size_t n, const RandGenParams ¶ms, D &&dist) { std::random_device rd; @@ -48,7 +48,7 @@ _gen_rand_(std::size_t n, const RandGenParams ¶ms, D &&dist) { if (params.seed != static_cast(-1)) gen.seed(params.seed); - std::vector result(n); + std::vector::type> result(n); for (auto iter = result.begin(); iter < result.end(); ++iter) *iter = dist(gen); @@ -57,8 +57,8 @@ _gen_rand_(std::size_t n, const RandGenParams ¶ms, D &&dist) { // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_uniform_int_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -75,7 +75,7 @@ gen_uniform_int_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::uniform_int_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::uniform_int_distribution(params.min_value, params.max_value))); @@ -83,8 +83,8 @@ gen_uniform_int_dist(std::size_t n, const RandGenParams ¶ms) { // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_uniform_real_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -94,7 +94,7 @@ gen_uniform_real_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::uniform_real_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::uniform_real_distribution(params.min_value, params.max_value))); @@ -102,20 +102,21 @@ gen_uniform_real_dist(std::size_t n, const RandGenParams ¶ms) { // ---------------------------------------------------------------------------- -std::vector +template +std::vector::type> gen_bernoulli_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::bernoulli_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::bernoulli_distribution(params.prob_true))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_binomial_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -132,7 +133,7 @@ gen_binomial_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::binomial_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::binomial_distribution(static_cast(params.t_dist), params.prob_true))); @@ -140,8 +141,8 @@ gen_binomial_dist(std::size_t n, const RandGenParams ¶ms) { // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_negative_binomial_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -158,7 +159,7 @@ gen_negative_binomial_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::negative_binomial_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::negative_binomial_distribution (static_cast(params.t_dist), params.prob_true))); @@ -166,8 +167,8 @@ gen_negative_binomial_dist(std::size_t n, const RandGenParams ¶ms) { // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_geometric_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -184,15 +185,15 @@ gen_geometric_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::geometric_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::geometric_distribution(params.prob_true))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_poisson_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -209,15 +210,15 @@ gen_poisson_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::poisson_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::poisson_distribution(params.mean))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_exponential_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -227,15 +228,15 @@ gen_exponential_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::exponential_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::exponential_distribution(params.lambda))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_gamma_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -245,15 +246,15 @@ gen_gamma_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::gamma_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::gamma_distribution(params.alpha, params.beta))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_weibull_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -263,15 +264,15 @@ gen_weibull_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::weibull_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::weibull_distribution(params.alpha, params.beta))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_extreme_value_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -281,15 +282,15 @@ gen_extreme_value_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::extreme_value_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::extreme_value_distribution(params.alpha, params.beta))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_normal_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -299,15 +300,15 @@ gen_normal_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::normal_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::normal_distribution(params.mean, params.std))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_lognormal_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -317,15 +318,15 @@ gen_lognormal_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::lognormal_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::lognormal_distribution(params.m, params.s))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_chi_squared_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -335,15 +336,15 @@ gen_chi_squared_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::chi_squared_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::chi_squared_distribution(params.n))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_cauchy_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -353,15 +354,15 @@ gen_cauchy_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::cauchy_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::cauchy_distribution(params.alpha, params.beta))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_fisher_f_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -371,15 +372,15 @@ gen_fisher_f_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::fisher_f_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::fisher_f_distribution(params.n, params.n2))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_student_t_dist(std::size_t n, const RandGenParams ¶ms) { static_assert(std::is_same::value || @@ -389,20 +390,21 @@ gen_student_t_dist(std::size_t n, const RandGenParams ¶ms) { using D = std::student_t_distribution; - return (_gen_rand_( + return (_gen_rand_( n, params, std::student_t_distribution(params.n))); } // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_log_space_nums(std::size_t n, T first, T last, T base) { - const T step = (last - first) / (T(n) - T(1)); - T current = first; - std::vector result (n); + const T step = + (last - first) / (T(n) - T(1)); + T current = first; + std::vector::type> result (n); for (auto iter = result.begin(); iter < result.end(); ++iter) { const T val = ::pow(base, current); @@ -416,12 +418,13 @@ gen_log_space_nums(std::size_t n, T first, T last, T base) { // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_even_space_nums(std::size_t n, T first, T last) { - const T step = (last - first) / T(n); - std::vector result; + const T step = + (last - first) / T(n); + std::vector::type> result; result.reserve(n + 1); // Make it efficient, if user wants to add last result.push_back(first); @@ -433,11 +436,11 @@ gen_even_space_nums(std::size_t n, T first, T last) { // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_triangular_nums(T last, T first) { - std::vector result; + std::vector::type> result; // With arbitrary first and last values, it is hard to do result.reserve(); // @@ -452,14 +455,16 @@ gen_triangular_nums(T last, T first) { // ---------------------------------------------------------------------------- -template -std::vector +template +std::vector::type> gen_sym_triangle(std::size_t n, const T &start_val, bool normalize) { - std::vector result; - const bool is_even = ! (n & std::size_t(0x01)); - const std::size_t max_loop { n / 2 + (is_even ? 0 : 1) }; - T sum { 0 }; + std::vector::type> result; + const bool is_even = + ! (n & std::size_t(0x01)); + const std::size_t max_loop { + n / 2 + (is_even ? 0 : 1) }; + T sum { 0 }; result.reserve(n); for (std::size_t i = 0; i < max_loop; ++i) { diff --git a/include/DataFrame/RandGen.h b/include/DataFrame/RandGen.h index 82198d5c8..5d15fd232 100644 --- a/include/DataFrame/RandGen.h +++ b/include/DataFrame/RandGen.h @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once #include +#include #include @@ -52,8 +53,8 @@ namespace hmdf // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_uniform_int_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -71,8 +72,8 @@ gen_uniform_int_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_uniform_real_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -90,7 +91,8 @@ gen_uniform_real_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -std::vector +template +std::vector::type> gen_bernoulli_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -109,8 +111,8 @@ gen_bernoulli_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_binomial_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -129,8 +131,8 @@ gen_binomial_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_negative_binomial_dist(std::size_t n, const RandGenParams ¶ms = {}); // ---------------------------------------------------------------------------- @@ -149,8 +151,8 @@ gen_negative_binomial_dist(std::size_t n, const RandGenParams ¶ms = {}); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_geometric_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -171,8 +173,8 @@ gen_geometric_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_poisson_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -189,8 +191,8 @@ gen_poisson_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_exponential_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -207,8 +209,8 @@ gen_exponential_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_gamma_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -225,8 +227,8 @@ gen_gamma_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_weibull_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -243,8 +245,8 @@ gen_weibull_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_extreme_value_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -261,8 +263,8 @@ gen_extreme_value_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_normal_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -279,8 +281,8 @@ gen_normal_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_lognormal_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -297,8 +299,8 @@ gen_lognormal_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_chi_squared_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -315,8 +317,8 @@ gen_chi_squared_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_cauchy_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -332,8 +334,8 @@ gen_cauchy_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_fisher_f_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -350,8 +352,8 @@ gen_fisher_f_dist(std::size_t n, const RandGenParams ¶ms = { }); // n: Number of numerics to generate // params: List of all applicable parameters, see DataFrameTypes.h // -template -std::vector +template +std::vector::type> gen_student_t_dist(std::size_t n, const RandGenParams ¶ms = { }); // ---------------------------------------------------------------------------- @@ -359,8 +361,8 @@ gen_student_t_dist(std::size_t n, const RandGenParams ¶ms = { }); // This function generates n logarithmically spaced numbers between the given // base raised to the power of first to last. // -template -std::vector +template +std::vector::type> gen_log_space_nums(std::size_t n, T first, T last, T base); // ---------------------------------------------------------------------------- @@ -369,8 +371,8 @@ gen_log_space_nums(std::size_t n, T first, T last, T base); // last parameters. // The result vector always starts with first and ends shy of last // -template -std::vector +template +std::vector::type> gen_even_space_nums(std::size_t n, T first, T last); // ---------------------------------------------------------------------------- @@ -386,8 +388,8 @@ gen_even_space_nums(std::size_t n, T first, T last); // The result vector always starts with a value >= than first and ends with // a value <= than last. // -template -std::vector +template +std::vector::type> gen_triangular_nums(T last, T first = T(1)); // ---------------------------------------------------------------------------- @@ -402,8 +404,8 @@ gen_triangular_nums(T last, T first = T(1)); // 1 1 // If normalize is true, the numbers are normalized by the sum of all numbers // -template -std::vector +template +std::vector::type> gen_sym_triangle(std::size_t n, const T &start_val, bool normalize = false); } // namespace hmdf diff --git a/test/dataframe_tester.cc b/test/dataframe_tester.cc index 40ff14d6d..a41b4964f 100644 --- a/test/dataframe_tester.cc +++ b/test/dataframe_tester.cc @@ -649,7 +649,7 @@ static void test_remove_column() { std::vector d22 = { 8, 9, 10, 11, 12, 13, 14 }; - df.load_column("col_2", std::move(d22)); + df.load_column("col_2", std::move(d22)); std::cout << "After adding back column `col_2`" << std::endl; df.write(std::cout); } @@ -1438,7 +1438,9 @@ static void test_fill_missing_values() { std::vector s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; - df.load_column("col_str", std::move(s1), nan_policy::dont_pad_with_nans); + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); std::cout << "Original DF:" << std::endl; df.write(std::cout); @@ -1502,7 +1504,9 @@ static void test_fill_missing_fill_forward() { std::vector s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; - df.load_column("col_str", std::move(s1), nan_policy::dont_pad_with_nans); + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); std::cout << "Original DF:" << std::endl; df.write(std::cout); @@ -1907,11 +1911,15 @@ static void test_get_row() { std::vector s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; - df.load_column("col_str", std::move(s1), nan_policy::dont_pad_with_nans); + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); std::vector i2 = { 22, 11 }; - df.load_column("col_int", std::move(i2), nan_policy::dont_pad_with_nans); + df.load_column("col_int", + std::move(i2), + nan_policy::dont_pad_with_nans); std::cout << "Original DF:" << std::endl; df.write(std::cout); @@ -2102,8 +2110,12 @@ static void test_median() { df.load_data(std::move(idx), std::make_pair("dblcol_1", d1), std::make_pair("intcol_1", i1)); - df.load_column("dblcol_2", std::move(d2), nan_policy::dont_pad_with_nans); - df.load_column("intcol_2", std::move(i2), nan_policy::dont_pad_with_nans); + df.load_column("dblcol_2", + std::move(d2), + nan_policy::dont_pad_with_nans); + df.load_column("intcol_2", + std::move(i2), + nan_policy::dont_pad_with_nans); MedianVisitor med_visit; double result = @@ -2234,23 +2246,23 @@ static void test_beta() { ReturnVisitor return_visit(return_policy::log); - df.load_column( + df.load_column( "dblcol_1_return", df.single_act_visit("dblcol_1", return_visit).get_result(), nan_policy::dont_pad_with_nans); - df.load_column( + df.load_column( "dblcol_2_return", df.single_act_visit("dblcol_2", return_visit).get_result(), nan_policy::dont_pad_with_nans); - df.load_column( + df.load_column( "dblcol_3_return", df.single_act_visit("dblcol_3", return_visit).get_result(), nan_policy::dont_pad_with_nans); - df.load_column( + df.load_column( "dblcol_4_return", df.single_act_visit("dblcol_4", return_visit).get_result(), nan_policy::dont_pad_with_nans); - df.load_column( + df.load_column( "dblcol_5_return", df.single_act_visit("dblcol_5", return_visit).get_result(), nan_policy::dont_pad_with_nans); @@ -2580,9 +2592,15 @@ static void test_some_visitors() { df.load_data(std::move(idx), std::make_pair("dblcol_1", d1), std::make_pair("intcol_1", i1)); - df.load_column("dblcol_2", std::move(d2), nan_policy::dont_pad_with_nans); - df.load_column("intcol_2", std::move(i2), nan_policy::dont_pad_with_nans); - df.load_column("dblcol_3", std::move(d3), nan_policy::dont_pad_with_nans); + df.load_column("dblcol_2", + std::move(d2), + nan_policy::dont_pad_with_nans); + df.load_column("intcol_2", + std::move(i2), + nan_policy::dont_pad_with_nans); + df.load_column("dblcol_3", + std::move(d3), + nan_policy::dont_pad_with_nans); SumVisitor sum_visit; ProdVisitor prod_visit; @@ -2650,9 +2668,15 @@ static void test_mode() { df.load_data(std::move(idx), std::make_pair("dblcol_1", d1), std::make_pair("intcol_1", i1)); - df.load_column("dblcol_2", std::move(d2), nan_policy::dont_pad_with_nans); - df.load_column("intcol_2", std::move(i2), nan_policy::dont_pad_with_nans); - df.load_column("dblcol_3", std::move(d3), nan_policy::dont_pad_with_nans); + df.load_column("dblcol_2", + std::move(d2), + nan_policy::dont_pad_with_nans); + df.load_column("intcol_2", + std::move(i2), + nan_policy::dont_pad_with_nans); + df.load_column("dblcol_3", + std::move(d3), + nan_policy::dont_pad_with_nans); ModeVisitor<3, double> mode_visit; const auto &result = From 5ba60a94ed4a11fbbc195fed400bbcb3a915aa76 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Thu, 22 Dec 2022 14:40:02 -0500 Subject: [PATCH 10/25] sofar dataframe_tester.cc builds --- include/DataFrame/DataFrame.h | 96 +- include/DataFrame/Internals/DataFrame.tcc | 179 ++-- .../DataFrame/Internals/DataFrame_functors.h | 56 +- include/DataFrame/Internals/DataFrame_get.tcc | 82 +- .../DataFrame/Internals/DataFrame_join.tcc | 92 +- .../DataFrame/Internals/DataFrame_misc.tcc | 36 +- .../Internals/DataFrame_private_decl.h | 559 +++++++++++- .../DataFrame/Internals/DataFrame_read.tcc | 144 +-- include/DataFrame/Internals/DataFrame_set.tcc | 54 +- .../DataFrame/Internals/DataFrame_shift.tcc | 8 +- .../Internals/DataFrame_standalone.tcc | 497 +---------- test/dataframe_tester.cc | 833 +++++++++--------- 12 files changed, 1341 insertions(+), 1295 deletions(-) diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index 45237104c..ec6d92ce1 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -72,7 +72,9 @@ class DataFrame : public ThreadGranularity { using DataVec = H; using DataVecVec = std::vector::type>; + typename allocator_declare< + DataVec, + std::size_t(H::align_value)>::type>; public: // Construction @@ -110,8 +112,13 @@ class DataFrame : public ThreadGranularity { void>::type; template - using ColumnVecType = - typename type_declare::type; + using ColumnVecType = typename type_declare::type; + + template + using StlVecType = + std::vector::type>; DataFrame() = default; @@ -253,13 +260,13 @@ class DataFrame : public ThreadGranularity { template size_type load_column(const char *name, - ColumnVecType &&data, + StlVecType &&data, nan_policy padding = nan_policy::pad_with_nans); template size_type load_column(const char *name, - const ColumnVecType &data, + const StlVecType &data, nan_policy padding = nan_policy::pad_with_nans); // This method creates a column similar to above, but assumes data is @@ -299,7 +306,7 @@ class DataFrame : public ThreadGranularity { size_type load_align_column( const char *name, - ColumnVecType &&data, + StlVecType &&data, size_type interval, bool start_from_beginning, const T &null_value = hmdf::get_nan(), @@ -377,7 +384,7 @@ class DataFrame : public ThreadGranularity { // template size_type - from_indicators(const ColumnVecType &ind_col_names, + from_indicators(const StlVecType &ind_col_names, const char *cat_col_name, const char *numeric_cols_prefix = nullptr); @@ -797,7 +804,7 @@ class DataFrame : public ThreadGranularity { // template void - shuffle(const ColumnVecType &col_names, + shuffle(const StlVecType &col_names, bool also_shuffle_index); // It fills all the "missing values" with the given values, and/or using @@ -824,9 +831,9 @@ class DataFrame : public ThreadGranularity { // template void - fill_missing(const ColumnVecType &col_names, + fill_missing(const StlVecType &col_names, fill_policy policy, - const ColumnVecType &values = { }, + const StlVecType &values = { }, int limit = -1); // It fills the missing values in all columns in self by investigating the @@ -889,8 +896,8 @@ class DataFrame : public ThreadGranularity { template size_type replace(const char *col_name, - const ColumnVecType &old_values, - const ColumnVecType &new_values, + const StlVecType &old_values, + const StlVecType &new_values, int limit = -1); // Same as replace() above, but executed asynchronously @@ -901,8 +908,8 @@ class DataFrame : public ThreadGranularity { template [[nodiscard]] std::future replace_async(const char *col_name, - const ColumnVecType &old_values, - const ColumnVecType &new_values, + const StlVecType &old_values, + const StlVecType &new_values, int limit = -1); // This is similar to replace() above but it lets a functor replace the @@ -948,8 +955,8 @@ class DataFrame : public ThreadGranularity { // Limit of how many items to replace. Default is to replace all. // size_type - replace_index(const ColumnVecType &old_values, - const ColumnVecType &new_values, + replace_index(const StlVecType &old_values, + const StlVecType &new_values, int limit = -1); // Sort the DataFrame by the named column. If name equals "INDEX" or @@ -1466,7 +1473,7 @@ class DataFrame : public ThreadGranularity { // Specifies the direction. In this case it is only up or down. // template - [[nodiscard]] ColumnVecType + [[nodiscard]] StlVecType shift(const char *col_name, size_type periods, shift_policy sp) const; // It rotates all the columns in self up, down, left, or right based on @@ -1610,7 +1617,7 @@ class DataFrame : public ThreadGranularity { template [[nodiscard]] HeteroVector get_row(size_type row_num, - const ColumnVecType &col_names) const; + const StlVecType &col_names) const; // This is same as get_row() above. But it always includes all the columns // in the returned row. The order is the column creation order. If you @@ -1674,7 +1681,7 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] DataFrame - get_data_by_idx(const ColumnVecType &values) const; + get_data_by_idx(const StlVecType &values) const; // It behaves like get_data_by_idx(range), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. @@ -1718,11 +1725,11 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] PtrView - get_view_by_idx(const ColumnVecType &values); + get_view_by_idx(const StlVecType &values); template [[nodiscard]] ConstPtrView - get_view_by_idx(const ColumnVecType &values) const; + get_view_by_idx(const StlVecType &values) const; // It returns a DataFrame (including the index and data columns) // containing the data from location begin to location end within range. @@ -1755,7 +1762,7 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] DataFrame - get_data_by_loc(const ColumnVecType &locations) const; + get_data_by_loc(const StlVecType &locations) const; // It behaves like get_data_by_loc(range), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. @@ -1799,11 +1806,11 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] PtrView - get_view_by_loc(const ColumnVecType &locations); + get_view_by_loc(const StlVecType &locations); template [[nodiscard]] ConstPtrView - get_view_by_loc(const ColumnVecType &locations) const; + get_view_by_loc(const StlVecType &locations) const; // This method does boolean filtering selection via the sel_functor // (e.g. a functor, function, or lambda). It returns a new DataFrame. @@ -2334,7 +2341,7 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] DataFrame - get_data(const ColumnVecType &col_names) const; + get_data(const StlVecType &col_names) const; // It behaves like get_data(), but it returns a View. // A view is a DataFrame that is a reference to the original DataFrame. @@ -2353,11 +2360,11 @@ class DataFrame : public ThreadGranularity { // template [[nodiscard]] View - get_view(const ColumnVecType &col_names); + get_view(const StlVecType &col_names); template [[nodiscard]] ConstView - get_view(const ColumnVecType &col_names) const; + get_view(const StlVecType &col_names) const; // It returns a const reference to the index container // @@ -2492,7 +2499,7 @@ class DataFrame : public ThreadGranularity { // T func(const T &self_data, const T &rhs_data) // template - [[nodiscard]] ColumnVecType + [[nodiscard]] StlVecType combine(const char *col_name, const DF &rhs, F &functor) const; // Same as the combine() above but it combines 3 columns. @@ -2519,7 +2526,7 @@ class DataFrame : public ThreadGranularity { // T func(const T &self_data, const T &df1_data, const T &df2_data) // template - [[nodiscard]] ColumnVecType + [[nodiscard]] StlVecType combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2557,7 +2564,7 @@ class DataFrame : public ThreadGranularity { // const T &df3_data) // template - [[nodiscard]] ColumnVecType + [[nodiscard]] StlVecType combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2565,18 +2572,18 @@ class DataFrame : public ThreadGranularity { F &functor) const; // This method feeds old_col_name1 and old_col_name2 of types OLD_T1 and - // OLD_T2 to functor which returns a ColumnVecType which will be + // OLD_T2 to functor which returns a StlVecType which will be // loaded into self as column new_col_name. Both old columns will be // removed, if delete_old_cols is true // Functor "functor" should implement the logic of consolidating two // columns into one. Functor signature is: // template - // ColumnVecType (IndexVecType::const_iterator idx_begin, + // StlVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end); // Where ITR[12] are iterators for columns 1 and 2. They are iterators - // of ColumnVecType. + // of StlVecType. // // NOTE: This method could not be called from views. // @@ -2612,13 +2619,13 @@ class DataFrame : public ThreadGranularity { // into one. // Functor signature is: // template - // ColumnVecType (IndexVecType::const_iterator idx_begin, + // StlVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end, // ITR3 col3_begin, ITR3 col3_end); // Where ITR[123] are iterators for columns 1, 2 and 3. They are - // iterators of ColumnVecType. + // iterators of StlVecType. // // NOTE: This method could not be called from views. // @@ -2661,14 +2668,14 @@ class DataFrame : public ThreadGranularity { // Functor signature is: // template - // ColumnVecType (IndexVecType::const_iterator idx_begin, + // StlVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end, // ITR3 col3_begin, ITR3 col3_end, // ITR4 col4_begin, ITR4 col4_end); // Where ITR[1234] are iterators for columns 1, 2, 3, and 4. They are - // iterators of ColumnVecType. + // iterators of StlVecType. // // NOTE: This method could not be called from views. // @@ -2717,7 +2724,7 @@ class DataFrame : public ThreadGranularity { // Functor signature is: // template - // ColumnVecType (IndexVecType::const_iterator idx_begin, + // StlVecType (IndexVecType::const_iterator idx_begin, // IndexVecType::const_iterator idx_end, // ITR1 col1_begin, ITR1 col1_end, // ITR2 col2_begin, ITR2 col2_end, @@ -2725,7 +2732,7 @@ class DataFrame : public ThreadGranularity { // ITR4 col4_begin, ITR4 col4_end, // ITR5 col5_begin, ITR5 col5_end); // Where ITR[12345] are iterators for columns 1, 2, 3, 4, and 5. - // They are iterators of ColumnVecType. + // They are iterators of StlVecType. // // NOTE: This method could not be called from views. // @@ -3497,9 +3504,8 @@ class DataFrame : public ThreadGranularity { // the list only once. // template - [[nodiscard]] ColumnVecType> + [[nodiscard]] + StlVecType> get_columns_info() const; // It returns the memory used by the given column and index column. @@ -3565,7 +3571,7 @@ class DataFrame : public ThreadGranularity { // NOTE: It is the responsibility of the programmer to make sure // IndexType type is big enough to contain the frequency. // - static ColumnVecType + static StlVecType gen_datetime_index(const char *start_datetime, const char *end_datetime, time_frequency t_freq, @@ -3586,7 +3592,7 @@ class DataFrame : public ThreadGranularity { // increment: // Increment by value // - static ColumnVecType + static StlVecType gen_sequence_index(const IndexType &start_value, const IndexType &end_value, long increment = 1); @@ -3779,7 +3785,7 @@ class DataFrame : public ThreadGranularity { using ColNameDict = std::unordered_map>; - using ColNameList = ColumnVecType>; + using ColNameList = StlVecType>; // Data fields // diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index d45f9c604..ca55d5b73 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -123,7 +123,7 @@ template void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { const size_type idx_s = df.indices_.size(); - ColumnVecType sorting_idxs(idx_s, 0); + StlVecType sorting_idxs(idx_s, 0); std::iota(sorting_idxs.begin(), sorting_idxs.end(), 0); std::sort(sorting_idxs.begin(), sorting_idxs.end(), comp_func); @@ -143,7 +143,7 @@ void DataFrame::sort_common_(DataFrame &df, CF &&comp_func) { template template void -DataFrame::shuffle(const ColumnVecType &col_names, +DataFrame::shuffle(const StlVecType &col_names, bool also_shuffle_index) { if (also_shuffle_index) { @@ -178,7 +178,7 @@ DataFrame::shuffle(const ColumnVecType &col_names, template template void DataFrame:: -fill_missing_value_(ColumnVecType &vec, +fill_missing_value_(StlVecType &vec, const T &value, int limit, size_type col_num) { @@ -207,7 +207,7 @@ fill_missing_value_(ColumnVecType &vec, template template void DataFrame:: -fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num) { +fill_missing_ffill_(StlVecType &vec, int limit, size_type col_num) { const size_type vec_size = vec.size(); @@ -245,7 +245,7 @@ template::value || ! std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_midpoint_(ColumnVecType &, int, size_type) { +fill_missing_midpoint_(StlVecType &, int, size_type) { throw NotFeasible("fill_missing_midpoint_(): ERROR: Mid-point filling is " "not feasible on non-arithmetic types"); @@ -258,7 +258,7 @@ template::value && std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type) { +fill_missing_midpoint_(StlVecType &vec, int limit, size_type) { const size_type vec_size = vec.size(); @@ -291,7 +291,7 @@ fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type) { template template void DataFrame:: -fill_missing_bfill_(ColumnVecType &vec, int limit) { +fill_missing_bfill_(StlVecType &vec, int limit) { const long vec_size = static_cast(vec.size()); @@ -318,7 +318,7 @@ template::value || ! std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_linter_(ColumnVecType &, const IndexVecType &, int) { +fill_missing_linter_(StlVecType &, const IndexVecType &, int) { throw NotFeasible("fill_missing_linter_(): ERROR: Interpolation is " "not feasible on non-arithmetic types"); @@ -331,7 +331,7 @@ template::value && std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_linter_(ColumnVecType &vec, +fill_missing_linter_(StlVecType &vec, const IndexVecType &index, int limit) { @@ -394,17 +394,17 @@ fill_missing_linter_(ColumnVecType &vec, template template void DataFrame:: -fill_missing(const ColumnVecType &col_names, +fill_missing(const StlVecType &col_names, fill_policy fp, - const ColumnVecType &values, + const StlVecType &values, int limit) { const size_type count = col_names.size(); - ColumnVecType> futures(get_thread_level()); + StlVecType> futures(get_thread_level()); size_type thread_count = 0; for (size_type i = 0; i < count; ++i) { - ColumnVecType &vec = get_column(col_names[i]); + StlVecType &vec = get_column(col_names[i]); if (fp == fill_policy::value) { if (thread_count >= get_thread_level()) @@ -581,14 +581,14 @@ template template typename DataFrame::size_type DataFrame:: replace(const char *col_name, - const ColumnVecType &old_values, - const ColumnVecType &new_values, + const StlVecType &old_values, + const StlVecType &new_values, int limit) { - ColumnVecType &vec = get_column(col_name); + StlVecType &vec = get_column(col_name); size_type count = 0; - _replace_vector_vals_, T> + _replace_vector_vals_, T> (vec, old_values, new_values, count, limit); return (count); @@ -598,8 +598,8 @@ replace(const char *col_name, template typename DataFrame::size_type DataFrame:: -replace_index(const ColumnVecType &old_values, - const ColumnVecType &new_values, +replace_index(const StlVecType &old_values, + const StlVecType &new_values, int limit) { size_type count = 0; @@ -617,7 +617,7 @@ template void DataFrame:: replace(const char *col_name, F &functor) { - ColumnVecType &vec = get_column(col_name); + StlVecType &vec = get_column(col_name); const size_type vec_s = vec.size(); for (size_type i = 0; i < vec_s; ++i) @@ -632,16 +632,16 @@ template template std::future::size_type> DataFrame:: replace_async(const char *col_name, - const ColumnVecType &old_values, - const ColumnVecType &new_values, + const StlVecType &old_values, + const StlVecType &new_values, int limit) { return (std::async(std::launch::async, &DataFrame::replace, this, col_name, - std::forward>(old_values), - std::forward>(new_values), + std::forward>(old_values), + std::forward>(new_values), limit)); } @@ -716,7 +716,7 @@ void DataFrame::sort(const char *name, sort_spec dir) { sort_common_(*this, std::move(d)); } else { - const ColumnVecType &idx_vec = get_column(name); + const StlVecType &idx_vec = get_column(name); auto a = [&x = idx_vec](size_type i, size_type j) -> bool { return (x[i] < x[j]); @@ -743,16 +743,16 @@ sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; + StlVecType *vec1 { nullptr}; + StlVecType *vec2 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); @@ -791,22 +791,22 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; - ColumnVecType *vec3 { nullptr}; + StlVecType *vec1 { nullptr}; + StlVecType *vec2 { nullptr}; + StlVecType *vec3 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); if (! ::strcmp(name3, DF_INDEX_COL_NAME)) - vec3 = reinterpret_cast *>(&indices_); + vec3 = reinterpret_cast *>(&indices_); else vec3 = &(get_column(name3)); @@ -859,28 +859,28 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; - ColumnVecType *vec3 { nullptr}; - ColumnVecType *vec4 { nullptr}; + StlVecType *vec1 { nullptr}; + StlVecType *vec2 { nullptr}; + StlVecType *vec3 { nullptr}; + StlVecType *vec4 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); if (! ::strcmp(name3, DF_INDEX_COL_NAME)) - vec3 = reinterpret_cast *>(&indices_); + vec3 = reinterpret_cast *>(&indices_); else vec3 = &(get_column(name3)); if (! ::strcmp(name4, DF_INDEX_COL_NAME)) - vec4 = reinterpret_cast *>(&indices_); + vec4 = reinterpret_cast *>(&indices_); else vec4 = &(get_column(name4)); @@ -947,34 +947,34 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; - ColumnVecType *vec3 { nullptr}; - ColumnVecType *vec4 { nullptr}; - ColumnVecType *vec5 { nullptr}; + StlVecType *vec1 { nullptr}; + StlVecType *vec2 { nullptr}; + StlVecType *vec3 { nullptr}; + StlVecType *vec4 { nullptr}; + StlVecType *vec5 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); if (! ::strcmp(name3, DF_INDEX_COL_NAME)) - vec3 = reinterpret_cast *>(&indices_); + vec3 = reinterpret_cast *>(&indices_); else vec3 = &(get_column(name3)); if (! ::strcmp(name4, DF_INDEX_COL_NAME)) - vec4 = reinterpret_cast *>(&indices_); + vec4 = reinterpret_cast *>(&indices_); else vec4 = &(get_column(name4)); if (! ::strcmp(name4, DF_INDEX_COL_NAME)) - vec5 = reinterpret_cast *>(&indices_); + vec5 = reinterpret_cast *>(&indices_); else vec5 = &(get_column(name5)); @@ -1139,14 +1139,14 @@ template DataFrame DataFrame:: groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { - const ColumnVecType *gb_vec { nullptr }; + const StlVecType *gb_vec { nullptr }; if (! ::strcmp(col_name, DF_INDEX_COL_NAME)) - gb_vec = (const ColumnVecType *) &(get_index()); + gb_vec = (const StlVecType *) &(get_index()); else - gb_vec = (const ColumnVecType *) &(get_column(col_name)); + gb_vec = (const StlVecType *) &(get_column(col_name)); - ColumnVecType sort_v (gb_vec->size(), 0); + StlVecType sort_v (gb_vec->size(), 0); std::iota(sort_v.begin(), sort_v.end(), 0); std::sort(sort_v.begin(), sort_v.end(), @@ -1187,23 +1187,23 @@ groupby2(const char *col_name1, I_V &&idx_visitor, Ts&& ... args) const { - const ColumnVecType *gb_vec1 { nullptr }; - const ColumnVecType *gb_vec2 { nullptr }; + const StlVecType *gb_vec1 { nullptr }; + const StlVecType *gb_vec2 { nullptr }; if (! ::strcmp(col_name1, DF_INDEX_COL_NAME)) { - gb_vec1 = (const ColumnVecType *) &(get_index()); - gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); + gb_vec1 = (const StlVecType *) &(get_index()); + gb_vec2 = (const StlVecType *) &(get_column(col_name2)); } else if (! ::strcmp(col_name2, DF_INDEX_COL_NAME)) { - gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); - gb_vec2 = (const ColumnVecType *) &(get_index()); + gb_vec1 = (const StlVecType *) &(get_column(col_name1)); + gb_vec2 = (const StlVecType *) &(get_index()); } else { - gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); - gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); + gb_vec1 = (const StlVecType *) &(get_column(col_name1)); + gb_vec2 = (const StlVecType *) &(get_column(col_name2)); } - ColumnVecType sort_v (std::min(gb_vec1->size(), + StlVecType sort_v (std::min(gb_vec1->size(), gb_vec2->size()), 0); @@ -1255,32 +1255,32 @@ groupby3(const char *col_name1, I_V &&idx_visitor, Ts&& ... args) const { - const ColumnVecType *gb_vec1 { nullptr }; - const ColumnVecType *gb_vec2 { nullptr }; - const ColumnVecType *gb_vec3 { nullptr }; + const StlVecType *gb_vec1 { nullptr }; + const StlVecType *gb_vec2 { nullptr }; + const StlVecType *gb_vec3 { nullptr }; if (! ::strcmp(col_name1, DF_INDEX_COL_NAME)) { - gb_vec1 = (const ColumnVecType *) &(get_index()); - gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); - gb_vec3 = (const ColumnVecType *) &(get_column(col_name3)); + gb_vec1 = (const StlVecType *) &(get_index()); + gb_vec2 = (const StlVecType *) &(get_column(col_name2)); + gb_vec3 = (const StlVecType *) &(get_column(col_name3)); } else if (! ::strcmp(col_name2, DF_INDEX_COL_NAME)) { - gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); - gb_vec2 = (const ColumnVecType *) &(get_index()); - gb_vec3 = (const ColumnVecType *) &(get_column(col_name3)); + gb_vec1 = (const StlVecType *) &(get_column(col_name1)); + gb_vec2 = (const StlVecType *) &(get_index()); + gb_vec3 = (const StlVecType *) &(get_column(col_name3)); } else if (! ::strcmp(col_name3, DF_INDEX_COL_NAME)) { - gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); - gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); - gb_vec3 = (const ColumnVecType *) &(get_index()); + gb_vec1 = (const StlVecType *) &(get_column(col_name1)); + gb_vec2 = (const StlVecType *) &(get_column(col_name2)); + gb_vec3 = (const StlVecType *) &(get_index()); } else { - gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); - gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); - gb_vec3 = (const ColumnVecType *) &(get_column(col_name3)); + gb_vec1 = (const StlVecType *) &(get_column(col_name1)); + gb_vec2 = (const StlVecType *) &(get_column(col_name2)); + gb_vec3 = (const StlVecType *) &(get_column(col_name3)); } - ColumnVecType sort_v( + StlVecType sort_v( std::min({ gb_vec1->size(), gb_vec2->size(), gb_vec3->size() }), 0); std::iota(sort_v.begin(), sort_v.end(), 0); @@ -1391,7 +1391,7 @@ template DataFrame> DataFrame::value_counts (const char *col_name) const { - const ColumnVecType &vec = get_column(col_name); + const StlVecType &vec = get_column(col_name); auto hash_func = [](std::reference_wrapper v) -> std::size_t { return(std::hash{}(v.get())); @@ -1422,8 +1422,8 @@ DataFrame::value_counts (const char *col_name) const { insert_result.first->second += 1; } - ColumnVecType res_indices; - ColumnVecType counts; + StlVecType res_indices; + StlVecType counts; counts.reserve(values_map.size()); res_indices.reserve(values_map.size()); @@ -1440,7 +1440,7 @@ DataFrame::value_counts (const char *col_name) const { DataFrame> result_df; result_df.load_index(std::move(res_indices)); - result_df.load_column("counts", std::move(counts)); + result_df.template load_column("counts", std::move(counts)); return(result_df); } @@ -1517,13 +1517,13 @@ transpose(IndexVecType &&indices, const V &new_col_names) const { "Length of new_col_names is not equal " "to number of rows"); - ColumnVecType *> current_cols; + StlVecType *> current_cols; current_cols.reserve(num_cols); for (const auto &citer : column_list_) current_cols.push_back(&(get_column(citer.first.c_str()))); - ColumnVecType> trans_cols(indices_.size()); + StlVecType> trans_cols(indices_.size()); DataFrame df; for (size_type i = 0; i < indices_.size(); ++i) { @@ -1538,7 +1538,8 @@ transpose(IndexVecType &&indices, const V &new_col_names) const { df.load_index(std::move(indices)); for (size_type i = 0; i < new_col_names.size(); ++i) - df.load_column(&(new_col_names[i][0]), std::move(trans_cols[i])); + df.template load_column(&(new_col_names[i][0]), + std::move(trans_cols[i])); return (df); } diff --git a/include/DataFrame/Internals/DataFrame_functors.h b/include/DataFrame/Internals/DataFrame_functors.h index bdd951e01..934036189 100644 --- a/include/DataFrame/Internals/DataFrame_functors.h +++ b/include/DataFrame/Internals/DataFrame_functors.h @@ -63,11 +63,11 @@ struct shrink_to_fit_functor_ : DataVec::template visitor_base { template struct sort_functor_ : DataVec::template visitor_base { - inline sort_functor_ (const ColumnVecType &si, size_t is) + inline sort_functor_ (const StlVecType &si, size_t is) : sorted_idxs(si), idx_s(is) { } - const ColumnVecType &sorted_idxs; - ColumnVecType sorted_idxs_copy; + const StlVecType &sorted_idxs; + StlVecType sorted_idxs_copy; const size_t idx_s; template @@ -373,12 +373,12 @@ friend struct rotate_functor_; template class OPT, typename ... Ts> struct operator_functor_ : DataVec::template visitor_base { - inline operator_functor_ (const ColumnVecType &lhsidx, - const ColumnVecType &rhsidx, - const ColumnVecType &newidx, - const StdDataFrame &rhsdf, + inline operator_functor_ (const StlVecType &lhsidx, + const StlVecType &rhsidx, + const StlVecType &newidx, + const DataFrame &rhsdf, const char *colname, - StdDataFrame &resultdf) + DataFrame &resultdf) : lhs_idx(lhsidx), rhs_idx(rhsidx), new_idx(newidx), @@ -386,12 +386,12 @@ struct operator_functor_ : DataVec::template visitor_base { col_name(colname), result_df(resultdf) { } - const ColumnVecType &lhs_idx; - const ColumnVecType &rhs_idx; - const ColumnVecType &new_idx; - const StdDataFrame &rhs_df; + const StlVecType &lhs_idx; + const StlVecType &rhs_idx; + const StlVecType &new_idx; + const DataFrame &rhs_df; const char *col_name; - StdDataFrame &result_df; + DataFrame &result_df; template void operator() (const T &lhs_vec); @@ -458,13 +458,13 @@ template struct sel_load_functor_ : DataVec::template visitor_base { inline sel_load_functor_ (const char *n, - const ColumnVecType &si, + const StlVecType &si, size_type is, DataFrame &d) : name (n), sel_indices (si), indices_size(is), df(d) { } const char *name; - const ColumnVecType &sel_indices; + const StlVecType &sel_indices; const size_type indices_size; DataFrame &df; @@ -478,13 +478,13 @@ template struct sel_load_view_functor_ : DataVec::template visitor_base { inline sel_load_view_functor_ (const char *n, - const ColumnVecType &si, + const StlVecType &si, size_type is, DF &d) : name (n), sel_indices (si), indices_size(is), dfv(d) { } const char *name; - const ColumnVecType &sel_indices; + const StlVecType &sel_indices; const size_type indices_size; DF &dfv; @@ -512,10 +512,10 @@ struct concat_load_view_functor_ : DataVec::template visitor_base { template struct sel_remove_functor_ : DataVec::template visitor_base { - inline sel_remove_functor_ (const ColumnVecType &si) + inline sel_remove_functor_ (const StlVecType &si) : sel_indices (si) { } - const ColumnVecType &sel_indices; + const StlVecType &sel_indices; template void operator() (T &vec) const; @@ -539,12 +539,12 @@ struct random_load_data_functor_ : DataVec::template visitor_base { inline random_load_data_functor_ ( const char *n, - const ColumnVecType &ri, + const StlVecType &ri, DataFrame &d) : name (n), rand_indices (ri), df(d) { } const char *name; - const ColumnVecType &rand_indices; + const StlVecType &rand_indices; DataFrame &df; template @@ -558,12 +558,12 @@ struct random_load_view_functor_ : DataVec::template visitor_base { inline random_load_view_functor_ ( const char *n, - const ColumnVecType &ri, + const StlVecType &ri, DF &d) : name (n), rand_indices (ri), dfv(d) { } const char *name; - const ColumnVecType &rand_indices; + const StlVecType &rand_indices; DF &dfv; template @@ -576,7 +576,7 @@ template struct columns_info_functor_ : DataVec::template visitor_base { using result_t = - ColumnVecType>; + StlVecType>; inline columns_info_functor_ (result_t &r, const char *n) : result(r), name(n) { } @@ -594,12 +594,12 @@ template struct copy_remove_functor_ : DataVec::template visitor_base { inline copy_remove_functor_ (const char *n, - const ColumnVecType &td, + const StlVecType &td, DataFrame &d) : name(n), to_delete (td), df(d) { } const char *name; - const ColumnVecType &to_delete; + const StlVecType &to_delete; DataFrame &df; template @@ -632,11 +632,11 @@ struct fill_missing_functor_ : template struct describe_functor_ : DataVec::template visitor_base { - inline describe_functor_ (const char *n, StdDataFrame &r) + inline describe_functor_ (const char *n, DataFrame &r) : name(n), result(r) { } const char *name; - StdDataFrame &result; + DataFrame &result; template void operator() (const T &vec); diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index fabb400fe..f2cc88d4b 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -216,7 +216,7 @@ DataFrame::get_index() { return (indices_); } template template HeteroVector DataFrame:: -get_row(size_type row_num, const ColumnVecType &col_names) const { +get_row(size_type row_num, const StlVecType &col_names) const { if (row_num >= indices_.size()) { char buffer [512]; @@ -376,11 +376,11 @@ DataFrame::get_data_by_idx (Index2D range) const { template template DataFrame DataFrame:: -get_data_by_idx(const ColumnVecType &values) const { +get_data_by_idx(const StlVecType &values) const { const std::unordered_set val_table(values.begin(), values.end()); IndexVecType new_index; - ColumnVecType locations; + StlVecType locations; const size_type values_s = values.size(); const size_type idx_s = indices_.size(); @@ -501,7 +501,7 @@ DataFrame::get_view_by_idx (Index2D range) const { template template typename DataFrame::PtrView DataFrame:: -get_view_by_idx(const ColumnVecType &values) { +get_view_by_idx(const StlVecType &values) { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); @@ -511,7 +511,7 @@ get_view_by_idx(const ColumnVecType &values) { const std::unordered_set val_table(values.begin(), values.end()); typename TheView::IndexVecType new_index; - ColumnVecType locations; + StlVecType locations; const size_type values_s = values.size(); const size_type idx_s = indices_.size(); @@ -549,7 +549,7 @@ template template typename DataFrame::ConstPtrView DataFrame:: -get_view_by_idx(const ColumnVecType &values) const { +get_view_by_idx(const StlVecType &values) const { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); @@ -559,7 +559,7 @@ get_view_by_idx(const ColumnVecType &values) const { const std::unordered_set val_table(values.begin(), values.end()); typename TheView::IndexVecType new_index; - ColumnVecType locations; + StlVecType locations; const size_type values_s = values.size(); const size_type idx_s = indices_.size(); @@ -638,7 +638,7 @@ DataFrame::get_data_by_loc (Index2D range) const { template template DataFrame DataFrame:: -get_data_by_loc (const ColumnVecType &locations) const { +get_data_by_loc (const StlVecType &locations) const { const size_type idx_s = indices_.size(); DataFrame df; @@ -768,7 +768,7 @@ DataFrame::get_view_by_loc (Index2D range) const { template template typename DataFrame::PtrView -DataFrame::get_view_by_loc (const ColumnVecType &locations) { +DataFrame::get_view_by_loc (const StlVecType &locations) { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -809,7 +809,7 @@ template template typename DataFrame::ConstPtrView DataFrame:: -get_view_by_loc (const ColumnVecType &locations) const { +get_view_by_loc (const StlVecType &locations) const { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_loc()"); @@ -854,7 +854,7 @@ get_data_by_sel (const char *name, F &sel_functor) const { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) @@ -896,7 +896,7 @@ get_view_by_sel (const char *name, F &sel_functor) { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) @@ -941,7 +941,7 @@ get_view_by_sel (const char *name, F &sel_functor) const { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) @@ -985,7 +985,7 @@ get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1035,7 +1035,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1088,7 +1088,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1142,7 +1142,7 @@ get_data_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1201,7 +1201,7 @@ get_data_by_sel (F &sel_functor) const { cols_for_filter); // Get the index of all records that meet the filters - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) { @@ -1266,7 +1266,7 @@ get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { cols_for_filter); // Get the index of all records that meet the filters - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) { @@ -1326,7 +1326,7 @@ get_view_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1385,7 +1385,7 @@ get_view_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1445,7 +1445,7 @@ get_data_by_sel(const char *name1, const size_type col_s4 = vec4.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1507,7 +1507,7 @@ get_view_by_sel(const char *name1, const size_type col_s4 = vec4.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1572,7 +1572,7 @@ get_view_by_sel(const char *name1, const size_type col_s4 = vec4.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1636,7 +1636,7 @@ get_data_by_sel(const char *name1, const size_type col_s5 = vec5.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4, col_s5 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1703,7 +1703,7 @@ get_view_by_sel(const char *name1, const size_type col_s5 = vec5.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4, col_s5 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1773,7 +1773,7 @@ get_view_by_sel(const char *name1, const size_type col_s5 = vec5.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3, col_s4, col_s5 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1842,7 +1842,7 @@ get_data_by_rand(random_policy spec, double n, size_type seed) const { if (use_seed) gen.seed(static_cast(seed)); std::uniform_int_distribution dis(0, index_s - 1); - ColumnVecType rand_indices(n_rows); + StlVecType rand_indices(n_rows); for (size_type i = 0; i < n_rows; ++i) rand_indices[i] = dis(gen); @@ -1916,7 +1916,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) { if (use_seed) gen.seed(static_cast(seed)); std::uniform_int_distribution dis(0, index_s - 1); - ColumnVecType rand_indices(n_rows); + StlVecType rand_indices(n_rows); for (size_type i = 0; i < n_rows; ++i) rand_indices[i] = dis(gen); @@ -1991,7 +1991,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { if (use_seed) gen.seed(static_cast(seed)); std::uniform_int_distribution dis(0, index_s - 1); - ColumnVecType rand_indices(n_rows); + StlVecType rand_indices(n_rows); for (size_type i = 0; i < n_rows; ++i) rand_indices[i] = dis(gen); @@ -2042,7 +2042,7 @@ get_view_by_rand (random_policy spec, double n, size_type seed) const { template template DataFrame DataFrame:: -get_data(const ColumnVecType &col_names) const { +get_data(const StlVecType &col_names) const { DataFrame df; @@ -2074,7 +2074,7 @@ get_data(const ColumnVecType &col_names) const { template template typename DataFrame::View DataFrame:: -get_view(const ColumnVecType &col_names) { +get_view(const StlVecType &col_names) { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view()"); @@ -2115,7 +2115,7 @@ template template typename DataFrame::ConstView DataFrame:: -get_view(const ColumnVecType &col_names) const { +get_view(const StlVecType &col_names) const { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view()"); @@ -2287,13 +2287,13 @@ get_reindexed_view(const char *col_to_be_index, template template -typename DataFrame::template ColumnVecType< +typename DataFrame::template StlVecType< std::tuple::ColNameType, typename DataFrame::size_type, std::type_index>> DataFrame::get_columns_info () const { - ColumnVecType> result; + StlVecType> result; result.reserve(column_list_.size()); @@ -2365,13 +2365,13 @@ pattern_match(const char *col_name, template template -typename DataFrame::template ColumnVecType DataFrame:: +typename DataFrame::template StlVecType DataFrame:: combine(const char *col_name, const DF &rhs, F &functor) const { const auto &lhs_col = get_column(col_name); const auto &rhs_col = rhs.template get_column(col_name); const size_type col_s = std::min(lhs_col.size(), rhs_col.size()); - ColumnVecType result; + StlVecType result; result.reserve(col_s); for (size_type i = 0; i < col_s; ++i) @@ -2384,7 +2384,7 @@ combine(const char *col_name, const DF &rhs, F &functor) const { template template -typename DataFrame::template ColumnVecType DataFrame:: +typename DataFrame::template StlVecType DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2395,7 +2395,7 @@ combine(const char *col_name, const auto &df2_col = df2.template get_column(col_name); const size_type col_s = std::min({ lhs_col.size(), df1_col.size(), df2_col.size() }); - ColumnVecType result; + StlVecType result; result.reserve(col_s); for (size_type i = 0; i < col_s; ++i) @@ -2409,7 +2409,7 @@ combine(const char *col_name, template template -typename DataFrame::template ColumnVecType DataFrame:: +typename DataFrame::template StlVecType DataFrame:: combine(const char *col_name, const DF1 &df1, const DF2 &df2, @@ -2422,7 +2422,7 @@ combine(const char *col_name, const auto &df3_col = df3.template get_column(col_name); const size_type col_s = std::min( { lhs_col.size(), df1_col.size(), df2_col.size(), df3_col.size() }); - ColumnVecType result; + StlVecType result; result.reserve(col_s); for (size_type i = 0; i < col_s; ++i) diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index ffd2866aa..44fa94464 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -54,8 +54,8 @@ join_by_index (const RHS_T &rhs, join_policy mp) const { const auto &rhs_idx = rhs.get_index(); const size_type lhs_idx_s = lhs_idx.size(); const size_type rhs_idx_s = rhs_idx.size(); - ColumnVecType> idx_vec_lhs; - ColumnVecType> idx_vec_rhs; + StlVecType> idx_vec_lhs; + StlVecType> idx_vec_rhs; idx_vec_lhs.reserve(lhs_idx_s); for (size_type i = 0; i < lhs_idx_s; ++i) @@ -116,8 +116,8 @@ join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { const size_type lhs_vec_s = lhs_vec.size(); const size_type rhs_vec_s = rhs_vec.size(); - ColumnVecType> col_vec_lhs; - ColumnVecType> col_vec_rhs; + StlVecType> col_vec_lhs; + StlVecType> col_vec_rhs; col_vec_lhs.reserve(lhs_vec_s); for (size_type i = 0; i < lhs_vec_s; ++i) @@ -222,7 +222,7 @@ index_join_helper_(const LHS_T &lhs, const IndexIdxVector &joined_index_idx) { DataFrame> result; - ColumnVecType result_index; + StlVecType result_index; // Load the index result_index.reserve(joined_index_idx.size()); @@ -266,9 +266,9 @@ column_join_helper_(const LHS_T &lhs, // Load the lhs and rhs indices into two columns in the result // Also load the unified named column - ColumnVecType lhs_index; - ColumnVecType rhs_index; - ColumnVecType named_col_vec; + StlVecType lhs_index; + StlVecType rhs_index; + StlVecType named_col_vec; const ColumnVecType &lhs_named_col_vec = lhs.template get_column(col_name); const ColumnVecType &rhs_named_col_vec = @@ -298,10 +298,10 @@ column_join_helper_(const LHS_T &lhs, char buffer[64]; ::snprintf(buffer, sizeof(buffer) - 1, "lhs.%s", DF_INDEX_COL_NAME); - result.load_column(buffer, std::move(lhs_index)); + result.template load_column(buffer, std::move(lhs_index)); ::snprintf(buffer, sizeof(buffer) - 1, "rhs.%s", DF_INDEX_COL_NAME); - result.load_column(buffer, std::move(rhs_index)); - result.load_column(col_name, std::move(named_col_vec)); + result.template load_column(buffer, std::move(rhs_index)); + result.template load_column(col_name, std::move(named_col_vec)); join_helper_common_ (lhs, rhs, joined_index_idx, result, col_name); @@ -314,8 +314,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_inner_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -348,12 +348,12 @@ template DataFrame> DataFrame:: index_inner_join_( const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (index_join_helper_ - (lhs, rhs, - get_inner_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + (lhs, rhs, + get_inner_index_idx_vector_(col_vec_lhs, col_vec_rhs))); } // ---------------------------------------------------------------------------- @@ -365,12 +365,12 @@ DataFrame:: column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, - get_inner_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + get_inner_index_idx_vector_(col_vec_lhs, col_vec_rhs))); } // ---------------------------------------------------------------------------- @@ -379,8 +379,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_left_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -420,12 +420,13 @@ template template DataFrame> DataFrame:: index_left_join_(const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (index_join_helper_ (lhs, rhs, - get_left_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + get_left_index_idx_vector_(col_vec_lhs, + col_vec_rhs))); } // ---------------------------------------------------------------------------- @@ -437,12 +438,12 @@ DataFrame:: column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, - get_left_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + get_left_index_idx_vector_(col_vec_lhs, col_vec_rhs))); } // ---------------------------------------------------------------------------- @@ -451,8 +452,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_right_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -497,12 +498,13 @@ template DataFrame> DataFrame:: index_right_join_( const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (index_join_helper_ (lhs, rhs, - get_right_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + get_right_index_idx_vector_(col_vec_lhs, + col_vec_rhs))); } // ---------------------------------------------------------------------------- @@ -514,12 +516,12 @@ DataFrame:: column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, - get_right_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + get_right_index_idx_vector_(col_vec_lhs, col_vec_rhs))); } // ---------------------------------------------------------------------------- @@ -528,8 +530,8 @@ template template typename DataFrame::IndexIdxVector DataFrame::get_left_right_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { size_type lhs_current = 0; const size_type lhs_end = col_vec_lhs.size(); @@ -582,12 +584,13 @@ DataFrame> DataFrame:: index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (index_join_helper_ (lhs, rhs, - get_left_right_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + get_left_right_index_idx_vector_(col_vec_lhs, + col_vec_rhs))); } // ---------------------------------------------------------------------------- @@ -599,12 +602,13 @@ DataFrame:: column_left_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs) { + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs) { return (column_join_helper_ (lhs, rhs, col_name, - get_left_right_index_idx_vector_(col_vec_lhs, col_vec_rhs))); + get_left_right_index_idx_vector_(col_vec_lhs, + col_vec_rhs))); } // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Internals/DataFrame_misc.tcc b/include/DataFrame/Internals/DataFrame_misc.tcc index 7c80e5c01..9e72e2b85 100644 --- a/include/DataFrame/Internals/DataFrame_misc.tcc +++ b/include/DataFrame/Internals/DataFrame_misc.tcc @@ -112,7 +112,7 @@ DataFrame::load_all_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; - df.load_column(name, { vec.begin(), vec.end() }, + df.template load_column(name, { vec.begin(), vec.end() }, nan_policy::pad_with_nans); return; } @@ -375,8 +375,8 @@ index_join_functor_common_::operator()(const T &lhs_vec) { using ValueType = typename VecType::value_type; const ColumnVecType &rhs_vec = rhs.get_column(name); - ColumnVecType lhs_result_col; - ColumnVecType rhs_result_col; + StlVecType lhs_result_col; + StlVecType rhs_result_col; lhs_result_col.reserve(joined_index_idx.size()); rhs_result_col.reserve(joined_index_idx.size()); @@ -397,8 +397,8 @@ index_join_functor_common_::operator()(const T &lhs_vec) { ::snprintf(lhs_str, sizeof(lhs_str) - 1, "lhs.%s", name); ::snprintf(rhs_str, sizeof(rhs_str) - 1, "rhs.%s", name); - result.load_column(lhs_str, std::move(lhs_result_col)); - result.load_column(rhs_str, std::move(rhs_result_col)); + result.template load_column(lhs_str, std::move(lhs_result_col)); + result.template load_column(rhs_str, std::move(rhs_result_col)); } // ---------------------------------------------------------------------------- @@ -412,7 +412,7 @@ operator()(const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; - ColumnVecType result_col; + StlVecType result_col; result_col.reserve(joined_index_idx.size()); for (const auto &citer : joined_index_idx) { @@ -423,7 +423,7 @@ operator()(const T &vec) { ? vec[i] : get_nan()); } - result.load_column(name, std::move(result_col)); + result.template load_column(name, std::move(result_col)); } // ---------------------------------------------------------------------------- @@ -438,11 +438,11 @@ operator()(const T &vec) { using ValueType = typename VecType::value_type; if (insert_col) { - ColumnVecType res_vec(original_index_s + vec.size(), + StlVecType res_vec(original_index_s + vec.size(), get_nan()); std::copy(vec.begin(), vec.end(), res_vec.begin() + original_index_s); - result.load_column(name, res_vec); + result.template load_column(name, res_vec); } else { ColumnVecType &res_vec = @@ -507,7 +507,7 @@ operator()(const T &lhs_vec) { const size_type new_col_size = std::min(std::min(lhs_vec.size(), rhs_vec.size()), new_idx.size()); - ColumnVecType new_col; + StlVecType new_col; auto Operator = OPT(); size_type lcounter = 0; size_type rcounter = 0; @@ -530,7 +530,7 @@ operator()(const T &lhs_vec) { } if (! new_col.empty()) - result_df.load_column(col_name, std::move(new_col)); + result_df.template load_column(col_name, std::move(new_col)); return; } @@ -602,7 +602,7 @@ operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; - ColumnVecType new_col; + StlVecType new_col; const size_type vec_size = vec.size(); new_col.reserve(std::min(sel_indices.size(), vec_size)); @@ -616,7 +616,9 @@ operator() (const T &vec) { break; } - df.load_column(name, std::move(new_col), nan_policy::dont_pad_with_nans); + df.template load_column(name, + std::move(new_col), + nan_policy::dont_pad_with_nans); return; } @@ -764,7 +766,7 @@ random_load_data_functor_::operator() (const T &vec) { break; } - df.load_column(name, + df.template load_column(name, std::move(new_vec), nan_policy::dont_pad_with_nans); return; @@ -843,7 +845,7 @@ DataFrame::copy_remove_functor_::operator() (const T &vec) { this->to_delete.end(), n) != this->to_delete.end()); }); - df.load_column(name, + df.template load_column(name, std::move(new_vec), nan_policy::dont_pad_with_nans); } @@ -886,7 +888,7 @@ DataFrame::describe_functor_::operator() (const T &vec) { using VecType = typename std::remove_reference::type; using ValueType = typename VecType::value_type; - ColumnVecType col_to_load; + StlVecType col_to_load; col_to_load.reserve(describe_index_col.size()); col_to_load.push_back(double(vec_s)); @@ -940,7 +942,7 @@ DataFrame::describe_functor_::operator() (const T &vec) { qt75.post(); col_to_load.push_back(double(qt75.get_result())); - result.load_column(name, std::move(col_to_load)); + result.template load_column(name, std::move(col_to_load)); } } // namespace hmdf diff --git a/include/DataFrame/Internals/DataFrame_private_decl.h b/include/DataFrame/Internals/DataFrame_private_decl.h index fd5c5ea36..caf5f65d4 100644 --- a/include/DataFrame/Internals/DataFrame_private_decl.h +++ b/include/DataFrame/Internals/DataFrame_private_decl.h @@ -59,39 +59,39 @@ sort_common_(DataFrame &df, CF &&comp_func); template static void -fill_missing_value_(ColumnVecType &vec, +fill_missing_value_(StlVecType &vec, const T &value, int limit, size_type col_num); template static void -fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num); +fill_missing_ffill_(StlVecType &vec, int limit, size_type col_num); template::value && std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type col_num); +fill_missing_midpoint_(StlVecType &vec, int limit, size_type col_num); template::value || ! std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type col_num); +fill_missing_midpoint_(StlVecType &vec, int limit, size_type col_num); template static void -fill_missing_bfill_(ColumnVecType &vec, int limit); +fill_missing_bfill_(StlVecType &vec, int limit); template::value && std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_linter_(ColumnVecType &vec, +fill_missing_linter_(StlVecType &vec, const IndexVecType &index, int limit); @@ -100,7 +100,7 @@ template::value || ! std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_linter_(ColumnVecType &, const IndexVecType &, int); +fill_missing_linter_(StlVecType &, const IndexVecType &, int); // Maps row number -> number of missing column(s) using DropRowMap = std::map; @@ -117,7 +117,7 @@ template void setup_view_column_(const char *name, Index2D range); -using IndexIdxVector = ColumnVecType>; +using IndexIdxVector = StlVecType>; template using JoinSortingPair = std::pair; @@ -147,65 +147,65 @@ column_join_helper_(const LHS_T &lhs, template static IndexIdxVector get_inner_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> index_inner_join_( const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> column_inner_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static IndexIdxVector get_left_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> index_left_join_( const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> column_left_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static IndexIdxVector get_right_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> index_right_join_( const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> column_right_join_(const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame @@ -221,15 +221,15 @@ concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns); template static IndexIdxVector get_left_right_index_idx_vector_( - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> index_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); template static DataFrame> @@ -237,8 +237,503 @@ column_left_right_join_( const LHS_T &lhs, const RHS_T &rhs, const char *col_name, - const ColumnVecType> &col_vec_lhs, - const ColumnVecType> &col_vec_rhs); + const StlVecType> &col_vec_lhs, + const StlVecType> &col_vec_rhs); + +// ---------------------------------------------------------------------------- + +template +static inline void +_sort_by_sorted_index_(T &to_be_sorted, + StlVecType &sorting_idxs, + size_t idx_s) { + + if (idx_s > 0) { + idx_s -= 1; + for (size_t i = 0; i < idx_s; ++i) { + // while the element i is not yet in place + // + while (sorting_idxs[i] != sorting_idxs[sorting_idxs[i]]) { + // swap it with the element at its final place + // + const size_t j = sorting_idxs[i]; + + std::swap(to_be_sorted[j], to_be_sorted[sorting_idxs[j]]); + std::swap(sorting_idxs[i], sorting_idxs[j]); + } + } + } +} + +// ---------------------------------------------------------------------------- + +template +inline static void +_replace_vector_vals_(V &data_vec, + const StlVecType &old_values, + const StlVecType &new_values, + std::size_t &count, + int limit) { + + const std::size_t vcnt = old_values.size(); + + assert(vcnt == new_values.size()); + + const std::size_t vec_s = data_vec.size(); + + for (std::size_t i = 0; i < vcnt; ++i) { + for (std::size_t j = 0; j < vec_s; ++j) { + if (limit >= 0 && count >= static_cast(limit)) + return; + if (old_values[i] == data_vec[j]) { + data_vec[j] = new_values[i]; + count += 1; + } + } + } +} + +// ---------------------------------------------------------------------------- + +template +inline static void +_col_vector_push_back_(V &vec, + std::istream &file, + T (*converter)(const char *, char **, int), + io_format file_type = io_format::csv) { + + char value[8192]; + char c = 0; + + while (file.get(c)) { + if (file_type == io_format::csv && c == '\n') break; + else if (file_type == io_format::json && c == ']') break; + file.unget(); + _get_token_from_file_(file, ',', value, + file_type == io_format::json ? ']' : '\0'); + vec.push_back(static_cast(converter(value, nullptr, 0))); + } +} + +// ---------------------------------------------------------------------------- + +template +inline static void +_col_vector_push_back_(V &vec, + std::istream &file, + T (*converter)(const char *, char **), + io_format file_type = io_format::csv) { + + char value[8192]; + char c = 0; + + while (file.get(c)) { + if (file_type == io_format::csv && c == '\n') break; + else if (file_type == io_format::json && c == ']') break; + file.unget(); + _get_token_from_file_(file, ',', value, + file_type == io_format::json ? ']' : '\0'); + vec.push_back(static_cast(converter(value, nullptr))); + } +} + +// ---------------------------------------------------------------------------- + +template<> +inline static void +_col_vector_push_back_>( + StlVecType &vec, + std::istream &file, + const char * (*)(const char *, char **), + io_format file_type) { + + char value[8192]; + char c = 0; + + while (file.get(c)) { + if (file_type == io_format::csv && c == '\n') break; + else if (file_type == io_format::json && c == ']') break; + file.unget(); + _get_token_from_file_(file, ',', value, + file_type == io_format::json ? ']' : '\0'); + vec.push_back(value); + } +} + +// ---------------------------------------------------------------------------- + +template<> +inline static void +_col_vector_push_back_>( + StlVecType &vec, + std::istream &file, + DateTime (*)(const char *, char **), + io_format file_type) { + + char value[1024]; + char c = 0; + + while (file.get(c)) { + if (file_type == io_format::csv && c == '\n') break; + else if (file_type == io_format::json && c == ']') break; + file.unget(); + _get_token_from_file_(file, ',', value, + file_type == io_format::json ? ']' : '\0'); + + time_t t; + int n; + DateTime dt; + +#ifdef _MSC_VER + ::sscanf(value, "%lld.%d", &t, &n); +#else + ::sscanf(value, "%ld.%d", &t, &n); +#endif // _MSC_VER + dt.set_time(t, n); + vec.emplace_back(std::move(dt)); + } +} + +// ---------------------------------------------------------------------------- + +inline static void +_json_str_col_vector_push_back_(StlVecType &vec, + std::istream &file) { + + char value[1024]; + char c = 0; + + while (file.get(c)) + if (c != ' ' && c != '\n' && c != '\t') { + file.unget(); + break; + } + + while (file.get(c)) { + if (c == ']') break; + file.unget(); + + std::size_t count = 0; + + while (file.get(c)) + if (c != ' ' && c != '\n' && c != '\t') break; + if (c != '"') + throw DataFrameError( + "_json_str_col_vector_push_back_(): ERROR: Expected '\"' (0)"); + + while (file.get(c)) + if (c == '"') + break; + else + value[count++] = c; + if (c != '"') + throw DataFrameError( + "DataFrame::read_json_(): ERROR: Expected '\"' (1)"); + + value[count] = 0; + vec.push_back(value); + + while (file.get(c)) + if (c != ' ' && c != '\n' && c != '\t') break; + if (c == ']') break; + else if (c != ',') + throw DataFrameError( + "_json_str_col_vector_push_back_(): ERROR: Expected ',' (2)"); + } +} + +// ---------------------------------------------------------------------------- + +template +struct _IdxParserFunctor_ { + + void operator()(StlVecType &, std::istream &, io_format) { } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtof, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtod, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtold, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtol, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtol, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtoll, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtoul, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtoul, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtoull, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + auto converter = + [](const char *s, char **)-> const char * { return s; }; + + _col_vector_push_back_> + (vec, file, converter, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + auto converter = + [](const char *, char **)-> DateTime { return DateTime(); }; + + _col_vector_push_back_> + (vec, file, converter, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template<> +struct _IdxParserFunctor_ { + + inline void operator()(StlVecType &vec, + std::istream &file, + io_format file_type = io_format::csv) { + + _col_vector_push_back_(vec, file, &::strtol, file_type); + } +}; + +// ---------------------------------------------------------------------------- + +template +inline static void +_generate_ts_index_(StlVecType &index_vec, + DateTime &start_di, + time_frequency t_freq, + long increment) { + + switch(t_freq) { + case time_frequency::annual: + index_vec.push_back(static_cast(start_di.date())); + start_di.add_years(increment); + break; + case time_frequency::monthly: + index_vec.push_back(static_cast(start_di.date())); + start_di.add_months(increment); + break; + case time_frequency::weekly: + index_vec.push_back(static_cast(start_di.date())); + start_di.add_days(increment * 7); + break; + case time_frequency::daily: + index_vec.push_back(static_cast(start_di.date())); + start_di.add_days(increment); + break; + case time_frequency::hourly: + index_vec.push_back(static_cast(start_di.time())); + start_di.add_seconds(increment * 60 * 60); + break; + case time_frequency::minutely: + index_vec.push_back(static_cast(start_di.time())); + start_di.add_seconds(increment * 60); + break; + case time_frequency::secondly: + index_vec.push_back(static_cast(start_di.time())); + start_di.add_seconds(increment); + break; + case time_frequency::millisecondly: + index_vec.push_back(static_cast(start_di.long_time())); + start_di.add_nanoseconds(increment * 1000000); + break; + default: + break; + } +} + +// ---------------------------------------------------------------------------- + +template<> +inline static void +_generate_ts_index_(StlVecType &index_vec, + DateTime &start_di, + time_frequency t_freq, + long increment) { + + index_vec.push_back(start_di); + switch(t_freq) { + case time_frequency::annual: + start_di.add_years(increment); + break; + case time_frequency::monthly: + start_di.add_months(increment); + break; + case time_frequency::weekly: + start_di.add_days(increment * 7); + break; + case time_frequency::daily: + start_di.add_days(increment); + break; + case time_frequency::hourly: + start_di.add_seconds(increment * 60 * 60); + break; + case time_frequency::minutely: + start_di.add_seconds(increment * 60); + break; + case time_frequency::secondly: + start_di.add_seconds(increment); + break; + case time_frequency::millisecondly: + start_di.add_nanoseconds(increment * 1000000); + break; + default: + break; + } +} + +// ---------------------------------------------------------------------------- + +template +inline static void _get_mem_numbers_(const VectorView &, + size_t &used_mem, + size_t &capacity_mem) { + + used_mem = sizeof(T *) * 2; + capacity_mem = sizeof(T *) * 2; +} + +// ---------------------------------------------------------------------------- + +template +inline static void +_get_mem_numbers_(const VectorPtrView &container, + size_t &used_mem, + size_t &capacity_mem) { + + used_mem = container.size() * sizeof(T *); + capacity_mem = container.capacity() * sizeof(T *); +} + +// ---------------------------------------------------------------------------- + +template +inline static void _get_mem_numbers_(const StlVecType &container, + size_t &used_mem, + size_t &capacity_mem) { + + used_mem = container.size() * sizeof(T); + capacity_mem = container.capacity() * sizeof(T); +} // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Internals/DataFrame_read.tcc b/include/DataFrame/Internals/DataFrame_read.tcc index 166afd6ad..a86dd4894 100644 --- a/include/DataFrame/Internals/DataFrame_read.tcc +++ b/include/DataFrame/Internals/DataFrame_read.tcc @@ -171,19 +171,19 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { } else { if (! ::strcmp(col_type, "float")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtof, io_format::json); } else if (! ::strcmp(col_type, "double")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtod, io_format::json); } else if (! ::strcmp(col_type, "longdouble")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -193,13 +193,13 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "int")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtol, io_format::json); } else if (! ::strcmp(col_type, "uint")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -209,13 +209,13 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "long")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtol, io_format::json); } else if (! ::strcmp(col_type, "longlong")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -225,7 +225,7 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "ulong")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -235,7 +235,7 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { io_format::json); } else if (! ::strcmp(col_type, "ulonglong")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(col_size); @@ -243,24 +243,24 @@ void DataFrame::read_json_(std::istream &stream, bool columns_only) { (vec, stream, &::strtoull, io_format::json); } else if (! ::strcmp(col_type, "string")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(col_size); _json_str_col_vector_push_back_(vec, stream); } else if (! ::strcmp(col_type, "DateTime")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); auto converter = [](const char *, char **)-> DateTime { return DateTime(); }; vec.reserve(col_size); - _col_vector_push_back_> + _col_vector_push_back_> (vec, stream, converter, io_format::json); } else if (! ::strcmp(col_type, "bool")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(col_size); _col_vector_push_back_(vec, stream, &::strtol, io_format::json); @@ -333,86 +333,86 @@ void DataFrame::read_csv_(std::istream &stream, bool columns_only) { } else { if (! ::strcmp(type_str, "float")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtof); } else if (! ::strcmp(type_str, "double")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtod); } else if (! ::strcmp(type_str, "longdouble")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtold); } else if (! ::strcmp(type_str, "int")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtol); } else if (! ::strcmp(type_str, "uint")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoul); } else if (! ::strcmp(type_str, "long")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtol); } else if (! ::strcmp(type_str, "longlong")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoll); } else if (! ::strcmp(type_str, "ulong")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoul); } else if (! ::strcmp(type_str, "ulonglong")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtoull); } else if (! ::strcmp(type_str, "string")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); auto converter = [](const char *s, char **)-> const char * { return s; }; vec.reserve(::atoi(value)); - _col_vector_push_back_> + _col_vector_push_back_> (vec, stream, converter); } else if (! ::strcmp(type_str, "DateTime")) { - ColumnVecType &vec = + StlVecType &vec = create_column(col_name); auto converter = [](const char *, char **)-> DateTime { return DateTime(); }; vec.reserve(::atoi(value)); - _col_vector_push_back_> + _col_vector_push_back_> (vec, stream, converter); } else if (! ::strcmp(type_str, "bool")) { - ColumnVecType &vec = create_column(col_name); + StlVecType &vec = create_column(col_name); vec.reserve(::atoi(value)); _col_vector_push_back_(vec, stream, &::strtol); @@ -432,14 +432,14 @@ struct _col_data_spec_ { String32 type_spec { }; String64 col_name { }; - template class V> - inline _col_data_spec_(V cv, + template + inline _col_data_spec_(V cv, const char *ts, const char *cn, std::size_t rs) : col_vec(cv), type_spec(ts), col_name(cn) { - std::any_cast &>(col_vec).reserve(rs); + std::any_cast(col_vec).reserve(rs); } }; @@ -450,7 +450,7 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { char value[8192]; char c; - ColumnVecType<_col_data_spec_> spec_vec; + StlVecType<_col_data_spec_> spec_vec; bool header_read = false; size_type col_index = 0; @@ -484,63 +484,63 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { if (c == '\n' || c == '\r') header_read = true; if (! ::strcmp(type_str, "float")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "double")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "longdouble")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "int")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "uint")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "long")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "longlong")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "ulong")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "ulonglong")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "string")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); // This includes DateTime, DateTimeAME, DateTimeEUR, DateTimeISO else if (! ::strncmp(type_str, "DateTime", 8)) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); else if (! ::strcmp(type_str, "bool")) - spec_vec.emplace_back(ColumnVecType(), + spec_vec.emplace_back(StlVecType(), type_str, col_name, ::atoi(value)); @@ -555,48 +555,48 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { if (col_spec.type_spec == "float") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back(strtof(value, nullptr)); } else if (col_spec.type_spec == "double") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back(strtod(value, nullptr)); } else if (col_spec.type_spec == "longdouble") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back(strtold(value, nullptr)); } else if (col_spec.type_spec == "int") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( (int) strtol(value, nullptr, 0)); } else if (col_spec.type_spec == "uint") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( (unsigned int) strtoul(value, nullptr, 0)); } else if (col_spec.type_spec == "long") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( strtol(value, nullptr, 0)); } else if (col_spec.type_spec == "longlong") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( strtoll(value, nullptr, 0)); } else if (col_spec.type_spec == "ulong") { if (value[0] != '\0') { const unsigned long v = strtoul(value, nullptr, 0); - ColumnVecType &vec = - std::any_cast &> + StlVecType &vec = + std::any_cast &> (col_spec.col_vec); vec.push_back(v); @@ -604,12 +604,12 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { } else if (col_spec.type_spec == "ulonglong") { if (value[0] != '\0') - std::any_cast &> + std::any_cast &> (col_spec.col_vec).push_back( strtoull(value, nullptr, 0)); } else if (col_spec.type_spec == "string") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back(value); } else if (col_spec.type_spec == "DateTime") { @@ -624,23 +624,23 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { ::sscanf(value, "%ld.%d", &t, &n); #endif // _MSC_VER dt.set_time(t, n); - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( std::move(dt)); } } else if (col_spec.type_spec == "DateTimeAME") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( value, DT_DATE_STYLE::AME_STYLE); } else if (col_spec.type_spec == "DateTimeEUR") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( value, DT_DATE_STYLE::EUR_STYLE); } else if (col_spec.type_spec == "DateTimeISO") { - std::any_cast &> + std::any_cast &> (col_spec.col_vec).emplace_back( value, DT_DATE_STYLE::ISO_STYLE); } @@ -648,8 +648,8 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { if (value[0] != '\0') { const bool v = static_cast(strtoul(value, nullptr, 0)); - ColumnVecType &vec = - std::any_cast &>(col_spec.col_vec); + StlVecType &vec = + std::any_cast &>(col_spec.col_vec); vec.push_back(v); } @@ -676,68 +676,68 @@ void DataFrame::read_csv2_(std::istream &stream, bool columns_only) { if (col_spec.type_spec == "float") load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "double") load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "longdouble") load_column(col_spec.col_name.c_str(), std::move(std::any_cast< - ColumnVecType &> + StlVecType &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "int") load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "uint") load_column(col_spec.col_name.c_str(), std::move(std::any_cast< - ColumnVecType &> + StlVecType &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "long") load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "longlong") load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "ulong") load_column(col_spec.col_name.c_str(), std::move(std::any_cast< - ColumnVecType&> + StlVecType&> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "ulonglong") load_column(col_spec.col_name.c_str(), std::move( std::any_cast< - ColumnVecType &> + StlVecType &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "string") load_column(col_spec.col_name.c_str(), std::move(std::any_cast< - ColumnVecType &> + StlVecType &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (! ::strncmp(col_spec.type_spec.c_str(), "DateTime", 8)) load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); else if (col_spec.type_spec == "bool") load_column(col_spec.col_name.c_str(), - std::move(std::any_cast &> + std::move(std::any_cast &> (col_spec.col_vec)), nan_policy::dont_pad_with_nans); } diff --git a/include/DataFrame/Internals/DataFrame_set.tcc b/include/DataFrame/Internals/DataFrame_set.tcc index b5d5f9217..ffe11d7d4 100644 --- a/include/DataFrame/Internals/DataFrame_set.tcc +++ b/include/DataFrame/Internals/DataFrame_set.tcc @@ -168,7 +168,7 @@ retype_column (const char *name, "Data column name cannot be 'INDEX'"); const ColumnVecType &old_vec = get_column(name); - ColumnVecType new_vec; + StlVecType new_vec; new_vec.reserve(old_vec.size()); for (const auto &citer : old_vec) @@ -234,7 +234,7 @@ DataFrame::load_index(IndexVecType &&idx) { // ---------------------------------------------------------------------------- template -typename DataFrame::template ColumnVecType +typename DataFrame::template StlVecType DataFrame:: gen_datetime_index(const char *start_datetime, const char *end_datetime, @@ -246,7 +246,7 @@ gen_datetime_index(const char *start_datetime, DT_DATE_STYLE::AME_STYLE, tz); const DateTime end_di(end_datetime, DT_DATE_STYLE::AME_STYLE, tz); const double diff = end_di.diff_seconds(start_di); - ColumnVecType index_vec; + StlVecType index_vec; switch(t_freq) { case time_frequency::annual: @@ -293,13 +293,13 @@ gen_datetime_index(const char *start_datetime, // ---------------------------------------------------------------------------- template -typename DataFrame::template ColumnVecType +typename DataFrame::template StlVecType DataFrame:: gen_sequence_index (const IndexType &start_value, const IndexType &end_value, long increment) { - ColumnVecType index_vec; + StlVecType index_vec; IndexType sv = start_value; while (sv < end_value) { @@ -366,7 +366,7 @@ load_column (const char *name, } const auto iter = column_tb_.find (name); - ColumnVecType *vec_ptr = nullptr; + StlVecType *vec_ptr = nullptr; if (iter == column_tb_.end()) vec_ptr = &(create_column(name)); @@ -430,7 +430,7 @@ load_result_as_column(V &visitor, const char *name, nan_policy padding) { } const auto iter = column_tb_.find (name); - ColumnVecType *vec_ptr = nullptr; + StlVecType *vec_ptr = nullptr; if (iter == column_tb_.end()) vec_ptr = &(create_column(name)); @@ -453,7 +453,7 @@ typename DataFrame::size_type DataFrame:: load_indicators(const char *cat_col_name, const char *numeric_cols_prefix) { - using map_t = std::unordered_map *>; + using map_t = std::unordered_map *>; const auto &cat_col = get_column(cat_col_name); const auto col_s = cat_col.size(); @@ -489,12 +489,12 @@ template template typename DataFrame::size_type DataFrame:: -from_indicators(const ColumnVecType &ind_col_names, +from_indicators(const StlVecType &ind_col_names, const char *cat_col_name, const char *numeric_cols_prefixg) { const size_type ind_col_s = ind_col_names.size(); - ColumnVecType *> ind_cols(ind_col_s, nullptr); + StlVecType *> ind_cols(ind_col_s, nullptr); for (size_type i = 0; i < ind_col_s; ++i) ind_cols[i] = &(get_column(ind_col_names[i])); @@ -551,7 +551,7 @@ template typename DataFrame::size_type DataFrame:: load_column (const char *name, - ColumnVecType &&column, + StlVecType &&column, nan_policy padding) { const size_type idx_s = indices_.size(); @@ -581,7 +581,7 @@ load_column (const char *name, } const auto iter = column_tb_.find (name); - ColumnVecType *vec_ptr = nullptr; + StlVecType *vec_ptr = nullptr; if (iter == column_tb_.end()) vec_ptr = &(create_column(name)); @@ -604,7 +604,7 @@ typename DataFrame::size_type DataFrame:: load_align_column( const char *name, - ColumnVecType &&column, + StlVecType &&column, size_type interval, bool start_from_beginning, const T &null_value, @@ -629,7 +629,7 @@ load_align_column( throw InconsistentData (buffer); } - ColumnVecType new_col(idx_s, null_value); + StlVecType new_col(idx_s, null_value); size_type idx_idx { 0 }; if (start_from_beginning) { @@ -661,7 +661,7 @@ template typename DataFrame::size_type DataFrame:: load_column (const char *name, - const ColumnVecType &data, + const StlVecType &data, nan_policy padding) { return (load_column(name, { data.begin(), data.end() }, padding)); @@ -690,7 +690,7 @@ append_column (const char *name, Index2D range, nan_policy padding) { - ColumnVecType &vec = get_column(name); + StlVecType &vec = get_column(name); size_type s = std::distance(range.begin, range.end) + vec.size (); const size_type idx_s = indices_.size(); @@ -731,7 +731,7 @@ typename DataFrame::size_type DataFrame:: append_column (const char *name, const T &val, nan_policy padding) { - ColumnVecType &vec = get_column(name); + StlVecType &vec = get_column(name); size_type s = 1; const size_type idx_s = indices_.size(); @@ -886,7 +886,7 @@ void DataFrame::remove_data_by_sel (const char *name, F &sel_functor) { const ColumnVecType &vec = get_column(name); const size_type col_s = vec.size(); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(indices_.size() / 2); for (size_type i = 0; i < col_s; ++i) @@ -922,7 +922,7 @@ remove_data_by_sel (const char *name1, const char *name2, F &sel_functor) { const size_type col_s1 = vec1.size(); const size_type col_s2 = vec2.size(); const size_type min_col_s = std::min(col_s1, col_s2); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -968,7 +968,7 @@ remove_data_by_sel (const char *name1, const size_type col_s2 = vec2.size(); const size_type col_s3 = vec3.size(); const size_type min_col_s = std::min({ col_s1, col_s2, col_s3 }); - ColumnVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < min_col_s; ++i) @@ -1007,7 +1007,7 @@ remove_dups_common_(const DataFrame &s_df, const MAP &row_table, const IndexVecType &index) { - using count_vec = ColumnVecType; + using count_vec = StlVecType; count_vec rows_to_del; @@ -1070,7 +1070,7 @@ remove_duplicates (const char *name, remove_dup_spec rds) const { using data_tuple = std::tuple; - using count_vec = ColumnVecType; + using count_vec = StlVecType; using data_map = std::unordered_map; const ColumnVecType &vec = get_column(name); @@ -1106,7 +1106,7 @@ remove_duplicates (const char *name1, remove_dup_spec rds) const { using data_tuple = std::tuple; - using count_vec = ColumnVecType; + using count_vec = StlVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1146,7 +1146,7 @@ remove_duplicates (const char *name1, using data_tuple = std::tuple; - using count_vec = ColumnVecType; + using count_vec = StlVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1190,7 +1190,7 @@ remove_duplicates (const char *name1, using data_tuple = std::tuple; - using count_vec = ColumnVecType; + using count_vec = StlVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1238,7 +1238,7 @@ remove_duplicates (const char *name1, using data_tuple = std::tuple; - using count_vec = ColumnVecType; + using count_vec = StlVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); @@ -1291,7 +1291,7 @@ remove_duplicates (const char *name1, const T3 &, const T4 &, const T5 &, const T6 &, const IndexType &>; - using count_vec = ColumnVecType; + using count_vec = StlVecType; using data_map = std::unordered_map; const ColumnVecType &vec1 = get_column(name1); diff --git a/include/DataFrame/Internals/DataFrame_shift.tcc b/include/DataFrame/Internals/DataFrame_shift.tcc index 626825bea..4e46fa189 100644 --- a/include/DataFrame/Internals/DataFrame_shift.tcc +++ b/include/DataFrame/Internals/DataFrame_shift.tcc @@ -47,7 +47,7 @@ void DataFrame::self_shift(size_type periods, shift_policy sp) { if (periods > 0) { if (sp == shift_policy::down || sp == shift_policy::up) { vertical_shift_functor_ functor(periods, sp); - ColumnVecType> futures(get_thread_level()); + StlVecType> futures(get_thread_level()); size_type thread_count = 0; const size_type data_size = data_.size(); @@ -105,13 +105,13 @@ shift(size_type periods, shift_policy sp) const { template template -typename DataFrame::template ColumnVecType DataFrame:: +typename DataFrame::template StlVecType DataFrame:: shift(const char *col_name, size_type periods, shift_policy sp) const { static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call shift()"); - ColumnVecType result = get_column(col_name); + StlVecType result = get_column(col_name); vertical_shift_functor_ functor(periods, sp); functor (result); @@ -130,7 +130,7 @@ void DataFrame::self_rotate(size_type periods, shift_policy sp) { if (periods > 0) { if (sp == shift_policy::down || sp == shift_policy::up) { rotate_functor_ functor(periods, sp); - ColumnVecType> futures(get_thread_level()); + StlVecType> futures(get_thread_level()); size_type thread_count = 0; const size_type data_size = data_.size(); diff --git a/include/DataFrame/Internals/DataFrame_standalone.tcc b/include/DataFrame/Internals/DataFrame_standalone.tcc index 911edb4e6..b7f3f8664 100644 --- a/include/DataFrame/Internals/DataFrame_standalone.tcc +++ b/include/DataFrame/Internals/DataFrame_standalone.tcc @@ -62,7 +62,7 @@ _load_groupby_data_1_( T &triple, I_V &&idx_visitor, const V &input_v, - const typename DF::template ColumnVecType &sort_v, + const typename DF::template StlVecType &sort_v, const char *col_name) { std::size_t marker = 0; @@ -147,7 +147,7 @@ _load_groupby_data_2_( I_V &&idx_visitor, const V1 &input_v1, const V2 &input_v2, - const typename DF::template ColumnVecType &sort_v, + const typename DF::template StlVecType &sort_v, const char *col_name1, const char *col_name2) { @@ -245,7 +245,7 @@ _load_groupby_data_3_( const V1 &input_v1, const V2 &input_v2, const V3 &input_v3, - const typename DF::template ColumnVecType &sort_v, + const typename DF::template StlVecType &sort_v, const char *col_name1, const char *col_name2, const char *col_name3) { @@ -408,56 +408,6 @@ _load_bucket_data_(const DF &source, // ---------------------------------------------------------------------------- -template -static inline void -_sort_by_sorted_index_(T &to_be_sorted, - std::vector &sorting_idxs, - size_t idx_s) { - - if (idx_s > 0) { - idx_s -= 1; - for (size_t i = 0; i < idx_s; ++i) { - // while the element i is not yet in place - while (sorting_idxs[i] != sorting_idxs[sorting_idxs[i]]) { - // swap it with the element at its final place - const size_t j = sorting_idxs[i]; - - std::swap(to_be_sorted[j], to_be_sorted[sorting_idxs[j]]); - std::swap(sorting_idxs[i], sorting_idxs[j]); - } - } - } -} - -// ---------------------------------------------------------------------------- - -template -inline static void -_replace_vector_vals_(V &data_vec, - const std::vector &old_values, - const std::vector &new_values, - size_t &count, - int limit) { - - const size_t vcnt = old_values.size(); - - assert(vcnt == new_values.size()); - - const size_t vec_s = data_vec.size(); - - for (size_t i = 0; i < vcnt; ++i) { - for (size_t j = 0; j < vec_s; ++j) { - if (limit >= 0 && count >= static_cast(limit)) return; - if (old_values[i] == data_vec[j]) { - data_vec[j] = new_values[i]; - count += 1; - } - } - } -} - -// ---------------------------------------------------------------------------- - template inline static S &_write_json_df_index_(S &o, const T &value) { @@ -508,414 +458,6 @@ _get_token_from_file_ (std::istream &file, // ---------------------------------------------------------------------------- -template -inline static void -_col_vector_push_back_(V &vec, - std::istream &file, - T (*converter)(const char *, char **, int), - io_format file_type = io_format::csv) { - - char value[8192]; - char c = 0; - - while (file.get(c)) { - if (file_type == io_format::csv && c == '\n') break; - else if (file_type == io_format::json && c == ']') break; - file.unget(); - _get_token_from_file_(file, ',', value, - file_type == io_format::json ? ']' : '\0'); - vec.push_back(static_cast(converter(value, nullptr, 0))); - } -} - -// ---------------------------------------------------------------------------- - -template -inline static void -_col_vector_push_back_(V &vec, - std::istream &file, - T (*converter)(const char *, char **), - io_format file_type = io_format::csv) { - - char value[8192]; - char c = 0; - - while (file.get(c)) { - if (file_type == io_format::csv && c == '\n') break; - else if (file_type == io_format::json && c == ']') break; - file.unget(); - _get_token_from_file_(file, ',', value, - file_type == io_format::json ? ']' : '\0'); - vec.push_back(static_cast(converter(value, nullptr))); - } -} - -// ---------------------------------------------------------------------------- - -template<> -inline void -_col_vector_push_back_>( - std::vector &vec, - std::istream &file, - const char * (*)(const char *, char **), - io_format file_type) { - - char value[8192]; - char c = 0; - - while (file.get(c)) { - if (file_type == io_format::csv && c == '\n') break; - else if (file_type == io_format::json && c == ']') break; - file.unget(); - _get_token_from_file_(file, ',', value, - file_type == io_format::json ? ']' : '\0'); - vec.push_back(value); - } -} - -// ---------------------------------------------------------------------------- - -inline void -_json_str_col_vector_push_back_(std::vector &vec, - std::istream &file) { - - char value[1024]; - char c = 0; - - while (file.get(c)) - if (c != ' ' && c != '\n' && c != '\t') { - file.unget(); - break; - } - - while (file.get(c)) { - if (c == ']') break; - file.unget(); - - std::size_t count = 0; - - while (file.get(c)) - if (c != ' ' && c != '\n' && c != '\t') break; - if (c != '"') - throw DataFrameError( - "_json_str_col_vector_push_back_(): ERROR: Expected '\"' (0)"); - - while (file.get(c)) - if (c == '"') - break; - else - value[count++] = c; - if (c != '"') - throw DataFrameError( - "DataFrame::read_json_(): ERROR: Expected '\"' (1)"); - - value[count] = 0; - vec.push_back(value); - - while (file.get(c)) - if (c != ' ' && c != '\n' && c != '\t') break; - if (c == ']') break; - else if (c != ',') - throw DataFrameError( - "_json_str_col_vector_push_back_(): ERROR: Expected ',' (2)"); - } -} - -// ---------------------------------------------------------------------------- - -template<> -inline void -_col_vector_push_back_>( - std::vector &vec, - std::istream &file, - DateTime (*)(const char *, char **), - io_format file_type) { - - char value[1024]; - char c = 0; - - while (file.get(c)) { - if (file_type == io_format::csv && c == '\n') break; - else if (file_type == io_format::json && c == ']') break; - file.unget(); - _get_token_from_file_(file, ',', value, - file_type == io_format::json ? ']' : '\0'); - - time_t t; - int n; - DateTime dt; - -#ifdef _MSC_VER - ::sscanf(value, "%lld.%d", &t, &n); -#else - ::sscanf(value, "%ld.%d", &t, &n); -#endif // _MSC_VER - dt.set_time(t, n); - vec.emplace_back(std::move(dt)); - } -} - -// ---------------------------------------------------------------------------- - -template -struct _IdxParserFunctor_ { - - void operator()(std::vector &, std::istream &, io_format) { } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtof, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtod, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtold, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtol, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtol, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtoll, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtoul, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtoul, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtoull, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - auto converter = - [](const char *s, char **)-> const char * { return s; }; - - _col_vector_push_back_> - (vec, file, converter, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - auto converter = - [](const char *, char **)-> DateTime { return DateTime(); }; - - _col_vector_push_back_> - (vec, file, converter, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template<> -struct _IdxParserFunctor_ { - - inline void operator()(std::vector &vec, - std::istream &file, - io_format file_type = io_format::csv) { - - _col_vector_push_back_(vec, file, &::strtol, file_type); - } -}; - -// ---------------------------------------------------------------------------- - -template -inline static void -_generate_ts_index_(std::vector &index_vec, - DateTime &start_di, - time_frequency t_freq, - long increment) { - - switch(t_freq) { - case time_frequency::annual: - index_vec.push_back(static_cast(start_di.date())); - start_di.add_years(increment); - break; - case time_frequency::monthly: - index_vec.push_back(static_cast(start_di.date())); - start_di.add_months(increment); - break; - case time_frequency::weekly: - index_vec.push_back(static_cast(start_di.date())); - start_di.add_days(increment * 7); - break; - case time_frequency::daily: - index_vec.push_back(static_cast(start_di.date())); - start_di.add_days(increment); - break; - case time_frequency::hourly: - index_vec.push_back(static_cast(start_di.time())); - start_di.add_seconds(increment * 60 * 60); - break; - case time_frequency::minutely: - index_vec.push_back(static_cast(start_di.time())); - start_di.add_seconds(increment * 60); - break; - case time_frequency::secondly: - index_vec.push_back(static_cast(start_di.time())); - start_di.add_seconds(increment); - break; - case time_frequency::millisecondly: - index_vec.push_back(static_cast(start_di.long_time())); - start_di.add_nanoseconds(increment * 1000000); - break; - default: - break; - } -} - -// ---------------------------------------------------------------------------- - -template<> -inline void -_generate_ts_index_(std::vector &index_vec, - DateTime &start_di, - time_frequency t_freq, - long increment) { - - index_vec.push_back(start_di); - switch(t_freq) { - case time_frequency::annual: - start_di.add_years(increment); - break; - case time_frequency::monthly: - start_di.add_months(increment); - break; - case time_frequency::weekly: - start_di.add_days(increment * 7); - break; - case time_frequency::daily: - start_di.add_days(increment); - break; - case time_frequency::hourly: - start_di.add_seconds(increment * 60 * 60); - break; - case time_frequency::minutely: - start_di.add_seconds(increment * 60); - break; - case time_frequency::secondly: - start_di.add_seconds(increment); - break; - case time_frequency::millisecondly: - start_di.add_nanoseconds(increment * 1000000); - break; - default: - break; - } -} - -// ---------------------------------------------------------------------------- - template inline static S & _write_csv_df_header_base_(S &o, const char *col_name, std::size_t col_size) { @@ -1036,39 +578,6 @@ inline static S &_write_csv_df_index_(S &o, const DateTime &value) { // ---------------------------------------------------------------------------- -template -inline static void _get_mem_numbers_(const VectorView &, - size_t &used_mem, - size_t &capacity_mem) { - - used_mem = sizeof(T *) * 2; - capacity_mem = sizeof(T *) * 2; -} - -// ---------------------------------------------------------------------------- - -template -inline static void _get_mem_numbers_(const VectorPtrView &container, - size_t &used_mem, - size_t &capacity_mem) { - - used_mem = container.size() * sizeof(T *); - capacity_mem = container.capacity() * sizeof(T *); -} - -// ---------------------------------------------------------------------------- - -template -inline static void _get_mem_numbers_(const std::vector &container, - size_t &used_mem, - size_t &capacity_mem) { - - used_mem = container.size() * sizeof(T); - capacity_mem = container.capacity() * sizeof(T); -} - -// ---------------------------------------------------------------------------- - // // Specializing std::hash for tuples // diff --git a/test/dataframe_tester.cc b/test/dataframe_tester.cc index a41b4964f..e197ca52c 100644 --- a/test/dataframe_tester.cc +++ b/test/dataframe_tester.cc @@ -45,6 +45,9 @@ using namespace hmdf; // using MyDataFrame = StdDataFrame; +template +using StlVecType = typename MyDataFrame::template StlVecType; + // ----------------------------------------------------------------------------- struct ReplaceFunctor { @@ -82,16 +85,16 @@ static void test_haphazard() { df.create_column(static_cast("col_name")); - std::vector intvec = { 1, 2, 3, 4, 5 }; - std::vector dblvec = + StlVecType intvec = { 1, 2, 3, 4, 5 }; + StlVecType dblvec = { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, 0.1 }; - std::vector strvec = + StlVecType strvec = { "Col_name", "Col_name", "Col_name", "Col_name", "Col_name" }; - std::vector ulgvec = + StlVecType ulgvec = { 1UL, 2UL, 3UL, 4UL, 5UL, 8UL, 7UL, 6UL }; - std::vector xulgvec = ulgvec; + StlVecType xulgvec = ulgvec; MyDataFrame::size_type rc = df.load_data(std::move(ulgvec), @@ -116,7 +119,7 @@ static void test_haphazard() { df.append_column("str_col", "Additional column"); df.append_column("dbl_col", 10.56); - std::vector ivec = df.get_column ("int_col"); + StlVecType ivec = df.get_column ("int_col"); std::cout << std::endl; assert(df.get_column("int_col") == df.get_column(std::size_t(1))); @@ -159,8 +162,8 @@ static void test_haphazard() { assert(::abs(df.visit("dbl_col", quad_dvisitor).get_result() - 5.39745) < 0.0001); - std::vector dvec = df.get_column ("dbl_col"); - std::vector dvec2 = df.get_column ("dbl_col_2"); + StlVecType dvec = df.get_column ("dbl_col"); + StlVecType dvec2 = df.get_column ("dbl_col_2"); assert(dvec.size() == 9); assert(dvec[0] == 1.2345); @@ -335,26 +338,26 @@ static void test_haphazard() { std::cout << "\nTesting GROUPBY ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 123450, 123451, 123452, 123450, 123455, 123450, 123449, 123448, 123451, 123452, 123452, 123450, 123455, 123450, 123454, 123453, 123456, 123457, 123458, 123459, 123460, 123441, 123442, 123432, 123433, 123434, 123435, 123436 }; - std::vector xulgvec2 = ulgvec2; - std::vector intvec2 = + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 22, 23, 24, 25, 30, 33, 34, 35, 36, 40, 45, 46 }; - std::vector xdblvec2 = + StlVecType xdblvec2 = { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, 10.0, 4.25, 0.009, 1.111, 8.0, 2.2222, 3.3333, 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, 12.0, 6.25, 2.009, 3.111, 10.0, 4.2222, 5.3333 }; - std::vector dblvec22 = + StlVecType dblvec22 = { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, 0.1, 0.0056, 0.07865, -0.9999, 0.0111, 0.1002, -0.8888, 0.14, 0.0456, 0.078654, -0.8999, 0.01119, 0.8002, -0.9888, 0.2, 0.1056, 0.87865, -0.6999, 0.4111, 0.1902, -0.4888 }; - std::vector strvec2 = + StlVecType strvec2 = { "4% of something", "Description 4/5", "This is bad", "3.4% of GDP", "Market drops", "Market pulls back", "$15 increase", "Running fast", "C++14 development", @@ -544,12 +547,12 @@ static void test_transpose() { std::cout << "\nTesting transpose() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; MyDataFrame df; df.load_data(std::move(idx), @@ -558,8 +561,8 @@ static void test_transpose() { std::make_pair("col_3", d3), std::make_pair("col_4", d4)); - std::vector tidx = { 100, 101, 102, 104 }; - std::vector tcol_names = + StlVecType tidx = { 100, 101, 102, 104 }; + StlVecType tcol_names = { "tcol_1", "tcol_2", "tcol_3", "tcol_4", "tcol_5", "tcol_6", "tcol_7" }; MyDataFrame tdf = @@ -577,12 +580,12 @@ static void test_get_data_by_loc_slicing() { std::cout << "\nTesting get_data_by_loc()/slicing ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; MyDataFrame df; df.load_data(std::move(idx), @@ -622,13 +625,13 @@ static void test_remove_column() { std::cout << "\nTesting remove_column() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector i1 = { 22, 23, 24, 25 }; - std::vector s1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType i1 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "xx", "yy", "gg", "string" }; MyDataFrame df; @@ -647,7 +650,7 @@ static void test_remove_column() { std::cout << "After removing column `col_str`" << std::endl; df.write(std::cout); - std::vector d22 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d22 = { 8, 9, 10, 11, 12, 13, 14 }; df.load_column("col_2", std::move(d22)); std::cout << "After adding back column `col_2`" << std::endl; @@ -660,15 +663,15 @@ static void test_rename_column() { std::cout << "\nTesting rename_column() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; - std::vector i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; MyDataFrame df; df.load_data(std::move(idx), @@ -690,15 +693,15 @@ static void test_get_col_unique_values() { std::cout << "\nTesting get_col_unique_values() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 0.89, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; MyDataFrame df; df.load_data(std::move(idx), @@ -710,7 +713,7 @@ static void test_get_col_unique_values() { df.write(std::cout); std::cout << "Getting unique values in column col_3" << std::endl; - const std::vector result = + const StlVecType result = df.get_col_unique_values("col_3"); for (auto &iter : result) @@ -724,15 +727,15 @@ static void test_remove_data_by_idx() { std::cout << "\nTesting remove_data_by_idx() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; - std::vector i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; MyDataFrame df; df.load_data(std::move(idx), @@ -753,15 +756,15 @@ static void test_remove_data_by_loc() { std::cout << "\nTesting remove_data_by_loc() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -783,16 +786,16 @@ static void test_value_counts() { std::cout << "\nTesting value_counts() ..." << std::endl; const double my_nan = sqrt(-1); - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 15, 18, 19, 16, 21, my_nan, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -818,15 +821,15 @@ static void test_index_inner_join() { std::cout << "\nTesting Index Inner Join ..." << std::endl; - std::vector idx = + StlVecType idx = { 123456, 123451, 123452, 123453, 123454, 123455, 123450, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 7, 2, 3, 4, 5, 6, 1, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 7, 2, 3, 4, 5, 6, 1, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 14, 9, 10, 11, 12, 13, 8, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 21, 16, 15, 18, 19, 16, 15, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -835,18 +838,18 @@ static void test_index_inner_join() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector idx2 = + StlVecType idx2 = { 123452, 123453, 123455, 123458, 123466, 223450, 223451, 223454, 223456, 223457, 223459, 223460, 223462, 223461 }; - std::vector d12 = + StlVecType d12 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 114, 113 }; - std::vector d22 = + StlVecType d22 = { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, 130, 131, 11.89, 132 }; - std::vector d32 = + StlVecType d32 = { 115, 116, 115, 118, 119, 116, 121, 10.34, 11.56, 10.34, 12.3, 119.0, 10.34 }; - std::vector i12 = { 122, 123, 124, 125, 199 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; MyDataFrame df2; df2.load_data(std::move(idx2), @@ -874,15 +877,15 @@ static void test_index_left_join() { std::cout << "\nTesting Index Left Join ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -891,18 +894,18 @@ static void test_index_left_join() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector idx2 = + StlVecType idx2 = { 123452, 123453, 123455, 123458, 123466, 223450, 223451, 223454, 223456, 223457, 223459, 223460, 223461, 223462 }; - std::vector d12 = + StlVecType d12 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 113, 114 }; - std::vector d22 = + StlVecType d22 = { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, 130, 131, 132, 11.89 }; - std::vector d32 = + StlVecType d32 = { 115, 116, 115, 118, 119, 116, 121, 10.34, 11.56, 10.34, 12.3, 10.34, 119.0 }; - std::vector i12 = { 122, 123, 124, 125, 199 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; MyDataFrame df2; df2.load_data(std::move(idx2), @@ -930,15 +933,15 @@ static void test_index_right_join() { std::cout << "\nTesting Index Right Join ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -947,18 +950,18 @@ static void test_index_right_join() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector idx2 = + StlVecType idx2 = { 123452, 123453, 123455, 123458, 123466, 223450, 223451, 223454, 223456, 223457, 223459, 223460, 223461, 223462 }; - std::vector d12 = + StlVecType d12 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 113, 114 }; - std::vector d22 = + StlVecType d22 = { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, 130, 131, 132, 11.89 }; - std::vector d32 = + StlVecType d32 = { 115, 116, 115, 118, 119, 116, 121, 10.34, 11.56, 10.34, 12.3, 10.34, 119.0 }; - std::vector i12 = { 122, 123, 124, 125, 199 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; MyDataFrame df2; df2.load_data(std::move(idx2), @@ -986,15 +989,15 @@ static void test_index_left_right_join() { std::cout << "\nTesting Index Left Right Join ..." << std::endl; - std::vector idx = + StlVecType idx = { 123466, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123450 }; - std::vector d1 = { 14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 }; - std::vector d2 = + StlVecType d1 = { 14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 }; + StlVecType d2 = { 1.89, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 8 }; - std::vector d3 = + StlVecType d3 = { 19.0, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 15.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -1003,18 +1006,18 @@ static void test_index_left_right_join() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector idx2 = + StlVecType idx2 = { 123452, 123453, 123455, 123458, 123466, 223450, 223451, 223454, 223456, 223457, 223459, 223461, 223460, 223462 }; - std::vector d12 = + StlVecType d12 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 113, 112, 114 }; - std::vector d22 = + StlVecType d22 = { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, 130, 132, 131, 11.89 }; - std::vector d32 = + StlVecType d32 = { 115, 116, 115, 118, 119, 116, 121, 10.34, 11.56, 10.34, 10.34, 12.3, 119.0 }; - std::vector i12 = { 122, 123, 124, 125, 199 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; MyDataFrame df2; df2.load_data(std::move(idx2), @@ -1042,15 +1045,15 @@ static void test_largest_smallest_visitors() { std::cout << "\nTesting Largest/Smallest visitors ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -1105,13 +1108,13 @@ static void test_shifting_up_down() { std::cout << "\nTesting Shifting Up/Down/Left/Right ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = + StlVecType d1 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; - std::vector s1 = + StlVecType i1 = { 22, 23, 24, 25, 99 }; + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "uuuu", "iiii", "oooo", "pppp", "2222", "aaaa", "dddd", "ffff" }; MyDataFrame df; @@ -1151,13 +1154,13 @@ static void test_rotating_up_down() { std::cout << "\nTesting Rotating Up/Down/Left/Right ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = + StlVecType d1 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; - std::vector s1 = + StlVecType i1 = { 22, 23, 24, 25, 99 }; + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "uuuu", "iiii", "oooo", "pppp", "2222", "aaaa", "dddd", "ffff" }; MyDataFrame df; @@ -1198,10 +1201,10 @@ static void test_dataframe_with_datetime() { std::cout << "\nTesting DataFrame with DateTime ..." << std::endl; DateTime dt(20010102); - std::vector idx; - std::vector d1; - std::vector i1; - std::vector s1; + StlVecType idx; + StlVecType d1; + StlVecType i1; + StlVecType s1; idx.reserve(20); d1.reserve(20); @@ -1329,13 +1332,13 @@ static void test_dataframe_friend_multiplies_operator() { std::cout << "\nTesting DataFrame friend multiplies operator ..." << std::endl; - std::vector idx1 = + StlVecType idx1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 25, 40, 55 }; - std::vector idx2 = { 1, 2, 3, 4, 5, 8, 9, 22, 25, 40 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; - std::vector d2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - std::vector s1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; - std::vector s2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + StlVecType idx2 = { 1, 2, 3, 4, 5, 8, 9, 22, 25, 40 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType d2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + StlVecType s1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType s2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; MyDataFrame df1; MyDataFrame df2; @@ -1363,13 +1366,13 @@ static void test_dataframe_friend_divides_operator() { std::cout << "\nTesting DataFrame friend divides operator ..." << std::endl; - std::vector idx1 = + StlVecType idx1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 25, 40, 55 }; - std::vector idx2 = { 1, 2, 3, 4, 5, 8, 9, 22, 25, 40 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; - std::vector d2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - std::vector s1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; - std::vector s2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + StlVecType idx2 = { 1, 2, 3, 4, 5, 8, 9, 22, 25, 40 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType d2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + StlVecType s1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType s2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; MyDataFrame df1; MyDataFrame df2; @@ -1397,17 +1400,17 @@ static void test_fill_missing_values() { std::cout << "\nTesting fill_missing(values) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1415,14 +1418,14 @@ static void test_fill_missing_values() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, @@ -1435,7 +1438,7 @@ static void test_fill_missing_values() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; df.load_column("col_str", @@ -1463,17 +1466,17 @@ static void test_fill_missing_fill_forward() { std::cout << "\nTesting fill_missing(fill_forward) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1481,14 +1484,14 @@ static void test_fill_missing_fill_forward() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, @@ -1501,7 +1504,7 @@ static void test_fill_missing_fill_forward() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; df.load_column("col_str", @@ -1530,17 +1533,17 @@ static void test_fill_missing_fill_backward() { std::cout << "\nTesting fill_missing(fill_backward) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1548,19 +1551,19 @@ static void test_fill_missing_fill_backward() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, std::numeric_limits::quiet_NaN() }; - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; MyDataFrame df; @@ -1589,17 +1592,17 @@ static void test_fill_missing_fill_linear_interpolation() { std::cout << "\nTesting fill_missing(linear_interpolate) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1607,14 +1610,14 @@ static void test_fill_missing_fill_linear_interpolation() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, @@ -1643,17 +1646,17 @@ static void test_drop_missing_all_no_drop() { std::cout << "\nTesting drop_missing(all) no drop ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1661,19 +1664,19 @@ static void test_drop_missing_all_no_drop() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, std::numeric_limits::quiet_NaN() }; - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; MyDataFrame df; @@ -1700,10 +1703,10 @@ static void test_drop_missing_all_2_drop() { std::cout << "\nTesting drop_missing(all) 2 drop ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 7, @@ -1712,7 +1715,7 @@ static void test_drop_missing_all_2_drop() { std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1722,7 +1725,7 @@ static void test_drop_missing_all_2_drop() { 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, @@ -1732,12 +1735,12 @@ static void test_drop_missing_all_2_drop() { std::numeric_limits::quiet_NaN(), 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, std::numeric_limits::quiet_NaN() }; - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "", "iiii", "oooo", "pppp", "2222", "", "dddd" }; MyDataFrame df; @@ -1764,17 +1767,17 @@ static void test_drop_missing_any() { std::cout << "\nTesting drop_missing(any) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1782,19 +1785,19 @@ static void test_drop_missing_any() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, std::numeric_limits::quiet_NaN() }; - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; MyDataFrame df; @@ -1821,17 +1824,17 @@ static void test_drop_threashold_3() { std::cout << "\nTesting drop_missing(threshold=3) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -1839,19 +1842,19 @@ static void test_drop_threashold_3() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, std::numeric_limits::quiet_NaN() }; - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; MyDataFrame df; @@ -1878,27 +1881,27 @@ static void test_get_row() { std::cout << "\nTesting get_row() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, 10, 11, 12, + StlVecType d2 = { 8, 9, 10, 11, 12, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { 400.4, 16, 500.5, 18, 19, 16, + StlVecType d3 = { 400.4, 16, 500.5, 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, 11, 34, 25, + StlVecType i1 = { 22, 11, 34, 25, std::numeric_limits::quiet_NaN() }; MyDataFrame df; @@ -1908,14 +1911,14 @@ static void test_get_row() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; df.load_column("col_str", std::move(s1), nan_policy::dont_pad_with_nans); - std::vector i2 = { 22, 11 }; + StlVecType i2 = { 22, 11 }; df.load_column("col_int", std::move(i2), @@ -1924,7 +1927,7 @@ static void test_get_row() { std::cout << "Original DF:" << std::endl; df.write(std::cout); - std::vector columns = + StlVecType columns = {"col_1", "col_2", "col_3", "col_4", "col_str", "col_int"}; auto row2 = df.get_row(2, columns); @@ -1954,19 +1957,19 @@ static void test_auto_correlation() { std::cout << "\nTesting Auto Correlation ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 0.387, 0.123, 1.06, 0.65, 2.03, 0.4, 1.0, 0.007 }; - std::vector d2 = + StlVecType d2 = { 1.23, 1.22, 1.21, 1.20, 1.19, 1.185, 1.181, 1.19, 1.195, 1.189, 1.185, 1.18, 1.181, 1.186, 1.189, 1.19, 1.194, 1.198, 1.199, 1.197, 1.193 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -2015,18 +2018,18 @@ static void test_return() { std::cout << "\nTesting Return ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 0.387, 0.123, 1.06, 0.65, 2.03, 0.4, 1.0, 0.59 }; - std::vector d2 = + StlVecType d2 = { 1.23, 1.22, 1.21, 1.20, 1.19, 1.185, 1.181, 1.19, 1.195, 1.189, 1.185, 1.18, 1.181, 1.186, 1.189, 1.19, 1.194, 1.198, 1.199, 1.197, 1.193 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -2089,20 +2092,20 @@ static void test_median() { std::cout << "\nTesting Median ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d2 = + StlVecType d2 = { 1.0, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector i1 = + StlVecType i1 = { 1, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector i2 = + StlVecType i2 = { 1, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7, 5, 9, 15, 14, 13, 12, 6, 4 }; MyDataFrame df; @@ -2142,25 +2145,25 @@ static void test_tracking_error() { std::cout << "\nTesting Tracking Error ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d2 = + StlVecType d2 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d3 = + StlVecType d3 = { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, 17.1, 19.9, 3.3, 2.2, 10.8, 7.4, 5.3, 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; - std::vector d4 = + StlVecType d4 = { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, 16.1, 18.9, 2.3, 1.2, 9.8, 6.4, 4.3, 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; - std::vector d5 = + StlVecType d5 = { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, -1.56, 20.1, 25.5, 30.89, 11.1, 7.4, 5.3, 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; @@ -2213,25 +2216,25 @@ static void test_beta() { std::cout << "\nTesting Beta ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d2 = + StlVecType d2 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d3 = + StlVecType d3 = { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, 17.1, 19.9, 3.3, 2.2, 10.8, 7.4, 5.3, 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; - std::vector d4 = + StlVecType d4 = { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, 16.1, 18.9, 2.3, 1.2, 9.8, 6.4, 4.3, 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; - std::vector d5 = + StlVecType d5 = { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, -1.56, 20.1, 25.5, 30.89, 11.1, 7.4, 5.3, 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; @@ -2299,7 +2302,7 @@ static void test_gen_datetime_index() { // I am commenting some of these out because with timezone spec, // it will take too long for the test to run - std::vector idx_vec1 = + StlVecType idx_vec1 = MyDataFrame::gen_datetime_index("01/01/2018", "12/31/2038", time_frequency::annual, @@ -2395,7 +2398,7 @@ static void test_gen_datetime_index() { assert(idx_vec1[73202] == 1514819401000000000); assert(idx_vec1[73203] == 1514819401500000000); - std::vector idx_vec2 = + StlVecType idx_vec2 = StdDataFrame::gen_datetime_index( "01/01/2018", "12/31/2022", @@ -2422,19 +2425,19 @@ static void test_replace_1() { std::cout << "\nTesting replace(1) ..." << std::endl; - std::vector d1 = + StlVecType d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d2 = + StlVecType d2 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d3 = + StlVecType d3 = { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, 17.1, 19.9, 3.3, 2.2, 10.8, 7.4, 5.3, 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; - std::vector d4 = + StlVecType d4 = { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, 16.1, 18.9, 2.3, 1.2, 9.8, 6.4, 4.3, 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; - std::vector d5 = + StlVecType d5 = { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, -1.56, 20.1, 25.5, 30.89, 11.1, 7.4, 5.3, 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; MyDataFrame df; @@ -2508,19 +2511,19 @@ static void test_replace_2() { std::cout << "\nTesting replace(2) ..." << std::endl; - std::vector d1 = + StlVecType d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d2 = + StlVecType d2 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d3 = + StlVecType d3 = { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, 17.1, 19.9, 3.3, 2.2, 10.8, 7.4, 5.3, 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; - std::vector d4 = + StlVecType d4 = { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, 16.1, 18.9, 2.3, 1.2, 9.8, 6.4, 4.3, 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; - std::vector d5 = + StlVecType d5 = { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, -1.56, 20.1, 25.5, 30.89, 11.1, 7.4, 5.3, 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; MyDataFrame df; @@ -2567,22 +2570,22 @@ static void test_some_visitors() { std::cout << "\nTesting some visitors ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d2 = + StlVecType d2 = { 1.0, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector i1 = + StlVecType i1 = { 1, 1, 2, 4, 3, 4, 5, 2, 1, 2, 2, 3, 4, 5, 7, 1, 2, 3, 2, 6, 4 }; - std::vector i2 = + StlVecType i2 = { 1, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d3 = + StlVecType d3 = { 1, 10, std::numeric_limits::quiet_NaN(), 18, 19, 16, 17, 20, std::numeric_limits::quiet_NaN(), 2, 11, 7, std::numeric_limits::quiet_NaN(), 5, @@ -2613,7 +2616,7 @@ static void test_some_visitors() { assert(prod_result == 464486400); CumSumVisitor cum_sum_visit; - const std::vector &cum_sum_result = + const StlVecType &cum_sum_result = df.single_act_visit("dblcol_3", cum_sum_visit).get_result(); assert(cum_sum_result.size() == 20); @@ -2625,7 +2628,7 @@ static void test_some_visitors() { assert(std::isnan(cum_sum_result[8])); CumMaxVisitor cum_max_visit; - const std::vector &cum_max_result = + const StlVecType &cum_max_result = df.single_act_visit("dblcol_3", cum_max_visit).get_result(); assert(cum_max_result.size() == 20); @@ -2643,22 +2646,22 @@ static void test_mode() { std::cout << "\nTesting Mode ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d2 = + StlVecType d2 = { 1.0, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector i1 = + StlVecType i1 = { 1, 1, 2, 4, 3, 4, 5, 2, 1, 2, 2, 3, 4, 5, 7, 1, 2, 3, 2, 6, 4 }; - std::vector i2 = + StlVecType i2 = { 1, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7, 5, 9, 15, 14, 13, 12, 6, 4 }; - std::vector d3 = + StlVecType d3 = { 1, 10, std::numeric_limits::quiet_NaN(), 18, 19, 16, 17, 20, std::numeric_limits::quiet_NaN(), 2, 11, 7, std::numeric_limits::quiet_NaN(), 5, @@ -2708,13 +2711,13 @@ static void test_remove_data_by_sel() { std::cout << "\nTesting remove_data_by_sel() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; - std::vector s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; MyDataFrame df; auto shape = df.shape(); @@ -2727,7 +2730,9 @@ static void test_remove_data_by_sel() { std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_str", s1)); - df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); shape = df.shape(); assert(shape.first == 7); @@ -2793,13 +2798,13 @@ static void test_shuffle() { std::cout << "\nTesting shuffle() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; - std::vector s1 = { "11", "22", "33", "aa", "bb", "cc", "dd" }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd" }; MyDataFrame df; df.load_data(std::move(idx), @@ -2807,7 +2812,9 @@ static void test_shuffle() { std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_str", s1)); - df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); // std::cout << "Original DatFrasme:" << std::endl; // df.write(std::cout); @@ -2827,18 +2834,18 @@ static void test_SimpleRollAdopter() { std::cout << "\nTesting SimpleRollAdopter{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - std::vector d2 = { 8, 9, 10, 11, + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, std::numeric_limits::quiet_NaN(), 13, 14, std::numeric_limits::quiet_NaN(), 16, 17, 18 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; - std::vector d4 = { 22, 23, 24, 25, 26, 27 }; - std::vector s1 = + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; MyDataFrame df; @@ -2847,7 +2854,9 @@ static void test_SimpleRollAdopter() { std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_str", s1)); - df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); SimpleRollAdopter, double> min_roller( MinVisitor(), 3); @@ -2907,18 +2916,18 @@ static void test_ExponentialRollAdopter() { std::cout << "\nTesting ExponentialRollAdopter{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - std::vector d2 = { 8, 9, 10, 11, + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, std::numeric_limits::quiet_NaN(), 13, 14, std::numeric_limits::quiet_NaN(), 16, 17, 18 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; - std::vector d4 = { 22, 23, 24, 25, 26, 27 }; - std::vector s1 = + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; MyDataFrame df; @@ -2927,7 +2936,9 @@ static void test_ExponentialRollAdopter() { std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_str", s1)); - df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); ExponentialRollAdopter, double> hl_expo_mean_roller( MeanVisitor(), 3, exponential_decay_spec::halflife, 0.5); @@ -2998,18 +3009,18 @@ static void test_ExponentiallyWeightedMeanVisitor() { std::cout << "\nTesting ExponentiallyWeightedMeanVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - std::vector d2 = { 8, 9, 10, 11, + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, std::numeric_limits::quiet_NaN(), 13, 14, std::numeric_limits::quiet_NaN(), 16, 17, 18 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; - std::vector d4 = { 22, 23, 24, 25, 26, 27 }; - std::vector s1 = + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; MyDataFrame df; @@ -3018,7 +3029,9 @@ static void test_ExponentiallyWeightedMeanVisitor() { std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_str", s1)); - df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); ewm_v hl_expo_mean_roller(exponential_decay_spec::halflife, 0.5); const auto &hl_expo_result = @@ -3094,14 +3107,14 @@ static void test_get_data_by_rand() { std::cout << "\nTesting get_data_by_rand() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; - std::vector d4 = { 22, 23, 24, 25, 26, 27 }; - std::vector s1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; MyDataFrame df; @@ -3110,7 +3123,9 @@ static void test_get_data_by_rand() { std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_str", s1)); - df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); auto result = df.get_data_by_rand @@ -3121,12 +3136,12 @@ static void test_get_data_by_rand() { result2.write(std::cout); - std::vector idx2 = { 123450 }; - std::vector d12 = { 1 }; - std::vector d22 = { 8 }; - std::vector d32 = { 15 }; - std::vector d42 = { 22 }; - std::vector s12 = { "11" }; + StlVecType idx2 = { 123450 }; + StlVecType d12 = { 1 }; + StlVecType d22 = { 8 }; + StlVecType d32 = { 15 }; + StlVecType d42 = { 22 }; + StlVecType s12 = { "11" }; MyDataFrame df2; df2.load_data(std::move(idx2), @@ -3134,7 +3149,9 @@ static void test_get_data_by_rand() { std::make_pair("col_2", d22), std::make_pair("col_3", d32), std::make_pair("col_str", s12)); - df2.load_column("col_4", std::move(d42), nan_policy::dont_pad_with_nans); + df2.load_column("col_4", + std::move(d42), + nan_policy::dont_pad_with_nans); auto result3 = df2.get_data_by_rand @@ -3142,12 +3159,12 @@ static void test_get_data_by_rand() { result3.write(std::cout); - std::vector idx3 = { 123450, 123451 }; - std::vector d13 = { 1, 2 }; - std::vector d23 = { 8, 9 }; - std::vector d33 = { 15, 16 }; - std::vector d43 = { 22, 23 }; - std::vector s13 = { "11", "22" }; + StlVecType idx3 = { 123450, 123451 }; + StlVecType d13 = { 1, 2 }; + StlVecType d23 = { 8, 9 }; + StlVecType d33 = { 15, 16 }; + StlVecType d43 = { 22, 23 }; + StlVecType s13 = { "11", "22" }; MyDataFrame df3; df3.load_data(std::move(idx3), @@ -3155,7 +3172,9 @@ static void test_get_data_by_rand() { std::make_pair("col_2", d23), std::make_pair("col_3", d33), std::make_pair("col_str", s13)); - df3.load_column("col_4", std::move(d43), nan_policy::dont_pad_with_nans); + df3.load_column("col_4", + std::move(d43), + nan_policy::dont_pad_with_nans); auto result4 = df3.get_data_by_rand @@ -3163,12 +3182,12 @@ static void test_get_data_by_rand() { result4.write(std::cout); - std::vector idx4 = { 123450, 123451, 123452 }; - std::vector d14 = { 1, 2, 3 }; - std::vector d24 = { 8, 9, 10 }; - std::vector d34 = { 15, 16, 17 }; - std::vector d44 = { 22, 23, 24 }; - std::vector s14 = { "11", "22", "33" }; + StlVecType idx4 = { 123450, 123451, 123452 }; + StlVecType d14 = { 1, 2, 3 }; + StlVecType d24 = { 8, 9, 10 }; + StlVecType d34 = { 15, 16, 17 }; + StlVecType d44 = { 22, 23, 24 }; + StlVecType s14 = { "11", "22", "33" }; MyDataFrame df4; df4.load_data(std::move(idx4), @@ -3176,7 +3195,9 @@ static void test_get_data_by_rand() { std::make_pair("col_2", d24), std::make_pair("col_3", d34), std::make_pair("col_str", s14)); - df4.load_column("col_4", std::move(d44), nan_policy::dont_pad_with_nans); + df4.load_column("col_4", + std::move(d44), + nan_policy::dont_pad_with_nans); auto result5 = df4.get_data_by_rand @@ -3191,14 +3212,14 @@ static void test_write_json() { std::cout << "\nTesting write(json) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; - std::vector d4 = { 22, 23, 24, 25, 26, 27 }; - std::vector s1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; MyDataFrame df; @@ -3207,7 +3228,9 @@ static void test_write_json() { std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_str", s1)); - df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); std::cout << "Writing in JSON:" << std::endl; df.write(std::cout, @@ -3223,19 +3246,19 @@ static void test_diff() { const double my_nan = std::numeric_limits::quiet_NaN(); const double epsilon = 0.0000001; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { my_nan, 16, 15, 18, my_nan, 16, 21, 0.34, 1.56, 0.34, 2.3, my_nan, 19.0, 0.387, 0.123, 1.06, my_nan, 2.03, 0.4, 1.0, my_nan }; - std::vector d2 = + StlVecType d2 = { 1.23, 1.22, 1.21, 1.20, 1.19, 1.185, 1.181, 1.19, 1.195, 1.189, 1.185, 1.18, 1.181, 1.186, 1.189, 1.19, 1.194, 1.198, 1.199, 1.197, 1.193 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -3376,12 +3399,12 @@ static void test_get_data_by_loc_location() { std::cout << "\nTesting get_data_by_loc(locations) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; MyDataFrame df; df.load_data(std::move(idx), @@ -3390,9 +3413,9 @@ static void test_get_data_by_loc_location() { std::make_pair("col_3", d3), std::make_pair("col_4", d4)); - MyDataFrame df2 = df.get_data_by_loc(std::vector { 3, 6 }); + MyDataFrame df2 = df.get_data_by_loc(StlVecType { 3, 6 }); MyDataFrame df3 = - df.get_data_by_loc(std::vector { -4, -1 , 5 }); + df.get_data_by_loc(StlVecType { -4, -1 , 5 }); assert(df2.get_index().size() == 2); assert(df2.get_column("col_3").size() == 2); @@ -3423,12 +3446,12 @@ static void test_get_data_by_idx_values() { std::cout << "\nTesting get_data_by_idx(values) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; MyDataFrame df; df.load_data(std::move(idx), @@ -3439,10 +3462,10 @@ static void test_get_data_by_idx_values() { MyDataFrame df2 = df.get_data_by_idx( - std::vector { 123452, 123455 }); + StlVecType { 123452, 123455 }); MyDataFrame df3 = df.get_data_by_idx( - std::vector { 123449, 123450 }); + StlVecType { 123449, 123450 }); assert(df2.get_index().size() == 2); assert(df2.get_column("col_3").size() == 2); @@ -3475,16 +3498,16 @@ static void test_z_score_visitor() { std::cout << "\nTesting Z-Score visitors ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 99.00011, 99.00012, 99.00013, 99.00014, 99.00015, 99.00016, 99.000113, 99.000112, 99.000111, 99.00019, 99.00018, 99.00017, 99.000114, 99.000115, 99.000116, 99.000117, 99.000118, 99.000119, 99.0001114, 99.0001113, 99.0001112 }; - std::vector d2 = + StlVecType d2 = { 10.1, 20.1, 30.1, 40.1, 50.1, 60.1, 70.1, 120.1, 110.1, 28.1, 18.1, 100.1, 90.1, 80.1, 130.1, 140.1, 150.1, 160.1, 170.1, 180.1, 190.1 }; @@ -3544,7 +3567,7 @@ static void test_thread_safety() { auto do_work = []() { #endif // _MSC_VER MyDataFrame df; - std::vector vec; + StlVecType vec; for (size_t i = 0; i < vec_size; ++i) vec.push_back(i); @@ -3580,7 +3603,7 @@ static void test_thread_safety() { }; SpinLock lock; - std::vector thr_vec; + StlVecType thr_vec; MyDataFrame::set_lock(&lock); @@ -3600,17 +3623,17 @@ static void test_view_visitors() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL, 8UL, 9UL, 10UL }; - std::vector dblvec1 = { 1.1, 2.2, 3.3, 4.4, 5.5 }; - std::vector dblvec2 = { 2.2, 3.3, 4.4, 5.5, 6.6 }; - std::vector dblvec3 = + StlVecType dblvec1 = { 1.1, 2.2, 3.3, 4.4, 5.5 }; + StlVecType dblvec2 = { 2.2, 3.3, 4.4, 5.5, 6.6 }; + StlVecType dblvec3 = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 }; - std::vector dblvec4 = + StlVecType dblvec4 = { 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1 }; - std::vector dblvec5 = + StlVecType dblvec5 = { 1.1, 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1, 10.1 }; - std::vector dblvec6 = { 1.1, 1.1, 3.3, 3.3, 1.1 }; + StlVecType dblvec6 = { 1.1, 1.1, 3.3, 3.3, 1.1 }; df.load_data(std::move(idxvec), std::make_pair("dbl_col1", dblvec1), @@ -3842,12 +3865,12 @@ static void test_k_means() { p.seed = 4356; auto y_vec = gen_lognormal_dist(item_cnt, p); - std::vector points; + StlVecType points; points.reserve(item_cnt); for (size_t i = 0; i < item_cnt; ++i) points.push_back(Point(x_vec[i], y_vec[i])); - df.load_column("point_col", std::move(points)); + df.load_column("point_col", std::move(points)); KMeansVisitor<5, Point> km_visitor2(1000, point_distance); @@ -3935,8 +3958,8 @@ static void test_affinity_propagation() { const size_t item_cnt = 50; MyDataFrame df; RandGenParams p; - std::vector final_col; - std::vector col_data; + StlVecType final_col; + StlVecType col_data; p.seed = 3575984165U; @@ -4002,18 +4025,18 @@ static void test_multi_col_sort() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; - std::vector strvec = + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -4068,15 +4091,15 @@ static void test_join_by_column() { std::cout << "\nTesting join by column ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = + StlVecType d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -4085,17 +4108,17 @@ static void test_join_by_column() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector idx2 = + StlVecType idx2 = { 123452, 123453, 123455, 123458, 123466, 223450, 223451, 223454, 223456, 223457, 223459, 223460, 223461, 223462 }; - std::vector d12 = + StlVecType d12 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 113, 114 }; - std::vector d22 = + StlVecType d22 = { 8, 19, 110, 111, 9, 113, 114, 99, 122, 123, 130, 131, 20, 11.89 }; - std::vector d32 = + StlVecType d32 = { 115, 116, 115, 118, 119, 116, 121, 10.34, 11.56, 10.34, 12.3, 10.34, 119.0 }; - std::vector i12 = { 122, 123, 124, 125, 199 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; MyDataFrame df2; df2.load_data(std::move(idx2), @@ -4171,11 +4194,11 @@ static void test_DoubleCrossOver() { MyDataFrame::set_thread_level(10); - std::vector idx = + StlVecType idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 17, 16, 15, 14, 13, 14, 13, 12, 11, 12, 10, 9, 8, 7, 6, 7, 5 }; @@ -4230,11 +4253,11 @@ static void test_BollingerBand() { MyDataFrame::set_thread_level(10); - std::vector idx = + StlVecType idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 17, 16, 15, 14, 13, 14, 13, 12, 11, 12, 10, 9, 8, 7, 6, 7, 5 }; @@ -4274,11 +4297,11 @@ static void test_MACDVisitor() { std::cout << "\nTesting MACDVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 17, 16, 15, 14, 13, 14, 13, 12, 11, 12, 10, 9, 8, 7, 6, 7, 5 }; @@ -4328,11 +4351,11 @@ static void test_ExpandingRollAdopter() { std::cout << "\nTesting ExpandingRollAdopter{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; @@ -4359,11 +4382,11 @@ static void test_MADVisitor() { std::cout << "\nTesting MADVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; @@ -4402,11 +4425,11 @@ static void test_SEMVisitor() { std::cout << "\nTesting SEMVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; @@ -4427,17 +4450,17 @@ static void test_fill_missing_mid_point() { std::cout << "\nTesting fill_missing(mid_point) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -4445,14 +4468,14 @@ static void test_fill_missing_mid_point() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, @@ -4465,10 +4488,12 @@ static void test_fill_missing_mid_point() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; - df.load_column("col_str", std::move(s1), nan_policy::dont_pad_with_nans); + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); // std::cout << "Original DF:" << std::endl; // df.write(std::cout); @@ -4486,27 +4511,27 @@ static void test_fill_missing_df() { std::cout << "\nTesting fill_missing(DataFrame) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector idx2 = + StlVecType idx2 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 1234570, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, + StlVecType d1 = { 1, 2, 3, 4, std::numeric_limits::quiet_NaN(), 6, 7, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d12 = { 1, 2, 3, 4, + StlVecType d12 = { 1, 2, 3, 4, 100, 6, 7, 101, 102, std::numeric_limits::quiet_NaN(), 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, + StlVecType d2 = { 8, 9, std::numeric_limits::quiet_NaN(), 11, 12, std::numeric_limits::quiet_NaN(), @@ -4514,7 +4539,7 @@ static void test_fill_missing_df() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d22 = { 8, 9, + StlVecType d22 = { 8, 9, 200, 11, 12, 201, @@ -4522,30 +4547,30 @@ static void test_fill_missing_df() { 20, 22, 23, 30, 31, std::numeric_limits::quiet_NaN(), 1.89 }; - std::vector d3 = { std::numeric_limits::quiet_NaN(), + StlVecType d3 = { std::numeric_limits::quiet_NaN(), 16, std::numeric_limits::quiet_NaN(), 18, 19, 16, std::numeric_limits::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits::quiet_NaN() }; - std::vector d32 = { 300, + StlVecType d32 = { 300, 16, 301, 18, 19, 16, 303, 0.34, 1.56, 0.34, 2.3, 0.34 }; - std::vector i1 = { 22, + StlVecType i1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, std::numeric_limits::quiet_NaN() }; - std::vector xi1 = { 22, + StlVecType xi1 = { 22, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN(), 25, std::numeric_limits::quiet_NaN() }; - std::vector i12 = { 22, + StlVecType i12 = { 22, 400, 401, 25, @@ -4565,14 +4590,18 @@ static void test_fill_missing_df() { std::make_pair("col_3", d32), std::make_pair("col_4", i12)); - std::vector s1 = + StlVecType s1 = { "qqqq", "wwww", "", "rrrr", "tttt", "", "iiii", "" }; - std::vector s12 = + StlVecType s12 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "aaaa", "bbbb", "cccc", "dddd", "gggg", "hhhh", "kkkk" }; - df.load_column("col_str", std::move(s1), nan_policy::dont_pad_with_nans); - df2.load_column("col_str", std::move(s12), nan_policy::dont_pad_with_nans); + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); + df2.load_column("col_str", + std::move(s12), + nan_policy::dont_pad_with_nans); df.fill_missing(df2); @@ -4586,11 +4615,11 @@ static void test_quantile() { std::cout << "\nTesting QuantileVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; @@ -4867,18 +4896,18 @@ static void test_self_concat() { MyDataFrame df1; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; - std::vector strvec = + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -4889,7 +4918,7 @@ static void test_self_concat() { MyDataFrame df2 = df1; - df2.load_column("dbl_col_2", std::move(dblvec2)); + df2.load_column("dbl_col_2", std::move(dblvec2)); df1.self_concat(df2, true); assert(df1.get_index().size() == 30); @@ -4921,18 +4950,18 @@ static void test_concat() { MyDataFrame df1; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; - std::vector strvec = + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -4943,7 +4972,7 @@ static void test_concat() { MyDataFrame df2 = df1; - df2.load_column("dbl_col_2", std::move(dblvec2)); + df2.load_column("dbl_col_2", std::move(dblvec2)); auto result1 = df1.concat(df2); From 802975fb90ffcb5aefbe1c4f14aa03fc58605dfe Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Fri, 23 Dec 2022 10:22:51 -0500 Subject: [PATCH 11/25] Everything compiles. next vistors and tests --- .../Internals/DataFrame_private_decl.h | 25 - .../Internals/DataFrame_standalone.tcc | 25 + test/dataframe_tester_2.cc | 532 +++++++++--------- test/dataframe_tester_3.cc | 93 +-- 4 files changed, 340 insertions(+), 335 deletions(-) diff --git a/include/DataFrame/Internals/DataFrame_private_decl.h b/include/DataFrame/Internals/DataFrame_private_decl.h index caf5f65d4..ebc8b6632 100644 --- a/include/DataFrame/Internals/DataFrame_private_decl.h +++ b/include/DataFrame/Internals/DataFrame_private_decl.h @@ -242,31 +242,6 @@ column_left_right_join_( // ---------------------------------------------------------------------------- -template -static inline void -_sort_by_sorted_index_(T &to_be_sorted, - StlVecType &sorting_idxs, - size_t idx_s) { - - if (idx_s > 0) { - idx_s -= 1; - for (size_t i = 0; i < idx_s; ++i) { - // while the element i is not yet in place - // - while (sorting_idxs[i] != sorting_idxs[sorting_idxs[i]]) { - // swap it with the element at its final place - // - const size_t j = sorting_idxs[i]; - - std::swap(to_be_sorted[j], to_be_sorted[sorting_idxs[j]]); - std::swap(sorting_idxs[i], sorting_idxs[j]); - } - } - } -} - -// ---------------------------------------------------------------------------- - template inline static void _replace_vector_vals_(V &data_vec, diff --git a/include/DataFrame/Internals/DataFrame_standalone.tcc b/include/DataFrame/Internals/DataFrame_standalone.tcc index b7f3f8664..2fdfc9565 100644 --- a/include/DataFrame/Internals/DataFrame_standalone.tcc +++ b/include/DataFrame/Internals/DataFrame_standalone.tcc @@ -640,6 +640,31 @@ inline static O _remove_copy_if_(I first, I last, O d_first, PRE predicate) { // ---------------------------------------------------------------------------- +template +static inline void +_sort_by_sorted_index_(T &to_be_sorted, + V &sorting_idxs, + size_t idx_s) { + + if (idx_s > 0) { + idx_s -= 1; + for (size_t i = 0; i < idx_s; ++i) { + // while the element i is not yet in place + // + while (sorting_idxs[i] != sorting_idxs[sorting_idxs[i]]) { + // swap it with the element at its final place + // + const size_t j = sorting_idxs[i]; + + std::swap(to_be_sorted[j], to_be_sorted[sorting_idxs[j]]); + std::swap(sorting_idxs[i], sorting_idxs[j]); + } + } + } +} + +// ---------------------------------------------------------------------------- + template inline static std::string _to_string_(const T &value) { diff --git a/test/dataframe_tester_2.cc b/test/dataframe_tester_2.cc index 7f8590a76..420bc2af2 100644 --- a/test/dataframe_tester_2.cc +++ b/test/dataframe_tester_2.cc @@ -42,6 +42,9 @@ using namespace hmdf; // using MyDataFrame = StdDataFrame; +template +using StlVecType = typename MyDataFrame::template StlVecType; + // ----------------------------------------------------------------------------- static void test_get_reindexed() { @@ -50,17 +53,17 @@ static void test_get_reindexed() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -111,17 +114,17 @@ static void test_get_reindexed_view() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -206,12 +209,12 @@ static void test_retype_column() { std::cout << "\nTesting retype_column( ) ..." << std::endl; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector intvec = + StlVecType intvec = { -1, 2, 3, 4, 5, 8, -6, 7, 11, 14, -9, 12, 13, 14, 15 }; - std::vector strvec = + StlVecType strvec = { "11", "22", "33", "44", "55", "66", "-77", "88", "99", "100", "101", "102", "103", "104", "-105" }; @@ -250,12 +253,12 @@ static void test_load_align_column() { std::cout << "\nTesting load_align_column( ) ..." << std::endl; - std::vector idxvec = + StlVecType idxvec = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }; - std::vector intvec = + StlVecType intvec = { -1, 2, 3, 4, 5, 8, -6, 7, 11, 14, -9, 12, 13, 14, 15 }; - std::vector summary_vec = { 100, 200, 300, 400, 500 }; + StlVecType summary_vec = { 100, 200, 300, 400, 500 }; MyDataFrame df; @@ -266,7 +269,7 @@ static void test_load_align_column() { true, std::sqrt(-1)); - std::vector summary_vec_2 = { 102, 202, 302, 402, 502 }; + StlVecType summary_vec_2 = { 102, 202, 302, 402, 502 }; df.load_align_column("summary_col_2", std::move(summary_vec_2), @@ -297,17 +300,17 @@ static void test_get_columns_info() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -361,14 +364,14 @@ static void test_CategoryVisitor() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, sqrt(-1), 4.0, 14.0, 14.0, 20.0 }; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "zz", "ww", "ee", "ff", "gg", "zz", "ii", "jj", "kk", "ll", "mm", "ee", "" }; @@ -414,17 +417,17 @@ static void test_FactorizeVisitor() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -561,14 +564,14 @@ static void test_ClipVisitor() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, sqrt(-1), 4.0, 14.0, 14.0, 20.0 }; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "zz", "ww", "ee", "ff", "gg", "zz", "ii", "jj", "kk", "ll", "mm", "ee", "" }; @@ -598,17 +601,17 @@ static void test_SharpeRatioVisitor() { std::cout << "\nTesting SharpeRatioVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 2.5, 2.45, -0.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, -0.34, 2.3, -0.34, -1.9, 0.387, 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59 }; - std::vector d2 = + StlVecType d2 = { 0.2, 0.58, -0.60, -0.08, 0.05, 0.87, 0.2, 0.4, 0.5, 0.06, 0.3, -0.34, -0.9, 0.8, -0.4, 0.86, 0.01, 1.02, -0.02, -1.5, 0.2 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -630,17 +633,17 @@ static void test_RankVisitor() { std::cout << "\nTesting RankVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 }; - std::vector d2 = + StlVecType d2 = { 10, 2, 3, 4, 5, 13, 7, 8, 9, 10, 1, 12, 13, 10, 15, 16, 17, 18, 19, 20, 13 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -676,17 +679,17 @@ static void test_RankVisitor() { const auto last_result2 = df.single_act_visit("d2_col", last_rank_v).get_result(); - std::vector ar_equal { 8, 1, 2, 3, 4, 12, 5, 6, 7, 9, 0, 11, 13, + StlVecType ar_equal { 8, 1, 2, 3, 4, 12, 5, 6, 7, 9, 0, 11, 13, 10, 15, 16, 17, 18, 19, 20, 14 }; assert(actual_result2 == ar_equal); - ar_equal = std::vector { 9, 1, 2, 3, 4, 13, 5, 6, 7, 9, 0, 11, 13, + ar_equal = StlVecType { 9, 1, 2, 3, 4, 13, 5, 6, 7, 9, 0, 11, 13, 9, 15, 16, 17, 18, 19, 20, 13 }; assert(avg_result2 == ar_equal); - ar_equal = std::vector { 8, 1, 2, 3, 4, 12, 5, 6, 7, 8, 0, 11, 12, + ar_equal = StlVecType { 8, 1, 2, 3, 4, 12, 5, 6, 7, 8, 0, 11, 12, 8, 15, 16, 17, 18, 19, 20, 12 }; assert(first_result2 == ar_equal); - ar_equal = std::vector { 10, 1, 2, 3, 4, 14, 5, 6, 7, 10, 0, 11, 14, + ar_equal = StlVecType { 10, 1, 2, 3, 4, 14, 5, 6, 7, 10, 0, 11, 14, 10, 15, 16, 17, 18, 19, 20, 14 }; assert(last_result2 == ar_equal); } @@ -697,17 +700,17 @@ static void test_SigmoidVisitor() { std::cout << "\nTesting SigmoidVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 }; - std::vector d2 = + StlVecType d2 = { 0.23, 0.25, 0.256, 0.26, 0.268, 0.271, 0.279, 0.285, 0.29, 0.3, 0.5, -0.2, 1, 0, 2, 0, -0.1, 0.55, 0.58, 0.6, 0.7 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), @@ -737,7 +740,7 @@ static void test_SigmoidVisitor() { const auto smo_result = df.single_act_visit("d2_col", sig_smo).get_result(); - std::vector result { + StlVecType result { 0.731059, 0.880797, 0.952574, 0.982014, 0.993307, 0.997527, 0.999089, 0.999665, 0.999877, 0.999955, 0.999983, 0.999994, 0.999998, 0.999999, 1, 1, 1, 1, 1, 1, 1 }; @@ -745,7 +748,7 @@ static void test_SigmoidVisitor() { for (size_t i = 0; i < result.size(); ++i) assert(fabs(result[i] - log_result[i]) < 0.00001); - result = std::vector { + result = StlVecType { 0.707107, 0.447214, 0.316228, 0.242536, 0.196116, 0.164399, 0.141421, 0.124035, 0.110432, 0.0995037, 0.0905357, 0.0830455, 0.0766965, 0.071247, 0.066519, 0.0623783, 0.058722, 0.05547, 0.0525588, @@ -753,33 +756,33 @@ static void test_SigmoidVisitor() { for (size_t i = 0; i < result.size(); ++i) assert(fabs(result[i] - alg_result[i]) < 0.00001); - result = std::vector { + result = StlVecType { 0.761594, 0.964028, 0.995055, 0.999329, 0.999909, 0.999988, 0.999998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; for (size_t i = 0; i < result.size(); ++i) assert(fabs(result[i] - tan_result[i]) < 0.00001); - result = std::vector { + result = StlVecType { 0.785398, 1.10715, 1.24905, 1.32582, 1.3734, 1.40565, 1.4289, 1.44644, 1.46014, 1.47113, 1.48014, 1.48766, 1.49402, 1.49949, 1.50423, 1.50838, 1.51204, 1.5153, 1.51821, 1.52084, 1.52321 }; for (size_t i = 0; i < result.size(); ++i) assert(fabs(result[i] - atan_result[i]) < 0.00001); - result = std::vector { + result = StlVecType { 0.842701, 0.995322, 0.999978, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; for (size_t i = 0; i < result.size(); ++i) assert(fabs(result[i] - err_result[i]) < 0.00001); - result = std::vector { + result = StlVecType { 0.865769, 1.30176, 1.4713, 1.53417, 1.55732, 1.56584, 1.56897, 1.57013, 1.57055, 1.57071, 1.57076, 1.57078, 1.57079, 1.57079, 1.5708, 1.5708, 1.5708, 1.5708, 1.5708, 1.5708, 1.5708 }; for (size_t i = 0; i < result.size(); ++i) assert(fabs(result[i] - gud_result[i]) < 0.00001); - result = std::vector { + result = StlVecType { 0.134366, 0.15625, 0.163054, 0.167648, 0.176974, 0.180518, 0.190088, 0.197377, 0.203522, 0.216, 0.5, 0, 1, 0, 1, 0, 0, 0.57475, 0.618976, 0.648, 0.784 }; @@ -798,32 +801,32 @@ static void test_combine() { std::cout << "\nTesting combine( ) ..." << std::endl; - std::vector idx1 = + StlVecType idx1 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector idx2 = + StlVecType idx2 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector idx3 = + StlVecType idx3 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector idx4 = + StlVecType idx4 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 100, 4, 5, 6, 7, 8, 9, 10, 11, 300, 13, 14, 15, 16, 17, 18, 19, 20, 200 }; - std::vector d2 = + StlVecType d2 = { 1, 2, 1000, 4, 5, 6, 7, 8, 9, 10, 11, 3000, 13, 14, 15, 16, 17, 18, 19, 20, 2000 }; - std::vector d3 = + StlVecType d3 = { 1, 2, 5000, 4, 5, 6, 7, 8, 9, 10, 11, 7000, 13, 14, 15, 16, 17, 18, 19, 20, 8000 }; - std::vector d4 = + StlVecType d4 = { 1, 2, 10000, 4, 5, 6, 7, 8, 9, 10, 11, 20000, 13, 14, 15, 16, 17, 18, 19, 20, 30000 }; MyDataFrame df1; @@ -838,7 +841,7 @@ static void test_combine() { df1.load_column("d2_col", df1.combine("d1_col", df2, df3, my_max)); - std::vector result { + StlVecType result { 1, 2, 5000, 4, 5, 6, 7, 8, 9, 10, 11, 7000, 13, 14, 15, 16, 17, 18, 19, 20, 8000 }; @@ -885,17 +888,17 @@ static void test_remove_duplicates() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 15.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 101.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = { 1, 2, 3, 4, 2, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 2, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "bb", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -916,10 +919,10 @@ static void test_remove_duplicates() { ("dbl_col", "dbl_col_2", "int_col", "str_col", false, remove_dup_spec::keep_first); - std::vector actual_d { + StlVecType actual_d { 100, 101, 102, 103, 105, 106.55, 107.34, 1.8, 111, 112, 113, 114, 115, 116 }; - std::vector actual_s { + StlVecType actual_s { "zz", "bb", "cc", "ww", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -933,10 +936,10 @@ static void test_remove_duplicates() { ("dbl_col", "dbl_col_2", "int_col", "str_col", false, remove_dup_spec::keep_last); - actual_d = std::vector { + actual_d = StlVecType { 100, 102, 103, 101, 105, 106.55, 107.34, 1.8, 111, 112, 113, 114, 115, 116 }; - actual_s = std::vector { + actual_s = StlVecType { "zz", "cc", "ww", "bb", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; assert(result3.get_index().size() == 14); @@ -949,10 +952,10 @@ static void test_remove_duplicates() { ("dbl_col", "dbl_col_2", "int_col", "str_col", false, remove_dup_spec::keep_none); - actual_d = std::vector { + actual_d = StlVecType { 100, 102, 103, 105, 106.55, 107.34, 1.8, 111, 112, 113, 114, 115, 116 }; - actual_s = std::vector { + actual_s = StlVecType { "zz", "cc", "ww", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; assert(result4.get_index().size() == 13); @@ -965,10 +968,10 @@ static void test_remove_duplicates() { ("dbl_col", "dbl_col_2", "int_col", "str_col", true, remove_dup_spec::keep_none); - actual_d = std::vector { + actual_d = StlVecType { 100, 101, 102, 103, 101, 105, 106.55, 107.34, 1.8, 111, 112, 113, 114, 115, 116 }; - actual_s = std::vector { + actual_s = StlVecType { "zz", "bb", "cc", "ww", "bb", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; assert(result5.get_index().size() == 15); @@ -979,10 +982,10 @@ static void test_remove_duplicates() { df.remove_duplicates ("dbl_col", false, remove_dup_spec::keep_first); - actual_d = std::vector + actual_d = StlVecType { 100, 101, 102, 103, 105, 106.55, 107.34, 1.8, 111, 112, 113, 114, 115, 116 }; - actual_s = std::vector + actual_s = StlVecType { "zz", "bb", "cc", "ww", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -1051,24 +1054,24 @@ static void test_groupby() { std::cout << "\nTesting groupby( ) ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 123450, 123451, 123452, 123450, 123455, 123450, 123449, 123450, 123451, 123450, 123452, 123450, 123455, 123450, 123454, 123450, 123450, 123457, 123458, 123459, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; - std::vector xulgvec2 = ulgvec2; - std::vector intvec2 = + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; - std::vector xdblvec2 = + StlVecType xdblvec2 = { 10, 20, 11, 11, 30, 40, 50, 40, 60, 70, 80, 90, 50, 100, 11, 25, 20, 30, 1, 3, 4, 12, 6, 2, 3, 10, 4, 5 }; - std::vector dblvec22 = + StlVecType dblvec22 = { 0.998, 1.545, 0.056, 0.15678, 1.545, 0.923, 0.06743, 0.1, -1.545, 0.07865, -0.9999, 1.545, 0.1002, -0.8888, 0.14, 0.0456, -1.545, -0.8999, 0.01119, 0.8002, -1.545, 0.2, 0.1056, 0.87865, -0.6999, 1.545, 0.1902, -1.545 }; - std::vector strvec2 = + StlVecType strvec2 = { "A", "B", "C", "D", "X", "Y", "W", "P", "Z", "S", "M", "B", "A", "H", "X", "Q", "V", "P", "W", "K", "I", "L", "J", "N", "Y", "G", "T", "U" }; @@ -1133,24 +1136,24 @@ static void test_groupby_2() { std::cout << "\nTesting groupby_2( ) ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 123450, 123451, 123452, 123450, 123455, 123450, 123449, 123450, 123451, 123450, 123452, 123450, 123455, 123450, 123454, 123450, 123450, 123457, 123458, 123459, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; - std::vector xulgvec2 = ulgvec2; - std::vector intvec2 = + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; - std::vector xdblvec2 = + StlVecType xdblvec2 = { 10, 20, 11, 11, 30, 40, 50, 40, 60, 70, 80, 90, 50, 100, 11, 25, 20, 30, 1, 3, 4, 12, 6, 2, 3, 10, 4, 5 }; - std::vector dblvec22 = + StlVecType dblvec22 = { 0.998, 1.545, 0.056, 0.15678, 1.545, 0.923, 0.06743, 0.1, -1.545, 0.07865, -0.9999, 1.545, 0.1002, -0.8888, 0.14, 0.0456, -1.545, -0.8999, 0.01119, 0.8002, -1.545, 0.2, 0.1056, 0.87865, -0.6999, 1.545, 0.1902, -1.545 }; - std::vector strvec2 = + StlVecType strvec2 = { "A", "B", "C", "D", "X", "Y", "W", "P", "Z", "S", "M", "B", "A", "H", "X", "Q", "V", "P", "W", "K", "I", "L", "J", "N", "Y", "G", "T", "U" }; @@ -1248,22 +1251,22 @@ static void test_groupby_3() { std::cout << "\nTesting groupby_3( ) ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 1, 2, 2, 2, 3, 4, 5, 5, 6, 6, 6, 7, 8, 9, 10, 10, 10, 11, 11, 11, 12, 13, 13, 14, 15, 16, 17, 17 }; - std::vector xulgvec2 = ulgvec2; - std::vector intvec2 = + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; - std::vector xdblvec2 = + StlVecType xdblvec2 = { 10, 20, 20, 11, 30, 40, 50, 50, 50, 50, 80, 90, 50, 11, 11, 25, 20, 30, 1, 2, 2, 2, 6, 2, 3, 10, 4, 5 }; - std::vector dblvec22 = + StlVecType dblvec22 = { 0.998, 1.545, 0.056, 0.15678, 1.545, 0.923, 0.06743, 0.1, -1.545, 0.07865, -0.9999, 1.545, 0.1002, -0.8888, 0.14, 0.0456, -1.545, -0.8999, 0.01119, 0.8002, -1.545, 0.2, 0.1056, 0.87865, -0.6999, 1.545, 0.1902, -1.545 }; - std::vector strvec2 = + StlVecType strvec2 = { "A", "A", "A", "B", "C", "C", "C", "C", "Z", "S", "M", "B", "A", "H", "X", "B", "Y", "Y", "W", "K", "K", "K", "J", "N", "Y", "G", "K", "B" }; @@ -1301,26 +1304,26 @@ static void test_io_format_csv2() { std::cout << "\nTesting io_format_csv2( ) ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 123450, 123451, 123452, 123450, 123455, 123450, 123449, 123450, 123451, 123450, 123452, 123450, 123455, 123450, 123454, 123450, 123450, 123457, 123458, 123459, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; - std::vector xulgvec2 = ulgvec2; - std::vector intvec2 = + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; - std::vector xdblvec2 = + StlVecType xdblvec2 = { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, 10.0, 4.25, 0.009, 8.0, 2.2222, 3.3333, 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, 12.0, 6.25, 2.009, 3.111, 10.0, 4.2222, 5.3333 }; - std::vector dblvec22 = + StlVecType dblvec22 = { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, 0.1, 0.0056, 0.07865, 0.0111, 0.1002, -0.8888, 0.14, 0.0456, 0.078654, -0.8999, 0.8002, -0.9888, 0.2, 0.1056, 0.87865, -0.6999, 0.4111, 0.1902, -0.4888 }; - std::vector strvec2 = + StlVecType strvec2 = { "4% of something", "Description 4/5", "This is bad", "3.4% of GDP", "Market drops", "Market pulls back", "$15 increase", "Running fast", "C++14 development", @@ -1328,7 +1331,7 @@ static void test_io_format_csv2() { "Almost done", "XXXX04", "XXXX2", "XXXX3", "XXXX4", "XXXX4", "XXXX5", "XXXX6", "XXXX7", "XXXX10", "XXXX11", "XXXX02", "XXXX03" }; - std::vector boolvec = + StlVecType boolvec = { true, true, true, false, false, true }; MyDataFrame df; @@ -1430,12 +1433,12 @@ static void test_NormalizeVisitor() { std::cout << "\nTesting NormalizeVisitor{ } ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 123450, 123451, 123452, 123450, 123455, 123450, 123449, 123450, 123451, 123450, 123452, 123450, 123455, 123450, 123454, 123450, 123450, 123457, 123458, 123459, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; - std::vector dblvec = + StlVecType dblvec = { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, 10.0, 4.25, 0.009, 8.0, 2.2222, 3.3333, 15.6, 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, @@ -1449,13 +1452,13 @@ static void test_NormalizeVisitor() { StandardizeVisitor stand_v; auto result = df.single_act_visit("dbl_col", norm_v).get_result(); - std::vector norm_result = { + StlVecType norm_result = { 0.078603, 0.142743, 0.206882, 0.271022, 0.335161, 0.191841, 0.0635559, 0.640818, 0.272016, 0, 0.512539, 0.141954, 0.213219, 1, 0.704958, 0.336155, 0.0641396, 0.134821, 0.576679, 0.206093, 0.277359, 0.769098, 0.400295, 0.128279, 0.198961, 0.640818, 0.270233, 0.341498, }; - std::vector stand_result = { + StlVecType stand_result = { -1.00542, -0.744444, -0.48347, -0.222497, 0.0384758, -0.544669, -1.06664, 1.28214, -0.218452, -1.32524, 0.760197, -0.747654, -0.457686, 2.74359, 1.54312, 0.0425209, -1.06427, -0.776674, 1.02117, -0.48668, @@ -1476,14 +1479,14 @@ static void test_HampelFilterVisitor() { std::cout << "\nTesting HampelFilterVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, 123467, 123468, 123469, 123470, 123471, 123472, 123473, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector d1 = + StlVecType d1 = { 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, -12.34, 2.3, -0.34, -1.9, 0.387, 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59, @@ -1497,7 +1500,7 @@ static void test_HampelFilterVisitor() { HampelFilterVisitor hf_v(7, hampel_type::mean, 2); auto result = df.single_act_visit("dbl_col", hf_v).get_result(); - std::vector hampel_result = { + StlVecType hampel_result = { 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, std::numeric_limits::quiet_NaN(), 2.3, -0.34, -1.9, 0.387, 0.123, 1.06, -0.65, 2.03, 0.4, -1, 0.59, 0.125, 1.9, -0.68, 2.0045, @@ -1523,7 +1526,7 @@ static void test_PolyFitVisitor() { std::cout << "\nTesting PolyFitVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, @@ -1558,11 +1561,11 @@ static void test_PolyFitVisitor() { df.single_act_visit("X1", "Y1", poly_v1).get_result(); auto result12 = df.single_act_visit("X1", "Y1", poly_v12).get_result(); - auto actual1 = std::vector { 0.8, 5.6, -1 }; + auto actual1 = StlVecType { 0.8, 5.6, -1 }; auto actual1_y = - std::vector { 5.4, 8, 8.6, 7.2, 3.8 }; + StlVecType { 5.4, 8, 8.6, 7.2, 3.8 }; auto actual12 = - std::vector { -1.97994, 6.99713, -1.14327 }; + StlVecType { -1.97994, 6.99713, -1.14327 }; assert(std::fabs(poly_v1.get_residual() - 5.6) < 0.00001); for (size_t i = 0; i < result1.size(); ++i) @@ -1578,7 +1581,7 @@ static void test_PolyFitVisitor() { auto result2 = df.single_act_visit("X2", "Y2", poly_v2).get_result(); auto actual2 = - std::vector { -0.0396825, 1.69312, -0.813492, 0.087037 }; + StlVecType { -0.0396825, 1.69312, -0.813492, 0.087037 }; for (size_t i = 0; i < result2.size(); ++i) assert(fabs(result2[i] - actual2[i]) < 0.00001); @@ -1596,10 +1599,10 @@ static void test_HurstExponentVisitor() { p.min_value = 0; p.max_value = 30; - std::vector d1 = gen_uniform_real_dist(1024, p); - std::vector d2 = + StlVecType d1 = gen_uniform_real_dist(1024, p); + StlVecType d2 = { 0.04, 0.02, 0.05, 0.08, 0.02, -0.17, 0.05, 0.0 }; - std::vector d3 = + StlVecType d3 = { 0.04, 0.05, 0.055, 0.06, 0.061, 0.072, 0.073, 0.8 }; MyDataFrame df; @@ -1634,7 +1637,7 @@ static void test_LogFitVisitor() { std::cout << "\nTesting LogFitVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, @@ -1661,9 +1664,9 @@ static void test_LogFitVisitor() { auto result1 = df.single_act_visit("X1", "Y1", log_v1).get_result(); auto actual1 = - std::vector { 6.98618, -0.403317 }; + StlVecType { 6.98618, -0.403317 }; auto actual1_y = - std::vector { 6.98618, 6.70662, 6.54309, 6.42706, 6.33706 }; + StlVecType { 6.98618, 6.70662, 6.54309, 6.42706, 6.33706 }; assert(std::fabs(log_v1.get_residual() - 20.9372) < 0.0001); for (size_t i = 0; i < result1.size(); ++i) @@ -1674,7 +1677,7 @@ static void test_LogFitVisitor() { LogFitVisitor log_v2; auto result2 = df.single_act_visit("X2", "Y2", log_v2).get_result(); - auto actual2 = std::vector { 1.11199, 2.25859 }; + auto actual2 = StlVecType { 1.11199, 2.25859 }; assert(std::fabs(log_v2.get_residual() - 0.237476) < 0.00001); for (size_t i = 0; i < result2.size(); ++i) @@ -1687,7 +1690,7 @@ static void test_ExponentialFitVisitor() { std::cout << "\nTesting ExponentialFitVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, @@ -1714,7 +1717,7 @@ static void test_ExponentialFitVisitor() { auto result1 = df.single_act_visit("X1", "Y1", exp_v1).get_result(); auto actual1 = - std::vector { 7.7647, 6.9316, 6.1879, 5.5239, 4.93126 }; + StlVecType { 7.7647, 6.9316, 6.1879, 5.5239, 4.93126 }; assert(std::fabs(exp_v1.get_residual() - 22.2154) < 0.0001); for (size_t i = 0; i < result1.size(); ++i) @@ -1724,7 +1727,7 @@ static void test_ExponentialFitVisitor() { auto result2 = df.single_act_visit("X2", "Y2", exp_v2).get_result(); auto actual2 = - std::vector { 1.63751, 2.02776, 3.10952, 4.76833, 7.31206 }; + StlVecType { 1.63751, 2.02776, 3.10952, 4.76833, 7.31206 }; assert(std::fabs(exp_v2.get_residual() - 3.919765) < 0.00001); for (size_t i = 0; i < result2.size(); ++i) @@ -1737,7 +1740,7 @@ static void test_LinearFitVisitor() { std::cout << "\nTesting LinearFitVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, @@ -1764,7 +1767,7 @@ static void test_LinearFitVisitor() { auto result1 = df.single_act_visit("X1", "Y1", lin_v1).get_result(); auto actual1 = - std::vector { 7.4, 7, 6.6, 6.2, 5.8 }; + StlVecType { 7.4, 7, 6.6, 6.2, 5.8 }; assert(std::fabs(lin_v1.get_residual() - 19.6) < 0.01); for (size_t i = 0; i < result1.size(); ++i) @@ -1774,7 +1777,7 @@ static void test_LinearFitVisitor() { auto result2 = df.single_act_visit("X2", "Y2", lin_v2).get_result(); auto actual2 = - std::vector { 1.73171, 2.37805, 3.67073, 4.96341, 6.2561 }; + StlVecType { 1.73171, 2.37805, 3.67073, 4.96341, 6.2561 }; assert(std::fabs(lin_v2.get_residual() - 1.097561) < 0.00001); for (size_t i = 0; i < result2.size(); ++i) @@ -1787,21 +1790,21 @@ static void test_ExpoSmootherVisitor() { std::cout << "\nTesting ExpoSmootherVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, 123467, 123468, 123469, 123470, 123471, 123472, 123473, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector d1 = + StlVecType d1 = { 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, -12.34, 2.3, -0.34, -1.9, 0.387, 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59, 0.125, 1.9, -0.68, 2.0045, 50.8, -1.0, 0.78, 0.48, 1.99, -0.97, 1.03, 8.678, -1.4, 1.59, }; - std::vector d1_copy = d1; + StlVecType d1_copy = d1; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("dbl_col", d1)); @@ -1821,7 +1824,7 @@ static void test_ExpoSmootherVisitor() { df.single_act_visit("dbl_col", es_v2); - auto actual2 = std::vector { + auto actual2 = StlVecType { 2.5, 2.485, 1.22, -1.185, -0.4, -0.209, 1.603, 0.788, 0.706, -2.61, -7.948, 1.508, -0.808, -1.2139, 0.3078, 0.4041, 0.547, 0.154, 1.541, -0.02, -0.523, @@ -1838,7 +1841,7 @@ static void test_ExpoSmootherVisitor() { df.single_act_visit("dbl_col", es_v3); - auto actual3 = std::vector { + auto actual3 = StlVecType { 2.5, 2.46, -0.83, -0.41, -0.9, 1.276, 1.158, 0.468, 1.316, -9.56, -0.628, 0.188, -1.588, -0.0704, 0.1758, 0.8726, -0.308, 1.494, 0.726, -0.72, 0.272, @@ -1854,7 +1857,7 @@ static void test_ExpoSmootherVisitor() { df2.single_act_visit("dbl_col", es_v3_4); - auto actual4 = std::vector { + auto actual4 = StlVecType { 2.5, 2.47952, 0.77968, -0.27248, -0.67824, 0.261712, 0.9932, 0.799584, 0.97488, -4.33518, -3.8625, -1.05213, -0.877632, -0.632813, -0.087968, 0.494816, 0.193696, 0.731832, 0.922821, 0.051104, -0.055568, 0.152752, @@ -1872,21 +1875,21 @@ static void test_HWExpoSmootherVisitor() { std::cout << "\nTesting HWExpoSmootherVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, 123467, 123468, 123469, 123470, 123471, 123472, 123473, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector d1 = + StlVecType d1 = { 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, -12.34, 2.3, -0.34, -1.9, 0.387, 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59, 0.125, 1.9, -0.68, 2.0045, 50.8, -1.0, 0.78, 0.48, 1.99, -0.97, 1.03, 8.678, -1.4, 1.59, }; - std::vector d1_copy = d1; + StlVecType d1_copy = d1; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("dbl_col", d1)); @@ -1904,7 +1907,7 @@ static void test_HWExpoSmootherVisitor() { df.single_act_visit("dbl_col", es_v2); - auto actual2 = std::vector { + auto actual2 = StlVecType { 2.5, 2.45, 1.185, -2.354, -0.6674, -0.64944, 2.17034, 0.879202, 0.581521, -2.34309, -11.6799, 3.36809, -0.431147, -1.42459, 0.821747, 0.638548, 0.950029, -0.0829826, 2.14921, -0.111474, -0.969884, @@ -1921,7 +1924,7 @@ static void test_HWExpoSmootherVisitor() { df.single_act_visit("dbl_col", es_v3); - auto actual3 = std::vector { + auto actual3 = StlVecType { 2.5, 2.45, -0.84, -1.068, -0.7836, 1.13928, 1.60586, 0.415171, 1.20303, -9.38739, -2.81748, 2.0925, -1.6295, -0.3283, 0.49014, 0.893228, -0.153954, 1.25121, 1.10624, -0.904752, 0.0110497, @@ -1935,21 +1938,21 @@ static void test_HWExpoSmootherVisitor() { // ----------------------------------------------------------------------------- -static std::vector +static StlVecType add_columns(MyDataFrame::IndexVecType::const_iterator /*idx_begin*/, MyDataFrame::IndexVecType::const_iterator /*idx_end*/, - std::vector::const_iterator b_citer1, - std::vector::const_iterator e_citer1, - std::vector::const_iterator b_citer2, - std::vector::const_iterator e_citer2, - std::vector::const_iterator b_citer3, - std::vector::const_iterator e_citer3) { + StlVecType::const_iterator b_citer1, + StlVecType::const_iterator e_citer1, + StlVecType::const_iterator b_citer2, + StlVecType::const_iterator e_citer2, + StlVecType::const_iterator b_citer3, + StlVecType::const_iterator e_citer3) { const std::size_t col_s = std::min ({ std::distance(b_citer1, e_citer1), std::distance(b_citer2, e_citer2), std::distance(b_citer3, e_citer3) }); - std::vector result (col_s); + StlVecType result (col_s); for (std::size_t i = 0; i < col_s; ++i) result[i] = @@ -1965,20 +1968,20 @@ static void test_consolidate() { MyDataFrame df; - std::vector idxvec = { + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = { + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = { + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = { + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -1999,7 +2002,7 @@ static void test_consolidate() { const auto &new_str_col = df.get_column("new_str_col"); - const std::vector actual = { + const StlVecType actual = { "zz100.000000", "bb116.000000", "cc116.000000", "ww105.000000", "ee105.000000", "ff117.000000", "gg117.550000", "hh115.340000", "ii8.800000", "jj117.000000", "kk117.000000", "ll117.000000", @@ -2016,7 +2019,7 @@ static void test_ExtremumSubArrayVisitor() { std::cout << "\nTesting ExtremumSubArrayVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, @@ -2052,7 +2055,7 @@ static void test_NExtremumSubArrayVisitor() { std::cout << "\nTesting NExtremumSubArrayVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, @@ -2126,18 +2129,18 @@ static void test_LowessVisitor() { std::cout << "\nTesting LowessVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector x_vec = { + StlVecType x_vec = { 0.5578196, 2.0217271, 2.5773252, 3.4140288, 4.3014084, 4.7448394, 5.1073781, 6.5411662, 6.7216176, 7.2600583, 8.1335874, 9.1224379, 1.9296663, 2.3797674, 3.2728619, 4.2767453, 5.3731026, 5.6476637, 8.5605355, 8.5866354, 8.7572812, }; - std::vector y_vec = { + StlVecType y_vec = { 18.63654, 103.49646, 150.35391, 190.51031, 208.70115, 213.71135, 228.49353, 233.55387, 234.55054, 223.89225, 227.68339, 223.91982, 168.01999, 164.95750, 152.61107, 160.78742, 168.55567, 152.42658, @@ -2153,7 +2156,7 @@ static void test_LowessVisitor() { df.single_act_visit("dep_var", "indep_var", l_v); - auto actual_yfit = std::vector { + auto actual_yfit = StlVecType { 68.1432, 119.432, 122.75, 135.633, 142.724, 165.905, 169.447, 185.617, 186.017, 191.865, 198.03, 202.234, 206.178, 215.053, 216.586, 220.408, 226.671, 229.052, 229.185, 230.023, 231.657, @@ -2162,7 +2165,7 @@ static void test_LowessVisitor() { for (size_t idx = 0; idx < actual_yfit.size(); ++idx) assert(fabs(l_v.get_result()[idx] - actual_yfit[idx]) < 0.001); - auto actual_weights = std::vector { + auto actual_weights = StlVecType { 0.641773, 0.653544, 0.940738, 0.865302, 0.990575, 0.971522, 0.92929, 0.902444, 0.918228, 0.924041, 0.855054, 0.824388, 0.586045, 0.945216, 0.94831, 0.998031, 0.999834, 0.991263, 0.993165, 0.972067, 0.990308, @@ -2179,12 +2182,12 @@ static void test_StepRollAdopter() { std::cout << "\nTesting StepRollAdopter{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123463, 123464, 123458, 123459, 123460, 123461, 123462 }; - std::vector d1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 }; MyDataFrame df; @@ -2210,7 +2213,7 @@ static void test_DecomposeVisitor() { std::cout << "\nTesting DecomposeVisitor{ } ..." << std::endl; - std::vector y_vec = + StlVecType y_vec = { 131.157, 131.367, 132.215, 132.725, 132.648, 130.585, 130.701, 129.631, 129.168, 129.554, 129.467, 129.670, 128.397, 129.014, 129.496, 131.067, 130.219, 128.947, 129.602, 128.118, 127.356, @@ -2234,7 +2237,7 @@ static void test_DecomposeVisitor() { df.single_act_visit("IBM_closes", d_v); - auto actual_trends = std::vector + auto actual_trends = StlVecType { 130.613, 130.55, 130.489, 130.43, 130.372, 130.317, 130.263, 130.211, 130.161, 130.111, 130.064, 130.017, 129.972, 129.928, 129.885, 129.842, 129.801, 129.76, 129.72, 129.681, 129.642, 129.603, 129.564, @@ -2253,7 +2256,7 @@ static void test_DecomposeVisitor() { for (size_t idx = 0; idx < actual_trends.size(); ++idx) assert(fabs(d_v.get_trend()[idx] - actual_trends[idx]) < 0.001); - auto actual_seasonals = std::vector + auto actual_seasonals = StlVecType { 0.499135, -0.362488, -0.0226401, -0.138991, -0.774313, -0.152695, 0.951993, 0.499135, -0.362488, -0.0226401, -0.138991, -0.774313, -0.152695, 0.951993, 0.499135, -0.362488, -0.0226401, -0.138991, @@ -2274,7 +2277,7 @@ static void test_DecomposeVisitor() { for (size_t idx = 0; idx < actual_seasonals.size(); ++idx) assert(fabs(d_v.get_seasonal()[idx] - actual_seasonals[idx]) < 0.00001); - auto actual_residuals = std::vector + auto actual_residuals = StlVecType { 0.0450645, 1.17948, 1.74866, 2.43421, 3.04989, 0.420796, -0.514129, -1.07918, -0.630027, -0.534809, -0.457752, 0.427013, -1.42233, -1.86582, -0.887751, 1.58716, 0.440736, -0.674248, 0.656095, @@ -2326,24 +2329,24 @@ static void test_TTestVisitor() { std::cout << "\nTesting TTestVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector x_vec = { + StlVecType x_vec = { 0.5578196, 2.0217271, 2.5773252, 3.4140288, 4.3014084, 4.7448394, 5.1073781, 6.5411662, 6.7216176, 7.2600583, 8.1335874, 9.1224379, 1.9296663, 2.3797674, 3.2728619, 4.2767453, 5.3731026, 5.6476637, 8.5605355, 8.5866354, 8.7572812, }; - std::vector y_vec = { + StlVecType y_vec = { 18.63654, 103.49646, 150.35391, 190.51031, 208.70115, 213.71135, 228.49353, 233.55387, 234.55054, 223.89225, 227.68339, 223.91982, 168.01999, 164.95750, 152.61107, 160.78742, 168.55567, 152.42658, 221.70702, 222.69040, 243.18828, }; - std::vector z_vec = { + StlVecType z_vec = { 0.5578296, 2.0217275, 2.5773252, 3.4140288, 4.3084084, 4.7448394, 5.1079781, 6.5411662, 6.1216176, 7.1600583, 8.1335174, 9.1223379, 1.9296663, 2.3727674, 3.2728619, 4.2767953, 5.3731056, 5.6426637, @@ -2383,17 +2386,17 @@ static void test_MassIndexVisitor() { std::cout << "\nTesting MassIndexVisitor{ } ..." << std::endl; - std::vector idx = { + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector high = { + StlVecType high = { 121.75, 122.75, 124.83, 124.39, 135.5, 132, 128.25, 127.15, 126.94, 125.22, 126.43, 127.35, 120.15, 117.69, 116.06, 116.62, 114.9, 112.22, 109.73, 109.64, 111.8, }; - std::vector low = { + StlVecType low = { 118.82, 121.05, 121.59, 122.32, 129.77, 127.6, 126.44, 124.46, 125.13, 123.85, 124.66, 125.08, 116.84, 117.69, 112.98, 115.53, 111.84, 110.03, 105.92, 106.55, 107.75, @@ -2426,14 +2429,14 @@ static void test_HullRollingMeanVisitor() { std::cout << "\nTesting HullRollingMeanVisitor{ } ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 123450, 123451, 123452, 123450, 123455, 123450, 123449, 123450, 123451, 123450, 123452, 123450, 123455, 123450, 123454, 123450, 123450, 123457, 123458, 123459, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; - std::vector dbl_vec = + StlVecType dbl_vec = { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2, 2, 3, 5, 6, 7, 7, 8, 1, 10, 11, 9, 8, 7, 6 }; @@ -2465,17 +2468,17 @@ static void test_RollingMidValueVisitor() { std::cout << "\nTesting RollingMidValueVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector high = { + StlVecType high = { 121, 122, 124, 124.5, 135.5, 132, 128, 127, 126, 125, 126.5, 127, 120, 117, 116, 116.5, 114, 112, 109, 109.5, 111, }; - std::vector low = { + StlVecType low = { 118, 121, 121.5, 122, 129, 127, 126, 124, 125, 123, 124, 125, 116, 114, 112, 115, 111, 110, 105, 106, 107, @@ -2507,12 +2510,12 @@ static void test_DrawdownVisitor() { std::cout << "\nTesting DrawdownVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, }; - std::vector close = { + StlVecType close = { 121, 122, 124, 124.5, 135.5, 132, 128, 127, 126, 125, 126.5, 127, 120, 135.6, 116, 116.5, 114, 112, 109, 136, 111, @@ -2658,12 +2661,12 @@ static void test_EntropyVisitor() { std::cout << "\nTesting EntropyVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, 22, 23, 24, 25, 26, 27, 28 }; - std::vector close = + StlVecType close = { 1.80, 2.80, 1.90, 14.00, 1.10, 6.00, 13.00, 8.00, 9.00, 2.80, 1.90, 4.30, 20.00, 1.85, 3.00, 34.00, 67.00, 23.00, 87.00, 9.00, 45.00, 1.00, 11.00, 456.00, 34.00, 7.00, 7778.00, 5.00 @@ -2755,26 +2758,26 @@ static void test_no_index_writes() { std::cout << "\nTesting no_index_writes ..." << std::endl; - std::vector ulgvec2 = + StlVecType ulgvec2 = { 123450, 123451, 123452, 123450, 123455, 123450, 123449, 123450, 123451, 123450, 123452, 123450, 123455, 123450, 123454, 123450, 123450, 123457, 123458, 123459, 123450, 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; - std::vector xulgvec2 = ulgvec2; - std::vector intvec2 = + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; - std::vector xdblvec2 = + StlVecType xdblvec2 = { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, 10.0, 4.25, 0.009, 8.0, 2.2222, 3.3333, 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, 12.0, 6.25, 2.009, 3.111, 10.0, 4.2222, 5.3333 }; - std::vector dblvec22 = + StlVecType dblvec22 = { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, 0.1, 0.0056, 0.07865, 0.0111, 0.1002, -0.8888, 0.14, 0.0456, 0.078654, -0.8999, 0.8002, -0.9888, 0.2, 0.1056, 0.87865, -0.6999, 0.4111, 0.1902, -0.4888 }; - std::vector strvec2 = + StlVecType strvec2 = { "4% of something", "Description 4/5", "This is bad", "3.4% of GDP", "Market drops", "Market pulls back", "$15 increase", "Running fast", "C++14 development", @@ -2782,7 +2785,7 @@ static void test_no_index_writes() { "Almost done", "XXXX04", "XXXX2", "XXXX3", "XXXX4", "XXXX4", "XXXX5", "XXXX6", "XXXX7", "XXXX10", "XXXX11", "XXXX02", "XXXX03" }; - std::vector boolvec = + StlVecType boolvec = { true, true, true, false, false, true }; MyDataFrame df; @@ -3062,10 +3065,10 @@ static void test_shifting_column() { std::cout << "\nTesting shifting columns ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = + StlVecType d1 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }; MyDataFrame df; @@ -3387,15 +3390,15 @@ static void test_AbsVisitor() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, -15.0, 14.0, 15.0, -1.0, 12.0, 11.0, -8.0, 15.0, 6.0, -1, 4.0, 14.0, 14.0, -20.0 }; - std::vector intvec = + StlVecType intvec = { -1, 2, 3, 4, 5, 8, -6, 7, 11, -14, 9, -3, -5, -4, 9 }; - std::vector strvec = + StlVecType strvec = { "zz", "bb", "zz", "ww", "ee", "ff", "gg", "zz", "ii", "jj", "kk", "ll", "mm", "ee", "" }; @@ -3414,10 +3417,10 @@ static void test_AbsVisitor() { assert(result == 5); assert(result_int == 6); - std::vector abs_dblvec = + StlVecType abs_dblvec = { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, 1, 4.0, 14.0, 14.0, 20.0 }; - std::vector abs_intvec = + StlVecType abs_intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 3, 5, 4, 9 }; assert((df.get_column("dbl_col") == abs_dblvec)); @@ -3668,12 +3671,12 @@ static void test_FastFourierTransVisitor() { using cx = std::complex; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL }; - std::vector dblvec = { 1, 1, 1, 1, 0, 0, 0, 0 }; - std::vector strvec = + StlVecType dblvec = { 1, 1, 1, 1, 0, 0, 0, 0 }; + StlVecType strvec = { "11", "22", "33", "44", "55", "66", "-77", "88" }; - std::vector cplxvec = + StlVecType cplxvec = { cx(0, 0), cx(1, 1), cx(3, 3), cx(4, 4), cx(4, 4), cx(3, 3), cx(1, 1) }; @@ -4142,13 +4145,13 @@ static void test_get_view_by_loc() { std::cout << "\nTesting get_view_by_loc() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; - std::vector s1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "xx", "yy", "gg", "string" }; MyDataFrame df; @@ -4163,9 +4166,8 @@ static void test_get_view_by_loc() { std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl; - typedef StdDataFrame::View MyDataFrameView; - typedef StdDataFrame::ConstView MyDataFrameConstView; - + typedef MyDataFrame::View MyDataFrameView; + typedef MyDataFrame::ConstView MyDataFrameConstView; const MyDataFrame &const_df = df; MyDataFrameView dfv = @@ -4199,15 +4201,15 @@ static void test_get_view_by_idx_slicing() { std::cout << "\nTesting get_view_by_idx()/slicing ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; - std::vector i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; MyDataFrame df; df.load_data(std::move(idx), @@ -4216,8 +4218,8 @@ static void test_get_view_by_idx_slicing() { std::make_pair("col_3", d3), std::make_pair("col_4", i1)); - typedef StdDataFrame::View MyDataFrameView; - typedef StdDataFrame::ConstView MyDataFrameConstView; + typedef MyDataFrame::View MyDataFrameView; + typedef MyDataFrame::ConstView MyDataFrameConstView; const MyDataFrame &const_df = df; @@ -4252,15 +4254,15 @@ static void test_get_data() { std::cout << "\nTesting get_[data|view]() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; - std::vector i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; MyDataFrame df; df.load_data(std::move(idx), @@ -4277,8 +4279,8 @@ static void test_get_data() { assert((df2.get_column("col_4")[8] == 2)); assert((df2.get_index()[3] == 123453)); - typedef StdDataFrame::View MyDataFrameView; - typedef StdDataFrame::ConstView MyDataFrameConstView; + typedef MyDataFrame::View MyDataFrameView; + typedef MyDataFrame::ConstView MyDataFrameConstView; const MyDataFrame &const_df = df; MyDataFrameView df3 = @@ -4314,13 +4316,13 @@ static void test_get_data_by_sel() { std::cout << "\nTesting get_data_by_sel() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; - std::vector s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; MyDataFrame df; df.load_data(std::move(idx), @@ -4385,7 +4387,7 @@ static void test_get_data_by_sel() { assert(result2.get_column("col_1")[1] == 3); assert(result2.get_column("col_1")[2] == 5); - std::vector s2 = { "aa", "bb", "cc", "10", "11", "12", "14" }; + StlVecType s2 = { "aa", "bb", "cc", "10", "11", "12", "14" }; df.load_column("col_str2", s2); @@ -4453,13 +4455,13 @@ static void test_get_view_by_sel() { std::cout << "\nTesting get_view_by_sel() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; - std::vector s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; MyDataFrame df; df.load_data(std::move(idx), @@ -4599,14 +4601,14 @@ static void test_get_view_by_rand() { std::cout << "\nTesting get_view_by_rand() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; - std::vector d4 = { 22, 23, 24, 25, 26, 27 }; - std::vector s1 = + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; MyDataFrame df; @@ -4655,12 +4657,12 @@ static void test_get_view_by_loc_location() { std::cout << "\nTesting get_view_by_loc(locations) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; MyDataFrame df; df.load_data(std::move(idx), @@ -4671,12 +4673,12 @@ static void test_get_view_by_loc_location() { const MyDataFrame &const_df = df; - auto dfv1 = df.get_view_by_loc(std::vector { 3, 6 }); - auto dfv2 = df.get_view_by_loc(std::vector { -4, -1 , 5 }); + auto dfv1 = df.get_view_by_loc(StlVecType { 3, 6 }); + auto dfv2 = df.get_view_by_loc(StlVecType { -4, -1 , 5 }); auto const_dfv1 = - const_df.get_view_by_loc(std::vector { 3, 6 }); + const_df.get_view_by_loc(StlVecType { 3, 6 }); auto const_dfv2 = - const_df.get_view_by_loc(std::vector { -4, -1 , 5 }); + const_df.get_view_by_loc(StlVecType { -4, -1 , 5 }); assert(dfv1.get_index().size() == 2); assert(dfv1.get_column("col_3").size() == 2); @@ -4738,12 +4740,12 @@ static void test_get_view_by_idx_values() { std::cout << "\nTesting get_view_by_idx(values) ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21 }; - std::vector d4 = { 22, 23, 24, 25 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; MyDataFrame df; df.load_data(std::move(idx), @@ -4756,16 +4758,16 @@ static void test_get_view_by_idx_values() { auto dfv1 = df.get_view_by_idx( - std::vector { 123452, 123455 }); + StlVecType { 123452, 123455 }); auto const_dfv1 = const_df.get_view_by_idx( - std::vector { 123452, 123455 }); + StlVecType { 123452, 123455 }); auto dfv2 = df.get_view_by_idx( - std::vector { 123449, 123450 }); + StlVecType { 123449, 123450 }); auto const_dfv2 = const_df.get_view_by_idx( - std::vector { 123449, 123450 }); + StlVecType { 123449, 123450 }); assert(dfv1.get_index().size() == 2); assert(dfv1.get_column("col_3").size() == 2); diff --git a/test/dataframe_tester_3.cc b/test/dataframe_tester_3.cc index e59f7b4c0..ea03e2ac6 100644 --- a/test/dataframe_tester_3.cc +++ b/test/dataframe_tester_3.cc @@ -41,6 +41,9 @@ using namespace hmdf; // using MyDataFrame = StdDataFrame; +template +using StlVecType = typename MyDataFrame::template StlVecType; + // ----------------------------------------------------------------------------- static void test_groupby_edge() { @@ -48,17 +51,17 @@ static void test_groupby_edge() { std::cout << "\nTesting groupby( ) ..." << std::endl; MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, -14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0}; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0}; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; dblvec2.resize(1); @@ -99,18 +102,18 @@ static void test_concat_view() { MyDataFrame df1; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; - std::vector strvec = + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -229,17 +232,17 @@ static void test_multithreading(int j) { std::cout << "\nTesting test ..." << std::endl; MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, -14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0}; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0}; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -282,16 +285,16 @@ static void test_to_from_string() { std::cout << "\nTesting to_from_string() ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; - std::vector d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - std::vector d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; - std::vector d3 = { 15, 16, 17, 18, 19, 20, 21, + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; - std::vector i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; - std::vector strvec = + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn" }; MyDataFrame df; @@ -713,18 +716,18 @@ static void test_col_name_to_idx() { MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; - std::vector intvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; - std::vector strvec = + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; @@ -852,17 +855,17 @@ static void test_append_row() { std::cout << "\nTesting append_row( ) ..." << std::endl; MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, -14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0}; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0}; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; df.load_data(std::move(idxvec), @@ -937,17 +940,17 @@ static void test_load_indicators() { std::cout << "\nTesting load_indicators( ) ..." << std::endl; MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 0.0, 1.0, 14.0, 11.5, 11.5, 7.25, 7.25, 7.25, 14.0, 7.25, 15.0, 0.0}; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0}; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "blue", "blue", "red", "green", "black", "green", "white", "black", "black", "white", "red", "yellow", "green", "green", "green" }; df.load_data(std::move(idxvec), @@ -984,17 +987,17 @@ static void test_from_indicators() { std::cout << "\nTesting from_indicators( ) ..." << std::endl; MyDataFrame df; - std::vector idxvec = + StlVecType idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; - std::vector dblvec = + StlVecType dblvec = { 0.0, 15.0, 14.0, 0.0, 1.0, 14.0, 11.5, 11.5, 7.25, 7.25, 7.25, 14.0, 7.25, 15.0, 0.0}; - std::vector dblvec2 = + StlVecType dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0}; - std::vector intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; - std::vector strvec = + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { "blue", "blue", "red", "green", "black", "green", "white", "black", "black", "white", "red", "yellow", "green", "green", "green" }; df.load_data(std::move(idxvec), @@ -1034,17 +1037,17 @@ static void test_TreynorRatioVisitor() { std::cout << "\nTesting TreynorRatioVisitor{ } ..." << std::endl; - std::vector idx = + StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; - std::vector d1 = + StlVecType d1 = { 2.5, 2.45, -0.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, -0.34, 2.3, -0.34, -1.9, 0.387, 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59 }; - std::vector d2 = + StlVecType d2 = { 0.2, 0.58, -0.60, -0.08, 0.05, 0.87, 0.2, 0.4, 0.5, 0.06, 0.3, -0.34, -0.9, 0.8, -0.4, 0.86, 0.01, 1.02, -0.02, -1.5, 0.2 }; - std::vector i1 = { 22, 23, 24, 25, 99 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), From 09d06761c533d76e777ea8ccb32268a87323625f Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sat, 24 Dec 2022 12:33:04 -0500 Subject: [PATCH 12/25] Added align parameter to visitors. Next adding tests ... --- benchmarks/dataframe_performance.cc | 6 +- .../DataFrame/DataFrameFinancialVisitors.h | 594 +++++++++--------- include/DataFrame/DataFrameMLVisitors.h | 66 +- include/DataFrame/DataFrameStatsVisitors.h | 374 ++++++----- .../DataFrame/DataFrameTransformVisitors.h | 14 +- include/DataFrame/Internals/DataFrame.tcc | 14 +- .../Internals/DataFrame_private_decl.h | 14 +- 7 files changed, 529 insertions(+), 553 deletions(-) diff --git a/benchmarks/dataframe_performance.cc b/benchmarks/dataframe_performance.cc index 91488ec3e..0cd8dc01e 100644 --- a/benchmarks/dataframe_performance.cc +++ b/benchmarks/dataframe_performance.cc @@ -25,6 +25,8 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#pragma omp declare simd clauses + #include #include #include @@ -33,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace hmdf; -constexpr std::size_t ALIGNMENT = 64; +constexpr std::size_t ALIGNMENT = 256; -typedef StdDataFrame64 MyDataFrame; +typedef StdDataFrame256 MyDataFrame; // ----------------------------------------------------------------------------- diff --git a/include/DataFrame/DataFrameFinancialVisitors.h b/include/DataFrame/DataFrameFinancialVisitors.h index 8304d1e06..0cd827342 100644 --- a/include/DataFrame/DataFrameFinancialVisitors.h +++ b/include/DataFrame/DataFrameFinancialVisitors.h @@ -48,10 +48,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace hmdf { -template::value, T>::type> +template struct ReturnVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -113,8 +110,7 @@ template::value, T>::type> + std::size_t A = 0> struct DoubleCrossOver { private: @@ -249,23 +245,24 @@ struct DoubleCrossOver { result_type short_term_to_long_term_; }; -template -using dco_v = DoubleCrossOver; +template +using dco_v = DoubleCrossOver; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct BollingerBand { private: const double upper_band_multiplier_; const double lower_band_multiplier_; - SimpleRollAdopter, T, I> mean_roller_; - SimpleRollAdopter, T, I> std_roller_; + SimpleRollAdopter, T, I, A> mean_roller_; + SimpleRollAdopter, T, I, A> std_roller_; template inline void @@ -385,10 +382,7 @@ struct BollingerBand { // Moving Average Convergence/Divergence // -template::value, T>::type> +template struct MACDVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -464,7 +458,7 @@ struct MACDVisitor { private: - using macd_roller_t = ewm_v; + using macd_roller_t = ewm_v; const size_type short_mean_period_; const size_type long_mean_period_; @@ -473,17 +467,14 @@ struct MACDVisitor { result_type macd_histogram_ { }; // MACD Line - Signal Line }; -template -using macd_v = MACDVisitor; +template +using macd_v = MACDVisitor; // ---------------------------------------------------------------------------- // Volume Weighted Average Price // -template::value, T>::type> +template struct VWAPVisitor { DEFINE_VISIT_BASIC_TYPES @@ -504,7 +495,8 @@ struct VWAPVisitor { { std::numeric_limits::max() }; }; - using result_type = std::vector; + using result_type = + std::vector::type>; using distance_func = std::function; @@ -653,17 +645,14 @@ struct VWAPVisitor { const double total_volume_limit_; }; -template -using vwap_v = VWAPVisitor; +template +using vwap_v = VWAPVisitor; // ---------------------------------------------------------------------------- // Volume Weighted Bid-Ask Spread // -template::value, T>::type> +template struct VWBASVisitor { DEFINE_VISIT_BASIC_TYPES @@ -693,7 +682,8 @@ struct VWBASVisitor { { std::numeric_limits::max() }; }; - using result_type = std::vector; + using result_type = + std::vector::type>; using distance_func = std::function; @@ -920,8 +910,8 @@ struct VWBASVisitor { const double max_volume_; }; -template -using vwbas_v = VWBASVisitor; +template +using vwbas_v = VWBASVisitor; // ---------------------------------------------------------------------------- @@ -1010,10 +1000,7 @@ using sharper_v = SharpeRatioVisitor; // // The input (column) to this visitor is assumed to be instrument prices. // -template::value, T>::type> +template struct RSIVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1029,7 +1016,7 @@ struct RSIVisitor { // if (avg_period_ >= T(col_s - 3)) return; - ReturnVisitor return_v (rp_); + ReturnVisitor return_v (rp_); return_v.pre(); return_v (idx_begin, idx_end, prices_begin, prices_end); @@ -1084,17 +1071,14 @@ struct RSIVisitor { result_type result_ { }; }; -template -using rsi_v = RSIVisitor; +template +using rsi_v = RSIVisitor; // ---------------------------------------------------------------------------- // RSX is a "noise free" version of RSI, with no added lag. // -template::value, T>::type> +template struct RSXVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1202,20 +1186,18 @@ struct RSXVisitor { result_type result_ { }; }; -template -using rsx_v = RSXVisitor; +template +using rsx_v = RSXVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct HurstExponentVisitor { DEFINE_VISIT_BASIC_TYPES_2 - using RangeVec = std::vector; + using RangeVec = + std::vector::type>; private: @@ -1238,9 +1220,10 @@ struct HurstExponentVisitor { GET_COL_SIZE - std::vector buckets; - MeanVisitor mv; - StdVisitor sv; + std::vector::type> buckets; + MeanVisitor mv; + StdVisitor sv; // Calculate each range basic stats // @@ -1291,8 +1274,12 @@ struct HurstExponentVisitor { size_type prev_size { 0 }; value_type count { 0 }; value_type total_rescaled_range { 0 }; - std::vector log_rescaled_mean; - std::vector log_size; + std::vector< + value_type, + typename allocator_declare::type> log_rescaled_mean; + std::vector< + value_type, + typename allocator_declare::type> log_size; log_rescaled_mean.reserve(ranges_.size()); log_size.reserve(ranges_.size()); @@ -1315,7 +1302,7 @@ struct HurstExponentVisitor { std::log(total_rescaled_range / count)); } - PolyFitVisitor pfv (1); // First degree + PolyFitVisitor pfv (1); // First degree pfv.pre(); pfv (idx_begin, idx_end, @@ -1339,15 +1326,12 @@ struct HurstExponentVisitor { result_type exponent_ { -1 }; }; -template -using hexpo_v = HurstExponentVisitor; +template +using hexpo_v = HurstExponentVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct MassIndexVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1363,7 +1347,7 @@ struct MassIndexVisitor { assert((col_s == size_type(std::distance(low_begin, low_end)))); assert(fast_ < slow_); - nzr_v non_z_range; + nzr_v non_z_range; non_z_range.pre(); non_z_range(idx_begin, idx_end, @@ -1427,20 +1411,20 @@ struct MassIndexVisitor { private: - using erm_t = ewm_v; - using srs_t = SimpleRollAdopter, T, I>; + using erm_t = ewm_v; + using srs_t = SimpleRollAdopter, T, I, A>; result_type result_ { }; const size_type slow_; const size_type fast_; }; -template -using mass_idx_v = MassIndexVisitor; +template +using mass_idx_v = MassIndexVisitor; // ---------------------------------------------------------------------------- -template +template struct HullRollingMeanVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1452,7 +1436,7 @@ struct HullRollingMeanVisitor { if (roll_count_ <= 1) return; - using wma_t = SimpleRollAdopter, T, I>; + using wma_t = SimpleRollAdopter, T, I, A>; GET_COL_SIZE @@ -1497,12 +1481,12 @@ struct HullRollingMeanVisitor { result_type result_ { }; }; -template -using hull_mean_v = HullRollingMeanVisitor; +template +using hull_mean_v = HullRollingMeanVisitor; // ---------------------------------------------------------------------------- -template +template struct RollingMidValueVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1563,12 +1547,12 @@ struct RollingMidValueVisitor { result_type result_ { }; }; -template -using mid_val_v = RollingMidValueVisitor; +template +using mid_val_v = RollingMidValueVisitor; // ---------------------------------------------------------------------------- -template +template struct DrawdownVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1580,7 +1564,7 @@ struct DrawdownVisitor { GET_COL_SIZE - CumMaxVisitor cm_v; + CumMaxVisitor cm_v; cm_v.pre(); cm_v (idx_begin, idx_end, column_begin, column_end); @@ -1629,7 +1613,7 @@ struct DrawdownVisitor { // Also called Stochastic Oscillator // -template +template struct WilliamPrcRVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1648,14 +1632,14 @@ struct WilliamPrcRVisitor { assert((col_s == size_type(std::distance(low_begin, low_end)))); assert((col_s == size_type(std::distance(high_begin, high_end)))); - SimpleRollAdopter, T, I> min_v (MinVisitor(), + SimpleRollAdopter, T, I, A> min_v (MinVisitor(), roll_count_); min_v.pre(); min_v (idx_begin, idx_end, low_begin, low_end); min_v.post(); - SimpleRollAdopter, T, I> max_v (MaxVisitor(), + SimpleRollAdopter, T, I, A> max_v (MaxVisitor(), roll_count_); max_v.pre(); @@ -1688,14 +1672,14 @@ struct WilliamPrcRVisitor { result_type result_ { }; }; -template -using willp_v = WilliamPrcRVisitor; +template +using willp_v = WilliamPrcRVisitor; // ---------------------------------------------------------------------------- // Psychological Line (PSL) is an oscillator-type indicator // -template +template struct PSLVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1743,7 +1727,7 @@ struct PSLVisitor { template inline void calculate_(const K &idx_begin, const K &idx_end) { - SimpleRollAdopter, T, I> sum_r (SumVisitor(), + SimpleRollAdopter, T, I, A> sum_r (SumVisitor(), roll_count_); sum_r.pre(); @@ -1764,7 +1748,7 @@ struct PSLVisitor { // Commodity Channel Index (CCI) // -template +template struct CCIVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1791,14 +1775,14 @@ struct CCIVisitor { (*(low_begin + i) + *(high_begin + i) + *(close_begin + i)) / T(3)); - SimpleRollAdopter, T, I> avg_v ( + SimpleRollAdopter, T, I, A> avg_v ( MeanVisitor(), roll_count_); avg_v.pre(); avg_v (idx_begin, idx_end, result.begin(), result.end()); avg_v.post(); - SimpleRollAdopter, T, I> mad_v ( + SimpleRollAdopter, T, I, A> mad_v ( MADVisitor(mad_type::mean_abs_dev_around_mean), roll_count_); mad_v.pre(); @@ -1830,10 +1814,7 @@ struct CCIVisitor { // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct GarmanKlassVolVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1897,15 +1878,12 @@ struct GarmanKlassVolVisitor { const size_type trading_periods_; }; -template -using gk_vol_v = GarmanKlassVolVisitor; +template +using gk_vol_v = GarmanKlassVolVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct YangZhangVolVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1989,14 +1967,14 @@ struct YangZhangVolVisitor { const size_type trading_periods_; }; -template -using yz_vol_v = YangZhangVolVisitor; +template +using yz_vol_v = YangZhangVolVisitor; // ---------------------------------------------------------------------------- // Kaufman's Adaptive Moving Average // -template +template struct KamaVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2023,7 +2001,7 @@ struct KamaVisitor { peer_diff[i] = std::fabs(*(column_begin + (i - 1)) - *(column_begin + i)); - SimpleRollAdopter, T, I> vol ( + SimpleRollAdopter, T, I, A> vol ( SumVisitor(), roll_count_); vol.pre(); @@ -2072,10 +2050,7 @@ struct KamaVisitor { // Fisher Transform Indicator // -template::value, T>::type> +template struct FisherTransVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2091,15 +2066,15 @@ struct FisherTransVisitor { assert((col_s == size_type(std::distance(high_begin, high_end)))); assert((roll_count_ < (col_s - 1))); - std::vector mid_hl; + result_type mid_hl; mid_hl.reserve(col_s); for (size_type i = 0; i < col_s; ++i) mid_hl.push_back((*(low_begin + i) + *(high_begin + i)) * T(0.5)); - SimpleRollAdopter, T, I> max_v (MaxVisitor(), + SimpleRollAdopter, T, I, A> max_v (MaxVisitor(), roll_count_); - SimpleRollAdopter, T, I> min_v (MinVisitor(), + SimpleRollAdopter, T, I, A> min_v (MinVisitor(), roll_count_); max_v.pre(); @@ -2152,17 +2127,14 @@ struct FisherTransVisitor { const size_type roll_count_; }; -template -using ftrans_v = FisherTransVisitor; +template +using ftrans_v = FisherTransVisitor; // ---------------------------------------------------------------------------- // Percentage Price Oscillator (PPO) // -template::value, T>::type> +template struct PercentPriceOSCIVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2228,8 +2200,8 @@ struct PercentPriceOSCIVisitor { private: - using erm_t = ewm_v; - using srs_t = SimpleRollAdopter, T, I>; + using erm_t = ewm_v; + using srs_t = SimpleRollAdopter, T, I, A>; result_type result_ { }; result_type histogram_ { }; @@ -2238,12 +2210,12 @@ struct PercentPriceOSCIVisitor { const size_type signal_; }; -template -using pp_osc_v = PercentPriceOSCIVisitor; +template +using pp_osc_v = PercentPriceOSCIVisitor; // ---------------------------------------------------------------------------- -template +template struct SlopeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2259,7 +2231,7 @@ struct SlopeVisitor { GET_COL_SIZE - DiffVisitor diff (periods_, false); + DiffVisitor diff (periods_, false); diff.pre(); diff (idx_begin, idx_end, column_begin, column_end); @@ -2302,7 +2274,7 @@ struct SlopeVisitor { // Ultimate Oscillator indicator // -template +template struct UltimateOSCIVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2319,7 +2291,7 @@ struct UltimateOSCIVisitor { assert((col_s == size_type(std::distance(low_begin, low_end)))); assert((col_s == size_type(std::distance(high_begin, high_end)))); - std::vector max_high; + result_type max_high; max_high.reserve(col_s); max_high.push_back(std::numeric_limits::quiet_NaN()); @@ -2327,7 +2299,7 @@ struct UltimateOSCIVisitor { max_high.push_back(std::max(*(high_begin + i), *(close_begin + (i - 1)))); - std::vector min_low; + result_type min_low; min_low.reserve(col_s); min_low.push_back(std::numeric_limits::quiet_NaN()); @@ -2335,13 +2307,13 @@ struct UltimateOSCIVisitor { min_low.push_back(std::min(*(low_begin + i), *(close_begin + (i - 1)))); - std::vector buying_pressure; + result_type buying_pressure; buying_pressure.reserve(col_s); for (size_type i = 0; i < col_s; ++i) buying_pressure.push_back(*(close_begin + i) - min_low[i]); - std::vector true_range; + result_type true_range; true_range.reserve(col_s); for (size_type i = 0; i < col_s; ++i) @@ -2418,7 +2390,7 @@ struct UltimateOSCIVisitor { private: - using ssr_t = SimpleRollAdopter, T, I>; + using ssr_t = SimpleRollAdopter, T, I, A>; const size_type slow_; const size_type fast_; @@ -2429,12 +2401,12 @@ struct UltimateOSCIVisitor { result_type result_ { }; }; -template -using u_osc_v = UltimateOSCIVisitor; +template +using u_osc_v = UltimateOSCIVisitor; // ---------------------------------------------------------------------------- -template +template struct UlcerIndexVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2448,7 +2420,7 @@ struct UlcerIndexVisitor { GET_COL_SIZE - SimpleRollAdopter, T, I> high (MaxVisitor(), + SimpleRollAdopter, T, I, A> high (MaxVisitor(), periods_); high.pre(); @@ -2464,9 +2436,9 @@ struct UlcerIndexVisitor { result[i] = val * val; } - SimpleRollAdopter, T, I> sum (SumVisitor(), + SimpleRollAdopter, T, I, A> sum (SumVisitor(), periods_); - SimpleRollAdopter, T, I> avg (MeanVisitor(), + SimpleRollAdopter, T, I, A> avg (MeanVisitor(), periods_); if (use_sum_) { @@ -2503,19 +2475,20 @@ struct UlcerIndexVisitor { result_type result_ { }; }; -template -using u_idx_v = UlcerIndexVisitor; +template +using u_idx_v = UlcerIndexVisitor; // ---------------------------------------------------------------------------- // Trade To Market trend indicator // -template +template struct TTMTrendVisitor { DEFINE_VISIT_BASIC_TYPES - using result_type = std::vector; + using result_type = + std::vector::type>; template inline void @@ -2532,7 +2505,7 @@ struct TTMTrendVisitor { assert((col_s == size_type(std::distance(high_begin, high_end)))); assert(((bar_periods_ + 1) < col_s)); - std::vector trend_avg; + std::vector::type> trend_avg; trend_avg.reserve(col_s); for (size_type i = 0; i < bar_periods_; ++i) @@ -2568,19 +2541,20 @@ struct TTMTrendVisitor { result_type result_ { }; }; -template -using ttmt_v = TTMTrendVisitor; +template +using ttmt_v = TTMTrendVisitor; // ---------------------------------------------------------------------------- // Parabolic Stop And Reverse (PSAR) // -template +template struct ParabolicSARVisitor { DEFINE_VISIT_BASIC_TYPES - using result_type = std::vector; + using result_type = + std::vector::type>; template inline void @@ -2598,13 +2572,22 @@ struct ParabolicSARVisitor { bool bullish { true }; value_type high_point { *high_begin }; value_type low_point { *low_begin }; - std::vector sar { close_begin, close_end }; + std::vector::type> + sar { close_begin, close_end }; value_type current_af { af_ }; - std::vector long_vec( - col_s, std::numeric_limits::quiet_NaN()); - std::vector short_vec { long_vec }; - std::vector accel_fact { long_vec }; - std::vector reversal(col_s, false); + std::vector::type> + long_vec(col_s, std::numeric_limits::quiet_NaN()); + std::vector::type> + short_vec { long_vec }; + std::vector::type> + accel_fact { long_vec }; + std::vector::type> + reversal(col_s, false); accel_fact[0] = accel_fact[1] = current_af; for (size_type i = 2; i < col_s; ++i) { @@ -2681,17 +2664,31 @@ struct ParabolicSARVisitor { inline void post () { } DEFINE_RESULT - inline const std::vector & + inline + const std::vector::type> & get_longs () const { return (long_); } - inline std::vector &get_longs () { return (long_); } - - inline const std::vector & + inline + std::vector::type> & + get_longs () { return (long_); } + + inline + const std::vector::type> & get_shorts () const { return (short_); } - inline std::vector &get_shorts () { return (short_); } - - inline const std::vector & + inline + std::vector::type> & + get_shorts () { return (short_); } + + inline + const std::vector::type> & get_acceleration_factors () const { return (accel_fact_); } - inline std::vector & + inline + std::vector::type> & get_acceleration_factors () { return (accel_fact_); } explicit @@ -2705,19 +2702,23 @@ struct ParabolicSARVisitor { const value_type af_; const value_type max_af_; result_type result_ { }; - std::vector long_ { }; - std::vector short_ { }; - std::vector accel_fact_ { }; + + std::vector::type> long_ { }; + std::vector::type> short_ { }; + std::vector::type> accel_fact_ { }; }; -template -using psar_v = ParabolicSARVisitor; +template +using psar_v = ParabolicSARVisitor; // ---------------------------------------------------------------------------- // Even Better Sine Wave (EBSW) indicator // -template +template struct EBSineWaveVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2732,7 +2733,7 @@ struct EBSineWaveVisitor { assert(hp_period_ > 38 && bar_period_ < col_s); assert(bar_period_ > 0 && hp_period_ < col_s); - std::vector result(col_s, std::numeric_limits::quiet_NaN()); + result_type result(col_s, std::numeric_limits::quiet_NaN()); value_type last_close = *close_begin; value_type last_high_pass { 0 }; value_type filter_hist[2] = { 0, 0 }; @@ -2799,14 +2800,14 @@ struct EBSineWaveVisitor { result_type result_ { }; }; -template -using ebsw_v = EBSineWaveVisitor; +template +using ebsw_v = EBSineWaveVisitor; // ---------------------------------------------------------------------------- // Ehler's Super Smoother Filter (SSF) indicator // -template +template struct EhlerSuperSmootherVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2871,14 +2872,14 @@ struct EhlerSuperSmootherVisitor { result_type result_ { }; }; -template -using ess_v = EhlerSuperSmootherVisitor; +template +using ess_v = EhlerSuperSmootherVisitor; // ---------------------------------------------------------------------------- // Variable Index Dynamic Average (VIDYA) indicator // -template +template struct VarIdxDynAvgVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2892,7 +2893,7 @@ struct VarIdxDynAvgVisitor { assert(roll_period_ > 1 && roll_period_ < col_s); - DiffVisitor diff(1, false); + DiffVisitor diff(1, false); diff.pre(); diff (idx_begin, idx_end, column_begin, column_end); @@ -2910,7 +2911,7 @@ struct VarIdxDynAvgVisitor { else negative[i] = std::fabs(negative[i]); } - SimpleRollAdopter, T, I> sum (SumVisitor(), + SimpleRollAdopter, T, I, A> sum (SumVisitor(), roll_period_); sum.pre(); @@ -2953,14 +2954,14 @@ struct VarIdxDynAvgVisitor { result_type result_ { }; }; -template -using vidya_v = VarIdxDynAvgVisitor; +template +using vidya_v = VarIdxDynAvgVisitor; // ---------------------------------------------------------------------------- // Pivot Points, Supports and Resistances indicators // -template +template struct PivotPointSRVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3056,14 +3057,14 @@ struct PivotPointSRVisitor { result_type support_3_ { }; }; -template -using ppsr_v = PivotPointSRVisitor; +template +using ppsr_v = PivotPointSRVisitor; // ---------------------------------------------------------------------------- // Average Directional Movement Index (ADX) // -template +template struct AvgDirMovIdxVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3100,7 +3101,8 @@ struct AvgDirMovIdxVisitor { true_range[i] = std::max(nxt_h, close) - std::min(nxt_l, close); } - ewm_v ewm(exponential_decay_spec::span, dir_smoother_, true); + ewm_v ewm(exponential_decay_spec::span, + dir_smoother_, true); ewm.pre(); ewm (idx_begin, idx_end, true_range.begin(), true_range.end()); @@ -3130,7 +3132,8 @@ struct AvgDirMovIdxVisitor { dx[i] = prev_val; } - ewm_v ewm2(exponential_decay_spec::span, adx_smoother_, true); + ewm_v ewm2(exponential_decay_spec::span, + adx_smoother_, true); ewm2.pre(); ewm2 (idx_begin, idx_end, dx.begin(), dx.end()); @@ -3151,14 +3154,14 @@ struct AvgDirMovIdxVisitor { result_type result_ { }; }; -template -using adx_v = AvgDirMovIdxVisitor; +template +using adx_v = AvgDirMovIdxVisitor; // ---------------------------------------------------------------------------- // Holt-Winter Channel (HWC) indicator // -template +template struct HoltWinterChannelVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3254,15 +3257,12 @@ struct HoltWinterChannelVisitor { result_type pct_diff_ { }; }; -template -using hwc_v = HoltWinterChannelVisitor; +template +using hwc_v = HoltWinterChannelVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct HeikinAshiCndlVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3334,14 +3334,14 @@ struct HeikinAshiCndlVisitor { result_type low_ { }; }; -template -using ha_cdl_v = HeikinAshiCndlVisitor; +template +using ha_cdl_v = HeikinAshiCndlVisitor; // ---------------------------------------------------------------------------- // Also called Stochastic Oscillator // -template +template struct CenterOfGravityVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3367,7 +3367,7 @@ struct CenterOfGravityVisitor { result[i] = dot_prd; } - SimpleRollAdopter, T, I> sum_v + SimpleRollAdopter, T, I, A> sum_v { SumVisitor(), roll_count_ }; sum_v.pre(); @@ -3391,14 +3391,14 @@ struct CenterOfGravityVisitor { result_type result_ { }; }; -template -using cog_v = CenterOfGravityVisitor; +template +using cog_v = CenterOfGravityVisitor; // ---------------------------------------------------------------------------- // Arnaud Legoux Moving Average // -template +template struct ArnaudLegouxMAVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3450,20 +3450,20 @@ struct ArnaudLegouxMAVisitor { private: - const size_type roll_count_; - const value_type m_; - const value_type s_; - value_type cum_sum_ { 0 }; - std::vector wtd_; - result_type result_ { }; + const size_type roll_count_; + const value_type m_; + const value_type s_; + value_type cum_sum_ { 0 }; + result_type wtd_; + result_type result_ { }; }; -template -using alma_v = ArnaudLegouxMAVisitor; +template +using alma_v = ArnaudLegouxMAVisitor; // ---------------------------------------------------------------------------- -template +template struct RateOfChangeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3476,7 +3476,7 @@ struct RateOfChangeVisitor { GET_COL_SIZE assert (period_ > 0); - DiffVisitor diff(period_, false); + DiffVisitor diff(period_, false); diff.pre(); diff (idx_begin, idx_end, column_begin, column_end); @@ -3501,14 +3501,14 @@ struct RateOfChangeVisitor { result_type result_ { }; }; -template -using roc_v = RateOfChangeVisitor; +template +using roc_v = RateOfChangeVisitor; // ---------------------------------------------------------------------------- // Accumulation/Distribution (AD) indicator // -template +template struct AccumDistVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3538,7 +3538,7 @@ struct AccumDistVisitor { result[i] = co * T(*(volume_begin + i)) / hl; } - CumSumVisitor cumsum; + CumSumVisitor cumsum; cumsum.pre(); cumsum (idx_begin, idx_end, result.begin(), result.end()); @@ -3556,14 +3556,14 @@ struct AccumDistVisitor { result_type result_ { }; }; -template -using ad_v = AccumDistVisitor; +template +using ad_v = AccumDistVisitor; // ---------------------------------------------------------------------------- // Chaikin Money Flow (CMF) indicator // -template +template struct ChaikinMoneyFlowVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3594,7 +3594,7 @@ struct ChaikinMoneyFlowVisitor { result[i] = co * T(*(volume_begin + i)) / hl; } - SimpleRollAdopter, T, I> sum + SimpleRollAdopter, T, I, A> sum { SumVisitor(), period_ }; sum.pre(); @@ -3625,14 +3625,14 @@ struct ChaikinMoneyFlowVisitor { result_type result_ { }; }; -template -using cmf_v = ChaikinMoneyFlowVisitor; +template +using cmf_v = ChaikinMoneyFlowVisitor; // ---------------------------------------------------------------------------- // Vertical Horizontal Filter (VHF) indicator // -template +template struct VertHorizFilterVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3645,21 +3645,21 @@ struct VertHorizFilterVisitor { GET_COL_SIZE assert (period_ > 0 && period_ < col_s); - SimpleRollAdopter, T, I> mx + SimpleRollAdopter, T, I, A> mx { MaxVisitor(), period_ }; mx.pre(); mx (idx_begin, idx_end, column_begin, column_end); mx.post(); - SimpleRollAdopter, T, I> mn + SimpleRollAdopter, T, I, A> mn { MinVisitor(), period_ }; mn.pre(); mn (idx_begin, idx_end, column_begin, column_end); mn.post(); - DiffVisitor diff(1, false); + DiffVisitor diff(1, false); diff.pre(); diff (idx_begin, idx_end, column_begin, column_end); @@ -3667,7 +3667,7 @@ struct VertHorizFilterVisitor { for (size_type i = 0; i < col_s; ++i) diff.get_result()[i] = std::fabs(diff.get_result()[i]); - SimpleRollAdopter, T, I> diff_sum + SimpleRollAdopter, T, I, A> diff_sum { SumVisitor(), period_ }; diff_sum.pre(); @@ -3697,14 +3697,14 @@ struct VertHorizFilterVisitor { result_type result_ { }; }; -template -using vhf_v = VertHorizFilterVisitor; +template +using vhf_v = VertHorizFilterVisitor; // ---------------------------------------------------------------------------- // On Balance Volume (OBV) indicator // -template +template struct OnBalanceVolumeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3719,7 +3719,7 @@ struct OnBalanceVolumeVisitor { assert((col_s == size_type(std::distance(volume_begin, volume_end)))); - ReturnVisitor ret (return_policy::trinary); + ReturnVisitor ret (return_policy::trinary); ret.pre(); ret (idx_begin, idx_end, close_begin, close_end); @@ -3731,7 +3731,7 @@ struct OnBalanceVolumeVisitor { for (size_type i = 0; i < col_s; ++i) result[i] *= T(*(volume_begin + i)); - CumSumVisitor cumsum; + CumSumVisitor cumsum; cumsum.pre(); cumsum (idx_begin, idx_end, result.begin(), result.end()); @@ -3747,12 +3747,12 @@ struct OnBalanceVolumeVisitor { result_type result_ { }; }; -template -using obv_v = OnBalanceVolumeVisitor; +template +using obv_v = OnBalanceVolumeVisitor; // ---------------------------------------------------------------------------- -template +template struct TrueRangeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3779,7 +3779,7 @@ struct TrueRangeVisitor { } if (rolling_avg_) { - ewm_v avg(exponential_decay_spec::span, + ewm_v avg(exponential_decay_spec::span, rolling_period_, true); @@ -3819,7 +3819,7 @@ struct TrueRangeVisitor { // Decay indicator // -template +template struct DecayVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3862,10 +3862,7 @@ struct DecayVisitor { // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct HodgesTompkinsVolVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3878,13 +3875,13 @@ struct HodgesTompkinsVolVisitor { GET_COL_SIZE assert (roll_count_ > 0 && roll_count_ < col_s); - ReturnVisitor ret (return_policy::log); + ReturnVisitor ret (return_policy::log); ret.pre(); ret (idx_begin, idx_end, column_begin, column_end); ret.post(); - SimpleRollAdopter, T, I> stdev + SimpleRollAdopter, T, I, A> stdev { StdVisitor(), roll_count_ }; stdev.pre(); @@ -3922,15 +3919,12 @@ struct HodgesTompkinsVolVisitor { const size_type trading_periods_; }; -template -using ht_vol_v = HodgesTompkinsVolVisitor; +template +using ht_vol_v = HodgesTompkinsVolVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct ParkinsonVolVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3956,7 +3950,7 @@ struct ParkinsonVolVisitor { result[i] = factor * val * val; } - SimpleRollAdopter, T, I> avg + SimpleRollAdopter, T, I, A> avg { MeanVisitor(), roll_count_ } ; avg.pre(); @@ -3985,12 +3979,12 @@ struct ParkinsonVolVisitor { const size_type trading_periods_; }; -template -using p_vol_v = ParkinsonVolVisitor; +template +using p_vol_v = ParkinsonVolVisitor; // ---------------------------------------------------------------------------- -template +template struct CoppockCurveVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4002,13 +3996,13 @@ struct CoppockCurveVisitor { GET_COL_SIZE - roc_v roc_l (roc_long_); + roc_v roc_l (roc_long_); roc_l.pre(); roc_l (idx_begin, idx_end, column_begin, column_end); roc_l.post(); - roc_v roc_s (roc_short_); + roc_v roc_s (roc_short_); roc_s.pre(); roc_s (idx_begin, idx_end, column_begin, column_end); @@ -4019,7 +4013,7 @@ struct CoppockCurveVisitor { for (size_type i = 0; i < col_s; ++i) result[i] += roc_s.get_result()[i]; - using wma_t = SimpleRollAdopter, T, I>; + using wma_t = SimpleRollAdopter, T, I, A>; wma_t wma (WeightedMeanVisitor(), wma_period_); @@ -4049,12 +4043,12 @@ struct CoppockCurveVisitor { result_type result_ { }; }; -template -using coppc_v = CoppockCurveVisitor; +template +using coppc_v = CoppockCurveVisitor; // ---------------------------------------------------------------------------- -template +template struct BalanceOfPowerVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4073,7 +4067,7 @@ struct BalanceOfPowerVisitor { assert((col_s == size_type(std::distance(open_begin, open_end)))); assert((col_s == size_type(std::distance(high_begin, high_end)))); - nzr_v non_z_range; + nzr_v non_z_range; non_z_range.pre(); non_z_range(idx_begin, idx_end, @@ -4091,7 +4085,7 @@ struct BalanceOfPowerVisitor { result[i] /= non_z_range.get_result()[i]; if (rolling_avg_) { - SimpleRollAdopter, T, I> avg + SimpleRollAdopter, T, I, A> avg { MeanVisitor(), rolling_period_ } ; avg.pre(); @@ -4119,12 +4113,12 @@ struct BalanceOfPowerVisitor { const size_type rolling_period_; }; -template -using bop_v = BalanceOfPowerVisitor; +template +using bop_v = BalanceOfPowerVisitor; // ---------------------------------------------------------------------------- -template +template struct ChandeKrollStopVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4141,7 +4135,7 @@ struct ChandeKrollStopVisitor { assert((col_s == size_type(std::distance(low_begin, low_end)))); assert((col_s == size_type(std::distance(high_begin, high_end)))); - TrueRangeVisitor atr(true, p_period_); + TrueRangeVisitor atr(true, p_period_); atr.pre(); atr(idx_begin, idx_end, @@ -4150,7 +4144,7 @@ struct ChandeKrollStopVisitor { close_begin, close_end); atr.post(); - SimpleRollAdopter, T, I> max1 + SimpleRollAdopter, T, I, A> max1 { MaxVisitor(), p_period_ }; max1.pre(); @@ -4162,7 +4156,7 @@ struct ChandeKrollStopVisitor { for (size_type i = 0; i < col_s; ++i) long_stop[i] -= multiplier_ * atr.get_result()[i]; - SimpleRollAdopter, T, I> max2 + SimpleRollAdopter, T, I, A> max2 { MaxVisitor(), q_period_ }; max2.pre(); @@ -4170,7 +4164,7 @@ struct ChandeKrollStopVisitor { max2.post(); long_stop = std::move(max2.get_result()); - SimpleRollAdopter, T, I> min1 + SimpleRollAdopter, T, I, A> min1 { MinVisitor(), p_period_ }; min1.pre(); @@ -4182,7 +4176,7 @@ struct ChandeKrollStopVisitor { for (size_type i = 0; i < col_s; ++i) short_stop[i] += multiplier_ * atr.get_result()[i]; - SimpleRollAdopter, T, I> min2 + SimpleRollAdopter, T, I, A> min2 { MaxVisitor(), q_period_ }; min2.pre(); @@ -4225,12 +4219,12 @@ struct ChandeKrollStopVisitor { const value_type multiplier_; // X }; -template -using cksp_v = ChandeKrollStopVisitor; +template +using cksp_v = ChandeKrollStopVisitor; // ---------------------------------------------------------------------------- -template +template struct VortexVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4248,7 +4242,7 @@ struct VortexVisitor { assert((col_s == size_type(std::distance(high_begin, high_end)))); assert((roll_period_ < (col_s - 1))); - TrueRangeVisitor tr (false); + TrueRangeVisitor tr (false); tr.pre(); tr(idx_begin, idx_end, @@ -4257,7 +4251,7 @@ struct VortexVisitor { close_begin, close_end); tr.post(); - SimpleRollAdopter, T, I> tr_sum + SimpleRollAdopter, T, I, A> tr_sum { SumVisitor(), roll_period_ }; tr_sum.pre(); @@ -4275,7 +4269,7 @@ struct VortexVisitor { std::fabs(*(low_begin + i) - *(high_begin + (i - 1))); } - SimpleRollAdopter, T, I> vtx_sum + SimpleRollAdopter, T, I, A> vtx_sum { SumVisitor(), roll_period_ }; vtx_sum.pre(); @@ -4326,15 +4320,12 @@ struct VortexVisitor { const size_type roll_period_; }; -template -using vtx_v = VortexVisitor; +template +using vtx_v = VortexVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct KeltnerChannelsVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4352,7 +4343,7 @@ struct KeltnerChannelsVisitor { assert((col_s == size_type(std::distance(high_begin, high_end)))); assert((roll_period_ < (col_s - 1))); - TrueRangeVisitor tr (false); + TrueRangeVisitor tr (false); tr.pre(); tr(idx_begin, idx_end, @@ -4361,13 +4352,13 @@ struct KeltnerChannelsVisitor { close_begin, close_end); tr.post(); - ewm_v basis(exponential_decay_spec::span, roll_period_, true); + ewm_v basis(exponential_decay_spec::span, roll_period_, true); basis.pre(); basis (idx_begin, idx_end, close_begin, close_end); basis.post(); - ewm_v band(exponential_decay_spec::span, roll_period_, true); + ewm_v band(exponential_decay_spec::span, roll_period_, true); band.pre(); band (idx_begin, idx_end, @@ -4415,15 +4406,12 @@ struct KeltnerChannelsVisitor { const value_type b_mult_; }; -template -using kch_v = KeltnerChannelsVisitor; +template +using kch_v = KeltnerChannelsVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct TrixVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4437,13 +4425,13 @@ struct TrixVisitor { assert(col_s > 3); - ewm_v ewm13(exponential_decay_spec::span, roll_period_, true); + ewm_v ewm13(exponential_decay_spec::span, roll_period_, true); ewm13.pre(); ewm13 (idx_begin, idx_end, column_begin, column_end); ewm13.post(); - ewm_v ewm2(exponential_decay_spec::span, roll_period_, true); + ewm_v ewm2(exponential_decay_spec::span, roll_period_, true); ewm2.pre(); ewm2 (idx_begin, idx_end, @@ -4455,7 +4443,7 @@ struct TrixVisitor { ewm2.get_result().begin(), ewm2.get_result().end()); ewm13.post(); - ReturnVisitor ret(return_policy::percentage); + ReturnVisitor ret(return_policy::percentage); ret.get_result().swap(ewm2.get_result()); ret.pre(); @@ -4466,7 +4454,7 @@ struct TrixVisitor { result_type result = std::move(ret.get_result()); if (avg_signal_) { - SimpleRollAdopter, T, I> avg + SimpleRollAdopter, T, I, A> avg { MeanVisitor(), sroll_period_ } ; avg.get_result().swap(ewm13.get_result()); @@ -4498,15 +4486,12 @@ struct TrixVisitor { const bool avg_signal_; }; -template -using trix_v = TrixVisitor; +template +using trix_v = TrixVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct PrettyGoodOsciVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4524,14 +4509,14 @@ struct PrettyGoodOsciVisitor { assert((col_s == size_type(std::distance(high_begin, high_end)))); assert((roll_period_ < (col_s - 1))); - SimpleRollAdopter, T, I> savg + SimpleRollAdopter, T, I, A> savg { MeanVisitor(), roll_period_ } ; savg.pre(); savg (idx_begin, idx_end, close_begin, close_end); savg.post(); - TrueRangeVisitor atr(true, roll_period_); + TrueRangeVisitor atr(true, roll_period_); atr.pre(); atr(idx_begin, idx_end, @@ -4545,7 +4530,7 @@ struct PrettyGoodOsciVisitor { for (size_type i = 0; i < col_s; ++i) result[i] = *(close_begin + i) - result[i]; - ewm_v ewm(exponential_decay_spec::span, roll_period_, true); + ewm_v ewm(exponential_decay_spec::span, roll_period_, true); ewm.pre(); ewm (idx_begin, idx_end, @@ -4571,15 +4556,12 @@ struct PrettyGoodOsciVisitor { const size_type roll_period_; }; -template -using pgo_v = PrettyGoodOsciVisitor; +template +using pgo_v = PrettyGoodOsciVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct T3MovingMeanVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4657,15 +4639,15 @@ struct T3MovingMeanVisitor { private: - using erm_t = ewm_v; + using erm_t = ewm_v; result_type result_ { }; const size_type rolling_period_; const double v_factor_; }; -template -using t3_v = T3MovingMeanVisitor; +template +using t3_v = T3MovingMeanVisitor; // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/DataFrameMLVisitors.h b/include/DataFrame/DataFrameMLVisitors.h index 930dca2e8..0aab603de 100644 --- a/include/DataFrame/DataFrameMLVisitors.h +++ b/include/DataFrame/DataFrameMLVisitors.h @@ -125,7 +125,10 @@ struct SLRegressionVisitor { // ---------------------------------------------------------------------------- -template +template struct KMeansVisitor { public: @@ -133,7 +136,7 @@ struct KMeansVisitor { DEFINE_VISIT_BASIC_TYPES using result_type = std::array; - using cluster_type = std::array, K>; + using cluster_type = std::array, K>; using distance_func = std::function; @@ -154,7 +157,9 @@ struct KMeansVisitor { for (auto &k_mean : result_) k_mean = *(column_begin + rd_gen(gen)); - std::vector assignments(col_size, 0); + std::vector::type> + assignments(col_size, 0); for (size_type iter = 0; iter < iter_num_; ++iter) { result_type new_means { value_type() }; @@ -271,15 +276,18 @@ struct KMeansVisitor { // ---------------------------------------------------------------------------- -template +template struct AffinityPropVisitor { public: DEFINE_VISIT_BASIC_TYPES - using result_type = VectorPtrView; - using cluster_type = std::vector>; + template + using vec_t = std::vector::type>; + + using result_type = VectorPtrView; + using cluster_type = vec_t>; using distance_func = std::function; @@ -291,11 +299,11 @@ struct AffinityPropVisitor { result_type result_ { }; // Centers template - inline std::vector + inline vec_t get_similarity_(const H &column_begin, size_type csize) { - std::vector simil((csize * (csize + 1)) / 2, 0.0); - double min_dist = std::numeric_limits::max(); + vec_t simil((csize * (csize + 1)) / 2, 0.0); + double min_dist = std::numeric_limits::max(); // Compute similarity between distinct data points i and j for (size_type i = 0; i < csize - 1; ++i) { @@ -317,10 +325,10 @@ struct AffinityPropVisitor { } inline void - get_avail_and_respon(const std::vector &simil, + get_avail_and_respon(const vec_t &simil, size_type csize, - std::vector &avail, - std::vector &respon) { + vec_t &avail, + vec_t &respon) { avail.resize(csize * csize, 0.0); respon.resize(csize * csize, 0.0); @@ -398,10 +406,10 @@ struct AffinityPropVisitor { const H &column_begin, const H &column_end) { GET_COL_SIZE - const std::vector simil = + const vec_t simil = std::move(get_similarity_(column_begin, col_s)); - std::vector avail; - std::vector respon; + vec_t avail; + vec_t respon; get_avail_and_respon(simil, col_s, avail, respon); @@ -468,17 +476,19 @@ struct AffinityPropVisitor { // ---------------------------------------------------------------------------- -template +template struct FastFourierTransVisitor { public: DEFINE_VISIT_BASIC_TYPES + template + using vec_t = std::vector::type>; using result_type = typename std::conditional::value, - std::vector, - std::vector>>::type; + vec_t, + vec_t>>::type; using real_t = typename result_type::value_type::value_type; private: @@ -694,13 +704,13 @@ struct FastFourierTransVisitor { inline void post () { } DEFINE_RESULT - inline const std::vector & + inline const vec_t & get_magnitude() const { return (const_cast *> (this)->get_magnitude()); } - inline std::vector & + inline vec_t & get_magnitude() { if (magnitude_.empty()) { @@ -710,13 +720,13 @@ struct FastFourierTransVisitor { } return (magnitude_); } - inline const std::vector & + inline const vec_t & get_angle() const { return (const_cast *> (this)->get_angle()); } - inline std::vector & + inline vec_t & get_angle() { if (angle_.empty()) { @@ -732,14 +742,14 @@ struct FastFourierTransVisitor { private: - const bool inverse_; - result_type result_ { }; - std::vector magnitude_ { }; - std::vector angle_ { }; + const bool inverse_; + result_type result_ { }; + vec_t magnitude_ { }; + vec_t angle_ { }; }; -template -using fft_v = FastFourierTransVisitor; +template +using fft_v = FastFourierTransVisitor; } // namespace hmdf diff --git a/include/DataFrame/DataFrameStatsVisitors.h b/include/DataFrame/DataFrameStatsVisitors.h index a093f5a54..d49db8507 100644 --- a/include/DataFrame/DataFrameStatsVisitors.h +++ b/include/DataFrame/DataFrameStatsVisitors.h @@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include #include @@ -72,7 +73,7 @@ namespace hmdf #define DEFINE_VISIT_BASIC_TYPES_3 \ DEFINE_VISIT_BASIC_TYPES \ - using result_type = std::vector; + using result_type = std::vector::type>; #define DEFINE_PRE_POST \ inline void pre () { result_.clear(); } \ @@ -956,8 +957,10 @@ using MinSubArrayVisitor = ExtremumSubArrayVisitor>; // ---------------------------------------------------------------------------- -template> +template, + std::size_t A = 0> struct NExtremumSubArrayVisitor { DEFINE_VISIT_BASIC_TYPES @@ -980,7 +983,9 @@ struct NExtremumSubArrayVisitor { } }; - using result_type = std::vector; + using result_type = + std::vector::type>; using compare_type = Cmp; inline void operator() (const index_type &idx, const value_type &val) { @@ -1033,7 +1038,7 @@ using NMinSubArrayVisitor = NExtremumSubArrayVisitor>; // Simple rolling adoptor for visitors // -template +template struct SimpleRollAdopter { private: @@ -1044,7 +1049,9 @@ struct SimpleRollAdopter { public: DEFINE_VISIT_BASIC_TYPES - using result_type = std::vector; + using result_type = + std::vector::type>; template inline void @@ -1080,9 +1087,9 @@ struct SimpleRollAdopter { private: - visitor_type visitor_ { }; - const size_type roll_count_ { 0 }; - std::vector result_ { }; + visitor_type visitor_ { }; + const size_type roll_count_ { 0 }; + result_type result_ { }; }; // ---------------------------------------------------------------------------- @@ -1131,7 +1138,7 @@ struct StepRollAdopter { // Expanding rolling adoptor for visitors // -template +template struct ExpandingRollAdopter { private: @@ -1139,15 +1146,16 @@ struct ExpandingRollAdopter { using visitor_type = F; using f_result_type = typename visitor_type::result_type; - visitor_type visitor_ { }; - const std::size_t init_roll_count_ { 0 }; - const std::size_t increment_count_ { 0 }; - std::vector result_ { }; + visitor_type visitor_ { }; + const std::size_t init_roll_count_ { 0 }; + const std::size_t increment_count_ { 0 }; public: DEFINE_VISIT_BASIC_TYPES - using result_type = std::vector; + using result_type = + std::vector::type>; template inline void @@ -1187,6 +1195,10 @@ struct ExpandingRollAdopter { : visitor_(std::move(functor)), init_roll_count_(r_count), increment_count_(i_count) { } + +private: + + result_type result_ { }; }; // ---------------------------------------------------------------------------- @@ -1194,7 +1206,7 @@ struct ExpandingRollAdopter { // Exponential rolling adoptor for visitors // (decay * Xt) + ((1 − decay) * AVGt-1) // -template +template struct ExponentialRollAdopter { private: @@ -1202,18 +1214,18 @@ struct ExponentialRollAdopter { using visitor_type = F; using f_result_type = typename visitor_type::result_type; - std::vector result_ { }; - visitor_type visitor_ { }; - const std::size_t roll_count_; - const std::size_t repeat_count_; - const T decay_; - const bool skip_nan_; + visitor_type visitor_ { }; + const std::size_t roll_count_; + const std::size_t repeat_count_; + const T decay_; + const bool skip_nan_; public: DEFINE_VISIT_BASIC_TYPES - - using result_type = std::vector; + using result_type = + std::vector::type>; template inline void @@ -1273,6 +1285,8 @@ struct ExponentialRollAdopter { return (decay_ * i_value + (T(1) - decay_) * i_1_value); } + + result_type result_ { }; }; // ---------------------------------------------------------------------------- @@ -1435,10 +1449,7 @@ struct TTestVisitor { // Single Action Visitors // -template::value, T>::type> +template struct CumSumVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1480,10 +1491,7 @@ struct CumSumVisitor { // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct CumProdVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1519,13 +1527,14 @@ struct CumProdVisitor { private: - std::vector result_ { }; - const bool skip_nan_; + result_type result_ { }; + const bool skip_nan_; }; // ---------------------------------------------------------------------------- -template> +template, std::size_t A = 0> struct CumExtremumVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1571,17 +1580,17 @@ struct CumExtremumVisitor { const bool skip_nan_; }; -template -using CumMaxVisitor = CumExtremumVisitor>; -template -using CumMinVisitor = CumExtremumVisitor>; +template +using CumMaxVisitor = CumExtremumVisitor, A>; +template +using CumMinVisitor = CumExtremumVisitor, A>; // ---------------------------------------------------------------------------- // This categorizes the values in the column with integer values starting // from 0 // -template +template struct CategoryVisitor { private: @@ -1594,7 +1603,8 @@ struct CategoryVisitor { public: DEFINE_VISIT_BASIC_TYPES - using result_type = std::vector; + using result_type = + std::vector::type>; template inline void @@ -1652,13 +1662,14 @@ struct CategoryVisitor { // This ranks the values in the column based on rank policy starting from 0. // -template +template struct RankVisitor { public: DEFINE_VISIT_BASIC_TYPES - using result_type = std::vector; + using result_type = + std::vector::type>; template inline void @@ -1666,7 +1677,8 @@ struct RankVisitor { const H &column_begin, const H &column_end) { GET_COL_SIZE - std::vector rank_vec(col_s); + std::vector::type> + rank_vec(col_s); std::iota(rank_vec.begin(), rank_vec.end(), 0); std::stable_sort( @@ -1741,11 +1753,12 @@ struct RankVisitor { // It factorizes the given column into a vector of Booleans based on the // result of the given function. // -template +template struct FactorizeVisitor { DEFINE_VISIT_BASIC_TYPES - using result_type = std::vector; + using result_type = + std::vector::type>; using factor_func = std::function; template @@ -1775,12 +1788,12 @@ struct FactorizeVisitor { // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct AutoCorrVisitor { + template + using vec_type = std::vector::type>; + public: DEFINE_VISIT_BASIC_TYPES_3 @@ -1793,12 +1806,12 @@ struct AutoCorrVisitor { if (col_s <= 4) return; - std::vector tmp_result(col_s - 4); - size_type lag = 1; - const size_type thread_level = + vec_type tmp_result(col_s - 4); + size_type lag = 1; + const size_type thread_level = ThreadGranularity::get_sensible_thread_level(); - std::vector> futures(thread_level); - size_type thread_count = 0; + vec_type> futures(thread_level); + size_type thread_count = 0; tmp_result[0] = 1.0; while (lag < col_s - 4) { @@ -1866,7 +1879,7 @@ struct AutoCorrVisitor { // ------------------------------------------------------------------------ // 1 + (1 - decay) + (1 - decay)^2 + ... + (1 - decay)^t // -template +template struct ExponentiallyWeightedMeanVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1941,12 +1954,12 @@ struct ExponentiallyWeightedMeanVisitor { result_type result_ { }; }; -template -using ewm_v = ExponentiallyWeightedMeanVisitor; +template +using ewm_v = ExponentiallyWeightedMeanVisitor; // ---------------------------------------------------------------------------- -template +template struct ZeroLagMovingMeanVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -1967,7 +1980,7 @@ struct ZeroLagMovingMeanVisitor { result_[i] = T(2) * *(column_begin + i) - *(column_begin + (i - lag)); - ewm_v ewm(exponential_decay_spec::span, roll_period_, true); + ewm_v ewm(exponential_decay_spec::span, roll_period_, true); ewm.pre(); ewm (idx_begin, idx_end, result_.begin() + lag, result_.end()); @@ -1990,22 +2003,25 @@ struct ZeroLagMovingMeanVisitor { result_type result_ { }; }; -template -using zlmm_v = ZeroLagMovingMeanVisitor; +template +using zlmm_v = ZeroLagMovingMeanVisitor; // ---------------------------------------------------------------------------- -template +template struct KthValueVisitor { DEFINE_VISIT_BASIC_TYPES_2 + template + using vec_type = std::vector::type>; + template inline void operator() (const K &, const K &, const H &values_begin, const H &values_end) { - std::vector aux (values_begin, values_end); + vec_type aux (values_begin, values_end); result_ = find_kth_element_(aux, 0, aux.size() - 1, kth_element_); } @@ -2063,12 +2079,12 @@ struct KthValueVisitor { } }; -template -using kthv_v = KthValueVisitor; +template +using kthv_v = KthValueVisitor; // ---------------------------------------------------------------------------- -template +template struct MedianVisitor { DEFINE_VISIT_BASIC_TYPES_2 @@ -2079,7 +2095,7 @@ struct MedianVisitor { const H &column_begin, const H &column_end) { GET_COL_SIZE - KthValueVisitor kv_visitor (col_s >> 1); + KthValueVisitor kv_visitor (col_s >> 1); kv_visitor.pre(); @@ -2087,7 +2103,7 @@ struct MedianVisitor { kv_visitor.post(); result_ = kv_visitor.get_result(); if (! (col_s & 0x0001)) { // even - KthValueVisitor kv_visitor2 ((col_s >> 1) + 1); + KthValueVisitor kv_visitor2 ((col_s >> 1) + 1); kv_visitor2.pre(); kv_visitor2(idx_begin, idx_end, column_begin, column_end); @@ -2107,12 +2123,12 @@ struct MedianVisitor { result_type result_ { }; }; -template -using med_v = MedianVisitor; +template +using med_v = MedianVisitor; // ---------------------------------------------------------------------------- -template +template struct QuantileVisitor { DEFINE_VISIT_BASIC_TYPES_2 @@ -2145,7 +2161,7 @@ struct QuantileVisitor { ! (col_s & 0x01) || double(int_idx) < vec_len_frac; if (qt_ == 0.0 || qt_ == 1.0) { - KthValueVisitor kth_value((qt_ == 0.0) ? 1 : col_s); + KthValueVisitor kth_value((qt_ == 0.0) ? 1 : col_s); kth_value.pre(); kth_value(idx_begin, idx_end, column_begin, column_end); @@ -2154,14 +2170,14 @@ struct QuantileVisitor { } else if (policy_ == quantile_policy::mid_point || policy_ == quantile_policy::linear) { - KthValueVisitor kth_value1(int_idx); + KthValueVisitor kth_value1(int_idx); kth_value1.pre(); kth_value1(idx_begin, idx_end, column_begin, column_end); kth_value1.post(); result_ = kth_value1.get_result(); if (need_two && int_idx + 1 < col_s) { - KthValueVisitor kth_value2(int_idx + 1); + KthValueVisitor kth_value2(int_idx + 1); kth_value2.pre(); kth_value2(idx_begin, idx_end, column_begin, column_end); @@ -2175,7 +2191,7 @@ struct QuantileVisitor { } else if (policy_ == quantile_policy::lower_value || policy_ == quantile_policy::higher_value) { - KthValueVisitor kth_value( + KthValueVisitor kth_value( policy_ == quantile_policy::lower_value ? int_idx : (int_idx + 1 < col_s && need_two ? int_idx + 1 : int_idx)); @@ -2202,8 +2218,8 @@ struct QuantileVisitor { const quantile_policy policy_; }; -template -using qt_v = QuantileVisitor; +template +using qt_v = QuantileVisitor; // ---------------------------------------------------------------------------- @@ -2213,18 +2229,22 @@ using qt_v = QuantileVisitor; // The T type must be hashable // Because of the information this has to return, it is not a cheap operation // -template +template struct ModeVisitor { DEFINE_VISIT_BASIC_TYPES + template + using vec_type = std::vector::type>; + struct DataItem { // Value of the column item // const value_type *value { nullptr }; // List of indices where value occurred // - VectorConstPtrView indices { }; + VectorConstPtrView indices { }; // Number of times value occurred // @@ -2232,7 +2252,7 @@ struct ModeVisitor { // List of column indices where value occurred // - std::vector value_indices_in_col { }; + vec_type value_indices_in_col { }; DataItem() = default; inline DataItem(const value_type &v) : value(&v) { @@ -2305,7 +2325,7 @@ struct ModeVisitor { } } - std::vector val_vec; + vec_type val_vec; val_vec.reserve(val_map.size() + 1); if (nan_item.value != nullptr) @@ -2349,18 +2369,16 @@ struct ModeVisitor { result_type result_ { }; }; -template -using mode_v = ModeVisitor; +template +using mode_v = ModeVisitor; // ---------------------------------------------------------------------------- // This calculates 4 different form of Mean Absolute Deviation based on the // requested type input. Please the mad_type enum type // -template::value, T>::type> +template struct MADVisitor { private: @@ -2406,7 +2424,7 @@ struct MADVisitor { const H &column_begin, const H &column_end) { - MedianVisitor median_visitor; + MedianVisitor median_visitor; median_visitor.pre(); median_visitor(idx_begin, idx_end, column_begin, column_end); @@ -2445,8 +2463,8 @@ struct MADVisitor { mean_visitor(idx_value, *(column_begin + i)); mean_visitor.post(); - MedianVisitor median_mean_visitor; - std::vector mean_dists; + MedianVisitor median_mean_visitor; + std::vector::type> mean_dists; mean_dists.reserve(col_s); for (std::size_t i = 0; i < col_s; ++i) @@ -2467,15 +2485,15 @@ struct MADVisitor { const H &column_begin, const H &column_end) { - MedianVisitor median_visitor; + MedianVisitor median_visitor; median_visitor.pre(); median_visitor(idx_begin, idx_end, column_begin, column_end); median_visitor.post(); GET_COL_SIZE - MedianVisitor median_median_visitor; - std::vector median_dists; + MedianVisitor median_median_visitor; + std::vector::type> median_dists; median_dists.reserve(col_s); for (std::size_t i = 0; i < col_s; ++i) @@ -2531,15 +2549,12 @@ struct MADVisitor { result_type result_ { }; }; -template -using mad_v = MADVisitor; +template +using mad_v = MADVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct DiffVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2631,15 +2646,12 @@ struct DiffVisitor { const bool non_zero_; }; -template -using diff_v = DiffVisitor; +template +using diff_v = DiffVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct ZScoreVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2692,8 +2704,8 @@ struct ZScoreVisitor { const bool skip_nan_; }; -template -using zs_v = ZScoreVisitor; +template +using zs_v = ZScoreVisitor; // ---------------------------------------------------------------------------- @@ -2768,10 +2780,7 @@ using szs_v = SampleZScoreVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct SigmoidVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -2862,15 +2871,12 @@ struct SigmoidVisitor { const sigmoid_type sigmoid_type_; }; -template -using sigm_v = SigmoidVisitor; +template +using sigm_v = SigmoidVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct BoxCoxVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3027,15 +3033,12 @@ struct BoxCoxVisitor { static constexpr value_type one_ { 1 }; }; -template -using bcox_v = BoxCoxVisitor; +template +using bcox_v = BoxCoxVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct NormalizeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3074,15 +3077,12 @@ struct NormalizeVisitor { result_type result_ { }; // Normalized }; -template -using norm_v = NormalizeVisitor; +template +using norm_v = NormalizeVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct StandardizeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3120,15 +3120,12 @@ struct StandardizeVisitor { result_type result_ { }; // Standardized }; -template -using stand_v = StandardizeVisitor; +template +using stand_v = StandardizeVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct PolyFitVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3164,7 +3161,7 @@ struct PolyFitVisitor { // Array that will store the values of // sigma(xi), sigma(xi^2), sigma(xi^3) ... sigma(xi^2n) // - std::vector sigma_x (2 * nrows, 0); + result_type sigma_x (2 * nrows, 0); for (size_type i = 0; i < sigma_x.size(); ++i) { // consecutive positions of the array will store @@ -3180,7 +3177,7 @@ struct PolyFitVisitor { // eq_mat is the Normal matrix (augmented) that will store the // equations. The extra column is the y column. // - std::vector eq_mat (nrows * (deg + 2), 0); + result_type eq_mat (nrows * (deg + 2), 0); for (size_type i = 0; i <= deg; ++i) { // Build the Normal matrix by storing the corresponding @@ -3194,7 +3191,7 @@ struct PolyFitVisitor { // Array to store the values of // sigma(yi), sigma(xi * yi), sigma(xi^2 * yi) ... sigma(xi^n * yi) // - std::vector sigma_y (nrows, 0); + result_type sigma_y (nrows, 0); for (size_type i = 0; i < sigma_y.size(); ++i) { // consecutive positions will store @@ -3314,15 +3311,12 @@ struct PolyFitVisitor { weight_func weights_; }; -template -using pfit_v = PolyFitVisitor; +template +using pfit_v = PolyFitVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct LogFitVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3336,7 +3330,7 @@ struct LogFitVisitor { const H &x_begin, const H &x_end, const H &y_begin, const H &y_end) { - std::vector logx (x_begin, x_end); + result_type logx (x_begin, x_end); std::transform(logx.begin(), logx.end(), logx.begin(), (value_type(*)(value_type)) std::log); @@ -3377,20 +3371,17 @@ struct LogFitVisitor { private: result_type y_fits_ { }; - PolyFitVisitor poly_fit_ { }; + PolyFitVisitor poly_fit_ { }; weight_func weights_; value_type residual_ { 0 }; }; -template -using lfit_v = LogFitVisitor; +template +using lfit_v = LogFitVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct ExponentialFitVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3470,15 +3461,12 @@ struct ExponentialFitVisitor { value_type intercept_ { 0 }; }; -template -using efit_v = ExponentialFitVisitor; +template +using efit_v = ExponentialFitVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct LinearFitVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3556,8 +3544,8 @@ struct LinearFitVisitor { value_type intercept_ { 0 }; }; -template -using linfit_v = LinearFitVisitor; +template +using linfit_v = LinearFitVisitor; // ---------------------------------------------------------------------------- @@ -3593,10 +3581,7 @@ using linfit_v = LinearFitVisitor; // and Smoothing Scatterplots". Journal of the American Statistical // Association 74 (368): 829-836. // -template::value, T>::type> +template struct LowessVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -3643,7 +3628,7 @@ struct LowessVisitor { resid_weights_[i] = std::fabs(*(y_begin + i) - *(y_fits_begin + i)); - MedianVisitor median_v; + MedianVisitor median_v; median_v.pre(); median_v(idx_begin, idx_end, @@ -4030,10 +4015,10 @@ struct LowessVisitor { if (sorted_) lowess_(idx_begin, idx_end, y_begin, y_end, x_begin, x_end); else { // Sort x and y in ascending order of x - const size_type col_s = std::distance(x_begin, x_end); - std::vector xvals (x_begin, x_end); - std::vector yvals (y_begin, y_end); - std::vector sorting_idxs (col_s); + const size_type col_s = std::distance(x_begin, x_end); + result_type xvals (x_begin, x_end); + result_type yvals (y_begin, y_end); + result_type sorting_idxs (col_s); std::iota(sorting_idxs.begin(), sorting_idxs.end(), 0); std::sort(sorting_idxs.begin(), sorting_idxs.end(), @@ -4106,15 +4091,12 @@ struct LowessVisitor { static constexpr value_type six_ { 6 }; }; -template -using lowess_v = LowessVisitor; +template +using lowess_v = LowessVisitor; // ---------------------------------------------------------------------------- -template::value, T>::type> +template struct DecomposeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4126,11 +4108,11 @@ struct DecomposeVisitor { do_trend_(const K &idx_begin, const K &idx_end, const H &y_begin, const H &y_end, size_type col_s, - std::vector &xvals) { + result_type &xvals) { std::iota(xvals.begin(), xvals.end(), 0); - LowessVisitor l_v (3, frac_, delta_ * value_type(col_s), true); + LowessVisitor l_v (3, frac_, delta_ * value_type(col_s), true); // Calculate trend // @@ -4143,7 +4125,7 @@ struct DecomposeVisitor { template inline void do_seasonal_(size_type col_s, const K &idx_begin, const K &idx_end, - const std::vector &detrended) { + const result_type &detrended) { StepRollAdopter sr_mean (MEAN(), s_period_); @@ -4185,7 +4167,7 @@ struct DecomposeVisitor { } inline void - do_residual_(const std::vector &detrended, size_type col_s) { + do_residual_(const result_type &detrended, size_type col_s) { // What is left is residual // @@ -4213,14 +4195,14 @@ struct DecomposeVisitor { assert(s_period_ <= col_s / 2); - std::vector xvals (col_s); + result_type xvals (col_s); do_trend_(idx_begin, idx_end, y_begin, y_end, col_s, xvals); // We want to reuse the vector, so just rename it. // This way nobody gets confused // - std::vector &detrended = xvals; + result_type &detrended = xvals; // Remove trend from observations in y // @@ -4288,12 +4270,12 @@ struct DecomposeVisitor { result_type residual_ { }; }; -template -using decom_v = DecomposeVisitor; +template +using decom_v = DecomposeVisitor; // ---------------------------------------------------------------------------- -template +template struct EntropyVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4307,7 +4289,7 @@ struct EntropyVisitor { GET_COL_SIZE - SimpleRollAdopter, T, I> sum_v(SumVisitor(), + SimpleRollAdopter, T, I, A> sum_v(SumVisitor(), roll_count_); sum_v.pre(); @@ -4349,8 +4331,8 @@ struct EntropyVisitor { result_type result_ { }; }; -template -using ent_v = EntropyVisitor; +template +using ent_v = EntropyVisitor; // ---------------------------------------------------------------------------- @@ -4469,11 +4451,11 @@ is_lognormal(const V &column, double epsl) { // ---------------------------------------------------------------------------- -template +template struct BiasVisitor { DEFINE_VISIT_BASIC_TYPES_3 - using avg_type = A; + using avg_type = AV; template inline void @@ -4484,7 +4466,7 @@ struct BiasVisitor { if (roll_period_ == 0 || roll_period_ >= col_s) return; - SimpleRollAdopter avger(std::move(avg_v_), + SimpleRollAdopter avger(std::move(avg_v_), roll_period_); avger.pre(); @@ -4513,12 +4495,12 @@ struct BiasVisitor { result_type result_ { }; }; -template -using bias_v = BiasVisitor; +template +using bias_v = BiasVisitor; // ---------------------------------------------------------------------------- -template +template struct NonZeroRangeVisitor { DEFINE_VISIT_BASIC_TYPES_3 @@ -4564,8 +4546,8 @@ struct NonZeroRangeVisitor { result_type result_ { }; }; -template -using nzr_v = NonZeroRangeVisitor; +template +using nzr_v = NonZeroRangeVisitor; } // namespace hmdf diff --git a/include/DataFrame/DataFrameTransformVisitors.h b/include/DataFrame/DataFrameTransformVisitors.h index b59f3651f..eae9f1703 100644 --- a/include/DataFrame/DataFrameTransformVisitors.h +++ b/include/DataFrame/DataFrameTransformVisitors.h @@ -116,7 +116,7 @@ struct AbsVisitor { // ---------------------------------------------------------------------------- -template +template struct HampelFilterVisitor { public: @@ -125,16 +125,16 @@ struct HampelFilterVisitor { private: - template + template inline void - hampel_(K idx_begin, K idx_end, H column_begin, H column_end, A &&aggr) { + hampel_(K idx_begin, K idx_end, H column_begin, H column_end, AR &&aggr) { aggr.pre(); aggr(idx_begin, idx_end, column_begin, column_end); aggr.post(); GET_COL_SIZE - std::vector diff; + std::vector::type> diff; diff.reserve(col_s); std::transform(aggr.get_result().begin(), aggr.get_result().end(), @@ -169,7 +169,7 @@ struct HampelFilterVisitor { inline void operator() (K idx_begin, K idx_end, H column_begin, H column_end) { - SimpleRollAdopter, T, I> med_v( + SimpleRollAdopter, T, I, A> med_v( MeanVisitor(), window_size_); if (type_ == hampel_type::median) @@ -201,8 +201,8 @@ struct HampelFilterVisitor { result_type count_ { 0 }; }; -template -using hamf_v = HampelFilterVisitor; +template +using hamf_v = HampelFilterVisitor; // ---------------------------------------------------------------------------- diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index ca55d5b73..159bc94d6 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -178,7 +178,7 @@ DataFrame::shuffle(const StlVecType &col_names, template template void DataFrame:: -fill_missing_value_(StlVecType &vec, +fill_missing_value_(ColumnVecType &vec, const T &value, int limit, size_type col_num) { @@ -207,7 +207,7 @@ fill_missing_value_(StlVecType &vec, template template void DataFrame:: -fill_missing_ffill_(StlVecType &vec, int limit, size_type col_num) { +fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num) { const size_type vec_size = vec.size(); @@ -245,7 +245,7 @@ template::value || ! std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_midpoint_(StlVecType &, int, size_type) { +fill_missing_midpoint_(ColumnVecType &, int, size_type) { throw NotFeasible("fill_missing_midpoint_(): ERROR: Mid-point filling is " "not feasible on non-arithmetic types"); @@ -258,7 +258,7 @@ template::value && std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_midpoint_(StlVecType &vec, int limit, size_type) { +fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type) { const size_type vec_size = vec.size(); @@ -291,7 +291,7 @@ fill_missing_midpoint_(StlVecType &vec, int limit, size_type) { template template void DataFrame:: -fill_missing_bfill_(StlVecType &vec, int limit) { +fill_missing_bfill_(ColumnVecType &vec, int limit) { const long vec_size = static_cast(vec.size()); @@ -318,7 +318,7 @@ template::value || ! std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_linter_(StlVecType &, const IndexVecType &, int) { +fill_missing_linter_(ColumnVecType &, const IndexVecType &, int) { throw NotFeasible("fill_missing_linter_(): ERROR: Interpolation is " "not feasible on non-arithmetic types"); @@ -331,7 +331,7 @@ template::value && std::is_arithmetic::value>::type*> void DataFrame:: -fill_missing_linter_(StlVecType &vec, +fill_missing_linter_(ColumnVecType &vec, const IndexVecType &index, int limit) { diff --git a/include/DataFrame/Internals/DataFrame_private_decl.h b/include/DataFrame/Internals/DataFrame_private_decl.h index ebc8b6632..6e4392cb6 100644 --- a/include/DataFrame/Internals/DataFrame_private_decl.h +++ b/include/DataFrame/Internals/DataFrame_private_decl.h @@ -59,39 +59,39 @@ sort_common_(DataFrame &df, CF &&comp_func); template static void -fill_missing_value_(StlVecType &vec, +fill_missing_value_(ColumnVecType &vec, const T &value, int limit, size_type col_num); template static void -fill_missing_ffill_(StlVecType &vec, int limit, size_type col_num); +fill_missing_ffill_(ColumnVecType &vec, int limit, size_type col_num); template::value && std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_midpoint_(StlVecType &vec, int limit, size_type col_num); +fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type col_num); template::value || ! std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_midpoint_(StlVecType &vec, int limit, size_type col_num); +fill_missing_midpoint_(ColumnVecType &vec, int limit, size_type col_num); template static void -fill_missing_bfill_(StlVecType &vec, int limit); +fill_missing_bfill_(ColumnVecType &vec, int limit); template::value && std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_linter_(StlVecType &vec, +fill_missing_linter_(ColumnVecType &vec, const IndexVecType &index, int limit); @@ -100,7 +100,7 @@ template::value || ! std::is_arithmetic::value>::type* = nullptr> static void -fill_missing_linter_(StlVecType &, const IndexVecType &, int); +fill_missing_linter_(ColumnVecType &, const IndexVecType &, int); // Maps row number -> number of missing column(s) using DropRowMap = std::map; From 4f6f5900a7236d3b1661f63be3cc6c88a93d321c Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sat, 24 Dec 2022 12:51:37 -0500 Subject: [PATCH 13/25] Corrected some over use of StlVecType --- include/DataFrame/Internals/DataFrame.tcc | 80 +++++++++---------- include/DataFrame/Internals/DataFrame_set.tcc | 4 +- .../DataFrame/Internals/DataFrame_shift.tcc | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index 159bc94d6..3c82bd93d 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -404,7 +404,7 @@ fill_missing(const StlVecType &col_names, size_type thread_count = 0; for (size_type i = 0; i < count; ++i) { - StlVecType &vec = get_column(col_names[i]); + ColumnVecType &vec = get_column(col_names[i]); if (fp == fill_policy::value) { if (thread_count >= get_thread_level()) @@ -585,10 +585,10 @@ replace(const char *col_name, const StlVecType &new_values, int limit) { - StlVecType &vec = get_column(col_name); + ColumnVecType &vec = get_column(col_name); size_type count = 0; - _replace_vector_vals_, T> + _replace_vector_vals_, T> (vec, old_values, new_values, count, limit); return (count); @@ -617,7 +617,7 @@ template void DataFrame:: replace(const char *col_name, F &functor) { - StlVecType &vec = get_column(col_name); + ColumnVecType &vec = get_column(col_name); const size_type vec_s = vec.size(); for (size_type i = 0; i < vec_s; ++i) @@ -716,7 +716,7 @@ void DataFrame::sort(const char *name, sort_spec dir) { sort_common_(*this, std::move(d)); } else { - const StlVecType &idx_vec = get_column(name); + const ColumnVecType &idx_vec = get_column(name); auto a = [&x = idx_vec](size_type i, size_type j) -> bool { return (x[i] < x[j]); @@ -743,8 +743,8 @@ sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { make_consistent(); - StlVecType *vec1 { nullptr}; - StlVecType *vec2 { nullptr}; + ColumnVecType *vec1 { nullptr}; + ColumnVecType *vec2 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); @@ -791,9 +791,9 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - StlVecType *vec1 { nullptr}; - StlVecType *vec2 { nullptr}; - StlVecType *vec3 { nullptr}; + ColumnVecType *vec1 { nullptr}; + ColumnVecType *vec2 { nullptr}; + ColumnVecType *vec3 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); @@ -859,10 +859,10 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - StlVecType *vec1 { nullptr}; - StlVecType *vec2 { nullptr}; - StlVecType *vec3 { nullptr}; - StlVecType *vec4 { nullptr}; + ColumnVecType *vec1 { nullptr}; + ColumnVecType *vec2 { nullptr}; + ColumnVecType *vec3 { nullptr}; + ColumnVecType *vec4 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); @@ -947,11 +947,11 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - StlVecType *vec1 { nullptr}; - StlVecType *vec2 { nullptr}; - StlVecType *vec3 { nullptr}; - StlVecType *vec4 { nullptr}; - StlVecType *vec5 { nullptr}; + ColumnVecType *vec1 { nullptr}; + ColumnVecType *vec2 { nullptr}; + ColumnVecType *vec3 { nullptr}; + ColumnVecType *vec4 { nullptr}; + ColumnVecType *vec5 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); @@ -1144,7 +1144,7 @@ groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { if (! ::strcmp(col_name, DF_INDEX_COL_NAME)) gb_vec = (const StlVecType *) &(get_index()); else - gb_vec = (const StlVecType *) &(get_column(col_name)); + gb_vec = (const ColumnVecType *) &(get_column(col_name)); StlVecType sort_v (gb_vec->size(), 0); @@ -1191,16 +1191,16 @@ groupby2(const char *col_name1, const StlVecType *gb_vec2 { nullptr }; if (! ::strcmp(col_name1, DF_INDEX_COL_NAME)) { - gb_vec1 = (const StlVecType *) &(get_index()); - gb_vec2 = (const StlVecType *) &(get_column(col_name2)); + gb_vec1 = (const ColumnVecType *) &(get_index()); + gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); } else if (! ::strcmp(col_name2, DF_INDEX_COL_NAME)) { - gb_vec1 = (const StlVecType *) &(get_column(col_name1)); - gb_vec2 = (const StlVecType *) &(get_index()); + gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); + gb_vec2 = (const ColumnVecType *) &(get_index()); } else { - gb_vec1 = (const StlVecType *) &(get_column(col_name1)); - gb_vec2 = (const StlVecType *) &(get_column(col_name2)); + gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); + gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); } StlVecType sort_v (std::min(gb_vec1->size(), @@ -1260,24 +1260,24 @@ groupby3(const char *col_name1, const StlVecType *gb_vec3 { nullptr }; if (! ::strcmp(col_name1, DF_INDEX_COL_NAME)) { - gb_vec1 = (const StlVecType *) &(get_index()); - gb_vec2 = (const StlVecType *) &(get_column(col_name2)); - gb_vec3 = (const StlVecType *) &(get_column(col_name3)); + gb_vec1 = (const ColumnVecType *) &(get_index()); + gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); + gb_vec3 = (const ColumnVecType *) &(get_column(col_name3)); } else if (! ::strcmp(col_name2, DF_INDEX_COL_NAME)) { - gb_vec1 = (const StlVecType *) &(get_column(col_name1)); - gb_vec2 = (const StlVecType *) &(get_index()); - gb_vec3 = (const StlVecType *) &(get_column(col_name3)); + gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); + gb_vec2 = (const ColumnVecType *) &(get_index()); + gb_vec3 = (const ColumnVecType *) &(get_column(col_name3)); } else if (! ::strcmp(col_name3, DF_INDEX_COL_NAME)) { - gb_vec1 = (const StlVecType *) &(get_column(col_name1)); - gb_vec2 = (const StlVecType *) &(get_column(col_name2)); - gb_vec3 = (const StlVecType *) &(get_index()); + gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); + gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); + gb_vec3 = (const ColumnVecType *) &(get_index()); } else { - gb_vec1 = (const StlVecType *) &(get_column(col_name1)); - gb_vec2 = (const StlVecType *) &(get_column(col_name2)); - gb_vec3 = (const StlVecType *) &(get_column(col_name3)); + gb_vec1 = (const ColumnVecType *) &(get_column(col_name1)); + gb_vec2 = (const ColumnVecType *) &(get_column(col_name2)); + gb_vec3 = (const ColumnVecType *) &(get_column(col_name3)); } StlVecType sort_v( @@ -1391,7 +1391,7 @@ template DataFrame> DataFrame::value_counts (const char *col_name) const { - const StlVecType &vec = get_column(col_name); + const ColumnVecType &vec = get_column(col_name); auto hash_func = [](std::reference_wrapper v) -> std::size_t { return(std::hash{}(v.get())); @@ -1517,7 +1517,7 @@ transpose(IndexVecType &&indices, const V &new_col_names) const { "Length of new_col_names is not equal " "to number of rows"); - StlVecType *> current_cols; + StlVecType *> current_cols; current_cols.reserve(num_cols); for (const auto &citer : column_list_) diff --git a/include/DataFrame/Internals/DataFrame_set.tcc b/include/DataFrame/Internals/DataFrame_set.tcc index ffe11d7d4..e81cc0b06 100644 --- a/include/DataFrame/Internals/DataFrame_set.tcc +++ b/include/DataFrame/Internals/DataFrame_set.tcc @@ -690,7 +690,7 @@ append_column (const char *name, Index2D range, nan_policy padding) { - StlVecType &vec = get_column(name); + ColumnVecType &vec = get_column(name); size_type s = std::distance(range.begin, range.end) + vec.size (); const size_type idx_s = indices_.size(); @@ -731,7 +731,7 @@ typename DataFrame::size_type DataFrame:: append_column (const char *name, const T &val, nan_policy padding) { - StlVecType &vec = get_column(name); + ColumnVecType &vec = get_column(name); size_type s = 1; const size_type idx_s = indices_.size(); diff --git a/include/DataFrame/Internals/DataFrame_shift.tcc b/include/DataFrame/Internals/DataFrame_shift.tcc index 4e46fa189..5bdbe78c7 100644 --- a/include/DataFrame/Internals/DataFrame_shift.tcc +++ b/include/DataFrame/Internals/DataFrame_shift.tcc @@ -111,7 +111,7 @@ shift(const char *col_name, size_type periods, shift_policy sp) const { static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call shift()"); - StlVecType result = get_column(col_name); + ColumnVecType result = get_column(col_name); vertical_shift_functor_ functor(periods, sp); functor (result); From 4ee41cf835e7e55e1eeb792db0f2cc1e5b223f2a Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sat, 24 Dec 2022 13:04:48 -0500 Subject: [PATCH 14/25] Corrected some over use of StlVecType 2 --- include/DataFrame/Internals/DataFrame.tcc | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index 3c82bd93d..8b8f668c2 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -747,12 +747,12 @@ sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2) { ColumnVecType *vec2 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); @@ -796,17 +796,17 @@ sort(const char *name1, sort_spec dir1, ColumnVecType *vec3 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); if (! ::strcmp(name3, DF_INDEX_COL_NAME)) - vec3 = reinterpret_cast *>(&indices_); + vec3 = reinterpret_cast *>(&indices_); else vec3 = &(get_column(name3)); @@ -865,22 +865,22 @@ sort(const char *name1, sort_spec dir1, ColumnVecType *vec4 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); if (! ::strcmp(name3, DF_INDEX_COL_NAME)) - vec3 = reinterpret_cast *>(&indices_); + vec3 = reinterpret_cast *>(&indices_); else vec3 = &(get_column(name3)); if (! ::strcmp(name4, DF_INDEX_COL_NAME)) - vec4 = reinterpret_cast *>(&indices_); + vec4 = reinterpret_cast *>(&indices_); else vec4 = &(get_column(name4)); @@ -954,27 +954,27 @@ sort(const char *name1, sort_spec dir1, ColumnVecType *vec5 { nullptr}; if (! ::strcmp(name1, DF_INDEX_COL_NAME)) - vec1 = reinterpret_cast *>(&indices_); + vec1 = reinterpret_cast *>(&indices_); else vec1 = &(get_column(name1)); if (! ::strcmp(name2, DF_INDEX_COL_NAME)) - vec2 = reinterpret_cast *>(&indices_); + vec2 = reinterpret_cast *>(&indices_); else vec2 = &(get_column(name2)); if (! ::strcmp(name3, DF_INDEX_COL_NAME)) - vec3 = reinterpret_cast *>(&indices_); + vec3 = reinterpret_cast *>(&indices_); else vec3 = &(get_column(name3)); if (! ::strcmp(name4, DF_INDEX_COL_NAME)) - vec4 = reinterpret_cast *>(&indices_); + vec4 = reinterpret_cast *>(&indices_); else vec4 = &(get_column(name4)); if (! ::strcmp(name4, DF_INDEX_COL_NAME)) - vec5 = reinterpret_cast *>(&indices_); + vec5 = reinterpret_cast *>(&indices_); else vec5 = &(get_column(name5)); @@ -1142,7 +1142,7 @@ groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { const StlVecType *gb_vec { nullptr }; if (! ::strcmp(col_name, DF_INDEX_COL_NAME)) - gb_vec = (const StlVecType *) &(get_index()); + gb_vec = (const ColumnVecType *) &(get_index()); else gb_vec = (const ColumnVecType *) &(get_column(col_name)); From 6f26f2996853374e508b0a010ed6bbef43b1d63f Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sat, 24 Dec 2022 13:09:40 -0500 Subject: [PATCH 15/25] Corrected some over use of StlVecType 3 --- include/DataFrame/Internals/DataFrame.tcc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index 8b8f668c2..f26da5642 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -1139,7 +1139,7 @@ template DataFrame DataFrame:: groupby1(const char *col_name, I_V &&idx_visitor, Ts&& ... args) const { - const StlVecType *gb_vec { nullptr }; + const ColumnVecType *gb_vec { nullptr }; if (! ::strcmp(col_name, DF_INDEX_COL_NAME)) gb_vec = (const ColumnVecType *) &(get_index()); @@ -1187,8 +1187,8 @@ groupby2(const char *col_name1, I_V &&idx_visitor, Ts&& ... args) const { - const StlVecType *gb_vec1 { nullptr }; - const StlVecType *gb_vec2 { nullptr }; + const ColumnVecType *gb_vec1 { nullptr }; + const ColumnVecType *gb_vec2 { nullptr }; if (! ::strcmp(col_name1, DF_INDEX_COL_NAME)) { gb_vec1 = (const ColumnVecType *) &(get_index()); @@ -1255,9 +1255,9 @@ groupby3(const char *col_name1, I_V &&idx_visitor, Ts&& ... args) const { - const StlVecType *gb_vec1 { nullptr }; - const StlVecType *gb_vec2 { nullptr }; - const StlVecType *gb_vec3 { nullptr }; + const ColumnVecType *gb_vec1 { nullptr }; + const ColumnVecType *gb_vec2 { nullptr }; + const ColumnVecType *gb_vec3 { nullptr }; if (! ::strcmp(col_name1, DF_INDEX_COL_NAME)) { gb_vec1 = (const ColumnVecType *) &(get_index()); From 9597735679eb6910cbdcebc5e79ee739f73e9053 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 25 Dec 2022 12:19:16 -0500 Subject: [PATCH 16/25] Added tests for DataFrame with aligned allocator --- include/DataFrame/DataFrameTypes.h | 3 + include/DataFrame/Internals/DataFrame_set.tcc | 2 +- .../DataFrame/Internals/DataFrame_shift.tcc | 2 +- src/CommonMakefile.mk | 18 +- test/CMakeLists.txt | 43 + test/aligned_dataframe_tester.cc | 5190 +++++++++++++++++ test/aligned_dataframe_tester_2.cc | 4927 ++++++++++++++++ test/dataframe_tester_3.cc | 61 +- 8 files changed, 10201 insertions(+), 45 deletions(-) create mode 100644 test/aligned_dataframe_tester.cc create mode 100644 test/aligned_dataframe_tester_2.cc diff --git a/include/DataFrame/DataFrameTypes.h b/include/DataFrame/DataFrameTypes.h index e15cfc655..bfdcdb6a4 100644 --- a/include/DataFrame/DataFrameTypes.h +++ b/include/DataFrame/DataFrameTypes.h @@ -515,6 +515,9 @@ using StdDataFrame256 = DataFrame>; template using StdDataFrame512 = DataFrame>; +template +using StdDataFrame1024 = DataFrame>; + // ---------------------------------------------------------------------------- inline static const std::vector describe_index_col { diff --git a/include/DataFrame/Internals/DataFrame_set.tcc b/include/DataFrame/Internals/DataFrame_set.tcc index e81cc0b06..1e0fd9c94 100644 --- a/include/DataFrame/Internals/DataFrame_set.tcc +++ b/include/DataFrame/Internals/DataFrame_set.tcc @@ -1037,7 +1037,7 @@ remove_dups_common_(const DataFrame &s_df, } } - StdDataFrame new_df; + DataFrame new_df; IndexVecType new_index (index.size() - rows_to_del.size()); _remove_copy_if_(index.begin(), index.end(), new_index.begin(), diff --git a/include/DataFrame/Internals/DataFrame_shift.tcc b/include/DataFrame/Internals/DataFrame_shift.tcc index 5bdbe78c7..edd12fa58 100644 --- a/include/DataFrame/Internals/DataFrame_shift.tcc +++ b/include/DataFrame/Internals/DataFrame_shift.tcc @@ -179,7 +179,7 @@ rotate(size_type periods, shift_policy sp) const { static_assert(std::is_base_of, DataVec>::value, "Only a StdDataFrame can call rotate()"); - StdDataFrame slug = *this; + DataFrame slug = *this; slug.template self_rotate(periods, sp); return (slug); diff --git a/src/CommonMakefile.mk b/src/CommonMakefile.mk index 8bf1fdaf8..7f72093f0 100644 --- a/src/CommonMakefile.mk +++ b/src/CommonMakefile.mk @@ -11,7 +11,9 @@ PROJECT_INCLUDE_DIR = ../../include # ----------------------------------------------------------------------------- SRCS = ../test/dataframe_tester.cc \ + ../test/aligned_dataframe_tester.cc \ ../test/dataframe_tester_2.cc \ + ../test/aligned_dataframe_tester_2.cc \ ../test/dataframe_tester_3.cc \ ../examples/hello_world.cc \ ../test/dataframe_thread_safety.cc \ @@ -69,7 +71,9 @@ TARGET_LIB = $(LOCAL_LIB_DIR)/lib$(LIB_NAME).a TARGETS += $(TARGET_LIB) \ $(LOCAL_BIN_DIR)/dataframe_tester \ + $(LOCAL_BIN_DIR)/aligned_dataframe_tester \ $(LOCAL_BIN_DIR)/dataframe_tester_2 \ + $(LOCAL_BIN_DIR)/aligned_dataframe_tester_2 \ $(LOCAL_BIN_DIR)/dataframe_tester_3 \ $(LOCAL_BIN_DIR)/hello_world \ $(LOCAL_BIN_DIR)/dataframe_thread_safety \ @@ -137,10 +141,18 @@ DATAFRAME_TESTER_OBJ = $(LOCAL_OBJ_DIR)/dataframe_tester.o $(LOCAL_BIN_DIR)/dataframe_tester: $(TARGET_LIB) $(DATAFRAME_TESTER_OBJ) $(CXX) -o $@ $(DATAFRAME_TESTER_OBJ) $(LIBS) +ALIGNED_DATAFRAME_TESTER_OBJ = $(LOCAL_OBJ_DIR)/aligned_dataframe_tester.o +$(LOCAL_BIN_DIR)/aligned_dataframe_tester: $(TARGET_LIB) $(ALIGNED_DATAFRAME_TESTER_OBJ) + $(CXX) -o $@ $(ALIGNED_DATAFRAME_TESTER_OBJ) $(LIBS) + DATAFRAME_TESTER_OBJ_2 = $(LOCAL_OBJ_DIR)/dataframe_tester_2.o $(LOCAL_BIN_DIR)/dataframe_tester_2: $(TARGET_LIB) $(DATAFRAME_TESTER_OBJ_2) $(CXX) -o $@ $(DATAFRAME_TESTER_OBJ_2) $(LIBS) +ALIGNED_DATAFRAME_TESTER_OBJ_2 = $(LOCAL_OBJ_DIR)/aligned_dataframe_tester_2.o +$(LOCAL_BIN_DIR)/aligned_dataframe_tester_2: $(TARGET_LIB) $(ALIGNED_DATAFRAME_TESTER_OBJ_2) + $(CXX) -o $@ $(ALIGNED_DATAFRAME_TESTER_OBJ_2) $(LIBS) + DATAFRAME_TESTER_OBJ_3 = $(LOCAL_OBJ_DIR)/dataframe_tester_3.o $(LOCAL_BIN_DIR)/dataframe_tester_3: $(TARGET_LIB) $(DATAFRAME_TESTER_OBJ_3) $(CXX) -o $@ $(DATAFRAME_TESTER_OBJ_3) $(LIBS) @@ -197,7 +209,8 @@ clean: $(DATAFRAME_PERFORMANCE_OBJ) $(DATAFRAME_TESTER_OBJ_2) \ $(DATAFRAME_TESTER_OBJ_3) $(HELLO_WORLD_OBJ) \ $(DATAFRAME_PERFORMANCE_2_OBJ) $(DATAFRAME_THREAD_SAFTY_OBJ) \ - $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) + $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) \ + $(ALIGNED_DATAFRAME_TESTER_OBJ) $(ALIGNED_DATAFRAME_TESTER_OBJ_2) clobber: rm -f $(LIB_OBJS) $(TARGETS) $(DATAFRAME_TESTER_OBJ) $(VECTORS_TESTER_OBJ) \ @@ -206,7 +219,8 @@ clobber: $(DATAFRAME_TESTER_OBJ_2) $(DATAFRAME_THREAD_SAFTY_OBJ) \ $(DATAFRAME_TESTER_OBJ_3) $(HELLO_WORLD_OBJ) \ $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) \ - $(DATAFRAME_PERFORMANCE_OBJ) $(DATAFRAME_PERFORMANCE_2_OBJ) + $(DATAFRAME_PERFORMANCE_OBJ) $(DATAFRAME_PERFORMANCE_2_OBJ) \ + $(ALIGNED_DATAFRAME_TESTER_OBJ) $(ALIGNED_DATAFRAME_TESTER_OBJ_2 install_lib: cp -pf $(TARGET_LIB) $(PROJECT_LIB_DIR)/. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 04f94ddd5..8631f8d14 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,21 @@ hmdf_target_data_files(dataframe_tester ) add_test(NAME dataframe_tester COMMAND dataframe_tester) +add_executable(aligned_dataframe_tester aligned_dataframe_tester.cc) +target_link_libraries(aligned_dataframe_tester PRIVATE DataFrame Threads::Threads) +target_compile_options(aligned_dataframe_tester + PRIVATE $<$:/bigobj> +) +hmdf_target_data_files(aligned_dataframe_tester + DATA_FILES + ${PROJECT_SOURCE_DIR}/data/sample_data_dt_index.csv + ${PROJECT_SOURCE_DIR}/data/sample_data_string_index.csv + ${PROJECT_SOURCE_DIR}/data/sample_data.csv + ${PROJECT_SOURCE_DIR}/data/sample_data.json +) +add_test(NAME aligned_dataframe_tester COMMAND aligned_dataframe_tester) + + add_executable(dataframe_tester_2 dataframe_tester_2.cc) target_link_libraries(dataframe_tester_2 PRIVATE DataFrame) target_compile_options(dataframe_tester_2 @@ -39,6 +54,34 @@ if(MSVC) set_tests_properties(dataframe_tester_2 PROPERTIES DISABLED TRUE) endif() +add_executable(aligned_dataframe_tester_2 aligned_dataframe_tester_2.cc) +target_link_libraries(aligned_dataframe_tester_2 PRIVATE DataFrame) +target_compile_options(aligned_dataframe_tester_2 + PRIVATE $<$:/bigobj> +) +hmdf_target_data_files(aligned_dataframe_tester_2 + DATA_FILES + ${PROJECT_SOURCE_DIR}/data/csv2_format_data_2.csv + ${PROJECT_SOURCE_DIR}/data/csv2_format_data_no_index.csv + ${PROJECT_SOURCE_DIR}/data/csv2_format_data.csv + ${PROJECT_SOURCE_DIR}/data/DT_IBM.csv + ${PROJECT_SOURCE_DIR}/data/FORD.csv + ${PROJECT_SOURCE_DIR}/data/IBM.csv + ${PROJECT_SOURCE_DIR}/data/sample_data_2.csv + ${PROJECT_SOURCE_DIR}/data/sample_data_2.json + ${PROJECT_SOURCE_DIR}/data/sample_data_no_index.csv + ${PROJECT_SOURCE_DIR}/data/sample_data_no_index.json + ${PROJECT_SOURCE_DIR}/data/sample_data.csv + ${PROJECT_SOURCE_DIR}/data/sample_data.json + ${PROJECT_SOURCE_DIR}/data/SHORT_IBM.csv +) +add_test(NAME aligned_dataframe_tester_2 COMMAND aligned_dataframe_tester_2) +if(MSVC) + # For some unknown reason to me, this test sigfaults in AppVeyor + set_tests_properties(aligned_dataframe_tester_2 PROPERTIES DISABLED TRUE) +endif() + + add_executable(dataframe_tester_3 dataframe_tester_3.cc) target_link_libraries(dataframe_tester_3 PRIVATE DataFrame) add_test(NAME dataframe_tester_3 COMMAND dataframe_tester_3) diff --git a/test/aligned_dataframe_tester.cc b/test/aligned_dataframe_tester.cc new file mode 100644 index 000000000..968e10e6e --- /dev/null +++ b/test/aligned_dataframe_tester.cc @@ -0,0 +1,5190 @@ +/* +Copyright (c) 2019-2026, Hossein Moein +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +* Neither the name of Hossein Moein and/or the DataFrame nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace hmdf; + +// A DataFrame with ulong index type +// +using MyDataFrame = StdDataFrame128; + +template +using StlVecType = typename MyDataFrame::template StlVecType; + +// ----------------------------------------------------------------------------- + +struct ReplaceFunctor { + + bool operator() (const unsigned int &idx, double &value) { + + if (idx == 20180103) { + value *= 1000.0; + count += 1; + } + else if (idx == 20180115) { + value *= 1000.0; + count += 1; + } + else if (idx == 20180121) { + value *= 1000.0; + count += 1; + } + + return (true); + } + + size_t count { 0 }; +}; + +// ----------------------------------------------------------------------------- + +static void test_haphazard() { + + MyDataFrame::set_thread_level(10); + + std::cout << "\nTesting load_data ..." << std::endl; + + MyDataFrame df; + + df.create_column(static_cast("col_name")); + + StlVecType intvec = { 1, 2, 3, 4, 5 }; + StlVecType dblvec = + { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345 }; + StlVecType dblvec2 = + { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, 0.1 }; + StlVecType strvec = + { "Col_name", "Col_name", "Col_name", "Col_name", "Col_name" }; + StlVecType ulgvec = + { 1UL, 2UL, 3UL, 4UL, 5UL, 8UL, 7UL, 6UL }; + StlVecType xulgvec = ulgvec; + + MyDataFrame::size_type rc = + df.load_data(std::move(ulgvec), + std::make_pair("int_col", intvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("str_col", strvec), + std::make_pair("ul_col", xulgvec)); + + assert(rc == 48); + + df.load_index(ulgvec.begin(), ulgvec.end()); + df.load_column("int_col", { intvec.begin(), intvec.end() }, + nan_policy::pad_with_nans); + df.load_column("str_col", { strvec.begin(), strvec.end() }, + nan_policy::pad_with_nans); + df.load_column("dbl_col", { dblvec.begin(), dblvec.end() }, + nan_policy::pad_with_nans); + df.load_column("dbl_col_2", { dblvec2.begin(), dblvec2.end() }, + nan_policy::dont_pad_with_nans); + + df.append_column("str_col", "Additional column"); + df.append_column("dbl_col", 10.56); + + StlVecType ivec = df.get_column ("int_col"); + + std::cout << std::endl; + assert(df.get_column("int_col") == df.get_column(std::size_t(1))); + assert(df.get_column ("dbl_col")[2] == 3.2345); + + std::cout << "\nTesting Visitors 1 ..." << std::endl; + + MyDataFrame df_dup = df; + MyDataFrame df_dup2(std::move(df)); + + df = std::move(df_dup); + + MeanVisitor ivisitor; + MeanVisitor dvisitor; + MeanVisitor rev_dvisitor; + WeightedMeanVisitor wm_dvisitor; + QuadraticMeanVisitor quad_dvisitor; + const MyDataFrame const_df = df; + auto const_fut = + const_df.visit_async("int_col", ivisitor); + + assert(const_fut.get().get_result() == 1); + + auto fut = df.visit_async("dbl_col", dvisitor); + // auto rev_fut = df.visit_async("dbl_col", rev_dvisitor); + // auto wm_fut = df.visit_async("dbl_col", wm_dvisitor); + // auto quad_fut = df.visit_async("dbl_col", quad_dvisitor); + + assert(abs(fut.get().get_result() - 3.2345) < 0.00001); + + df.get_column("dbl_col")[5] = 6.5; + df.get_column("dbl_col")[6] = 7.5; + df.get_column("dbl_col")[7] = 8.5; + assert(::abs(df.visit("dbl_col", dvisitor).get_result() - + 4.83406) < 0.0001); + assert(::abs(df.visit("dbl_col", rev_dvisitor, true).get_result() - + 4.83406) < 0.0001); + assert(::abs(df.visit("dbl_col", wm_dvisitor).get_result() - + 6.05604) < 0.0001); + assert(::abs(df.visit("dbl_col", quad_dvisitor).get_result() - + 5.39745) < 0.0001); + + StlVecType dvec = df.get_column ("dbl_col"); + StlVecType dvec2 = df.get_column ("dbl_col_2"); + + assert(dvec.size() == 9); + assert(dvec[0] == 1.2345); + assert(dvec[1] == 2.2345); + assert(dvec[3] == 4.2345); + assert(dvec[8] == 10.56); + + assert(dvec2.size() == 8); + assert(dvec2[0] == 0.998); + assert(dvec2[1] == 0.3456); + assert(dvec2[4] == 0.00345); + assert(dvec2[7] == 0.1); + + std::cout << "\nTesting make_consistent ..." << std::endl; + + df.make_consistent(); + df.shrink_to_fit(); + dvec = df.get_column ("dbl_col"); + dvec2 = df.get_column ("dbl_col_2"); + + assert(dvec.size() == 8); + assert(dvec[0] == 1.2345); + assert(dvec[1] == 2.2345); + assert(dvec[3] == 4.2345); + assert(dvec[7] == 8.5); + + assert(dvec2.size() == 8); + assert(dvec2[0] == 0.998); + assert(dvec2[1] == 0.3456); + assert(dvec2[4] == 0.00345); + assert(dvec2[7] == 0.1); + + std::cout << "\nTesting sort 1 ..." << std::endl; + + df.sort + (DF_INDEX_COL_NAME, sort_spec::ascen); + dvec = df.get_column ("dbl_col"); + dvec2 = df.get_column ("dbl_col_2"); + + assert(dvec.size() == 8); + assert(dvec[0] == 1.2345); + assert(dvec[1] == 2.2345); + assert(dvec[3] == 4.2345); + assert(dvec[5] == 8.5); + assert(dvec[7] == 6.5); + + assert(dvec2.size() == 8); + assert(dvec2[0] == 0.998); + assert(dvec2[1] == 0.3456); + assert(dvec2[4] == 0.00345); + assert(dvec2[5] == 0.1); + assert(dvec2[7] == 0.923); + + std::cout << "\nTesting sort 2 ..." << std::endl; + + df.sort("dbl_col_2", sort_spec::desce); + dvec = df.get_column ("dbl_col"); + dvec2 = df.get_column ("dbl_col_2"); + + assert(dvec[0] == 1.2345); + assert(dvec[7] == 5.2345); + + assert(dvec2[0] == 0.998); + assert(dvec2[7] == 0.00345); + + std::cout << "\nTesting sort 3 ..." << std::endl; + + df.sort("dbl_col_2", sort_spec::ascen); + dvec = df.get_column ("dbl_col"); + dvec2 = df.get_column ("dbl_col_2"); + + assert(dvec.size() == 8); + assert(dvec[0] == 5.2345); + assert(dvec[1] == 3.2345); + assert(dvec[3] == 8.5); + assert(dvec[5] == 2.2345); + assert(dvec[7] == 1.2345); + + assert(dvec2.size() == 8); + assert(dvec2[0] == 0.00345); + assert(dvec2[1] == 0.056); + assert(dvec2[4] == 0.15678); + assert(dvec2[5] == 0.3456); + assert(dvec2[7] == 0.998); + + std::cout << "\nTesting get_data_by_idx() ..." << std::endl; + + df.sort + (DF_INDEX_COL_NAME, sort_spec::ascen); + + MyDataFrame df2 = + df.get_data_by_idx( + Index2D { 3, 5 }); + + dvec = df2.get_column ("dbl_col"); + dvec2 = df2.get_column ("dbl_col_2"); + + assert(dvec.size() == 3); + assert(dvec[0] == 3.2345); + assert(dvec[1] == 4.2345); + + assert(dvec2.size() == 3); + assert(dvec2[0] == 0.056); + assert(dvec2[1] == 0.15678); + + std::cout << "\nTesting get_data_by_loc() ..." << std::endl; + + df.sort("dbl_col_2", sort_spec::ascen); + + MyDataFrame df3 = df.get_data_by_loc + (Index2D { 1, 2 }); + + assert(df3.get_index().size() == 1); + assert(df3.get_column("int_col").size() == 1); + assert(df3.get_column("dbl_col").size() == 1); + assert(df3.get_column("dbl_col_2").size() == 1); + assert(df3.get_column("str_col").size() == 1); + assert(df3.get_index()[0] == 3); + assert(df3.get_column("dbl_col")[0] == 3.2345); + assert(df3.get_column("col_name")[0] == 0); + assert(df3.get_column("str_col")[0] == "Col_name"); + + // Printing the second df after get_data_by_loc() ... + + dvec = df3.get_column ("dbl_col"); + dvec2 = df3.get_column ("dbl_col_2"); + + assert(dvec.size() == 1); + assert(dvec[0] == 3.2345); + + assert(dvec2.size() == 1); + assert(dvec2[0] == 0.056); + + std::cout << "\nTesting Correlation Visitor ..." << std::endl; + + CorrVisitor corr_visitor; + CorrVisitor rev_corr_visitor; + auto fut10 = + df.visit_async("dbl_col", "dbl_col_2", corr_visitor); + auto rev_fut10 = + df.visit_async("dbl_col", "dbl_col_2", + rev_corr_visitor, true); + const double corr = fut10.get().get_result(); + const double rev_corr = rev_fut10.get().get_result(); + + assert(fabs(corr - -0.358381) < 0.000001); + assert(fabs(rev_corr - -0.358381) < 0.000001); + + std::cout << "\nTesting Stats Visitor ..." << std::endl; + + StatsVisitor stats_visitor; + + df.visit("dbl_col", stats_visitor); + dvec = df.get_column ("dbl_col"); + assert(fabs(stats_visitor.get_skew() - 0.0396307) < 0.0001); + assert(fabs(stats_visitor.get_kurtosis() - -1.273) < 0.0001); + assert(fabs(stats_visitor.get_mean() - 4.83406) < 0.0001); + assert(fabs(stats_visitor.get_variance() - 6.58781) < 0.0001); + + std::cout << "\nTesting SLRegression Visitor ..." << std::endl; + + SLRegressionVisitor slr_visitor; + + df.visit("dbl_col", "dbl_col_2", slr_visitor); + assert(slr_visitor.get_count() == 8); + assert(fabs(slr_visitor.get_slope() - -0.0561415) < 0.00001); + assert(fabs(slr_visitor.get_intercept() - 0.602674) < 0.00001); + assert(fabs(slr_visitor.get_corr() - -0.358381) < 0.00001); + assert(fabs(df.visit("dbl_col", "dbl_col_2", + corr_visitor).get_result() - + -0.358381) < 0.00001); + + std::cout << "\nTesting GROUPBY ..." << std::endl; + + StlVecType ulgvec2 = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449, + 123448, 123451, 123452, 123452, 123450, 123455, 123450, + 123454, 123453, 123456, 123457, 123458, 123459, 123460, + 123441, 123442, 123432, 123433, 123434, 123435, 123436 }; + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 20, 22, 23, 24, 25, 30, 33, 34, 35, 36, 40, 45, 46 }; + StlVecType xdblvec2 = + { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, + 10.0, 4.25, 0.009, 1.111, 8.0, 2.2222, 3.3333, + 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, + 12.0, 6.25, 2.009, 3.111, 10.0, 4.2222, 5.3333 }; + StlVecType dblvec22 = + { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, + 0.1, 0.0056, 0.07865, -0.9999, 0.0111, 0.1002, -0.8888, + 0.14, 0.0456, 0.078654, -0.8999, 0.01119, 0.8002, -0.9888, + 0.2, 0.1056, 0.87865, -0.6999, 0.4111, 0.1902, -0.4888 }; + StlVecType strvec2 = + { "4% of something", "Description 4/5", "This is bad", + "3.4% of GDP", "Market drops", "Market pulls back", + "$15 increase", "Running fast", "C++14 development", + "Some explanation", "More strings", "Bonds vs. Equities", + "Almost done", "Here comes the sun", "XXXX1", "XXXX04", + "XXXX2", "XXXX3", "XXXX4", "XXXX4", "XXXX5", "XXXX6", + "XXXX7", "XXXX10", "XXXX11", "XXXX01", "XXXX02", "XXXX03" }; + + MyDataFrame dfx; + + dfx.load_data(std::move(ulgvec2), + std::make_pair("xint_col", intvec2), + std::make_pair("dbl_col", xdblvec2), + std::make_pair("dbl_col_2", dblvec22), + std::make_pair("str_col", strvec2), + std::make_pair("ul_col", xulgvec2)); + dfx.write(std::cout); + + std::cout << "\nTesting Async write ..." << std::endl; + + std::future fut2 = + dfx.write_async(std::cout); + + fut2.get(); + + std::cout << "\nTesting Async sort ..." << std::endl; + + auto sf = dfx.sort_async + (DF_INDEX_COL_NAME, sort_spec::ascen, + "str_col", sort_spec::desce); + + sf.get(); + + std::cout << "\nTesting Async sort 2 ..." << std::endl; + + std::future sort_fut = + dfx.sort_async + (DF_INDEX_COL_NAME, sort_spec::ascen); + + sort_fut.get(); + dfx.write(std::cout); + + std::cout << "\nTesting multi_visit() ..." << std::endl; + + MeanVisitor ivisitor2; + MeanVisitor ulvisitor; + MeanVisitor dvisitor2; + MeanVisitor dvisitor22; + + dfx.multi_visit(std::make_pair("xint_col", &ivisitor2), + std::make_pair("dbl_col", &dvisitor2), + std::make_pair("dbl_col_2", &dvisitor22), + std::make_pair("ul_col", &ulvisitor)); + assert(ivisitor2.get_result() == 19); + assert(fabs(dvisitor2.get_result() - 4.5696) < 0.0001); + assert(fabs(dvisitor22.get_result() - 0.0264609) < 0.00001); + assert(ulvisitor.get_result() == 123448); + + const MyDataFrame dfx_c = dfx; + + dfx_c.multi_visit(std::make_pair("xint_col", &ivisitor2), + std::make_pair("dbl_col", &dvisitor2), + std::make_pair("dbl_col_2", &dvisitor22), + std::make_pair("ul_col", &ulvisitor)); + assert(ivisitor2.get_result() == 19); + assert(fabs(dvisitor2.get_result() - 4.5696) < 0.0001); + assert(fabs(dvisitor22.get_result() - 0.0264609) < 0.00001); + assert(ulvisitor.get_result() == 123448); + + MyDataFrame df_copy_con = dfx; + + assert((df_copy_con.is_equal(dfx))); + + df_copy_con.get_column("dbl_col")[7] = 88.888888; + assert(dfx.get_column("dbl_col")[7] == 10.0); + assert( + fabs(df_copy_con.get_column("dbl_col")[7] - 88.888888) < + 0.00001); + assert(! (df_copy_con.is_equal(dfx))); + + std::cout << "dfx before modify_by_idx()" << std::endl; + dfx.write(std::cout); + + dfx.modify_by_idx(df_copy_con); + std::cout << "dfx after modify_by_idx()" << std::endl; + dfx.write(std::cout); + dfx.modify_by_idx(df); + std::cout << "dfx after modify_by_idx()" << std::endl; + dfx.write(std::cout); + + MyDataFrame::set_thread_level(5); + assert(MyDataFrame::get_thread_level() == 5); + MyDataFrame::set_thread_level(0); + assert(MyDataFrame::get_thread_level() == 0); + MyDataFrame::set_thread_level(10); +} + +// ----------------------------------------------------------------------------- + +static void test_read() { + + std::cout << "\nTesting read() ..." << std::endl; + + MyDataFrame df_read; + + try { + std::future fut2 = df_read.read_async("data/sample_data.csv"); + + fut2.get(); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } + df_read.write(std::cout); + + StdDataFrame df_read_str; + + try { + df_read_str.read("data/sample_data_string_index.csv"); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } + df_read_str.write(std::cout); + + StdDataFrame df_read_dt; + + try { + df_read_dt.read("data/sample_data_dt_index.csv"); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } + df_read_dt.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_transpose() { + + std::cout << "\nTesting transpose() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", d4)); + + StlVecType tidx = { 100, 101, 102, 104 }; + StlVecType tcol_names = + { "tcol_1", "tcol_2", "tcol_3", + "tcol_4", "tcol_5", "tcol_6", "tcol_7" }; + MyDataFrame tdf = + df.transpose(std::move(tidx), tcol_names); + + std::cout << "Original DataFrame:" << std::endl; + df.write(std::cout); + std::cout << "Transposed DataFrame:" << std::endl; + tdf.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_get_data_by_loc_slicing() { + + std::cout << "\nTesting get_data_by_loc()/slicing ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", d4)); + + MyDataFrame df2 = df.get_data_by_loc(Index2D { 3, 6 }); + MyDataFrame df3 = df.get_data_by_loc(Index2D { 0, 7 }); + MyDataFrame df4 = df.get_data_by_loc(Index2D { -4, -1 }); + MyDataFrame df5 = df.get_data_by_loc(Index2D { -4, 6 }); + + df.write(std::cout); + df2.write(std::cout); + df3.write(std::cout); + df4.write(std::cout); + df5.write(std::cout); + + try { + MyDataFrame df2 = df.get_data_by_loc(Index2D { 3, 8 }); + } + catch (const BadRange &ex) { + std::cout << "Caught: " << ex.what() << std::endl; + } + try { + MyDataFrame df2 = df.get_data_by_loc(Index2D { -8, -1 }); + } + catch (const BadRange &ex) { + std::cout << "Caught: " << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_remove_column() { + + std::cout << "\nTesting remove_column() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType i1 = { 22, 23, 24, 25 }; + StlVecType s1 = + { "11", "22", "33", "xx", "yy", "gg", "string" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_int", i1), + std::make_pair("col_str", s1)); + + df.write(std::cout); + df.remove_column("col_2"); + std::cout << "After removing column `col_2`" << std::endl; + df.write(std::cout); + df.remove_column("col_str"); + std::cout << "After removing column `col_str`" << std::endl; + df.write(std::cout); + + StlVecType d22 = { 8, 9, 10, 11, 12, 13, 14 }; + + df.load_column("col_2", std::move(d22)); + std::cout << "After adding back column `col_2`" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_rename_column() { + + std::cout << "\nTesting rename_column() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + std::cout << "Before rename" << std::endl; + df.write(std::cout); + df.rename_column("col_2", "renamed_column"); + std::cout << "After rename" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_get_col_unique_values() { + + std::cout << "\nTesting get_col_unique_values() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 0.89, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + df.write(std::cout); + std::cout << "Getting unique values in column col_3" << std::endl; + + const StlVecType result = + df.get_col_unique_values("col_3"); + + for (auto &iter : result) + std::cout << iter << ","; + std::cout << std::endl; +} + +// ----------------------------------------------------------------------------- + +static void test_remove_data_by_idx() { + + std::cout << "\nTesting remove_data_by_idx() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + df.write(std::cout); + std::cout << "After removing by ibdex { 123452, 123460 }" << std::endl; + df.remove_data_by_idx({ 123452, 123460 }); + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_remove_data_by_loc() { + + std::cout << "\nTesting remove_data_by_loc() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + df.write(std::cout); + std::cout << "After removing by ibdex { 3, -3 }" << std::endl; + df.remove_data_by_loc({ 3, -3 }); + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_value_counts() { + + std::cout << "\nTesting value_counts() ..." << std::endl; + + const double my_nan = sqrt(-1); + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 15, 18, 19, 16, 21, my_nan, 0.34, 1.56, 0.34, 2.3, 0.34, + 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + df.write(std::cout); + + auto result = df.value_counts("col_3"); + auto result2 = df.value_counts("col_4"); + auto result3 = df.value_counts(3); + + assert((result2.is_equal(result3))); + std::cout << "After calling value_counts(cols_3)" << std::endl; + result.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_index_inner_join() { + + std::cout << "\nTesting Index Inner Join ..." << std::endl; + + StlVecType idx = + { 123456, 123451, 123452, 123453, 123454, 123455, 123450, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 7, 2, 3, 4, 5, 6, 1, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 14, 9, 10, 11, 12, 13, 8, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 21, 16, 15, 18, 19, 16, 15, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType idx2 = + { 123452, 123453, 123455, 123458, 123466, 223450, 223451, + 223454, 223456, 223457, 223459, 223460, 223462, 223461 }; + StlVecType d12 = + { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 114, 113 }; + StlVecType d22 = + { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, + 130, 131, 11.89, 132 }; + StlVecType d32 = + { 115, 116, 115, 118, 119, 116, 121, + 10.34, 11.56, 10.34, 12.3, 119.0, 10.34 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; + MyDataFrame df2; + + df2.load_data(std::move(idx2), + std::make_pair("xcol_1", d12), + std::make_pair("col_2", d22), + std::make_pair("xcol_3", d32), + std::make_pair("col_4", i12)); + + std::cout << "First DF:" << std::endl; + df.write(std::cout); + std::cout << "Second DF2:" << std::endl; + df2.write(std::cout); + + MyDataFrame join_df = + df.join_by_index + (df2, join_policy::inner_join); + + std::cout << "Now The joined DF:" << std::endl; + join_df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_index_left_join() { + + std::cout << "\nTesting Index Left Join ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType idx2 = + { 123452, 123453, 123455, 123458, 123466, 223450, 223451, + 223454, 223456, 223457, 223459, 223460, 223461, 223462 }; + StlVecType d12 = + { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 113, 114 }; + StlVecType d22 = + { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, + 130, 131, 132, 11.89 }; + StlVecType d32 = + { 115, 116, 115, 118, 119, 116, 121, + 10.34, 11.56, 10.34, 12.3, 10.34, 119.0 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; + MyDataFrame df2; + + df2.load_data(std::move(idx2), + std::make_pair("xcol_1", d12), + std::make_pair("col_2", d22), + std::make_pair("xcol_3", d32), + std::make_pair("col_4", i12)); + + std::cout << "First DF:" << std::endl; + df.write(std::cout); + std::cout << "Second DF2:" << std::endl; + df2.write(std::cout); + + MyDataFrame join_df = + df.join_by_index + (df2, join_policy::left_join); + + std::cout << "Now The joined DF:" << std::endl; + join_df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_index_right_join() { + + std::cout << "\nTesting Index Right Join ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType idx2 = + { 123452, 123453, 123455, 123458, 123466, 223450, 223451, + 223454, 223456, 223457, 223459, 223460, 223461, 223462 }; + StlVecType d12 = + { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 113, 114 }; + StlVecType d22 = + { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, + 130, 131, 132, 11.89 }; + StlVecType d32 = + { 115, 116, 115, 118, 119, 116, 121, + 10.34, 11.56, 10.34, 12.3, 10.34, 119.0 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; + MyDataFrame df2; + + df2.load_data(std::move(idx2), + std::make_pair("xcol_1", d12), + std::make_pair("col_2", d22), + std::make_pair("xcol_3", d32), + std::make_pair("col_4", i12)); + + std::cout << "First DF:" << std::endl; + df.write(std::cout); + std::cout << "Second DF2:" << std::endl; + df2.write(std::cout); + + MyDataFrame join_df = + df.join_by_index + (df2, join_policy::right_join); + + std::cout << "Now The joined DF:" << std::endl; + join_df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_index_left_right_join() { + + std::cout << "\nTesting Index Left Right Join ..." << std::endl; + + StlVecType idx = + { 123466, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123450 }; + StlVecType d1 = { 14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 }; + StlVecType d2 = + { 1.89, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 8 }; + StlVecType d3 = + { 19.0, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 15.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType idx2 = + { 123452, 123453, 123455, 123458, 123466, 223450, 223451, + 223454, 223456, 223457, 223459, 223461, 223460, 223462 }; + StlVecType d12 = + { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 113, 112, 114 }; + StlVecType d22 = + { 18, 19, 110, 111, 112, 113, 114, 120, 122, 123, + 130, 132, 131, 11.89 }; + StlVecType d32 = + { 115, 116, 115, 118, 119, 116, 121, + 10.34, 11.56, 10.34, 10.34, 12.3, 119.0 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; + MyDataFrame df2; + + df2.load_data(std::move(idx2), + std::make_pair("xcol_1", d12), + std::make_pair("col_2", d22), + std::make_pair("xcol_3", d32), + std::make_pair("col_4", i12)); + + std::cout << "First DF:" << std::endl; + df.write(std::cout); + std::cout << "Second DF2:" << std::endl; + df2.write(std::cout); + + MyDataFrame join_df = + df.join_by_index + (df2, join_policy::left_right_join); + + std::cout << "Now The joined DF:" << std::endl; + join_df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_largest_smallest_visitors() { + + std::cout << "\nTesting Largest/Smallest visitors ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + NLargestVisitor<5, double> nl_visitor; + + df.visit("col_3", nl_visitor, true); + std::cout << "N largest result for col_3:" << std::endl; + for (auto iter : nl_visitor.get_result()) + std::cout << iter.index << '|' << iter.value << " "; + std::cout << std::endl; + nl_visitor.sort_by_index(); + std::cout << "N largest result for col_3 sorted by index:" << std::endl; + for (auto iter : nl_visitor.get_result()) + std::cout << iter.index << '|' << iter.value << " "; + std::cout << std::endl; + nl_visitor.sort_by_value(); + std::cout << "N largest result for col_3 sorted by value:" << std::endl; + for (auto iter : nl_visitor.get_result()) + std::cout << iter.index << '|' << iter.value << " "; + std::cout << std::endl; + + NSmallestVisitor<5, double> ns_visitor; + + df.visit("col_3", ns_visitor); + std::cout << "N smallest result for col_3:" << std::endl; + for (auto iter : ns_visitor.get_result()) + std::cout << iter.index << '|' << iter.value << " "; + std::cout << std::endl; + ns_visitor.sort_by_index(); + std::cout << "N smallest result for col_3 sorted by index:" << std::endl; + for (auto iter : ns_visitor.get_result()) + std::cout << iter.index << '|' << iter.value << " "; + std::cout << std::endl; + ns_visitor.sort_by_value(); + std::cout << "N smallest result for col_3 sorted by value:" << std::endl; + for (auto iter : ns_visitor.get_result()) + std::cout << iter.index << '|' << iter.value << " "; + std::cout << std::endl; +} + +// ----------------------------------------------------------------------------- + +static void test_shifting_up_down() { + + std::cout << "\nTesting Shifting Up/Down/Left/Right ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "uuuu", + "iiii", "oooo", "pppp", "2222", "aaaa", "dddd", "ffff" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("dbl_col", d1), + std::make_pair("int_col", i1), + std::make_pair("str_col", s1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + auto sudf = df.shift(3, shift_policy::up); + + std::cout << "Shifted Up DF:" << std::endl; + sudf.write(std::cout); + + auto sddf = df.shift(3, shift_policy::down); + + std::cout << "Shifted Down DF:" << std::endl; + sddf.write(std::cout); + + auto sldf = df.shift(2, shift_policy::left); + + std::cout << "Shifted Left DF:" << std::endl; + sldf.write(std::cout); + + auto srdf = df.shift(2, shift_policy::right); + + std::cout << "Shifted Right DF:" << std::endl; + srdf.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_rotating_up_down() { + + std::cout << "\nTesting Rotating Up/Down/Left/Right ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "uuuu", + "iiii", "oooo", "pppp", "2222", "aaaa", "dddd", "ffff" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("dbl_col", d1), + std::make_pair("int_col", i1), + std::make_pair("str_col", s1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + auto rudf = df.rotate(3, shift_policy::up); + + std::cout << "Rotated Up DF:" << std::endl; + rudf.write(std::cout); + + auto rddf = df.rotate(3, shift_policy::down); + + std::cout << "Rotated Down DF:" << std::endl; + rddf.write(std::cout); + + auto rldf = df.rotate(2, shift_policy::left); + + std::cout << "Rotated Left DF:" << std::endl; + rldf.write(std::cout); + + auto rrdf = df.rotate(2, shift_policy::right); + + std::cout << "Rotated Right DF:" << std::endl; + rrdf.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_dataframe_with_datetime() { + + std::cout << "\nTesting DataFrame with DateTime ..." << std::endl; + + DateTime dt(20010102); + StlVecType idx; + StlVecType d1; + StlVecType i1; + StlVecType s1; + + idx.reserve(20); + d1.reserve(20); + i1.reserve(20); + s1.reserve(20); + for (int i = 0; i < 20; ++i) { + idx.emplace_back(dt); + d1.push_back(i + 0.345689); + i1.push_back(i); + dt.add_days(1); + s1.emplace_back("Test str"); + } + + StdDataFrame128 df; + + df.load_data(std::move(idx), + std::make_pair("dbl_col", d1), + std::make_pair("int_col", i1), + std::make_pair("str_col", s1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_dataframe_friend_plus_operator() { + + std::cout << "\nTesting DataFrame friend plus operator ..." << std::endl; + + MyDataFrame df1; + MyDataFrame df2; + + try { + df1.read("data/sample_data.csv"); + df2.read("data/sample_data.csv"); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } + + MyDataFrame result = + df_plus(df1, df2); + + std::cout << "Original DF1:" << std::endl; + df1.write(std::cout); + std::cout << "Original DF2:" << std::endl; + df2.write(std::cout); + std::cout << "Result DF:" << std::endl; + result.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_dataframe_friend_minus_operator() { + + std::cout << "\nTesting DataFrame friend minus operator ..." << std::endl; + + MyDataFrame df1; + MyDataFrame df2; + + try { + df1.read("data/sample_data.csv"); + df2.read("data/sample_data.csv"); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } + + // Notice I am omitting std::string here, since minus is not defined for + // std::string, and hence it won't compile + MyDataFrame result = + df_minus(df1, df2); + + std::cout << "Original DF1:" << std::endl; + df1.write(std::cout); + std::cout << "Original DF2:" << std::endl; + df2.write(std::cout); + std::cout << "Result DF:" << std::endl; + result.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_dataframe_friend_multiplies_operator() { + + std::cout << "\nTesting DataFrame friend multiplies operator ..." + << std::endl; + + StlVecType idx1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 25, 40, 55 }; + StlVecType idx2 = { 1, 2, 3, 4, 5, 8, 9, 22, 25, 40 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType d2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + StlVecType s1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType s2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + MyDataFrame df1; + MyDataFrame df2; + + df1.load_data(std::move(idx1), + std::make_pair("dbl_col", d1), + std::make_pair("same_name", s1)); + df2.load_data(std::move(idx2), + std::make_pair("dbl_col", d2), + std::make_pair("same_name", s2)); + + MyDataFrame result = df_multiplies(df1, df2); + + std::cout << "Original DF1:" << std::endl; + df1.write(std::cout); + std::cout << "Original DF2:" << std::endl; + df2.write(std::cout); + std::cout << "Result DF:" << std::endl; + result.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_dataframe_friend_divides_operator() { + + std::cout << "\nTesting DataFrame friend divides operator ..." << std::endl; + + StlVecType idx1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 25, 40, 55 }; + StlVecType idx2 = { 1, 2, 3, 4, 5, 8, 9, 22, 25, 40 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType d2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + StlVecType s1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + StlVecType s2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + MyDataFrame df1; + MyDataFrame df2; + + df1.load_data(std::move(idx1), + std::make_pair("dbl_col", d1), + std::make_pair("same_name", s1)); + df2.load_data(std::move(idx2), + std::make_pair("dbl_col", d2), + std::make_pair("same_name", s2)); + + MyDataFrame result = df_divides(df1, df2); + + std::cout << "Original DF1:" << std::endl; + df1.write(std::cout); + std::cout << "Original DF2:" << std::endl; + df2.write(std::cout); + std::cout << "Result DF:" << std::endl; + result.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_fill_missing_values() { + + std::cout << "\nTesting fill_missing(values) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; + + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.fill_missing({ "col_1", "col_2", "col_3" }, + fill_policy::value, + { 1001, 1002, 1003 }, + 3); + df.fill_missing({ "col_str" }, + fill_policy::value, + { "XXXXXX" }); + + std::cout << "After fill missing with values DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_fill_missing_fill_forward() { + + std::cout << "\nTesting fill_missing(fill_forward) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; + + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.fill_missing({ "col_1", "col_2", "col_3" }, + fill_policy::fill_forward, + { }, + 3); + df.fill_missing({ "col_str" }, + fill_policy::fill_forward, + { }, + 3); + + std::cout << "After fill missing with values DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_fill_missing_fill_backward() { + + std::cout << "\nTesting fill_missing(fill_backward) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", + "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1), + std::make_pair("col_4", i1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.fill_missing({ "col_1", "col_2", "col_3" }, + fill_policy::fill_backward); + df.fill_missing({ "col_str" }, fill_policy::fill_backward); + + std::cout << "After fill missing with values DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_fill_missing_fill_linear_interpolation() { + + std::cout << "\nTesting fill_missing(linear_interpolate) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.fill_missing({ "col_1", "col_2", "col_3" }, + fill_policy::linear_interpolate); + + std::cout << "After fill missing with values DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_drop_missing_all_no_drop() { + + std::cout << "\nTesting drop_missing(all) no drop ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", + "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1), + std::make_pair("col_4", i1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.drop_missing(drop_policy::all); + + std::cout << "After drop missing all DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_drop_missing_all_2_drop() { + + std::cout << "\nTesting drop_missing(all) 2 drop ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, + std::numeric_limits::quiet_NaN(), + 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, + std::numeric_limits::quiet_NaN(), + 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "", + "iiii", "oooo", "pppp", "2222", "", "dddd" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1), + std::make_pair("col_4", i1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.drop_missing(drop_policy::all); + + std::cout << "After drop missing all DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_drop_missing_any() { + + std::cout << "\nTesting drop_missing(any) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", + "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1), + std::make_pair("col_4", i1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.drop_missing(drop_policy::any); + + std::cout << "After drop missing all DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_drop_threashold_3() { + + std::cout << "\nTesting drop_missing(threshold=3) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", + "iiii", "oooo", "pppp", "2222", "aaaa", "dddd" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1), + std::make_pair("col_4", i1)); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + df.drop_missing(drop_policy::threshold, 3); + + std::cout << "After drop missing all DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_get_row() { + + std::cout << "\nTesting get_row() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { 400.4, 16, 500.5, 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, 11, 34, 25, + std::numeric_limits::quiet_NaN() }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; + + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); + + StlVecType i2 = { 22, 11 }; + + df.load_column("col_int", + std::move(i2), + nan_policy::dont_pad_with_nans); + + std::cout << "Original DF:" << std::endl; + df.write(std::cout); + + StlVecType columns = + {"col_1", "col_2", "col_3", "col_4", "col_str", "col_int"}; + auto row2 = + df.get_row(2, columns); + + assert(row2.at(0) == 123452); + assert(row2.at(0) == 3.0); + assert(row2.at(1) == 10.0); + assert(row2.at(2) == 500.5); + assert(row2.at(0) == 34); + assert(row2.at(1) == 0); + assert(row2.at(0) == "eeee"); + + auto row3 = df.get_row(3); + + assert(row3.at(0) == 123453); + assert(row3.at(0) == 4.0); + assert(row3.at(1) == 11.0); + assert(row3.at(2) == 18.0); + assert(row3.at(0) == 25); + assert(row3.at(1) == 0); + assert(row3.at(0) == "rrrr"); +} + +// ----------------------------------------------------------------------------- + +static void test_auto_correlation() { + + std::cout << "\nTesting Auto Correlation ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 15, 16, 15, 18, 19, 16, 21, + 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 0.387, + 0.123, 1.06, 0.65, 2.03, 0.4, 1.0, 0.007 }; + StlVecType d2 = + { 1.23, 1.22, 1.21, 1.20, 1.19, 1.185, 1.181, + 1.19, 1.195, 1.189, 1.185, 1.18, 1.181, 1.186, + 1.189, 1.19, 1.194, 1.198, 1.199, 1.197, 1.193 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", i1)); + + AutoCorrVisitor auto_corr; + auto fut = + df.single_act_visit_async("col_1", auto_corr); + const auto &result = fut.get().get_result(); + + assert(result.size() == 17); + assert(result[0] == 1.0); + assert(fabs(result[1] - 0.562001) < 0.00001); + assert(fabs(result[16] - -0.265228) < 0.00001); + assert(fabs(result[6] - 0.388131) < 0.00001); + assert(fabs(result[10] - 0.125514) < 0.00001); + + const auto &result2 = + df.single_act_visit("col_2", auto_corr).get_result(); + + assert(result2.size() == 17); + assert(result2[0] == 1.0); + assert(fabs(result2[1] - 0.903754) < 0.00001); + assert(fabs(result2[16] - 0.183254) < 0.00001); + assert(fabs(result2[6] - -0.263385) < 0.00001); + assert(fabs(result2[10] - -0.712274) < 0.00001); + + const MyDataFrame df_c = df; + + const auto &result3 = + df_c.single_act_visit("col_2", auto_corr).get_result(); + + assert(result3.size() == 17); + assert(result3[0] == 1.0); + assert(fabs(result3[1] - 0.903754) < 0.00001); + assert(fabs(result3[16] - 0.183254) < 0.00001); + assert(fabs(result3[6] - -0.263385) < 0.00001); + assert(fabs(result3[10] - -0.712274) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_return() { + + std::cout << "\nTesting Return ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 0.387, + 0.123, 1.06, 0.65, 2.03, 0.4, 1.0, 0.59 }; + StlVecType d2 = + { 1.23, 1.22, 1.21, 1.20, 1.19, 1.185, 1.181, + 1.19, 1.195, 1.189, 1.185, 1.18, 1.181, 1.186, + 1.189, 1.19, 1.194, 1.198, 1.199, 1.197, 1.193 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", i1)); + + ReturnVisitor return_visit(return_policy::monetary); + const auto &result = + df.single_act_visit("col_1", return_visit).get_result(); + + assert(result.size() == 21); + assert(std::isnan(result[0])); + assert(result[1] == 1.0); + assert(result[2] == -1.0); + assert(result[17] == 1.38); + assert(result[7] == -20.66); + assert(fabs(result[11] - -1.96) < 0.00001); + + ReturnVisitor return_visit2(return_policy::percentage); + const auto &result2 = + df.single_act_visit("col_1", return_visit2).get_result(); + + assert(result2.size() == 21); + assert(std::isnan(result2[0])); + assert(fabs(result2[1] - 0.0666667) < 0.00001); + assert(fabs(result2[2] - -0.0625) < 0.00001); + assert(fabs(result2[17] - 2.12308) < 0.00001); + assert(fabs(result2[7] - -0.98381) < 0.00001); + assert(fabs(result2[11] - -0.852174) < 0.00001); + + ReturnVisitor return_visit3(return_policy::log); + const auto &result3 = + df.single_act_visit("col_1", return_visit3).get_result(); + + assert(result3.size() == 21); + assert(std::isnan(result3[0])); + assert(fabs(result3[1] - 0.0645385) < 0.00001); + assert(fabs(result3[2] - -0.0645385) < 0.00001); + assert(fabs(result3[17] - 1.13882) < 0.00001); + assert(fabs(result3[7] - -4.12333) < 0.00001); + assert(fabs(result3[11] - -1.91172) < 0.00001); + + ReturnVisitor return_visit4(return_policy::trinary); + const auto &result4 = + df.single_act_visit("col_1", return_visit4).get_result(); + + assert(result4.size() == 21); + assert(std::isnan(result4[0])); + assert(result4[1] == 1); + assert(result4[2] == -1); + assert(result4[17] == 1); + assert(result4[7] == -1); + assert(result4[11] == -1); +} + +// ----------------------------------------------------------------------------- + +static void test_median() { + + std::cout << "\nTesting Median ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d2 = + { 1.0, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType i1 = + { 1, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType i2 = + { 1, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7, 5, + 9, 15, 14, 13, 12, 6, 4 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("dblcol_1", d1), + std::make_pair("intcol_1", i1)); + df.load_column("dblcol_2", + std::move(d2), + nan_policy::dont_pad_with_nans); + df.load_column("intcol_2", + std::move(i2), + nan_policy::dont_pad_with_nans); + + MedianVisitor med_visit; + double result = + df.single_act_visit("dblcol_1", med_visit, true).get_result(); + + assert(result == 10.0); + + result = df.single_act_visit("dblcol_2", med_visit).get_result(); + assert(result == 10.50); + + MedianVisitor med_visit2; + int result2 = + df.single_act_visit("intcol_1", med_visit2).get_result(); + + assert(result2 == 10); + + result2 = df.single_act_visit("intcol_2", med_visit2).get_result(); + assert(result2 == 10); +} + +// ----------------------------------------------------------------------------- + +static void test_tracking_error() { + + std::cout << "\nTesting Tracking Error ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d2 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d3 = + { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, + 17.1, 19.9, 3.3, 2.2, 10.8, 7.4, 5.3, + 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; + StlVecType d4 = + { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, + 16.1, 18.9, 2.3, 1.2, 9.8, 6.4, 4.3, + 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; + StlVecType d5 = + { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, + -1.56, 20.1, 25.5, 30.89, 11.1, 7.4, 5.3, + 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("dblcol_1", d1), + std::make_pair("dblcol_2", d2), + std::make_pair("dblcol_3", d3), + std::make_pair("dblcol_4", d4), + std::make_pair("dblcol_5", d5)); + + TrackingErrorVisitor tracking_visit; + double result = + df.visit("dblcol_1", + "dblcol_2", + tracking_visit).get_result(); + + assert(result == 0.0); + + result = df.visit("dblcol_1", + "dblcol_3", + tracking_visit, true).get_result(); + assert(fabs(result - 0.256416) < 0.00001); + + result = df.visit("dblcol_1", + "dblcol_4", + tracking_visit).get_result(); + assert(fabs(result - 0.256416) < 0.00001); + + result = df.visit("dblcol_3", + "dblcol_4", + tracking_visit).get_result(); + assert(result == 0.0); + + result = df.visit("dblcol_2", + "dblcol_4", + tracking_visit).get_result(); + assert(fabs(result - 0.256416) < 0.00001); + + result = df.visit("dblcol_1", + "dblcol_5", + tracking_visit).get_result(); + assert(fabs(result - 17.0566) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_beta() { + + std::cout << "\nTesting Beta ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d2 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d3 = + { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, + 17.1, 19.9, 3.3, 2.2, 10.8, 7.4, 5.3, + 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; + StlVecType d4 = + { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, + 16.1, 18.9, 2.3, 1.2, 9.8, 6.4, 4.3, + 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; + StlVecType d5 = + { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, + -1.56, 20.1, 25.5, 30.89, 11.1, 7.4, 5.3, + 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("dblcol_1", d1), + std::make_pair("dblcol_2", d2), + std::make_pair("dblcol_3", d3), + std::make_pair("dblcol_4", d4), + std::make_pair("dblcol_5", d5)); + + ReturnVisitor return_visit(return_policy::log); + + df.load_column( + "dblcol_1_return", + df.single_act_visit("dblcol_1", return_visit).get_result(), + nan_policy::dont_pad_with_nans); + df.load_column( + "dblcol_2_return", + df.single_act_visit("dblcol_2", return_visit).get_result(), + nan_policy::dont_pad_with_nans); + df.load_column( + "dblcol_3_return", + df.single_act_visit("dblcol_3", return_visit).get_result(), + nan_policy::dont_pad_with_nans); + df.load_column( + "dblcol_4_return", + df.single_act_visit("dblcol_4", return_visit).get_result(), + nan_policy::dont_pad_with_nans); + df.load_column( + "dblcol_5_return", + df.single_act_visit("dblcol_5", return_visit).get_result(), + nan_policy::dont_pad_with_nans); + + BetaVisitor beta_visit; + double result = + df.visit("dblcol_1_return", + "dblcol_2_return", + beta_visit).get_result(); + + assert(result == 1.0); + + result = df.visit("dblcol_1_return", + "dblcol_3_return", + beta_visit).get_result(); + assert(fabs(result - 1.04881) < 0.00001); + + result = df.visit("dblcol_1_return", + "dblcol_4_return", + beta_visit).get_result(); + assert(fabs(result - 0.647582) < 0.00001); + + result = df.visit("dblcol_1_return", + "dblcol_5_return", + beta_visit).get_result(); + assert(fabs(result - -0.128854) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_gen_datetime_index() { + + std::cout << "\nTesting gen_datetime_index() ..." << std::endl; + // I am commenting some of these out because with timezone spec, + // it will take too long for the test to run + + StlVecType idx_vec1 = + MyDataFrame::gen_datetime_index("01/01/2018", + "12/31/2038", + time_frequency::annual, + 1, + DT_TIME_ZONE::AM_NEW_YORK); + + assert(idx_vec1.size() == 21); + assert(idx_vec1.capacity() == 22); + assert(idx_vec1[0] == 20180101); + assert(idx_vec1[1] == 20190101); + assert(idx_vec1[10] == 20280101); + assert(idx_vec1[20] == 20380101); + + /* + idx_vec1 = MyDataFrame::gen_datetime_index("01/01/2018", + "12/31/2038", + time_frequency::monthly, + 3, + DT_TIME_ZONE::AM_NEW_YORK); + assert(idx_vec1.size() == 84); + assert(idx_vec1.capacity() == 86); + assert(idx_vec1[0] == 20180101); + assert(idx_vec1[1] == 20180401); + assert(idx_vec1[2] == 20180701); + assert(idx_vec1[40] == 20280101); + assert(idx_vec1[83] == 20381001); + + idx_vec1 = MyDataFrame::gen_datetime_index("01/01/2018", + "12/31/2038", + time_frequency::weekly, + 4, + DT_TIME_ZONE::AM_NEW_YORK); + assert(idx_vec1.size() == 274); + assert(idx_vec1.capacity() == 274); + assert(idx_vec1[0] == 20180101); + assert(idx_vec1[1] == 20180129); + assert(idx_vec1[2] == 20180226); + assert(idx_vec1[272] == 20381108); + assert(idx_vec1[273] == 20381206); + + idx_vec1 = MyDataFrame::gen_datetime_index("01/01/2018", + "12/31/2038", + time_frequency::daily, + 1, + DT_TIME_ZONE::AM_NEW_YORK); + assert(idx_vec1.size() == 7669); + assert(idx_vec1.capacity() == 7670); + assert(idx_vec1[0] == 20180101); + assert(idx_vec1[1] == 20180102); + assert(idx_vec1[2] == 20180103); + assert(idx_vec1[7667] == 20381229); + assert(idx_vec1[7668] == 20381230); + + idx_vec1 = MyDataFrame::gen_datetime_index("01/01/2018", + "12/31/2022", + time_frequency::hourly, + 1, + DT_TIME_ZONE::AM_NEW_YORK); + assert(idx_vec1.size() == 43800); + assert(idx_vec1.capacity() == 43801); + assert(idx_vec1[0] == 1514782800); + assert(idx_vec1[1] == 1514786400); + assert(idx_vec1[2] == 1514790000); + assert(idx_vec1[43798] == 1672455600); + assert(idx_vec1[43799] == 1672459200); + */ + + idx_vec1 = MyDataFrame::gen_datetime_index("01/01/2018", + "03/31/2018", + time_frequency::secondly, + 10, + DT_TIME_ZONE::AM_NEW_YORK); + assert(idx_vec1.size() == 768600); + assert(idx_vec1.capacity() == 768601); + assert(idx_vec1[0] == 1514782800); + assert(idx_vec1[1] == 1514782810); + assert(idx_vec1[2] == 1514782820); + assert(idx_vec1[768598] == 1522468780); + assert(idx_vec1[768599] == 1522468790); + + idx_vec1 = MyDataFrame::gen_datetime_index( + "01/01/2018 00:00:00.000", + "01/01/2018 10:10:01.600", + time_frequency::millisecondly, + 500, + DT_TIME_ZONE::AM_NEW_YORK); + assert(idx_vec1.size() == 73204); + assert(idx_vec1.capacity() == 73229); + assert(idx_vec1[0] == 1514782800000000000); + assert(idx_vec1[1] == 1514782800500000000); + assert(idx_vec1[2] == 1514782801000000000); + assert(idx_vec1[73201] == 1514819400500000000); + assert(idx_vec1[73202] == 1514819401000000000); + assert(idx_vec1[73203] == 1514819401500000000); + + StlVecType idx_vec2 = + StdDataFrame128::gen_datetime_index( + "01/01/2018", + "12/31/2022", + time_frequency::hourly, + 1, + DT_TIME_ZONE::AM_NEW_YORK); + + assert(idx_vec2.size() == 43800); + assert(idx_vec2[0].string_format (DT_FORMAT::DT_TM2) == + "01/01/2018 00:00:00.000"); + assert(idx_vec2[1].string_format (DT_FORMAT::DT_TM2) == + "01/01/2018 01:00:00.000"); + assert(idx_vec2[2].string_format (DT_FORMAT::DT_TM2) == + "01/01/2018 02:00:00.000"); + assert(idx_vec2[43798].string_format (DT_FORMAT::DT_TM2) == + "12/30/2022 22:00:00.000"); + assert(idx_vec2[43799].string_format (DT_FORMAT::DT_TM2) == + "12/30/2022 23:00:00.000"); +} + +// ----------------------------------------------------------------------------- + +static void test_replace_1() { + + std::cout << "\nTesting replace(1) ..." << std::endl; + + StlVecType d1 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, + 12, 6, 4 }; + StlVecType d2 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, + 12, 6, 4 }; + StlVecType d3 = + { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, 17.1, 19.9, 3.3, 2.2, 10.8, + 7.4, 5.3, 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; + StlVecType d4 = + { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, 16.1, 18.9, 2.3, 1.2, 9.8, + 6.4, 4.3, 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; + StlVecType d5 = + { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, -1.56, 20.1, 25.5, 30.89, + 11.1, 7.4, 5.3, 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; + MyDataFrame df; + + df.load_data(MyDataFrame::gen_datetime_index("01/01/2018", + "01/22/2018", + time_frequency::daily), + std::make_pair("dblcol_1", d1), + std::make_pair("dblcol_2", d2), + std::make_pair("dblcol_3", d3), + std::make_pair("dblcol_4", d4), + std::make_pair("dblcol_5", d5)); + assert(df.get_column("dblcol_1")[0] == 1.0); + assert(df.get_column("dblcol_1")[20] == 4.0); + assert(df.get_column("dblcol_1")[1] == 10.0); + assert(df.get_column("dblcol_1")[2] == 8.0); + assert(df.get_column("dblcol_1")[6] == 21.0); + assert(df.get_column("dblcol_1")[7] == 17.0); + assert(df.get_column("dblcol_1")[11] == 11.0); + assert(df.get_column("dblcol_1")[15] == 15.0); + + assert(df.get_column("dblcol_5")[0] == 20.0); + assert(df.get_column("dblcol_5")[20] == 40.1); + assert(df.get_column("dblcol_5")[1] == 10.1); + assert(df.get_column("dblcol_5")[2] == -30.2); + assert(df.get_column("dblcol_5")[3] == 18.5); + assert(df.get_column("dblcol_5")[10] == 30.89); + assert(df.get_column("dblcol_5")[11] == 11.1); + assert(df.get_column("dblcol_5")[17] == 1.2); + assert(df.get_column("dblcol_5")[19] == 23.2); + + auto result1 = df.replace_async( + "dblcol_1", { 10.0, 21.0, 11.0 }, { 1000.0, 2100.0, 1100.0 }); + + df.replace_index({ 20180101, 20180102, 20180103 }, { 1000, 2100, 1100 }); + + auto result2 = df.replace_async( + "dblcol_5", + { -45.0, -100.0, -30.2, 30.89, 40.1, 1.2 }, + { 0.0, 0.0, 300.0, 210.0, 110.0, 1200.0 }, + 3); + + auto count = result1.get(); + + assert(count == 3); + assert(df.get_column("dblcol_1")[0] == 1.0); + assert(df.get_column("dblcol_1")[20] == 4.0); + assert(df.get_column("dblcol_1")[1] == 1000.0); + assert(df.get_column("dblcol_1")[2] == 8.0); + assert(df.get_column("dblcol_1")[6] == 2100.0); + assert(df.get_column("dblcol_1")[7] == 17.0); + assert(df.get_column("dblcol_1")[11] == 1100.0); + assert(df.get_column("dblcol_1")[15] == 15.0); + + count = result2.get(); + assert(count == 3); + assert(df.get_column("dblcol_5")[0] == 20.0); + assert(df.get_column("dblcol_5")[20] == 110.0); + assert(df.get_column("dblcol_5")[1] == 10.1); + assert(df.get_column("dblcol_5")[2] == 300.0); + assert(df.get_column("dblcol_5")[3] == 18.5); + assert(df.get_column("dblcol_5")[10] == 210.0); + assert(df.get_column("dblcol_5")[11] == 11.1); + assert(df.get_column("dblcol_5")[17] == 1.2); + assert(df.get_column("dblcol_5")[19] == 23.2); +} + +// ----------------------------------------------------------------------------- + +static void test_replace_2() { + + std::cout << "\nTesting replace(2) ..." << std::endl; + + StlVecType d1 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, + 12, 6, 4 }; + StlVecType d2 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, + 12, 6, 4 }; + StlVecType d3 = + { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, 17.1, 19.9, 3.3, 2.2, 10.8, + 7.4, 5.3, 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; + StlVecType d4 = + { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, 16.1, 18.9, 2.3, 1.2, 9.8, + 6.4, 4.3, 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; + StlVecType d5 = + { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, -1.56, 20.1, 25.5, 30.89, + 11.1, 7.4, 5.3, 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; + MyDataFrame df; + + df.load_data(MyDataFrame::gen_datetime_index("01/01/2018", + "01/22/2018", + time_frequency::daily), + std::make_pair("dblcol_1", d1), + std::make_pair("dblcol_2", d2), + std::make_pair("dblcol_3", d3), + std::make_pair("dblcol_4", d4), + std::make_pair("dblcol_5", d5)); + assert(df.get_column("dblcol_1")[0] == 1.0); + assert(df.get_column("dblcol_1")[19] == 6.0); + assert(df.get_column("dblcol_1")[20] == 4.0); + assert(df.get_column("dblcol_1")[2] == 8.0); + assert(df.get_column("dblcol_1")[14] == 9.0); + + ReplaceFunctor functor; + auto result = + df.replace_async("dblcol_1", functor); + + result.get(); + assert(functor.count == 3); + assert(df.get_column("dblcol_1")[0] == 1.0); + assert(df.get_column("dblcol_1")[19] == 6.0); + assert(df.get_column("dblcol_1")[20] == 4000.0); + assert(df.get_column("dblcol_1")[2] == 8000.0); + assert(df.get_column("dblcol_1")[14] == 9000.0); + + auto seq_vec = MyDataFrame::gen_sequence_index(1, 200, 4); + + assert(seq_vec.size() == 50); + assert(seq_vec[0] == 1); + assert(seq_vec[2] == 9); + assert(seq_vec[3] == 13); + assert(seq_vec[49] == 197); + assert(seq_vec[48] == 193); +} + +// ----------------------------------------------------------------------------- + +static void test_some_visitors() { + + std::cout << "\nTesting some visitors ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d2 = + { 1.0, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType i1 = + { 1, 1, 2, 4, 3, 4, 5, 2, 1, 2, 2, 3, 4, 5, 7, 1, 2, 3, 2, 6, 4 }; + StlVecType i2 = + { 1, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d3 = + { 1, 10, std::numeric_limits::quiet_NaN(), 18, 19, 16, + 17, 20, std::numeric_limits::quiet_NaN(), + 2, 11, 7, std::numeric_limits::quiet_NaN(), 5, + 9, 15, 14, 13, 12, 6 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("dblcol_1", d1), + std::make_pair("intcol_1", i1)); + df.load_column("dblcol_2", + std::move(d2), + nan_policy::dont_pad_with_nans); + df.load_column("intcol_2", + std::move(i2), + nan_policy::dont_pad_with_nans); + df.load_column("dblcol_3", + std::move(d3), + nan_policy::dont_pad_with_nans); + + SumVisitor sum_visit; + ProdVisitor prod_visit; + int sum_result = + df.visit("intcol_2", sum_visit).get_result(); + int prod_result = + df.visit("intcol_1", prod_visit).get_result(); + + assert(sum_result == 210); + assert(prod_result == 464486400); + + CumSumVisitor cum_sum_visit; + const StlVecType &cum_sum_result = + df.single_act_visit("dblcol_3", cum_sum_visit).get_result(); + + assert(cum_sum_result.size() == 20); + assert(cum_sum_result[0] == 1); + assert(cum_sum_result[1] == 11); + assert(cum_sum_result[19] == 195); + assert(cum_sum_result[18] == 189); + assert(std::isnan(cum_sum_result[2])); + assert(std::isnan(cum_sum_result[8])); + + CumMaxVisitor cum_max_visit; + const StlVecType &cum_max_result = + df.single_act_visit("dblcol_3", cum_max_visit).get_result(); + + assert(cum_max_result.size() == 20); + assert(cum_max_result[0] == 1); + assert(cum_max_result[1] == 10); + assert(cum_max_result[19] == 20); + assert(cum_max_result[18] == 20); + assert(std::isnan(cum_max_result[2])); + assert(std::isnan(cum_max_result[8])); +} + +// ----------------------------------------------------------------------------- + +static void test_mode() { + + std::cout << "\nTesting Mode ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d2 = + { 1.0, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7.0, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType i1 = + { 1, 1, 2, 4, 3, 4, 5, 2, 1, 2, 2, 3, 4, 5, 7, 1, 2, 3, 2, 6, 4 }; + StlVecType i2 = + { 1, 10, 8, 18, 19, 16, 17, 20, 3, 2, 11, 7, 5, + 9, 15, 14, 13, 12, 6, 4 }; + StlVecType d3 = + { 1, 10, std::numeric_limits::quiet_NaN(), 18, 19, 16, + 17, 20, std::numeric_limits::quiet_NaN(), + 2, 11, 7, std::numeric_limits::quiet_NaN(), 5, + 9, 15, 14, 13, 12, 6 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("dblcol_1", d1), + std::make_pair("intcol_1", i1)); + df.load_column("dblcol_2", + std::move(d2), + nan_policy::dont_pad_with_nans); + df.load_column("intcol_2", + std::move(i2), + nan_policy::dont_pad_with_nans); + df.load_column("dblcol_3", + std::move(d3), + nan_policy::dont_pad_with_nans); + + ModeVisitor<3, double> mode_visit; + const auto &result = + df.single_act_visit("dblcol_3", mode_visit).get_result(); + + assert(result.size() == 3); + assert(result[0].indices.size() == 3); + assert(result[0].value_indices_in_col.size() == 3); + assert(std::isnan(result[0].get_value())); + assert(result[0].repeat_count() == 3); + assert(result[0].indices[1] == 123458); + assert(result[0].value_indices_in_col[2] == 12); + + ModeVisitor<4, int> mode_visit2; + const auto &result2 = + df.single_act_visit("intcol_1", mode_visit2).get_result(); + + assert(result2.size() == 4); + assert(result2[0].indices.size() == 6); + assert(result2[0].value_indices_in_col.size() == 6); + assert(result2[0].repeat_count() == 6); + assert(result2[0].get_value() == 2); + assert(result2[1].repeat_count() == 4); +} + +// ----------------------------------------------------------------------------- + +static void test_remove_data_by_sel() { + + std::cout << "\nTesting remove_data_by_sel() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; + MyDataFrame df; + + auto shape = df.shape(); + + assert(shape.first == 0); + assert(shape.second == 0); + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); + + shape = df.shape(); + assert(shape.first == 7); + assert(shape.second == 5); + + MyDataFrame df2 = df; + + auto functor = + [](const unsigned long &, const double &val)-> bool { + return (val >= 5); + }; + + df.remove_data_by_sel + ("col_1", functor); + + assert(df.get_index().size() == 4); + assert(df.get_column("col_1").size() == 4); + assert(df.get_column("col_str").size() == 4); + assert(df.get_column("col_4").size() == 4); + assert(df.get_index()[0] == 123450); + assert(df.get_index()[2] == 123452); + assert(df.get_column("col_2")[1] == 9); + assert(df.get_column("col_str")[1] == "22"); + assert(df.get_column("col_str")[2] == "33"); + assert(df.get_column("col_1")[1] == 2); + assert(df.get_column("col_1")[2] == 3); + assert(df.get_column("col_4")[3] == 25); + + auto functor2 = + [](const unsigned long &, + const double &val1, + const double &val2, + const std::string val3)-> bool { + return (val1 >= 5 || val2 == 15 || val3 == "33"); + }; + + df2.remove_data_by_sel + ("col_1", "col_3", "col_str", functor2); + + assert(df2.get_index().size() == 2); + assert(df2.get_column("col_1").size() == 2); + assert(df2.get_column("col_str").size() == 2); + assert(df2.get_column("col_4").size() == 2); + assert(df2.get_index()[0] == 123451); + assert(df2.get_index()[1] == 123453); + assert(df2.get_column("col_2")[0] == 9); + assert(df2.get_column("col_2")[1] == 11); + assert(df2.get_column("col_4")[0] == 23); + assert(df2.get_column("col_4")[1] == 25); + assert(df2.get_column("col_str")[0] == "22"); + assert(df2.get_column("col_str")[1] == "ee"); + assert(df2.get_column("col_1")[0] == 2); + assert(df2.get_column("col_1")[1] == 4); +} + +// ----------------------------------------------------------------------------- + +static void test_shuffle() { + + std::cout << "\nTesting shuffle() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "aa", "bb", "cc", "dd" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); + + // std::cout << "Original DatFrasme:" << std::endl; + // df.write(std::cout); + + df.shuffle({"col_1", "col_str"}, false); + // std::cout << "shuffle with no index:" << std::endl; + // df.write(std::cout); + + df.shuffle({"col_2", "col_3"}, true); + // std::cout << "shuffle with index:" << std::endl; + // df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_SimpleRollAdopter() { + + std::cout << "\nTesting SimpleRollAdopter{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, + std::numeric_limits::quiet_NaN(), + 13, 14, + std::numeric_limits::quiet_NaN(), + 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = + { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); + + SimpleRollAdopter, + double, + unsigned long, + 128> min_roller(MinVisitor(), 3); + const auto &result = + df.single_act_visit("col_1", min_roller).get_result(); + + assert(result.size() == 11); + assert(std::isnan(result[0])); + assert(std::isnan(result[1])); + assert(result[2] == 1.0); + assert(result[5] == 4.0); + assert(result[8] == 7.0); + + SimpleRollAdopter, + double, + unsigned long, + 128> mean_roller(MeanVisitor(), 3); + const auto &result2 = + df.single_act_visit("col_3", mean_roller).get_result(); + + assert(result2.size() == 11); + assert(std::isnan(result2[0])); + assert(std::isnan(result2[1])); + assert(result2[2] == 16.0); + assert(result2[5] == 19.0); + assert(result2[8] == 22.0); + + SimpleRollAdopter, + double, + unsigned long, + 128> max_roller(MaxVisitor(), 3); + const auto &result3 = + df.single_act_visit("col_4", max_roller).get_result(); + + assert(result3.size() == 6); + assert(std::isnan(result3[0])); + assert(std::isnan(result3[1])); + assert(result3[2] == 24.0); + assert(result3[4] == 26.0); + assert(result3[5] == 27.0); + + SimpleRollAdopter, + double, + unsigned long, + 128> max2_roller(MaxVisitor(false), 3); + const auto &result4 = + df.single_act_visit("col_2", max2_roller).get_result(); + + assert(result4.size() == 11); + assert(std::isnan(result4[0])); + assert(std::isnan(result4[1])); + assert(result4[2] == 10.0); + assert(result4[3] == 11.0); + assert(std::isnan(result4[4])); + assert(std::isnan(result4[8])); + assert(std::isnan(result4[9])); + assert(result4[10] == 18.0); +} + +// ----------------------------------------------------------------------------- + +static void test_ExponentialRollAdopter() { + + std::cout << "\nTesting ExponentialRollAdopter{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, + std::numeric_limits::quiet_NaN(), + 13, 14, + std::numeric_limits::quiet_NaN(), + 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = + { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); + + ExponentialRollAdopter, + double, + unsigned long, + 128> hl_expo_mean_roller( + MeanVisitor(), 3, exponential_decay_spec::halflife, 0.5); + const auto &hl_expo_result = + df.single_act_visit("col_3", hl_expo_mean_roller).get_result(); + + assert(hl_expo_result.size() == 11); + assert(std::isnan(hl_expo_result[0])); + assert(std::isnan(hl_expo_result[1])); + assert(hl_expo_result[2] == 16.0); + assert(fabs(hl_expo_result[5] - 19.6562) < 0.0001); + assert(fabs(hl_expo_result[8] - 22.6665) < 0.0001); + + ExponentialRollAdopter, + double, + unsigned long, + 128> cg_expo_mean_roller( + MeanVisitor(), + 3, + exponential_decay_spec::center_of_gravity, + 0.5); + const auto &cg_expo_result = + df.single_act_visit("col_3", cg_expo_mean_roller).get_result(); + + assert(cg_expo_result.size() == 11); + assert(std::isnan(cg_expo_result[0])); + assert(std::isnan(cg_expo_result[1])); + assert(cg_expo_result[2] == 16.0); + assert(fabs(cg_expo_result[5] - 19.4815) < 0.0001); + assert(fabs(cg_expo_result[8] - 22.4993) < 0.0001); + + ExponentialRollAdopter, + double, + unsigned long, + 128> s_expo_mean_roller( + MeanVisitor(), 3, exponential_decay_spec::span, 1.5); + const auto &s_expo_result = + df.single_act_visit("col_3", s_expo_mean_roller).get_result(); + + assert(s_expo_result.size() == 11); + assert(std::isnan(s_expo_result[0])); + assert(std::isnan(s_expo_result[1])); + assert(s_expo_result[2] == 16.0); + assert(s_expo_result[5] == 19.744); + assert(fabs(s_expo_result[8] - 22.75) < 0.0001); + + ExponentialRollAdopter, + double, + unsigned long, + 128> f_expo_mean_roller( + MeanVisitor(), 3, exponential_decay_spec::fixed, 0.5); + const auto &f_expo_result = + df.single_act_visit("col_3", f_expo_mean_roller).get_result(); + + assert(f_expo_result.size() == 11); + assert(std::isnan(f_expo_result[0])); + assert(std::isnan(f_expo_result[1])); + assert(f_expo_result[2] == 16.0); + assert(f_expo_result[5] == 19.0); + assert(f_expo_result[8] == 22.0); + + ExponentialRollAdopter, + double, + unsigned long, + 128> expo_mean_roller_3( + MeanVisitor(), 3, exponential_decay_spec::span, 3, 3); + const auto &expo_result_3 = + df.single_act_visit("col_3", expo_mean_roller_3).get_result(); + + assert(expo_result_3.size() == 11); + assert(std::isnan(expo_result_3[0])); + assert(std::isnan(expo_result_3[1])); + assert(expo_result_3[2] == 16.0); + assert(std::fabs(expo_result_3[5] - 18.125) < 0.0001); + assert(std::fabs(expo_result_3[8] - 21.0156) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_ExponentiallyWeightedMeanVisitor() { + + std::cout << "\nTesting ExponentiallyWeightedMeanVisitor{ } ..." + << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, + std::numeric_limits::quiet_NaN(), + 13, 14, + std::numeric_limits::quiet_NaN(), + 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = + { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); + + ewm_v hl_expo_mean_roller(exponential_decay_spec::halflife, 0.5); + const auto &hl_expo_result = + df.single_act_visit("col_3", hl_expo_mean_roller).get_result(); + + assert(hl_expo_result.size() == 11); + assert(hl_expo_result[0] == 15.0); + assert(fabs(hl_expo_result[1] - 15.75) < 0.01); + assert(fabs(hl_expo_result[2] - 16.6875) < 0.0001); + assert(fabs(hl_expo_result[5] - 19.667) < 0.001); + assert(fabs(hl_expo_result[8] - 22.6667) < 0.0001); + + ewm_v cg_expo_mean_roller( + exponential_decay_spec::center_of_gravity, 0.5); + const auto &cg_expo_result = + df.single_act_visit("col_3", cg_expo_mean_roller).get_result(); + + assert(cg_expo_result.size() == 11); + assert(cg_expo_result[0] == 15.0); + assert(fabs(cg_expo_result[1] - 15.6667) < 0.0001); + assert(fabs(cg_expo_result[2] - 16.5556) < 0.0001); + assert(fabs(cg_expo_result[5] - 19.5021) < 0.0001); + assert(fabs(cg_expo_result[8] - 22.5001) < 0.0001); + + ewm_v s_expo_mean_roller(exponential_decay_spec::span, 1.5); + const auto &s_expo_result = + df.single_act_visit("col_3", s_expo_mean_roller).get_result(); + + assert(s_expo_result.size() == 11); + assert(s_expo_result[0] == 15.0); + assert(fabs(s_expo_result[1] - 15.8) < 0.01); + assert(fabs(s_expo_result[2] - 16.76) < 0.001); + assert(fabs(s_expo_result[5] - 19.7501) < 0.0001); + assert(fabs(s_expo_result[8] - 22.75) < 0.001); + + ewm_v f_expo_mean_roller(exponential_decay_spec::fixed, 0.5); + const auto &f_expo_result = + df.single_act_visit("col_3", f_expo_mean_roller).get_result(); + + assert(f_expo_result.size() == 11); + assert(f_expo_result[0] == 15.0); + assert(fabs(f_expo_result[1] - 15.5) < 0.01); + assert(fabs(f_expo_result[2] - 16.25) < 0.001); + assert(fabs(f_expo_result[5] - 19.0312) < 0.0001); + assert(fabs(f_expo_result[8] - 22.0039) < 0.0001); + + ewm_v expo_mean_roller_3(exponential_decay_spec::span, 3); + const auto &expo_result_3 = + df.single_act_visit("col_3", expo_mean_roller_3).get_result(); + + assert(expo_result_3.size() == 11); + assert(expo_result_3[0] == 15.0); + assert(std::fabs(expo_result_3[1] - 15.5) < 0.01); + assert(std::fabs(expo_result_3[2] - 16.25) < 0.001); + assert(std::fabs(expo_result_3[5] - 19.0312) < 0.0001); + assert(std::fabs(expo_result_3[8] - 22.0039) < 0.0001); + + ewm_v expo_mean_roller_3_t(exponential_decay_spec::span, 3, true); + const auto &expo_result_3_t = + df.single_act_visit("col_3", expo_mean_roller_3_t).get_result(); + + assert(expo_result_3_t.size() == 11); + assert(expo_result_3_t[0] == 15.0); + assert(std::fabs(expo_result_3_t[1] - 15.6667) < 0.0001); + assert(std::fabs(expo_result_3_t[2] - 16.4286) < 0.0001); + assert(std::fabs(expo_result_3_t[5] - 19.0952) < 0.0001); + assert(std::fabs(expo_result_3_t[8] - 22.0176) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_get_data_by_rand() { + + std::cout << "\nTesting get_data_by_rand() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = + { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); + + auto result = + df.get_data_by_rand + (random_policy::num_rows_no_seed, 5); + auto result2 = + df.get_data_by_rand + (random_policy::frac_rows_with_seed, 0.8, 23); + + result2.write(std::cout); + + StlVecType idx2 = { 123450 }; + StlVecType d12 = { 1 }; + StlVecType d22 = { 8 }; + StlVecType d32 = { 15 }; + StlVecType d42 = { 22 }; + StlVecType s12 = { "11" }; + MyDataFrame df2; + + df2.load_data(std::move(idx2), + std::make_pair("col_1", d12), + std::make_pair("col_2", d22), + std::make_pair("col_3", d32), + std::make_pair("col_str", s12)); + df2.load_column("col_4", + std::move(d42), + nan_policy::dont_pad_with_nans); + + auto result3 = + df2.get_data_by_rand + (random_policy::num_rows_no_seed, 1); + + result3.write(std::cout); + + StlVecType idx3 = { 123450, 123451 }; + StlVecType d13 = { 1, 2 }; + StlVecType d23 = { 8, 9 }; + StlVecType d33 = { 15, 16 }; + StlVecType d43 = { 22, 23 }; + StlVecType s13 = { "11", "22" }; + MyDataFrame df3; + + df3.load_data(std::move(idx3), + std::make_pair("col_1", d13), + std::make_pair("col_2", d23), + std::make_pair("col_3", d33), + std::make_pair("col_str", s13)); + df3.load_column("col_4", + std::move(d43), + nan_policy::dont_pad_with_nans); + + auto result4 = + df3.get_data_by_rand + (random_policy::num_rows_no_seed, 1); + + result4.write(std::cout); + + StlVecType idx4 = { 123450, 123451, 123452 }; + StlVecType d14 = { 1, 2, 3 }; + StlVecType d24 = { 8, 9, 10 }; + StlVecType d34 = { 15, 16, 17 }; + StlVecType d44 = { 22, 23, 24 }; + StlVecType s14 = { "11", "22", "33" }; + MyDataFrame df4; + + df4.load_data(std::move(idx4), + std::make_pair("col_1", d14), + std::make_pair("col_2", d24), + std::make_pair("col_3", d34), + std::make_pair("col_str", s14)); + df4.load_column("col_4", + std::move(d44), + nan_policy::dont_pad_with_nans); + + auto result5 = + df4.get_data_by_rand + (random_policy::num_rows_no_seed, 1); + + result5.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_write_json() { + + std::cout << "\nTesting write(json) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = + { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", + std::move(d4), + nan_policy::dont_pad_with_nans); + + std::cout << "Writing in JSON:" << std::endl; + df.write(std::cout, + io_format::json); +} + +// ----------------------------------------------------------------------------- + +static void test_diff() { + + std::cout << "\nTesting Diff ..." << std::endl; + + const double my_nan = std::numeric_limits::quiet_NaN(); + const double epsilon = 0.0000001; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { my_nan, 16, 15, 18, my_nan, 16, 21, + 0.34, 1.56, 0.34, 2.3, my_nan, 19.0, 0.387, + 0.123, 1.06, my_nan, 2.03, 0.4, 1.0, my_nan }; + StlVecType d2 = + { 1.23, 1.22, 1.21, 1.20, 1.19, 1.185, 1.181, + 1.19, 1.195, 1.189, 1.185, 1.18, 1.181, 1.186, + 1.189, 1.19, 1.194, 1.198, 1.199, 1.197, 1.193 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", i1)); + + DiffVisitor diff_visit(1, false); + const auto &result = + df.single_act_visit("col_1", diff_visit).get_result(); + + assert(result.size() == 21); + assert(std::isnan(result[0])); + assert(std::isnan(result[1])); + assert(result[2] == -1.0); + assert(result[3] == 3); + assert(std::isnan(result[4])); + assert(std::isnan(result[17])); + assert(result[18] == -1.63); + assert(result[19] == 0.6); + assert(std::isnan(result[20])); + + DiffVisitor diff_visit2(-1, false); + const auto &result2 = + df.single_act_visit("col_1", diff_visit2).get_result(); + + assert(result2.size() == 21); + assert(std::isnan(result2[0])); + assert(result2[1] == 1.0); + assert(result2[2] == -3); + assert(std::isnan(result2[4])); + assert(std::isnan(result2[16])); + assert(result2[17] == 1.63); + assert(result2[18] == -0.6); + assert(std::isnan(result2[19])); + assert(std::isnan(result2[20])); + + DiffVisitor diff_visit3(3, false); + const auto &result3 = + df.single_act_visit("col_1", diff_visit3).get_result(); + + assert(result3.size() == 21); + assert(std::isnan(result3[0])); + assert(std::isnan(result3[1])); + assert(std::isnan(result3[2])); + assert(std::isnan(result3[4])); + assert(result3[5] == 1.0); + assert(result3[6] == 3.0); + assert(std::isnan(result3[7])); + assert(std::isnan(result3[16])); + assert(fabs(result3[17] - 1.907) < epsilon); + assert(result3[18] == -0.66); + assert(std::isnan(result3[19])); + assert(std::isnan(result3[20])); + + DiffVisitor diff_visit4(-3, false); + const auto &result4 = + df.single_act_visit("col_1", diff_visit4).get_result(); + + assert(result4.size() == 21); + assert(std::isnan(result4[0])); + assert(std::isnan(result4[1])); + assert(result4[2] == -1.0); + assert(result4[3] == -3.0); + assert(std::isnan(result4[4])); + assert(std::isnan(result4[13])); + assert(fabs(result4[14] - -1.907) < epsilon); + assert(result4[15] == 0.66); + assert(std::isnan(result4[16])); + assert(std::isnan(result4[17])); + assert(std::isnan(result4[18])); + assert(std::isnan(result4[19])); + assert(std::isnan(result4[20])); + + DiffVisitor diff_visit5(3, true); + const auto &result5 = + df.single_act_visit("col_1", diff_visit5).get_result(); + + assert(result5.size() == 10); + assert(result5[0] == 1.0); + assert(result5[1] == 3.0); + assert(result5[2] == -14.44); + assert(result5[7] == -17.94); + assert(fabs(result5[8] - 1.907) < epsilon); + assert(result5[9] == -0.66); + + DiffVisitor diff_visit6(-3, true); + const auto &result6 = + df.single_act_visit("col_1", diff_visit6).get_result(); + + assert(result6.size() == 10); + assert(result6[0] == -1.0); + assert(result6[1] == -3.0); + assert(result6[2] == 14.44); + assert(result6[7] == 17.94); + assert(fabs(result6[8] - -1.907) < epsilon); + assert(result6[9] == 0.66); +} + +// ----------------------------------------------------------------------------- + +static void test_reading_writing_json() { + + std::cout << "\nTesting reading/writing JSON ..." << std::endl; + + MyDataFrame df; + + try { + df.read("data/sample_data.json", io_format::json); + assert(df.get_index().size() == 12); + assert(df.get_index()[0] == 123450); + assert(df.get_index()[4] == 123454); + assert(df.get_index()[11] == 555555); + assert(df.get_column("col_4").size() == 6); + assert(df.get_column("col_4")[0] == 22.0); + assert(df.get_column("col_4")[4] == 26.0); + assert(df.get_column("col_4")[5] == 27.0); + assert(df.get_column("col_str").size() == 12); + assert(df.get_column("col_str")[0] == "11"); + assert(df.get_column("col_str")[8] == "uu"); + assert(df.get_column("col_str")[11] == "This is a test"); + assert(df.get_column("col_1").size() == 12); + assert(df.get_column("col_2").size() == 12); + assert(df.get_column("col_2")[6] == 14.0); + assert(df.get_column("col_2")[11] == 777.78); + assert(df.get_column("col_3").size() == 12); + assert(df.get_column("col_3")[3] == 18.0); + assert(df.get_column("col_3")[11] == 555.543); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_get_data_by_loc_location() { + + std::cout << "\nTesting get_data_by_loc(locations) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", d4)); + + MyDataFrame df2 = df.get_data_by_loc(StlVecType { 3, 6 }); + MyDataFrame df3 = + df.get_data_by_loc(StlVecType { -4, -1 , 5 }); + + assert(df2.get_index().size() == 2); + assert(df2.get_column("col_3").size() == 2); + assert(df2.get_column("col_2").size() == 2); + assert(df2.get_index()[0] == 123450); + assert(df2.get_index()[1] == 123449); + assert(df2.get_column("col_3")[0] == 18.0); + assert(df2.get_column("col_2")[1] == 14.0); + assert(std::isnan(df2.get_column("col_4")[1])); + + assert(df3.get_index().size() == 3); + assert(df3.get_column("col_3").size() == 3); + assert(df3.get_column("col_2").size() == 3); + assert(df3.get_column("col_1").size() == 3); + assert(df3.get_index()[0] == 123450); + assert(df3.get_index()[1] == 123449); + assert(df3.get_index()[2] == 123450); + assert(df3.get_column("col_1")[0] == 4.0); + assert(df3.get_column("col_2")[2] == 13.0); + assert(df3.get_column("col_4")[0] == 25.0); + assert(std::isnan(df3.get_column("col_4")[1])); + assert(std::isnan(df3.get_column("col_4")[2])); +} + +// ----------------------------------------------------------------------------- + +static void test_get_data_by_idx_values() { + + std::cout << "\nTesting get_data_by_idx(values) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", d4)); + + MyDataFrame df2 = + df.get_data_by_idx( + StlVecType { 123452, 123455 }); + MyDataFrame df3 = + df.get_data_by_idx( + StlVecType { 123449, 123450 }); + + assert(df2.get_index().size() == 2); + assert(df2.get_column("col_3").size() == 2); + assert(df2.get_column("col_2").size() == 2); + assert(df2.get_index()[0] == 123452); + assert(df2.get_index()[1] == 123455); + assert(df2.get_column("col_3")[0] == 17.0); + assert(df2.get_column("col_2")[1] == 12.0); + assert(std::isnan(df2.get_column("col_4")[1])); + + assert(df3.get_index().size() == 4); + assert(df3.get_column("col_3").size() == 4); + assert(df3.get_column("col_2").size() == 4); + assert(df3.get_column("col_1").size() == 4); + assert(df3.get_index()[0] == 123450); + assert(df3.get_index()[1] == 123450); + assert(df3.get_index()[2] == 123450); + assert(df3.get_index()[3] == 123449); + assert(df3.get_column("col_1")[0] == 1.0); + assert(df3.get_column("col_2")[2] == 13.0); + assert(df3.get_column("col_4")[0] == 22.0); + assert(df3.get_column("col_4")[1] == 25.0); + assert(std::isnan(df3.get_column("col_4")[2])); + assert(std::isnan(df3.get_column("col_4")[3])); +} + +// ----------------------------------------------------------------------------- + +static void test_z_score_visitor() { + + std::cout << "\nTesting Z-Score visitors ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 99.00011, 99.00012, 99.00013, 99.00014, 99.00015, 99.00016, + 99.000113, 99.000112, 99.000111, 99.00019, 99.00018, 99.00017, + 99.000114, 99.000115, 99.000116, 99.000117, 99.000118, 99.000119, + 99.0001114, 99.0001113, 99.0001112 }; + StlVecType d2 = + { 10.1, 20.1, 30.1, 40.1, 50.1, 60.1, 70.1, + 120.1, 110.1, 28.1, 18.1, 100.1, 90.1, 80.1, + 130.1, 140.1, 150.1, 160.1, 170.1, 180.1, 190.1 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2)); + + ZScoreVisitor z_score; + ZScoreVisitor z_score2; + const auto result = + df.single_act_visit("col_1", z_score).get_result(); + const auto result2 = + df.single_act_visit("col_2", z_score2).get_result(); + + assert(result.size() == 21); + assert(fabs(result[0] - -0.774806) < 0.000001); + assert(fabs(result[4] - 0.816872) < 0.000001); + assert(fabs(result[10] - 2.01063) < 0.000001); + assert(fabs(result[19] - -0.723076) < 0.000001); + assert(fabs(result[20] - -0.727055) < 0.000001); + + assert(result2.size() == 21); + assert(fabs(result2[0] - -1.42003) < 0.00001); + assert(fabs(result2[4] - -0.732921) < 0.00001); + assert(fabs(result2[10] - -1.28261) < 0.00001); + assert(fabs(result2[19] - 1.5002) < 0.00001); + assert(fabs(result2[20] - 1.67198) < 0.00001); + + const MyDataFrame const_df = df; + SampleZScoreVisitor z_score3; + auto fut = + const_df.single_act_visit_async + ("col_1", "col_2", z_score3); + auto result3 = fut.get().get_result(); + + assert(fabs(result3 - -1136669.1600501483772) < 0.000001); + result3 = + df.single_act_visit("col_2", + "col_2", + z_score3).get_result(); + assert(result3 == 0.0); +} + +// ----------------------------------------------------------------------------- + +static void test_thread_safety() { + + std::cout << "\nTesting Thread safety ..." << std::endl; + + const size_t vec_size = 100000; + +#ifdef _MSC_VER + auto do_work = [vec_size]() { +#else + auto do_work = []() { +#endif // _MSC_VER + MyDataFrame df; + StlVecType vec; + + for (size_t i = 0; i < vec_size; ++i) + vec.push_back(i); + df.load_data(MyDataFrame::gen_sequence_index( + 0, + static_cast(vec_size), + 1), + std::make_pair("col1", vec)); + + auto functor = + [](const unsigned long &, const size_t &val)-> bool { + return (val < size_t(100001)); + }; + auto df2 = + df.get_data_by_sel + ("col1", functor); + + // This is an extremely inefficient way of doing it, especially in + // a multithreaded program. Each “get_column” is a hash table + // look up and in multithreaded programs requires a lock. + // It is much more efficient to call “get_column” outside the loop + // and loop over the referenced vector. + // Here I am doing it this way to make sure synchronization + // between threads are bulletproof. + // + for (size_t i = 0; i < vec_size; ++i) { + const size_t j = df2.get_column("col1")[i]; + + assert(i == j); + } + df.shrink_to_fit(); + df2.shrink_to_fit(); + }; + + SpinLock lock; + StlVecType thr_vec; + + MyDataFrame::set_lock(&lock); + + for (size_t i = 0; i < 20; ++i) + thr_vec.push_back(std::thread(do_work)); + for (size_t i = 0; i < 20; ++i) + thr_vec[i].join(); + + MyDataFrame::remove_lock(); +} + +// ----------------------------------------------------------------------------- + +static void test_view_visitors() { + + std::cout << "\nTesting View visitors ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL, 8UL, 9UL, 10UL }; + StlVecType dblvec1 = { 1.1, 2.2, 3.3, 4.4, 5.5 }; + StlVecType dblvec2 = { 2.2, 3.3, 4.4, 5.5, 6.6 }; + StlVecType dblvec3 = + { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 }; + StlVecType dblvec4 = + { 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1 }; + StlVecType dblvec5 = + { 1.1, 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1, 10.1 }; + StlVecType dblvec6 = { 1.1, 1.1, 3.3, 3.3, 1.1 }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col1", dblvec1), + std::make_pair("dbl_col2", dblvec2), + std::make_pair("dbl_col3", dblvec3), + std::make_pair("dbl_col4", dblvec4), + std::make_pair("dbl_col5", dblvec5), + std::make_pair("dbl_col6", dblvec6)); + + typedef StdDataFrame128::View MyDataFrameView; + + MyDataFrameView dfv = + df.get_view_by_idx(Index2D { 2, 4 }); + assert(dfv.get_index().size() == 3); + MeanVisitor mean_visitor; + assert(fabs(dfv.visit("dbl_col1", + mean_visitor).get_result() - 3.3) < 0.00001); + + DotProdVisitor dp_visitor; + assert(fabs(dfv.visit("dbl_col1", "dbl_col2", + dp_visitor).get_result() - 45.98) < 0.00001); + + SimpleRollAdopter, double, unsigned long, 128> + mean_roller1(MeanVisitor(), 3); + const auto &res_sra = + dfv.single_act_visit("dbl_col1", + mean_roller1, + true).get_result(); + + assert(fabs(res_sra[2] - 3.3) < 0.00001); + + SimpleRollAdopter, double, unsigned long, 128> + geo_mean_roller(GeometricMeanVisitor(), 3); + const auto &res_srga = + df.single_act_visit("dbl_col4", geo_mean_roller).get_result(); + + assert(fabs(res_srga[2] - 2.96098) < 0.00001); + assert(fabs(res_srga[6] - 5.25368) < 0.00001); + + SimpleRollAdopter, double, unsigned long, 128> + har_mean_roller(HarmonicMeanVisitor(), 3); + const auto &res_srha = + df.single_act_visit("dbl_col4", har_mean_roller).get_result(); + + assert(fabs(res_srha[2] - 2.14782) < 0.00001); + assert(fabs(res_srha[6] - 5.0785) < 0.00001); + + CumSumVisitor cs_visitor; + const auto &res_cs = + dfv.single_act_visit("dbl_col1", cs_visitor).get_result(); + assert(fabs(res_cs[0] - 2.2) < 0.00001); + assert(fabs(res_cs[1] - 5.5) < 0.00001); + assert(fabs(res_cs[2] - 9.9) < 0.00001); + + CumProdVisitor cp_visitor; + const auto &res_cp = + dfv.single_act_visit("dbl_col1", cp_visitor).get_result(); + assert(fabs(res_cp[0] - 2.2) < 0.00001); + assert(fabs(res_cp[1] - 7.26) < 0.00001); + assert(fabs(res_cp[2] - 31.944) < 0.00001); + + CumMinVisitor cmin_visitor; + const auto &res_cmin = + dfv.single_act_visit("dbl_col1", cmin_visitor).get_result(); + assert(fabs(res_cmin[0] - 2.2) < 0.00001); + assert(fabs(res_cmin[1] - 2.2) < 0.00001); + assert(fabs(res_cmin[2] - 2.2) < 0.00001); + + CumMaxVisitor cmax_visitor; + const auto &res_cmax = + dfv.single_act_visit("dbl_col1", cmax_visitor).get_result(); + assert(fabs(res_cmax[0] - 2.2) < 0.00001); + assert(fabs(res_cmax[1] - 3.3) < 0.00001); + assert(fabs(res_cmax[2] - 4.4) < 0.00001); + + MyDataFrameView dfv2 = + df.get_view_by_idx(Index2D { 2, 9 }); + + AutoCorrVisitor ac_visitor; + const auto &res_ac = + dfv2.single_act_visit("dbl_col5", ac_visitor).get_result(); + assert(fabs(res_ac[1] - -0.36855) < 0.00001); + // assert(fabs(res_ac[5] - 0.67957) < 0.0001); + + ReturnVisitor ret_visitor(return_policy::monetary); + const auto &res_ret = + df.single_act_visit("dbl_col4", ret_visitor).get_result(); + assert(std::isnan(res_ret[0])); + assert(fabs(res_ret[1] - -1.5) < 0.00001); + assert(fabs(res_ret[7] - 0.3) < 0.00001); + + MedianVisitor med_visitor; + const auto &res_med = + dfv2.single_act_visit("dbl_col3", med_visitor).get_result(); + assert(fabs(res_med - 4.95) < 0.00001); + + ModeVisitor<2, double> mode_visitor; + const auto &res_mode = + dfv2.single_act_visit("dbl_col6", mode_visitor).get_result(); + assert(fabs(res_mode[1].get_value() - 3.3) < 0.00001); + + DiffVisitor diff_visitor(1); + const auto &res_diff = + dfv.single_act_visit("dbl_col1", diff_visitor).get_result(); + assert(res_diff.size() == 2); + assert(fabs(res_diff[0] - 1.1) < 0.00001); + assert(fabs(res_diff[1] - 1.1) < 0.00001); + + ZScoreVisitor zs_visitor; + const auto &res_zs = + dfv2.single_act_visit("dbl_col5", zs_visitor).get_result(); + assert(fabs(res_zs[2] - -1.61418) < 0.00001); + assert(fabs(res_zs[4] - 0.04336) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +struct Point { + + double x { 0.0 }; + double y { 0.0 }; + + Point() = default; + Point(double xx, double yy) : x(xx), y(yy) { } + Point(const Point &) = default; + Point &operator = (const Point &) = default; + + friend Point operator + (const Point &lhs, const Point &rhs) { + + return (Point(lhs.x + rhs.x, lhs.y + rhs.y)); + } + friend Point operator / (const Point &lhs, double rhs) { + + return (Point(lhs.x / rhs, lhs.y / rhs)); + } + + template + friend S &operator << (S &s, const Point &rhs) { + + return (s << rhs.x << ", " << rhs.y); + } +}; + +static double point_distance(const Point &lhs, const Point &rhs) { + + return ((lhs.x - rhs.x) * (lhs.x - rhs.x) + + (lhs.y - rhs.y) * (lhs.y - rhs.y)); +} + +static void test_k_means() { + + std::cout << "\nTesting k-means visitor ..." << std::endl; + + const size_t item_cnt = 1024; + MyDataFrame df; + RandGenParams p; + + p.mean = 1.0; // Default + p.std = 0.005; + p.seed = 10; + + df.load_data(MyDataFrame::gen_sequence_index(0, item_cnt, 1), + std::make_pair("col1", + gen_lognormal_dist(item_cnt, p))); + + KMeansVisitor<5, double, unsigned long, 128> km_visitor(1000); + + df.single_act_visit("col1", km_visitor); + + const auto &col1 = df.get_column("col1"); + // Using the calculated means, separate the given column into clusters + const auto clusters = + km_visitor.get_clusters(df.get_index().begin(), df.get_index().end(), + col1.begin(), col1.end()); +/* + bool found = false; + + for (auto iter : clusters) { + if (::fabs(iter[0] - 1.89348) < 0.00001) { + if (::fabs(iter[6] - 1.44231) < 0.00001) { + found = true; + break; + } + } + } + assert(found); + found = false; + for (auto iter : clusters) { + if (::fabs(iter[0] - 0.593126) < 0.00001) { + if (::fabs(iter[2] - 0.950026) < 0.00001) { + found = true; + break; + } + } + } + assert(found); + found = false; + for (auto iter : clusters) { + if (::fabs(iter[0] - 14.2245) < 0.0001) { + found = true; + break; + } + } + assert(found); + found = false; + for (auto iter : clusters) { + if (::fabs(iter[0] - 6.90427) < 0.00001) { + found = true; + break; + } + } + assert(found); + found = false; + for (auto iter : clusters) { + if (::fabs(iter[0] - 3.8146) < 0.00001) { + found = true; + break; + } + } + assert(found); +*/ + + // Now try with Points + // + p.seed = 200; + + auto x_vec = gen_lognormal_dist(item_cnt, p); + + p.seed = 4356; + + auto y_vec = gen_lognormal_dist(item_cnt, p); + StlVecType points; + + points.reserve(item_cnt); + for (size_t i = 0; i < item_cnt; ++i) + points.push_back(Point(x_vec[i], y_vec[i])); + df.load_column("point_col", std::move(points)); + + KMeansVisitor<5, + Point, + unsigned long, + 128> km_visitor2(1000, point_distance); + + df.single_act_visit("point_col", km_visitor2); + + // Using the calculated means, separate the given column into clusters + const auto &point_col = df.get_column("point_col"); + const auto clusters2 = + km_visitor2.get_clusters(df.get_index().begin(), df.get_index().end(), + point_col.begin(), point_col.end()); + + for (auto iter : clusters2) { + for (auto iter2 : iter) { + std::cout << iter2.x << " | " << iter2.y << ", "; + } + std::cout << "\n\n" << std::endl; + } + +/* + found = false; + for (auto iter : clusters2) { + if (::fabs(iter[0].x - 18.9556) < 0.1 && + ::fabs(iter[0].y - 2.17537) < 0.1) { + if (::fabs(iter[6].x - 16.7309) < 0.1 && + ::fabs(iter[6].y - 0.872376) < 0.1) { + found = true; + break; + } + } + } + assert(found); +*/ +/* + found = false; + for (auto iter : clusters2) { + if (::fabs(iter[0].x - 0.943977) < 0.1 && + ::fabs(iter[0].y - 0.910989) < 0.1) { + if (::fabs(iter[2].x - 0.30509) < 0.1 && + ::fabs(iter[2].y - 1.69017) < 0.1) { + found = true; + break; + } + } + } + assert(found); + found = false; + for (auto iter : clusters2) { + if (::fabs(iter[0].x - 4.31973) < 0.1 && + ::fabs(iter[0].y - 1.24214) < 0.1) { + if (::fabs(iter[3].x - 4.68381) < 0.1 && + ::fabs(iter[3].y - 0.453632) < 0.1) { + found = true; + break; + } + } + } + assert(found); + found = false; + for (auto iter : clusters2) { + if (::fabs(iter[0].x - 1.5694) < 0.1 && + ::fabs(iter[0].y - 15.3338) < 0.1) { + found = true; + break; + } + } + assert(found); + found = false; + for (auto iter : clusters2) { + if (::fabs(iter[0].x - 1.29624) < 0.1 && + ::fabs(iter[0].y - 4.13919) < 0.1) { + found = true; + break; + } + } + assert(found); +*/ +} + +// ----------------------------------------------------------------------------- + +static void test_affinity_propagation() { + + std::cout << "\nTesting affinity propagation visitor ..." << std::endl; + + const size_t item_cnt = 50; + MyDataFrame df; + RandGenParams p; + StlVecType final_col; + StlVecType col_data; + + p.seed = 3575984165U; + + p.min_value = 0; + p.max_value = 10; + col_data = gen_uniform_real_dist(item_cnt, p); + final_col.insert(final_col.end(), col_data.begin(), col_data.end()); + + p.min_value = 20; + p.max_value = 30; + col_data = gen_uniform_real_dist(item_cnt, p); + final_col.insert(final_col.end(), col_data.begin(), col_data.end()); + + p.min_value = 40; + p.max_value = 50; + col_data = gen_uniform_real_dist(item_cnt, p); + final_col.insert(final_col.end(), col_data.begin(), col_data.end()); + + p.min_value = 60; + p.max_value = 70; + col_data = gen_uniform_real_dist(item_cnt, p); + final_col.insert(final_col.end(), col_data.begin(), col_data.end()); + + p.min_value = 80; + p.max_value = 90; + col_data = gen_uniform_real_dist(item_cnt, p); + final_col.insert(final_col.end(), col_data.begin(), col_data.end()); + + df.load_data(MyDataFrame::gen_sequence_index(0, item_cnt * 5, 1), + std::make_pair("col1", final_col)); + df.shuffle({"col1"}, false); + + KMeansVisitor<5, double, unsigned long, 128> km_visitor(1000); + AffinityPropVisitor ap_visitor(50); + + df.single_act_visit("col1", km_visitor); + df.single_act_visit("col1", ap_visitor); + + // Using the calculated means, separate the given column into clusters + const auto k_means = km_visitor.get_result(); + const auto &col1 = df.get_column("col1"); + const auto results = + ap_visitor.get_clusters(df.get_index().begin(), df.get_index().end(), + col1.begin(), col1.end()); + + for (auto iter : k_means) { + std::cout << iter << ", "; + } + std::cout << "\n\n" << std::endl; + for (auto iter : results) { + for (auto iter2 : iter) { + std::cout << iter2 << ", "; + } + std::cout << "\n" << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_multi_col_sort() { + + std::cout << "\nTesting multi-column sort ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, + 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = + { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("int_col", intvec), + std::make_pair("str_col", strvec)); + // df.write(std::cout); + + auto sf = df.sort_async + (DF_INDEX_COL_NAME, sort_spec::ascen, + "int_col", sort_spec::desce, + "str_col", sort_spec::desce); + + sf.get(); + assert(df.get_index()[0] == 1); + assert(df.get_index()[5] == 8); + assert(df.get_index()[8] == 10); + assert(df.get_index()[13] == 14); + assert(df.get_index()[14] == 15); + + assert(df.get_column("int_col")[0] == 1); + assert(df.get_column("int_col")[5] == 6); + assert(df.get_column("int_col")[8] == 9); + assert(df.get_column("int_col")[13] == 13); + assert(df.get_column("int_col")[14] == 12); + + assert(df.get_column("str_col")[0] == "zz"); + assert(df.get_column("str_col")[5] == "gg"); + assert(df.get_column("str_col")[8] == "kk"); + assert(df.get_column("str_col")[13] == "oo"); + assert(df.get_column("str_col")[14] == "nn"); + + assert(df.get_column("dbl_col")[0] == 0.0); + assert(df.get_column("dbl_col")[5] == 11.0); + assert(df.get_column("dbl_col")[8] == 5.0); + assert(df.get_column("dbl_col")[13] == 10.0); + assert(df.get_column("dbl_col")[14] == 9.0); + + assert(df.get_column("dbl_col_2")[0] == 100.0); + assert(df.get_column("dbl_col_2")[5] == 106.55); + assert(df.get_column("dbl_col_2")[8] == 112.0); + assert(df.get_column("dbl_col_2")[13] == 116.0); + assert(df.get_column("dbl_col_2")[14] == 115.0); +} + +// ----------------------------------------------------------------------------- + +static void test_join_by_column() { + + std::cout << "\nTesting join by column ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = + { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; + StlVecType d3 = + { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType idx2 = + { 123452, 123453, 123455, 123458, 123466, 223450, 223451, + 223454, 223456, 223457, 223459, 223460, 223461, 223462 }; + StlVecType d12 = + { 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111, 112, 113, 114 }; + StlVecType d22 = + { 8, 19, 110, 111, 9, 113, 114, 99, 122, 123, 130, 131, 20, 11.89 }; + StlVecType d32 = + { 115, 116, 115, 118, 119, 116, 121, 10.34, 11.56, 10.34, 12.3, 10.34, + 119.0 }; + StlVecType i12 = { 122, 123, 124, 125, 199 }; + MyDataFrame df2; + + df2.load_data(std::move(idx2), + std::make_pair("xcol_1", d12), + std::make_pair("col_2", d22), + std::make_pair("xcol_3", d32), + std::make_pair("col_4", i12)); + + StdDataFrame128 inner_result = + df.join_by_column + (df2, "col_2", join_policy::inner_join); + + assert(inner_result.get_index().size() == 3); + assert(inner_result.get_column("xcol_1")[2] == 113.0); + assert(inner_result.get_column("xcol_3")[1] == 119.0); + assert(inner_result.get_column("col_1")[2] == 8.0); + assert(inner_result.get_column("col_3")[0] == 15.0); + assert(inner_result.get_column("rhs.col_4")[2] == 0); + assert(inner_result.get_column("lhs.col_4")[0] == 22); + assert(inner_result.get_column("rhs.INDEX")[1] == 123466); + assert(inner_result.get_column("lhs.INDEX")[2] == 123457); + + StdDataFrame128 left_result = + df.join_by_column + (df2, "col_2", join_policy::left_join); + + assert(left_result.get_index().size() == 14); + assert(std::isnan(left_result.get_column("xcol_1")[5])); + assert(left_result.get_column("xcol_3")[8] == 119.0); + assert(left_result.get_column("col_1")[13] == 13.0); + assert(left_result.get_column("col_3")[9] == 1.56); + assert(left_result.get_column("rhs.col_4")[2] == 199); + assert(left_result.get_column("lhs.col_4")[5] == 99); + assert(left_result.get_column("rhs.INDEX")[3] == 0); + assert(left_result.get_column("lhs.INDEX")[11] == 123460); + + StdDataFrame128 right_result = + df.join_by_column + (df2, "col_2", join_policy::right_join); + + assert(right_result.get_index().size() == 14); + assert(right_result.get_column("xcol_1")[5] == 18.0); + assert(std::isnan(right_result.get_column("xcol_3")[2])); + assert(right_result.get_column("col_1")[4] == 8.0); + assert(std::isnan(right_result.get_column("col_3")[5])); + assert(right_result.get_column("rhs.col_4")[2] == 0); + assert(right_result.get_column("lhs.col_4")[5] == 0); + assert(right_result.get_column("rhs.INDEX")[3] == 123453); + assert(right_result.get_column("lhs.INDEX")[11] == 0); + + StdDataFrame128 left_right_result = + df.join_by_column + (df2, "col_2", join_policy::left_right_join); + + assert(left_right_result.get_index().size() == 25); + assert(left_right_result.get_column("xcol_1")[2] == 15.0); + assert(left_right_result.get_column("xcol_3")[1] == 115.0); + assert(left_right_result.get_column("col_1")[2] == 2.0); + assert(std::isnan(left_right_result.get_column("col_3")[0])); + assert(left_right_result.get_column("rhs.col_4")[2] == 199); + assert(left_right_result.get_column("lhs.col_4")[0] == 0); + assert(left_right_result.get_column("rhs.INDEX")[1] == + 123452); + assert(left_right_result.get_column("lhs.INDEX")[2] == + 123451); +} + +// ----------------------------------------------------------------------------- + +static void test_DoubleCrossOver() { + + std::cout << "\nTesting DoubleCrossOver{ } ..." << std::endl; + + MyDataFrame::set_thread_level(10); + + StlVecType idx = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 19, 18, 17, 17, 16, 15, 14, 13, 14, 13, 12, 11, 12, 10, 9, 8, 7, + 6, 7, 5 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + + using geo_mean_t = GeometricMeanVisitor; + using short_roller_t = SimpleRollAdopter; + using long_roller_t = ewm_v; + using double_cross_t = dco_v; + + double_cross_t visitor(short_roller_t(geo_mean_t(), 3), + long_roller_t(exponential_decay_spec::span, 1.5)); + + df.single_act_visit("col_1", visitor); + + auto &raw_to_short = visitor.get_raw_to_short_term(); + auto &raw_to_long = visitor.get_raw_to_long_term(); + auto &short_to_long = visitor.get_short_term_to_long_term(); + + assert(raw_to_short.size() == 40); + assert(std::isnan(raw_to_short[1])); + assert(fabs(raw_to_short[8] - 1.04189) < 0.00001); + assert(fabs(raw_to_short[12] - 1.02784) < 0.00001); + assert(fabs(raw_to_short[39] - -0.943922) < 0.00001); + assert(fabs(raw_to_short[38] - 0.3506) < 0.00001); + + assert(raw_to_long.size() == 40); + assert(fabs(raw_to_long[2] - 0.24) < 0.001); + assert(fabs(raw_to_long[8] - 0.249999) < 0.000001); + assert(fabs(raw_to_long[12] - 0.25) < 0.001); + assert(fabs(raw_to_long[39] - -0.370008) < 0.00001); + assert(fabs(raw_to_long[38] - 0.149962) < 0.00001); + + assert(short_to_long.size() == 40); + assert(std::isnan(short_to_long[0])); + assert(std::isnan(short_to_long[1])); + assert(fabs(short_to_long[8] - -0.791886) < 0.00001); + assert(fabs(short_to_long[12] - -0.777842) < 0.00001); + assert(fabs(short_to_long[39] - 0.573914) < 0.00001); + assert(fabs(short_to_long[38] - -0.200639) < 0.00001); + + MyDataFrame::set_thread_level(0); +} + +// ----------------------------------------------------------------------------- + +static void test_BollingerBand() { + + std::cout << "\nTesting BollingerBand{ } ..." << std::endl; + + MyDataFrame::set_thread_level(10); + + StlVecType idx = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 19, 18, 17, 17, 16, 15, 14, 13, 14, 13, 12, 11, 12, 10, 9, 8, 7, + 6, 7, 5 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + + using bollinger_band_t = BollingerBand; + + bollinger_band_t visitor(2.0, 2.0, 5); + + df.single_act_visit("col_1", visitor); + + auto &upper_to_raw = visitor.get_upper_band_to_raw(); + auto &raw_to_lower = visitor.get_raw_to_lower_band(); + + assert(upper_to_raw.size() == 40); + assert(std::isnan(upper_to_raw[3])); + assert(fabs(upper_to_raw[8] - 1.16228) < 0.00001); + assert(fabs(upper_to_raw[12] - 1.16228) < 0.00001); + assert(fabs(upper_to_raw[38] - 2.68035) < 0.00001); + assert(fabs(upper_to_raw[39] - 3.88035) < 0.00001); + + assert(raw_to_lower.size() == 40); + assert(std::isnan(raw_to_lower[1])); + assert(fabs(raw_to_lower[8] - 5.16228) < 0.00001); + assert(fabs(raw_to_lower[12] - 5.16228) < 0.00001); + assert(fabs(raw_to_lower[38] - 1.88035) < 0.00001); + assert(fabs(raw_to_lower[39] - 0.680351) < 0.00001); + + MyDataFrame::set_thread_level(0); +} + +// ----------------------------------------------------------------------------- + +static void test_MACDVisitor() { + + std::cout << "\nTesting MACDVisitor{ } ..." << std::endl; + + StlVecType idx = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 19, 18, 17, 17, 16, 15, 14, 13, 14, 13, 12, 11, 12, 10, 9, 8, 7, + 6, 7, 5 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + + using macd_t = MACDVisitor; + + macd_t visitor(2, 5, 6); + + df.single_act_visit("col_1", visitor); + + auto &macd_result = visitor.get_macd_line(); + auto &signal_line = visitor.get_signal_line(); + auto &macd_histo = visitor.get_macd_histogram(); + + assert(macd_result.size() == 40); + assert(macd_result[0] == 0); + assert(fabs(macd_result[3] - 0.925926) < 0.000001); + assert(fabs(macd_result[8] - 1.42204) < 0.00001); + assert(fabs(macd_result[12] - 1.48459) < 0.00001); + assert(fabs(macd_result[38] - -0.777175) < 0.000001); + assert(fabs(macd_result[39] - -1.12938) < 0.00001); + + assert(signal_line.size() == 40); + assert(signal_line[0] == 0); + assert(fabs(signal_line[2] - 0.258503) < 0.00001); + assert(fabs(signal_line[4] - 0.638314) < 0.00001); + assert(fabs(signal_line[8] - 1.17688) < 0.00001); + assert(fabs(signal_line[12] - 1.3963) < 0.0001); + assert(fabs(signal_line[38] - -1.08527) < 0.00001); + assert(fabs(signal_line[39] - -1.09787) < 0.00001); + + assert(macd_histo.size() == 40); + assert(macd_histo[0] == 0); + assert(fabs(macd_histo[4] - 0.472797) < 0.00001); + assert(fabs(macd_histo[8] - 0.245164) < 0.00001); + assert(fabs(macd_histo[12] - 0.0882894) < 0.000001); + assert(fabs(macd_histo[38] - 0.308093) < 0.000001); + assert(fabs(macd_histo[39] - -0.0315057) < 0.000001); +} + +// ----------------------------------------------------------------------------- + +static void test_ExpandingRollAdopter() { + + std::cout << "\nTesting ExpandingRollAdopter{ } ..." << std::endl; + + StlVecType idx = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + + ExpandingRollAdopter, double, unsigned long, 128> + expand_roller(MeanVisitor(), 2); + const auto &result = + df.single_act_visit("col_1", expand_roller).get_result(); + + assert(result.size() == 21); + assert(std::isnan(result[0])); + assert(result[8] == 12); + assert(result[13] == 19.5); + assert(result[15] == 22.5); + assert(result[20] == 30); +} + +// ----------------------------------------------------------------------------- + +static void test_MADVisitor() { + + std::cout << "\nTesting MADVisitor{ } ..." << std::endl; + + StlVecType idx = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + + MADVisitor mad_visitor1(mad_type::mean_abs_dev_around_mean); + const auto result1 = + df.single_act_visit("col_1", mad_visitor1).get_result(); + + assert(result1 == 10.0); + + MADVisitor mad_visitor2(mad_type::mean_abs_dev_around_median); + const auto result2 = + df.single_act_visit("col_1", mad_visitor2).get_result(); + + assert(result2 == 10.0); + + MADVisitor mad_visitor3(mad_type::median_abs_dev_around_mean); + const auto result3 = + df.single_act_visit("col_1", mad_visitor3).get_result(); + + assert(result3 == 10.0); + + MADVisitor mad_visitor4(mad_type::median_abs_dev_around_median); + const auto result4 = + df.single_act_visit("col_1", mad_visitor4).get_result(); + + assert(result4 == 10.0); +} + +// ----------------------------------------------------------------------------- + +static void test_SEMVisitor() { + + std::cout << "\nTesting SEMVisitor{ } ..." << std::endl; + + StlVecType idx = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + + SEMVisitor sem_visitor; + const auto result = + df.visit("col_1", sem_visitor).get_result(); + + assert(fabs(result - 1.84842) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_fill_missing_mid_point() { + + std::cout << "\nTesting fill_missing(mid_point) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + StlVecType s1 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; + + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); + + // std::cout << "Original DF:" << std::endl; + // df.write(std::cout); + + df.fill_missing({ "col_1", "col_2", "col_3" }, + fill_policy::mid_point); + + std::cout << "After fill missing with values DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_fill_missing_df() { + + std::cout << "\nTesting fill_missing(DataFrame) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType idx2 = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 1234570, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, + std::numeric_limits::quiet_NaN(), + 6, 7, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d12 = { 1, 2, 3, 4, + 100, + 6, 7, + 101, + 102, + std::numeric_limits::quiet_NaN(), + 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, + std::numeric_limits::quiet_NaN(), + 11, 12, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d22 = { 8, 9, + 200, + 11, 12, + 201, + 202, + 20, 22, 23, 30, 31, + std::numeric_limits::quiet_NaN(), + 1.89 }; + StlVecType d3 = { std::numeric_limits::quiet_NaN(), + 16, + std::numeric_limits::quiet_NaN(), + 18, 19, 16, + std::numeric_limits::quiet_NaN(), + 0.34, 1.56, 0.34, 2.3, 0.34, + std::numeric_limits::quiet_NaN() }; + StlVecType d32 = { 300, + 16, + 301, + 18, 19, 16, + 303, + 0.34, 1.56, 0.34, 2.3, 0.34 }; + StlVecType i1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + StlVecType xi1 = { 22, + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + 25, + std::numeric_limits::quiet_NaN() }; + StlVecType i12 = { 22, + 400, + 401, + 25, + std::numeric_limits::quiet_NaN() }; + MyDataFrame df; + MyDataFrame df2; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1), + std::make_pair("xcol_4", xi1)); + df2.load_data(std::move(idx2), + std::make_pair("col_1", d12), + std::make_pair("col_2", d22), + std::make_pair("col_3", d32), + std::make_pair("col_4", i12)); + + StlVecType s1 = + { "qqqq", "wwww", "", "rrrr", "tttt", "", "iiii", "" }; + StlVecType s12 = + { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", + "aaaa", "bbbb", "cccc", "dddd", "gggg", "hhhh", "kkkk" }; + + df.load_column("col_str", + std::move(s1), + nan_policy::dont_pad_with_nans); + df2.load_column("col_str", + std::move(s12), + nan_policy::dont_pad_with_nans); + + df.fill_missing(df2); + + std::cout << "After fill missing with values DF:" << std::endl; + df.write(std::cout); +} + +// ----------------------------------------------------------------------------- + +static void test_quantile() { + + std::cout << "\nTesting QuantileVisitor{ } ..." << std::endl; + + StlVecType idx = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + df.shuffle({"col_1"}, false); + + QuantileVisitor v1(1, quantile_policy::mid_point); + auto result = + df.single_act_visit("col_1", v1).get_result(); + + assert(result == 40.0); + + QuantileVisitor v2(0.5, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v2).get_result(); + assert(result == 20.5); + + QuantileVisitor v3(0.5, quantile_policy::linear); + + result = df.single_act_visit("col_1", v3).get_result(); + assert(result == 20.5); + + QuantileVisitor v4(0.5, quantile_policy::higher_value); + + result = df.single_act_visit("col_1", v4).get_result(); + assert(result == 21.0); + + QuantileVisitor v5(0.5, quantile_policy::lower_value); + + result = df.single_act_visit("col_1", v5).get_result(); + assert(result == 20.0); + + QuantileVisitor v6(0.55, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v6).get_result(); + assert(result == 22.5); + + QuantileVisitor v7(0.55, quantile_policy::linear); + + result = df.single_act_visit("col_1", v7).get_result(); + assert(result == 22.45); + + QuantileVisitor v8(0.75, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v8).get_result(); + assert(result == 30.5); + + QuantileVisitor v9(0.75, quantile_policy::linear); + + result = df.single_act_visit("col_1", v9).get_result(); + assert(result == 30.25); + + QuantileVisitor v10(0, quantile_policy::linear); + + result = df.single_act_visit("col_1", v10).get_result(); + assert(result == 1.0); + + df.get_index().push_back(41); + df.get_column("col_1").push_back(41); + + QuantileVisitor v11(0.75, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v11).get_result(); + assert(result == 31.0); + + QuantileVisitor v12(0.75, quantile_policy::linear); + + result = df.single_act_visit("col_1", v12).get_result(); + assert(result == 31.0); + + QuantileVisitor v13(0.75, quantile_policy::lower_value); + + result = df.single_act_visit("col_1", v13).get_result(); + assert(result == 31.0); + + QuantileVisitor v14(0.75, quantile_policy::higher_value); + + result = df.single_act_visit("col_1", v14).get_result(); + assert(result == 31.0); + + QuantileVisitor v15(0.71, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v15).get_result(); + assert(result == 29.5); + + QuantileVisitor v16(0.71, quantile_policy::linear); + + result = df.single_act_visit("col_1", v16).get_result(); + assert(result == 29.29); + + QuantileVisitor v17(0.23, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v17).get_result(); + assert(result == 9.5); + + QuantileVisitor v18(0.2, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v18).get_result(); + assert(result == 8.5); + + QuantileVisitor v19(0.23, quantile_policy::linear); + + result = df.single_act_visit("col_1", v19).get_result(); + assert(result == 9.77); + + QuantileVisitor v20(0.23, quantile_policy::lower_value); + + result = df.single_act_visit("col_1", v20).get_result(); + assert(result == 9.0); + + QuantileVisitor v21(0.23, quantile_policy::higher_value); + + result = df.single_act_visit("col_1", v21).get_result(); + assert(result == 10.0); + + QuantileVisitor v22(1, quantile_policy::linear); + + result = df.single_act_visit("col_1", v22).get_result(); + assert(result == 41.0); + + QuantileVisitor v23(0, quantile_policy::mid_point); + + result = df.single_act_visit("col_1", v23).get_result(); + assert(result == 1.0); +} + +// ----------------------------------------------------------------------------- + +static void test_VWAP() { + + std::cout << "\nTesting VWAPVisitor{ } ..." << std::endl; + + RandGenParams price_p; + + price_p.mean = 1.0; + price_p.std = 0.005; + price_p.seed = 10; + price_p.min_value = 500.0; + price_p.max_value = 580.0; + + RandGenParams size_p = price_p; + + size_p.std = 1; + size_p.min_value = 50.0; + size_p.max_value = 2000.0; + + MyDataFrame df; + + df.load_data( + MyDataFrame::gen_sequence_index(100, 1124, 1), + std::make_pair("price", + gen_uniform_real_dist(1024, price_p)), + std::make_pair("size", + gen_uniform_real_dist(1024, size_p))); + + VWAPVisitor v1(100); + auto result = + df.visit("price", "size", v1).get_result(); + + assert(result.size() == 11); + assert(result[0].event_count == 100); + assert(result[0].index_value == 100); + assert(result[1].event_count == 100); + assert(result[1].index_value == 200); + assert(result[10].event_count == 24); + assert(result[10].index_value == 1100); +/* + assert(fabs(result[0].vwap - 548.091) < 0.001); + assert(fabs(result[0].average_price - 535.331) < 0.001); + assert(fabs(result[0].cumulative_vwap - 548.091) < 0.001); + assert(fabs(result[4].vwap - 551.923) < 0.001); + assert(fabs(result[4].average_price - 537.798) < 0.001); + assert(fabs(result[4].cumulative_vwap - 550.347) < 0.001); + assert(fabs(result[10].vwap - 553.196) < 0.001); + assert(fabs(result[10].average_price - 539.629) < 0.001); + assert(fabs(result[10].cumulative_vwap - 552.067) < 0.001); +*/ +} + +// ----------------------------------------------------------------------------- + +static void test_VWBAS() { + + std::cout << "\nTesting VWBASVisitor{ } ..." << std::endl; + + RandGenParams bprice_p; + + bprice_p.mean = 1.0; + bprice_p.std = 0.005; + bprice_p.seed = 10; + bprice_p.min_value = 100.0; + bprice_p.max_value = 102.0; + + RandGenParams aprice_p = bprice_p; + + aprice_p.seed = 200; + aprice_p.min_value = 102.0; + aprice_p.max_value = 104.0; + + RandGenParams asize_p = bprice_p; + + asize_p.std = 1; + asize_p.seed = 500; + asize_p.min_value = 50.0; + asize_p.max_value = 2000.0; + + RandGenParams bsize_p = asize_p; + + asize_p.std = 1; + asize_p.seed = 123456; + asize_p.min_value = 50.0; + asize_p.max_value = 2000.0; + MyDataFrame df; + + df.load_data( + MyDataFrame::gen_sequence_index(100, 1124, 1), + std::make_pair("bid_price", + gen_uniform_real_dist(1024, bprice_p)), + std::make_pair("ask_price", + gen_uniform_real_dist(1024, aprice_p)), + std::make_pair("bid_size", + gen_uniform_real_dist(1024, bsize_p)), + std::make_pair("ask_size", + gen_uniform_real_dist(1024, asize_p))); + + VWBASVisitor v1(100); + const MyDataFrame const_df = df; + auto fut = + const_df.visit_async + ("bid_price", "ask_price", "bid_size", "ask_size", v1); + auto result = fut.get().get_result(); + + assert(result.size() == 11); + assert(result[0].event_count == 100); + assert(result[0].index_value == 100); + assert(result[1].event_count == 100); + assert(result[1].cumulative_event_count == 200); + assert(result[1].index_value == 200); + assert(result[10].event_count == 24); + assert(result[10].index_value == 1100); + +/* + assert(fabs(result[0].spread - 2.11835) < 0.00001); + assert(fabs(result[0].percent_spread - 2.0998) < 0.0001); + assert(fabs(result[0].vwbas - 2.15156) < 0.00001); + assert(fabs(result[0].percent_vwbas - 2.13298) < 0.00001); + assert(fabs(result[0].high_bid_price - 101.966) < 0.001); + assert(fabs(result[0].low_ask_price - 102.012) < 0.001); + assert(fabs(result[0].cumulative_vwbas - 2.15156) < 0.00001); + + assert(fabs(result[5].spread - 1.92471) < 0.00001); + assert(fabs(result[5].percent_spread - 1.90509) < 0.0001); + assert(fabs(result[5].vwbas - 1.9199) < 0.0001); + assert(fabs(result[5].percent_vwbas - 1.90052) < 0.00001); + assert(fabs(result[5].high_bid_price - 101.987) < 0.001); + assert(fabs(result[5].low_ask_price - 102.04) < 0.01); + assert(fabs(result[5].cumulative_vwbas - 2.07029) < 0.00001); + + assert(fabs(result[10].spread - 1.98223) < 0.00001); + assert(fabs(result[10].percent_spread - 1.96279) < 0.0001); + assert(fabs(result[10].vwbas - 2.05129) < 0.0001); + assert(fabs(result[10].percent_vwbas - 2.03336) < 0.00001); + assert(fabs(result[10].high_bid_price - 101.997) < 0.001); + assert(fabs(result[10].low_ask_price - 102.12) < 0.01); + assert(fabs(result[10].cumulative_vwbas - 2.02198) < 0.00001); +*/ +} + +// ----------------------------------------------------------------------------- + +static void test_self_concat() { + + std::cout << "\nTesting self_concat( ) ..." << std::endl; + + MyDataFrame df1; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, + 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = + { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + df1.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("int_col", intvec), + std::make_pair("str_col", strvec)); + + MyDataFrame df2 = df1; + + df2.load_column("dbl_col_2", std::move(dblvec2)); + + df1.self_concat(df2, true); + assert(df1.get_index().size() == 30); + assert(df1.get_column("dbl_col_2").size() == 30); + assert(df1.get_column("dbl_col").size() == 30); + assert(df1.get_column("str_col").size() == 30); + assert(df1.get_column("int_col").size() == 30); + assert(df1.get_index()[0] == 1); + assert(df1.get_index()[14] == 14); + assert(df1.get_index()[15] == 1); + assert(df1.get_index()[29] == 14); + assert(std::isnan(df1.get_column("dbl_col_2")[0])); + assert(std::isnan(df1.get_column("dbl_col_2")[14])); + assert(df1.get_column("dbl_col_2")[15] == 100.0); + assert(df1.get_column("dbl_col_2")[29] == 116.0); + assert(df1.get_column("str_col")[0] == "zz"); + assert(df1.get_column("str_col")[14] == "oo"); + assert(df1.get_column("str_col")[15] == "zz"); + assert(df1.get_column("int_col")[0] == 1); + assert(df1.get_column("int_col")[14] == 13); + assert(df1.get_column("int_col")[15] == 1); +} + +// ----------------------------------------------------------------------------- + +static void test_concat() { + + std::cout << "\nTesting concat( ) ..." << std::endl; + + MyDataFrame df1; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, + 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = + { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 10, 15, 12, 13 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + df1.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("int_col", intvec), + std::make_pair("str_col", strvec)); + + MyDataFrame df2 = df1; + + df2.load_column("dbl_col_2", std::move(dblvec2)); + + auto result1 = df1.concat(df2); + + assert(result1.get_index().size() == 30); + assert(result1.get_column("dbl_col_2").size() == 30); + assert(result1.get_column("dbl_col").size() == 30); + assert(result1.get_column("str_col").size() == 30); + assert(result1.get_column("int_col").size() == 30); + assert(result1.get_index()[0] == 1); + assert(result1.get_index()[14] == 14); + assert(result1.get_index()[15] == 1); + assert(result1.get_index()[29] == 14); + assert(std::isnan(result1.get_column("dbl_col_2")[0])); + assert(std::isnan(result1.get_column("dbl_col_2")[14])); + assert(result1.get_column("dbl_col_2")[15] == 100.0); + assert(result1.get_column("dbl_col_2")[29] == 116.0); + assert(result1.get_column("str_col")[0] == "zz"); + assert(result1.get_column("str_col")[14] == "oo"); + assert(result1.get_column("str_col")[15] == "zz"); + assert(result1.get_column("int_col")[0] == 1); + assert(result1.get_column("int_col")[14] == 13); + assert(result1.get_column("int_col")[15] == 1); + + auto result2 = + df1.concat + (df2, concat_policy::common_columns); + + assert(result2.get_index().size() == 30); + assert(result2.get_column("dbl_col").size() == 30); + assert(result2.get_column("str_col").size() == 30); + assert(result2.get_column("str_col")[0] == "zz"); + assert(result2.get_column("str_col")[14] == "oo"); + assert(result2.get_column("str_col")[15] == "zz"); + assert(! result2.has_column("dbl_col_2")); + + auto result3 = + df1.concat + (df2, concat_policy::lhs_and_common_columns); + + assert((result2.is_equal(result3))); +} + +// ----------------------------------------------------------------------------- + +int main(int, char *[]) { + + test_haphazard(); + test_read(); + test_transpose(); + test_get_data_by_loc_slicing(); + test_remove_column(); + test_rename_column(); + test_get_col_unique_values(); + test_remove_data_by_idx(); + test_remove_data_by_loc(); + test_value_counts(); + test_index_inner_join(); + test_index_left_join(); + test_index_right_join(); + test_index_left_right_join(); + test_largest_smallest_visitors(); + test_shifting_up_down(); + test_rotating_up_down(); + test_dataframe_with_datetime(); + test_dataframe_friend_plus_operator(); + test_dataframe_friend_minus_operator(); + test_dataframe_friend_multiplies_operator(); + test_dataframe_friend_divides_operator(); + test_fill_missing_df(); + test_fill_missing_values(); + test_fill_missing_fill_forward(); + test_fill_missing_fill_backward(); + test_fill_missing_fill_linear_interpolation(); + test_drop_missing_all_no_drop(); + test_drop_missing_all_2_drop(); + test_drop_missing_any(); + test_drop_threashold_3(); + test_get_row(); + test_auto_correlation(); + test_return(); + test_median(); + test_tracking_error(); + test_beta(); + test_gen_datetime_index(); + test_replace_1(); + test_replace_2(); + test_some_visitors(); + test_mode(); + test_remove_data_by_sel(); + test_shuffle(); + test_SimpleRollAdopter(); + test_get_data_by_rand(); + test_write_json(); + test_diff(); + test_reading_writing_json(); + test_get_data_by_loc_location(); + test_get_data_by_idx_values(); + test_z_score_visitor(); + test_thread_safety(); + test_view_visitors(); + test_k_means(); + test_affinity_propagation(); + test_multi_col_sort(); + test_join_by_column(); + test_ExponentialRollAdopter(); + test_ExponentiallyWeightedMeanVisitor(); + test_DoubleCrossOver(); + test_BollingerBand(); + test_MACDVisitor(); + test_ExpandingRollAdopter(); + test_MADVisitor(); + test_SEMVisitor(); + test_fill_missing_mid_point(); + test_quantile(); + test_VWAP(); + test_VWBAS(); + test_self_concat(); + test_concat(); + + return (0); +} + +// ----------------------------------------------------------------------------- + +// Local Variables: +// mode:C++ +// tab-width:4 +// c-basic-offset:4 +// End: diff --git a/test/aligned_dataframe_tester_2.cc b/test/aligned_dataframe_tester_2.cc new file mode 100644 index 000000000..8a4261e9a --- /dev/null +++ b/test/aligned_dataframe_tester_2.cc @@ -0,0 +1,4927 @@ +/* +Copyright (c) 2019-2026, Hossein Moein +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +* Neither the name of Hossein Moein and/or the DataFrame nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace hmdf; + +// A DataFrame with ulong index type +// +using MyDataFrame = StdDataFrame64; + +template +using StlVecType = typename MyDataFrame::template StlVecType; + +// ----------------------------------------------------------------------------- + +static void test_get_reindexed() { + + std::cout << "\nTesting get_reindexed( ) ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, + 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("str_col", strvec)); + df.load_column("int_col", + std::move(intvec), + nan_policy::dont_pad_with_nans); + + auto result1 = + df.get_reindexed + ("dbl_col", "OLD_IDX"); + + assert(result1.get_index().size() == 15); + assert(result1.get_column("dbl_col_2").size() == 15); + assert(result1.get_column("OLD_IDX").size() == 15); + assert(result1.get_column("str_col").size() == 15); + assert(result1.get_column("int_col").size() == 11); + assert(result1.get_index()[0] == 0); + assert(result1.get_index()[14] == 10.0); + assert(result1.get_column("int_col")[3] == 4); + assert(result1.get_column("int_col")[9] == 14); + assert(result1.get_column("str_col")[5] == "ff"); + assert(result1.get_column("dbl_col_2")[10] == 112.0); + + auto result2 = + df.get_reindexed("int_col", "OLD_IDX"); + + assert(result2.get_index().size() == 11); + assert(result2.get_column("dbl_col_2").size() == 11); + assert(result2.get_column("dbl_col").size() == 11); + assert(result2.get_column("OLD_IDX").size() == 11); + assert(result2.get_column("str_col").size() == 11); + assert(result2.get_column("dbl_col_2")[10] == 112.0); + assert(result2.get_column("dbl_col")[3] == 2.0); + assert(result2.get_column("str_col")[5] == "ff"); + assert(result2.get_index()[0] == 1); + assert(result2.get_index()[10] == 9); +} + +// ----------------------------------------------------------------------------- + +static void test_get_reindexed_view() { + + std::cout << "\nTesting get_reindexed_view( ) ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, + 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("str_col", strvec)); + df.load_column("int_col", + std::move(intvec), + nan_policy::dont_pad_with_nans); + + const MyDataFrame &const_df = df; + auto result1 = + df.get_reindexed_view + ("dbl_col", "OLD_IDX"); + auto const_result1 = + const_df.get_reindexed_view + ("dbl_col", "OLD_IDX"); + + assert(result1.get_index().size() == 15); + assert(result1.get_column("dbl_col_2").size() == 15); + assert(result1.get_column("OLD_IDX").size() == 15); + assert(result1.get_column("str_col").size() == 15); + assert(result1.get_column("int_col").size() == 11); + assert(result1.get_index()[0] == 0); + assert(result1.get_index()[14] == 10.0); + assert(result1.get_column("int_col")[3] == 4); + assert(result1.get_column("int_col")[9] == 14); + assert(result1.get_column("str_col")[5] == "ff"); + assert(result1.get_column("dbl_col_2")[10] == 112.0); + + assert(const_result1.get_index().size() == 15); + assert(const_result1.get_column("dbl_col_2").size() == 15); + assert(const_result1.get_column("OLD_IDX").size() == 15); + assert(const_result1.get_column("str_col").size() == 15); + assert(const_result1.get_column("int_col").size() == 11); + assert(const_result1.get_index()[0] == 0); + assert(const_result1.get_index()[14] == 10.0); + assert(const_result1.get_column("int_col")[3] == 4); + assert(const_result1.get_column("int_col")[9] == 14); + assert(const_result1.get_column("str_col")[5] == "ff"); + assert(const_result1.get_column("dbl_col_2")[10] == 112.0); + + auto result2 = + df.get_reindexed_view + ("int_col", "OLD_IDX"); + auto const_result2 = + const_df.get_reindexed_view + ("int_col", "OLD_IDX"); + + assert(result2.get_index().size() == 11); + assert(result2.get_column("dbl_col_2").size() == 11); + assert(result2.get_column("dbl_col").size() == 11); + assert(result2.get_column("OLD_IDX").size() == 11); + assert(result2.get_column("str_col").size() == 11); + assert(result2.get_column("dbl_col_2")[10] == 112.0); + assert(result2.get_column("dbl_col")[3] == 2.0); + assert(result2.get_column("str_col")[5] == "ff"); + assert(result2.get_index()[0] == 1); + assert(result2.get_index()[10] == 9); + + assert(const_result2.get_index().size() == 11); + assert(const_result2.get_column("dbl_col_2").size() == 11); + assert(const_result2.get_column("dbl_col").size() == 11); + assert(const_result2.get_column("OLD_IDX").size() == 11); + assert(const_result2.get_column("str_col").size() == 11); + assert(const_result2.get_column("dbl_col_2")[10] == 112.0); + assert(const_result2.get_column("dbl_col")[3] == 2.0); + assert(const_result2.get_column("str_col")[5] == "ff"); + assert(const_result2.get_index()[0] == 1); + assert(const_result2.get_index()[10] == 9); + + result2.get_column("dbl_col")[3] = 1002.45; + assert(result2.get_column("dbl_col")[3] == 1002.45); + assert(df.get_column("dbl_col")[3] == + result2.get_column("dbl_col")[3]); +} + +// ----------------------------------------------------------------------------- + +static void test_retype_column() { + + std::cout << "\nTesting retype_column( ) ..." << std::endl; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, + 10UL, 13UL, 10UL, 15UL, 14UL }; + StlVecType intvec = + { -1, 2, 3, 4, 5, 8, -6, 7, 11, 14, -9, 12, 13, 14, 15 }; + StlVecType strvec = + { "11", "22", "33", "44", "55", "66", "-77", "88", "99", "100", + "101", "102", "103", "104", "-105" }; + + MyDataFrame df; + + df.load_data(std::move(idxvec), + std::make_pair("str_col", strvec), + std::make_pair("int_col", intvec)); + + df.retype_column("int_col"); + assert(df.get_index().size() == 15); + assert(df.get_column("int_col").size() == 15); + assert(df.get_column("int_col")[0] == 4294967295); + assert(df.get_column("int_col")[1] == 2); + assert(df.get_column("int_col")[6] == 4294967290); + assert(df.get_column("int_col")[8] == 11); + assert(df.get_column("str_col")[0] == "11"); + assert(df.get_column("str_col")[6] == "-77"); + + df.retype_column("str_col", + [](const std::string &val) -> int { + return (std::stoi(val)); + }); + assert(df.get_index().size() == 15); + assert(df.get_column("int_col").size() == 15); + assert(df.get_column("str_col").size() == 15); + assert(df.get_column("int_col")[6] == 4294967290); + assert(df.get_column("int_col")[8] == 11); + assert(df.get_column("str_col")[0] == 11); + assert(df.get_column("str_col")[6] == -77); +} + +// ----------------------------------------------------------------------------- + +static void test_load_align_column() { + + std::cout << "\nTesting load_align_column( ) ..." << std::endl; + + StlVecType idxvec = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }; + StlVecType intvec = + { -1, 2, 3, 4, 5, 8, -6, 7, 11, 14, -9, 12, 13, 14, 15 }; + StlVecType summary_vec = { 100, 200, 300, 400, 500 }; + + MyDataFrame df; + + df.load_data(std::move(idxvec), std::make_pair("int_col", intvec)); + df.load_align_column("summary_col", + std::move(summary_vec), + 5, + true, + std::sqrt(-1)); + + StlVecType summary_vec_2 = { 102, 202, 302, 402, 502 }; + + df.load_align_column("summary_col_2", + std::move(summary_vec_2), + 5, + false, + std::sqrt(-1)); + + assert(df.get_column("summary_col").size() == 28); + assert(df.get_column("summary_col_2").size() == 28); + assert(df.get_column("summary_col")[0] == 100); + assert(std::isnan(df.get_column("summary_col_2")[0])); + assert(df.get_column("summary_col")[5] == 200); + assert(std::isnan(df.get_column("summary_col")[6])); + assert(df.get_column("summary_col_2")[5] == 102); + assert(df.get_column("summary_col")[20] == 500); + assert(df.get_column("summary_col_2")[25] == 502); + assert(std::isnan(df.get_column("summary_col")[27])); + assert(std::isnan(df.get_column("summary_col")[26])); + assert(std::isnan(df.get_column("summary_col_2")[27])); + assert(std::isnan(df.get_column("summary_col_2")[26])); +} + +// ----------------------------------------------------------------------------- + +static void test_get_columns_info() { + + std::cout << "\nTesting get_columns_info( ) ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, + 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("str_col", strvec)); + df.load_column("int_col", + std::move(intvec), + nan_policy::dont_pad_with_nans); + + auto result = df.get_columns_info(); + bool dbl_col_found = false; + bool dbl_col_2_found = false; + bool str_col_found = false; + bool int_col_found = false; + + for (auto citer: result) { + if (std::get<0>(citer) == "dbl_col") { + dbl_col_found = true; + assert(std::get<1>(citer) == 15); + assert(std::get<2>(citer) == std::type_index(typeid(double))); + } + if (std::get<0>(citer) == "dbl_col_2") { + dbl_col_2_found = true; + assert(std::get<1>(citer) == 15); + assert(std::get<2>(citer) == std::type_index(typeid(double))); + } + if (std::get<0>(citer) == "str_col") { + str_col_found = true; + assert(std::get<1>(citer) == 15); + assert(std::get<2>(citer) == std::type_index(typeid(std::string))); + } + if (std::get<0>(citer) == "int_col") { + int_col_found = true; + assert(std::get<1>(citer) == 11); + assert(std::get<2>(citer) == std::type_index(typeid(int))); + } + } + assert(dbl_col_found); + assert(dbl_col_2_found); + assert(str_col_found); + assert(int_col_found); +} + +// ----------------------------------------------------------------------------- + +static void test_CategoryVisitor() { + + std::cout << "\nTesting CategoryVisitor{ } ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, sqrt(-1), + 4.0, 14.0, 14.0, 20.0 }; + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = + { "zz", "bb", "zz", "ww", "ee", "ff", "gg", "zz", "ii", "jj", "kk", + "ll", "mm", "ee", "" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("str_col", strvec)); + df.load_column("int_col", + std::move(intvec), + nan_policy::dont_pad_with_nans); + + CategoryVisitor cat; + auto result = + df.single_act_visit("dbl_col", cat).get_result(); + + assert(result.size() == 15); + assert(result[0] == 0); + assert(result[1] == 1); + assert(result[2] == 2); + assert(result[3] == 1); + assert(result[4] == 3); + assert(result[8] == 1); + assert(result[13] == 2); + assert(result[12] == 2); + assert(result[11] == 8); + assert(result[10] == static_cast(-1)); + + CategoryVisitor cat2; + auto result2 = + df.single_act_visit("str_col", cat2).get_result(); + + assert(result2.size() == 15); + assert(result2[0] == 0); + assert(result2[1] == 1); + assert(result2[2] == 0); + assert(result2[13] == 3); +} + +// ----------------------------------------------------------------------------- + +static void test_FactorizeVisitor() { + + std::cout << "\nTesting FactorizeVisitor{ } ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, + 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("str_col", strvec)); + df.load_column("int_col", + std::move(intvec), + nan_policy::dont_pad_with_nans); + + FactorizeVisitor fact([] (const double &f) -> bool { + return (f > 106.0 && f < 114.0); + }); + df.load_column("bool_col", + df.single_act_visit("dbl_col_2", fact).get_result()); + assert(df.get_column("bool_col").size() == 15); + assert(df.get_column("bool_col")[0] == false); + assert(df.get_column("bool_col")[4] == false); + assert(df.get_column("bool_col")[6] == true); + assert(df.get_column("bool_col")[7] == true); + assert(df.get_column("bool_col")[8] == false); + assert(df.get_column("bool_col")[9] == true); + assert(df.get_column("bool_col")[11] == true); + assert(df.get_column("bool_col")[13] == false); +} + +// ----------------------------------------------------------------------------- + +static void test_pattern_match() { + + std::cout << "\nTesting pattern_match( ) ..." << std::endl; + + const size_t item_cnt = 8192; + MyDataFrame df; + RandGenParams p; + + p.mean = 5.6; + p.std = 0.5; + p.seed = 123; + p.min_value = 0; + p.max_value = 30; + + df.load_data(MyDataFrame::gen_sequence_index(0, item_cnt, 1), + std::make_pair("lognormal", + gen_lognormal_dist(item_cnt, p)), + std::make_pair("normal", + gen_normal_dist(item_cnt, p)), + std::make_pair("uniform_real", + gen_uniform_real_dist(item_cnt, p))); + p.mean = 0; + p.std = 1.0; + p.min_value = -30; + p.max_value = 30; + df.load_column("std_normal", gen_normal_dist(item_cnt, p)); + df.load_column( + "increasing", + MyDataFrame::gen_sequence_index(0, item_cnt, 1)); + + bool result = + df.pattern_match("lognormal", + pattern_spec::normally_distributed, + 0.01); + assert(result == false); + + result = df.pattern_match("normal", + pattern_spec::normally_distributed, + 0.01); + assert(result == true); + + result = df.pattern_match( + "std_normal", + pattern_spec::standard_normally_distributed, + 0.05); + assert(result == true); + + result = df.pattern_match("lognormal", + pattern_spec::lognormally_distributed, + 0.01); + assert(result == true); + + result = df.pattern_match("normal", + pattern_spec::lognormally_distributed, + 0.01); + assert(result == false); + + result = df.pattern_match("uniform_real", + pattern_spec::lognormally_distributed, + 1.0); + assert(result == false); + + result = df.pattern_match("uniform_real", + pattern_spec::normally_distributed, + 0.05); + assert(result == false); + + result = df.pattern_match( + "increasing", + pattern_spec::monotonic_increasing); + assert(result == true); + result = df.pattern_match( + "increasing", + pattern_spec::strictly_monotonic_increasing); + assert(result == true); + + df.get_column("increasing")[10] = 9; + + result = df.pattern_match( + "increasing", + pattern_spec::monotonic_increasing); + assert(result == true); + result = df.pattern_match( + "increasing", + pattern_spec::strictly_monotonic_increasing); + assert(result == false); + + df.get_column("increasing")[1000] = 988; + + result = df.pattern_match( + "increasing", + pattern_spec::monotonic_increasing); + assert(result == false); + result = df.pattern_match( + "increasing", + pattern_spec::strictly_monotonic_increasing); + assert(result == false); +} + +// ----------------------------------------------------------------------------- + +static void test_ClipVisitor() { + + std::cout << "\nTesting ClipVisitor{ } ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, sqrt(-1), + 4.0, 14.0, 14.0, 20.0 }; + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = + { "zz", "bb", "zz", "ww", "ee", "ff", "gg", "zz", "ii", "jj", "kk", + "ll", "mm", "ee", "" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("str_col", strvec)); + df.load_column("int_col", + std::move(intvec), + nan_policy::dont_pad_with_nans); + + const double upper = 14; + const double lower = 5; + ClipVisitor clip (upper, lower); + auto result = df.visit("dbl_col", clip).get_result(); + + assert(result == 7); + assert(df.get_column("dbl_col")[0] == 5.0); + assert(df.get_column("dbl_col")[1] == 14.0); + assert(df.get_column("dbl_col")[2] == 14.0); + assert(df.get_column("dbl_col")[4] == 5.0); + assert(df.get_column("dbl_col")[5] == 12.0); +} + +// ----------------------------------------------------------------------------- + +static void test_SharpeRatioVisitor() { + + std::cout << "\nTesting SharpeRatioVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 2.5, 2.45, -0.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, -0.34, 2.3, + -0.34, -1.9, 0.387, 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59 }; + StlVecType d2 = + { 0.2, 0.58, -0.60, -0.08, 0.05, 0.87, 0.2, 0.4, 0.5, 0.06, 0.3, -0.34, + -0.9, 0.8, -0.4, 0.86, 0.01, 1.02, -0.02, -1.5, 0.2 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("asset", d1), + std::make_pair("benchmark", d2), + std::make_pair("col_3", i1)); + + SharpeRatioVisitor sh_ratio; + const auto result = + df.single_act_visit("asset", "benchmark", + sh_ratio, true).get_result(); + + assert(fabs(result - 0.425631) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_RankVisitor() { + + std::cout << "\nTesting RankVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21 }; + StlVecType d2 = + { 10, 2, 3, 4, 5, 13, 7, 8, 9, 10, 1, 12, 13, 10, 15, 16, 17, 18, 19, + 20, 13 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("d1_col", d1), + std::make_pair("d2_col", d2), + std::make_pair("col_3", i1)); + + RankVisitor avg_rank_v(rank_policy::average); + RankVisitor first_rank_v(rank_policy::first); + RankVisitor last_rank_v(rank_policy::last); + RankVisitor actual_rank_v(rank_policy::actual); + const auto actual_result = + df.single_act_visit("d1_col", actual_rank_v).get_result(); + const auto avg_result = + df.single_act_visit("d1_col", avg_rank_v).get_result(); + const auto first_result = + df.single_act_visit("d1_col", first_rank_v).get_result(); + const auto last_result = + df.single_act_visit("d1_col", last_rank_v).get_result(); + + for (size_t i = 0; i < actual_result.size(); ++i) + assert(actual_result[i] == double(i)); + assert(actual_result == avg_result); + assert(actual_result == last_result); + assert(actual_result == first_result); + + const auto actual_result2 = + df.single_act_visit("d2_col", actual_rank_v).get_result(); + const auto avg_result2 = + df.single_act_visit("d2_col", avg_rank_v).get_result(); + const auto first_result2 = + df.single_act_visit("d2_col", first_rank_v).get_result(); + const auto last_result2 = + df.single_act_visit("d2_col", last_rank_v).get_result(); + + StlVecType ar_equal { 8, 1, 2, 3, 4, 12, 5, 6, 7, 9, 0, 11, 13, + 10, 15, 16, 17, 18, 19, 20, 14 }; + + assert(actual_result2 == ar_equal); + ar_equal = StlVecType { 9, 1, 2, 3, 4, 13, 5, 6, 7, 9, 0, 11, 13, + 9, 15, 16, 17, 18, 19, 20, 13 }; + assert(avg_result2 == ar_equal); + ar_equal = StlVecType { 8, 1, 2, 3, 4, 12, 5, 6, 7, 8, 0, 11, 12, + 8, 15, 16, 17, 18, 19, 20, 12 }; + assert(first_result2 == ar_equal); + ar_equal = StlVecType { 10, 1, 2, 3, 4, 14, 5, 6, 7, 10, 0, 11, 14, + 10, 15, 16, 17, 18, 19, 20, 14 }; + assert(last_result2 == ar_equal); +} + +// ----------------------------------------------------------------------------- + +static void test_SigmoidVisitor() { + + std::cout << "\nTesting SigmoidVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21 }; + StlVecType d2 = + { 0.23, 0.25, 0.256, 0.26, 0.268, 0.271, 0.279, 0.285, 0.29, 0.3, 0.5, + -0.2, 1, 0, 2, 0, -0.1, 0.55, 0.58, 0.6, 0.7 }; + StlVecType i1 = { 22, 23, 24, 25, 99 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("d1_col", d1), + std::make_pair("d2_col", d2), + std::make_pair("col_3", i1)); + + SigmoidVisitor sig_log(sigmoid_type::logistic); + SigmoidVisitor sig_alg(sigmoid_type::algebraic); + SigmoidVisitor sig_tan(sigmoid_type::hyperbolic_tan); + SigmoidVisitor sig_atan(sigmoid_type::arc_tan); + SigmoidVisitor sig_err(sigmoid_type::error_function); + SigmoidVisitor sig_gud(sigmoid_type::gudermannian); + SigmoidVisitor sig_smo(sigmoid_type::smoothstep); + const auto log_result = + df.single_act_visit("d1_col", sig_log).get_result(); + const auto alg_result = + df.single_act_visit("d1_col", sig_alg).get_result(); + const auto tan_result = + df.single_act_visit("d1_col", sig_tan).get_result(); + const auto atan_result = + df.single_act_visit("d1_col", sig_atan).get_result(); + const auto err_result = + df.single_act_visit("d1_col", sig_err).get_result(); + const auto gud_result = + df.single_act_visit("d1_col", sig_gud).get_result(); + const auto smo_result = + df.single_act_visit("d2_col", sig_smo).get_result(); + + StlVecType result { + 0.731059, 0.880797, 0.952574, 0.982014, 0.993307, 0.997527, 0.999089, + 0.999665, 0.999877, 0.999955, 0.999983, 0.999994, 0.999998, 0.999999, + 1, 1, 1, 1, 1, 1, 1 }; + + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - log_result[i]) < 0.00001); + + result = StlVecType { + 0.707107, 0.447214, 0.316228, 0.242536, 0.196116, 0.164399, 0.141421, + 0.124035, 0.110432, 0.0995037, 0.0905357, 0.0830455, 0.0766965, + 0.071247, 0.066519, 0.0623783, 0.058722, 0.05547, 0.0525588, + 0.0499376, 0.0475651 }; + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - alg_result[i]) < 0.00001); + + result = StlVecType { + 0.761594, 0.964028, 0.995055, 0.999329, 0.999909, 0.999988, 0.999998, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - tan_result[i]) < 0.00001); + + result = StlVecType { + 0.785398, 1.10715, 1.24905, 1.32582, 1.3734, 1.40565, 1.4289, 1.44644, + 1.46014, 1.47113, 1.48014, 1.48766, 1.49402, 1.49949, 1.50423, 1.50838, + 1.51204, 1.5153, 1.51821, 1.52084, 1.52321 }; + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - atan_result[i]) < 0.00001); + + result = StlVecType { + 0.842701, 0.995322, 0.999978, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 }; + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - err_result[i]) < 0.00001); + + result = StlVecType { + 0.865769, 1.30176, 1.4713, 1.53417, 1.55732, 1.56584, 1.56897, 1.57013, + 1.57055, 1.57071, 1.57076, 1.57078, 1.57079, 1.57079, 1.5708, 1.5708, + 1.5708, 1.5708, 1.5708, 1.5708, 1.5708 }; + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - gud_result[i]) < 0.00001); + + result = StlVecType { + 0.134366, 0.15625, 0.163054, 0.167648, 0.176974, 0.180518, 0.190088, + 0.197377, 0.203522, 0.216, 0.5, 0, 1, 0, 1, 0, 0, 0.57475, 0.618976, + 0.648, 0.784 }; + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - smo_result[i]) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static double my_max(const double &d1, const double &d2, const double &d3) { + + return (std::max({ d1, d2, d3 })); +} + +static void test_combine() { + + std::cout << "\nTesting combine( ) ..." << std::endl; + + StlVecType idx1 = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType idx2 = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType idx3 = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType idx4 = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; + StlVecType d1 = + { 1, 2, 100, 4, 5, 6, 7, 8, 9, 10, 11, 300, 13, 14, 15, 16, 17, 18, 19, + 20, 200 }; + StlVecType d2 = + { 1, 2, 1000, 4, 5, 6, 7, 8, 9, 10, 11, 3000, 13, 14, 15, 16, 17, 18, + 19, 20, 2000 }; + StlVecType d3 = + { 1, 2, 5000, 4, 5, 6, 7, 8, 9, 10, 11, 7000, 13, 14, 15, 16, 17, 18, + 19, 20, 8000 }; + StlVecType d4 = + { 1, 2, 10000, 4, 5, 6, 7, 8, 9, 10, 11, 20000, 13, 14, 15, 16, 17, + 18, 19, 20, 30000 }; + MyDataFrame df1; + MyDataFrame df2; + MyDataFrame df3; + MyDataFrame df4; + + df1.load_data(std::move(idx1), std::make_pair("d1_col", d1)); + df2.load_data(std::move(idx2), std::make_pair("d1_col", d2)); + df3.load_data(std::move(idx3), std::make_pair("d1_col", d3)); + df4.load_data(std::move(idx4), std::make_pair("d1_col", d4)); + + df1.load_column("d2_col", df1.combine("d1_col", df2, df3, my_max)); + + StlVecType result { + 1, 2, 5000, 4, 5, 6, 7, 8, 9, 10, 11, 7000, 13, 14, 15, 16, 17, 18, + 19, 20, 8000 }; + + assert(df1.get_column("d2_col") == result); +} + +// ----------------------------------------------------------------------------- + +static void test_RSIVisitor() { + + std::cout << "\nTesting RSIVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + RSIVisitor rsi(return_policy::percentage); + + df.single_act_visit("IBM_Close", rsi); + + assert(rsi.get_result().size() == 1708); + assert(std::abs(rsi.get_result()[1] - 41.0826) < 0.0001); + assert(std::abs(rsi.get_result()[9] - 35.7869) < 0.0001); + assert(std::abs(rsi.get_result()[11] - 37.3135) < 0.0001); + assert(std::abs(rsi.get_result()[15] - 46.4432) < 0.0001); + assert(std::abs(rsi.get_result()[26] - 53.6717) < 0.0001); + assert(std::abs(rsi.get_result()[1707] - 43.3186) < 0.0001); + assert(std::abs(rsi.get_result()[1699] - 47.0717) < 0.0001); + assert(std::abs(rsi.get_result()[1694] - 54.2938) < 0.0001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_remove_duplicates() { + + std::cout << "\nTesting remove_duplicates( ) ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, + 10UL, 13UL, 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, 15.0, 14.0, 2.0, 15.0, 12.0, 11.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 9.0, 10.0 }; + StlVecType dblvec2 = + { 100.0, 101.0, 102.0, 103.0, 101.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 }; + StlVecType intvec = { 1, 2, 3, 4, 2, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = + { "zz", "bb", "cc", "ww", "bb", "ff", "gg", "hh", "ii", "jj", + "kk", "ll", "mm", "nn", "oo" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("str_col", strvec)); + df.load_column("int_col", + std::move(intvec), + nan_policy::dont_pad_with_nans); + + auto result1 = + df.remove_duplicates + ("dbl_col", "int_col", false, remove_dup_spec::keep_first); + auto result2 = + df.remove_duplicates + ("dbl_col", "dbl_col_2", "int_col", "str_col", + false, remove_dup_spec::keep_first); + + StlVecType actual_d { + 100, 101, 102, 103, 105, 106.55, 107.34, 1.8, 111, 112, 113, + 114, 115, 116 }; + StlVecType actual_s { + "zz", "bb", "cc", "ww", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + + assert(result2.get_index().size() == 14); + assert(result2.get_column("dbl_col_2") == actual_d); + assert(result2.get_column("str_col") == actual_s); + + auto result3 = + df.remove_duplicates + ("dbl_col", "dbl_col_2", "int_col", "str_col", + false, remove_dup_spec::keep_last); + + actual_d = StlVecType { + 100, 102, 103, 101, 105, 106.55, 107.34, 1.8, 111, 112, 113, + 114, 115, 116 }; + actual_s = StlVecType { + "zz", "cc", "ww", "bb", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + assert(result3.get_index().size() == 14); + assert(result3.get_column("dbl_col_2") == actual_d); + assert(result3.get_column("str_col") == actual_s); + + auto result4 = + df.remove_duplicates + ("dbl_col", "dbl_col_2", "int_col", "str_col", + false, remove_dup_spec::keep_none); + + actual_d = StlVecType { + 100, 102, 103, 105, 106.55, 107.34, 1.8, 111, 112, 113, + 114, 115, 116 }; + actual_s = StlVecType { + "zz", "cc", "ww", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + assert(result4.get_index().size() == 13); + assert(result4.get_column("dbl_col_2") == actual_d); + assert(result4.get_column("str_col") == actual_s); + + auto result5 = + df.remove_duplicates + ("dbl_col", "dbl_col_2", "int_col", "str_col", + true, remove_dup_spec::keep_none); + + actual_d = StlVecType { + 100, 101, 102, 103, 101, 105, 106.55, 107.34, 1.8, 111, 112, 113, + 114, 115, 116 }; + actual_s = StlVecType { + "zz", "bb", "cc", "ww", "bb", "ff", "gg", "hh", "ii", "jj", "kk", + "ll", "mm", "nn", "oo" }; + assert(result5.get_index().size() == 15); + assert(result5.get_column("dbl_col_2") == actual_d); + assert(result5.get_column("str_col") == actual_s); + + auto result6 = + df.remove_duplicates + ("dbl_col", false, remove_dup_spec::keep_first); + + actual_d = StlVecType + { 100, 101, 102, 103, 105, 106.55, 107.34, 1.8, 111, 112, 113, 114, + 115, 116 }; + actual_s = StlVecType + { "zz", "bb", "cc", "ww", "ff", "gg", "hh", "ii", "jj", "kk", "ll", + "mm", "nn", "oo" + }; + assert(result6.get_index().size() == 14); + assert(result6.get_column("dbl_col_2") == actual_d); + assert(result6.get_column("str_col") == actual_s); +} + +// ----------------------------------------------------------------------------- + +static void test_bucketize() { + + std::cout << "\nTesting bucketize( ) ..." << std::endl; + + MyDataFrame df; + + try { + df.read("data/FORD.csv", io_format::csv2); + + auto fut = + df.bucketize_async( + bucket_type::by_distance, + 100, + LastVisitor(), + std::make_tuple("Date", "Date", LastVisitor()), + std::make_tuple("FORD_Close", "High", MaxVisitor()), + std::make_tuple("FORD_Close", "Low", MinVisitor()), + std::make_tuple("FORD_Close", "Open", FirstVisitor()), + std::make_tuple("FORD_Close", "Close", LastVisitor()), + std::make_tuple("FORD_Close", "Mean", MeanVisitor()), + std::make_tuple("FORD_Close", "Std", StdVisitor()), + std::make_tuple("FORD_Volume", "Volume", SumVisitor())); + MyDataFrame result = fut.get(); + + result.write + (std::cout, io_format::csv2); + + // FORD index is just an increasing number starting from 0. + // So, by_count should give the same result as by_distance + // + auto fut2 = + df.bucketize_async( + bucket_type::by_count, + 100, + LastVisitor(), + std::make_tuple("Date", "Date", LastVisitor()), + std::make_tuple("FORD_Close", "High", MaxVisitor()), + std::make_tuple("FORD_Close", "Low", MinVisitor()), + std::make_tuple("FORD_Close", "Open", FirstVisitor()), + std::make_tuple("FORD_Close", "Close", LastVisitor()), + std::make_tuple("FORD_Close", "Mean", MeanVisitor()), + std::make_tuple("FORD_Close", "Std", StdVisitor()), + std::make_tuple("FORD_Volume", "Volume", SumVisitor())); + MyDataFrame result2 = fut2.get(); + + assert((result.is_equal(result2))); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_groupby() { + + std::cout << "\nTesting groupby( ) ..." << std::endl; + + StlVecType ulgvec2 = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449, + 123450, 123451, 123450, 123452, 123450, 123455, 123450, + 123454, 123450, 123450, 123457, 123458, 123459, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = + { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, + 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; + StlVecType xdblvec2 = + { 10, 20, 11, 11, 30, 40, 50, 40, 60, 70, 80, 90, 50, 100, 11, 25, 20, + 30, 1, 3, 4, 12, 6, 2, 3, 10, 4, 5 }; + StlVecType dblvec22 = + { 0.998, 1.545, 0.056, 0.15678, 1.545, 0.923, 0.06743, + 0.1, -1.545, 0.07865, -0.9999, 1.545, 0.1002, -0.8888, + 0.14, 0.0456, -1.545, -0.8999, 0.01119, 0.8002, -1.545, + 0.2, 0.1056, 0.87865, -0.6999, 1.545, 0.1902, -1.545 }; + StlVecType strvec2 = + { "A", "B", "C", "D", "X", "Y", "W", "P", "Z", "S", "M", "B", + "A", "H", "X", "Q", "V", "P", "W", "K", "I", "L", "J", "N", + "Y", "G", "T", "U" }; + + MyDataFrame df; + + df.load_data(std::move(ulgvec2), + std::make_pair("xint_col", intvec2), + std::make_pair("dbl_col", xdblvec2), + std::make_pair("dbl_col_2", dblvec22), + std::make_pair("str_col", strvec2), + std::make_pair("ul_col", xulgvec2)); + + auto fut1 = + df.groupby1_async + (DF_INDEX_COL_NAME, + LastVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + auto result1 = fut1.get(); + + result1.write + (std::cout, io_format::csv2); + + auto fut2 = + df.groupby1_async + ("ul_col", + LastVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + auto result2 = fut2.get(); + + result2.write + (std::cout, io_format::csv2); + + auto fut3 = + df.groupby1_async + ("dbl_col_2", + MaxVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + auto result3 = fut3.get(); + + result3.write + (std::cout, io_format::csv2); +} + +// ----------------------------------------------------------------------------- + +static void test_groupby_2() { + +// Due to a bug in MS VC++ compiler being used by appveyor, this cannot be +// compiled by them +// +#ifndef _MSC_VER + + std::cout << "\nTesting groupby_2( ) ..." << std::endl; + + StlVecType ulgvec2 = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449, + 123450, 123451, 123450, 123452, 123450, 123455, 123450, + 123454, 123450, 123450, 123457, 123458, 123459, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = + { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, + 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; + StlVecType xdblvec2 = + { 10, 20, 11, 11, 30, 40, 50, 40, 60, 70, 80, 90, 50, 100, 11, 25, 20, + 30, 1, 3, 4, 12, 6, 2, 3, 10, 4, 5 }; + StlVecType dblvec22 = + { 0.998, 1.545, 0.056, 0.15678, 1.545, 0.923, 0.06743, + 0.1, -1.545, 0.07865, -0.9999, 1.545, 0.1002, -0.8888, + 0.14, 0.0456, -1.545, -0.8999, 0.01119, 0.8002, -1.545, + 0.2, 0.1056, 0.87865, -0.6999, 1.545, 0.1902, -1.545 }; + StlVecType strvec2 = + { "A", "B", "C", "D", "X", "Y", "W", "P", "Z", "S", "M", "B", + "A", "H", "X", "Q", "V", "P", "W", "K", "I", "L", "J", "N", + "Y", "G", "T", "U" }; + + MyDataFrame df; + + df.load_data(std::move(ulgvec2), + std::make_pair("xint_col", intvec2), + std::make_pair("dbl_col", xdblvec2), + std::make_pair("dbl_col_2", dblvec22), + std::make_pair("str_col", strvec2), + std::make_pair("ul_col", xulgvec2)); + + auto result1 = + df.groupby2 + (DF_INDEX_COL_NAME, + "dbl_col_2", + LastVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col_2", "cnt_dbl", CountVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + + result1.write + (std::cout, io_format::csv2); + + auto result2 = + df.groupby2 + ("dbl_col_2", + DF_INDEX_COL_NAME, + MinVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col_2", "cnt_dbl", CountVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + + result2.write + (std::cout, io_format::csv2); + + auto result3 = + df.groupby2 + ("dbl_col_2", + "xint_col", + MaxVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col_2", "cnt_dbl", CountVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + + result3.write + (std::cout, io_format::csv2); + + auto result4 = + df.groupby2 + ("xint_col", + "dbl_col_2", + FirstVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col_2", "cnt_dbl", CountVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + + result4.write + (std::cout, io_format::csv2); + + auto result5 = + df.groupby2 + ("str_col", + DF_INDEX_COL_NAME, + FirstVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col_2", "cnt_dbl", CountVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + + result5.write + (std::cout, io_format::csv2); + +#endif // !_MSC_VER +} + +// ----------------------------------------------------------------------------- + +static void test_groupby_3() { + +// Due to a bug in MS VC++ compiler being used by appveyor, this cannot be +// compiled by them +// +#ifndef _MSC_VER + + std::cout << "\nTesting groupby_3( ) ..." << std::endl; + + StlVecType ulgvec2 = + { 1, 2, 2, 2, 3, 4, 5, 5, 6, 6, 6, 7, 8, 9, 10, 10, 10, 11, 11, 11, 12, + 13, 13, 14, 15, 16, 17, 17 }; + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = + { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, + 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; + StlVecType xdblvec2 = + { 10, 20, 20, 11, 30, 40, 50, 50, 50, 50, 80, 90, 50, 11, 11, 25, 20, + 30, 1, 2, 2, 2, 6, 2, 3, 10, 4, 5 }; + StlVecType dblvec22 = + { 0.998, 1.545, 0.056, 0.15678, 1.545, 0.923, 0.06743, + 0.1, -1.545, 0.07865, -0.9999, 1.545, 0.1002, -0.8888, + 0.14, 0.0456, -1.545, -0.8999, 0.01119, 0.8002, -1.545, + 0.2, 0.1056, 0.87865, -0.6999, 1.545, 0.1902, -1.545 }; + StlVecType strvec2 = + { "A", "A", "A", "B", "C", "C", "C", "C", "Z", "S", "M", "B", + "A", "H", "X", "B", "Y", "Y", "W", "K", "K", "K", "J", "N", + "Y", "G", "K", "B" }; + + MyDataFrame df; + + df.load_data(std::move(ulgvec2), + std::make_pair("xint_col", intvec2), + std::make_pair("dbl_col", xdblvec2), + std::make_pair("dbl_col_2", dblvec22), + std::make_pair("str_col", strvec2), + std::make_pair("ul_col", xulgvec2)); + + auto result1 = + df.groupby3 + ("dbl_col", + DF_INDEX_COL_NAME, + "str_col", + LastVisitor(), + std::make_tuple("str_col", "sum_str", SumVisitor()), + std::make_tuple("xint_col", "max_int", MaxVisitor()), + std::make_tuple("xint_col", "min_int", MinVisitor()), + std::make_tuple("dbl_col_2", "cnt_dbl", CountVisitor()), + std::make_tuple("dbl_col", "sum_dbl", SumVisitor())); + + result1.write + (std::cout, io_format::csv2); + +#endif // !_MSC_VER +} + +// ----------------------------------------------------------------------------- + +static void test_io_format_csv2() { + + std::cout << "\nTesting io_format_csv2( ) ..." << std::endl; + + StlVecType ulgvec2 = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449, + 123450, 123451, 123450, 123452, 123450, 123455, 123450, + 123454, 123450, 123450, 123457, 123458, 123459, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = + { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, + 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; + StlVecType xdblvec2 = + { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, + 10.0, 4.25, 0.009, 8.0, 2.2222, 3.3333, + 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, + 12.0, 6.25, 2.009, 3.111, 10.0, 4.2222, 5.3333 }; + StlVecType dblvec22 = + { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, + 0.1, 0.0056, 0.07865, 0.0111, 0.1002, -0.8888, + 0.14, 0.0456, 0.078654, -0.8999, 0.8002, -0.9888, + 0.2, 0.1056, 0.87865, -0.6999, 0.4111, 0.1902, -0.4888 }; + StlVecType strvec2 = + { "4% of something", "Description 4/5", "This is bad", + "3.4% of GDP", "Market drops", "Market pulls back", + "$15 increase", "Running fast", "C++14 development", + "Some explanation", "More strings", "Bonds vs. Equities", + "Almost done", "XXXX04", + "XXXX2", "XXXX3", "XXXX4", "XXXX4", "XXXX5", "XXXX6", + "XXXX7", "XXXX10", "XXXX11", "XXXX02", "XXXX03" }; + StlVecType boolvec = + { true, true, true, false, false, true }; + + MyDataFrame df; + + df.load_data(std::move(ulgvec2), std::make_pair("ul_col", xulgvec2)); + df.load_column("xint_col", + std::move(intvec2), + nan_policy::dont_pad_with_nans); + df.load_column("str_col", + std::move(strvec2), + nan_policy::dont_pad_with_nans); + df.load_column("dbl_col", + std::move(xdblvec2), + nan_policy::dont_pad_with_nans); + df.load_column("dbl_col_2", + std::move(dblvec22), + nan_policy::dont_pad_with_nans); + df.load_column("bool_col", + std::move(boolvec), + nan_policy::dont_pad_with_nans); + + df.write(std::cout, io_format::csv2); + + MyDataFrame df_read; + + try { + df_read.read("data/csv2_format_data.csv", io_format::csv2); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } + df_read.write(std::cout, io_format::csv2); +} + +// ----------------------------------------------------------------------------- + +static void test_BoxCoxVisitor() { + + std::cout << "\nTesting BoxCoxVisitor{ } ..." << std::endl; + + const size_t item_cnt = 16; + MyDataFrame df; + RandGenParams p; + + p.mean = 5.6; + p.std = 0.5; + p.seed = 123; + p.min_value = -15; + p.max_value = 30; + + df.load_data(MyDataFrame::gen_sequence_index(0, item_cnt, 1), + std::make_pair("lognormal", + gen_lognormal_dist(item_cnt, p)), + std::make_pair("normal", + gen_normal_dist(item_cnt, p)), + std::make_pair("uniform_real", + gen_uniform_real_dist(item_cnt, p))); + + BoxCoxVisitor bc_v1(box_cox_type::original, 1.5, true); + const auto &result1 = + df.single_act_visit("lognormal", bc_v1).get_result(); + BoxCoxVisitor bc_v2(box_cox_type::original, 1.5, false); + const auto &result2 = + df.single_act_visit("uniform_real", bc_v2).get_result(); + BoxCoxVisitor bc_v3(box_cox_type::modulus, -0.5, false); + const auto &result3 = + df.single_act_visit("uniform_real", bc_v3).get_result(); + BoxCoxVisitor bc_v4(box_cox_type::exponential, -0.5, false); + const auto &result4 = + df.single_act_visit("uniform_real", bc_v4).get_result(); + + for(auto citer : result1) + std::cout << citer << ", "; + std::cout << std::endl; + for(auto citer : result2) + std::cout << citer << ", "; + std::cout << std::endl; + for(auto citer : result3) + std::cout << citer << ", "; + std::cout << std::endl; + for(auto citer : result4) + std::cout << citer << ", "; + std::cout << std::endl; +} + +// ----------------------------------------------------------------------------- + +static void test_NormalizeVisitor() { + + std::cout << "\nTesting NormalizeVisitor{ } ..." << std::endl; + + StlVecType ulgvec2 = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449, + 123450, 123451, 123450, 123452, 123450, 123455, 123450, + 123454, 123450, 123450, 123457, 123458, 123459, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; + StlVecType dblvec = + { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, + 10.0, 4.25, 0.009, 8.0, 2.2222, 3.3333, 15.6, + 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, + 12.0, 6.25, 2.009, 3.111, 10.0, 4.2222, 5.3333 }; + + MyDataFrame df; + + df.load_data(std::move(ulgvec2), std::make_pair("dbl_col", dblvec)); + + NormalizeVisitor norm_v; + StandardizeVisitor stand_v; + auto result = + df.single_act_visit("dbl_col", norm_v).get_result(); + StlVecType norm_result = { + 0.078603, 0.142743, 0.206882, 0.271022, 0.335161, 0.191841, 0.0635559, + 0.640818, 0.272016, 0, 0.512539, 0.141954, 0.213219, 1, 0.704958, + 0.336155, 0.0641396, 0.134821, 0.576679, 0.206093, 0.277359, 0.769098, + 0.400295, 0.128279, 0.198961, 0.640818, 0.270233, 0.341498, + }; + StlVecType stand_result = { + -1.00542, -0.744444, -0.48347, -0.222497, 0.0384758, -0.544669, + -1.06664, 1.28214, -0.218452, -1.32524, 0.760197, -0.747654, -0.457686, + 2.74359, 1.54312, 0.0425209, -1.06427, -0.776674, 1.02117, -0.48668, + -0.196713, 1.80409, 0.303494, -0.803293, -0.515701, 1.28214, -0.225707, + 0.06426 + }; + + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - norm_result[i]) < 0.00001); + result = df.single_act_visit("dbl_col", stand_v).get_result(); + for (size_t i = 0; i < result.size(); ++i) + assert(fabs(result[i] - stand_result[i]) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_HampelFilterVisitor() { + + std::cout << "\nTesting HampelFilterVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + StlVecType d1 = + { 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, + 0.34, 1.56, -12.34, 2.3, -0.34, -1.9, 0.387, + 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59, + 0.125, 1.9, -0.68, 2.0045, 50.8, -1.0, 0.78, + 0.48, 1.99, -0.97, 1.03, 8.678, -1.4, 1.59, + }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("dbl_col", d1)); + + HampelFilterVisitor hf_v(7, hampel_type::mean, 2); + auto result = + df.single_act_visit("dbl_col", hf_v).get_result(); + StlVecType hampel_result = { + 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, 0.34, 1.56, + std::numeric_limits::quiet_NaN(), 2.3, -0.34, -1.9, 0.387, + 0.123, 1.06, -0.65, 2.03, 0.4, -1, 0.59, 0.125, 1.9, -0.68, 2.0045, + std::numeric_limits::quiet_NaN(), -1, 0.78, 0.48, 1.99, + -0.97, 1.03, 8.678, -1.4, 1.59 + }; + const auto &column = df.get_column("dbl_col"); + + assert(result == 2); + for (size_t i = 0; i < hampel_result.size(); ++i) { + const auto v = column[i]; + + if (std::isnan(v)) + assert(std::isnan(hampel_result[i])); + else + assert(hampel_result[i] == v); + } +} + +// ----------------------------------------------------------------------------- + +static void test_PolyFitVisitor() { + + std::cout << "\nTesting PolyFitVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + MyDataFrame df; + + df.load_index(std::move(idx)); + df.load_column("X1", + { 1, 2, 3, 4, 5 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y1", + { 6, 7, 8, 9, 3 }, + nan_policy::dont_pad_with_nans); + df.load_column("X2", + { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y2", + { 0.0, 0.8, 0.9, 0.1, -0.8, -1.0 }, + nan_policy::dont_pad_with_nans); + + PolyFitVisitor poly_v1 (2); + PolyFitVisitor poly_v12 ( + 2, + [](const unsigned int &, std::size_t i) -> double { + const std::array weights = { 0.1, 0.8, 0.3, 0.5, 0.2 }; + + return (weights[i]); + }); + auto result1 = + df.single_act_visit("X1", "Y1", poly_v1).get_result(); + auto result12 = + df.single_act_visit("X1", "Y1", poly_v12).get_result(); + auto actual1 = StlVecType { 0.8, 5.6, -1 }; + auto actual1_y = + StlVecType { 5.4, 8, 8.6, 7.2, 3.8 }; + auto actual12 = + StlVecType { -1.97994, 6.99713, -1.14327 }; + + assert(std::fabs(poly_v1.get_residual() - 5.6) < 0.00001); + for (size_t i = 0; i < result1.size(); ++i) + assert(fabs(result1[i] - actual1[i]) < 0.00001); + for (size_t i = 0; i < poly_v1.get_y_fits().size(); ++i) + assert(fabs(poly_v1.get_y_fits()[i] - actual1_y[i]) < 0.01); + + assert(std::fabs(poly_v12.get_residual() - 0.70981) < 0.00001); + for (size_t i = 0; i < result12.size(); ++i) + assert(fabs(result12[i] - actual12[i]) < 0.00001); + + PolyFitVisitor poly_v2 (3); + auto result2 = + df.single_act_visit("X2", "Y2", poly_v2).get_result(); + auto actual2 = + StlVecType { -0.0396825, 1.69312, -0.813492, 0.087037 }; + + for (size_t i = 0; i < result2.size(); ++i) + assert(fabs(result2[i] - actual2[i]) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_HurstExponentVisitor() { + + std::cout << "\nTesting HurstExponentVisitor{ } ..." << std::endl; + + RandGenParams p; + + p.seed = 123; + p.min_value = 0; + p.max_value = 30; + + StlVecType d1 = gen_uniform_real_dist(1024, p); + StlVecType d2 = + { 0.04, 0.02, 0.05, 0.08, 0.02, -0.17, 0.05, 0.0 }; + StlVecType d3 = + { 0.04, 0.05, 0.055, 0.06, 0.061, 0.072, 0.073, 0.8 }; + + MyDataFrame df; + + df.load_index(MyDataFrame::gen_sequence_index(0, 1024, 1)); + df.load_column("d1_col", std::move(d1), nan_policy::dont_pad_with_nans); + df.load_column("d2_col", std::move(d2), nan_policy::dont_pad_with_nans); + df.load_column("d3_col", std::move(d3), nan_policy::dont_pad_with_nans); + + HurstExponentVisitor he_v1 ({ 1, 2, 4 }); + auto result1 = + df.single_act_visit("d2_col", he_v1).get_result(); + + assert(result1 - 0.865926 < 0.00001); + + HurstExponentVisitor he_v2 ({ 1, 2, 4, 5, 6, 7 }); + auto result2 = + df.single_act_visit("d1_col", he_v2).get_result(); + + assert(result2 - 0.487977 < 0.00001); + + HurstExponentVisitor he_v3 ({ 1, 2, 4 }); + auto result3 = + df.single_act_visit("d3_col", he_v3, true).get_result(); + + assert(result3 - 0.903057 < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_LogFitVisitor() { + + std::cout << "\nTesting LogFitVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + MyDataFrame df; + + df.load_index(std::move(idx)); + df.load_column("X1", + { 1, 2, 3, 4, 5 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y1", + { 6, 7, 8, 9, 3 }, + nan_policy::dont_pad_with_nans); + df.load_column("X2", + { 1, 2, 4, 6, 8 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y2", + { 1, 3, 4, 5, 6 }, + nan_policy::dont_pad_with_nans); + + LogFitVisitor log_v1; + auto result1 = + df.single_act_visit("X1", "Y1", log_v1).get_result(); + auto actual1 = + StlVecType { 6.98618, -0.403317 }; + auto actual1_y = + StlVecType { 6.98618, 6.70662, 6.54309, 6.42706, 6.33706 }; + + assert(std::fabs(log_v1.get_residual() - 20.9372) < 0.0001); + for (size_t i = 0; i < result1.size(); ++i) + assert(fabs(result1[i] - actual1[i]) < 0.00001); + for (size_t i = 0; i < log_v1.get_y_fits().size(); ++i) + assert(fabs(log_v1.get_y_fits()[i] - actual1_y[i]) < 0.01); + + LogFitVisitor log_v2; + auto result2 = + df.single_act_visit("X2", "Y2", log_v2).get_result(); + auto actual2 = StlVecType { 1.11199, 2.25859 }; + + assert(std::fabs(log_v2.get_residual() - 0.237476) < 0.00001); + for (size_t i = 0; i < result2.size(); ++i) + assert(fabs(result2[i] - actual2[i]) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_ExponentialFitVisitor() { + + std::cout << "\nTesting ExponentialFitVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + MyDataFrame df; + + df.load_index(std::move(idx)); + df.load_column("X1", + { 1, 2, 3, 4, 5 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y1", + { 6, 7, 8, 9, 3 }, + nan_policy::dont_pad_with_nans); + df.load_column("X2", + { 1, 2, 4, 6, 8 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y2", + { 1, 3, 4, 5, 6 }, + nan_policy::dont_pad_with_nans); + + ExponentialFitVisitor exp_v1; + auto result1 = + df.single_act_visit("X1", "Y1", exp_v1).get_result(); + auto actual1 = + StlVecType { 7.7647, 6.9316, 6.1879, 5.5239, 4.93126 }; + + assert(std::fabs(exp_v1.get_residual() - 22.2154) < 0.0001); + for (size_t i = 0; i < result1.size(); ++i) + assert(fabs(result1[i] - actual1[i]) < 0.0001); + + efit_v exp_v2; + auto result2 = + df.single_act_visit("X2", "Y2", exp_v2).get_result(); + auto actual2 = + StlVecType { 1.63751, 2.02776, 3.10952, 4.76833, 7.31206 }; + + assert(std::fabs(exp_v2.get_residual() - 3.919765) < 0.00001); + for (size_t i = 0; i < result2.size(); ++i) + assert(fabs(result2[i] - actual2[i]) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_LinearFitVisitor() { + + std::cout << "\nTesting LinearFitVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + MyDataFrame df; + + df.load_index(std::move(idx)); + df.load_column("X1", + { 1, 2, 3, 4, 5 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y1", + { 6, 7, 8, 9, 3 }, + nan_policy::dont_pad_with_nans); + df.load_column("X2", + { 1, 2, 4, 6, 8 }, + nan_policy::dont_pad_with_nans); + df.load_column("Y2", + { 1, 3, 4, 5, 6 }, + nan_policy::dont_pad_with_nans); + + LinearFitVisitor lin_v1; + auto result1 = + df.single_act_visit("X1", "Y1", lin_v1).get_result(); + auto actual1 = + StlVecType { 7.4, 7, 6.6, 6.2, 5.8 }; + + assert(std::fabs(lin_v1.get_residual() - 19.6) < 0.01); + for (size_t i = 0; i < result1.size(); ++i) + assert(fabs(result1[i] - actual1[i]) < 0.0001); + + linfit_v lin_v2; + auto result2 = + df.single_act_visit("X2", "Y2", lin_v2).get_result(); + auto actual2 = + StlVecType { 1.73171, 2.37805, 3.67073, 4.96341, 6.2561 }; + + assert(std::fabs(lin_v2.get_residual() - 1.097561) < 0.00001); + for (size_t i = 0; i < result2.size(); ++i) + assert(fabs(result2[i] - actual2[i]) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_ExpoSmootherVisitor() { + + std::cout << "\nTesting ExpoSmootherVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + StlVecType d1 = + { 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, + 0.34, 1.56, -12.34, 2.3, -0.34, -1.9, 0.387, + 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59, + 0.125, 1.9, -0.68, 2.0045, 50.8, -1.0, 0.78, + 0.48, 1.99, -0.97, 1.03, 8.678, -1.4, 1.59, + }; + StlVecType d1_copy = d1; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("dbl_col", d1)); + + MyDataFrame df2 = df; + + ExpoSmootherVisitor es_v1(1); + + df.single_act_visit("dbl_col", es_v1); + + const auto &col1 = df.get_column("dbl_col"); + + for (size_t i = 0; i < col1.size(); ++i) + assert(fabs(col1[i] - d1_copy[i]) < 0.00001); + + ExpoSmootherVisitor es_v2(0.3); + + df.single_act_visit("dbl_col", es_v2); + + auto actual2 = StlVecType { + 2.5, 2.485, 1.22, -1.185, -0.4, -0.209, 1.603, + 0.788, 0.706, -2.61, -7.948, 1.508, -0.808, -1.2139, + 0.3078, 0.4041, 0.547, 0.154, 1.541, -0.02, -0.523, + 0.4505, 0.6575, 1.126, 0.12535, 16.6431, 35.26, -0.466, + 0.69, 0.933, 1.102, -0.37, 3.3244, 5.6546, -0.503 + }; + + for (size_t i = 0; i < col1.size(); ++i) + assert(fabs(col1[i] - actual2[i]) < 0.0001); + + df.get_column("dbl_col") = d1_copy; + + ExpoSmootherVisitor es_v3(0.8); + + df.single_act_visit("dbl_col", es_v3); + + auto actual3 = StlVecType { + 2.5, 2.46, -0.83, -0.41, -0.9, 1.276, 1.158, + 0.468, 1.316, -9.56, -0.628, 0.188, -1.588, -0.0704, + 0.1758, 0.8726, -0.308, 1.494, 0.726, -0.72, 0.272, + 0.218, 1.545, -0.164, 1.4676, 41.0409, 9.36, 0.424, + 0.54, 1.688, -0.378, 0.63, 7.1484, 0.6156, 0.992 + }; + + for (size_t i = 0; i < col1.size(); ++i) + assert(fabs(col1[i] - actual3[i]) < 0.0001); + + ExpoSmootherVisitor es_v3_4 (0.8, 4); + const auto &col21 = df2.get_column("dbl_col"); + + df2.single_act_visit("dbl_col", es_v3_4); + + auto actual4 = StlVecType { + 2.5, 2.47952, 0.77968, -0.27248, -0.67824, 0.261712, 0.9932, 0.799584, + 0.97488, -4.33518, -3.8625, -1.05213, -0.877632, -0.632813, -0.087968, + 0.494816, 0.193696, 0.731832, 0.922821, 0.051104, -0.055568, 0.152752, + 0.895104, 0.532416, 0.838499, 21.5731, 20.6916, 7.763, 1.66618, + 1.1872, 0.509888, 0.343776, 3.87912, 3.11763, 1.43558 + }; + + for (size_t i = 0; i < col21.size(); ++i) + assert(fabs(col21[i] - actual4[i]) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_HWExpoSmootherVisitor() { + + std::cout << "\nTesting HWExpoSmootherVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + StlVecType d1 = + { 2.5, 2.45, -1.65, -0.1, -1.1, 1.87, 0.98, + 0.34, 1.56, -12.34, 2.3, -0.34, -1.9, 0.387, + 0.123, 1.06, -0.65, 2.03, 0.4, -1.0, 0.59, + 0.125, 1.9, -0.68, 2.0045, 50.8, -1.0, 0.78, + 0.48, 1.99, -0.97, 1.03, 8.678, -1.4, 1.59, + }; + StlVecType d1_copy = d1; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("dbl_col", d1)); + + HWExpoSmootherVisitor es_v1(1, 1); + + df.single_act_visit("dbl_col", es_v1); + + const auto &col1 = df.get_column("dbl_col"); + + for (size_t i = 0; i < col1.size(); ++i) + assert(fabs(col1[i] - d1_copy[i]) < 0.00001); + + HWExpoSmootherVisitor es_v2(0.3, 0.4); + + df.single_act_visit("dbl_col", es_v2); + + auto actual2 = StlVecType { + 2.5, 2.45, 1.185, -2.354, -0.6674, -0.64944, 2.17034, + 0.879202, 0.581521, -2.34309, -11.6799, 3.36809, -0.431147, -1.42459, + 0.821747, 0.638548, 0.950029, -0.0829826, 2.14921, -0.111474, -0.969884, + 0.627569, 0.633542, 1.60863, -0.307475, 17.1351, 49.2179, -6.59525, + -2.48915, -1.05849, 0.329906, -1.66206, 3.10917, 7.6669, -2.11746, + }; + + for (size_t i = 0; i < col1.size(); ++i) + assert(fabs(col1[i] - actual2[i]) < 0.0001); + + df.get_column("dbl_col") = d1_copy; + + HWExpoSmootherVisitor es_v3(0.8, 0.8); + + df.single_act_visit("dbl_col", es_v3); + + auto actual3 = StlVecType { + 2.5, 2.45, -0.84, -1.068, -0.7836, 1.13928, 1.60586, + 0.415171, 1.20303, -9.38739, -2.81748, 2.0925, -1.6295, -0.3283, + 0.49014, 0.893228, -0.153954, 1.25121, 1.10624, -0.904752, 0.0110497, + 0.42021, 1.51104, 0.113208, 1.11024, 41.3989, 17.2389, -6.28822, + -0.517644, 1.42847, -0.188306, 0.194339, 7.38127, 1.88585, -0.366429 + }; + + for (size_t i = 0; i < col1.size(); ++i) + assert(fabs(col1[i] - actual3[i]) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static StlVecType +add_columns(MyDataFrame::IndexVecType::const_iterator /*idx_begin*/, + MyDataFrame::IndexVecType::const_iterator /*idx_end*/, + StlVecType::const_iterator b_citer1, + StlVecType::const_iterator e_citer1, + StlVecType::const_iterator b_citer2, + StlVecType::const_iterator e_citer2, + StlVecType::const_iterator b_citer3, + StlVecType::const_iterator e_citer3) { + + const std::size_t col_s = + std::min ({ std::distance(b_citer1, e_citer1), + std::distance(b_citer2, e_citer2), + std::distance(b_citer3, e_citer3) }); + StlVecType result (col_s); + + for (std::size_t i = 0; i < col_s; ++i) + result[i] = + *(b_citer3 + i) + std::to_string(*(b_citer1 + i) + *(b_citer2 + i)); + return (result); +} + +// -------------------------------------- + +static void test_consolidate() { + + std::cout << "\nTesting consolidate( ) ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = { + 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, + 10UL, 13UL, 10UL, 15UL, 14UL + }; + StlVecType dblvec = { + 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 9.0, 10.0 + }; + StlVecType dblvec2 = { + 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, + 112.0, 113.0, 114.0, 115.0, 116.0 + }; + StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; + StlVecType strvec = { + "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", + "kk", "ll", "mm", "nn", "oo" + }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("dbl_col_2", dblvec2), + std::make_pair("str_col", strvec)); + df.load_column("int_col", std::move(intvec), + nan_policy::dont_pad_with_nans); + + df.consolidate + ("dbl_col", "dbl_col_2", "str_col", "new_str_col", add_columns, true); + assert(! df.has_column("dbl_col")); + assert(! df.has_column("dbl_col_2")); + assert(! df.has_column("str_col")); + assert(df.has_column("new_str_col")); + + const auto &new_str_col = + df.get_column("new_str_col"); + const StlVecType actual = { + "zz100.000000", "bb116.000000", "cc116.000000", "ww105.000000", + "ee105.000000", "ff117.000000", "gg117.550000", "hh115.340000", + "ii8.800000", "jj117.000000", "kk117.000000", "ll117.000000", + "mm117.000000", "nn124.000000", "oo126.000000" + }; + + for (size_t idx = 0; idx < actual.size(); ++idx) + assert(new_str_col[idx] == actual[idx]); +} + +// ----------------------------------------------------------------------------- + +static void test_ExtremumSubArrayVisitor() { + + std::cout << "\nTesting ExtremumSubArrayVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + MyDataFrame df; + + df.load_index(std::move(idx)); + df.load_column("dbl_col1", + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, + nan_policy::dont_pad_with_nans); + df.load_column("dbl_col2", + { -3, 1, -8, 4, -1, 2, 1, -5, 5 }, + nan_policy::dont_pad_with_nans); + + ExtremumSubArrayVisitor msa_v; + + df.visit("dbl_col1", msa_v); + assert(msa_v.get_result() == 55); + assert(msa_v.get_begin_idx() == 0); + assert(msa_v.get_end_idx() == 10); + + df.visit("dbl_col2", msa_v); + assert(msa_v.get_result() == 6); + assert(msa_v.get_begin_idx() == 3); + assert(msa_v.get_end_idx() == 7); +} + +// ----------------------------------------------------------------------------- + +static void test_NExtremumSubArrayVisitor() { + + std::cout << "\nTesting NExtremumSubArrayVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + MyDataFrame df; + + df.load_index(std::move(idx)); + df.load_column("dbl_col1", + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, + nan_policy::dont_pad_with_nans); + df.load_column("dbl_col2", + { -3, 1, -8, 4, -1, 2, 1, -5, 5 }, + nan_policy::dont_pad_with_nans); + + NExtremumSubArrayVisitor<5, double> msa_v; + + df.visit("dbl_col1", msa_v); + assert((msa_v.get_result()[0].sum == 21)); + assert((msa_v.get_result()[0].begin_index == 0)); + assert((msa_v.get_result()[0].end_index == 6)); + assert((msa_v.get_result()[1].sum == 28)); + assert((msa_v.get_result()[1].begin_index == 0)); + assert((msa_v.get_result()[1].end_index == 7)); + assert((msa_v.get_result()[2].sum == 36)); + assert((msa_v.get_result()[2].begin_index == 0)); + assert((msa_v.get_result()[2].end_index == 8)); + assert((msa_v.get_result()[3].sum == 45)); + assert((msa_v.get_result()[3].begin_index == 0)); + assert((msa_v.get_result()[3].end_index == 9)); + assert((msa_v.get_result()[4].sum == 55)); + assert((msa_v.get_result()[4].begin_index == 0)); + assert((msa_v.get_result()[4].end_index == 10)); + + NExtremumSubArrayVisitor<4, double> msa_v2; + + df.visit("dbl_col2", msa_v2); + assert((msa_v2.get_result()[0].sum == 1)); + assert((msa_v2.get_result()[0].begin_index == 1)); + assert((msa_v2.get_result()[0].end_index == 2)); + assert((msa_v2.get_result()[1].sum == 4)); + assert((msa_v2.get_result()[1].begin_index == 3)); + assert((msa_v2.get_result()[1].end_index == 4)); + assert((msa_v2.get_result()[2].sum == 5)); + assert((msa_v2.get_result()[2].begin_index == 3)); + assert((msa_v2.get_result()[2].end_index == 6)); + assert((msa_v2.get_result()[3].sum == 6)); + assert((msa_v2.get_result()[3].begin_index == 3)); + assert((msa_v2.get_result()[3].end_index == 7)); + + NMinSubArrayVisitor<5, double> msa_v3; + + df.visit("dbl_col1", msa_v3); + assert((msa_v3.get_result()[0].sum == 1)); + assert((msa_v3.get_result()[0].begin_index == 0)); + assert((msa_v3.get_result()[0].end_index == 1)); + + df.visit("dbl_col2", msa_v3); + assert((msa_v3.get_result()[0].sum == -3)); + assert((msa_v3.get_result()[0].begin_index == 0)); + assert((msa_v3.get_result()[0].end_index == 1)); + assert((msa_v3.get_result()[1].sum == -10)); + assert((msa_v3.get_result()[1].begin_index == 0)); + assert((msa_v3.get_result()[1].end_index == 3)); +} + +// ----------------------------------------------------------------------------- + +static void test_LowessVisitor() { + + std::cout << "\nTesting LowessVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + StlVecType x_vec = { + 0.5578196, 2.0217271, 2.5773252, 3.4140288, 4.3014084, 4.7448394, + 5.1073781, 6.5411662, 6.7216176, 7.2600583, 8.1335874, 9.1224379, + 1.9296663, 2.3797674, 3.2728619, 4.2767453, 5.3731026, 5.6476637, + 8.5605355, 8.5866354, 8.7572812, + }; + StlVecType y_vec = { + 18.63654, 103.49646, 150.35391, 190.51031, 208.70115, 213.71135, + 228.49353, 233.55387, 234.55054, 223.89225, 227.68339, 223.91982, + 168.01999, 164.95750, 152.61107, 160.78742, 168.55567, 152.42658, + 221.70702, 222.69040, 243.18828, + }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("indep_var", x_vec), + std::make_pair("dep_var", y_vec)); + + LowessVisitor l_v; + + df.single_act_visit("dep_var", "indep_var", l_v); + + auto actual_yfit = StlVecType { + 68.1432, 119.432, 122.75, 135.633, 142.724, 165.905, 169.447, 185.617, + 186.017, 191.865, 198.03, 202.234, 206.178, 215.053, 216.586, 220.408, + 226.671, 229.052, 229.185, 230.023, 231.657, + }; + + for (size_t idx = 0; idx < actual_yfit.size(); ++idx) + assert(fabs(l_v.get_result()[idx] - actual_yfit[idx]) < 0.001); + + auto actual_weights = StlVecType { + 0.641773, 0.653544, 0.940738, 0.865302, 0.990575, 0.971522, 0.92929, + 0.902444, 0.918228, 0.924041, 0.855054, 0.824388, 0.586045, 0.945216, + 0.94831, 0.998031, 0.999834, 0.991263, 0.993165, 0.972067, 0.990308, + }; + + for (size_t idx = 0; idx < actual_weights.size(); ++idx) + assert(fabs(l_v.get_residual_weights()[idx] - + actual_weights[idx]) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_StepRollAdopter() { + + std::cout << "\nTesting StepRollAdopter{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123463, + 123464, 123458, 123459, 123460, 123461, 123462 + }; + StlVecType d1 = + { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("col_1", d1)); + + StepRollAdopter, double> mean_roller( + MeanVisitor(), 5); + auto result = + df.single_act_visit("col_1", mean_roller).get_result(); + + assert(result == 1.0); + + StepRollAdopter, double> mean_roller2( + MeanVisitor(), 3); + + result = df.single_act_visit("col_1", mean_roller2).get_result(); + assert(result == 2.857142857142857); +} + +// ----------------------------------------------------------------------------- + +static void test_DecomposeVisitor() { + + std::cout << "\nTesting DecomposeVisitor{ } ..." << std::endl; + + StlVecType y_vec = + { 131.157, 131.367, 132.215, 132.725, 132.648, 130.585, 130.701, + 129.631, 129.168, 129.554, 129.467, 129.670, 128.397, 129.014, + 129.496, 131.067, 130.219, 128.947, 129.602, 128.118, 127.356, + 127.231, 127.154, 128.417, 129.091, 129.082, 128.937, 130.441, + 129.371, 129.294, 129.381, 129.564, 129.708, 130.701, 130.663, + 130.113, 130.046, 130.393, 128.026, 129.204, 130.530, 129.499, + 129.266, 129.357, 130.431, 131.810, 131.761, 131.675, 130.923, + 131.694, 133.005, 133.323, 134.152, 138.702, 137.719, 135.492, + 133.622, 134.518, 132.725, 131.839, 138.548, 140.996, 143.734, + 150.693, 151.108, 149.423, 150.416, 149.491, 151.273, 150.299, + 146.783, 147.173, 146.939, 147.290, 145.946, 142.624, 138.027, + 136.118, 129.650, 126.767, 130.809, 125.550, 130.732, 126.183, + 124.410, 114.748, 121.527, 114.904, 100.138, 105.144, + }; + MyDataFrame df; + + df.load_data(MyDataFrame::gen_sequence_index(0, y_vec.size(), 1), + std::make_pair("IBM_closes", y_vec)); + + DecomposeVisitor d_v (7, 0.6, 0.01); + + df.single_act_visit("IBM_closes", d_v); + + auto actual_trends = StlVecType + { 130.613, 130.55, 130.489, 130.43, 130.372, 130.317, 130.263, 130.211, + 130.161, 130.111, 130.064, 130.017, 129.972, 129.928, 129.885, + 129.842, 129.801, 129.76, 129.72, 129.681, 129.642, 129.603, 129.564, + 129.526, 129.49, 129.458, 129.435, 129.459, 129.496, 129.546, 129.61, + 129.688, 129.78, 129.885, 130.002, 130.129, 130.267, 130.414, + 130.568, 130.73, 130.898, 131.071, 131.248, 131.429, 131.613, + 131.801, 131.994, 132.193, 132.4, 132.618, 132.847, 133.089, 133.343, + 133.594, 133.814, 133.958, 133.982, 133.867, 133.633, 133.329, + 133.013, 132.715, 132.449, 132.214, 131.88, 131.594, 131.336, + 131.094, 130.862, 130.636, 130.412, 130.191, 129.97, 129.749, + 129.527, 129.305, 129.082, 128.858, 128.633, 128.406, 128.178, + 127.949, 127.717, 127.484, 127.249, 127.012, 126.773, 126.531, + 126.288, 126.043 + }; + + for (size_t idx = 0; idx < actual_trends.size(); ++idx) + assert(fabs(d_v.get_trend()[idx] - actual_trends[idx]) < 0.001); + + auto actual_seasonals = StlVecType + { 0.499135, -0.362488, -0.0226401, -0.138991, -0.774313, -0.152695, + 0.951993, 0.499135, -0.362488, -0.0226401, -0.138991, -0.774313, + -0.152695, 0.951993, 0.499135, -0.362488, -0.0226401, -0.138991, + -0.774313, -0.152695, 0.951993, 0.499135, -0.362488, -0.0226401, + -0.138991, -0.774313, -0.152695, 0.951993, 0.499135, -0.362488, + -0.0226401, -0.138991, -0.774313, -0.152695, 0.951993, 0.499135, + -0.362488, -0.0226401, -0.138991, -0.774313, -0.152695, 0.951993, + 0.499135, -0.362488, -0.0226401, -0.138991, -0.774313, -0.152695, + 0.951993, 0.499135, -0.362488, -0.0226401, -0.138991, -0.774313, + -0.152695, 0.951993, 0.499135, -0.362488, -0.0226401, -0.138991, + -0.774313, -0.152695, 0.951993, 0.499135, -0.362488, -0.0226401, + -0.138991, -0.774313, -0.152695, 0.951993, 0.499135, -0.362488, + -0.0226401, -0.138991, -0.774313, -0.152695, 0.951993, 0.499135, + -0.362488, -0.0226401, -0.138991, -0.774313, -0.152695, 0.951993, + 0.499135, -0.362488, -0.0226401, -0.138991, -0.774313, -0.152695 + }; + + for (size_t idx = 0; idx < actual_seasonals.size(); ++idx) + assert(fabs(d_v.get_seasonal()[idx] - actual_seasonals[idx]) < 0.00001); + + auto actual_residuals = StlVecType + { 0.0450645, 1.17948, 1.74866, 2.43421, 3.04989, 0.420796, -0.514129, + -1.07918, -0.630027, -0.534809, -0.457752, 0.427013, -1.42233, + -1.86582, -0.887751, 1.58716, 0.440736, -0.674248, 0.656095, + -1.41002, -3.2376, -2.87093, -2.04782, -1.08684, -0.260342, 0.397977, + -0.345524, 0.0298508, -0.623855, 0.110697, -0.206247, 0.014974, + 0.702412, 0.968872, -0.290624, -0.515527, 0.141332, 0.0017837, + -2.40348, -0.751754, -0.215182, -2.52399, -2.48155, -1.7098, + -1.15976, 0.147774, 0.541487, -0.36517, -2.4292, -1.42281, 0.520609, + 0.256637, 0.94848, 5.88205, 4.05781, 0.58219, -0.858726, 1.01365, + -0.88524, -1.35148, 6.30971, 8.4335, 10.3326, 17.98, 19.5905, + 17.8516, 19.2189, 19.171, 20.5634, 18.7112, 15.8714, 17.3448, + 16.992, 17.6804, 17.1932, 13.4718, 7.99313, 6.76106, 1.3799, + -1.61643, 2.7699, -1.62422, 3.16745, -2.25312, -3.33817, -11.9014, + -5.22295, -11.4883, -25.3757, -20.7463 + }; + + for (size_t idx = 0; idx < actual_residuals.size(); ++idx) + assert(fabs(d_v.get_residual()[idx] - actual_residuals[idx]) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_DT_IBM_data() { + + std::cout << "\nTesting DT_IBM_data( ) ..." << std::endl; + + typedef StdDataFrame DT_DataFrame; + + DT_DataFrame df; + + try { + df.read("data/DT_IBM.csv", io_format::csv2); + + assert(df.get_column("IBM_Open")[0] == 98.4375); + assert(df.get_column("IBM_Close")[18] == 97.875); + assert(df.get_index()[18] == DateTime(20001128)); + assert(fabs(df.get_column("IBM_High")[5030] - 111.8) < 0.001); + assert(df.get_column("IBM_Volume")[5022] == 21501100L); + assert(df.get_index()[5020] == DateTime(20201016)); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// -------------------------------------------------------------------- + +static void test_TTestVisitor() { + + std::cout << "\nTesting TTestVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466, + 123467, 123468, 123469, 123470, 123471, 123472, 123473, + }; + StlVecType x_vec = { + 0.5578196, 2.0217271, 2.5773252, 3.4140288, 4.3014084, 4.7448394, + 5.1073781, 6.5411662, 6.7216176, 7.2600583, 8.1335874, 9.1224379, + 1.9296663, 2.3797674, 3.2728619, 4.2767453, 5.3731026, 5.6476637, + 8.5605355, 8.5866354, 8.7572812, + }; + StlVecType y_vec = { + 18.63654, 103.49646, 150.35391, 190.51031, 208.70115, 213.71135, + 228.49353, 233.55387, 234.55054, 223.89225, 227.68339, 223.91982, + 168.01999, 164.95750, 152.61107, 160.78742, 168.55567, 152.42658, + 221.70702, 222.69040, 243.18828, + }; + StlVecType z_vec = { + 0.5578296, 2.0217275, 2.5773252, 3.4140288, 4.3084084, 4.7448394, + 5.1079781, 6.5411662, 6.1216176, 7.1600583, 8.1335174, 9.1223379, + 1.9296663, 2.3727674, 3.2728619, 4.2767953, 5.3731056, 5.6426637, + 8.5602355, 8.5866354, 8.7572819, + }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("x_data", x_vec), + std::make_pair("y_data", y_vec), + std::make_pair("z_data", z_vec)); + + TTestVisitor tt_v (false); + + df.visit("x_data", "y_data", tt_v); + assert(fabs(tt_v.get_result() - -15.3585) < 0.0001); + assert(tt_v.get_deg_freedom() == 40); + + df.visit("x_data", "z_data", tt_v); + assert(fabs(tt_v.get_result() - 0.0421697) < 0.000001); + assert(tt_v.get_deg_freedom() == 40); + + TTestVisitor tt_v2 (true); + + df.visit("x_data", "y_data", tt_v2); + assert(fabs(tt_v2.get_result() - -15.9748) < 0.0001); + assert(tt_v2.get_deg_freedom() == 20); + + df.visit("x_data", "z_data", tt_v2); + assert(fabs(tt_v2.get_result() - 1.16854) < 0.00001); + assert(tt_v2.get_deg_freedom() == 20); +} + +// ----------------------------------------------------------------------------- + +static void test_MassIndexVisitor() { + + std::cout << "\nTesting MassIndexVisitor{ } ..." << std::endl; + + StlVecType idx = { + 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, + 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, + 123469, 123470, 123471, 123472, 123473, + }; + StlVecType high = { + 121.75, 122.75, 124.83, 124.39, 135.5, 132, 128.25, 127.15, 126.94, + 125.22, 126.43, 127.35, 120.15, 117.69, 116.06, 116.62, 114.9, 112.22, + 109.73, 109.64, 111.8, + }; + StlVecType low = { + 118.82, 121.05, 121.59, 122.32, 129.77, 127.6, 126.44, 124.46, 125.13, + 123.85, 124.66, 125.08, 116.84, 117.69, 112.98, 115.53, 111.84, 110.03, + 105.92, 106.55, 107.75, + }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("high", high), + std::make_pair("low", low)); + + MassIndexVisitor mi_v (3, 5); + + // The values here are nonsensical, because the time-series and periods + // are too short + // + df.single_act_visit("high", "low", mi_v); + + assert(mi_v.get_result().size() == 21); + assert(std::isnan(mi_v.get_result()[0])); + assert(std::isnan(mi_v.get_result()[3])); + assert(fabs(mi_v.get_result()[6] - 5.21367) < 0.00001); + assert(fabs(mi_v.get_result()[10] - 4.3473) < 0.0001); + assert(fabs(mi_v.get_result()[20] - 5.51902) < 0.00001); + assert(fabs(mi_v.get_result()[17] - 4.87194) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_HullRollingMeanVisitor() { + + std::cout << "\nTesting HullRollingMeanVisitor{ } ..." << std::endl; + + StlVecType ulgvec2 = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449, + 123450, 123451, 123450, 123452, 123450, 123455, 123450, + 123454, 123450, 123450, 123457, 123458, 123459, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; + StlVecType dbl_vec = + { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, + 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2, + 2, 3, 5, 6, 7, 7, 8, 1, 10, 11, 9, 8, 7, 6 }; + MyDataFrame df; + + df.load_data(std::move(ulgvec2), std::make_pair("col_1", dbl_vec)); + + HullRollingMeanVisitor hull_roller(6); + const auto &result = + df.single_act_visit("col_1", hull_roller).get_result(); + + assert(result.size() == 42); + assert(std::isnan(result[0])); + assert(std::isnan(result[1])); + assert(std::isnan(result[4])); + assert(abs(result[5] - 4.19048) < 0.00001); + assert(abs(result[6] - 5.42857) < 0.00001); + assert(abs(result[10] - 7.61905) < 0.00001); + assert(abs(result[20] - 2.95238) < 0.00001); + assert(abs(result[41] - 6.8254) < 0.0001); + assert(abs(result[40] - 7.84127) < 0.00001); + assert(abs(result[39] - 9.93651) < 0.00001); + assert(abs(result[38] - 10.9365) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_RollingMidValueVisitor() { + + std::cout << "\nTesting RollingMidValueVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, + 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, + 123469, 123470, 123471, 123472, 123473, + }; + StlVecType high = { + 121, 122, 124, 124.5, 135.5, 132, 128, 127, 126, + 125, 126.5, 127, 120, 117, 116, 116.5, 114, 112, + 109, 109.5, 111, + }; + StlVecType low = { + 118, 121, 121.5, 122, 129, 127, 126, 124, 125, + 123, 124, 125, 116, 114, 112, 115, 111, 110, + 105, 106, 107, + }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("high", high), + std::make_pair("low", low)); + + RollingMidValueVisitor rmv_v (5); + + df.single_act_visit("low", "high", rmv_v); + assert(rmv_v.get_result().size() == 21); + assert(std::isnan(rmv_v.get_result()[0])); + assert(std::isnan(rmv_v.get_result()[1])); + assert(std::isnan(rmv_v.get_result()[3])); + assert(rmv_v.get_result()[4] == 126.75); + assert(rmv_v.get_result()[5] == 128.25); + assert(rmv_v.get_result()[10] == 125.5); + assert(rmv_v.get_result()[11] == 125); + assert(rmv_v.get_result()[20] == 109.5); + assert(rmv_v.get_result()[19] == 110.75); +} + +// ----------------------------------------------------------------------------- + +static void test_DrawdownVisitor() { + + std::cout << "\nTesting DrawdownVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, + 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, + 123469, 123470, 123471, 123472, 123473, + }; + StlVecType close = { + 121, 122, 124, 124.5, 135.5, 132, 128, 127, 126, + 125, 126.5, 127, 120, 135.6, 116, 116.5, 114, 112, + 109, 136, 111, + }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("close", close)); + + DrawdownVisitor dd_v; + + df.single_act_visit("close", dd_v); + assert(dd_v.get_result().size() == 21); + assert(dd_v.get_log_drawdown().size() == 21); + assert(dd_v.get_pct_drawdown().size() == 21); + assert(dd_v.get_result()[0] == 0); + assert(dd_v.get_log_drawdown()[0] == 0); + assert(dd_v.get_pct_drawdown()[0] == 0); + assert(dd_v.get_result()[3] == 0); + assert(dd_v.get_log_drawdown()[3] == 0); + assert(dd_v.get_pct_drawdown()[3] == 0); + assert(dd_v.get_result()[13] == 0); + assert(dd_v.get_log_drawdown()[13] == 0); + assert(dd_v.get_pct_drawdown()[13] == 0); + assert(dd_v.get_result()[19] == 0); + assert(dd_v.get_log_drawdown()[19] == 0); + assert(dd_v.get_pct_drawdown()[19] == 0); + assert(dd_v.get_result()[8] == 9.5); + assert(std::abs(dd_v.get_log_drawdown()[8] - 0.0726897) < 0.000001); + assert(std::abs(dd_v.get_pct_drawdown()[8] - 0.0701107) < 0.000001); + assert(std::abs(dd_v.get_result()[15] - 19.1) < 0.00001); + assert(std::abs(dd_v.get_log_drawdown()[15] - 0.151818) < 0.00001); + assert(std::abs(dd_v.get_pct_drawdown()[15] - 0.140855) < 0.00001); + assert(std::abs(dd_v.get_result()[20] - 25) < 0.00001); + assert(std::abs(dd_v.get_log_drawdown()[20] - 0.203125) < 0.00001); + assert(std::abs(dd_v.get_pct_drawdown()[20] - 0.183824) < 0.00001); +} + +// ----------------------------------------------------------------------------- + +static void test_WilliamPrcRVisitor() { + + std::cout << "\nTesting WilliamPrcRVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + WilliamPrcRVisitor wpr_v; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Close", wpr_v); + + assert(wpr_v.get_result().size() == 5031); + assert(std::isnan(wpr_v.get_result()[0])); + assert(std::isnan(wpr_v.get_result()[12])); + assert(std::abs(wpr_v.get_result()[14] - -46.0784) < 0.0001); + assert(std::abs(wpr_v.get_result()[20] - -85.2941) < 0.0001); + assert(std::abs(wpr_v.get_result()[5030] - -73.2151) < 0.0001); + assert(std::abs(wpr_v.get_result()[5026] - -98.3939) < 0.0001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_PSLVisitor() { + + std::cout << "\nTesting PSLVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + PSLVisitor psl_v; + + df.single_act_visit("IBM_Close", "IBM_Open", psl_v); + assert(psl_v.get_result().size() == 5031); + assert(std::isnan(psl_v.get_result()[0])); + assert(std::isnan(psl_v.get_result()[12])); + assert(std::abs(psl_v.get_result()[14] - 57.1429) < 0.0001); + assert(std::abs(psl_v.get_result()[20] - 42.8571) < 0.0001); + assert(std::abs(psl_v.get_result()[5030] - 42.8571) < 0.0001); + assert(std::abs(psl_v.get_result()[5026] - 42.8571) < 0.0001); + assert(std::abs(psl_v.get_result()[5021] - 57.1429) < 0.0001); + + df.single_act_visit("IBM_Close", psl_v); + assert(psl_v.get_result().size() == 5031); + assert(std::isnan(psl_v.get_result()[0])); + assert(std::isnan(psl_v.get_result()[12])); + assert(std::abs(psl_v.get_result()[14] - 50) < 0.0001); + assert(std::abs(psl_v.get_result()[20] - 42.8571) < 0.0001); + assert(std::abs(psl_v.get_result()[5030] - 42.8571) < 0.0001); + assert(std::abs(psl_v.get_result()[5026] - 42.8571) < 0.0001); + assert(std::abs(psl_v.get_result()[5021] - 42.8571) < 0.0001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_CCIVisitor() { + + std::cout << "\nTesting CCIVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + CCIVisitor cci_v; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Close", cci_v); + + assert(cci_v.get_result().size() == 5031); + assert(std::isnan(cci_v.get_result()[0])); + assert(std::isnan(cci_v.get_result()[12])); + assert(std::abs(cci_v.get_result()[14] - 30.3681) < 0.0001); + assert(std::abs(cci_v.get_result()[20] - -178.37) < 0.001); + assert(std::abs(cci_v.get_result()[5030] - -77.4585) < 0.0001); + assert(std::abs(cci_v.get_result()[5026] - -127.358) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_EntropyVisitor() { + + std::cout << "\nTesting EntropyVisitor{ } ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, + 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, + 123469, 123470, 123471, 123472, 123473, 22, 23, 24, 25, 26, 27, 28 + }; + StlVecType close = + { 1.80, 2.80, 1.90, 14.00, 1.10, 6.00, 13.00, 8.00, 9.00, 2.80, 1.90, + 4.30, 20.00, 1.85, 3.00, 34.00, 67.00, 23.00, 87.00, 9.00, 45.00, + 1.00, 11.00, 456.00, 34.00, 7.00, 7778.00, 5.00 + }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("close", close)); + + EntropyVisitor e_v (5); + + df.single_act_visit("close", e_v); + + assert(e_v.get_result().size() == 28); + assert(std::isnan(e_v.get_result()[0])); + assert(std::isnan(e_v.get_result()[7])); + assert(std::abs(e_v.get_result()[8] - 2.18974) < 0.00001); + assert(std::abs(e_v.get_result()[10] - 1.98477) < 0.00001); + assert(std::abs(e_v.get_result()[14] - 1.7154) < 0.0001); + assert(std::abs(e_v.get_result()[27] - 0.596666) < 0.00001); + assert(std::abs(e_v.get_result()[25] - 0.822228) < 0.00001); + assert(std::abs(e_v.get_result()[22] - 1.49397) < 0.0001); +} + +// ----------------------------------------------------------------------------- + +static void test_GarmanKlassVolVisitor() { + + std::cout << "\nTesting GarmanKlassVolVisitor{ } ..." << std::endl; + + typedef StdDataFrame512 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + GarmanKlassVolVisitor gkv_v; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", gkv_v); + + assert(gkv_v.get_result().size() == 5031); + assert(std::isnan(gkv_v.get_result()[0])); + assert(std::isnan(gkv_v.get_result()[28])); + assert(std::abs(gkv_v.get_result()[29] - 0.392054) < 0.00001); + assert(std::abs(gkv_v.get_result()[34] - 0.401494) < 0.00001); + assert(std::abs(gkv_v.get_result()[5030] - 0.230028) < 0.00001); + assert(std::abs(gkv_v.get_result()[5026] - 0.221514) < 0.00001); + assert(std::abs(gkv_v.get_result()[5021] - 0.216817) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_YangZhangVolVisitor() { + + std::cout << "\nTesting YangZhangVolVisitor{ } ..." << std::endl; + + MyDataFrame df; + + try { + df.read("data/FORD.csv", io_format::csv2); + + YangZhangVolVisitor yz_v; + + df.single_act_visit + ("FORD_Low", "FORD_High", "FORD_Open", "FORD_Close", yz_v); + + assert(yz_v.get_result().size() == 12265); + assert(std::isnan(yz_v.get_result()[0])); + assert(std::isnan(yz_v.get_result()[29])); + assert(std::abs(yz_v.get_result()[30] - 0.169461) < 0.00001); + assert(std::abs(yz_v.get_result()[35] - 0.181149) < 0.00001); + assert(std::abs(yz_v.get_result()[12264] - 0.292034) < 0.00001); + assert(std::abs(yz_v.get_result()[12260] - 0.279347) < 0.00001); + assert(std::abs(yz_v.get_result()[12255] - 0.293528) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_no_index_writes() { + + std::cout << "\nTesting no_index_writes ..." << std::endl; + + StlVecType ulgvec2 = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449, + 123450, 123451, 123450, 123452, 123450, 123455, 123450, + 123454, 123450, 123450, 123457, 123458, 123459, 123450, + 123441, 123442, 123432, 123450, 123450, 123435, 123450 }; + StlVecType xulgvec2 = ulgvec2; + StlVecType intvec2 = + { 1, 2, 3, 4, 5, 3, 7, 3, 9, 10, 3, 2, 3, 14, + 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 36, 2, 45, 2 }; + StlVecType xdblvec2 = + { 1.2345, 2.2345, 3.2345, 4.2345, 5.2345, 3.0, 0.9999, + 10.0, 4.25, 0.009, 8.0, 2.2222, 3.3333, + 11.0, 5.25, 1.009, 2.111, 9.0, 3.2222, 4.3333, + 12.0, 6.25, 2.009, 3.111, 10.0, 4.2222, 5.3333 }; + StlVecType dblvec22 = + { 0.998, 0.3456, 0.056, 0.15678, 0.00345, 0.923, 0.06743, + 0.1, 0.0056, 0.07865, 0.0111, 0.1002, -0.8888, + 0.14, 0.0456, 0.078654, -0.8999, 0.8002, -0.9888, + 0.2, 0.1056, 0.87865, -0.6999, 0.4111, 0.1902, -0.4888 }; + StlVecType strvec2 = + { "4% of something", "Description 4/5", "This is bad", + "3.4% of GDP", "Market drops", "Market pulls back", + "$15 increase", "Running fast", "C++14 development", + "Some explanation", "More strings", "Bonds vs. Equities", + "Almost done", "XXXX04", + "XXXX2", "XXXX3", "XXXX4", "XXXX4", "XXXX5", "XXXX6", + "XXXX7", "XXXX10", "XXXX11", "XXXX02", "XXXX03" }; + StlVecType boolvec = + { true, true, true, false, false, true }; + + MyDataFrame df; + + df.load_data(std::move(ulgvec2), std::make_pair("ul_col", xulgvec2)); + df.load_column("xint_col", + std::move(intvec2), + nan_policy::dont_pad_with_nans); + df.load_column("str_col", + std::move(strvec2), + nan_policy::dont_pad_with_nans); + df.load_column("dbl_col", + std::move(xdblvec2), + nan_policy::dont_pad_with_nans); + df.load_column("dbl_col_2", + std::move(dblvec22), + nan_policy::dont_pad_with_nans); + df.load_column("bool_col", + std::move(boolvec), + nan_policy::dont_pad_with_nans); + + df.write(std::cout, io_format::csv, 6, false); + std::cout << std::endl; + df.write(std::cout, io_format::csv, 6, true); + std::cout << '\n' << std::endl; + + df.write(std::cout, io_format::csv2, 6, false); + std::cout << std::endl; + df.write(std::cout, io_format::csv2, 12, true); + std::cout << '\n' << std::endl; + + df.write(std::cout, io_format::json, 12, false); + std::cout << std::endl; + df.write(std::cout, io_format::json, 12, true); +} + +// ----------------------------------------------------------------------------- + +static void test_no_index_reads() { + + std::cout << "\nTesting no_index_reads ..." << std::endl; + + MyDataFrame df; + MyDataFrame df2; + MyDataFrame df3; + + try { + df.read("data/csv2_format_data.csv", io_format::csv2, false); + df.read("data/csv2_format_data_2.csv", io_format::csv2, true); + df.read("data/csv2_format_data_no_index.csv", io_format::csv2, true); + df.write(std::cout, io_format::csv2); + + std::cout << '\n' << std::endl; + df2.read("data/sample_data.csv", io_format::csv, false); + df2.read("data/sample_data_2.csv", io_format::csv, true); + df2.read("data/sample_data_no_index.csv", io_format::csv, true); + df2.write(std::cout, io_format::csv2); + + std::cout << '\n' << std::endl; + df3.read("data/sample_data.json", io_format::json, false); + df3.read("data/sample_data_2.json", io_format::json, true); + df3.read("data/sample_data_no_index.json", io_format::json, true); + df3.write(std::cout, io_format::csv2); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_KamaVisitor() { + + std::cout << "\nTesting KamaVisitor{ } ..." << std::endl; + + typedef StdDataFrame512 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + KamaVisitor k_v; + + df.single_act_visit("IBM_Close", k_v); + + assert(k_v.get_result().size() == 5031); + assert(std::isnan(k_v.get_result()[0])); + assert(std::isnan(k_v.get_result()[8])); + assert(k_v.get_result()[9] == 0); + assert(std::abs(k_v.get_result()[29] - 31.6281) < 0.0001); + assert(std::abs(k_v.get_result()[34] - 47.2049) < 0.0001); + assert(std::abs(k_v.get_result()[5030] - 112.438) < 0.001); + assert(std::abs(k_v.get_result()[5026] - 118.829) < 0.001); + assert(std::abs(k_v.get_result()[5021] - 125.937) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_FisherTransVisitor() { + + std::cout << "\nTesting FisherTransVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + FisherTransVisitor ft_v; + + df.single_act_visit("IBM_Low", "IBM_High", ft_v); + + assert(ft_v.get_result().size() == 5031); + assert(std::isnan(ft_v.get_result()[0])); + assert(std::isnan(ft_v.get_result()[7])); + assert(ft_v.get_result()[8] == 0); + assert(std::abs(ft_v.get_result()[29] - -1.47814) < 0.00001); + assert(std::abs(ft_v.get_result()[34] - -2.12198) < 0.00001); + assert(std::abs(ft_v.get_result()[5030] - -2.82683) < 0.00001); + assert(std::abs(ft_v.get_result()[5026] - -2.12427) < 0.00001); + assert(std::abs(ft_v.get_result()[5021] - -0.266774) < 0.000001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_PercentPriceOSCIVisitor() { + + std::cout << "\nTesting PercentPriceOSCIVisitor{ } ..." << std::endl; + + typedef StdDataFrame512 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + PercentPriceOSCIVisitor ppo_v; + + df.single_act_visit("IBM_Close", ppo_v); + + assert(ppo_v.get_result().size() == 5031); + assert(std::isnan(ppo_v.get_result()[0])); + assert(std::isnan(ppo_v.get_result()[24])); + assert(std::abs(ppo_v.get_result()[25] - -1.01156) < 0.00001); + assert(std::abs(ppo_v.get_result()[29] - -1.63896) < 0.00001); + assert(std::abs(ppo_v.get_result()[34] - -3.17651) < 0.00001); + assert(std::abs(ppo_v.get_result()[5030] - -3.46821) < 0.00001); + assert(std::abs(ppo_v.get_result()[5026] - -0.00785639) < 0.00001); + assert(std::abs(ppo_v.get_result()[5021] - 1.69995) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_SlopeVisitor() { + + std::cout << "\nTesting SlopeVisitor{ } ..." << std::endl; + + typedef StdDataFrame512 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + SlopeVisitor s_v (10, true, true); + + df.single_act_visit("IBM_Close", s_v); + + assert(s_v.get_result().size() == 5031); + assert(std::isnan(s_v.get_result()[0])); + assert(std::isnan(s_v.get_result()[9])); + assert(std::abs(s_v.get_result()[10] - 4.64508) < 0.00001); + assert(std::abs(s_v.get_result()[29] - -40.5718) < 0.0001); + assert(std::abs(s_v.get_result()[34] - -47.07) < 0.001); + assert(std::abs(s_v.get_result()[5030] - -54.9783) < 0.0001); + assert(std::abs(s_v.get_result()[5026] - -56.2923) < 0.0001); + assert(std::abs(s_v.get_result()[5021] - 19.341) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_UltimateOSCIVisitor() { + + std::cout << "\nTesting UltimateOSCIVisitor{ } ..." << std::endl; + + typedef StdDataFrame512 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + UltimateOSCIVisitor uo_v; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Close", uo_v); + + assert(uo_v.get_result().size() == 5031); + assert(std::isnan(uo_v.get_result()[0])); + assert(std::isnan(uo_v.get_result()[26])); + assert(std::abs(uo_v.get_result()[27] - 41.3509) < 0.0001); + assert(std::abs(uo_v.get_result()[31] - 32.1768) < 0.0001); + assert(std::abs(uo_v.get_result()[5030] - 45.076) < 0.001); + assert(std::abs(uo_v.get_result()[5026] - 31.3935) < 0.0001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_shifting_column() { + + std::cout << "\nTesting shifting columns ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = + { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }; + MyDataFrame df; + + df.load_data(std::move(idx), std::make_pair("dbl_col", d1)); + + df.load_column("dbl_col t-1", + df.shift("dbl_col", 1, shift_policy::down)); + df.load_column("dbl_col t-2", + df.shift("dbl_col", 2, shift_policy::down)); + df.load_column("dbl_col t-3", + df.shift("dbl_col", 3, shift_policy::down)); + df.load_column("dbl_col t-4", + df.shift("dbl_col", 4, shift_policy::down)); + df.load_column("dbl_col t-5", + df.shift("dbl_col", 5, shift_policy::down)); + df.load_column("dbl_col t-6", + df.shift("dbl_col", 6, shift_policy::down)); + df.load_column("dbl_col t-7", + df.shift("dbl_col", 7, shift_policy::down)); + + df.load_column("dbl_col t+1", + df.shift("dbl_col", 1, shift_policy::up)); + df.load_column("dbl_col t+2", + df.shift("dbl_col", 2, shift_policy::up)); + df.load_column("dbl_col t+3", + df.shift("dbl_col", 3, shift_policy::up)); + df.load_column("dbl_col t+4", + df.shift("dbl_col", 4, shift_policy::up)); + df.load_column("dbl_col t+5", + df.shift("dbl_col", 5, shift_policy::up)); + df.load_column("dbl_col t+6", + df.shift("dbl_col", 6, shift_policy::up)); + df.load_column("dbl_col t+7", + df.shift("dbl_col", 7, shift_policy::up)); + + df.write(std::cout, io_format::csv2); +} + +// ----------------------------------------------------------------------------- + +static void test_UlcerIndexVisitor() { + + std::cout << "\nTesting UlcerIndexVisitor{ } ..." << std::endl; + + typedef StdDataFrame1024 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + UlcerIndexVisitor ui_v; + + df.single_act_visit("IBM_Close", ui_v); + + assert(ui_v.get_result().size() == 5031); + assert(std::isnan(ui_v.get_result()[0])); + assert(std::isnan(ui_v.get_result()[12])); + assert(ui_v.get_result()[13] == 0); + assert(std::abs(ui_v.get_result()[27] - 6.10378) < 0.00001); + assert(std::abs(ui_v.get_result()[31] - 8.48463) < 0.00001); + assert(std::abs(ui_v.get_result()[5030] - 11.1348) < 0.0001); + assert(std::abs(ui_v.get_result()[5026] - 7.98096) < 0.00001); + + UlcerIndexVisitor ui_v2 (14, false); + + df.single_act_visit("IBM_Close", ui_v2); + + assert(ui_v2.get_result().size() == 5031); + assert(std::isnan(ui_v2.get_result()[0])); + assert(std::isnan(ui_v2.get_result()[12])); + assert(ui_v2.get_result()[13] == 0); + assert(std::abs(ui_v2.get_result()[27] - 1.6313) < 0.0001); + assert(std::abs(ui_v2.get_result()[31] - 2.26761) < 0.00001); + assert(std::abs(ui_v2.get_result()[5030] - 2.9759) < 0.0001); + assert(std::abs(ui_v2.get_result()[5026] - 2.133) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_RSXVisitor() { + + std::cout << "\nTesting RSXVisitor{ } ..." << std::endl; + + typedef StdDataFrame1024 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + RSXVisitor rsx_v; + + df.single_act_visit("IBM_Close", rsx_v); + + assert(rsx_v.get_result().size() == 5031); + assert(std::isnan(rsx_v.get_result()[0])); + assert(std::isnan(rsx_v.get_result()[12])); + assert(rsx_v.get_result()[13] == 0); + assert(rsx_v.get_result()[14] == 50.0); + assert(rsx_v.get_result()[26] == 50.0); + assert(std::abs(rsx_v.get_result()[29] - 44.2103) < 0.0001); + assert(std::abs(rsx_v.get_result()[34] - 37.4583) < 0.0001); + assert(std::abs(rsx_v.get_result()[5030] - 21.0277) < 0.0001); + assert(std::abs(rsx_v.get_result()[5026] - 31.1071) < 0.0001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_TTMTrendVisitor() { + + std::cout << "\nTesting TTMTrendVisitor{ } ..." << std::endl; + + typedef StdDataFrame512 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/IBM.csv", io_format::csv2); + + TTMTrendVisitor ttmt_v; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Close", ttmt_v); + + assert(ttmt_v.get_result().size() == 5031); + assert((! ttmt_v.get_result()[0])); + assert((! ttmt_v.get_result()[8])); + assert(ttmt_v.get_result()[9]); + assert(ttmt_v.get_result()[13]); + assert((! ttmt_v.get_result()[14])); + assert(ttmt_v.get_result()[5030]); + assert((! ttmt_v.get_result()[5027])); + assert(ttmt_v.get_result()[5016]); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_ParabolicSARVisitor() { + + std::cout << "\nTesting ParabolicSARVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + ParabolicSARVisitor psar_v; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Close", psar_v); + + assert(psar_v.get_result().size() == 1721); + assert((! psar_v.get_result()[0])); + assert((psar_v.get_result()[2])); + assert((psar_v.get_result()[3])); + assert((psar_v.get_result()[26])); + assert((! psar_v.get_result()[1720])); + assert((! psar_v.get_result()[1718])); + assert((psar_v.get_result()[1709])); + + assert(psar_v.get_longs().size() == 1721); + assert(std::isnan(psar_v.get_longs()[0])); + assert(std::isnan(psar_v.get_longs()[2])); + assert(std::abs(psar_v.get_longs()[5] - 185.401) < 0.001); + assert(std::abs(psar_v.get_longs()[11] - 183.86) < 0.01); + assert(std::isnan(psar_v.get_longs()[18])); + assert(std::isnan(psar_v.get_longs()[1720])); + assert(std::abs(psar_v.get_longs()[1708] - 124.46) < 0.01); + + assert(psar_v.get_shorts().size() == 1721); + assert(std::isnan(psar_v.get_shorts()[0])); + assert(std::abs(psar_v.get_shorts()[2] - 187.4) < 0.1); + assert(std::isnan(psar_v.get_shorts()[6])); + assert(std::abs(psar_v.get_shorts()[7] - 190.35) < 0.01); + assert(std::abs(psar_v.get_shorts()[1720] - 120.7) < 0.1); + assert(std::isnan(psar_v.get_shorts()[1708])); + + assert(psar_v.get_acceleration_factors().size() == 1721); + assert(psar_v.get_acceleration_factors()[0] == 0.02); + assert(psar_v.get_acceleration_factors()[2] == 0.02); + assert(psar_v.get_acceleration_factors()[15] == 0.02); + assert(psar_v.get_acceleration_factors()[16] == 0.04); + assert(psar_v.get_acceleration_factors()[1720] == 0.14); + assert(std::abs(psar_v.get_acceleration_factors()[1718] - 0.12) < 0.01); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_EBSineWaveVisitor() { + + std::cout << "\nTesting EBSineWaveVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + EBSineWaveVisitor ebsw_v; + + df.single_act_visit("IBM_Close", ebsw_v); + + assert(ebsw_v.get_result().size() == 1721); + assert(std::isnan(ebsw_v.get_result()[0])); + assert(std::abs(ebsw_v.get_result()[5] - 0.927837) < 0.00001); + assert(std::abs(ebsw_v.get_result()[14] - -0.560866) < 0.00001); + assert(std::abs(ebsw_v.get_result()[25] - -0.36883) < 0.00001); + assert(std::abs(ebsw_v.get_result()[1720] - -0.901317) < 0.00001); + assert(std::abs(ebsw_v.get_result()[1712] - -0.730321) < 0.00001); + assert(std::abs(ebsw_v.get_result()[1707] - 0.841759) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_EhlerSuperSmootherVisitor() { + + std::cout << "\nTesting EhlerSuperSmootherVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + EhlerSuperSmootherVisitor ssf_v2; // poles = 2 + EhlerSuperSmootherVisitor ssf_v3(3); // poles = 3 + + df.single_act_visit("IBM_Close", ssf_v2); + df.single_act_visit("IBM_Close", ssf_v3); + + assert(ssf_v2.get_result().size() == 1721); + assert(ssf_v3.get_result().size() == 1721); + + assert(std::abs(ssf_v2.get_result()[0] - 185.53) < 0.01); + assert(std::abs(ssf_v2.get_result()[5] - 188.117) < 0.001); + assert(std::abs(ssf_v2.get_result()[14] - 185.497) < 0.001); + assert(std::abs(ssf_v2.get_result()[25] - 174.736) < 0.001); + assert(std::abs(ssf_v2.get_result()[1720] - 109.294) < 0.001); + assert(std::abs(ssf_v2.get_result()[1712] - 123.43) < 0.01); + assert(std::abs(ssf_v2.get_result()[1707] - 127.323) < 0.001); + + assert(std::abs(ssf_v3.get_result()[0] - 185.53) < 0.01); + assert(std::abs(ssf_v3.get_result()[5] - 186.159) < 0.001); + assert(std::abs(ssf_v3.get_result()[14] - 186.681) < 0.001); + assert(std::abs(ssf_v3.get_result()[25] - 174.294) < 0.001); + assert(std::abs(ssf_v3.get_result()[1720] - 109.187) < 0.001); + assert(std::abs(ssf_v3.get_result()[1712] - 124.31) < 0.01); + assert(std::abs(ssf_v3.get_result()[1707] - 127.603) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_VarIdxDynAvgVisitor() { + + std::cout << "\nTesting VarIdxDynAvgVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + VarIdxDynAvgVisitor vidya_v; + + df.single_act_visit("IBM_Close", vidya_v); + + assert(vidya_v.get_result().size() == 1721); + + assert(std::isnan(vidya_v.get_result()[0])); + assert(std::isnan(vidya_v.get_result()[12])); + assert(vidya_v.get_result()[13] == 0); + assert(std::abs(vidya_v.get_result()[14] - 2.70068) < 0.00001); + assert(std::abs(vidya_v.get_result()[21] - 57.6682) < 0.0001); + assert(std::abs(vidya_v.get_result()[31] - 106.451) < 0.001); + assert(std::abs(vidya_v.get_result()[1720] - 118.962) < 0.001); + assert(std::abs(vidya_v.get_result()[1712] - 123.811) < 0.001); + assert(std::abs(vidya_v.get_result()[1707] - 123.712) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_AbsVisitor() { + + std::cout << "\nTesting AbsVisitor{ } ..." << std::endl; + + MyDataFrame df; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, + 10UL, 15UL, 14UL }; + StlVecType dblvec = + { 0.0, -15.0, 14.0, 15.0, -1.0, 12.0, 11.0, -8.0, 15.0, 6.0, -1, + 4.0, 14.0, 14.0, -20.0 }; + StlVecType intvec = + { -1, 2, 3, 4, 5, 8, -6, 7, 11, -14, 9, -3, -5, -4, 9 }; + StlVecType strvec = + { "zz", "bb", "zz", "ww", "ee", "ff", "gg", "zz", "ii", "jj", "kk", + "ll", "mm", "ee", "" }; + + df.load_data(std::move(idxvec), + std::make_pair("dbl_col", dblvec), + std::make_pair("int_col", intvec), + std::make_pair("str_col", strvec)); + + AbsVisitor abs_v; + AbsVisitor abs_v_int; + auto result = + df.visit("dbl_col", abs_v).get_result(); + auto result_int = + df.single_act_visit("int_col", abs_v_int).get_result(); + + assert(result == 5); + assert(result_int == 6); + + StlVecType abs_dblvec = + { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, 1, + 4.0, 14.0, 14.0, 20.0 }; + StlVecType abs_intvec = + { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9, 3, 5, 4, 9 }; + + assert((df.get_column("dbl_col") == abs_dblvec)); + assert((df.get_column("int_col") == abs_intvec)); +} + +// ----------------------------------------------------------------------------- + +static void test_PivotPointSRVisitor() { + + std::cout << "\nTesting PivotPointSRVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + PivotPointSRVisitor ppsr_v; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Close", ppsr_v); + + assert(ppsr_v.get_result().size() == 1721); + assert(std::abs(ppsr_v.get_result()[0] - 186.043) < 0.001); + assert(std::abs(ppsr_v.get_result()[5] - 187.81) < 0.01); + assert(std::abs(ppsr_v.get_result()[14] - 182.387) < 0.001); + assert(std::abs(ppsr_v.get_result()[25] - 176.627) < 0.001); + assert(std::abs(ppsr_v.get_result()[1720] - 110.403) < 0.001); + assert(std::abs(ppsr_v.get_result()[1712] - 118.12) < 0.01); + assert(std::abs(ppsr_v.get_result()[1707] - 125.57) < 0.01); + + assert(ppsr_v.get_resist_1().size() == 1721); + assert(std::abs(ppsr_v.get_resist_1()[0] - 186.887) < 0.001); + assert(std::abs(ppsr_v.get_resist_1()[5] - 189.07) < 0.01); + assert(std::abs(ppsr_v.get_resist_1()[14] - 184.063) < 0.001); + assert(std::abs(ppsr_v.get_resist_1()[25] - 178.183) < 0.001); + assert(std::abs(ppsr_v.get_resist_1()[1720] - 113.057) < 0.001); + assert(std::abs(ppsr_v.get_resist_1()[1712] - 119.4) < 0.01); + assert(std::abs(ppsr_v.get_resist_1()[1707] - 126.68) < 0.01); + + assert(ppsr_v.get_support_1().size() == 1721); + assert(std::abs(ppsr_v.get_support_1()[0] - 184.687) < 0.001); + assert(std::abs(ppsr_v.get_support_1()[5] - 186.12) < 0.01); + assert(std::abs(ppsr_v.get_support_1()[14] - 181.053) < 0.001); + assert(std::abs(ppsr_v.get_support_1()[25] - 175.693) < 0.001); + assert(std::abs(ppsr_v.get_support_1()[1720] - 109.007) < 0.001); + assert(std::abs(ppsr_v.get_support_1()[1712] - 116.09) < 0.01); + assert(std::abs(ppsr_v.get_support_1()[1707] - 123.99) < 0.01); + + assert(ppsr_v.get_resist_2().size() == 1721); + assert(std::abs(ppsr_v.get_resist_2()[0] - 188.243) < 0.001); + assert(std::abs(ppsr_v.get_resist_2()[5] - 190.76) < 0.01); + assert(std::abs(ppsr_v.get_resist_2()[14] - 185.397) < 0.001); + assert(std::abs(ppsr_v.get_resist_2()[25] - 179.117) < 0.001); + assert(std::abs(ppsr_v.get_resist_2()[1720] - 114.453) < 0.001); + assert(std::abs(ppsr_v.get_resist_2()[1712] - 121.43) < 0.01); + assert(std::abs(ppsr_v.get_resist_2()[1707] - 128.26) < 0.01); + + assert(ppsr_v.get_support_2().size() == 1721); + assert(std::abs(ppsr_v.get_support_2()[0] - 183.843) < 0.001); + assert(std::abs(ppsr_v.get_support_2()[5] - 184.86) < 0.01); + assert(std::abs(ppsr_v.get_support_2()[14] - 179.377) < 0.001); + assert(std::abs(ppsr_v.get_support_2()[25] - 174.137) < 0.001); + assert(std::abs(ppsr_v.get_support_2()[1720] - 106.353) < 0.001); + assert(std::abs(ppsr_v.get_support_2()[1712] - 114.81) < 0.01); + assert(std::abs(ppsr_v.get_support_2()[1707] - 122.88) < 0.01); + + assert(ppsr_v.get_resist_3().size() == 1721); + assert(std::abs(ppsr_v.get_resist_3()[0] - 189.087) < 0.001); + assert(std::abs(ppsr_v.get_resist_3()[5] - 192.02) < 0.01); + assert(std::abs(ppsr_v.get_resist_3()[14] - 187.073) < 0.001); + assert(std::abs(ppsr_v.get_resist_3()[25] - 180.673) < 0.001); + assert(std::abs(ppsr_v.get_resist_3()[1720] - 117.107) < 0.001); + assert(std::abs(ppsr_v.get_resist_3()[1712] - 122.71) < 0.01); + assert(std::abs(ppsr_v.get_resist_3()[1707] - 129.37) < 0.01); + + assert(ppsr_v.get_support_3().size() == 1721); + assert(std::abs(ppsr_v.get_support_3()[0] - 182.487) < 0.001); + assert(std::abs(ppsr_v.get_support_3()[5] - 183.17) < 0.01); + assert(std::abs(ppsr_v.get_support_3()[14] - 178.043) < 0.001); + assert(std::abs(ppsr_v.get_support_3()[25] - 173.203) < 0.001); + assert(std::abs(ppsr_v.get_support_3()[1720] - 104.957) < 0.001); + assert(std::abs(ppsr_v.get_support_3()[1712] - 112.78) < 0.01); + assert(std::abs(ppsr_v.get_support_3()[1707] - 121.3) < 0.01); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_AvgDirMovIdxVisitor() { + + std::cout << "\nTesting AvgDirMovIdxVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + adx_v adx_v (3, 4); + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Close", adx_v); + + assert(adx_v.get_result().size() == 1721); + assert(adx_v.get_result()[0] == 0); + assert(std::abs(adx_v.get_result()[10] - 0.73029) < 0.00001); + assert(std::abs(adx_v.get_result()[14] - 0.735792) < 0.000001); + assert(std::abs(adx_v.get_result()[25] - 0.691082) < 0.000001); + assert(std::abs(adx_v.get_result()[1720] - 0.372184) < 0.000001); + assert(std::abs(adx_v.get_result()[1712] - 0.703394) < 0.000001); + assert(std::abs(adx_v.get_result()[1707] - 0.383002) < 0.000001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_HoltWinterChannelVisitor() { + + std::cout << "\nTesting HoltWinterChannelVisitor{ } ..." << std::endl; + + typedef StdDataFrame256 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + hwc_v hwc; + + df.single_act_visit("IBM_Close", hwc); + + assert(hwc.get_result().size() == 1721); + assert(std::abs(hwc.get_result()[0] - 185.53) < 0.001); + assert(std::abs(hwc.get_result()[5] - 187.349) < 0.001); + assert(std::abs(hwc.get_result()[14] - 186.534) < 0.001); + assert(std::abs(hwc.get_result()[25] - 171.785) < 0.001); + assert(std::abs(hwc.get_result()[1720] - 111.435) < 0.001); + assert(std::abs(hwc.get_result()[1712] - 126.602) < 0.001); + assert(std::abs(hwc.get_result()[1707] - 126.443) < 0.001); + + assert(hwc.get_upper_band().size() == 1721); + assert(std::abs(hwc.get_upper_band()[0] - 185.53) < 0.001); + assert(std::abs(hwc.get_upper_band()[5] - 188.322) < 0.001); + assert(std::abs(hwc.get_upper_band()[14] - 187.683) < 0.001); + assert(std::abs(hwc.get_upper_band()[25] - 174.518) < 0.001); + assert(std::abs(hwc.get_upper_band()[1720] - 117.324) < 0.001); + assert(std::abs(hwc.get_upper_band()[1712] - 129.354) < 0.001); + assert(std::abs(hwc.get_upper_band()[1707] - 129.713) < 0.001); + + assert(hwc.get_lower_band().size() == 1721); + assert(std::abs(hwc.get_lower_band()[0] - 185.53) < 0.001); + assert(std::abs(hwc.get_lower_band()[5] - 186.375) < 0.001); + assert(std::abs(hwc.get_lower_band()[14] - 185.386) < 0.001); + assert(std::abs(hwc.get_lower_band()[25] - 169.053) < 0.001); + assert(std::abs(hwc.get_lower_band()[1720] - 105.545) < 0.001); + assert(std::abs(hwc.get_lower_band()[1712] - 123.851) < 0.001); + assert(std::abs(hwc.get_lower_band()[1707] - 123.173) < 0.001); + + assert(hwc.get_pct_diff().size() == 1721); + assert(std::isnan(hwc.get_pct_diff()[0])); + assert(std::isnan(hwc.get_pct_diff()[2])); + assert(std::abs(hwc.get_pct_diff()[5] - 0.516164) < 0.00001); + assert(std::abs(hwc.get_pct_diff()[14] - -1.15602) < 0.00001); + assert(std::abs(hwc.get_pct_diff()[25] - 1.50004) < 0.00001); + assert(std::abs(hwc.get_pct_diff()[1720] - 0.51913) < 0.00001); + assert(std::abs(hwc.get_pct_diff()[1712] - -1.17764) < 0.00001); + assert(std::abs(hwc.get_pct_diff()[1707] - 0.294638) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_HeikinAshiCndlVisitor() { + + std::cout << "\nTesting HeikinAshiCndlVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + ha_cdl_v ha; + + df.single_act_visit + ("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", ha); + + assert(ha.get_result().size() == 1721); + assert(std::abs(ha.get_result()[0] - 186.335) < 0.001); + assert(std::abs(ha.get_result()[10] - 188.02) < 0.001); + assert(std::abs(ha.get_result()[14] - 182.147) < 0.001); + assert(std::abs(ha.get_result()[25] - 176.38) < 0.001); + assert(std::abs(ha.get_result()[1720] - 109.778) < 0.001); + assert(std::abs(ha.get_result()[1712] - 118.54) < 0.001); + assert(std::abs(ha.get_result()[1707] - 125.82) < 0.001); + + assert(ha.get_open().size() == 1721); + assert(std::abs(ha.get_open()[0] - 186.37) < 0.001); + assert(std::abs(ha.get_open()[10] - 186.432) < 0.001); + assert(std::abs(ha.get_open()[14] - 185.131) < 0.001); + assert(std::abs(ha.get_open()[25] - 174.113) < 0.001); + assert(std::abs(ha.get_open()[1720] - 109.256) < 0.001); + assert(std::abs(ha.get_open()[1712] - 125.839) < 0.001); + assert(std::abs(ha.get_open()[1707] - 128.034) < 0.001); + + assert(ha.get_high().size() == 1721); + assert(std::abs(ha.get_high()[0] - 187.4) < 0.001); + assert(std::abs(ha.get_high()[10] - 188.99) < 0.01); + assert(std::abs(ha.get_high()[14] - 185.131) < 0.001); + assert(std::abs(ha.get_high()[25] - 177.56) < 0.001); + assert(std::abs(ha.get_high()[1720] - 111.8) < 0.001); + assert(std::abs(ha.get_high()[1712] - 125.839) < 0.001); + assert(std::abs(ha.get_high()[1707] - 128.034) < 0.001); + + assert(ha.get_low().size() == 1721); + assert(std::abs(ha.get_low()[0] - 185.2) < 0.001); + assert(std::abs(ha.get_low()[10] - 186.432) < 0.001); + assert(std::abs(ha.get_low()[14] - 180.71) < 0.001); + assert(std::abs(ha.get_low()[25] - 174.113) < 0.001); + assert(std::abs(ha.get_low()[1720] - 107.75) < 0.001); + assert(std::abs(ha.get_low()[1712] - 116.84) < 0.001); + assert(std::abs(ha.get_low()[1707] - 124.46) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_FastFourierTransVisitor() { + + std::cout << "\nTesting FastFourierTransVisitor{ } ..." << std::endl; + + using cx = std::complex; + + StlVecType idxvec = + { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL }; + StlVecType dblvec = { 1, 1, 1, 1, 0, 0, 0, 0 }; + StlVecType strvec = + { "11", "22", "33", "44", "55", "66", "-77", "88" }; + StlVecType cplxvec = + { cx(0, 0), cx(1, 1), cx(3, 3), cx(4, 4), + cx(4, 4), cx(3, 3), cx(1, 1) }; + + MyDataFrame df; + + df.load_data(std::move(idxvec), + std::make_pair("str_col", strvec), + std::make_pair("dbl_col", dblvec)); + df.load_column("cplx_col", cplxvec, nan_policy::dont_pad_with_nans); + + fft_v fft; + + df.single_act_visit("dbl_col", fft); + + for (auto citer : fft.get_result()) + std::cout << citer << " | "; + std::cout << std::endl; + df.load_column("FFT int col", fft.get_result(), + nan_policy::dont_pad_with_nans); + + fft_v, unsigned long, 64> i_fft (true); + + df.single_act_visit>("FFT int col", i_fft); + + for (auto citer : i_fft.get_result()) + std::cout << citer << " | "; + std::cout << std::endl; + + // The case of size is not a power of 2 + // + fft_v fft_cx; + + df.single_act_visit("cplx_col", fft_cx); + + for (auto citer : fft_cx.get_result()) + std::cout << citer << " | "; + std::cout << std::endl; + df.load_column("FFT int col 2", fft_cx.get_result(), + nan_policy::dont_pad_with_nans); + + fft_v i_fft2 (true); + + df.single_act_visit>("FFT int col 2", i_fft2); + + for (auto citer : i_fft2.get_result()) + std::cout << citer << " | "; + std::cout << std::endl; + + try { + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df2; + + df2.read("data/SHORT_IBM.csv", io_format::csv2); + + fft_v fft2; + + df2.single_act_visit("IBM_Close", fft2); + df2.load_column("FFT Close", fft2.get_result()); + + fft_v i_fft2 (true); + + df2.single_act_visit("FFT Close", i_fft2); + + /* + for (auto citer : i_fft2.get_result()) + std::cout << citer << ", "; + std::cout << std::endl; + */ + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_CenterOfGravityVisitor() { + + std::cout << "\nTesting CenterOfGravityVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + cog_v cog; + + df.single_act_visit("IBM_Close", cog); + + assert(cog.get_result().size() == 1721); + assert(std::isnan(cog.get_result()[0])); + assert(std::isnan(cog.get_result()[8])); + assert(std::abs(cog.get_result()[10] - -5.4998) < 0.0001); + assert(std::abs(cog.get_result()[14] - -5.51127) < 0.0001); + assert(std::abs(cog.get_result()[25] - -5.51401) < 0.0001); + assert(std::abs(cog.get_result()[1720] - -5.60765) < 0.0001); + assert(std::abs(cog.get_result()[1712] - -5.54681) < 0.0001); + assert(std::abs(cog.get_result()[1707] - -5.44354) < 0.0001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_ArnaudLegouxMAVisitor() { + + std::cout << "\nTesting ArnaudLegouxMAVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + alma_v alma; + + df.single_act_visit("IBM_Close", alma); + + assert(alma.get_result().size() == 1721); + assert(std::isnan(alma.get_result()[0])); + assert(std::isnan(alma.get_result()[9])); + assert(std::abs(alma.get_result()[10] - 187.533) < 0.001); + assert(std::abs(alma.get_result()[14] - 186.359) < 0.001); + assert(std::abs(alma.get_result()[25] - 176.892) < 0.001); + assert(std::abs(alma.get_result()[1720] - 117.841) < 0.001); + assert(std::abs(alma.get_result()[1712] - 127.677) < 0.001); + assert(std::abs(alma.get_result()[1707] - 121.435) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_RateOfChangeVisitor() { + + std::cout << "\nTesting RateOfChangeVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + roc_v roc (10); // 10 period rate of change + + df.single_act_visit("IBM_Close", roc); + + assert(roc.get_result().size() == 1721); + assert(std::isnan(roc.get_result()[0])); + assert(std::isnan(roc.get_result()[9])); + assert(std::abs(roc.get_result()[10] - 0.0174096) < 0.000001); + assert(std::abs(roc.get_result()[14] - -0.0278768) < 0.000001); + assert(std::abs(roc.get_result()[25] - -0.0133044) < 0.000001); + assert(std::abs(roc.get_result()[1720] - -0.113317) < 0.00001); + assert(std::abs(roc.get_result()[1712] - -0.0377142) < 0.000001); + assert(std::abs(roc.get_result()[1707] - 0.0343972) < 0.000001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_AccumDistVisitor() { + + std::cout << "\nTesting AccumDistVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + ad_v ad; + + std::future &> fut = + df.single_act_visit_async + ("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", "IBM_Volume", ad); + + fut.get(); + assert(ad.get_result().size() == 1721); + assert(std::abs(ad.get_result()[0] - -3471893.994401) < 0.00001); + assert(std::abs(ad.get_result()[10] - -3089366.572853) < 0.00001); + assert(std::abs(ad.get_result()[14] - 3190895.313251) < 0.00001); + assert(std::abs(ad.get_result()[25] - -4599921.087384) < 0.00001); + assert(std::abs(ad.get_result()[1720] - -70588883.462685) < 0.00001); + assert(std::abs(ad.get_result()[1712] - -61812361.976164) < 0.00001); + assert(std::abs(ad.get_result()[1707] - -47503851.035966) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_ChaikinMoneyFlowVisitor() { + + std::cout << "\nTesting ChaikinMoneyFlowVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + cmf_v cmf; + + std::future &> fut = + df.single_act_visit_async + ("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", "IBM_Volume", cmf); + + fut.get(); + assert(cmf.get_result().size() == 1721); + assert(std::isnan(cmf.get_result()[0])); + assert(std::isnan(cmf.get_result()[19])); + assert(std::abs(cmf.get_result()[20] - -0.0404048) < 0.00001); + assert(std::abs(cmf.get_result()[24] - -0.0674374) < 0.00001); + assert(std::abs(cmf.get_result()[25] - -0.0201182) < 0.00001); + assert(std::abs(cmf.get_result()[1720] - -0.195288) < 0.00001); + assert(std::abs(cmf.get_result()[1712] - -0.175841) < 0.00001); + assert(std::abs(cmf.get_result()[1707] - -0.0827408) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_VertHorizFilterVisitor() { + + std::cout << "\nTesting VertHorizFilterVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + vhf_v vhf; + + df.single_act_visit("IBM_Close", vhf); + + assert(vhf.get_result().size() == 1721); + assert(std::isnan(vhf.get_result()[0])); + assert(std::isnan(vhf.get_result()[27])); + assert(std::abs(vhf.get_result()[28] - 0.385992) < 0.000001); + assert(std::abs(vhf.get_result()[30] - 0.371847) < 0.000001); + assert(std::abs(vhf.get_result()[35] - 0.417574) < 0.000001); + assert(std::abs(vhf.get_result()[1720] - 0.450244) < 0.00001); + assert(std::abs(vhf.get_result()[1712] - 0.301387) < 0.000001); + assert(std::abs(vhf.get_result()[1707] - 0.297249) < 0.000001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_OnBalanceVolumeVisitor() { + + std::cout << "\nTesting OnBalanceVolumeVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + obv_v obv; + + std::future &> fut = + df.single_act_visit_async + ("IBM_Close", "IBM_Volume", obv); + + fut.get(); + assert(obv.get_result().size() == 1721); + assert(std::abs(obv.get_result()[0] - 4546500) < 0.001); + assert(std::abs(obv.get_result()[19] - -21855500) < 0.001); + assert(std::abs(obv.get_result()[20] - -27048900) < 0.001); + assert(std::abs(obv.get_result()[24] - -29581000) < 0.001); + assert(std::abs(obv.get_result()[25] - -24888100) < 0.001); + assert(std::abs(obv.get_result()[1720] - -18817000) < 0.001); + assert(std::abs(obv.get_result()[1712] - -12925800) < 0.001); + assert(std::abs(obv.get_result()[1707] - 10998800) < 0.001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + + +// ----------------------------------------------------------------------------- + +static void test_TrueRangeVisitor() { + + std::cout << "\nTesting TrueRangeVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + TrueRangeVisitor tr; + + std::future &> fut = + df.single_act_visit_async + ("IBM_Low", "IBM_High", "IBM_Close", tr); + + fut.get(); + + assert(tr.get_result().size() == 1721); + assert(std::abs(tr.get_result()[0] - 2.2) < 0.0001); + assert(std::abs(tr.get_result()[12] - 2.8906) < 0.0001); + assert(std::abs(tr.get_result()[19] - 2.8988) < 0.0001); + assert(std::abs(tr.get_result()[20] - 2.8429) < 0.0001); + assert(std::abs(tr.get_result()[24] - 2.5409) < 0.0001); + assert(std::abs(tr.get_result()[25] - 2.5886) < 0.0001); + assert(std::abs(tr.get_result()[1720] - 3.4109) < 0.0001); + assert(std::abs(tr.get_result()[1712] - 3.6414) < 0.0001); + assert(std::abs(tr.get_result()[1707] - 3.5273) < 0.0001); + + TrueRangeVisitor tr2 (true, 14, true); + + std::future &> fut2 = + df.single_act_visit_async + ("IBM_Low", "IBM_High", "IBM_Close", tr2); + + fut2.get(); + + assert(tr2.get_result().size() == 1721); + assert(std::abs(tr2.get_result()[0] - 1.1858) < 0.0001); + assert(std::abs(tr2.get_result()[12] - 1.534) < 0.0001); + assert(std::abs(tr2.get_result()[19] - 1.6344) < 0.0001); + assert(std::abs(tr2.get_result()[20] - 1.609) < 0.0001); + assert(std::abs(tr2.get_result()[24] - 1.4547) < 0.0001); + assert(std::abs(tr2.get_result()[25] - 1.4604) < 0.0001); + assert(std::abs(tr2.get_result()[1720] - 3.0547) < 0.0001); + assert(std::abs(tr2.get_result()[1712] - 3.1025) < 0.0001); + assert(std::abs(tr2.get_result()[1707] - 2.8196) < 0.0001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_DecayVisitor() { + + std::cout << "\nTesting DecayVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + DecayVisitor decay(5, true); + + df.single_act_visit("IBM_Close", decay); + + assert(decay.get_result().size() == 1721); + assert(std::abs(decay.get_result()[0] - 185.53) < 0.01); + assert(std::abs(decay.get_result()[27] - 179.7) < 0.01); + assert(std::abs(decay.get_result()[28] - 180.24) < 0.01); + assert(std::abs(decay.get_result()[30] - 183.69) < 0.01); + assert(std::abs(decay.get_result()[35] - 183.45) < 0.01); + assert(std::abs(decay.get_result()[1720] - 111.66) < 0.01); + assert(std::abs(decay.get_result()[1712] - 125.513) < 0.01); + assert(std::abs(decay.get_result()[1707] - 127.203) < 0.01); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_HodgesTompkinsVolVisitor() { + + std::cout << "\nTesting HodgesTompkinsVolVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + ht_vol_v ht; + + df.single_act_visit("IBM_Close", ht); + + assert(ht.get_result().size() == 1721); + assert(std::isnan(ht.get_result()[0])); + assert(std::isnan(ht.get_result()[28])); + assert(std::abs(ht.get_result()[29] - 0.187655) < 0.00001); + assert(std::abs(ht.get_result()[30] - 0.187132) < 0.00001); + assert(std::abs(ht.get_result()[31] - 0.186253) < 0.00001); + assert(std::abs(ht.get_result()[35] - 0.177077) < 0.00001); + assert(std::abs(ht.get_result()[1720] - 0.365188) < 0.00001); + assert(std::abs(ht.get_result()[1712] - 0.326883) < 0.00001); + assert(std::abs(ht.get_result()[1707] - 0.298478) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_ParkinsonVolVisitor() { + + std::cout << "\nTesting ParkinsonVolVisitor{ } ..." << std::endl; + + typedef StdDataFrame64 StrDataFrame; + + StrDataFrame df; + + try { + df.read("data/SHORT_IBM.csv", io_format::csv2); + + p_vol_v pv; + + df.single_act_visit("IBM_Low", "IBM_High", pv); + + assert(pv.get_result().size() == 1721); + assert(std::isnan(pv.get_result()[0])); + assert(std::isnan(pv.get_result()[28])); + assert(std::abs(pv.get_result()[29] - 0.143397) < 0.00001); + assert(std::abs(pv.get_result()[30] - 0.145651) < 0.00001); + assert(std::abs(pv.get_result()[31] - 0.145266) < 0.00001); + assert(std::abs(pv.get_result()[35] - 0.144596) < 0.00001); + assert(std::abs(pv.get_result()[1720] - 0.225651) < 0.00001); + assert(std::abs(pv.get_result()[1712] - 0.208081) < 0.00001); + assert(std::abs(pv.get_result()[1707] - 0.236226) < 0.00001); + } + catch (const DataFrameError &ex) { + std::cout << ex.what() << std::endl; + } +} + +// ----------------------------------------------------------------------------- + +static void test_get_view_by_loc() { + + std::cout << "\nTesting get_view_by_loc() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = + { "11", "22", "33", "xx", "yy", "gg", "string" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", d4), + std::make_pair("col_str", s1)); + + auto memory_use1 = df.get_memory_usage("col_3"); + + std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl; + + typedef MyDataFrame::View MyDataFrameView; + typedef MyDataFrame::ConstView MyDataFrameConstView; + + const MyDataFrame &const_df = df; + MyDataFrameView dfv = + df.get_view_by_loc(Index2D { 3, 6 }); + MyDataFrameView dfv2 = + df.get_view_by_loc(Index2D { -5, -1 }); + MyDataFrameConstView dfcv = + const_df.get_view_by_loc(Index2D { 3, 6 }); + MyDataFrameConstView dfcv2 = + const_df.get_view_by_loc(Index2D { -5, -1 }); + + dfv.shrink_to_fit(); + dfv.write(std::cout); + dfv2.write(std::cout); + dfv.get_column("col_3")[0] = 88.0; + assert(dfv.get_column("col_3")[0] == + df.get_column("col_3")[3]); + assert(dfv.get_column("col_3")[0] == 88.0); + assert(dfcv.get_column("col_3")[0] == + df.get_column("col_3")[3]); + assert(dfcv.get_column("col_3")[0] == 88.0); + + auto memory_use2 = dfv.get_memory_usage("col_3"); + + std::cout << "View Memory Usage:\n" << memory_use2 << std::endl; +} + +// ----------------------------------------------------------------------------- + +static void test_get_view_by_idx_slicing() { + + std::cout << "\nTesting get_view_by_idx()/slicing ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, + 30, 31, 32, 1.89 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, + 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + typedef MyDataFrame::View MyDataFrameView; + typedef MyDataFrame::ConstView MyDataFrameConstView; + + const MyDataFrame &const_df = df; + + MyDataFrame df2 = + df.get_data_by_idx( + Index2D { 123452, 123460 }); + MyDataFrameView dfv = + df.get_view_by_idx( + Index2D { 123452, 123466 }); + MyDataFrameConstView dfcv = + const_df.get_view_by_idx( + Index2D { 123452, 123466 }); + + df.write(std::cout); + df2.write(std::cout); + dfv.write(std::cout); + + dfv.get_column("col_3")[0] = 88.0; + assert(dfv.get_column("col_3")[0] == + df.get_column("col_3")[2]); + assert(dfv.get_column("col_3")[0] == 88.0); + assert(dfv.shape().first == 12); // added + assert(dfcv.get_column("col_3")[0] == + df.get_column("col_3")[2]); + assert(dfcv.get_column("col_3")[0] == 88.0); + assert(dfcv.shape().first == 12); // added +} + +// ----------------------------------------------------------------------------- + +static void test_get_data() { + + std::cout << "\nTesting get_[data|view]() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, + 30, 31, 32, 1.89 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, + 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; + StlVecType i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", i1)); + + auto df2 = df.get_data({ "col_1", "col_4"}); + + assert((! df2.has_column("col_2"))); + assert((! df2.has_column("col_3"))); + assert((df2.get_column("col_1")[11] == 12)); + assert((df2.get_column("col_4")[8] == 2)); + assert((df2.get_index()[3] == 123453)); + + typedef MyDataFrame::View MyDataFrameView; + typedef MyDataFrame::ConstView MyDataFrameConstView; + + const MyDataFrame &const_df = df; + MyDataFrameView df3 = + df.get_view({ "col_1", "col_4"}); + MyDataFrameConstView const_df3 = + const_df.get_view({ "col_1", "col_4"}); + + assert((! df3.has_column("col_2"))); + assert((! df3.has_column("col_3"))); + assert((df3.get_column("col_1")[11] == 12)); + assert((df3.get_column("col_4")[8] == 2)); + assert((df3.get_index()[3] == 123453)); + + df3.get_index()[3] = 100; + df3.get_column("col_4")[8] = 101; + df3.get_column("col_1")[11] = 102.2; + + assert((df3.get_column("col_1")[11] == 102.2)); + assert((df3.get_column("col_4")[8] == 101)); + assert((df3.get_index()[3] == 100)); + assert((df.get_column("col_1")[11] == 102.2)); + assert((df.get_column("col_4")[8] == 101)); + assert((df.get_index()[3] == 100)); + + assert((const_df3.get_column("col_1")[11] == 102.2)); + assert((const_df3.get_column("col_4")[8] == 101)); + assert((const_df3.get_index()[3] == 100)); +} + +// ----------------------------------------------------------------------------- + +static void test_get_data_by_sel() { + + std::cout << "\nTesting get_data_by_sel() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + + auto functor = + [](const unsigned long &, const double &val)-> bool { + return (val >= 5); + }; + auto result = + df.get_data_by_sel + ("col_1", functor); + + assert(result.get_index().size() == 3); + assert(result.get_column("col_1").size() == 3); + assert(result.get_column("col_str").size() == 3); + assert(result.get_column("col_4").size() == 0); + assert(result.get_index()[0] == 123454); + assert(result.get_index()[2] == 123456); + assert(result.get_column("col_2")[1] == 13); + assert(result.get_column("col_str")[1] == "gg"); + assert(result.get_column("col_str")[2] == "ll"); + assert(result.get_column("col_1")[1] == 6); + assert(result.get_column("col_1")[2] == 7); + + auto functor2 = + [](const unsigned long &, + const double &val1, + const double &val2, + const std::string &val3)-> bool { + return (val1 >= 5 || val2 == 15 || val3 == "33"); + }; + auto result2 = + df.get_data_by_sel + ("col_1", "col_3", "col_str", functor2); + + assert(result2.get_index().size() == 5); + assert(result2.get_column("col_1").size() == 5); + assert(result2.get_column("col_str").size() == 5); + assert(result2.get_column("col_4").size() == 2); + assert(result2.get_index()[0] == 123450); + assert(result2.get_index()[2] == 123454); + assert(result2.get_index()[4] == 123456); + assert(result2.get_column("col_2")[0] == 8); + assert(result2.get_column("col_2")[1] == 10); + assert(result2.get_column("col_2")[3] == 13); + assert(result2.get_column("col_4")[0] == 22); + assert(result2.get_column("col_4")[1] == 24); + assert(result2.get_column("col_str")[0] == "11"); + assert(result2.get_column("col_str")[1] == "33"); + assert(result2.get_column("col_str")[2] == "ff"); + assert(result2.get_column("col_str")[4] == "ll"); + assert(result2.get_column("col_1")[0] == 1); + assert(result2.get_column("col_1")[1] == 3); + assert(result2.get_column("col_1")[2] == 5); + + StlVecType s2 = { "aa", "bb", "cc", "10", "11", "12", "14" }; + + df.load_column("col_str2", s2); + + auto functor3 = + [](const unsigned long &, + const double &val1, + const double &, + const double &val3, + const std::string &, + const std::string &val5)-> bool { + return (val1 >= 5 || val3 == 15 || val5 == "cc"); + }; + auto result3 = + df.get_data_by_sel + ("col_1", "col_2", "col_3", "col_str", "col_str2", functor3); + + const MyDataFrame &const_df = df; + + auto result4 = + df.get_view_by_sel + ("col_1", "col_2", "col_3", "col_str", "col_str2", functor3); + auto const_result4 = + const_df.get_view_by_sel + ("col_1", "col_2", "col_3", "col_str", "col_str2", functor3); + + assert(result3.get_index().size() == 5); + assert(result4.get_index().size() == 5); + assert(result3.get_column("col_1").size() == 5); + assert(result4.get_column("col_1").size() == 5); + assert(result3.get_column("col_2")[3] == 13); + assert(result4.get_column("col_2")[3] == 13); + assert(result3.get_column("col_str")[2] == "ff"); + assert(result4.get_column("col_str")[2] == "ff"); + assert(result3.get_column("col_1")[2] == 5); + assert(result4.get_column("col_1")[2] == 5); + + assert(const_result4.get_index().size() == 5); + assert(const_result4.get_column("col_1").size() == 5); + assert(const_result4.get_column("col_2")[3] == 13); + assert(const_result4.get_column("col_str")[2] == "ff"); + assert(const_result4.get_column("col_1")[2] == 5); +} + +// ----------------------------------------------------------------------------- + +static void test_get_view_by_sel() { + + std::cout << "\nTesting get_view_by_sel() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + StlVecType s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + + const MyDataFrame &const_df = df; + auto functor = + [](const unsigned long &, const double &val)-> bool { + return (val >= 5); + }; + auto result = + df.get_view_by_sel + ("col_1", functor); + auto const_result = + const_df.get_view_by_sel + ("col_1", functor); + + result.shrink_to_fit(); + assert(result.get_index().size() == 3); + assert(result.get_column("col_1").size() == 3); + assert(result.get_column("col_str").size() == 3); + assert(result.get_column("col_4").size() == 0); + assert(result.get_index()[0] == 123454); + assert(result.get_index()[2] == 123456); + assert(result.get_column("col_2")[1] == 13); + assert(result.get_column("col_str")[1] == "gg"); + assert(result.get_column("col_str")[2] == "ll"); + assert(result.get_column("col_1")[1] == 6); + assert(result.get_column("col_1")[2] == 7); + + assert(const_result.get_index().size() == 3); + assert(const_result.get_column("col_1").size() == 3); + assert(const_result.get_column("col_str").size() == 3); + assert(const_result.get_column("col_4").size() == 0); + assert(const_result.get_index()[0] == 123454); + assert(const_result.get_index()[2] == 123456); + assert(const_result.get_column("col_2")[1] == 13); + assert(const_result.get_column("col_str")[1] == "gg"); + assert(const_result.get_column("col_str")[2] == "ll"); + assert(const_result.get_column("col_1")[1] == 6); + assert(const_result.get_column("col_1")[2] == 7); + + result.get_column("col_1")[1] = 600; + assert(result.get_column("col_1")[1] == 600); + assert(const_result.get_column("col_1")[1] == 600); + assert(df.get_column("col_1")[5] == 600); + + auto functor2 = + [](const unsigned long &, + const double &val1, + const double &val2)-> bool { + return (val1 >= 5 || val2 == 15); + }; + auto result2 = + df.get_view_by_sel + ("col_1", "col_3", functor2); + auto const_result2 = + const_df.get_view_by_sel + ("col_1", "col_3", functor2); + + auto functor3 = + [](const unsigned long &, + const double &val1, + const double &val2, + const std::string val3)-> bool { + return (val1 >= 5 || val2 == 15 || val3 == "33"); + }; + auto result3 = + df.get_view_by_sel + ("col_1", "col_3", "col_str", functor3); + auto const_result3 = + const_df.get_view_by_sel + ("col_1", "col_3", "col_str", functor3); + + assert(result3.get_index().size() == 5); + assert(result3.get_column("col_1").size() == 5); + assert(result3.get_column("col_str").size() == 5); + assert(result3.get_column("col_4").size() == 2); + assert(result3.get_index()[0] == 123450); + assert(result3.get_index()[2] == 123454); + assert(result3.get_index()[4] == 123456); + assert(result3.get_column("col_2")[0] == 8); + assert(result3.get_column("col_2")[1] == 10); + assert(result3.get_column("col_2")[3] == 13); + assert(result3.get_column("col_4")[0] == 22); + assert(result3.get_column("col_4")[1] == 24); + assert(result3.get_column("col_str")[0] == "11"); + assert(result3.get_column("col_str")[1] == "33"); + assert(result3.get_column("col_str")[2] == "ff"); + assert(result3.get_column("col_str")[4] == "ll"); + assert(result3.get_column("col_1")[0] == 1); + assert(result3.get_column("col_1")[1] == 3); + assert(result3.get_column("col_1")[2] == 5); + + assert(const_result3.get_index().size() == 5); + assert(const_result3.get_column("col_1").size() == 5); + assert(const_result3.get_column("col_str").size() == 5); + assert(const_result3.get_column("col_4").size() == 2); + assert(const_result3.get_index()[0] == 123450); + assert(const_result3.get_index()[2] == 123454); + assert(const_result3.get_index()[4] == 123456); + assert(const_result3.get_column("col_2")[0] == 8); + assert(const_result3.get_column("col_2")[1] == 10); + assert(const_result3.get_column("col_2")[3] == 13); + assert(const_result3.get_column("col_4")[0] == 22); + assert(const_result3.get_column("col_4")[1] == 24); + assert(const_result3.get_column("col_str")[0] == "11"); + assert(const_result3.get_column("col_str")[1] == "33"); + assert(const_result3.get_column("col_str")[2] == "ff"); + assert(const_result3.get_column("col_str")[4] == "ll"); + assert(const_result3.get_column("col_1")[0] == 1); + assert(const_result3.get_column("col_1")[1] == 3); + assert(const_result3.get_column("col_1")[2] == 5); +} + +// ----------------------------------------------------------------------------- + +static void test_get_view_by_rand() { + + std::cout << "\nTesting get_view_by_rand() ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123453, 123454, 123455, 123456, + 123457, 123458, 123459, 123460 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; + StlVecType d4 = { 22, 23, 24, 25, 26, 27 }; + StlVecType s1 = + { "11", "22", "33", "aa", "bb", "cc", "dd", "tt", "uu", "ii", "88" }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_str", s1)); + df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); + + const MyDataFrame &const_df = df; + auto result = + df.get_view_by_rand + (random_policy::num_rows_no_seed, 5); + auto result2 = + df.get_view_by_rand + (random_policy::frac_rows_with_seed, 0.8, 23); + auto const_result = + const_df.get_view_by_rand + (random_policy::num_rows_no_seed, 5); + auto const_result2 = + const_df.get_view_by_rand + (random_policy::frac_rows_with_seed, 0.8, 23); + + result2.write(std::cout); +/* + assert(result2.get_index().size() == 6); + assert(result2.get_column("col_1").size() == 6); + assert(result2.get_column("col_4").size() == 1); + assert(result2.get_column("col_str").size() == 6); + assert(result2.get_column("col_4")[0] == 25.0); + assert(result2.get_column("col_3")[4] == 24.0); + assert(result2.get_column("col_1")[5] == 11.0); + assert(result2.get_column("col_str")[4] == "ii"); + + result2.get_column("col_str")[4] = "TEST"; + assert(result2.get_column("col_str")[4] == "TEST"); + assert(result2.get_column("col_str")[4] == + df.get_column("col_str")[9]); +*/ +} + +// ----------------------------------------------------------------------------- + +static void test_get_view_by_loc_location() { + + std::cout << "\nTesting get_view_by_loc(locations) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", d4)); + + const MyDataFrame &const_df = df; + + auto dfv1 = df.get_view_by_loc(StlVecType { 3, 6 }); + auto dfv2 = df.get_view_by_loc(StlVecType { -4, -1 , 5 }); + auto const_dfv1 = + const_df.get_view_by_loc(StlVecType { 3, 6 }); + auto const_dfv2 = + const_df.get_view_by_loc(StlVecType { -4, -1 , 5 }); + + assert(dfv1.get_index().size() == 2); + assert(dfv1.get_column("col_3").size() == 2); + assert(dfv1.get_column("col_2").size() == 2); + assert(dfv1.get_index()[0] == 123450); + assert(dfv1.get_index()[1] == 123449); + assert(dfv1.get_column("col_3")[0] == 18.0); + assert(dfv1.get_column("col_2")[1] == 14.0); + assert(std::isnan(dfv1.get_column("col_4")[1])); + + assert(const_dfv1.get_index().size() == 2); + assert(const_dfv1.get_column("col_3").size() == 2); + assert(const_dfv1.get_column("col_2").size() == 2); + assert(const_dfv1.get_index()[0] == 123450); + assert(const_dfv1.get_index()[1] == 123449); + assert(const_dfv1.get_column("col_3")[0] == 18.0); + assert(const_dfv1.get_column("col_2")[1] == 14.0); + assert(std::isnan(const_dfv1.get_column("col_4")[1])); + + assert(dfv2.get_index().size() == 3); + assert(dfv2.get_column("col_3").size() == 3); + assert(dfv2.get_column("col_2").size() == 3); + assert(dfv2.get_column("col_1").size() == 3); + assert(dfv2.get_index()[0] == 123450); + assert(dfv2.get_index()[1] == 123449); + assert(dfv2.get_index()[2] == 123450); + assert(dfv2.get_column("col_1")[0] == 4.0); + assert(dfv2.get_column("col_2")[2] == 13.0); + assert(dfv2.get_column("col_4")[0] == 25.0); + assert(std::isnan(dfv2.get_column("col_4")[1])); + assert(std::isnan(dfv2.get_column("col_4")[2])); + + assert(const_dfv2.get_index().size() == 3); + assert(const_dfv2.get_column("col_3").size() == 3); + assert(const_dfv2.get_column("col_2").size() == 3); + assert(const_dfv2.get_column("col_1").size() == 3); + assert(const_dfv2.get_index()[0] == 123450); + assert(const_dfv2.get_index()[1] == 123449); + assert(const_dfv2.get_index()[2] == 123450); + assert(const_dfv2.get_column("col_1")[0] == 4.0); + assert(const_dfv2.get_column("col_2")[2] == 13.0); + assert(const_dfv2.get_column("col_4")[0] == 25.0); + assert(std::isnan(const_dfv2.get_column("col_4")[1])); + assert(std::isnan(const_dfv2.get_column("col_4")[2])); + + dfv2.get_column("col_1")[0] = 101.0; + assert(dfv2.get_column("col_1")[0] == 101.0); + assert(const_dfv2.get_column("col_1")[0] == 101.0); + assert(df.get_column("col_1")[3] == 101.0); + + auto memory_use = dfv2.get_memory_usage("col_3"); + + std::cout << "View Memory Usage:\n" << memory_use << std::endl; +} + +// ----------------------------------------------------------------------------- + +static void test_get_view_by_idx_values() { + + std::cout << "\nTesting get_view_by_idx(values) ..." << std::endl; + + StlVecType idx = + { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; + StlVecType d1 = { 1, 2, 3, 4, 5, 6, 7 }; + StlVecType d2 = { 8, 9, 10, 11, 12, 13, 14 }; + StlVecType d3 = { 15, 16, 17, 18, 19, 20, 21 }; + StlVecType d4 = { 22, 23, 24, 25 }; + MyDataFrame df; + + df.load_data(std::move(idx), + std::make_pair("col_1", d1), + std::make_pair("col_2", d2), + std::make_pair("col_3", d3), + std::make_pair("col_4", d4)); + + const MyDataFrame &const_df = df; + + auto dfv1 = + df.get_view_by_idx( + StlVecType { 123452, 123455 }); + auto const_dfv1 = + const_df.get_view_by_idx( + StlVecType { 123452, 123455 }); + auto dfv2 = + df.get_view_by_idx( + StlVecType { 123449, 123450 }); + auto const_dfv2 = + const_df.get_view_by_idx( + StlVecType { 123449, 123450 }); + + assert(dfv1.get_index().size() == 2); + assert(dfv1.get_column("col_3").size() == 2); + assert(dfv1.get_column("col_2").size() == 2); + assert(dfv1.get_index()[0] == 123452); + assert(dfv1.get_index()[1] == 123455); + assert(dfv1.get_column("col_3")[0] == 17.0); + assert(dfv1.get_column("col_2")[1] == 12.0); + assert(std::isnan(dfv1.get_column("col_4")[1])); + + assert(const_dfv1.get_index().size() == 2); + assert(const_dfv1.get_column("col_3").size() == 2); + assert(const_dfv1.get_column("col_2").size() == 2); + assert(const_dfv1.get_index()[0] == 123452); + assert(const_dfv1.get_index()[1] == 123455); + assert(const_dfv1.get_column("col_3")[0] == 17.0); + assert(const_dfv1.get_column("col_2")[1] == 12.0); + assert(std::isnan(const_dfv1.get_column("col_4")[1])); + + assert(dfv2.get_index().size() == 4); + assert(dfv2.get_column("col_3").size() == 4); + assert(dfv2.get_column("col_2").size() == 4); + assert(dfv2.get_column("col_1").size() == 4); + assert(dfv2.get_index()[0] == 123450); + assert(dfv2.get_index()[1] == 123450); + assert(dfv2.get_index()[2] == 123450); + assert(dfv2.get_index()[3] == 123449); + assert(dfv2.get_column("col_1")[0] == 1.0); + assert(dfv2.get_column("col_2")[2] == 13.0); + assert(dfv2.get_column("col_4")[0] == 22.0); + assert(dfv2.get_column("col_4")[1] == 25.0); + assert(std::isnan(dfv2.get_column("col_4")[2])); + assert(std::isnan(dfv2.get_column("col_4")[3])); + + assert(const_dfv2.get_index().size() == 4); + assert(const_dfv2.get_column("col_3").size() == 4); + assert(const_dfv2.get_column("col_2").size() == 4); + assert(const_dfv2.get_column("col_1").size() == 4); + assert(const_dfv2.get_index()[0] == 123450); + assert(const_dfv2.get_index()[1] == 123450); + assert(const_dfv2.get_index()[2] == 123450); + assert(const_dfv2.get_index()[3] == 123449); + assert(const_dfv2.get_column("col_1")[0] == 1.0); + assert(const_dfv2.get_column("col_2")[2] == 13.0); + assert(const_dfv2.get_column("col_4")[0] == 22.0); + assert(const_dfv2.get_column("col_4")[1] == 25.0); + assert(std::isnan(const_dfv2.get_column("col_4")[2])); + assert(std::isnan(const_dfv2.get_column("col_4")[3])); + + dfv2.get_column("col_1")[0] = 101.0; + assert(dfv2.get_column("col_1")[0] == 101.0); + assert(df.get_column("col_1")[0] == 101.0); +} + +// ----------------------------------------------------------------------------- + +int main(int, char *[]) { + + test_get_reindexed(); + test_get_reindexed_view(); + test_retype_column(); + test_load_align_column(); + test_get_columns_info(); + test_CategoryVisitor(); + test_FactorizeVisitor(); + test_pattern_match(); + test_ClipVisitor(); + test_SharpeRatioVisitor(); + test_RankVisitor(); + test_SigmoidVisitor(); + test_combine(); + test_RSIVisitor(); + test_remove_duplicates(); + test_groupby(); + test_groupby_2(); + test_groupby_3(); + test_io_format_csv2(); + test_BoxCoxVisitor(); + test_NormalizeVisitor(); + test_HampelFilterVisitor(); + test_PolyFitVisitor(); + test_HurstExponentVisitor(); + test_LogFitVisitor(); + test_ExponentialFitVisitor(); + test_LinearFitVisitor(); + test_ExpoSmootherVisitor(); + test_HWExpoSmootherVisitor(); + test_consolidate(); + test_ExtremumSubArrayVisitor(); + test_NExtremumSubArrayVisitor(); + test_LowessVisitor(); + test_StepRollAdopter(); + test_DecomposeVisitor(); + test_DT_IBM_data(); + test_TTestVisitor(); + test_MassIndexVisitor(); + test_HullRollingMeanVisitor(); + test_RollingMidValueVisitor(); + test_DrawdownVisitor(); + test_WilliamPrcRVisitor(); + test_PSLVisitor(); + test_CCIVisitor(); + test_EntropyVisitor(); + test_GarmanKlassVolVisitor(); + test_YangZhangVolVisitor(); + test_no_index_writes(); + test_no_index_reads(); + test_KamaVisitor(); + test_FisherTransVisitor(); + test_PercentPriceOSCIVisitor(); + test_SlopeVisitor(); + test_UltimateOSCIVisitor(); + test_shifting_column(); + test_UlcerIndexVisitor(); + test_bucketize(); + test_RSXVisitor(); + test_TTMTrendVisitor(); + test_ParabolicSARVisitor(); + test_EBSineWaveVisitor(); + test_EhlerSuperSmootherVisitor(); + test_VarIdxDynAvgVisitor(); + test_AbsVisitor(); + test_PivotPointSRVisitor(); + test_AvgDirMovIdxVisitor(); + test_HoltWinterChannelVisitor(); + test_HeikinAshiCndlVisitor(); + test_FastFourierTransVisitor(); + test_CenterOfGravityVisitor(); + test_ArnaudLegouxMAVisitor(); + test_RateOfChangeVisitor(); + test_AccumDistVisitor(); + test_ChaikinMoneyFlowVisitor(); + test_VertHorizFilterVisitor(); + test_OnBalanceVolumeVisitor(); + test_TrueRangeVisitor(); + test_DecayVisitor(); + test_HodgesTompkinsVolVisitor(); + test_ParkinsonVolVisitor(); + test_get_view_by_loc(); + test_get_view_by_idx_slicing(); + test_get_data(); + test_get_data_by_sel(); + test_get_view_by_sel(); + test_get_view_by_rand(); + test_get_view_by_loc_location(); + test_get_view_by_idx_values(); + + return (0); +} + +// ----------------------------------------------------------------------------- + +// Local Variables: +// mode:C++ +// tab-width:4 +// c-basic-offset:4 +// End: diff --git a/test/dataframe_tester_3.cc b/test/dataframe_tester_3.cc index ea03e2ac6..d27d3164e 100644 --- a/test/dataframe_tester_3.cc +++ b/test/dataframe_tester_3.cc @@ -39,7 +39,8 @@ using namespace hmdf; // A DataFrame with ulong index type // -using MyDataFrame = StdDataFrame; +using MyDataFrame = StdDataFrame256; +using StrDataFrame = StdDataFrame256; template using StlVecType = typename MyDataFrame::template StlVecType; @@ -76,7 +77,7 @@ static void test_groupby_edge() { df.load_column("int_col", std::move(intvec), nan_policy::dont_pad_with_nans); - FactorizeVisitor fact([] (const double &f) -> bool { + FactorizeVisitor fact([] (const double &f) -> bool { return (f > 11106.0 && f < 114.0); }); df.load_column("bool_col", @@ -255,7 +256,7 @@ static void test_multithreading(int j) { std::cout << "PRINTING FIRST ..." << std::endl; df.write (std::cout, io_format::json); - FactorizeVisitor fact([] (const double &f) -> bool { + FactorizeVisitor fact([] (const double &f) -> bool { return (f > 11106.0 && f < 114.0); }); df.load_column("bool_col", @@ -326,14 +327,12 @@ static void test_CoppockCurveVisitor() { std::cout << "\nTesting CoppockCurveVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - coppc_v copp; + coppc_v copp; df.single_act_visit("IBM_Close", copp); @@ -357,8 +356,6 @@ static void test_BiasVisitor() { std::cout << "\nTesting BiasVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { @@ -367,7 +364,7 @@ static void test_BiasVisitor() { using avg1 = MeanVisitor; avg1 avg1_v; - bias_v bias1 (avg1_v); + bias_v bias1 (avg1_v); df.single_act_visit("IBM_Close", bias1); @@ -383,7 +380,7 @@ static void test_BiasVisitor() { using s_avg1 = StableMeanVisitor; s_avg1 s_avg1_v; - bias_v s_bias1 (s_avg1_v); + bias_v s_bias1 (s_avg1_v); df.single_act_visit("IBM_Close", s_bias1); @@ -399,7 +396,7 @@ static void test_BiasVisitor() { using avg2 = WeightedMeanVisitor; avg2 avg2_v; - bias_v bias2 (avg2_v); + bias_v bias2 (avg2_v); df.single_act_visit("IBM_Close", bias2); @@ -415,7 +412,7 @@ static void test_BiasVisitor() { using avg3 = GeometricMeanVisitor; avg3 avg3_v; - bias_v bias3 (avg3_v); + bias_v bias3 (avg3_v); df.single_act_visit("IBM_Close", bias3); @@ -431,7 +428,7 @@ static void test_BiasVisitor() { using avg4 = HarmonicMeanVisitor; avg4 avg4_v; - bias_v bias4 (avg4_v); + bias_v bias4 (avg4_v); df.single_act_visit("IBM_Close", bias4); @@ -456,14 +453,12 @@ static void test_BalanceOfPowerVisitor() { std::cout << "\nTesting BalanceOfPowerVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - bop_v bop; + bop_v bop; df.single_act_visit ("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", bop); @@ -503,14 +498,12 @@ static void test_ChandeKrollStopVisitor() { std::cout << "\nTesting ChandeKrollStopVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - cksp_v cksp; + cksp_v cksp; df.single_act_visit ("IBM_Low", "IBM_High", "IBM_Close", cksp); @@ -546,14 +539,12 @@ static void test_VortexVisitor() { std::cout << "\nTesting VortexVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - vtx_v vtx; + vtx_v vtx; df.single_act_visit ("IBM_Low", "IBM_High", "IBM_Close", vtx); @@ -589,14 +580,12 @@ static void test_KeltnerChannelsVisitor() { std::cout << "\nTesting KeltnerChannelsVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - kch_v kch; + kch_v kch; df.single_act_visit ("IBM_Low", "IBM_High", "IBM_Close", kch); @@ -632,14 +621,12 @@ static void test_TrixVisitor() { std::cout << "\nTesting TrixVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - trix_v trix; + trix_v trix; df.single_act_visit("IBM_Close", trix); @@ -653,7 +640,7 @@ static void test_TrixVisitor() { assert(std::abs(trix.get_result()[1712] - 0.0008) < 0.0001); assert(std::abs(trix.get_result()[1707] - 0.0003) < 0.0001); - trix_v trix2 (14, true); + trix_v trix2 (14, true); df.single_act_visit("IBM_Close", trix2); @@ -679,14 +666,12 @@ static void test_PrettyGoodOsciVisitor() { std::cout << "\nTesting PrettyGoodOsciVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - pgo_v pgo; + pgo_v pgo; df.single_act_visit ("IBM_Low", "IBM_High", "IBM_Close", pgo); @@ -768,14 +753,12 @@ static void test_ZeroLagMovingMeanVisitor() { std::cout << "\nTesting ZeroLagMovingMeanVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); - zlmm_v zlmm(10); + zlmm_v zlmm(10); df.single_act_visit("IBM_Close", zlmm); @@ -824,14 +807,12 @@ static void test_T3MovingMeanVisitor() { std::cout << "\nTesting T3MovingMeanVisitor{ } ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { df.read("data/IBM.csv", io_format::csv2); - t3_v t3; + t3_v t3; df.single_act_visit ("IBM_Close", t3); @@ -902,8 +883,6 @@ static void test_load_result_as_column() { std::cout << "\nTesting load_result_as_column( ) ..." << std::endl; - typedef StdDataFrame StrDataFrame; - StrDataFrame df; try { @@ -911,7 +890,7 @@ static void test_load_result_as_column() { // CoppockCurveVisitor // - coppc_v copp; + coppc_v copp; df.single_act_visit("IBM_Close", copp); df.load_result_as_column(copp, "IBM_close_curve"); From 56424ecbe3bc9b7e936860eeec0193c17c58c67e Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 25 Dec 2022 12:42:06 -0500 Subject: [PATCH 17/25] code reformatting --- test/aligned_dataframe_tester.cc | 7 +-- test/aligned_dataframe_tester_2.cc | 83 ++++++++++++++++++++---------- test/dataframe_tester_3.cc | 14 ++--- 3 files changed, 67 insertions(+), 37 deletions(-) diff --git a/test/aligned_dataframe_tester.cc b/test/aligned_dataframe_tester.cc index 968e10e6e..990e9b32e 100644 --- a/test/aligned_dataframe_tester.cc +++ b/test/aligned_dataframe_tester.cc @@ -606,13 +606,13 @@ static void test_get_data_by_loc_slicing() { df5.write(std::cout); try { - MyDataFrame df2 = df.get_data_by_loc(Index2D { 3, 8 }); + MyDataFrame df6 = df.get_data_by_loc(Index2D { 3, 8 }); } catch (const BadRange &ex) { std::cout << "Caught: " << ex.what() << std::endl; } try { - MyDataFrame df2 = df.get_data_by_loc(Index2D { -8, -1 }); + MyDataFrame df7 = df.get_data_by_loc(Index2D { -8, -1 }); } catch (const BadRange &ex) { std::cout << "Caught: " << ex.what() << std::endl; @@ -785,7 +785,8 @@ static void test_value_counts() { std::cout << "\nTesting value_counts() ..." << std::endl; - const double my_nan = sqrt(-1); + const double my_nan = + std::numeric_limits::quiet_NaN(); StlVecType idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; diff --git a/test/aligned_dataframe_tester_2.cc b/test/aligned_dataframe_tester_2.cc index 8a4261e9a..1685c13c9 100644 --- a/test/aligned_dataframe_tester_2.cc +++ b/test/aligned_dataframe_tester_2.cc @@ -267,7 +267,7 @@ static void test_load_align_column() { std::move(summary_vec), 5, true, - std::sqrt(-1)); + std::numeric_limits::quiet_NaN()); StlVecType summary_vec_2 = { 102, 202, 302, 402, 502 }; @@ -275,7 +275,7 @@ static void test_load_align_column() { std::move(summary_vec_2), 5, false, - std::sqrt(-1)); + std::numeric_limits::quiet_NaN()); assert(df.get_column("summary_col").size() == 28); assert(df.get_column("summary_col_2").size() == 28); @@ -368,7 +368,8 @@ static void test_CategoryVisitor() { { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; StlVecType dblvec = - { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, sqrt(-1), + { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, + std::numeric_limits::quiet_NaN(), 4.0, 14.0, 14.0, 20.0 }; StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; StlVecType strvec = @@ -439,9 +440,10 @@ static void test_FactorizeVisitor() { std::move(intvec), nan_policy::dont_pad_with_nans); - FactorizeVisitor fact([] (const double &f) -> bool { - return (f > 106.0 && f < 114.0); - }); + FactorizeVisitor + fact([] (const double &f) -> bool { + return (f > 106.0 && f < 114.0); + }); df.load_column("bool_col", df.single_act_visit("dbl_col_2", fact).get_result()); assert(df.get_column("bool_col").size() == 15); @@ -472,12 +474,15 @@ static void test_pattern_match() { p.max_value = 30; df.load_data(MyDataFrame::gen_sequence_index(0, item_cnt, 1), - std::make_pair("lognormal", - gen_lognormal_dist(item_cnt, p)), - std::make_pair("normal", - gen_normal_dist(item_cnt, p)), - std::make_pair("uniform_real", - gen_uniform_real_dist(item_cnt, p))); + std::make_pair( + "lognormal", + gen_lognormal_dist(item_cnt, p)), + std::make_pair( + "normal", + gen_normal_dist(item_cnt, p)), + std::make_pair( + "uniform_real", + gen_uniform_real_dist(item_cnt, p))); p.mean = 0; p.std = 1.0; p.min_value = -30; @@ -568,7 +573,8 @@ static void test_ClipVisitor() { { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; StlVecType dblvec = - { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, sqrt(-1), + { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, + std::numeric_limits::quiet_NaN(), 4.0, 14.0, 14.0, 20.0 }; StlVecType intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; StlVecType strvec = @@ -720,11 +726,16 @@ static void test_SigmoidVisitor() { SigmoidVisitor sig_log(sigmoid_type::logistic); SigmoidVisitor sig_alg(sigmoid_type::algebraic); - SigmoidVisitor sig_tan(sigmoid_type::hyperbolic_tan); - SigmoidVisitor sig_atan(sigmoid_type::arc_tan); - SigmoidVisitor sig_err(sigmoid_type::error_function); - SigmoidVisitor sig_gud(sigmoid_type::gudermannian); - SigmoidVisitor sig_smo(sigmoid_type::smoothstep); + SigmoidVisitor sig_tan( + sigmoid_type::hyperbolic_tan); + SigmoidVisitor sig_atan( + sigmoid_type::arc_tan); + SigmoidVisitor sig_err( + sigmoid_type::error_function); + SigmoidVisitor sig_gud( + sigmoid_type::gudermannian); + SigmoidVisitor sig_smo( + sigmoid_type::smoothstep); const auto log_result = df.single_act_visit("d1_col", sig_log).get_result(); const auto alg_result = @@ -1397,19 +1408,28 @@ static void test_BoxCoxVisitor() { gen_lognormal_dist(item_cnt, p)), std::make_pair("normal", gen_normal_dist(item_cnt, p)), - std::make_pair("uniform_real", - gen_uniform_real_dist(item_cnt, p))); + std::make_pair( + "uniform_real", + gen_uniform_real_dist(item_cnt, p))); - BoxCoxVisitor bc_v1(box_cox_type::original, 1.5, true); + BoxCoxVisitor bc_v1(box_cox_type::original, + 1.5, + true); const auto &result1 = df.single_act_visit("lognormal", bc_v1).get_result(); - BoxCoxVisitor bc_v2(box_cox_type::original, 1.5, false); + BoxCoxVisitor bc_v2(box_cox_type::original, + 1.5, + false); const auto &result2 = df.single_act_visit("uniform_real", bc_v2).get_result(); - BoxCoxVisitor bc_v3(box_cox_type::modulus, -0.5, false); + BoxCoxVisitor bc_v3(box_cox_type::modulus, + -0.5, + false); const auto &result3 = df.single_act_visit("uniform_real", bc_v3).get_result(); - BoxCoxVisitor bc_v4(box_cox_type::exponential, -0.5, false); + BoxCoxVisitor bc_v4(box_cox_type::exponential, + -0.5, + false); const auto &result4 = df.single_act_visit("uniform_real", bc_v4).get_result(); @@ -1497,7 +1517,9 @@ static void test_HampelFilterVisitor() { df.load_data(std::move(idx), std::make_pair("dbl_col", d1)); - HampelFilterVisitor hf_v(7, hampel_type::mean, 2); + HampelFilterVisitor hf_v(7, + hampel_type::mean, + 2); auto result = df.single_act_visit("dbl_col", hf_v).get_result(); StlVecType hampel_result = { @@ -1618,7 +1640,8 @@ static void test_HurstExponentVisitor() { assert(result1 - 0.865926 < 0.00001); - HurstExponentVisitor he_v2 ({ 1, 2, 4, 5, 6, 7 }); + HurstExponentVisitor he_v2 ( + { 1, 2, 4, 5, 6, 7 }); auto result2 = df.single_act_visit("d1_col", he_v2).get_result(); @@ -3318,8 +3341,12 @@ static void test_EhlerSuperSmootherVisitor() { try { df.read("data/SHORT_IBM.csv", io_format::csv2); - EhlerSuperSmootherVisitor ssf_v2; // poles = 2 - EhlerSuperSmootherVisitor ssf_v3(3); // poles = 3 + // poles = 2 + // + EhlerSuperSmootherVisitor ssf_v2; + // poles = 3 + // + EhlerSuperSmootherVisitor ssf_v3(3); df.single_act_visit("IBM_Close", ssf_v2); df.single_act_visit("IBM_Close", ssf_v3); diff --git a/test/dataframe_tester_3.cc b/test/dataframe_tester_3.cc index d27d3164e..79015f318 100644 --- a/test/dataframe_tester_3.cc +++ b/test/dataframe_tester_3.cc @@ -77,9 +77,10 @@ static void test_groupby_edge() { df.load_column("int_col", std::move(intvec), nan_policy::dont_pad_with_nans); - FactorizeVisitor fact([] (const double &f) -> bool { - return (f > 11106.0 && f < 114.0); - }); + FactorizeVisitor + fact([] (const double &f) -> bool { + return (f > 11106.0 && f < 114.0); + }); df.load_column("bool_col", df.single_act_visit("dbl_col_2", fact).get_result()); @@ -256,9 +257,10 @@ static void test_multithreading(int j) { std::cout << "PRINTING FIRST ..." << std::endl; df.write (std::cout, io_format::json); - FactorizeVisitor fact([] (const double &f) -> bool { - return (f > 11106.0 && f < 114.0); - }); + FactorizeVisitor + fact([] (const double &f) -> bool { + return (f > 11106.0 && f < 114.0); + }); df.load_column("bool_col", df.single_act_visit("dbl_col_2", fact).get_result()); From ae13ad6c8a8d24c8a129007bdc7b2f883033f8cf Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 25 Dec 2022 12:48:57 -0500 Subject: [PATCH 18/25] code reformatting 2 --- test/aligned_dataframe_tester_2.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/aligned_dataframe_tester_2.cc b/test/aligned_dataframe_tester_2.cc index 1685c13c9..09b91c51b 100644 --- a/test/aligned_dataframe_tester_2.cc +++ b/test/aligned_dataframe_tester_2.cc @@ -2152,7 +2152,7 @@ static void test_LowessVisitor() { std::cout << "\nTesting LowessVisitor{ } ..." << std::endl; - StlVecType idx = + StlVecType indx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473, @@ -2169,9 +2169,9 @@ static void test_LowessVisitor() { 168.01999, 164.95750, 152.61107, 160.78742, 168.55567, 152.42658, 221.70702, 222.69040, 243.18828, }; - MyDataFrame df; + MyDataFrame df; - df.load_data(std::move(idx), + df.load_data(std::move(indx), std::make_pair("indep_var", x_vec), std::make_pair("dep_var", y_vec)); @@ -3764,12 +3764,12 @@ static void test_FastFourierTransVisitor() { df2.single_act_visit("IBM_Close", fft2); df2.load_column("FFT Close", fft2.get_result()); - fft_v i_fft2 (true); + fft_v i_fft2_2 (true); - df2.single_act_visit("FFT Close", i_fft2); + df2.single_act_visit("FFT Close", i_fft2_2); /* - for (auto citer : i_fft2.get_result()) + for (auto citer : i_fft2_2.get_result()) std::cout << citer << ", "; std::cout << std::endl; */ From ca2032f169fca8761e7b435129e1af2cb8b88b00 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 25 Dec 2022 12:53:53 -0500 Subject: [PATCH 19/25] code reformatting 3 --- test/dataframe_tester_3.cc | 2 +- test/dataframe_tester_output.txt | 34 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/test/dataframe_tester_3.cc b/test/dataframe_tester_3.cc index 79015f318..967e16494 100644 --- a/test/dataframe_tester_3.cc +++ b/test/dataframe_tester_3.cc @@ -79,7 +79,7 @@ static void test_groupby_edge() { FactorizeVisitor fact([] (const double &f) -> bool { - return (f > 11106.0 && f < 114.0); + return (f > 11106.0 && f < 30000.0); }); df.load_column("bool_col", df.single_act_visit("dbl_col_2", fact).get_result()); diff --git a/test/dataframe_tester_output.txt b/test/dataframe_tester_output.txt index 7d18249b9..791ac1bcf 100644 --- a/test/dataframe_tester_output.txt +++ b/test/dataframe_tester_output.txt @@ -744,12 +744,12 @@ col_3:1::15, col_str:1::11, col_4:1::22, -INDEX:1::123450, -col_1:1::1, -col_2:1::8, -col_3:1::15, -col_str:1::11, -col_4:1::22, +INDEX:1::123451, +col_1:1::2, +col_2:1::9, +col_3:1::16, +col_str:1::22, +col_4:1::23, INDEX:1::123451, col_1:1::2, @@ -785,33 +785,35 @@ Testing Thread safety ... Testing View visitors ... Testing k-means visitor ... -1.17763942501 | 4.38928183597, 1.28493013344 | 6.35939017311, 0.240869258025 | 7.03164244336, 1.06446976862 | 5.76755888038, 1.85091480661 | 3.56601755836, 0.560800191803 | 3.94172421199, 0.204326020026 | 5.38053457013, 1.06227749902 | 3.32887892782, 0.767676157037 | 8.04083157094, 0.287658429308 | 3.90035765824, 0.549078572277 | 3.46521175036, 1.28557432634 | 4.02652216308, 1.3717432107 | 4.15135683906, 1.1666765887 | 4.21940782793, 1.88126693343 | 3.24503920767, 2.33162638935 | 3.61621194349, 0.88572948374 | 5.62811295615, 1.7815347027 | 6.39802154383, 0.482693103106 | 3.87937362627, 1.02200676131 | 5.82491379951, 2.30702542995 | 3.87702901921, 1.03305362898 | 2.95951458779, 1.32783017054 | 3.73183746736, 2.29782959738 | 2.95475595328, 0.581358895235 | 3.14196042234, 0.289052140622 | 4.21385549394, 0.616046410687 | 2.99549423288, 1.71229618928 | 2.65349923804, 0.0886306586577 | 5.54720096044, 0.542110934517 | 5.27291489362, 0.752293305347 | 2.81746035796, 0.670098941575 | 2.96202919149, 2.47145131742 | 3.79801401632, 0.28133750636 | 4.60208804416, 1.35267797996 | 4.28292648693, 0.364540243969 | 6.3569781481, 2.20812323428 | 5.07805996318, 2.12137568015 | 6.6747098452, 0.166353203758 | 4.03550302661, 0.620417494294 | 4.95164596018, 0.26121846435 | 2.82614274714, 3.22665353121 | 7.54935839024, 3.92625567711 | 6.96830309826, 0.60837176819 | 3.31354097698, 1.64989967559 | 3.30217349962, 0.445023478607 | 3.72288458019, 2.0682043428 | 5.01261948869, 2.63356686713 | 4.72964211396, 0.819647716489 | 3.82130603233, 0.171170256461 | 3.2017898339, 0.524251231048 | 4.09041765945, 0.724765244843 | 3.1598983741, 0.4697885866 | 3.15802002661, 0.52324978008 | 5.96912943032, 0.893823084826 | 5.45683921096, 0.722953832927 | 3.62714869847, 0.704881878481 | 4.02419056834, 4.1602516774 | 6.33314126649, 0.500534521353 | 3.02627453718, 0.583126817415 | 5.96386076994, 0.466048124604 | 3.46294257099, 0.179031759309 | 5.26607584377, 0.45724210253 | 3.11801722202, 0.862164525581 | 2.92851391572, 0.173314113277 | 3.72735933464, 0.538569287115 | 4.92580493638, 0.390680263449 | 2.79462407244, 1.15433944412 | 3.57435442163, 0.0732141894855 | 2.93116741568, 0.263645372967 | 3.57756419709, 0.391982292778 | 4.18362781814, 0.594217196889 | 3.53179940652, 2.14109421305 | 6.55987520748, 3.83639899335 | 4.86797816393, 0.348746070584 | 6.3700253128, 2.12549239953 | 4.98282617037, 2.36752634548 | 3.22792442933, 1.22119375487 | 2.77697171188, 1.00979686636 | 5.29703984899, 0.833895274719 | 6.62909042771, 0.347141870601 | 4.40659287289, 5.08221553469 | 6.10303415513, 0.964895788694 | 5.44053902503, 1.08756545279 | 4.8789513143, 2.23999505903 | 4.3166879081, 0.473521329208 | 2.98710598996, 0.328338724717 | 3.63097391706, 1.23470920872 | 6.7973727924, 1.9035288097 | 3.24610611687, 1.1784536745 | 3.94056489811, 0.411994713837 | 2.91333974149, 0.489683388036 | 3.24695467582, 3.31228444368 | 5.16608807043, 2.15783928424 | 6.64157896073, 0.443948417653 | 3.90620905535, 0.857821288928 | 2.99368138591, 1.49978921496 | 4.82356273722, 0.872133033001 | 3.24174085834, 0.671829924207 | 7.0297101486, 1.05445859205 | 5.57595950789, 2.05900637254 | 6.26457094003, 1.57523003841 | 4.52409713881, 1.86723700435 | 3.43962071765, 1.02665748354 | 2.88684218402, 0.615864835786 | 2.79588577333, 3.19936855967 | 6.28220288061, 2.24047550738 | 5.53008426524, 2.67776787413 | 4.6979181139, 0.691843888188 | 3.21307396541, 0.571058813624 | 2.73530696092, 1.43753751622 | 5.45398911799, 1.24904449588 | 4.59098415211, 1.54683188803 | 6.95696824446, 2.47779777105 | 2.93320405304, 0.781522157919 | 2.91004051631, 0.301246739639 | 5.26895903219, 0.306685834123 | 4.60887518719, 0.265632061612 | 3.26882144595, 1.19966487878 | 3.6535443819, 0.188136710265 | 4.14584814624, 2.33527964251 | 5.80344863563, 1.13784018644 | 3.42992972216, 0.91284645791 | 2.98845131819, 1.0433126427 | 3.16354583136, 1.26296583529 | 3.19865984381, 0.505621332362 | 4.19219777501, 0.931137763214 | 5.40185803252, 2.04991447833 | 4.62938819872, 1.13690449509 | 4.79651539634, 0.351554660116 | 2.8958337638, 1.51567327906 | 4.55829133501, 0.649572699232 | 4.88949726483, 1.33977020783 | 4.82209780777, 2.23734997143 | 3.3258080338, 0.952472446905 | 5.97617136259, 2.57089117035 | 5.69604486922, 1.37084925259 | 5.01281981416, 0.271180017839 | 3.54518484945, 0.856736542786 | 3.53818746945, 1.37977612576 | 4.25200938943, 0.938933657517 | 6.26438414846, 1.17952710259 | 2.88790645751, 0.192888783336 | 5.09273429578, 1.49949839775 | 2.95199691542, 0.84897400017 | 2.91089046258, 1.22377461382 | 4.42589120179, 1.417365782 | 4.06896381627, +0.945638582511 | 0.981290892304, 0.169963486799 | 0.296020947379, 0.271942650466 | 1.64739221905, 0.326711138057 | 0.863565309388, 1.66146343193 | 0.10325913533, 0.893056486982 | 0.808682871045, 0.282138178835 | 0.371623453277, 0.371895553115 | 0.434925299581, 0.376274486482 | 1.39877606315, 1.0446211384 | 0.571090947977, 0.466324696171 | 0.308323819636, 1.44638826983 | 1.56045441673, 0.320121767249 | 0.501052292835, 0.580846772301 | 1.30830960928, 0.521159294492 | 2.32581712491, 1.36234293815 | 0.289371891003, 0.963647635211 | 1.0261635, 0.637637095911 | 2.04389724471, 1.73748324726 | 0.860053341243, 0.613136565362 | 0.190705662033, 0.701077196961 | 0.193164499076, 0.107195404818 | 0.534806493228, 2.16015060747 | 0.42304329124, 0.922355654532 | 2.02841264143, 1.16959960242 | 2.31610780363, 1.02545023421 | 0.582097280023, 0.494289746101 | 1.28037865741, 0.040977350523 | 0.439638684942, 0.812148875111 | 1.47854501694, 0.569251356464 | 1.15224692006, 0.252754750614 | 0.89989902386, 2.06911336897 | 0.290356054276, 0.305260524931 | 0.990555427867, 0.874265659665 | 2.20241001084, 0.339578116871 | 0.320754547992, 1.93511267746 | 0.587733491711, 1.49362864494 | 1.93197678658, 0.412150967857 | 1.01319160519, 0.902855287476 | 1.07735390865, 1.0106755563 | 0.665572272889, 0.735666970712 | 0.302010636883, 2.07588001793 | 0.794593877907, 0.171995382581 | 1.49726413026, 1.78587441529 | 0.243153154046, 0.378541436116 | 1.31991388346, 0.918472780684 | 2.06758418387, 0.249403107207 | 0.454176981891, 0.583046618517 | 1.94950630499, 0.0628704638461 | 0.387939757822, 2.42609604173 | 1.29214747348, 1.43586493567 | 2.0391938725, 0.417967523855 | 2.22062836794, 1.098242156 | 2.59297376409, 0.480189177144 | 2.10100373728, 1.73565282659 | 1.62926884235, 0.760730091571 | 0.315153143947, 0.866559797058 | 1.76506993856, 0.984499639614 | 0.44249951319, 1.30348326941 | 1.44005990567, 0.13105037532 | 2.63608457803, 0.252311764312 | 1.41263674761, 0.228552899932 | 1.18621757992, 1.0290999953 | 0.390120245762, 0.882866151676 | 1.64057234467, 1.23446216599 | 2.00902296698, 1.71823504911 | 1.66540218242, 0.372278412557 | 1.07397574734, 1.63805067019 | 0.722246090948, 2.57845909391 | 0.640741806074, 1.49235149587 | 1.45715491558, 2.21722378657 | 1.27240410181, 0.326815409914 | 0.485455556687, 0.748585404096 | 0.78756538169, 0.21745467698 | 1.0401079674, 2.21873677412 | 1.02993567713, 1.03597832861 | 0.350879406929, 0.343317792485 | 1.41188975191, 2.51673013034 | 1.01486660235, 1.1147940572 | 1.19178509596, 0.849198242163 | 1.69635984254, 0.758328393524 | 1.4736114257, 0.327236321769 | 0.947598237393, 0.297280087477 | 1.1390147908, 2.18011601789 | 0.297370086524, 0.8865335918 | 1.69415944125, 0.462460808338 | 1.8253858595, 0.960770450807 | 0.280985644803, 0.323387454337 | 0.152741315791, 0.295106002294 | 0.683710648029, 1.56585975281 | 0.828774714947, 1.28799561213 | 0.795433234715, 0.254180636839 | 0.739464244104, 0.486943161095 | 1.03563187104, 0.660394558092 | 0.803358570279, 0.954368451522 | 0.276509523751, 0.406474300541 | 0.827818544391, 0.461464091627 | 0.599869936581, 0.199402475443 | 1.68554411367, 1.20127716327 | 0.216781902792, 0.110914892968 | 0.306856799157, 0.150685481569 | 1.19148169785, 1.83776276952 | 0.469180820593, 1.1195849682 | 2.44610092219, 0.737349207148 | 2.3976699186, 0.333876817449 | 1.37480679256, 1.30679336404 | 1.41567335553, 0.816394091152 | 1.10046765105, 2.29856419478 | 0.485561779197, 0.403110767438 | 1.6268797303, 0.299919940596 | 0.331093402906, 0.483404071006 | 0.290318020102, 0.744873723165 | 1.30272252912, 2.26695861761 | 1.08617294566, 1.50590267295 | 0.433719251144, 1.97273495528 | 2.02645491744, 0.412510467935 | 1.53621178736, 0.340579806797 | 0.953479355234, 0.477579225453 | 1.14369175893, 0.242254482121 | 1.14793354682, 0.812293430821 | 1.56412861853, 0.879667239287 | 0.866309360039, 0.634709228209 | 0.950164048793, 1.76004127096 | 0.755274750165, 1.05606204331 | 2.448576038, 1.76765732635 | 0.983803575974, 0.585782455829 | 0.432310082049, 0.348373922445 | 0.512929947691, 1.60506043565 | 1.07206564725, 0.507838904838 | 1.44461249943, 1.05914192838 | 0.380250398523, 0.896368847415 | 0.299026808915, 1.38264259557 | 0.328637413493, 0.197905188789 | 0.219648997204, 0.610847484075 | 1.378647892, 0.869589558242 | 0.440714327768, 0.783770455788 | 1.06490063493, 0.974629152681 | 2.20910632802, 2.33542719376 | 0.745929386166, 0.315350487304 | 0.354331468356, 0.492928346606 | 0.219002553457, 2.55146883283 | 0.274969047634, 1.40057031621 | 2.27381199684, 1.03864873742 | 0.979007797872, 0.962250524318 | 0.48152121663, 0.386891788541 | 0.483093997597, 1.29666721286 | 1.72165015887, 1.34710948498 | 0.507143795547, 2.18322390256 | 0.172569287983, 1.56301083559 | 0.458743636828, 0.751123742453 | 0.946768432963, 0.690327863639 | 0.992447329403, 0.671823935165 | 2.0978362702, 0.461285118688 | 2.42986142136, 0.250587958715 | 1.29453084627, 2.12937070061 | 1.6383108554, 2.14104233392 | 0.786737857766, 1.66896358889 | 0.377690250523, 2.64777900836 | 0.256778514556, 1.27016157677 | 0.957061170215, 1.48771892078 | 0.616825275551, 0.562017881387 | 1.74590123742, 1.56481864613 | 1.43614555065, 1.10247098536 | 0.377623446533, 0.602776058237 | 0.859106463858, 0.202677292862 | 0.855468120433, 1.82480920271 | 0.496915629909, 0.487247587407 | 0.801326132058, 0.515826294323 | 0.871320724668, 2.19109082809 | 0.644508364546, 0.884618026883 | 1.11758756205, 1.59484914041 | 0.57017322245, 0.498701179507 | 0.933886600228, 0.9693112402 | 1.31405068172, 1.66852970075 | 1.28329575891, 0.579302946369 | 0.151769005917, 0.263279735437 | 2.45623642144, 1.62841230125 | 1.1730311994, 0.307412429659 | 0.676678406507, 0.310302068518 | 0.565438184851, 1.37517051701 | 1.20057856368, 0.252429971783 | 1.69157736474, 0.351928716246 | 2.45380572359, 0.78207486059 | 0.303181203474, 0.818487565897 | 0.0922592753118, 1.30759253408 | 2.28938372681, 0.0365828847014 | 2.65549003031, 0.383402451249 | 0.545838008629, 0.163346978989 | 0.348357206478, 1.22557680956 | 1.42433129564, 1.65024542028 | 0.856078285278, 1.19555457329 | 0.15903928358, 1.20995434808 | 0.961732048479, 0.416115951752 | 0.376111365586, 0.465160867886 | 1.74674578848, 1.68903481752 | 1.72441216776, 1.67477696097 | 2.60016921821, 0.930827044668 | 0.894383569469, 0.498284284652 | 1.53063385682, 2.69170609551 | 0.557907104774, 0.88187712161 | 0.250559670471, 0.22676531703 | 0.429813566252, 0.956716138216 | 0.130649805751, 0.456105469958 | 1.87824852012, 0.474202306008 | 1.32051975501, 0.311833074448 | 1.19912691392, 0.243732233658 | 0.402424265378, 1.02215168453 | 1.86176187971, 0.936961221963 | 0.293180129731, 2.53127719979 | 0.818797484154, 0.416835118578 | 0.733084462339, 2.09182221074 | 1.09530550263, 1.5377669992 | 0.445950122358, 0.204831284909 | 1.3178848594, 0.549254096821 | 1.68936636922, 0.71094663964 | 0.117115367062, 2.23920560823 | 0.145518035333, 0.973116540588 | 1.82170431151, 0.743233301348 | 1.52405120812, 0.658241041235 | 0.360435704697, 1.76919944043 | 0.857601246328, 0.276799082879 | 1.91143301777, 0.79134554538 | 0.743552871892, 0.724608730694 | 1.22684618238, 0.623110069773 | 1.53275190557, 0.312840367772 | 0.344455103878, 1.05691049646 | 1.15728791277, 0.887089613177 | 0.402850065386, 1.42555762373 | 2.36884242177, 1.47592563111 | 2.34839395956, 1.16457801632 | 1.22734496901, 0.783878255489 | 2.25752535531, 2.20804418257 | 1.21773633899, 0.241587451543 | 0.774212980682, 1.00505746299 | 0.812620504393, 1.66815323836 | 0.715371383661, 0.766527640568 | 1.71161858755, 2.05901816836 | 1.16153214238, 0.868749340576 | 0.971393032742, 1.40106991445 | 2.12294583893, 1.05536033497 | 0.164177899521, 2.36560207183 | 0.27734683301, 0.980177237504 | 0.543463248649, 1.08704357615 | 0.455083257825, 0.865440367712 | 0.561580102184, 1.45086272985 | 1.79651065388, 0.173171780362 | 0.521629375215, 1.02386212465 | 0.923704072222, 2.13355472037 | 0.426544022113, 0.663554456113 | 2.10181679452, 0.407430964684 | 2.26725646845, 1.43898785591 | 0.200391084607, 0.194643343686 | 0.418568600642, 0.93320304839 | 0.701183244743, 1.0023018653 | 0.982458148711, 0.203912872225 | 2.35983089781, 0.597685297377 | 0.934032105178, 0.56274796731 | 1.37174805663, 0.454101796359 | 2.68035254973, 0.550821658799 | 0.904427683499, 0.864005872791 | 1.44879086382, 0.888159398828 | 0.588379026454, 0.931121787456 | 1.60958802959, 0.704842970104 | 1.41076676979, 1.9601170371 | 0.293684499559, 0.441600207327 | 1.29210072348, 0.186913610614 | 0.721378346275, 1.08064941697 | 0.960767147851, 1.78162939885 | 0.467341316827, 0.652344124139 | 0.507023869883, 0.774367097583 | 1.65016248063, 0.1720556597 | 0.678633121852, 2.07498016083 | 1.81380931024, 1.7286173085 | 1.40212944728, 2.60004402628 | 1.27068724087, 1.28532968364 | 0.370060400749, 0.166369844744 | 0.122998474704, 0.510398539045 | 1.21490966623, 0.630318270253 | 2.39089643976, 0.905989117184 | 0.500760167128, 0.411668316376 | 0.557951377106, 1.42068599634 | 0.900566133803, 0.437521123395 | 0.892652768709, 0.420202460094 | 0.294168014628, 1.68008509731 | 0.211094396734, 1.25487856277 | 2.57344633519, 2.49384672854 | 1.20152376007, 1.15518708601 | 1.10416702024, 1.63321448193 | 0.58792458609, 0.958840262092 | 0.595406726254, 0.561483869816 | 0.444579804477, 0.706789275528 | 0.502767161944, 1.10985090694 | 2.11414192209, 1.09534403376 | 0.500158077678, 1.0010283532 | 2.03128916932, 0.422999121123 | 0.55114088445, 1.4327102843 | 0.4236682025, 2.25781580774 | 0.120786449823, 0.629075089004 | 1.60295440061, 0.225025775619 | 0.833568335906, 1.21452252754 | 0.530369453109, 0.50045367977 | 2.66772686192, 0.631097719153 | 0.449290649308, 1.62617489517 | 0.669897743569, 0.15844024558 | 0.253388002697, 0.725149018541 | 0.265037040637, 0.53002489067 | 2.30031197637, 1.39565285273 | 0.976122356777, 0.30640654915 | 0.568772989178, 0.40938388171 | 1.14663487734, 0.435696076396 | 1.34209081007, 0.938392435311 | 0.561376360631, 0.529331993958 | 0.537495254361, 0.989327786559 | 0.431691501708, 0.425334803543 | 0.237494380559, 1.6994977688 | 0.711516292504, 0.508282652828 | 0.470621634986, 0.949366270837 | 0.38411875556, 0.820774682384 | 1.40456469575, 0.692317412848 | 0.438430613274, 1.00929866149 | 0.893650197321, 0.387846108432 | 0.268509916794, 1.27671131479 | 1.62801362147, 0.267203120339 | 0.570965479242, 2.09456628119 | 0.281499069012, 0.82383188417 | 0.318940184304, 1.23539172258 | 0.772306193335, 0.373867669606 | 2.29078453512, 0.28210053162 | 1.36232285579, 0.494882550551 | 0.649548385865, 0.808060415401 | 1.71990258451, 2.29629733041 | 0.830011621788, 0.399303755146 | 1.09577281718, 0.397020067431 | 1.10348325361, 1.09250514355 | 0.542655028833, 0.901057404441 | 0.731512366958, 2.46928657737 | 1.57278241092, 2.498282512 | 0.452416381131, 0.890337588128 | 1.67761448177, 2.27438277799 | 0.149031471475, 0.462431477873 | 1.11630608799, 1.82087708903 | 2.13833284998, 1.71205170727 | 0.422208884884, 0.718991222734 | 0.999172444412, 0.90409622282 | 0.770902294249, 0.41595031335 | 0.301609068896, 0.537498432655 | 0.159178443431, 2.05242704057 | 0.409303474894, 0.323174970795 | 1.56859933281, 0.136081406461 | 1.75935494095, 0.359225375456 | 0.828503162647, 0.474833116607 | 1.38219933945, 0.36294977912 | 1.54186210627, 0.171192485795 | 0.365059759874, 0.334182459126 | 0.745342750611, 0.728429486311 | 0.153240675947, 2.08090480299 | 1.46323076922, 0.421432445838 | 0.875606531018, 0.645400212811 | 0.167875334373, 0.222398227763 | 0.277204905022, 0.397502013991 | 1.37811694283, 0.29246139853 | 0.635786327135, 0.170354761219 | 0.708223947746, 0.439340129297 | 1.53213549452, 1.18023540556 | 0.121456580178, 1.94794701947 | 0.312182693105, 0.529972160774 | 1.04310152524, 1.87586780141 | 1.26254799827, 0.477130456532 | 0.97691541019, 0.170524391565 | 1.62963040786, 2.38548774243 | 0.465172517712, 0.512036027982 | 2.14009371978, 0.229784327831 | 0.127123967881, 1.96755726076 | 2.08141385208, 1.96862533501 | 0.2631088277, 1.41925129919 | 0.572428676801, 0.205180768736 | 0.454617726276, 1.60056379553 | 0.6761093445, 0.425651919745 | 0.484887596033, 1.48090906946 | 0.211726923328, 1.92753780122 | 2.39257243326, 0.640071263911 | 0.525528901278, 0.647831837101 | 0.658106984551, 1.41171609269 | 1.39900005357, 0.964187221285 | 0.155376748348, 1.68417673539 | 0.185645233388, 1.41243205755 | 0.809937910121, 1.64830925878 | 0.738013539721, 0.305338428251 | 2.07398096159, 1.01281101684 | 1.82626181913, 1.8126029486 | 0.218993819183, 0.71966531448 | 0.362541592676, 2.08641562045 | 0.98148684941, 0.636535224106 | 0.313872315055, 1.40977258716 | 0.678022159306, 1.24166641221 | 0.609991845116, 1.74253866817 | 1.46040158917, 1.53754329054 | 0.660626454717, 0.597995275824 | 1.48814745089, 1.20542447458 | 0.505315919074, 0.536401176403 | 0.281826270627, 1.070798275 | 0.95834475172, 1.35298629652 | 0.673784667412, 0.599803458852 | 0.219417883296, 2.26559303637 | 1.42413692639, 0.535151579789 | 0.657256964612, 0.480512266067 | 0.815388055578, 0.773392724319 | 1.61013365084, 0.493310761399 | 0.418544613608, 1.34089170111 | 1.7068975579, 0.673330271486 | 0.264375854879, 0.575452003518 | 1.63173639771, 2.2081146561 | 0.364365530036, 1.72225825441 | 1.5470904448, 0.952163870647 | 1.49778474856, 1.15337131483 | 1.09003763497, 0.782193790851 | 0.178966874852, 0.765340012954 | 0.852179683933, 0.496726682726 | 0.167151510528, 0.663326898335 | 0.948944448328, 1.97981599474 | 0.707205610376, 0.84340642222 | 0.436949076491, 0.91963443566 | 0.776046575221, 0.605737424917 | 1.60015270552, 0.422421990368 | 1.04936456164, 0.381151414216 | 0.264343430161, 0.622164638491 | 0.852284921196, 0.305098959856 | 1.77366223436, 0.481777476786 | 1.60802928194, 0.163359027537 | 0.710824636012, 0.684987565952 | 0.99510238546, 0.188211268233 | 0.823820497723, 2.14311778893 | 1.56206519754, 1.3086307245 | 1.08109631897, 0.390588336682 | 0.919819819885, 2.31974002745 | 1.62756987109, 0.614974801944 | 0.598313170447, 0.843626194748 | 0.604242807902, 0.636158508427 | 1.12989253902, 0.67105709693 | 0.758347926235, 0.775979699259 | 1.53209138919, 0.887546305819 | 1.20789735698, 2.52182183354 | 0.812329311574, 0.0971717140767 | 0.964320738679, 0.14004048798 | 0.920098235851, 2.00846366364 | 2.4557011831, 1.12151090032 | 0.853759604699, 0.727162510977 | 0.231292123824, 1.59527491231 | 0.926772209017, 0.731720842669 | 0.202655056805, 0.525579966204 | 0.533822043294, 1.25057832601 | 0.645088929691, 0.843880981994 | 1.95791961703, 0.712715776817 | 2.18829586412, 1.10783936766 | 1.73224684766, 0.578847997854 | 0.924281167826, 0.589314544945 | 0.808646078631, 1.21492852927 | 2.1230332813, 0.341393443397 | 1.21037536003, 0.126432699551 | 1.54192553591, 0.511932202416 | 0.765899793629, 0.395202383353 | 1.2363401175, 0.77724713562 | 2.51855342955, 0.273856441279 | 0.393652186888, 0.882024098771 | 0.566599088531, 0.690396308482 | 1.88319788867, 0.999749198393 | 0.733638578713, 2.22882275773 | 0.669853410149, 0.875218740075 | 0.582649287505, 1.63328674826 | 0.201133960007, 0.793161060451 | 0.663718597361, 0.329071873479 | 1.07987583433, 1.99120622681 | 1.99211913207, 0.504233548664 | 0.659435709443, 0.853499272731 | 0.345364456904, 1.34431769103 | 0.278306797127, 0.209910644811 | 1.88000099606, 0.402769254395 | 0.954466120856, 1.86003563015 | 0.87892618468, 2.00752873919 | 2.1407856441, 0.620211007538 | 0.138453930261, 0.770165847942 | 0.62378215165, 0.74959336533 | 1.33728533031, 0.50462114009 | 0.445042859751, 0.189250295657 | 0.660406391209, 0.434605552397 | 0.22178322483, 0.68236604141 | 1.56166769423, 0.832239910097 | 0.233221488198, 0.78245768116 | 0.741202429821, 0.965826839553 | 0.934556395143, 0.130846893621 | 1.11587381052, 0.667497076673 | 0.717405898166, 0.97740562861 | 0.689225474105, 0.795988256774 | 1.66696061208, 2.34354518593 | 1.5179763001, 1.38697819984 | 0.473498124854, 0.349913622683 | 1.32267170468, 2.1159373567 | 0.259589940885, 2.25210302955 | 1.95958894032, 0.710976019695 | 1.04963312821, 0.924015256509 | 0.760544725505, 0.296514874359 | 0.113122440263, 2.23084646792 | 0.243564664551, 0.26346461111 | 0.440754560368, 1.0715856015 | 0.509927020375, 1.63783411807 | 1.12521756605, 2.2302529008 | 2.35645791433, 0.915087720222 | 1.56710280562, 0.769485344172 | 0.248207342307, 0.562717869221 | 0.965526877092, 0.336842640208 | 0.19853158974, 0.427024239875 | 2.24454740734, 0.764685185952 | 0.619480787044, 0.418033596885 | 0.774286104585, 0.68888479574 | 0.125979540079, 0.0789017155741 | 0.461785526451, 0.801360151769 | 0.345616246776, 2.1789940249 | 1.30334820382, 1.20677929031 | 0.507175219192, 2.19566132931 | 0.465653543398, 0.16590374418 | 0.308072265434, 0.0637027302805 | 0.483564192316, 1.09349401349 | 0.905851262722, 0.573089947219 | 0.715019506955, 1.48483305656 | 0.380738427642, 1.14935744019 | 0.333763234994, 1.24029775728 | 0.397111634141, 1.34418585379 | 0.113193498003, 0.671041101156 | 1.35410590562, 0.390926660115 | 1.08186320167, 0.33661534615 | 0.765425749799, 1.08834975518 | 0.810947205976, 0.569418944679 | 0.940696496622, 1.25997239312 | 0.626483377512, 0.413155167038 | 0.904442146327, 1.03203991993 | 0.711938444817, 1.52168008363 | 1.54080563258, 0.38928585155 | 0.770407515959, 0.085255861139 | 0.73923254933, 1.58762941258 | 0.659138709005, 0.512284455921 | 0.92031895578, 0.850342009856 | 0.268061807311, 1.14058104213 | 1.56681409758, 1.44216026603 | 1.91421615747, 0.845885547906 | 1.63985372312, 1.24478247216 | 0.450748132611, 1.82410974566 | 0.697395503699, 1.82872152949 | 1.25926866537, 0.694586560271 | 0.388500238778, 1.72232493005 | 0.274416690378, 1.15291850738 | 0.90296219851, 1.16673054304 | 0.104305361337, 1.16063279398 | 0.521132703284, 0.296156686446 | 1.8679029195, 1.17686072594 | 2.02285673943, 1.7778341745 | 1.23127181834, 0.756965279945 | 1.67483657582, 1.01403434916 | 0.740872489054, 0.812595873307 | 0.917893956796, 0.817842968403 | 0.558584850458, 0.232684911588 | 0.678369122611, 0.278425956778 | 0.227775690666, 0.178533495852 | 1.33749658045, 0.631646125283 | 1.42185983994, 0.765984060952 | 0.908957391154, 0.44790886395 | 1.54482216087, 0.704456763101 | 1.36945926045, 2.17914005163 | 1.62467102869, 0.489003519059 | 0.690705448433, 1.83283363575 | 1.01767679582, 0.70861080217 | 1.57450668475, 0.57610882203 | 0.473249561678, 0.664741868378 | 0.735208685119, 1.5757565479 | 0.18426288072, 0.878309875115 | 0.332975169199, 0.438143922785 | 0.215967922997, 1.36421398698 | 0.471883689741, 0.256211198777 | 0.414998667144, 1.31092843969 | 0.219586816948, 0.783520026453 | 0.831975463277, 0.195890217112 | 1.4299150827, 1.95815197824 | 1.05002765427, 1.52913978352 | 1.23150409232, 0.580259945724 | 2.35911126559, 2.22769732589 | 1.61770663679, 0.183492787229 | 0.643513245427, 0.988382500483 | 1.85752344497, 0.848080293145 | 1.35119281053, 2.48171183089 | 1.28632655848, 0.312491623546 | 0.841463611185, 0.157004140351 | 2.45436382205, 0.507365294761 | 0.304117530758, 0.869372517219 | 0.353336617062, 0.763104658288 | 2.32420390099, 1.88019093712 | 1.95216407426, 0.204714685224 | 1.52780993423, 0.0545826165707 | 2.38315812496, 0.14295967406 | 0.225578590239, 0.693437878737 | 0.535668065968, 0.0819471695546 | 0.462541931253, 0.293870938911 | 0.441694179349, 2.33937617784 | 0.142259395872, 0.825252543535 | 0.456228012554, 0.702242653502 | 0.46739999492, 0.889612835974 | 1.21256708162, 2.42940024377 | 0.423790867265, 0.127026739464 | 0.580616610077, 0.197206956564 | 0.996879044506, 0.427231755341 | 0.393218233116, 0.951241339176 | 0.36110858966, 0.111899851393 | 0.690828417936, 1.26487113741 | 1.33535834546, 0.633474291484 | 2.10362625787, 1.94450849716 | 0.78007343787, 0.752310627076 | 0.280668266579, 0.314568159422 | 1.31691816663, 1.75436750673 | 0.701082667486, 1.2839408341 | 0.388150026311, 0.170860339017 | 1.35866365911, 1.85320399828 | 1.37060928035, 1.30963875486 | 2.17247469363, 0.301561762877 | 0.687279017126, 0.314213489864 | 1.11787138165, 1.40929186547 | 1.95659146094, 0.264813382951 | 0.547163494095, 0.795750610604 | 1.01228248999, 0.324091207232 | 0.685667622517, 0.985314319927 | 1.5705959015, 1.30117489635 | 1.31299302769, 1.30407945375 | 0.182469523169, 0.439047079725 | 0.795790051555, 1.91611507184 | 1.20599571362, 0.56106358881 | 1.0745739754, 0.208406057798 | 1.18054244106, 1.94570404926 | 0.0928107785895, 1.3955435982 | 1.51637512069, 0.4417995657 | 1.94249144146, 1.17963917692 | 0.448236324737, 0.852969585332 | 0.183091926755, 1.79031991058 | 0.675614281957, 0.936484890277 | 0.0746451914142, 2.50483731076 | 0.54000859291, 1.84259862454 | 2.57103833386, 1.1349984282 | 0.748745663131, 0.796693534504 | 0.614492421858, 0.537169856445 | 0.462171128835, 2.16174141875 | 0.347557637785, 0.181603755915 | 1.57429390357, 2.39914666631 | 0.38834115031, 0.133616301846 | 1.5954546239, 0.577078642539 | 0.910071071042, 1.23516277524 | 0.66520761334, 0.370906958471 | 0.855509777542, 0.290070488546 | 0.76668747369, 1.22623691309 | 0.103596005078, 2.21146694485 | 1.69138889677, 0.514613006991 | 1.39026361086, 0.230859156687 | 1.85117096138, 0.361941883968 | 0.23503813583, 0.67075189379 | 0.711943965736, 1.55807956365 | 1.39302173275, 0.616058695784 | 1.91959850383, 1.70575501048 | 0.189408386188, 0.692221896558 | 0.395819025962, 0.253648549006 | 1.91475448468, 0.495884526486 | 0.233077201067, 0.340204109878 | 0.247563401137, 0.93707721899 | 1.13127817125, 0.269090748269 | 1.1631762973, 0.638751187288 | 0.321131937769, 0.492992920485 | 0.447407655479, 2.02440389451 | 2.26231648074, 0.789882261738 | 1.15794284614, 0.29278782541 | 1.10024583258, 0.45049179626 | 0.678611186296, 1.04589787191 | 1.64656087762, 0.178864369497 | 0.761164146489, 0.89806046891 | 1.45528284778, 0.379016876334 | 0.451555418047, 1.23540113658 | 1.0817579536, 0.513355152752 | 0.87737706784, 1.29144542689 | 0.729080787308, 0.258520249874 | 0.239467171244, 0.323560188597 | 2.08624039163, 0.797604356098 | 0.273101440892, 2.61953474612 | 1.19207111958, 1.36129334193 | 1.8685736771, 0.749890256181 | 0.445499643062, 0.174595392697 | 0.838493637356, 1.39208279198 | 0.517891810342, 0.95046039368 | 1.45344517236, 0.227773910269 | 0.522981059249, 0.120324153047 | 1.37535157239, 0.244158432185 | 1.22661164086, 0.331264977016 | 0.782302622523, 1.88051895815 | 0.448592430089, 0.466689623514 | 0.462346397071, 0.480646947224 | 1.20639666774, 2.43404313107 | 0.814361675357, 0.551635800558 | 2.31858685454, 0.624310045902 | 1.02813347379, 2.21144953237 | 0.899248530077, 0.442620551965 | 2.00807591843, -1.54081876229 | 12.3779975132, 0.766429423621 | 9.34776193739, 0.455413356751 | 13.183251825, 3.68161078878 | 20.3481237204, 2.35425744809 | 10.9139359587, 0.613231973752 | 12.364624746, 1.94693471203 | 12.8171405043, 0.840922034797 | 9.41115051023, 0.95734730579 | 9.49469931487, 1.97015551877 | 8.89570840834, 0.458238675858 | 19.101984561, 0.869923011972 | 11.646262575, 4.87816630053 | 8.33695792175, 0.921539044558 | 10.9787428056, 1.98427978492 | 10.4619593119, 1.37603007069 | 19.4718669618, 0.569969260551 | 9.76362147103, 1.60606491009 | 8.97144761846, 0.423403937902 | 11.2998140608, 0.472892304832 | 18.3879587203, 4.33486051914 | 10.3958590128, 0.61651596336 | 8.79223302653, 0.709333471028 | 10.1578879873, 4.43210849644 | 11.6260528893, 1.0927858146 | 9.53206042213, 0.188054928458 | 23.7488315602, +1.17763942501 | 4.38928183597, 1.28493013344 | 6.35939017311, 0.240869258025 | 7.03164244336, 1.06446976862 | 5.76755888038, 1.85091480661 | 3.56601755836, 0.560800191803 | 3.94172421199, 0.204326020026 | 5.38053457013, 1.06227749902 | 3.32887892782, 0.767676157037 | 8.04083157094, 0.287658429308 | 3.90035765824, 0.549078572277 | 3.46521175036, 1.28557432634 | 4.02652216308, 1.3717432107 | 4.15135683906, 1.1666765887 | 4.21940782793, 1.88126693343 | 3.24503920767, 2.33162638935 | 3.61621194349, 0.88572948374 | 5.62811295615, 1.7815347027 | 6.39802154383, 0.482693103106 | 3.87937362627, 1.02200676131 | 5.82491379951, 2.30702542995 | 3.87702901921, 1.03305362898 | 2.95951458779, 1.32783017054 | 3.73183746736, 2.29782959738 | 2.95475595328, 0.581358895235 | 3.14196042234, 0.289052140622 | 4.21385549394, 0.616046410687 | 2.99549423288, 1.71229618928 | 2.65349923804, 0.0886306586577 | 5.54720096044, 0.542110934517 | 5.27291489362, 0.752293305347 | 2.81746035796, 0.670098941575 | 2.96202919149, 2.47145131742 | 3.79801401632, 0.28133750636 | 4.60208804416, 1.35267797996 | 4.28292648693, 0.364540243969 | 6.3569781481, 2.20812323428 | 5.07805996318, 2.12137568015 | 6.6747098452, 0.166353203758 | 4.03550302661, 0.620417494294 | 4.95164596018, 0.26121846435 | 2.82614274714, 3.22665353121 | 7.54935839024, 3.92625567711 | 6.96830309826, 0.60837176819 | 3.31354097698, 1.64989967559 | 3.30217349962, 0.445023478607 | 3.72288458019, 2.0682043428 | 5.01261948869, 2.63356686713 | 4.72964211396, 0.819647716489 | 3.82130603233, 0.171170256461 | 3.2017898339, 0.524251231048 | 4.09041765945, 0.724765244843 | 3.1598983741, 0.4697885866 | 3.15802002661, 0.52324978008 | 5.96912943032, 0.893823084826 | 5.45683921096, 0.722953832927 | 3.62714869847, 0.704881878481 | 4.02419056834, 4.1602516774 | 6.33314126649, 0.500534521353 | 3.02627453718, 0.583126817415 | 5.96386076994, 0.466048124604 | 3.46294257099, 0.179031759309 | 5.26607584377, 0.45724210253 | 3.11801722202, 0.862164525581 | 2.92851391572, 0.173314113277 | 3.72735933464, 0.538569287115 | 4.92580493638, 0.390680263449 | 2.79462407244, 1.15433944412 | 3.57435442163, 0.0732141894855 | 2.93116741568, 0.263645372967 | 3.57756419709, 0.391982292778 | 4.18362781814, 0.594217196889 | 3.53179940652, 2.14109421305 | 6.55987520748, 3.83639899335 | 4.86797816393, 0.348746070584 | 6.3700253128, 2.12549239953 | 4.98282617037, 2.36752634548 | 3.22792442933, 1.22119375487 | 2.77697171188, 1.00979686636 | 5.29703984899, 0.833895274719 | 6.62909042771, 0.347141870601 | 4.40659287289, 5.08221553469 | 6.10303415513, 0.964895788694 | 5.44053902503, 1.08756545279 | 4.8789513143, 2.23999505903 | 4.3166879081, 0.473521329208 | 2.98710598996, 0.328338724717 | 3.63097391706, 1.23470920872 | 6.7973727924, 1.9035288097 | 3.24610611687, 1.1784536745 | 3.94056489811, 0.411994713837 | 2.91333974149, 0.489683388036 | 3.24695467582, 3.31228444368 | 5.16608807043, 2.15783928424 | 6.64157896073, 0.443948417653 | 3.90620905535, 0.857821288928 | 2.99368138591, 1.49978921496 | 4.82356273722, 0.872133033001 | 3.24174085834, 0.671829924207 | 7.0297101486, 1.05445859205 | 5.57595950789, 2.05900637254 | 6.26457094003, 1.57523003841 | 4.52409713881, 1.86723700435 | 3.43962071765, 1.02665748354 | 2.88684218402, 0.615864835786 | 2.79588577333, 3.19936855967 | 6.28220288061, 2.24047550738 | 5.53008426524, 2.67776787413 | 4.6979181139, 0.691843888188 | 3.21307396541, 0.571058813624 | 2.73530696092, 1.43753751622 | 5.45398911799, 1.24904449588 | 4.59098415211, 1.54683188803 | 6.95696824446, 2.47779777105 | 2.93320405304, 0.781522157919 | 2.91004051631, 0.301246739639 | 5.26895903219, 0.306685834123 | 4.60887518719, 0.265632061612 | 3.26882144595, 1.19966487878 | 3.6535443819, 0.188136710265 | 4.14584814624, 2.33527964251 | 5.80344863563, 1.13784018644 | 3.42992972216, 0.91284645791 | 2.98845131819, 1.0433126427 | 3.16354583136, 1.26296583529 | 3.19865984381, 0.505621332362 | 4.19219777501, 0.931137763214 | 5.40185803252, 2.04991447833 | 4.62938819872, 1.13690449509 | 4.79651539634, 0.351554660116 | 2.8958337638, 1.51567327906 | 4.55829133501, 0.649572699232 | 4.88949726483, 1.33977020783 | 4.82209780777, 2.23734997143 | 3.3258080338, 0.952472446905 | 5.97617136259, 2.57089117035 | 5.69604486922, 1.37084925259 | 5.01281981416, 0.271180017839 | 3.54518484945, 0.856736542786 | 3.53818746945, 1.37977612576 | 4.25200938943, 0.938933657517 | 6.26438414846, 1.17952710259 | 2.88790645751, 0.192888783336 | 5.09273429578, 1.49949839775 | 2.95199691542, 0.84897400017 | 2.91089046258, 1.22377461382 | 4.42589120179, 1.417365782 | 4.06896381627, -4.39684180804 | 1.12423086285, 5.32645061833 | 0.258879189718, 6.56770612254 | 1.88980716816, 4.97200415894 | 0.407118210797, 6.03564845001 | 0.751012545119, 2.94035843782 | 0.314775456319, 2.85547872035 | 2.51220235177, 3.60858208918 | 2.8089375563, 3.89964990999 | 0.856374176369, 3.02735723184 | 0.226780241358, 3.11375978646 | 1.37885008492, 3.23563684881 | 1.32453935853, 4.74247908133 | 2.89363607052, 3.96514946019 | 0.387975516108, 4.4204216991 | 0.657322986031, 5.4094749177 | 0.376668387939, 3.3948416627 | 0.163593376023, 3.21957447237 | 2.63364446483, 5.92619382132 | 1.84933460179, 3.84539096788 | 0.297100044069, 4.590537026 | 2.53226329642, 3.06375316017 | 1.05043548764, 5.07407491355 | 2.45226502214, 6.28652144612 | 0.975087587592, 6.58207129189 | 0.355147337604, 3.72469838853 | 1.61156994808, 6.52684709038 | 1.96726515223, 2.9631288797 | 0.857151949309, 2.97138456376 | 0.629994862143, 3.05207906639 | 0.495742043608, 5.90181207884 | 1.652460374, 2.89162903925 | 1.03099415637, 4.2123939732 | 2.11995054879, 2.75375629284 | 1.33757933345, 4.7521600173 | 1.26866382559, 9.20566066884 | 0.635108361464, 3.35937247059 | 0.237096980877, 6.7470372648 | 2.90489612946, 5.56776407333 | 1.45780412902, 2.97283115952 | 0.768662732119, 5.29033890732 | 1.46684775613, 3.33442909318 | 1.41208702577, 3.3456478028 | 3.15791207885, 6.26122042314 | 0.228863156957, 5.34911249975 | 0.310107651423, 4.0839718193 | 0.433244844548, 5.58341660812 | 0.652454865698, 3.4840279873 | 0.588712471498, 5.48604913149 | 1.29273094631, 2.69170609551 | 0.557907104774, 4.07594518419 | 0.0794660417283, 4.22286388466 | 2.27121671294, 2.78656421487 | 1.09789223697, 3.68130821292 | 0.42822664425, 3.77323745304 | 2.3901193323, 5.99835163287 | 1.64461791151, 4.28719972597 | 0.741702952331, 3.48535661343 | 0.547992783008, 2.91570692268 | 0.297979629089, 4.22482418509 | 1.60766663614, 2.87894041417 | 0.210360178912, 3.81005611699 | 2.09964844162, 5.79399808209 | 0.665058152339, 4.83290584104 | 0.917001805312, 4.54824347301 | 1.28630290164, 2.7904401791 | 0.303055664379, 4.08422388761 | 1.52920833284, 4.597008972 | 0.552201184549, 3.44381095773 | 0.166042909241, 3.50438824207 | 1.92655877373, 4.00278453337 | 0.724330335054, 4.13312479796 | 3.83162584598, 2.98368298402 | 0.248108338937, 2.99413350468 | 0.106464616772, 4.57993344663 | 2.78540985725, 5.34126437112 | 0.222824052156, 7.41604024389 | 0.452783882865, 3.28587796229 | 0.595307265723, 3.3611648224 | 0.838456623147, 3.12354995598 | 0.167846498981, 3.42429119576 | 0.789557072651, 5.8512550284 | 1.99281532804, 3.91105879269 | 0.452095791245, 3.69740704803 | 0.820050676208, 3.1442635652 | 2.21862308472, 2.92284337303 | 0.620210327906, 3.36458898403 | 0.714739708796, 3.19489739931 | 0.350048969031, 7.88833318096 | 0.365468571658, 5.00308578152 | 0.223766784791, 3.22840497378 | 0.539154032626, 4.32414826891 | 0.342917766201, 4.2372602031 | 2.62312171147, 4.03489667364 | 1.19724040465, 2.98468107894 | 1.70816624101, 3.70061721998 | 0.144003322043, 3.32759851079 | 3.22759915673, 3.5348883024 | 2.26666238419, 3.61986027727 | 1.42234783125, 4.13584607426 | 0.38240113167, 3.13105489274 | 0.42684491591, 5.29386720306 | 1.13522472017, 4.35065180729 | 0.450662984793, 4.92212961708 | 0.504918122593, 4.19696666531 | 0.542106242523, 4.70822553306 | 0.431753357932, 4.70496853934 | 0.585882562077, 2.82163939708 | 0.354211377662, 2.7749285673 | 0.773819372569, 4.20106078629 | 3.5468186015, 3.25806230422 | 1.16446490776, 2.97824153046 | 0.634719609118, 6.24049625894 | 0.604503799466, 7.18692448088 | 0.702479476078, 3.9767986394 | 2.46691462078, 4.90972585114 | 2.12411456206, 3.25824555983 | 1.42599273813, 3.1842857736 | 0.780409710085, 7.33108959719 | 0.948593648814, 6.88914480747 | 1.18840666953, 3.93008795772 | 1.03634566272, 4.86100091822 | 0.460655730352, 5.64255515254 | 0.727288715906, 4.05696325215 | 0.596443341098, 4.12078782301 | 0.766925538593, 6.46611201826 | 1.85524070679, 4.94726132676 | 1.97043281815, 6.83805063598 | 0.444160900675, 4.86890068342 | 0.625975194945, 6.76331265223 | 0.224926532447, 8.96799021152 | 1.90689894212, 3.16719895489 | 0.646323589286, 4.93474307859 | 1.07218770687, 4.37542292896 | 0.884930238015, 5.81515843154 | 5.06933221904, +4.40966237731 | 1.12848893622, 5.32645061833 | 0.258879189718, 6.56770612254 | 1.88980716816, 4.97200415894 | 0.407118210797, 6.03564845001 | 0.751012545119, 2.94035843782 | 0.314775456319, 2.85547872035 | 2.51220235177, 3.60858208918 | 2.8089375563, 3.89964990999 | 0.856374176369, 3.02735723184 | 0.226780241358, 3.11375978646 | 1.37885008492, 3.23563684881 | 1.32453935853, 4.74247908133 | 2.89363607052, 3.96514946019 | 0.387975516108, 4.4204216991 | 0.657322986031, 5.4094749177 | 0.376668387939, 3.3948416627 | 0.163593376023, 3.21957447237 | 2.63364446483, 5.92619382132 | 1.84933460179, 3.84539096788 | 0.297100044069, 4.590537026 | 2.53226329642, 3.06375316017 | 1.05043548764, 5.07407491355 | 2.45226502214, 6.28652144612 | 0.975087587592, 6.58207129189 | 0.355147337604, 3.72469838853 | 1.61156994808, 6.52684709038 | 1.96726515223, 2.9631288797 | 0.857151949309, 2.97138456376 | 0.629994862143, 3.05207906639 | 0.495742043608, 5.90181207884 | 1.652460374, 2.89162903925 | 1.03099415637, 4.2123939732 | 2.11995054879, 2.75375629284 | 1.33757933345, 4.7521600173 | 1.26866382559, 9.20566066884 | 0.635108361464, 3.35937247059 | 0.237096980877, 6.7470372648 | 2.90489612946, 5.56776407333 | 1.45780412902, 2.97283115952 | 0.768662732119, 5.29033890732 | 1.46684775613, 3.33442909318 | 1.41208702577, 3.3456478028 | 3.15791207885, 6.26122042314 | 0.228863156957, 5.34911249975 | 0.310107651423, 4.0839718193 | 0.433244844548, 5.58341660812 | 0.652454865698, 3.4840279873 | 0.588712471498, 5.48604913149 | 1.29273094631, 4.07594518419 | 0.0794660417283, 4.22286388466 | 2.27121671294, 2.78656421487 | 1.09789223697, 3.68130821292 | 0.42822664425, 3.77323745304 | 2.3901193323, 5.99835163287 | 1.64461791151, 4.28719972597 | 0.741702952331, 3.48535661343 | 0.547992783008, 2.91570692268 | 0.297979629089, 4.22482418509 | 1.60766663614, 2.87894041417 | 0.210360178912, 3.81005611699 | 2.09964844162, 5.79399808209 | 0.665058152339, 4.83290584104 | 0.917001805312, 4.54824347301 | 1.28630290164, 2.7904401791 | 0.303055664379, 4.08422388761 | 1.52920833284, 4.597008972 | 0.552201184549, 3.44381095773 | 0.166042909241, 3.50438824207 | 1.92655877373, 4.00278453337 | 0.724330335054, 4.13312479796 | 3.83162584598, 2.98368298402 | 0.248108338937, 2.99413350468 | 0.106464616772, 4.57993344663 | 2.78540985725, 5.34126437112 | 0.222824052156, 7.41604024389 | 0.452783882865, 3.28587796229 | 0.595307265723, 3.3611648224 | 0.838456623147, 3.12354995598 | 0.167846498981, 3.42429119576 | 0.789557072651, 5.8512550284 | 1.99281532804, 3.91105879269 | 0.452095791245, 3.69740704803 | 0.820050676208, 3.1442635652 | 2.21862308472, 2.92284337303 | 0.620210327906, 3.36458898403 | 0.714739708796, 3.19489739931 | 0.350048969031, 7.88833318096 | 0.365468571658, 5.00308578152 | 0.223766784791, 3.22840497378 | 0.539154032626, 4.32414826891 | 0.342917766201, 4.2372602031 | 2.62312171147, 4.03489667364 | 1.19724040465, 2.98468107894 | 1.70816624101, 3.70061721998 | 0.144003322043, 3.32759851079 | 3.22759915673, 3.5348883024 | 2.26666238419, 3.61986027727 | 1.42234783125, 4.13584607426 | 0.38240113167, 3.13105489274 | 0.42684491591, 5.29386720306 | 1.13522472017, 4.35065180729 | 0.450662984793, 4.92212961708 | 0.504918122593, 4.19696666531 | 0.542106242523, 4.70822553306 | 0.431753357932, 4.70496853934 | 0.585882562077, 2.82163939708 | 0.354211377662, 2.7749285673 | 0.773819372569, 4.20106078629 | 3.5468186015, 3.25806230422 | 1.16446490776, 2.97824153046 | 0.634719609118, 6.24049625894 | 0.604503799466, 7.18692448088 | 0.702479476078, 3.9767986394 | 2.46691462078, 4.90972585114 | 2.12411456206, 3.25824555983 | 1.42599273813, 3.1842857736 | 0.780409710085, 7.33108959719 | 0.948593648814, 6.88914480747 | 1.18840666953, 3.93008795772 | 1.03634566272, 4.86100091822 | 0.460655730352, 5.64255515254 | 0.727288715906, 4.05696325215 | 0.596443341098, 4.12078782301 | 0.766925538593, 6.46611201826 | 1.85524070679, 4.94726132676 | 1.97043281815, 6.83805063598 | 0.444160900675, 4.86890068342 | 0.625975194945, 6.76331265223 | 0.224926532447, 8.96799021152 | 1.90689894212, 3.16719895489 | 0.646323589286, 4.93474307859 | 1.07218770687, 4.37542292896 | 0.884930238015, 5.81515843154 | 5.06933221904, -0.94314420035 | 0.981895726286, 0.169963486799 | 0.296020947379, 0.271942650466 | 1.64739221905, 0.326711138057 | 0.863565309388, 1.66146343193 | 0.10325913533, 0.893056486982 | 0.808682871045, 0.282138178835 | 0.371623453277, 0.371895553115 | 0.434925299581, 0.376274486482 | 1.39877606315, 1.0446211384 | 0.571090947977, 0.466324696171 | 0.308323819636, 1.44638826983 | 1.56045441673, 0.320121767249 | 0.501052292835, 0.580846772301 | 1.30830960928, 0.521159294492 | 2.32581712491, 1.36234293815 | 0.289371891003, 0.963647635211 | 1.0261635, 0.637637095911 | 2.04389724471, 1.73748324726 | 0.860053341243, 0.613136565362 | 0.190705662033, 0.701077196961 | 0.193164499076, 0.107195404818 | 0.534806493228, 2.16015060747 | 0.42304329124, 0.922355654532 | 2.02841264143, 1.16959960242 | 2.31610780363, 1.02545023421 | 0.582097280023, 0.494289746101 | 1.28037865741, 0.040977350523 | 0.439638684942, 0.812148875111 | 1.47854501694, 0.569251356464 | 1.15224692006, 0.252754750614 | 0.89989902386, 2.06911336897 | 0.290356054276, 0.305260524931 | 0.990555427867, 0.874265659665 | 2.20241001084, 0.339578116871 | 0.320754547992, 1.93511267746 | 0.587733491711, 1.49362864494 | 1.93197678658, 0.412150967857 | 1.01319160519, 0.902855287476 | 1.07735390865, 1.0106755563 | 0.665572272889, 0.735666970712 | 0.302010636883, 2.07588001793 | 0.794593877907, 0.171995382581 | 1.49726413026, 1.78587441529 | 0.243153154046, 0.378541436116 | 1.31991388346, 0.918472780684 | 2.06758418387, 0.249403107207 | 0.454176981891, 0.583046618517 | 1.94950630499, 0.0628704638461 | 0.387939757822, 2.42609604173 | 1.29214747348, 1.43586493567 | 2.0391938725, 0.417967523855 | 2.22062836794, 1.098242156 | 2.59297376409, 0.480189177144 | 2.10100373728, 1.73565282659 | 1.62926884235, 0.760730091571 | 0.315153143947, 0.866559797058 | 1.76506993856, 0.984499639614 | 0.44249951319, 1.30348326941 | 1.44005990567, 0.13105037532 | 2.63608457803, 0.252311764312 | 1.41263674761, 0.228552899932 | 1.18621757992, 1.0290999953 | 0.390120245762, 0.882866151676 | 1.64057234467, 1.23446216599 | 2.00902296698, 1.71823504911 | 1.66540218242, 0.372278412557 | 1.07397574734, 1.63805067019 | 0.722246090948, 2.57845909391 | 0.640741806074, 1.49235149587 | 1.45715491558, 2.21722378657 | 1.27240410181, 0.326815409914 | 0.485455556687, 0.748585404096 | 0.78756538169, 0.21745467698 | 1.0401079674, 2.21873677412 | 1.02993567713, 1.03597832861 | 0.350879406929, 0.343317792485 | 1.41188975191, 2.51673013034 | 1.01486660235, 1.1147940572 | 1.19178509596, 0.849198242163 | 1.69635984254, 0.758328393524 | 1.4736114257, 0.327236321769 | 0.947598237393, 0.297280087477 | 1.1390147908, 2.18011601789 | 0.297370086524, 0.8865335918 | 1.69415944125, 0.462460808338 | 1.8253858595, 0.960770450807 | 0.280985644803, 0.323387454337 | 0.152741315791, 0.295106002294 | 0.683710648029, 1.56585975281 | 0.828774714947, 1.28799561213 | 0.795433234715, 0.254180636839 | 0.739464244104, 0.486943161095 | 1.03563187104, 0.660394558092 | 0.803358570279, 0.954368451522 | 0.276509523751, 0.406474300541 | 0.827818544391, 0.461464091627 | 0.599869936581, 0.199402475443 | 1.68554411367, 1.20127716327 | 0.216781902792, 0.110914892968 | 0.306856799157, 0.150685481569 | 1.19148169785, 1.83776276952 | 0.469180820593, 1.1195849682 | 2.44610092219, 0.737349207148 | 2.3976699186, 0.333876817449 | 1.37480679256, 1.30679336404 | 1.41567335553, 0.816394091152 | 1.10046765105, 2.29856419478 | 0.485561779197, 0.403110767438 | 1.6268797303, 0.299919940596 | 0.331093402906, 0.483404071006 | 0.290318020102, 0.744873723165 | 1.30272252912, 2.26695861761 | 1.08617294566, 1.50590267295 | 0.433719251144, 1.97273495528 | 2.02645491744, 0.412510467935 | 1.53621178736, 0.340579806797 | 0.953479355234, 0.477579225453 | 1.14369175893, 0.242254482121 | 1.14793354682, 0.812293430821 | 1.56412861853, 0.879667239287 | 0.866309360039, 0.634709228209 | 0.950164048793, 1.76004127096 | 0.755274750165, 1.05606204331 | 2.448576038, 1.76765732635 | 0.983803575974, 0.585782455829 | 0.432310082049, 0.348373922445 | 0.512929947691, 1.60506043565 | 1.07206564725, 0.507838904838 | 1.44461249943, 1.05914192838 | 0.380250398523, 0.896368847415 | 0.299026808915, 1.38264259557 | 0.328637413493, 0.197905188789 | 0.219648997204, 0.610847484075 | 1.378647892, 0.869589558242 | 0.440714327768, 0.783770455788 | 1.06490063493, 0.974629152681 | 2.20910632802, 2.33542719376 | 0.745929386166, 0.315350487304 | 0.354331468356, 0.492928346606 | 0.219002553457, 2.55146883283 | 0.274969047634, 1.40057031621 | 2.27381199684, 1.03864873742 | 0.979007797872, 0.962250524318 | 0.48152121663, 0.386891788541 | 0.483093997597, 1.29666721286 | 1.72165015887, 1.34710948498 | 0.507143795547, 2.18322390256 | 0.172569287983, 1.56301083559 | 0.458743636828, 0.751123742453 | 0.946768432963, 0.690327863639 | 0.992447329403, 0.671823935165 | 2.0978362702, 0.461285118688 | 2.42986142136, 0.250587958715 | 1.29453084627, 2.12937070061 | 1.6383108554, 2.14104233392 | 0.786737857766, 1.66896358889 | 0.377690250523, 2.64777900836 | 0.256778514556, 1.27016157677 | 0.957061170215, 1.48771892078 | 0.616825275551, 0.562017881387 | 1.74590123742, 1.56481864613 | 1.43614555065, 1.10247098536 | 0.377623446533, 0.602776058237 | 0.859106463858, 0.202677292862 | 0.855468120433, 1.82480920271 | 0.496915629909, 0.487247587407 | 0.801326132058, 0.515826294323 | 0.871320724668, 2.19109082809 | 0.644508364546, 0.884618026883 | 1.11758756205, 1.59484914041 | 0.57017322245, 0.498701179507 | 0.933886600228, 0.9693112402 | 1.31405068172, 1.66852970075 | 1.28329575891, 0.579302946369 | 0.151769005917, 0.263279735437 | 2.45623642144, 1.62841230125 | 1.1730311994, 0.307412429659 | 0.676678406507, 0.310302068518 | 0.565438184851, 1.37517051701 | 1.20057856368, 0.252429971783 | 1.69157736474, 0.351928716246 | 2.45380572359, 0.78207486059 | 0.303181203474, 0.818487565897 | 0.0922592753118, 1.30759253408 | 2.28938372681, 0.0365828847014 | 2.65549003031, 0.383402451249 | 0.545838008629, 0.163346978989 | 0.348357206478, 1.22557680956 | 1.42433129564, 1.65024542028 | 0.856078285278, 1.19555457329 | 0.15903928358, 1.20995434808 | 0.961732048479, 0.416115951752 | 0.376111365586, 0.465160867886 | 1.74674578848, 1.68903481752 | 1.72441216776, 1.67477696097 | 2.60016921821, 0.930827044668 | 0.894383569469, 0.498284284652 | 1.53063385682, 0.88187712161 | 0.250559670471, 0.22676531703 | 0.429813566252, 0.956716138216 | 0.130649805751, 0.456105469958 | 1.87824852012, 0.474202306008 | 1.32051975501, 0.311833074448 | 1.19912691392, 0.243732233658 | 0.402424265378, 1.02215168453 | 1.86176187971, 0.936961221963 | 0.293180129731, 2.53127719979 | 0.818797484154, 0.416835118578 | 0.733084462339, 2.09182221074 | 1.09530550263, 1.5377669992 | 0.445950122358, 0.204831284909 | 1.3178848594, 0.549254096821 | 1.68936636922, 0.71094663964 | 0.117115367062, 2.23920560823 | 0.145518035333, 0.973116540588 | 1.82170431151, 0.743233301348 | 1.52405120812, 0.658241041235 | 0.360435704697, 1.76919944043 | 0.857601246328, 0.276799082879 | 1.91143301777, 0.79134554538 | 0.743552871892, 0.724608730694 | 1.22684618238, 0.623110069773 | 1.53275190557, 0.312840367772 | 0.344455103878, 1.05691049646 | 1.15728791277, 0.887089613177 | 0.402850065386, 1.42555762373 | 2.36884242177, 1.47592563111 | 2.34839395956, 1.16457801632 | 1.22734496901, 0.783878255489 | 2.25752535531, 2.20804418257 | 1.21773633899, 0.241587451543 | 0.774212980682, 1.00505746299 | 0.812620504393, 1.66815323836 | 0.715371383661, 0.766527640568 | 1.71161858755, 2.05901816836 | 1.16153214238, 0.868749340576 | 0.971393032742, 1.40106991445 | 2.12294583893, 1.05536033497 | 0.164177899521, 2.36560207183 | 0.27734683301, 0.980177237504 | 0.543463248649, 1.08704357615 | 0.455083257825, 0.865440367712 | 0.561580102184, 1.45086272985 | 1.79651065388, 0.173171780362 | 0.521629375215, 1.02386212465 | 0.923704072222, 2.13355472037 | 0.426544022113, 0.663554456113 | 2.10181679452, 0.407430964684 | 2.26725646845, 1.43898785591 | 0.200391084607, 0.194643343686 | 0.418568600642, 0.93320304839 | 0.701183244743, 1.0023018653 | 0.982458148711, 0.203912872225 | 2.35983089781, 0.597685297377 | 0.934032105178, 0.56274796731 | 1.37174805663, 0.454101796359 | 2.68035254973, 0.550821658799 | 0.904427683499, 0.864005872791 | 1.44879086382, 0.888159398828 | 0.588379026454, 0.931121787456 | 1.60958802959, 0.704842970104 | 1.41076676979, 1.9601170371 | 0.293684499559, 0.441600207327 | 1.29210072348, 0.186913610614 | 0.721378346275, 1.08064941697 | 0.960767147851, 1.78162939885 | 0.467341316827, 0.652344124139 | 0.507023869883, 0.774367097583 | 1.65016248063, 0.1720556597 | 0.678633121852, 2.07498016083 | 1.81380931024, 1.7286173085 | 1.40212944728, 2.60004402628 | 1.27068724087, 1.28532968364 | 0.370060400749, 0.166369844744 | 0.122998474704, 0.510398539045 | 1.21490966623, 0.630318270253 | 2.39089643976, 0.905989117184 | 0.500760167128, 0.411668316376 | 0.557951377106, 1.42068599634 | 0.900566133803, 0.437521123395 | 0.892652768709, 0.420202460094 | 0.294168014628, 1.68008509731 | 0.211094396734, 1.25487856277 | 2.57344633519, 2.49384672854 | 1.20152376007, 1.15518708601 | 1.10416702024, 1.63321448193 | 0.58792458609, 0.958840262092 | 0.595406726254, 0.561483869816 | 0.444579804477, 0.706789275528 | 0.502767161944, 1.10985090694 | 2.11414192209, 1.09534403376 | 0.500158077678, 1.0010283532 | 2.03128916932, 0.422999121123 | 0.55114088445, 1.4327102843 | 0.4236682025, 2.25781580774 | 0.120786449823, 0.629075089004 | 1.60295440061, 0.225025775619 | 0.833568335906, 1.21452252754 | 0.530369453109, 0.50045367977 | 2.66772686192, 0.631097719153 | 0.449290649308, 1.62617489517 | 0.669897743569, 0.15844024558 | 0.253388002697, 0.725149018541 | 0.265037040637, 0.53002489067 | 2.30031197637, 1.39565285273 | 0.976122356777, 0.30640654915 | 0.568772989178, 0.40938388171 | 1.14663487734, 0.435696076396 | 1.34209081007, 0.938392435311 | 0.561376360631, 0.529331993958 | 0.537495254361, 0.989327786559 | 0.431691501708, 0.425334803543 | 0.237494380559, 1.6994977688 | 0.711516292504, 0.508282652828 | 0.470621634986, 0.949366270837 | 0.38411875556, 0.820774682384 | 1.40456469575, 0.692317412848 | 0.438430613274, 1.00929866149 | 0.893650197321, 0.387846108432 | 0.268509916794, 1.27671131479 | 1.62801362147, 0.267203120339 | 0.570965479242, 2.09456628119 | 0.281499069012, 0.82383188417 | 0.318940184304, 1.23539172258 | 0.772306193335, 0.373867669606 | 2.29078453512, 0.28210053162 | 1.36232285579, 0.494882550551 | 0.649548385865, 0.808060415401 | 1.71990258451, 2.29629733041 | 0.830011621788, 0.399303755146 | 1.09577281718, 0.397020067431 | 1.10348325361, 1.09250514355 | 0.542655028833, 0.901057404441 | 0.731512366958, 2.46928657737 | 1.57278241092, 2.498282512 | 0.452416381131, 0.890337588128 | 1.67761448177, 2.27438277799 | 0.149031471475, 0.462431477873 | 1.11630608799, 1.82087708903 | 2.13833284998, 1.71205170727 | 0.422208884884, 0.718991222734 | 0.999172444412, 0.90409622282 | 0.770902294249, 0.41595031335 | 0.301609068896, 0.537498432655 | 0.159178443431, 2.05242704057 | 0.409303474894, 0.323174970795 | 1.56859933281, 0.136081406461 | 1.75935494095, 0.359225375456 | 0.828503162647, 0.474833116607 | 1.38219933945, 0.36294977912 | 1.54186210627, 0.171192485795 | 0.365059759874, 0.334182459126 | 0.745342750611, 0.728429486311 | 0.153240675947, 2.08090480299 | 1.46323076922, 0.421432445838 | 0.875606531018, 0.645400212811 | 0.167875334373, 0.222398227763 | 0.277204905022, 0.397502013991 | 1.37811694283, 0.29246139853 | 0.635786327135, 0.170354761219 | 0.708223947746, 0.439340129297 | 1.53213549452, 1.18023540556 | 0.121456580178, 1.94794701947 | 0.312182693105, 0.529972160774 | 1.04310152524, 1.87586780141 | 1.26254799827, 0.477130456532 | 0.97691541019, 0.170524391565 | 1.62963040786, 2.38548774243 | 0.465172517712, 0.512036027982 | 2.14009371978, 0.229784327831 | 0.127123967881, 1.96755726076 | 2.08141385208, 1.96862533501 | 0.2631088277, 1.41925129919 | 0.572428676801, 0.205180768736 | 0.454617726276, 1.60056379553 | 0.6761093445, 0.425651919745 | 0.484887596033, 1.48090906946 | 0.211726923328, 1.92753780122 | 2.39257243326, 0.640071263911 | 0.525528901278, 0.647831837101 | 0.658106984551, 1.41171609269 | 1.39900005357, 0.964187221285 | 0.155376748348, 1.68417673539 | 0.185645233388, 1.41243205755 | 0.809937910121, 1.64830925878 | 0.738013539721, 0.305338428251 | 2.07398096159, 1.01281101684 | 1.82626181913, 1.8126029486 | 0.218993819183, 0.71966531448 | 0.362541592676, 2.08641562045 | 0.98148684941, 0.636535224106 | 0.313872315055, 1.40977258716 | 0.678022159306, 1.24166641221 | 0.609991845116, 1.74253866817 | 1.46040158917, 1.53754329054 | 0.660626454717, 0.597995275824 | 1.48814745089, 1.20542447458 | 0.505315919074, 0.536401176403 | 0.281826270627, 1.070798275 | 0.95834475172, 1.35298629652 | 0.673784667412, 0.599803458852 | 0.219417883296, 2.26559303637 | 1.42413692639, 0.535151579789 | 0.657256964612, 0.480512266067 | 0.815388055578, 0.773392724319 | 1.61013365084, 0.493310761399 | 0.418544613608, 1.34089170111 | 1.7068975579, 0.673330271486 | 0.264375854879, 0.575452003518 | 1.63173639771, 2.2081146561 | 0.364365530036, 1.72225825441 | 1.5470904448, 0.952163870647 | 1.49778474856, 1.15337131483 | 1.09003763497, 0.782193790851 | 0.178966874852, 0.765340012954 | 0.852179683933, 0.496726682726 | 0.167151510528, 0.663326898335 | 0.948944448328, 1.97981599474 | 0.707205610376, 0.84340642222 | 0.436949076491, 0.91963443566 | 0.776046575221, 0.605737424917 | 1.60015270552, 0.422421990368 | 1.04936456164, 0.381151414216 | 0.264343430161, 0.622164638491 | 0.852284921196, 0.305098959856 | 1.77366223436, 0.481777476786 | 1.60802928194, 0.163359027537 | 0.710824636012, 0.684987565952 | 0.99510238546, 0.188211268233 | 0.823820497723, 2.14311778893 | 1.56206519754, 1.3086307245 | 1.08109631897, 0.390588336682 | 0.919819819885, 2.31974002745 | 1.62756987109, 0.614974801944 | 0.598313170447, 0.843626194748 | 0.604242807902, 0.636158508427 | 1.12989253902, 0.67105709693 | 0.758347926235, 0.775979699259 | 1.53209138919, 0.887546305819 | 1.20789735698, 2.52182183354 | 0.812329311574, 0.0971717140767 | 0.964320738679, 0.14004048798 | 0.920098235851, 2.00846366364 | 2.4557011831, 1.12151090032 | 0.853759604699, 0.727162510977 | 0.231292123824, 1.59527491231 | 0.926772209017, 0.731720842669 | 0.202655056805, 0.525579966204 | 0.533822043294, 1.25057832601 | 0.645088929691, 0.843880981994 | 1.95791961703, 0.712715776817 | 2.18829586412, 1.10783936766 | 1.73224684766, 0.578847997854 | 0.924281167826, 0.589314544945 | 0.808646078631, 1.21492852927 | 2.1230332813, 0.341393443397 | 1.21037536003, 0.126432699551 | 1.54192553591, 0.511932202416 | 0.765899793629, 0.395202383353 | 1.2363401175, 0.77724713562 | 2.51855342955, 0.273856441279 | 0.393652186888, 0.882024098771 | 0.566599088531, 0.690396308482 | 1.88319788867, 0.999749198393 | 0.733638578713, 2.22882275773 | 0.669853410149, 0.875218740075 | 0.582649287505, 1.63328674826 | 0.201133960007, 0.793161060451 | 0.663718597361, 0.329071873479 | 1.07987583433, 1.99120622681 | 1.99211913207, 0.504233548664 | 0.659435709443, 0.853499272731 | 0.345364456904, 1.34431769103 | 0.278306797127, 0.209910644811 | 1.88000099606, 0.402769254395 | 0.954466120856, 1.86003563015 | 0.87892618468, 2.00752873919 | 2.1407856441, 0.620211007538 | 0.138453930261, 0.770165847942 | 0.62378215165, 0.74959336533 | 1.33728533031, 0.50462114009 | 0.445042859751, 0.189250295657 | 0.660406391209, 0.434605552397 | 0.22178322483, 0.68236604141 | 1.56166769423, 0.832239910097 | 0.233221488198, 0.78245768116 | 0.741202429821, 0.965826839553 | 0.934556395143, 0.130846893621 | 1.11587381052, 0.667497076673 | 0.717405898166, 0.97740562861 | 0.689225474105, 0.795988256774 | 1.66696061208, 2.34354518593 | 1.5179763001, 1.38697819984 | 0.473498124854, 0.349913622683 | 1.32267170468, 2.1159373567 | 0.259589940885, 2.25210302955 | 1.95958894032, 0.710976019695 | 1.04963312821, 0.924015256509 | 0.760544725505, 0.296514874359 | 0.113122440263, 2.23084646792 | 0.243564664551, 0.26346461111 | 0.440754560368, 1.0715856015 | 0.509927020375, 1.63783411807 | 1.12521756605, 2.2302529008 | 2.35645791433, 0.915087720222 | 1.56710280562, 0.769485344172 | 0.248207342307, 0.562717869221 | 0.965526877092, 0.336842640208 | 0.19853158974, 0.427024239875 | 2.24454740734, 0.764685185952 | 0.619480787044, 0.418033596885 | 0.774286104585, 0.68888479574 | 0.125979540079, 0.0789017155741 | 0.461785526451, 0.801360151769 | 0.345616246776, 2.1789940249 | 1.30334820382, 1.20677929031 | 0.507175219192, 2.19566132931 | 0.465653543398, 0.16590374418 | 0.308072265434, 0.0637027302805 | 0.483564192316, 1.09349401349 | 0.905851262722, 0.573089947219 | 0.715019506955, 1.48483305656 | 0.380738427642, 1.14935744019 | 0.333763234994, 1.24029775728 | 0.397111634141, 1.34418585379 | 0.113193498003, 0.671041101156 | 1.35410590562, 0.390926660115 | 1.08186320167, 0.33661534615 | 0.765425749799, 1.08834975518 | 0.810947205976, 0.569418944679 | 0.940696496622, 1.25997239312 | 0.626483377512, 0.413155167038 | 0.904442146327, 1.03203991993 | 0.711938444817, 1.52168008363 | 1.54080563258, 0.38928585155 | 0.770407515959, 0.085255861139 | 0.73923254933, 1.58762941258 | 0.659138709005, 0.512284455921 | 0.92031895578, 0.850342009856 | 0.268061807311, 1.14058104213 | 1.56681409758, 1.44216026603 | 1.91421615747, 0.845885547906 | 1.63985372312, 1.24478247216 | 0.450748132611, 1.82410974566 | 0.697395503699, 1.82872152949 | 1.25926866537, 0.694586560271 | 0.388500238778, 1.72232493005 | 0.274416690378, 1.15291850738 | 0.90296219851, 1.16673054304 | 0.104305361337, 1.16063279398 | 0.521132703284, 0.296156686446 | 1.8679029195, 1.17686072594 | 2.02285673943, 1.7778341745 | 1.23127181834, 0.756965279945 | 1.67483657582, 1.01403434916 | 0.740872489054, 0.812595873307 | 0.917893956796, 0.817842968403 | 0.558584850458, 0.232684911588 | 0.678369122611, 0.278425956778 | 0.227775690666, 0.178533495852 | 1.33749658045, 0.631646125283 | 1.42185983994, 0.765984060952 | 0.908957391154, 0.44790886395 | 1.54482216087, 0.704456763101 | 1.36945926045, 2.17914005163 | 1.62467102869, 0.489003519059 | 0.690705448433, 1.83283363575 | 1.01767679582, 0.70861080217 | 1.57450668475, 0.57610882203 | 0.473249561678, 0.664741868378 | 0.735208685119, 1.5757565479 | 0.18426288072, 0.878309875115 | 0.332975169199, 0.438143922785 | 0.215967922997, 1.36421398698 | 0.471883689741, 0.256211198777 | 0.414998667144, 1.31092843969 | 0.219586816948, 0.783520026453 | 0.831975463277, 0.195890217112 | 1.4299150827, 1.95815197824 | 1.05002765427, 1.52913978352 | 1.23150409232, 0.580259945724 | 2.35911126559, 2.22769732589 | 1.61770663679, 0.183492787229 | 0.643513245427, 0.988382500483 | 1.85752344497, 0.848080293145 | 1.35119281053, 2.48171183089 | 1.28632655848, 0.312491623546 | 0.841463611185, 0.157004140351 | 2.45436382205, 0.507365294761 | 0.304117530758, 0.869372517219 | 0.353336617062, 0.763104658288 | 2.32420390099, 1.88019093712 | 1.95216407426, 0.204714685224 | 1.52780993423, 0.0545826165707 | 2.38315812496, 0.14295967406 | 0.225578590239, 0.693437878737 | 0.535668065968, 0.0819471695546 | 0.462541931253, 0.293870938911 | 0.441694179349, 2.33937617784 | 0.142259395872, 0.825252543535 | 0.456228012554, 0.702242653502 | 0.46739999492, 0.889612835974 | 1.21256708162, 2.42940024377 | 0.423790867265, 0.127026739464 | 0.580616610077, 0.197206956564 | 0.996879044506, 0.427231755341 | 0.393218233116, 0.951241339176 | 0.36110858966, 0.111899851393 | 0.690828417936, 1.26487113741 | 1.33535834546, 0.633474291484 | 2.10362625787, 1.94450849716 | 0.78007343787, 0.752310627076 | 0.280668266579, 0.314568159422 | 1.31691816663, 1.75436750673 | 0.701082667486, 1.2839408341 | 0.388150026311, 0.170860339017 | 1.35866365911, 1.85320399828 | 1.37060928035, 1.30963875486 | 2.17247469363, 0.301561762877 | 0.687279017126, 0.314213489864 | 1.11787138165, 1.40929186547 | 1.95659146094, 0.264813382951 | 0.547163494095, 0.795750610604 | 1.01228248999, 0.324091207232 | 0.685667622517, 0.985314319927 | 1.5705959015, 1.30117489635 | 1.31299302769, 1.30407945375 | 0.182469523169, 0.439047079725 | 0.795790051555, 1.91611507184 | 1.20599571362, 0.56106358881 | 1.0745739754, 0.208406057798 | 1.18054244106, 1.94570404926 | 0.0928107785895, 1.3955435982 | 1.51637512069, 0.4417995657 | 1.94249144146, 1.17963917692 | 0.448236324737, 0.852969585332 | 0.183091926755, 1.79031991058 | 0.675614281957, 0.936484890277 | 0.0746451914142, 2.50483731076 | 0.54000859291, 1.84259862454 | 2.57103833386, 1.1349984282 | 0.748745663131, 0.796693534504 | 0.614492421858, 0.537169856445 | 0.462171128835, 2.16174141875 | 0.347557637785, 0.181603755915 | 1.57429390357, 2.39914666631 | 0.38834115031, 0.133616301846 | 1.5954546239, 0.577078642539 | 0.910071071042, 1.23516277524 | 0.66520761334, 0.370906958471 | 0.855509777542, 0.290070488546 | 0.76668747369, 1.22623691309 | 0.103596005078, 2.21146694485 | 1.69138889677, 0.514613006991 | 1.39026361086, 0.230859156687 | 1.85117096138, 0.361941883968 | 0.23503813583, 0.67075189379 | 0.711943965736, 1.55807956365 | 1.39302173275, 0.616058695784 | 1.91959850383, 1.70575501048 | 0.189408386188, 0.692221896558 | 0.395819025962, 0.253648549006 | 1.91475448468, 0.495884526486 | 0.233077201067, 0.340204109878 | 0.247563401137, 0.93707721899 | 1.13127817125, 0.269090748269 | 1.1631762973, 0.638751187288 | 0.321131937769, 0.492992920485 | 0.447407655479, 2.02440389451 | 2.26231648074, 0.789882261738 | 1.15794284614, 0.29278782541 | 1.10024583258, 0.45049179626 | 0.678611186296, 1.04589787191 | 1.64656087762, 0.178864369497 | 0.761164146489, 0.89806046891 | 1.45528284778, 0.379016876334 | 0.451555418047, 1.23540113658 | 1.0817579536, 0.513355152752 | 0.87737706784, 1.29144542689 | 0.729080787308, 0.258520249874 | 0.239467171244, 0.323560188597 | 2.08624039163, 0.797604356098 | 0.273101440892, 2.61953474612 | 1.19207111958, 1.36129334193 | 1.8685736771, 0.749890256181 | 0.445499643062, 0.174595392697 | 0.838493637356, 1.39208279198 | 0.517891810342, 0.95046039368 | 1.45344517236, 0.227773910269 | 0.522981059249, 0.120324153047 | 1.37535157239, 0.244158432185 | 1.22661164086, 0.331264977016 | 0.782302622523, 1.88051895815 | 0.448592430089, 0.466689623514 | 0.462346397071, 0.480646947224 | 1.20639666774, 2.43404313107 | 0.814361675357, 0.551635800558 | 2.31858685454, 0.624310045902 | 1.02813347379, 2.21144953237 | 0.899248530077, 0.442620551965 | 2.00807591843, +14.4078912631 | 1.64264269874, 13.594934717 | 5.95077654393, 16.4959253192 | 1.97264931319, 12.208321242 | 0.516538018932, 9.22794863419 | 5.23499591345, 9.91394556678 | 1.17445635113, 11.2219801324 | 0.497749565137, 11.7552028282 | 1.56562428674, 9.60547805235 | 2.87565801039, 18.589076052 | 1.05392224519, 14.892785513 | 1.66165089796, 18.0532898611 | 1.83213697413, 10.0767516465 | 0.853622379735, 13.8654008849 | 1.15348718526, 21.299910856 | 0.175289746186, 10.0890500803 | 0.316811426954, 10.2076269439 | 0.966166300131, 19.6188474702 | 1.81215314571, 14.8509606357 | 1.45522893062, 28.1824975639 | 0.141294041196, -14.4078912631 | 1.64264269874, 13.594934717 | 5.95077654393, 16.4959253192 | 1.97264931319, 12.208321242 | 0.516538018932, 9.22794863419 | 5.23499591345, 9.91394556678 | 1.17445635113, 11.2219801324 | 0.497749565137, 11.7552028282 | 1.56562428674, 9.60547805235 | 2.87565801039, 18.589076052 | 1.05392224519, 14.892785513 | 1.66165089796, 18.0532898611 | 1.83213697413, 10.0767516465 | 0.853622379735, 13.8654008849 | 1.15348718526, 21.299910856 | 0.175289746186, 10.0890500803 | 0.316811426954, 10.2076269439 | 0.966166300131, 19.6188474702 | 1.81215314571, 14.8509606357 | 1.45522893062, 28.1824975639 | 0.141294041196, +1.54081876229 | 12.3779975132, 0.766429423621 | 9.34776193739, 0.455413356751 | 13.183251825, 3.68161078878 | 20.3481237204, 2.35425744809 | 10.9139359587, 0.613231973752 | 12.364624746, 1.94693471203 | 12.8171405043, 0.840922034797 | 9.41115051023, 0.95734730579 | 9.49469931487, 1.97015551877 | 8.89570840834, 0.458238675858 | 19.101984561, 0.869923011972 | 11.646262575, 4.87816630053 | 8.33695792175, 0.921539044558 | 10.9787428056, 1.98427978492 | 10.4619593119, 1.37603007069 | 19.4718669618, 0.569969260551 | 9.76362147103, 1.60606491009 | 8.97144761846, 0.423403937902 | 11.2998140608, 0.472892304832 | 18.3879587203, 4.33486051914 | 10.3958590128, 0.61651596336 | 8.79223302653, 0.709333471028 | 10.1578879873, 4.43210849644 | 11.6260528893, 1.0927858146 | 9.53206042213, 0.188054928458 | 23.7488315602, Testing affinity propagation visitor ... -24.8864674204, 78.7138957809, 2.07290290881, 50.3013717523, 7.28320755981, +14.8864674204, 44.8864674204, 82.2902292707, 64.8864674204, 87.48270557, + +81.5840275508, 81.4526416181, 80.5427763693, 81.0856084652, 82.068028164, 80.507737207, 80.3368455564, 81.831434088, 81.185637531, 80.6319322423, 80.792112092, 81.4048670495, 82.0294774779, -20.6319322423, 29.8325726377, 27.7393170613, 29.5990682814, 24.0887403668, 26.2709592201, 21.0856084652, 8.16060831768, 6.88111906546, 23.6535581541, 3.65355815409, 21.4526416181, 25.7834812385, 4.79096707423, 27.4997084472, 23.2290856718, 28.7116662964, 9.44428195809, 24.1464065746, 25.3735876517, 5.13910636019, 3.17472024588, 20.507737207, 0.542776369347, 8.41473516768, 28.8116955834, 4.78799779085, 0.50773720697, 21.185637531, 24.7879977908, 2.87000320452, 9.38457552296, 1.40486704949, 9.83257263767, 22.8714543256, 0.336845556413, 2.0294774779, 28.7009633844, 20.5427763693, 28.4147351677, 2.06802816399, 7.73931706126, 7.23098877717, 1.58402755076, 26.8811190655, 8.71166629641, 1.45264161815, 2.70969027208, 24.7909670742, 28.6910053353, 5.37358765167, 9.08561217549, 28.0351069192, 29.4442819581, 20.792112092, 25.3504194723, 0.631932242255, 22.0294774779, 28.1606083177, 6.04436169077, 27.2309887772, 24.9938335144, 4.08874036683, 9.59906828139, 0.79211209196, 4.99383351443, 8.8116955834, 8.69100533529, 26.3554630222, 1.83143408803, 2.86411589824, 6.2709592201, 2.87145432564, 29.0856121755, 21.4048670495, 1.18563753105, 22.6158667776, 5.78348123847, 22.7096902721, 22.8641158982, 23.1747202459, 22.068028164, 4.14640657457, 2.6158667776, 5.53340214896, 6.35546302222, 22.8700032045, 29.384575523, 26.0443616908, 3.22908567178, 8.70096338444, 21.5840275508, 1.08560846516, 21.831434088, 20.3368455564, 5.35041947229, 7.49970844719, 25.533402149, 8.0351069192, 25.1391063602, +67.7393170613, 60.5427763693, 61.4048670495, 67.2309887772, 69.8325726377, 65.1391063602, 65.3735876517, 61.0856084652, 68.6910053353, 60.6319322423, 64.0887403668, 62.0294774779, 69.384575523, 67.4997084472, 69.5990682814, 66.8811190655, 66.0443616908, 62.8641158982, 62.6158667776, 61.5840275508, 64.7879977908, 68.4147351677, 65.533402149, 69.0856121755, 61.185637531, 68.7009633844, 68.8116955834, 60.3368455564, 66.3554630222, 63.6535581541, 65.7834812385, 64.9938335144, 68.0351069192, 62.8700032045, 65.3504194723, 61.4526416181, 62.8714543256, 62.068028164, 62.7096902721, 66.2709592201, 64.1464065746, 60.507737207, 68.7116662964, 68.1606083177, 61.831434088, 60.792112092, 63.2290856718, 69.4442819581, 63.1747202459, 64.7909670742, -40.792112092, 45.7834812385, 41.831434088, 47.4997084472, 43.2290856718, 47.7393170613, 40.6319322423, 41.0856084652, 41.5840275508, 41.185637531, 48.0351069192, 48.6910053353, 49.8325726377, 48.8116955834, 46.8811190655, 47.2309887772, 40.3368455564, 46.2709592201, 41.4048670495, 42.8714543256, 42.0294774779, 42.068028164, 48.1606083177, 44.1464065746, 48.4147351677, 48.7009633844, 40.5427763693, 49.5990682814, 42.6158667776, 42.7096902721, 40.507737207, 42.8641158982, 49.0856121755, 49.4442819581, 44.7879977908, 45.1391063602, 48.7116662964, 46.0443616908, 43.1747202459, 46.3554630222, 42.8700032045, 41.4526416181, 44.9938335144, 45.3504194723, 43.6535581541, 45.3735876517, 44.0887403668, 45.533402149, 44.7909670742, 49.384575523, +45.3504194723, 42.6158667776, 40.507737207, 44.7909670742, 47.4997084472, 49.5990682814, 46.3554630222, 41.185637531, 45.7834812385, 46.0443616908, 47.2309887772, 44.1464065746, 43.2290856718, 48.7009633844, 48.8116955834, 42.068028164, 48.4147351677, 41.4048670495, 43.1747202459, 42.7096902721, 40.3368455564, 40.792112092, 40.6319322423, 42.0294774779, 43.6535581541, 47.7393170613, 48.7116662964, 46.2709592201, 44.0887403668, 44.9938335144, 45.3735876517, 46.8811190655, 45.533402149, 42.8714543256, 40.5427763693, 48.1606083177, 41.831434088, 49.0856121755, 48.0351069192, 45.1391063602, 49.8325726377, 41.0856084652, 49.384575523, 41.5840275508, 44.7879977908, 42.8641158982, 41.4526416181, 49.4442819581, 48.6910053353, 42.8700032045, -86.0443616908, 80.5427763693, 83.1747202459, 80.507737207, 82.8641158982, 81.4048670495, 85.3735876517, 84.9938335144, 88.1606083177, 88.8116955834, 82.8714543256, 82.6158667776, 82.7096902721, 81.5840275508, 84.1464065746, 84.7879977908, 85.1391063602, 80.3368455564, 85.7834812385, 89.5990682814, 81.0856084652, 86.2709592201, 88.0351069192, 81.831434088, 85.3504194723, 88.7116662964, 85.533402149, 87.2309887772, 82.0294774779, 89.8325726377, 83.6535581541, 88.6910053353, 80.792112092, 87.7393170613, 89.384575523, 82.068028164, 84.0887403668, 84.7909670742, 89.4442819581, 86.3554630222, 82.8700032045, 87.4997084472, 89.0856121755, 88.4147351677, 81.185637531, 81.4526416181, 88.7009633844, 86.8811190655, 80.6319322423, 83.2290856718, +27.2309887772, 27.7393170613, 22.6158667776, 25.3735876517, 1.45264161815, 2.87145432564, 29.4442819581, 29.384575523, 28.4147351677, 22.068028164, 23.2290856718, 20.3368455564, 6.88111906546, 8.16060831768, 20.6319322423, 3.22908567178, 25.1391063602, 25.533402149, 4.79096707423, 2.06802816399, 21.831434088, 6.35546302222, 6.2709592201, 22.8714543256, 8.41473516768, 23.1747202459, 9.59906828139, 24.7879977908, 28.6910053353, 2.0294774779, 8.0351069192, 25.7834812385, 21.5840275508, 26.8811190655, 28.0351069192, 8.71166629641, 2.70969027208, 5.53340214896, 22.8641158982, 24.9938335144, 7.23098877717, 28.1606083177, 9.08561217549, 7.73931706126, 22.8700032045, 21.185637531, 8.70096338444, 24.0887403668, 9.38457552296, 0.336845556413, 28.8116955834, 0.50773720697, 26.2709592201, 6.04436169077, 27.4997084472, 2.86411589824, 28.7116662964, 21.0856084652, 29.8325726377, 0.631932242255, 8.69100533529, 21.4048670495, 20.792112092, 4.08874036683, 4.99383351443, 5.78348123847, 4.14640657457, 3.65355815409, 1.58402755076, 20.507737207, 1.40486704949, 24.7909670742, 5.13910636019, 28.7009633844, 5.35041947229, 3.17472024588, 22.7096902721, 24.1464065746, 26.3554630222, 4.78799779085, 7.49970844719, 22.0294774779, 2.6158667776, 2.87000320452, 20.5427763693, 21.4526416181, 29.5990682814, 29.0856121755, 1.83143408803, 5.37358765167, 26.0443616908, 23.6535581541, 9.83257263767, 9.44428195809, 25.3504194723, 1.18563753105, 1.08560846516, 0.79211209196, 0.542776369347, 8.8116955834, -62.8700032045, 69.384575523, 66.3554630222, 61.4048670495, 64.9938335144, 68.7116662964, 68.0351069192, 61.831434088, 65.1391063602, 62.7096902721, 62.6158667776, 69.4442819581, 67.7393170613, 61.185637531, 64.7879977908, 63.1747202459, 62.8641158982, 66.0443616908, 61.5840275508, 60.507737207, 64.1464065746, 69.5990682814, 68.1606083177, 68.4147351677, 65.533402149, 65.7834812385, 60.792112092, 64.0887403668, 68.6910053353, 69.8325726377, 63.6535581541, 68.7009633844, 68.8116955834, 66.8811190655, 62.8714543256, 60.3368455564, 67.4997084472, 61.4526416181, 60.6319322423, 60.5427763693, 62.0294774779, 62.068028164, 64.7909670742, 66.2709592201, 65.3735876517, 65.3504194723, 61.0856084652, 69.0856121755, 63.2290856718, 67.2309887772, +89.8325726377, 86.8811190655, 85.533402149, 88.1606083177, 88.4147351677, 82.6158667776, 88.0351069192, 84.0887403668, 89.5990682814, 88.7116662964, 84.7879977908, 89.4442819581, 87.4997084472, 88.8116955834, 89.384575523, 82.7096902721, 86.3554630222, 83.1747202459, 87.7393170613, 88.6910053353, 87.2309887772, 84.7909670742, 84.9938335144, 82.8641158982, 82.8714543256, 86.2709592201, 84.1464065746, 82.8700032045, 86.0443616908, 83.6535581541, 88.7009633844, 85.1391063602, 85.3735876517, 85.7834812385, 85.3504194723, 89.0856121755, 83.2290856718, Testing multi-column sort ... From 8ac0e8886d49f5c2ffca8b17bdcf35cef9cfa100 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Thu, 29 Dec 2022 09:27:34 -0500 Subject: [PATCH 20/25] Adjusted docs for aligned memory allocator --- docs/HTML/AutoCorrVisitor.html | 6 ++- docs/HTML/BiasVisitor.html | 11 +++-- docs/HTML/BoxCoxVisitor.html | 11 +++-- docs/HTML/CategoryVisitor.html | 6 ++- docs/HTML/CumMaxVisitor.html | 16 ++++--- docs/HTML/CumProdVisitor.html | 6 ++- docs/HTML/CumSumVisitor.html | 6 ++- docs/HTML/DecomposeVisitor.html | 11 +++-- docs/HTML/EntropyVisitor.html | 11 +++-- docs/HTML/ExpandingRollAdopter.html | 6 ++- docs/HTML/ExponentialRollAdopter.html | 6 ++- .../ExponentiallyWeightedMeanVisitor.html | 11 +++-- docs/HTML/FactorizeVisitor.html | 6 ++- docs/HTML/HurstExponentVisitor.html | 5 +- docs/HTML/KthValueVisitor.html | 11 +++-- docs/HTML/LowessVisitor.html | 11 +++-- docs/HTML/MADVisitor.html | 11 +++-- docs/HTML/MaxSubArrayVisitor.html | 13 ++--- docs/HTML/MedianVisitor.html | 11 +++-- docs/HTML/ModeVisitor.html | 20 +++++--- docs/HTML/NonZeroRangeVisitor.html | 11 +++-- docs/HTML/NormalizeVisitor.html | 22 +++++---- docs/HTML/PolyFitVisitor.html | 48 +++++++++++-------- docs/HTML/QuantileVisitor.html | 11 +++-- docs/HTML/RankVisitor.html | 6 ++- docs/HTML/SigmoidVisitor.html | 11 +++-- docs/HTML/SimpleRollAdopter.html | 6 ++- docs/HTML/ZScoreVisitor.html | 11 +++-- docs/HTML/ZeroLagMovingMeanVisitor.html | 9 ++-- include/DataFrame/DataFrameStatsVisitors.h | 11 +++-- src/CommonMakefile.mk | 2 +- 31 files changed, 217 insertions(+), 126 deletions(-) diff --git a/docs/HTML/AutoCorrVisitor.html b/docs/HTML/AutoCorrVisitor.html index 644329dd0..5744c7fe2 100644 --- a/docs/HTML/AutoCorrVisitor.html +++ b/docs/HTML/AutoCorrVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct AutoCorrVisitor;
         
@@ -44,7 +45,8 @@ T: Column data type. T must be an arithmetic-enabled type
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/BiasVisitor.html b/docs/HTML/BiasVisitor.html index 1dfae814f..55e2b62d7 100644 --- a/docs/HTML/BiasVisitor.html +++ b/docs/HTML/BiasVisitor.html @@ -35,14 +35,16 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
 template<typename A, typename T,
-         typename I = unsigned long>
+         typename I = unsigned long,
+         std::size_t A = 0>
 struct BiasVisitor;
 
 // -------------------------------------
 
 template<typename A, typename T,
-         typename I = unsigned long>
-using bias_v = BiasVisitor<A, T, I>;
+         typename I = unsigned long,
+         std::size_t A = 0>
+using bias_v = BiasVisitor<A, T, I, A>;
         
@@ -58,7 +60,8 @@ A: Mean visitor type.
T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/BoxCoxVisitor.html b/docs/HTML/BoxCoxVisitor.html index 6495be247..642f5b8a5 100644 --- a/docs/HTML/BoxCoxVisitor.html +++ b/docs/HTML/BoxCoxVisitor.html @@ -70,13 +70,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct BoxCoxVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using bcox_v = BoxCoxVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using bcox_v = BoxCoxVisitor<T, I, A>;
         
@@ -93,7 +95,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/CategoryVisitor.html b/docs/HTML/CategoryVisitor.html index e4b7b4599..e32acc6ea 100644 --- a/docs/HTML/CategoryVisitor.html +++ b/docs/HTML/CategoryVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct CategoryVisitor;
         
@@ -51,7 +52,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/CumMaxVisitor.html b/docs/HTML/CumMaxVisitor.html index 6aa765a36..d1814faa9 100644 --- a/docs/HTML/CumMaxVisitor.html +++ b/docs/HTML/CumMaxVisitor.html @@ -35,15 +35,18 @@

 #include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long, typename Cmp = std::less<T>>
+template<typename T, typename I = unsigned long, typename Cmp = std::less<T>,
+         std::size_t A = 0>
 struct CumExtremumVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using CumMaxVisitor = CumExtremumVisitor<T, I, std::less<T>>;
-template<typename T, typename I = unsigned long>
-using CumMinVisitor = CumExtremumVisitor<T, I, std::greater<T>>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using CumMaxVisitor = CumExtremumVisitor<T, I, std::less<T>, A>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using CumMinVisitor = CumExtremumVisitor<T, I, std::greater<T>, A>;
         
@@ -53,7 +56,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/CumProdVisitor.html b/docs/HTML/CumProdVisitor.html index fb440292a..bc07286bd 100644 --- a/docs/HTML/CumProdVisitor.html +++ b/docs/HTML/CumProdVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct CumProdVisitor;
         
@@ -45,7 +46,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/CumSumVisitor.html b/docs/HTML/CumSumVisitor.html index 34f9444d4..0d38cb266 100644 --- a/docs/HTML/CumSumVisitor.html +++ b/docs/HTML/CumSumVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct CumSumVisitor;
         
@@ -45,7 +46,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/DecomposeVisitor.html b/docs/HTML/DecomposeVisitor.html index cb109d05c..4780c05ac 100644 --- a/docs/HTML/DecomposeVisitor.html +++ b/docs/HTML/DecomposeVisitor.html @@ -62,13 +62,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct DecomposeVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using decom_v = DecomposeVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using decom_v = DecomposeVisitor<T, I, A>;
         
@@ -91,7 +93,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/EntropyVisitor.html b/docs/HTML/EntropyVisitor.html index c8d59d364..493faf553 100644 --- a/docs/HTML/EntropyVisitor.html +++ b/docs/HTML/EntropyVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct EntropyVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ent_v = EntropyVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ent_v = EntropyVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ExpandingRollAdopter.html b/docs/HTML/ExpandingRollAdopter.html index 9b4a7949e..755deaad1 100644 --- a/docs/HTML/ExpandingRollAdopter.html +++ b/docs/HTML/ExpandingRollAdopter.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename F, typename T, typename I = unsigned long>
+template<typename F, typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ExpandingRollAdopter;
         
@@ -53,7 +54,8 @@ F: Functor type
T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ExponentialRollAdopter.html b/docs/HTML/ExponentialRollAdopter.html index 4031b1795..b8156d4c8 100644 --- a/docs/HTML/ExponentialRollAdopter.html +++ b/docs/HTML/ExponentialRollAdopter.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename F, typename T, typename I = unsigned long>
+template<typename F, typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ExponentialRollAdopter;
         
@@ -59,7 +60,8 @@ F: Functor type
T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ExponentiallyWeightedMeanVisitor.html b/docs/HTML/ExponentiallyWeightedMeanVisitor.html index 417dfbb98..b2196f174 100644 --- a/docs/HTML/ExponentiallyWeightedMeanVisitor.html +++ b/docs/HTML/ExponentiallyWeightedMeanVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ExponentiallyWeightedMeanVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ewm_v = ExponentiallyWeightedMeanVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ewm_v = ExponentiallyWeightedMeanVisitor<T, I, A>;
         
@@ -69,7 +71,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/FactorizeVisitor.html b/docs/HTML/FactorizeVisitor.html index 2739ea7bf..b816e9f98 100644 --- a/docs/HTML/FactorizeVisitor.html +++ b/docs/HTML/FactorizeVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct FactorizeVisitor;
         
@@ -53,7 +54,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/HurstExponentVisitor.html b/docs/HTML/HurstExponentVisitor.html index 13daae155..e859cb58d 100644 --- a/docs/HTML/HurstExponentVisitor.html +++ b/docs/HTML/HurstExponentVisitor.html @@ -62,8 +62,11 @@
+    using RangeVec =
+        std::vector<size_type, typename allocator_declare<size_type, A>::type>;
+
     explicit
-    HurstExponentVisitor(std::vector<size_t> &&ranges)
+    HurstExponentVisitor(RangeVec<size_t> &&ranges);
 
     ranges: A vector of column length divisors.
             For example, {1, 2, 4 } means calculate Hurst exponent in 3 steps.
diff --git a/docs/HTML/KthValueVisitor.html b/docs/HTML/KthValueVisitor.html
index f1d473161..2cd16a13d 100644
--- a/docs/HTML/KthValueVisitor.html
+++ b/docs/HTML/KthValueVisitor.html
@@ -34,13 +34,15 @@
        
         
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct KthValueVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using kthv_v = KthValueVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using kthv_v = KthValueVisitor<T, I, A>;
         
@@ -55,7 +57,8 @@ T: Column data type
- I: Index type + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/LowessVisitor.html b/docs/HTML/LowessVisitor.html index 06a72f219..7c3ed86ee 100644 --- a/docs/HTML/LowessVisitor.html +++ b/docs/HTML/LowessVisitor.html @@ -35,13 +35,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct LowessVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using lowess_v = LowessVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using lowess_v = LowessVisitor<T, I, A>;
         
@@ -73,7 +75,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/MADVisitor.html b/docs/HTML/MADVisitor.html index 5656f9751..06d7a90d7 100644 --- a/docs/HTML/MADVisitor.html +++ b/docs/HTML/MADVisitor.html @@ -60,13 +60,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct MADVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using mad_v = MADVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using mad_v = MADVisitor<T, I, A>;
         
@@ -81,7 +83,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/MaxSubArrayVisitor.html b/docs/HTML/MaxSubArrayVisitor.html index 9fe31c54e..3c26e0cce 100644 --- a/docs/HTML/MaxSubArrayVisitor.html +++ b/docs/HTML/MaxSubArrayVisitor.html @@ -72,17 +72,17 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
 template<std::size_t N, typename T, typename I = unsigned long,
-         typename Cmp = std::less<T>>
+         typename Cmp = std::less<T>, std::size_t A = 0>
 struct NExtremumSubArrayVisitor;
 
 // -------------------------------------
 
-template<std::size_t N, typename T, typename I>
+template<std::size_t N, typename T, typename I, std::size_t A = 0>
 using NMaxSubArrayVisitor =
-    NExtremumSubArrayVisitor<N, T, I, std::less<T>>;
-template<std::size_t N, typename T, typename I>
+    NExtremumSubArrayVisitor<N, T, I, std::less<T>, A>;
+template<std::size_t N, typename T, typename I, std::size_t A = 0>
 using NMinSubArrayVisitor =
-    NExtremumSubArrayVisitor<N, T, I, std::greater<T>>;
+    NExtremumSubArrayVisitor<N, T, I, std::greater<T>, A>;
         
@@ -105,7 +105,8 @@ T: Column data type. T must be an arithmetic-enabled type
- I: Index type. + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/MedianVisitor.html b/docs/HTML/MedianVisitor.html index 2de57e1c8..a6c74eeb3 100644 --- a/docs/HTML/MedianVisitor.html +++ b/docs/HTML/MedianVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct MedianVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using med_v = MedianVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using med_v = MedianVisitor<T, I, A>;
         
@@ -49,7 +51,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ModeVisitor.html b/docs/HTML/ModeVisitor.html index c921ae124..50c625514 100644 --- a/docs/HTML/ModeVisitor.html +++ b/docs/HTML/ModeVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<std::size_t N, typename T, typename I = unsigned long,>
+         std::size_t A = 0>
 struct ModeVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using mode_v = ModeVisitor<T, I>;
+template<std::size_t N, typename T, typename I = unsigned long,>
+         std::size_t A = 0>
+using mode_v = ModeVisitor<N, T, I, A>;
         
@@ -49,15 +51,18 @@ The result is an array of N items each of this type:
+    template<typename U>
+    using vec_type = std::vector<U, typename allocator_declare<U, A>::type>;
+			  
     struct  DataItem  {
-        T                         value;    // Value of the column item
-        std::vector<I>            indices;  // List of indices where value occurred
+        T                               value;    // Value of the column item
+        VectorConstPtrView<I, A>  indices;  // List of indices where value occurred
 
         // Number of times value occurred
         inline std::size_t repeat_count() const  { return (indices.size()); }
 
         // List of column indices where value occurred
-        std::vector<std::size_t>  value_indices_in_col;
+        vec_type<std::size_t>  value_indices_in_col;
     };
         
@@ -65,7 +70,8 @@ N: Number of modes to find
T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/NonZeroRangeVisitor.html b/docs/HTML/NonZeroRangeVisitor.html index d6a876302..54b06d5fc 100644 --- a/docs/HTML/NonZeroRangeVisitor.html +++ b/docs/HTML/NonZeroRangeVisitor.html @@ -35,13 +35,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct NonZeroRangeVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using nzr_v = NonZeroRangeVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using nzr_v = NonZeroRangeVisitor<T, I, A>;
         
@@ -50,7 +52,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/NormalizeVisitor.html b/docs/HTML/NormalizeVisitor.html index 1777f70e8..e69538992 100644 --- a/docs/HTML/NormalizeVisitor.html +++ b/docs/HTML/NormalizeVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct NormalizeVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using norm_v = NormalizeVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using norm_v = NormalizeVisitor<T, I, A>;
         
@@ -49,7 +51,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
@@ -57,13 +60,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct StandardizeVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using stand_v = StandardizeVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using stand_v = StandardizeVisitor<T, I, A>;
         
@@ -72,7 +77,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/PolyFitVisitor.html b/docs/HTML/PolyFitVisitor.html index dbdd6d1cf..ad95e87dd 100644 --- a/docs/HTML/PolyFitVisitor.html +++ b/docs/HTML/PolyFitVisitor.html @@ -36,13 +36,15 @@

#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct PolyFitVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using pfit_v = PolyFitVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using pfit_v = PolyFitVisitor<T, I, A>;
         
@@ -66,7 +68,8 @@

T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
@@ -74,13 +77,15 @@

#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct LogFitVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using lfit_v = LogFitVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using lfit_v = LogFitVisitor<T, I, A>;
         
@@ -102,7 +107,8 @@

T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
@@ -110,13 +116,15 @@

#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ExponentialFitVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using efit_v = ExponentialFitVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using efit_v = ExponentialFitVisitor<T, I, A>;
         
@@ -134,25 +142,24 @@

T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
- - - -
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct LinearFitVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using linfit_v = LinearFitVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using linfit_v = LinearFitVisitor<T, I, A>;
         
@@ -170,7 +177,8 @@

T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/QuantileVisitor.html b/docs/HTML/QuantileVisitor.html index 85957be87..cd953797c 100644 --- a/docs/HTML/QuantileVisitor.html +++ b/docs/HTML/QuantileVisitor.html @@ -61,13 +61,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct QuantileVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using qt_v = QuantileVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using qt_v = QuantileVisitor<T, I, A>;
         
@@ -82,7 +84,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/RankVisitor.html b/docs/HTML/RankVisitor.html index 1b3136e8f..9a3f34a9a 100644 --- a/docs/HTML/RankVisitor.html +++ b/docs/HTML/RankVisitor.html @@ -59,7 +59,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct RankVisitor;
         
@@ -75,7 +76,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/SigmoidVisitor.html b/docs/HTML/SigmoidVisitor.html index 020073388..207a0d33d 100644 --- a/docs/HTML/SigmoidVisitor.html +++ b/docs/HTML/SigmoidVisitor.html @@ -62,13 +62,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct SigmoidVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using sigm_v = SigmoidVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using sigm_v = SigmoidVisitor<T, I, A>;
         
@@ -83,7 +85,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/SimpleRollAdopter.html b/docs/HTML/SimpleRollAdopter.html index 727f11cab..0f00d4a68 100644 --- a/docs/HTML/SimpleRollAdopter.html +++ b/docs/HTML/SimpleRollAdopter.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename F, typename T, typename I = unsigned long>
+template<typename F, typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct SimpleRollAdopter;
         
@@ -50,7 +51,8 @@ F: Functor type
T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ZScoreVisitor.html b/docs/HTML/ZScoreVisitor.html index 7ea7ec146..9bac8b4cd 100644 --- a/docs/HTML/ZScoreVisitor.html +++ b/docs/HTML/ZScoreVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ZScoreVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using zs_v = ZScoreVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using zs_v = ZScoreVisitor<T, I, A>;
         
@@ -49,7 +51,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ZeroLagMovingMeanVisitor.html b/docs/HTML/ZeroLagMovingMeanVisitor.html index 0d8b0ff2b..d831f10bf 100644 --- a/docs/HTML/ZeroLagMovingMeanVisitor.html +++ b/docs/HTML/ZeroLagMovingMeanVisitor.html @@ -34,12 +34,14 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ZeroLagMovingMeanVisitorz;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 using zlmm_v = ZeroLagMovingMeanVisitorz<T, I>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/include/DataFrame/DataFrameStatsVisitors.h b/include/DataFrame/DataFrameStatsVisitors.h index d49db8507..b3c5b1eeb 100644 --- a/include/DataFrame/DataFrameStatsVisitors.h +++ b/include/DataFrame/DataFrameStatsVisitors.h @@ -1029,10 +1029,13 @@ struct NExtremumSubArrayVisitor { compare_type cmp_ { }; }; -template -using NMaxSubArrayVisitor = NExtremumSubArrayVisitor>; -template -using NMinSubArrayVisitor = NExtremumSubArrayVisitor>; +template +using NMaxSubArrayVisitor = NExtremumSubArrayVisitor, A>; +template +using NMinSubArrayVisitor = + NExtremumSubArrayVisitor, A>; // ---------------------------------------------------------------------------- diff --git a/src/CommonMakefile.mk b/src/CommonMakefile.mk index 7f72093f0..ffd8896db 100644 --- a/src/CommonMakefile.mk +++ b/src/CommonMakefile.mk @@ -220,7 +220,7 @@ clobber: $(DATAFRAME_TESTER_OBJ_3) $(HELLO_WORLD_OBJ) \ $(DATAFRAME_TESTER_SCHEMA_OBJ) $(ALLOCATOR_TESTER_OBJ) \ $(DATAFRAME_PERFORMANCE_OBJ) $(DATAFRAME_PERFORMANCE_2_OBJ) \ - $(ALIGNED_DATAFRAME_TESTER_OBJ) $(ALIGNED_DATAFRAME_TESTER_OBJ_2 + $(ALIGNED_DATAFRAME_TESTER_OBJ) $(ALIGNED_DATAFRAME_TESTER_OBJ_2) install_lib: cp -pf $(TARGET_LIB) $(PROJECT_LIB_DIR)/. From 9ef87f9b30f50a144d176cd9338e15c32bb46786 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Thu, 29 Dec 2022 14:01:17 -0500 Subject: [PATCH 21/25] Adjusted docs for aligned memory allocator 2 --- docs/HTML/AccumDistVisitor.html | 9 +++++--- docs/HTML/AffinityPropVisitor.html | 6 +++-- docs/HTML/ArnaudLegouxMAVisitor.html | 11 ++++++---- docs/HTML/AvgDirMovIdxVisitor.html | 11 ++++++---- docs/HTML/BalanceOfPowerVisitor.html | 11 ++++++---- docs/HTML/BollingerBand.html | 6 +++-- docs/HTML/CCIVisitor.html | 6 +++-- docs/HTML/CenterOfGravityVisitor.html | 11 ++++++---- docs/HTML/ChaikinMoneyFlowVisitor.html | 11 ++++++---- docs/HTML/ChandeKrollStopVisitor.html | 11 ++++++---- docs/HTML/CoppockCurveVisitor.html | 11 ++++++---- docs/HTML/DecayVisitor.html | 6 +++-- docs/HTML/DoubleCrossOver.html | 15 ++++++++++--- docs/HTML/DrawdownVisitor.html | 6 +++-- docs/HTML/EBSineWaveVisitor.html | 11 ++++++---- docs/HTML/EhlerSuperSmootherVisitor.html | 11 ++++++---- docs/HTML/FastFourierTransVisitor.html | 11 ++++++---- docs/HTML/FisherTransVisitor.html | 11 ++++++---- docs/HTML/GarmanKlassVolVisitor.html | 11 ++++++---- docs/HTML/HeikinAshiCndlVisitor.html | 11 ++++++---- docs/HTML/HodgesTompkinsVolVisitor.html | 11 ++++++---- docs/HTML/HoltWinterChannelVisitor.html | 11 ++++++---- docs/HTML/HullRollingMeanVisitor.html | 11 ++++++---- docs/HTML/HurstExponentVisitor.html | 11 ++++++---- docs/HTML/KMeansVisitor.html | 6 +++-- docs/HTML/KamaVisitor.html | 6 +++-- docs/HTML/KeltnerChannelsVisitor.html | 11 ++++++---- docs/HTML/MACDVisitor.html | 11 ++++++---- docs/HTML/MassIndexVisitor.html | 11 ++++++---- docs/HTML/OnBalanceVolumeVisitor.html | 11 ++++++---- docs/HTML/PSLVisitor.html | 6 +++-- docs/HTML/ParabolicSARVisitor.html | 11 ++++++---- docs/HTML/ParkinsonVolVisitor.html | 9 +++++--- docs/HTML/PercentPriceOSCIVisitor.html | 11 ++++++---- docs/HTML/PivotPointSRVisitor.html | 11 ++++++---- docs/HTML/PrettyGoodOsciVisitor.html | 11 ++++++---- docs/HTML/RSIVisitor.html | 22 ++++++++++++------- docs/HTML/RateOfChangeVisitor.html | 11 ++++++---- docs/HTML/ReturnVisitor.html | 6 +++-- docs/HTML/RollingMidValueVisitor.html | 11 ++++++---- docs/HTML/SlopeVisitor.html | 6 +++-- docs/HTML/T3MovingMeanVisitor.html | 11 ++++++---- docs/HTML/TTMTrendVisitor.html | 11 ++++++---- docs/HTML/TrixVisitor.html | 11 ++++++---- docs/HTML/TrueRangeVisitor.html | 6 +++-- docs/HTML/UlcerIndexVisitor.html | 11 ++++++---- docs/HTML/UltimateOSCIVisitor.html | 11 ++++++---- docs/HTML/VWAPVisitor.html | 11 ++++++---- docs/HTML/VWBASVisitor.html | 11 ++++++---- docs/HTML/VarIdxDynAvgVisitor.html | 11 ++++++---- docs/HTML/VertHorizFilterVisitor.html | 11 ++++++---- docs/HTML/VortexVisitor.html | 11 ++++++---- docs/HTML/WilliamPrcRVisitor.html | 11 ++++++---- docs/HTML/YangZhangVolVisitor.html | 11 ++++++---- .../DataFrame/DataFrameFinancialVisitors.h | 10 ++++----- 55 files changed, 360 insertions(+), 200 deletions(-) diff --git a/docs/HTML/AccumDistVisitor.html b/docs/HTML/AccumDistVisitor.html index 9967d52e6..0e748f48f 100644 --- a/docs/HTML/AccumDistVisitor.html +++ b/docs/HTML/AccumDistVisitor.html @@ -34,12 +34,14 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct AccumDistVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 using ad_v = AccumDistVisitor<T, I>;
         
@@ -51,7 +53,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/AffinityPropVisitor.html b/docs/HTML/AffinityPropVisitor.html index bd8472e34..7ef490ad8 100644 --- a/docs/HTML/AffinityPropVisitor.html +++ b/docs/HTML/AffinityPropVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameMLVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct AffinityPropVisitor;
         
@@ -61,7 +62,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ArnaudLegouxMAVisitor.html b/docs/HTML/ArnaudLegouxMAVisitor.html index 18b6cfb8d..a1e19a6c3 100644 --- a/docs/HTML/ArnaudLegouxMAVisitor.html +++ b/docs/HTML/ArnaudLegouxMAVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ArnaudLegouxMAVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using alma_v = ArnaudLegouxMAVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using alma_v = ArnaudLegouxMAVisitor<T, I, A>;
         
@@ -63,7 +65,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/AvgDirMovIdxVisitor.html b/docs/HTML/AvgDirMovIdxVisitor.html index 6d0b6bfca..6bc61e79f 100644 --- a/docs/HTML/AvgDirMovIdxVisitor.html +++ b/docs/HTML/AvgDirMovIdxVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct AvgDirMovIdxVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using adx_v = AvgDirMovIdxVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using adx_v = AvgDirMovIdxVisitor<T, I, A>;
         
@@ -51,7 +53,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/BalanceOfPowerVisitor.html b/docs/HTML/BalanceOfPowerVisitor.html index 547461aef..30f094d5f 100644 --- a/docs/HTML/BalanceOfPowerVisitor.html +++ b/docs/HTML/BalanceOfPowerVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct BalanceOfPowerVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using bop_v = BalanceOfPowerVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using bop_v = BalanceOfPowerVisitor<T, I, A>;
         
@@ -61,7 +63,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/BollingerBand.html b/docs/HTML/BollingerBand.html index cb1ce9a3d..e2597faf8 100644 --- a/docs/HTML/BollingerBand.html +++ b/docs/HTML/BollingerBand.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct BollingerBand;
         
@@ -65,7 +66,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/CCIVisitor.html b/docs/HTML/CCIVisitor.html index e1f3b1c37..2a6cb03af 100644 --- a/docs/HTML/CCIVisitor.html +++ b/docs/HTML/CCIVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct CCIVisitor;
         
@@ -53,7 +54,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/CenterOfGravityVisitor.html b/docs/HTML/CenterOfGravityVisitor.html index 8b95fb8bc..361c7c5ce 100644 --- a/docs/HTML/CenterOfGravityVisitor.html +++ b/docs/HTML/CenterOfGravityVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct CenterOfGravityVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using cog_v = CenterOfGravityVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using cog_v = CenterOfGravityVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ChaikinMoneyFlowVisitor.html b/docs/HTML/ChaikinMoneyFlowVisitor.html index 25df5b88c..5827be779 100644 --- a/docs/HTML/ChaikinMoneyFlowVisitor.html +++ b/docs/HTML/ChaikinMoneyFlowVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ChaikinMoneyFlowVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using cmf_v = ChaikinMoneyFlowVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using cmf_v = ChaikinMoneyFlowVisitor<T, I, A>;
         
@@ -51,7 +53,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ChandeKrollStopVisitor.html b/docs/HTML/ChandeKrollStopVisitor.html index 97ce7f819..938f49824 100644 --- a/docs/HTML/ChandeKrollStopVisitor.html +++ b/docs/HTML/ChandeKrollStopVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ChandeKrollStopVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using cksp_v = ChandeKrollStopVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using cksp_v = ChandeKrollStopVisitor<T, I, A>;
         
@@ -69,7 +71,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/CoppockCurveVisitor.html b/docs/HTML/CoppockCurveVisitor.html index 01a0193e4..d3efd89c9 100644 --- a/docs/HTML/CoppockCurveVisitor.html +++ b/docs/HTML/CoppockCurveVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct CoppockCurveVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using coppc_v = CoppockCurveVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using coppc_v = CoppockCurveVisitor<T, I, A>;
         
@@ -59,7 +61,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/DecayVisitor.html b/docs/HTML/DecayVisitor.html index f02cf4593..dace90c71 100644 --- a/docs/HTML/DecayVisitor.html +++ b/docs/HTML/DecayVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct DecayVisitor;
         
@@ -55,7 +56,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/DoubleCrossOver.html b/docs/HTML/DoubleCrossOver.html index 7e5874adc..d06894d1f 100644 --- a/docs/HTML/DoubleCrossOver.html +++ b/docs/HTML/DoubleCrossOver.html @@ -34,13 +34,21 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename S_RT,  // Short duration rolling adopter
+         typename L_RT,  // Longer duration rolling adopter
+         typename T,
+         typename I = unsigned long,
+         std::size_t A = 0>
 struct DoubleCrossOver;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using dco_v = DoubleCrossOver<T, I>;
+template<typename S_RT,  // Short duration rolling adopter
+         typename L_RT,  // Longer duration rolling adopter
+         typename T,
+         typename I = unsigned long,
+         std::size_t A = 0>
+using dco_v = DoubleCrossOver<S_RT, L_RT, T, I, A>;
         
@@ -64,6 +72,7 @@ L_RT: A longer term moving average adopter. For example, an exponential moving adopter using a simple mean
T: Column data type
I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/DrawdownVisitor.html b/docs/HTML/DrawdownVisitor.html index caee82bd2..3434e2489 100644 --- a/docs/HTML/DrawdownVisitor.html +++ b/docs/HTML/DrawdownVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct DrawdownVisitor;
         
@@ -50,7 +51,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/EBSineWaveVisitor.html b/docs/HTML/EBSineWaveVisitor.html index c4bb480d3..40dfca9fe 100644 --- a/docs/HTML/EBSineWaveVisitor.html +++ b/docs/HTML/EBSineWaveVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct EBSineWaveVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ebsw_v = EBSineWaveVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ebsw_v = EBSineWaveVisitor<T, I, A>;
         
@@ -59,7 +61,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/EhlerSuperSmootherVisitor.html b/docs/HTML/EhlerSuperSmootherVisitor.html index 19ac008cf..e6b8be9a8 100644 --- a/docs/HTML/EhlerSuperSmootherVisitor.html +++ b/docs/HTML/EhlerSuperSmootherVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct EhlerSuperSmootherVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ess_v = EhlerSuperSmootherVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ess_v = EhlerSuperSmootherVisitor<T, I, A>;
         
@@ -58,7 +60,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/FastFourierTransVisitor.html b/docs/HTML/FastFourierTransVisitor.html index d32fb2dd1..4974bc61b 100644 --- a/docs/HTML/FastFourierTransVisitor.html +++ b/docs/HTML/FastFourierTransVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameMLVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct FastFourierTransVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using fft_v = FastFourierTransVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using fft_v = FastFourierTransVisitor<T, I, A>;
         
@@ -62,7 +64,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/FisherTransVisitor.html b/docs/HTML/FisherTransVisitor.html index d6ae5b2e3..9819d1e86 100644 --- a/docs/HTML/FisherTransVisitor.html +++ b/docs/HTML/FisherTransVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct FisherTransVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ftrans_v = FisherTransVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ftrans_v = FisherTransVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/GarmanKlassVolVisitor.html b/docs/HTML/GarmanKlassVolVisitor.html index 8220f8ee8..cd6ce14bf 100644 --- a/docs/HTML/GarmanKlassVolVisitor.html +++ b/docs/HTML/GarmanKlassVolVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct GarmanKlassVolVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using gk_vol_v = GarmanKlassVolVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using gk_vol_v = GarmanKlassVolVisitor<T, I, A>;
         
@@ -58,7 +60,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/HeikinAshiCndlVisitor.html b/docs/HTML/HeikinAshiCndlVisitor.html index 0b1246ae6..89d4cc538 100644 --- a/docs/HTML/HeikinAshiCndlVisitor.html +++ b/docs/HTML/HeikinAshiCndlVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct HeikinAshiCndlVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ha_cdl_v = HeikinAshiCndlVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ha_cdl_v = HeikinAshiCndlVisitor<T, I, A>;
         
@@ -55,7 +57,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/HodgesTompkinsVolVisitor.html b/docs/HTML/HodgesTompkinsVolVisitor.html index baa2ceb5f..aa8b22257 100644 --- a/docs/HTML/HodgesTompkinsVolVisitor.html +++ b/docs/HTML/HodgesTompkinsVolVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct HodgesTompkinsVolVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ht_vol_v = HodgesTompkinsVolVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ht_vol_v = HodgesTompkinsVolVisitor<T, I, A>;
         
@@ -58,7 +60,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/HoltWinterChannelVisitor.html b/docs/HTML/HoltWinterChannelVisitor.html index 1fbde2a9a..a9f27e53b 100644 --- a/docs/HTML/HoltWinterChannelVisitor.html +++ b/docs/HTML/HoltWinterChannelVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct HoltWinterChannelVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using hwc_v = HoltWinterChannelVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using hwc_v = HoltWinterChannelVisitor<T, I, A>;
         
@@ -69,7 +71,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/HullRollingMeanVisitor.html b/docs/HTML/HullRollingMeanVisitor.html index b84428877..21c5770ef 100644 --- a/docs/HTML/HullRollingMeanVisitor.html +++ b/docs/HTML/HullRollingMeanVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct HullRollingMeanVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using hull_mean_v = HullRollingMeanVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using hull_mean_v = HullRollingMeanVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/HurstExponentVisitor.html b/docs/HTML/HurstExponentVisitor.html index e859cb58d..9834ea1d3 100644 --- a/docs/HTML/HurstExponentVisitor.html +++ b/docs/HTML/HurstExponentVisitor.html @@ -35,13 +35,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct HurstExponentVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using hexpo_v = HurstExponentVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using hexpo_v = HurstExponentVisitor<T, I, A>;
         
@@ -76,7 +78,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/KMeansVisitor.html b/docs/HTML/KMeansVisitor.html index 039348381..cfd8ac3f2 100644 --- a/docs/HTML/KMeansVisitor.html +++ b/docs/HTML/KMeansVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameMLVisitors.h>
 
-template<size_t K, typename T, typename I = unsigned long>
+template<size_t K, typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct KMeansVisitor;
         
@@ -62,7 +63,8 @@ K: Number of means to find
T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/KamaVisitor.html b/docs/HTML/KamaVisitor.html index 0c89bf43c..100b43149 100644 --- a/docs/HTML/KamaVisitor.html +++ b/docs/HTML/KamaVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct KamaVisitor;
         
@@ -53,7 +54,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/KeltnerChannelsVisitor.html b/docs/HTML/KeltnerChannelsVisitor.html index d3b96f9b9..105554352 100644 --- a/docs/HTML/KeltnerChannelsVisitor.html +++ b/docs/HTML/KeltnerChannelsVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct KeltnerChannelsVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using kch_v = KeltnerChannelsVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using kch_v = KeltnerChannelsVisitor<T, I, A>;
         
@@ -68,7 +70,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/MACDVisitor.html b/docs/HTML/MACDVisitor.html index de90efad9..91c28a546 100644 --- a/docs/HTML/MACDVisitor.html +++ b/docs/HTML/MACDVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct MACDVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using macd_v = MACDVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using macd_v = MACDVisitor<T, I, A>;
         
@@ -70,7 +72,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/MassIndexVisitor.html b/docs/HTML/MassIndexVisitor.html index 3b9bd5700..0a2b2975b 100644 --- a/docs/HTML/MassIndexVisitor.html +++ b/docs/HTML/MassIndexVisitor.html @@ -35,13 +35,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct MassIndexVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using mass_idx_v = MassIndexVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using mass_idx_v = MassIndexVisitor<T, I, A>;
         
@@ -60,7 +62,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/OnBalanceVolumeVisitor.html b/docs/HTML/OnBalanceVolumeVisitor.html index b38035aa9..dfe125840 100644 --- a/docs/HTML/OnBalanceVolumeVisitor.html +++ b/docs/HTML/OnBalanceVolumeVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct OnBalanceVolumeVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using obv_v = OnBalanceVolumeVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using obv_v = OnBalanceVolumeVisitor<T, I, A>;
         
@@ -51,7 +53,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/PSLVisitor.html b/docs/HTML/PSLVisitor.html index ddbeed77c..0476bb402 100644 --- a/docs/HTML/PSLVisitor.html +++ b/docs/HTML/PSLVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct PSLVisitor;
         
@@ -53,7 +54,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ParabolicSARVisitor.html b/docs/HTML/ParabolicSARVisitor.html index 47d4e4e90..d2a1eea43 100644 --- a/docs/HTML/ParabolicSARVisitor.html +++ b/docs/HTML/ParabolicSARVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ParabolicSARVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using psar_v = ParabolicSARVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using psar_v = ParabolicSARVisitor<T, I, A>;
         
@@ -63,7 +65,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ParkinsonVolVisitor.html b/docs/HTML/ParkinsonVolVisitor.html index bff1698a0..427e66ac6 100644 --- a/docs/HTML/ParkinsonVolVisitor.html +++ b/docs/HTML/ParkinsonVolVisitor.html @@ -34,12 +34,14 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ParkinsonVolVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 using p_vol_v = ParkinsonVolVisitor<T, I>;
         
@@ -58,7 +60,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/PercentPriceOSCIVisitor.html b/docs/HTML/PercentPriceOSCIVisitor.html index a576fc304..702843cfa 100644 --- a/docs/HTML/PercentPriceOSCIVisitor.html +++ b/docs/HTML/PercentPriceOSCIVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct PercentPriceOSCIVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using pp_osc_v = PercentPriceOSCIVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using pp_osc_v = PercentPriceOSCIVisitor<T, I, A>;
         
@@ -59,7 +61,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/PivotPointSRVisitor.html b/docs/HTML/PivotPointSRVisitor.html index 21c707120..b974d9c52 100644 --- a/docs/HTML/PivotPointSRVisitor.html +++ b/docs/HTML/PivotPointSRVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct PivotPointSRVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ppsr_v = PivotPointSRVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ppsr_v = PivotPointSRVisitor<T, I, A>;
         
@@ -59,7 +61,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/PrettyGoodOsciVisitor.html b/docs/HTML/PrettyGoodOsciVisitor.html index c5de7cdc3..7746f0d90 100644 --- a/docs/HTML/PrettyGoodOsciVisitor.html +++ b/docs/HTML/PrettyGoodOsciVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct PrettyGoodOsciVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using pgo_v = PrettyGoodOsciVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using pgo_v = PrettyGoodOsciVisitor<T, I, A>;
         
@@ -58,7 +60,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/RSIVisitor.html b/docs/HTML/RSIVisitor.html index a7955524f..1f4e6164a 100644 --- a/docs/HTML/RSIVisitor.html +++ b/docs/HTML/RSIVisitor.html @@ -35,13 +35,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct RSIVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using rsi_v = RSIVisitor<<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using rsi_v = RSIVisitor<<T, I, A>;
         
@@ -61,7 +63,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
@@ -69,13 +72,15 @@
#include <DataFrame/DataFrameStatsVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct RSXVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using rsx_v = RSXVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using rsx_v = RSXVisitor<T, I, A>;
         
@@ -90,7 +95,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/RateOfChangeVisitor.html b/docs/HTML/RateOfChangeVisitor.html index 72d02ac0c..17680034f 100644 --- a/docs/HTML/RateOfChangeVisitor.html +++ b/docs/HTML/RateOfChangeVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct RateOfChangeVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using roc_v = RateOfChangeVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using roc_v = RateOfChangeVisitor<T, I, A>;
         
@@ -59,7 +61,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/ReturnVisitor.html b/docs/HTML/ReturnVisitor.html index 16b6e90ed..2f974afba 100644 --- a/docs/HTML/ReturnVisitor.html +++ b/docs/HTML/ReturnVisitor.html @@ -60,7 +60,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct ReturnVisitor;
         
@@ -76,7 +77,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/RollingMidValueVisitor.html b/docs/HTML/RollingMidValueVisitor.html index 4c79ba58a..92b298e45 100644 --- a/docs/HTML/RollingMidValueVisitor.html +++ b/docs/HTML/RollingMidValueVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct RollingMidValueVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using mid_val_v = RollingMidValueVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using mid_val_v = RollingMidValueVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/SlopeVisitor.html b/docs/HTML/SlopeVisitor.html index 85af00fbe..2f5e44510 100644 --- a/docs/HTML/SlopeVisitor.html +++ b/docs/HTML/SlopeVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct SlopeVisitor;
         
@@ -54,7 +55,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/T3MovingMeanVisitor.html b/docs/HTML/T3MovingMeanVisitor.html index d6d6a69a3..61162b7b6 100644 --- a/docs/HTML/T3MovingMeanVisitor.html +++ b/docs/HTML/T3MovingMeanVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct T3MovingMeanVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using t3_v = T3MovingMeanVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using t3_v = T3MovingMeanVisitor<T, I, A>;
         
@@ -59,7 +61,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/TTMTrendVisitor.html b/docs/HTML/TTMTrendVisitor.html index 979076c34..8ee02a3b2 100644 --- a/docs/HTML/TTMTrendVisitor.html +++ b/docs/HTML/TTMTrendVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct TTMTrendVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using ttmt_v = TTMTrendVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using ttmt_v = TTMTrendVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/TrixVisitor.html b/docs/HTML/TrixVisitor.html index 569aec3b5..59743e758 100644 --- a/docs/HTML/TrixVisitor.html +++ b/docs/HTML/TrixVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct TrixVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using trix_v = TrixVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using trix_v = TrixVisitor<T, I, A>;
         
@@ -65,7 +67,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/TrueRangeVisitor.html b/docs/HTML/TrueRangeVisitor.html index e1e02fffd..c534be642 100644 --- a/docs/HTML/TrueRangeVisitor.html +++ b/docs/HTML/TrueRangeVisitor.html @@ -34,7 +34,8 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct TrueRangeVisitor;
         
@@ -58,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/UlcerIndexVisitor.html b/docs/HTML/UlcerIndexVisitor.html index 536d84d26..125bd0e7a 100644 --- a/docs/HTML/UlcerIndexVisitor.html +++ b/docs/HTML/UlcerIndexVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct UlcerIndexVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using u_idx_v = UlcerIndexVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using u_idx_v = UlcerIndexVisitor<T, I, A>;
         
@@ -60,7 +62,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/UltimateOSCIVisitor.html b/docs/HTML/UltimateOSCIVisitor.html index 80bd1a752..35bbdba17 100644 --- a/docs/HTML/UltimateOSCIVisitor.html +++ b/docs/HTML/UltimateOSCIVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct UltimateOSCIVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using u_osc_v = UltimateOSCIVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using u_osc_v = UltimateOSCIVisitor<T, I, A>;
         
@@ -66,7 +68,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/VWAPVisitor.html b/docs/HTML/VWAPVisitor.html index 7c17ca84c..dddcfb7e4 100644 --- a/docs/HTML/VWAPVisitor.html +++ b/docs/HTML/VWAPVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct VWAPVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using vwap_v = VWAPVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using vwap_v = VWAPVisitor<T, I, A>;
         
@@ -84,7 +86,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/VWBASVisitor.html b/docs/HTML/VWBASVisitor.html index 85b7bc2cf..8de47f880 100644 --- a/docs/HTML/VWBASVisitor.html +++ b/docs/HTML/VWBASVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct VWBASVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using vwbas_v = VWBASVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using vwbas_v = VWBASVisitor<T, I, A>;
         
@@ -92,7 +94,8 @@ T: Column data type.
- I: Index type. + I: Index type.
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/VarIdxDynAvgVisitor.html b/docs/HTML/VarIdxDynAvgVisitor.html index f0f39a6f9..45d0b4c36 100644 --- a/docs/HTML/VarIdxDynAvgVisitor.html +++ b/docs/HTML/VarIdxDynAvgVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct VarIdxDynAvgVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using vidya_v = VarIdxDynAvgVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using vidya_v = VarIdxDynAvgVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/VertHorizFilterVisitor.html b/docs/HTML/VertHorizFilterVisitor.html index 11173ed39..d6ef28c6c 100644 --- a/docs/HTML/VertHorizFilterVisitor.html +++ b/docs/HTML/VertHorizFilterVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct VertHorizFilterVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using vhf_v = VertHorizFilterVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using vhf_v = VertHorizFilterVisitor<T, I, A>;
         
@@ -59,7 +61,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/VortexVisitor.html b/docs/HTML/VortexVisitor.html index 5a5bb452d..5cd0ed134 100644 --- a/docs/HTML/VortexVisitor.html +++ b/docs/HTML/VortexVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct VortexVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using vtx_v = VortexVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using vtx_v = VortexVisitor<T, I, A>;
         
@@ -65,7 +67,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/WilliamPrcRVisitor.html b/docs/HTML/WilliamPrcRVisitor.html index 6272fd08c..6cc91b6bc 100644 --- a/docs/HTML/WilliamPrcRVisitor.html +++ b/docs/HTML/WilliamPrcRVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct WilliamPrcRVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using willp_v = WilliamPrcRVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using willp_v = WilliamPrcRVisitor<T, I, A>;
         
@@ -57,7 +59,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/docs/HTML/YangZhangVolVisitor.html b/docs/HTML/YangZhangVolVisitor.html index f02d85a65..75765d274 100644 --- a/docs/HTML/YangZhangVolVisitor.html +++ b/docs/HTML/YangZhangVolVisitor.html @@ -34,13 +34,15 @@
#include <DataFrame/DataFrameFinancialVisitors.h>
 
-template<typename T, typename I = unsigned long>
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
 struct YangZhangVolVisitor;
 
 // -------------------------------------
 
-template<typename T, typename I = unsigned long>
-using yz_vol_v = YangZhangVolVisitor<T, I>;
+template<typename T, typename I = unsigned long,
+         std::size_t A = 0>
+using yz_vol_v = YangZhangVolVisitor<T, I, A>;
         
@@ -60,7 +62,8 @@ T: Column data type
- I: Index type + I: Index type
+ A: Memory alignment boundary for vectors. Default is system default alignment
diff --git a/include/DataFrame/DataFrameFinancialVisitors.h b/include/DataFrame/DataFrameFinancialVisitors.h index 0cd827342..293b53e38 100644 --- a/include/DataFrame/DataFrameFinancialVisitors.h +++ b/include/DataFrame/DataFrameFinancialVisitors.h @@ -1632,14 +1632,14 @@ struct WilliamPrcRVisitor { assert((col_s == size_type(std::distance(low_begin, low_end)))); assert((col_s == size_type(std::distance(high_begin, high_end)))); - SimpleRollAdopter, T, I, A> min_v (MinVisitor(), + SimpleRollAdopter, T, I, A> min_v(MinVisitor(), roll_count_); min_v.pre(); min_v (idx_begin, idx_end, low_begin, low_end); min_v.post(); - SimpleRollAdopter, T, I, A> max_v (MaxVisitor(), + SimpleRollAdopter, T, I, A> max_v(MaxVisitor(), roll_count_); max_v.pre(); @@ -1727,7 +1727,7 @@ struct PSLVisitor { template inline void calculate_(const K &idx_begin, const K &idx_end) { - SimpleRollAdopter, T, I, A> sum_r (SumVisitor(), + SimpleRollAdopter, T, I, A> sum_r(SumVisitor(), roll_count_); sum_r.pre(); @@ -2072,9 +2072,9 @@ struct FisherTransVisitor { for (size_type i = 0; i < col_s; ++i) mid_hl.push_back((*(low_begin + i) + *(high_begin + i)) * T(0.5)); - SimpleRollAdopter, T, I, A> max_v (MaxVisitor(), + SimpleRollAdopter, T, I, A> max_v(MaxVisitor(), roll_count_); - SimpleRollAdopter, T, I, A> min_v (MinVisitor(), + SimpleRollAdopter, T, I, A> min_v(MinVisitor(), roll_count_); max_v.pre(); From b75f26200204a29e2308e16b995152c5a63fcd54 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sat, 31 Dec 2022 12:50:41 -0500 Subject: [PATCH 22/25] Adjusted docs for aligned memory allocator 3 --- docs/HTML/DotProdVisitor.html | 34 +- docs/HTML/concat.html | 6 +- docs/HTML/get_data.html | 114 ++--- docs/HTML/get_data_by_idx.html | 368 +++++++------- docs/HTML/get_data_by_loc.html | 453 +++++++++--------- docs/HTML/get_data_by_rand.html | 8 +- docs/HTML/get_data_by_sel.html | 20 +- docs/HTML/get_memory_usage.html | 30 +- docs/HTML/get_reindexed.html | 6 +- include/DataFrame/DataFrame.h | 4 +- include/DataFrame/Internals/DataFrame_get.tcc | 2 +- .../DataFrame/Internals/DataFrame_join.tcc | 2 +- 12 files changed, 528 insertions(+), 519 deletions(-) diff --git a/docs/HTML/DotProdVisitor.html b/docs/HTML/DotProdVisitor.html index c4936bc75..63966027f 100644 --- a/docs/HTML/DotProdVisitor.html +++ b/docs/HTML/DotProdVisitor.html @@ -49,19 +49,19 @@ -
static void test_view_visitors()  {
+
static void test_view_visitors()  {
 
     std::cout << "\nTesting View visitors ..." << std::endl;
 
     MyDataFrame         df;
 
-    std::vector<unsigned long>  idxvec = { 1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL, 8UL, 9UL, 10UL };
-    std::vector<double>         dblvec1 = { 1.1, 2.2, 3.3, 4.4, 5.5 };
-    std::vector<double>         dblvec2 = { 2.2, 3.3, 4.4, 5.5, 6.6 };
-    std::vector<double>         dblvec3 = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
-    std::vector<double>         dblvec4 = { 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1 };
-    std::vector<double>         dblvec5 = { 1.1, 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1, 10.1 };
-    std::vector<double>         dblvec6 = { 1.1, 1.1, 3.3, 3.3, 1.1 };
+    StlVecType<unsigned long>  idxvec = { 1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL, 8UL, 9UL, 10UL };
+    StlVecType<double>         dblvec1 = { 1.1, 2.2, 3.3, 4.4, 5.5 };
+    StlVecType<double>         dblvec2 = { 2.2, 3.3, 4.4, 5.5, 6.6 };
+    StlVecType<double>         dblvec3 = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
+    StlVecType<double>         dblvec4 = { 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1 };
+    StlVecType<double>         dblvec5 = { 1.1, 5.9, 4.4, 1.0, 9.8, 5.3, 7.2, 3.8, 4.1, 10.1 };
+    StlVecType<double>         dblvec6 = { 1.1, 1.1, 3.3, 3.3, 1.1 };
 
     df.load_data(std::move(idxvec),
                  std::make_pair("dbl_col1", dblvec1),
@@ -71,7 +71,7 @@
                  std::make_pair("dbl_col5", dblvec5),
                  std::make_pair("dbl_col6", dblvec6));
 
-    typedef DataFrameView<unsigned long> MyDataFrameView;
+    typedef StdDataFrame<unsigned long>::View MyDataFrameView;
 
     MyDataFrameView dfv = df.get_view_by_idx<double>(Index2D<unsigned long> { 2, 4 });
     assert(dfv.get_index().size() == 3);
@@ -81,19 +81,18 @@
     DotProdVisitor<double> dp_visitor;
     assert(fabs(dfv.visit<double, double>("dbl_col1", "dbl_col2", dp_visitor).get_result() - 45.98) < 0.00001);
 
-
-    SimpleRollAdopter<MeanVisitor<double>, double> mean_roller1(MeanVisitor<double>(), 3);
-    const auto &res_sra = dfv.single_act_visit<double>("dbl_col1", mean_roller1).get_result();
+    SimpleRollAdopter<MeanVisitor<double>, double>mean_roller1(MeanVisitor<double>(), 3);
+    const auto &res_sra = dfv.single_act_visit<double>("dbl_col1", mean_roller1, true).get_result();
 
     assert(fabs(res_sra[2] - 3.3) < 0.00001);
 
-    SimpleRollAdopter<GeometricMeanVisitor<double>, double> geo_mean_roller(GeometricMeanVisitor<double>(), 3);
+    SimpleRollAdopter<GeometricMeanVisitor<double>, double>  geo_mean_roller(GeometricMeanVisitor<double>(), 3);
     const auto  &res_srga = df.single_act_visit<double>("dbl_col4", geo_mean_roller).get_result();
 
     assert(fabs(res_srga[2] - 2.96098) < 0.00001);
     assert(fabs(res_srga[6] - 5.25368) < 0.00001);
 
-    SimpleRollAdopter<HarmonicMeanVisitor<double>, double> har_mean_roller(HarmonicMeanVisitor<double>(), 3);
+    SimpleRollAdopter<HarmonicMeanVisitor<double>, double>  har_mean_roller(HarmonicMeanVisitor<double>(), 3);
     const auto  &res_srha = df.single_act_visit<double>("dbl_col4", har_mean_roller).get_result();
 
     assert(fabs(res_srha[2] - 2.14782) < 0.00001);
@@ -132,8 +131,9 @@
 
     ReturnVisitor<double> ret_visitor(return_policy::monetary);
     const auto &res_ret = df.single_act_visit<double>("dbl_col4", ret_visitor).get_result();
-    assert(fabs(res_ret[0] - -1.5) < 0.00001);
-    assert(fabs(res_ret[6] - 0.3) < 0.00001);
+    assert(std::isnan(res_ret[0]));
+    assert(fabs(res_ret[1] - -1.5) < 0.00001);
+    assert(fabs(res_ret[7] - 0.3) < 0.00001);
 
     MedianVisitor<double> med_visitor;
     const auto &res_med = dfv2.single_act_visit<double>("dbl_col3", med_visitor).get_result();
@@ -155,7 +155,7 @@
     assert(fabs(res_zs[4] - 0.04336) < 0.00001);
 }
 
- + C++ DataFrame diff --git a/docs/HTML/concat.html b/docs/HTML/concat.html index 1716bec68..9fb9423cf 100644 --- a/docs/HTML/concat.html +++ b/docs/HTML/concat.html @@ -67,7 +67,7 @@

 template<typename RHS_T, typename ... Ts>
-StdDataFrame<I>
+DataFrame<I, H>
 concat(const RHS_T &rhs,
        concat_policy cp = concat_policy::all_columns) const;
         
@@ -88,7 +88,7 @@

 template<typename RHS_T, typename ... Ts>
-DataFramePtrView<I>
+PtrView
 concat_view(
     RHS_T &rhs,
     concat_policy cp = concat_policy::common_columns);
@@ -111,7 +111,7 @@
        
         

 template<typename RHS_T, typename ... Ts>
-DataFramePtrView<I>
+ConstPtrView
 concat_view(
     RHS_T &rhs,
     concat_policy cp = concat_policy::common_columns) const;
diff --git a/docs/HTML/get_data.html b/docs/HTML/get_data.html
index 483a06342..4733d6f2f 100644
--- a/docs/HTML/get_data.html
+++ b/docs/HTML/get_data.html
@@ -52,12 +52,12 @@
        
         

 template<typename ... Ts>
-DataFrameView<I>
+View
 get_view(const std::vector<const char *> col_names);
         
- It behaves like get_data(), but it returns a DataFrameView. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.
+ It behaves like get_data(), but it returns a View. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.
NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
NOTE: Views could not be const, becuase you can change original data through views.
@@ -71,7 +71,7 @@

 template<typename ... Ts>
-DataFrameConstView<I>
+ConstView
 get_view(const std::vector<const char *> col_names) const;
         
@@ -86,58 +86,62 @@ -
static void test_get_data()  {
-
-    std::cout << "\nTesting get_[data|view]() ..." << std::endl;
-
-    std::vector<unsigned long>  idx =
-        { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 };
-    std::vector<int>    i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 };
-    MyDataFrame         df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", i1));
-
-    auto    df2 = df.get_data<double, int>({ "col_1", "col_4"});
-
-    assert((! df2.has_column("col_2")));
-    assert((! df2.has_column("col_3")));
-    assert((df2.get_column<double>("col_1")[11] == 12));
-    assert((df2.get_column<int>("col_4")[8] == 2));
-    assert((df2.get_index()[3] == 123453));
-
-    const MyDataFrame                   &const_df = df;
-    DataFrameView<unsigned long>        df3 = df.get_view<double, int>({ "col_1", "col_4"});
-    DataFrameConstView<unsigned long>   const_df3 = const_df.get_view<double, int>({ "col_1", "col_4"});
-
-    assert((! df3.has_column("col_2")));
-    assert((! df3.has_column("col_3")));
-    assert((df3.get_column<double>("col_1")[11] == 12));
-    assert((df3.get_column<int>("col_4")[8] == 2));
-    assert((df3.get_index()[3] == 123453));
-
-    df3.get_index()[3] = 100;
-    df3.get_column<int>("col_4")[8] = 101;
-    df3.get_column<double>("col_1")[11] = 102.2;
-
-    assert((df3.get_column<double>("col_1")[11] == 102.2));
-    assert((df3.get_column<int>("col_4")[8] == 101));
-    assert((df3.get_index()[3] == 100));
-    assert((df.get_column<double>("col_1")[11] == 102.2));
-    assert((df.get_column<int>("col_4")[8] == 101));
-    assert((df.get_index()[3] == 100));
-
-    assert((const_df3.get_column<double>("col_1")[11] == 102.2));
-    assert((const_df3.get_column<int>("col_4")[8] == 101));
-    assert((const_df3.get_index()[3] == 100));
-}
-
+
static void test_get_data()  {
+
+    std::cout << "\nTesting get_[data|view]() ..." << std::endl;
+
+    StlVecType<unsigned long>  idx =
+        { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 };
+    StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 };
+    StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 };
+    StlVecType<int>    i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 };
+    MyDataFrame        df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", i1));
+
+    auto    df2 = df.get_data<double, int>({ "col_1", "col_4"});
+
+    assert((! df2.has_column("col_2")));
+    assert((! df2.has_column("col_3")));
+    assert((df2.get_column<double>("col_1")[11] == 12));
+    assert((df2.get_column<int>("col_4")[8] == 2));
+    assert((df2.get_index()[3] == 123453));
+
+    typedef MyDataFrame::View MyDataFrameView;
+    typedef MyDataFrame::ConstView MyDataFrameConstView;
+
+    const MyDataFrame       &const_df = df;
+    MyDataFrameView         df3 = df.get_view<double, int>({ "col_1", "col_4"});
+    MyDataFrameConstView    const_df3 = const_df.get_view<double, int>({ "col_1", "col_4"});
+
+    assert((! df3.has_column("col_2")));
+    assert((! df3.has_column("col_3")));
+    assert((df3.get_column<double>("col_1")[11] == 12));
+    assert((df3.get_column<int>("col_4")[8] == 2));
+    assert((df3.get_index()[3] == 123453));
+
+    df3.get_index()[3] = 100;
+    df3.get_column<int>("col_4")[8] = 101;
+    df3.get_column<double>("col_1")[11] = 102.2;
+
+    assert((df3.get_column<double>("col_1")[11] == 102.2));
+    assert((df3.get_column<int>("col_4")[8] == 101));
+    assert((df3.get_index()[3] == 100));
+    assert((df.get_column<double>("col_1")[11] == 102.2));
+    assert((df.get_column<int>("col_4")[8] == 101));
+    assert((df.get_index()[3] == 100));
+
+    assert((const_df3.get_column<double>("col_1")[11] == 102.2));
+    assert((const_df3.get_column<int>("col_4")[8] == 101));
+    assert((const_df3.get_index()[3] == 100));
+}
+
+ C++ DataFrame diff --git a/docs/HTML/get_data_by_idx.html b/docs/HTML/get_data_by_idx.html index c4ae478ad..e3e5c8ce8 100644 --- a/docs/HTML/get_data_by_idx.html +++ b/docs/HTML/get_data_by_idx.html @@ -70,12 +70,12 @@

 template<typename ... Ts>
-DataFrameView<I>
+View
 get_view_by_idx(Index2D<IndexType> range);
         
- It behaves like get_data_by_idx(range), but it returns a DataFrameView.
+ It behaves like get_data_by_idx(range), but it returns a View.
A view is a DataFrame that is a reference to the original DataFrame.
So if you modify anything in the view the original DataFrame will also be modified.
NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
@@ -91,12 +91,12 @@

 template<typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_idx(const std::vector<IndexType> &values);
         
- It behaves like get_data_by_idx(values), but it returns a DataFramePtrView.
+ It behaves like get_data_by_idx(values), but it returns a PtrView.
A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.
NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
NOTE: Views could not be const, becuase you can change original data through views.
@@ -111,7 +111,7 @@

 template<typename ... Ts>
-DataFrameConstView<I>
+ConstView
 get_view_by_idx(Index2D<IndexType> range) const;
         
@@ -128,7 +128,7 @@

 template<typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_idx(const std::vector<IndexType> &values) const;
         
@@ -143,184 +143,184 @@ -
static void test_get_view_by_idx_slicing()  {
-
-    std::cout << "\nTesting get_view_by_idx()/slicing ..." << std::endl;
-
-    std::vector<unsigned long>  idx =
-        { 123450, 123451, 123452, 123453, 123454, 123455, 123456,
-          123457, 123458, 123459, 123460, 123461, 123462, 123466 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21,
-                               0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 };
-    std::vector<int>    i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 };
-    MyDataFrame         df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", i1));
-
-    typedef DataFrameView<unsigned long> MyDataFrameView;
-    typedef DataFrameConstView<unsigned long> MyDataFrameConstView;
-
-    const MyDataFrame   &const_df = df;
-
-    MyDataFrame             df2 =
-        df.get_data_by_idx<double, int>(Index2D<MyDataFrame::IndexType> { 123452, 123460 });
-    MyDataFrameView         dfv =
-        df.get_view_by_idx<double, int>(Index2D<MyDataFrame::IndexType> { 123452, 123466 });
-    MyDataFrameConstView    dfcv =
-        const_df.get_view_by_idx<double, int>(Index2D<MyDataFrame::IndexType> { 123452, 123466 });
-
-    df.write<std::ostream, double, int>(std::cout);
-    df2.write<std::ostream, double, int>(std::cout);
-    dfv.write<std::ostream, double, int>(std::cout);
-
-    dfv.get_column<double>("col_3")[0] = 88.0;
-    assert(dfv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[2]);
-    assert(dfv.get_column<double>("col_3")[0] == 88.0);
-    assert(dfv.shape().first == 12);  // added
-    assert(dfcv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[2]);
-    assert(dfcv.get_column<double>("col_3")[0] == 88.0);
-    assert(dfcv.shape().first == 12);  // added
-}
-
-// -----------------------------------------------------------------------------
-
-static void test_get_data_by_idx_values()  {
-
-    std::cout << "\nTesting get_data_by_idx(values) ..." << std::endl;
-
-    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
-    std::vector<double> d4 = { 22, 23, 24, 25 };
-    MyDataFrame         df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", d4));
-
-    MyDataFrame df2 =
-        df.get_data_by_idx<double>(std::vector<MyDataFrame::IndexType> { 123452, 123455 });
-    MyDataFrame df3 =
-        df.get_data_by_idx<double>(std::vector<MyDataFrame::IndexType> { 123449, 123450 });
-
-    assert(df2.get_index().size() == 2);
-    assert(df2.get_column<double>("col_3").size() == 2);
-    assert(df2.get_column<double>("col_2").size() == 2);
-    assert(df2.get_index()[0] == 123452);
-    assert(df2.get_index()[1] == 123455);
-    assert(df2.get_column<double>("col_3")[0] == 17.0);
-    assert(df2.get_column<double>("col_2")[1] == 12.0);
-    assert(std::isnan(df2.get_column<double>("col_4")[1]));
-
-    assert(df3.get_index().size() == 4);
-    assert(df3.get_column<double>("col_3").size() == 4);
-    assert(df3.get_column<double>("col_2").size() == 4);
-    assert(df3.get_column<double>("col_1").size() == 4);
-    assert(df3.get_index()[0] == 123450);
-    assert(df3.get_index()[1] == 123450);
-    assert(df3.get_index()[2] == 123450);
-    assert(df3.get_index()[3] == 123449);
-    assert(df3.get_column<double>("col_1")[0] == 1.0);
-    assert(df3.get_column<double>("col_2")[2] == 13.0);
-    assert(df3.get_column<double>("col_4")[0] == 22.0);
-    assert(df3.get_column<double>("col_4")[1] == 25.0);
-    assert(std::isnan(df3.get_column<double>("col_4")[2]));
-    assert(std::isnan(df3.get_column<double>("col_4")[3]));
-}
-
-// ----------------------------------------------------------------------
-
-static void test_get_view_by_idx_values()  {
-
-    std::cout << "\nTesting get_view_by_idx(values) ..." << std::endl;
-
-    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
-    std::vector<double> d4 = { 22, 23, 24, 25 };
-    MyDataFrame         df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", d4));
-
-    const MyDataFrame   &const_df = df;
-
-    auto    dfv1 =
-        df.get_view_by_idx<double>(std::vector<MyDataFrame::IndexType> { 123452, 123455 });
-    auto    const_dfv1 =
-        const_df.get_view_by_idx<double>(std::vector<MyDataFrame::IndexType> { 123452, 123455 });
-    auto    dfv2 =
-        df.get_view_by_idx<double>(std::vector<MyDataFrame::IndexType> { 123449, 123450 });
-    auto    const_dfv2 =
-        const_df.get_view_by_idx<double>(std::vector<MyDataFrame::IndexType> { 123449, 123450 });
-
-    assert(dfv1.get_index().size() == 2);
-    assert(dfv1.get_column<double>("col_3").size() == 2);
-    assert(dfv1.get_column<double>("col_2").size() == 2);
-    assert(dfv1.get_index()[0] == 123452);
-    assert(dfv1.get_index()[1] == 123455);
-    assert(dfv1.get_column<double>("col_3")[0] == 17.0);
-    assert(dfv1.get_column<double>("col_2")[1] == 12.0);
-    assert(std::isnan(dfv1.get_column<double>("col_4")[1]));
-
-    assert(const_dfv1.get_index().size() == 2);
-    assert(const_dfv1.get_column<double>("col_3").size() == 2);
-    assert(const_dfv1.get_column<double>("col_2").size() == 2);
-    assert(const_dfv1.get_index()[0] == 123452);
-    assert(const_dfv1.get_index()[1] == 123455);
-    assert(const_dfv1.get_column<double>("col_3")[0] == 17.0);
-    assert(const_dfv1.get_column<double>("col_2")[1] == 12.0);
-    assert(std::isnan(const_dfv1.get_column<double>("col_4")[1]));
-
-    assert(dfv2.get_index().size() == 4);
-    assert(dfv2.get_column<double>("col_3").size() == 4);
-    assert(dfv2.get_column<double>("col_2").size() == 4);
-    assert(dfv2.get_column<double>("col_1").size() == 4);
-    assert(dfv2.get_index()[0] == 123450);
-    assert(dfv2.get_index()[1] == 123450);
-    assert(dfv2.get_index()[2] == 123450);
-    assert(dfv2.get_index()[3] == 123449);
-    assert(dfv2.get_column<double>("col_1")[0] == 1.0);
-    assert(dfv2.get_column<double>("col_2")[2] == 13.0);
-    assert(dfv2.get_column<double>("col_4")[0] == 22.0);
-    assert(dfv2.get_column<double>("col_4")[1] == 25.0);
-    assert(std::isnan(dfv2.get_column<double>("col_4")[2]));
-    assert(std::isnan(dfv2.get_column<double>("col_4")[3]));
-
-    assert(const_dfv2.get_index().size() == 4);
-    assert(const_dfv2.get_column<double>("col_3").size() == 4);
-    assert(const_dfv2.get_column<double>("col_2").size() == 4);
-    assert(const_dfv2.get_column<double>("col_1").size() == 4);
-    assert(const_dfv2.get_index()[0] == 123450);
-    assert(const_dfv2.get_index()[1] == 123450);
-    assert(const_dfv2.get_index()[2] == 123450);
-    assert(const_dfv2.get_index()[3] == 123449);
-    assert(const_dfv2.get_column<double>("col_1")[0] == 1.0);
-    assert(const_dfv2.get_column<double>("col_2")[2] == 13.0);
-    assert(const_dfv2.get_column<double>("col_4")[0] == 22.0);
-    assert(const_dfv2.get_column<double>("col_4")[1] == 25.0);
-    assert(std::isnan(const_dfv2.get_column<double>("col_4")[2]));
-    assert(std::isnan(const_dfv2.get_column<double>("col_4")[3]));
-
-    dfv2.get_column<double>("col_1")[0] = 101.0;
-    assert(dfv2.get_column<double>("col_1")[0] == 101.0);
-    assert(df.get_column<double>("col_1")[0] == 101.0);
-}
-
- +
static void test_get_view_by_idx_slicing()  {
+
+    std::cout << "\nTesting get_view_by_idx()/slicing ..." << std::endl;
+
+    StlVecType<unsigned long>  idx =
+        { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 };
+    StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 };
+    StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 };
+    StlVecType<int>    i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 };
+    MyDataFrame        df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", i1));
+
+    typedef MyDataFrame::View MyDataFrameView;
+    typedef MyDataFrame::ConstView MyDataFrameConstView;
+
+    const MyDataFrame   &const_df = df;
+
+    MyDataFrame             df2 =
+        df.get_data_by_idx<double, int>(Index2D<MyDataFrame::IndexType> { 123452, 123460 });
+    MyDataFrameView         dfv =
+        df.get_view_by_idx<double, int>(Index2D<MyDataFrame::IndexType> { 123452, 123466 });
+    MyDataFrameConstView    dfcv =
+        const_df.get_view_by_idx<double, int>(Index2D<MyDataFrame::IndexType> { 123452, 123466 });
+
+    df.write<std::ostream, double, int>(std::cout);
+    df2.write<std::ostream, double, int>(std::cout);
+    dfv.write<std::ostream, double, int>(std::cout);
+
+    dfv.get_column<double>("col_3")[0] = 88.0;
+    assert(dfv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[2]);
+    assert(dfv.get_column<double>("col_3")[0] == 88.0);
+    assert(dfv.shape().first == 12);  // added
+    assert(dfcv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[2]);
+    assert(dfcv.get_column<double>("col_3")[0] == 88.0);
+    assert(dfcv.shape().first == 12);  // added
+}
+
+// -----------------------------------------------------------------------------
+
+static void test_get_data_by_idx_values()  {
+
+    std::cout << "\nTesting get_data_by_idx(values) ..." << std::endl;
+
+    StlVecType<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
+    StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
+    StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
+    StlVecType<double> d4 = { 22, 23, 24, 25 };
+    MyDataFrame        df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", d4));
+
+    MyDataFrame df2 =
+        df.get_data_by_idx<double>( StlVecType<MyDataFrame::IndexType> { 123452, 123455 });
+    MyDataFrame df3 =
+        df.get_data_by_idx<double>( StlVecType<MyDataFrame::IndexType> { 123449, 123450 });
+
+    assert(df2.get_index().size() == 2);
+    assert(df2.get_column<double>("col_3").size() == 2);
+    assert(df2.get_column<double>("col_2").size() == 2);
+    assert(df2.get_index()[0] == 123452);
+    assert(df2.get_index()[1] == 123455);
+    assert(df2.get_column<double>("col_3")[0] == 17.0);
+    assert(df2.get_column<double>("col_2")[1] == 12.0);
+    assert(std::isnan(df2.get_column<double>("col_4")[1]));
+
+    assert(df3.get_index().size() == 4);
+    assert(df3.get_column<double>("col_3").size() == 4);
+    assert(df3.get_column<double>("col_2").size() == 4);
+    assert(df3.get_column<double>("col_1").size() == 4);
+    assert(df3.get_index()[0] == 123450);
+    assert(df3.get_index()[1] == 123450);
+    assert(df3.get_index()[2] == 123450);
+    assert(df3.get_index()[3] == 123449);
+    assert(df3.get_column<double>("col_1")[0] == 1.0);
+    assert(df3.get_column<double>("col_2")[2] == 13.0);
+    assert(df3.get_column<double>("col_4")[0] == 22.0);
+    assert(df3.get_column<double>("col_4")[1] == 25.0);
+    assert(std::isnan(df3.get_column<double>("col_4")[2]));
+    assert(std::isnan(df3.get_column<double>("col_4")[3]));
+}
+
+// -----------------------------------------------------------------------------
+
+static void test_get_view_by_idx_values()  {
+
+    std::cout << "\nTesting get_view_by_idx(values) ..." << std::endl;
+
+    StlVecType<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
+    StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
+    StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
+    StlVecType<double> d4 = { 22, 23, 24, 25 };
+    MyDataFrame        df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", d4));
+
+    const MyDataFrame   &const_df = df;
+
+    auto    dfv1 =
+        df.get_view_by_idx<double>(StlVecType<MyDataFrame::IndexType> { 123452, 123455 });
+    auto    const_dfv1 =
+        const_df.get_view_by_idx<double>(StlVecType<MyDataFrame::IndexType> { 123452, 123455 });
+    auto    dfv2 =
+        df.get_view_by_idx<double>(StlVecType<MyDataFrame::IndexType> { 123449, 123450 });
+    auto    const_dfv2 =
+        const_df.get_view_by_idx<double>(StlVecType<MyDataFrame::IndexType> { 123449, 123450 });
+
+    assert(dfv1.get_index().size() == 2);
+    assert(dfv1.get_column<double>("col_3").size() == 2);
+    assert(dfv1.get_column<double>("col_2").size() == 2);
+    assert(dfv1.get_index()[0] == 123452);
+    assert(dfv1.get_index()[1] == 123455);
+    assert(dfv1.get_column<double>("col_3")[0] == 17.0);
+    assert(dfv1.get_column<double>("col_2")[1] == 12.0);
+    assert(std::isnan(dfv1.get_column<double>("col_4")[1]));
+
+    assert(const_dfv1.get_index().size() == 2);
+    assert(const_dfv1.get_column<double>("col_3").size() == 2);
+    assert(const_dfv1.get_column<double>("col_2").size() == 2);
+    assert(const_dfv1.get_index()[0] == 123452);
+    assert(const_dfv1.get_index()[1] == 123455);
+    assert(const_dfv1.get_column<double>("col_3")[0] == 17.0);
+    assert(const_dfv1.get_column<double>("col_2")[1] == 12.0);
+    assert(std::isnan(const_dfv1.get_column<double>("col_4")[1]));
+
+    assert(dfv2.get_index().size() == 4);
+    assert(dfv2.get_column<double>("col_3").size() == 4);
+    assert(dfv2.get_column<double>("col_2").size() == 4);
+    assert(dfv2.get_column<double>("col_1").size() == 4);
+    assert(dfv2.get_index()[0] == 123450);
+    assert(dfv2.get_index()[1] == 123450);
+    assert(dfv2.get_index()[2] == 123450);
+    assert(dfv2.get_index()[3] == 123449);
+    assert(dfv2.get_column<double>("col_1")[0] == 1.0);
+    assert(dfv2.get_column<double>("col_2")[2] == 13.0);
+    assert(dfv2.get_column<double>("col_4")[0] == 22.0);
+    assert(dfv2.get_column<double>("col_4")[1] == 25.0);
+    assert(std::isnan(dfv2.get_column<double>("col_4")[2]));
+    assert(std::isnan(dfv2.get_column<double>("col_4")[3]));
+
+    assert(const_dfv2.get_index().size() == 4);
+    assert(const_dfv2.get_column<double>("col_3").size() == 4);
+    assert(const_dfv2.get_column<double>("col_2").size() == 4);
+    assert(const_dfv2.get_column<double>("col_1").size() == 4);
+    assert(const_dfv2.get_index()[0] == 123450);
+    assert(const_dfv2.get_index()[1] == 123450);
+    assert(const_dfv2.get_index()[2] == 123450);
+    assert(const_dfv2.get_index()[3] == 123449);
+    assert(const_dfv2.get_column<double>("col_1")[0] == 1.0);
+    assert(const_dfv2.get_column<double>("col_2")[2] == 13.0);
+    assert(const_dfv2.get_column<double>("col_4")[0] == 22.0);
+    assert(const_dfv2.get_column<double>("col_4")[1] == 25.0);
+    assert(std::isnan(const_dfv2.get_column<double>("col_4")[2]));
+    assert(std::isnan(const_dfv2.get_column<double>("col_4")[3]));
+
+    dfv2.get_column<double>("col_1")[0] = 101.0;
+    assert(dfv2.get_column<double>("col_1")[0] == 101.0);
+    assert(df.get_column<double>("col_1")[0] == 101.0);
+}
+
+
+
+ C++ DataFrame diff --git a/docs/HTML/get_data_by_loc.html b/docs/HTML/get_data_by_loc.html index 82808a508..e88f0b613 100644 --- a/docs/HTML/get_data_by_loc.html +++ b/docs/HTML/get_data_by_loc.html @@ -35,7 +35,7 @@

 template<typename ... Ts>
-DataFrame
+DataFrame<I, H>
 get_data_by_loc(Index2D<long> range) const;
         
@@ -53,7 +53,7 @@

 template<typename ... Ts>
-DataFrame<
+DataFrame<I, H>
 get_data_by_loc(const std::vector<long> &locations) const;
         
@@ -72,12 +72,12 @@

 template<typename ... Ts>
-DataFrameView<I>
+View
 get_view_by_loc(Index2D<long> range);
         
- It behaves like get_data_by_loc(), but it returns a DataFrameView.
+ It behaves like get_data_by_loc(), but it returns a View.
A view is a DataFrame that is a reference to the original DataFrame.
So if you modify anything in the view the original DataFrame will also be modified.
NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
@@ -93,12 +93,12 @@

 template<typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_loc(const std::vector<long> &locations);
         
- It behaves like get_data_by_loc(locations), but it returns a DataFramePtrView.
+ It behaves like get_data_by_loc(locations), but it returns a PtrView.
A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.
NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
NOTE: Views could not be const, becuase you can change original data through views.
@@ -113,7 +113,7 @@

 template<typename ... Ts>
-DataFrameConstView<I>
+ConstView
 get_view_by_loc(Index2D<long> range) const;
         
@@ -130,7 +130,7 @@

 template<typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_loc(const std::vector<long> &locations) const;
         
@@ -145,226 +145,223 @@ -
static void test_get_data_by_loc_slicing()  {
-
-    std::cout << "\nTesting get_data_by_loc()/slicing ..." << std::endl;
-
-    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
-    std::vector<double> d4 = { 22, 23, 24, 25 };
-    MyDataFrame         df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", d4));
-
-    MyDataFrame df2 = df.get_data_by_loc<double>(Index2D<long> { 3, 6 });
-    MyDataFrame df3 = df.get_data_by_loc<double>(Index2D<long> { 0, 7 });
-    MyDataFrame df4 = df.get_data_by_loc<double>(Index2D<long> { -4, -1 });
-    MyDataFrame df5 = df.get_data_by_loc<double>(Index2D<long> { -4, 6 });
-
-    df.write<std::ostream, double>(std::cout);
-    df2.write<std::ostream, double>(std::cout);
-    df3.write<std::ostream, double>(std::cout);
-    df4.write<std::ostream, double>(std::cout);
-    df5.write<std::ostream, double>(std::cout);
-
-    try  {
-        MyDataFrame df2 = df.get_data_by_loc<double>(Index2D<long> { 3, 8 });
-    }
-    catch (const BadRange &ex)  {
-        std::cout << "Caught: " << ex.what() << std::endl;
-    }
-    try  {
-        MyDataFrame df2 = df.get_data_by_loc<double>(Index2D<long> { -8, -1 });
-    }
-    catch (const BadRange &ex)  {
-        std::cout << "Caught: " << ex.what() << std::endl;
-    }
-}
-
-// -----------------------------------------------------------------------------
-
-static void test_get_view_by_loc()  {
-
-    std::cout << "\nTesting get_view_by_loc() ..." << std::endl;
-
-    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
-    std::vector<double>         d1 = { 1, 2, 3, 4, 5, 6, 7 };
-    std::vector<double>         d2 = { 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double>         d3 = { 15, 16, 17, 18, 19, 20, 21 };
-    std::vector<double>         d4 = { 22, 23, 24, 25 };
-    std::vector<std::string>    s1 = { "11", "22", "33", "xx", "yy", "gg", "string" };
-    MyDataFrame                 df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", d4),
-                 std::make_pair("col_str", s1));
-
-    auto  memory_use1 = df.get_memory_usage<double>("col_3");
-
-    std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl;
-
-    typedef DataFrameView<unsigned long> MyDataFrameView;
-    typedef DataFrameConstView<unsigned long> MyDataFrameConstView;
-
-    const MyDataFrame   &const_df = df;
-    MyDataFrameView         dfv =
-        df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });
-    MyDataFrameView         dfv2 =
-        df.get_view_by_loc<double, std::string>(Index2D<long> { -5, -1 });
-    MyDataFrameConstView    dfcv =
-        const_df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });
-    MyDataFrameConstView    dfcv2 =
-        const_df.get_view_by_loc<double, std::string>(Index2D<long> { -5, -1 });
-
-    dfv.shrink_to_fit<double, std::string>();
-    dfv.write<std::ostream, double, std::string>(std::cout);
-    dfv2.write<std::ostream, double, std::string>(std::cout);
-    dfv.get_column<double>("col_3")[0] = 88.0;
-    assert(dfv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[3]);
-    assert(dfv.get_column<double>("col_3")[0] == 88.0);
-    assert(dfcv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[3]);
-    assert(dfcv.get_column<double>("col_3")[0] == 88.0);
-
-    auto  memory_use2 = dfv.get_memory_usage<double>("col_3");
-
-    std::cout << "View Memory Usage:\n" << memory_use2 << std::endl;
-}
-
-// -----------------------------------------------------------------------------
-
-static void test_get_data_by_loc_location()  {
-
-    std::cout << "\nTesting get_data_by_loc(locations) ..." << std::endl;
-
-    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
-    std::vector<double> d4 = { 22, 23, 24, 25 };
-    MyDataFrame         df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", d4));
-
-    MyDataFrame df2 = df.get_data_by_loc<double>(std::vector<long> { 3, 6 });
-    MyDataFrame df3 = df.get_data_by_loc<double>(std::vector<long> { -4, -1 , 5 });
-
-    assert(df2.get_index().size() == 2);
-    assert(df2.get_column<double>("col_3").size() == 2);
-    assert(df2.get_column<double>("col_2").size() == 2);
-    assert(df2.get_index()[0] == 123450);
-    assert(df2.get_index()[1] == 123449);
-    assert(df2.get_column<double>("col_3")[0] == 18.0);
-    assert(df2.get_column<double>("col_2")[1] == 14.0);
-    assert(std::isnan(df2.get_column<double>("col_4")[1]));
-
-    assert(df3.get_index().size() == 3);
-    assert(df3.get_column<double>("col_3").size() == 3);
-    assert(df3.get_column<double>("col_2").size() == 3);
-    assert(df3.get_column<double>("col_1").size() == 3);
-    assert(df3.get_index()[0] == 123450);
-    assert(df3.get_index()[1] == 123449);
-    assert(df3.get_index()[2] == 123450);
-    assert(df3.get_column<double>("col_1")[0] == 4.0);
-    assert(df3.get_column<double>("col_2")[2] == 13.0);
-    assert(df3.get_column<double>("col_4")[0] == 25.0);
-    assert(std::isnan(df3.get_column<double>("col_4")[1]));
-    assert(std::isnan(df3.get_column<double>("col_4")[2]));
-}
-
-// -----------------------------------------------------------------------------
-
-static void test_get_view_by_loc_location()  {
-
-    std::cout << "\nTesting get_view_by_loc(locations) ..." << std::endl;
-
-    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
-    std::vector<double> d4 = { 22, 23, 24, 25 };
-    MyDataFrame         df;
-
-    df.load_data(std::move(idx),
-                 std::make_pair("col_1", d1),
-                 std::make_pair("col_2", d2),
-                 std::make_pair("col_3", d3),
-                 std::make_pair("col_4", d4));
-
-    const MyDataFrame   &const_df = df;
-
-    auto    dfv1 = df.get_view_by_loc<double>(std::vector<long> { 3, 6 });
-    auto    dfv2 = df.get_view_by_loc<double>(std::vector<long> { -4, -1 , 5 });
-    auto    const_dfv1 = const_df.get_view_by_loc<double>(std::vector<long> { 3, 6 });
-    auto    const_dfv2 = const_df.get_view_by_loc<double>(std::vector<long> { -4, -1 , 5 });
-
-    assert(dfv1.get_index().size() == 2);
-    assert(dfv1.get_column<double>("col_3").size() == 2);
-    assert(dfv1.get_column<double>("col_2").size() == 2);
-    assert(dfv1.get_index()[0] == 123450);
-    assert(dfv1.get_index()[1] == 123449);
-    assert(dfv1.get_column<double>("col_3")[0] == 18.0);
-    assert(dfv1.get_column<double>("col_2")[1] == 14.0);
-    assert(std::isnan(dfv1.get_column<double>("col_4")[1]));
-
-    assert(const_dfv1.get_index().size() == 2);
-    assert(const_dfv1.get_column<double>("col_3").size() == 2);
-    assert(const_dfv1.get_column<double>("col_2").size() == 2);
-    assert(const_dfv1.get_index()[0] == 123450);
-    assert(const_dfv1.get_index()[1] == 123449);
-    assert(const_dfv1.get_column<double>("col_3")[0] == 18.0);
-    assert(const_dfv1.get_column<double>("col_2")[1] == 14.0);
-    assert(std::isnan(const_dfv1.get_column<double>("col_4")[1]));
-
-    assert(dfv2.get_index().size() == 3);
-    assert(dfv2.get_column<double>("col_3").size() == 3);
-    assert(dfv2.get_column<double>("col_2").size() == 3);
-    assert(dfv2.get_column<double>("col_1").size() == 3);
-    assert(dfv2.get_index()[0] == 123450);
-    assert(dfv2.get_index()[1] == 123449);
-    assert(dfv2.get_index()[2] == 123450);
-    assert(dfv2.get_column<double>("col_1")[0] == 4.0);
-    assert(dfv2.get_column<double>("col_2")[2] == 13.0);
-    assert(dfv2.get_column<double>("col_4")[0] == 25.0);
-    assert(std::isnan(dfv2.get_column<double>("col_4")[1]));
-    assert(std::isnan(dfv2.get_column<double>("col_4")[2]));
-
-    assert(const_dfv2.get_index().size() == 3);
-    assert(const_dfv2.get_column<double>("col_3").size() == 3);
-    assert(const_dfv2.get_column<double>("col_2").size() == 3);
-    assert(const_dfv2.get_column<double>("col_1").size() == 3);
-    assert(const_dfv2.get_index()[0] == 123450);
-    assert(const_dfv2.get_index()[1] == 123449);
-    assert(const_dfv2.get_index()[2] == 123450);
-    assert(const_dfv2.get_column<double>("col_1")[0] == 4.0);
-    assert(const_dfv2.get_column<double>("col_2")[2] == 13.0);
-    assert(const_dfv2.get_column<double>("col_4")[0] == 25.0);
-    assert(std::isnan(const_dfv2.get_column<double>("col_4")[1]));
-    assert(std::isnan(const_dfv2.get_column<double>("col_4")[2]));
-
-    dfv2.get_column<double>("col_1")[0] = 101.0;
-    assert(dfv2.get_column<double>("col_1")[0] == 101.0);
-    assert(const_dfv2.get_column<double>("col_1")[0] == 101.0);
-    assert(df.get_column<double>("col_1")[3] == 101.0);
-
-    auto  memory_use = dfv2.get_memory_usage<double>("col_3");
-
-    std::cout << "View Memory Usage:\n" << memory_use << std::endl;
-}
-
- +
static void test_get_data_by_loc_slicing()  {
+
+    std::cout << "\nTesting get_data_by_loc()/slicing ..." << std::endl;
+
+    StlVecType<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
+    StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
+    StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
+    StlVecType<double> d4 = { 22, 23, 24, 25 };
+    MyDataFrame        df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", d4));
+
+    MyDataFrame df2 = df.get_data_by_loc<double>(Index2D<long> { 3, 6 });
+    MyDataFrame df3 = df.get_data_by_loc<double>(Index2D<long> { 0, 7 });
+    MyDataFrame df4 = df.get_data_by_loc<double>(Index2D<long> { -4, -1 });
+    MyDataFrame df5 = df.get_data_by_loc<double>(Index2D<long> { -4, 6 });
+
+    df.write<std::ostream, double>(std::cout);
+    df2.write<std::ostream, double>(std::cout);
+    df3.write<std::ostream, double>(std::cout);
+    df4.write<std::ostream, double>(std::cout);
+    df5.write<std::ostream, double>(std::cout);
+
+    try  {
+        MyDataFrame df2 = df.get_data_by_loc<double>(Index2D<long> { 3, 8 });
+    }
+    catch (const BadRange &ex)  {
+        std::cout << "Caught: " << ex.what() << std::endl;
+    }
+    try  {
+        MyDataFrame df2 = df.get_data_by_loc<double>(Index2D<long> { -8, -1 });
+    }
+    catch (const BadRange &ex)  {
+        std::cout << "Caught: " << ex.what() << std::endl;
+    }
+}
+
+// -----------------------------------------------------------------------------
+
+static void test_get_view_by_loc()  {
+
+    std::cout << "\nTesting get_view_by_loc() ..." << std::endl;
+
+    StlVecType<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
+    StlVecType<double>         d1 = { 1, 2, 3, 4, 5, 6, 7 };
+    StlVecType<double>         d2 = { 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double>         d3 = { 15, 16, 17, 18, 19, 20, 21 };
+    StlVecType<double>         d4 = { 22, 23, 24, 25 };
+    StlVecType<std::string>    s1 = { "11", "22", "33", "xx", "yy", "gg", "string" };
+    MyDataFrame                df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", d4),
+                 std::make_pair("col_str", s1));
+
+    auto  memory_use1 = df.get_memory_usage<double>("col_3");
+
+    std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl;
+
+    typedef MyDataFrame::View MyDataFrameView;
+    typedef MyDataFrame::ConstView MyDataFrameConstView;
+
+    const MyDataFrame       &const_df = df;
+    MyDataFrameView         dfv = df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });
+    MyDataFrameView         dfv2 = df.get_view_by_loc<double, std::string>(Index2D<long> { -5, -1 });
+    MyDataFrameConstView    dfcv = const_df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });
+    MyDataFrameConstView    dfcv2 = const_df.get_view_by_loc<double, std::string>(Index2D<long> { -5, -1 });
+
+    dfv.shrink_to_fit<double, std::string>();
+    dfv.write<std::ostream, double, std::string>(std::cout);
+    dfv2.write<std::ostream, double, std::string>(std::cout);
+    dfv.get_column<double>("col_3")[0] = 88.0;
+    assert(dfv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[3]);
+    assert(dfv.get_column<double>("col_3")[0] == 88.0);
+    assert(dfcv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[3]);
+    assert(dfcv.get_column<double>("col_3")[0] == 88.0);
+
+    auto  memory_use2 = dfv.get_memory_usage<double>("col_3");
+
+    std::cout << "View Memory Usage:\n" << memory_use2 << std::endl;
+}
+
+// -----------------------------------------------------------------------------
+
+static void test_get_data_by_loc_location()  {
+
+    std::cout << "\nTesting get_data_by_loc(locations) ..." << std::endl;
+
+    StlVecType<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
+    StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
+    StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
+    StlVecType<double> d4 = { 22, 23, 24, 25 };
+    MyDataFrame        df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", d4));
+
+    MyDataFrame df2 = df.get_data_by_loc<double>(StlVecType<long> { 3, 6 });
+    MyDataFrame df3 = df.get_data_by_loc<double>(StlVecType<long> { -4, -1 , 5 });
+
+    assert(df2.get_index().size() == 2);
+    assert(df2.get_column<double>("col_3").size() == 2);
+    assert(df2.get_column<double>("col_2").size() == 2);
+    assert(df2.get_index()[0] == 123450);
+    assert(df2.get_index()[1] == 123449);
+    assert(df2.get_column<double>("col_3")[0] == 18.0);
+    assert(df2.get_column<double>("col_2")[1] == 14.0);
+    assert(std::isnan(df2.get_column<double>("col_4")[1]));
+
+    assert(df3.get_index().size() == 3);
+    assert(df3.get_column<double>("col_3").size() == 3);
+    assert(df3.get_column<double>("col_2").size() == 3);
+    assert(df3.get_column<double>("col_1").size() == 3);
+    assert(df3.get_index()[0] == 123450);
+    assert(df3.get_index()[1] == 123449);
+    assert(df3.get_index()[2] == 123450);
+    assert(df3.get_column<double>("col_1")[0] == 4.0);
+    assert(df3.get_column<double>("col_2")[2] == 13.0);
+    assert(df3.get_column<double>("col_4")[0] == 25.0);
+    assert(std::isnan(df3.get_column<double>("col_4")[1]));
+    assert(std::isnan(df3.get_column<double>("col_4")[2]));
+}
+
+// -----------------------------------------------------------------------------
+
+static void test_get_view_by_loc_location()  {
+
+    std::cout << "\nTesting get_view_by_loc(locations) ..." << std::endl;
+
+    StlVecType<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
+    StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
+    StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
+    StlVecType<double> d4 = { 22, 23, 24, 25 };
+    MyDataFrame        df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", d4));
+
+    const MyDataFrame   &const_df = df;
+
+    auto    dfv1 = df.get_view_by_loc<double>(StlVecType<long> { 3, 6 });
+    auto    dfv2 = df.get_view_by_loc<double>(StlVecType<long> { -4, -1 , 5 });
+    auto    const_dfv1 = const_df.get_view_by_loc<double>(StlVecType<long> { 3, 6 });
+    auto    const_dfv2 = const_df.get_view_by_loc<double>(StlVecType<long> { -4, -1 , 5 });
+
+    assert(dfv1.get_index().size() == 2);
+    assert(dfv1.get_column<double>("col_3").size() == 2);
+    assert(dfv1.get_column<double>("col_2").size() == 2);
+    assert(dfv1.get_index()[0] == 123450);
+    assert(dfv1.get_index()[1] == 123449);
+    assert(dfv1.get_column<double>("col_3")[0] == 18.0);
+    assert(dfv1.get_column<double>("col_2")[1] == 14.0);
+    assert(std::isnan(dfv1.get_column<double>("col_4")[1]));
+
+    assert(const_dfv1.get_index().size() == 2);
+    assert(const_dfv1.get_column<double>("col_3").size() == 2);
+    assert(const_dfv1.get_column<double>("col_2").size() == 2);
+    assert(const_dfv1.get_index()[0] == 123450);
+    assert(const_dfv1.get_index()[1] == 123449);
+    assert(const_dfv1.get_column<double>("col_3")[0] == 18.0);
+    assert(const_dfv1.get_column<double>("col_2")[1] == 14.0);
+    assert(std::isnan(const_dfv1.get_column<double>("col_4")[1]));
+
+    assert(dfv2.get_index().size() == 3);
+    assert(dfv2.get_column<double>("col_3").size() == 3);
+    assert(dfv2.get_column<double>("col_2").size() == 3);
+    assert(dfv2.get_column<double>("col_1").size() == 3);
+    assert(dfv2.get_index()[0] == 123450);
+    assert(dfv2.get_index()[1] == 123449);
+    assert(dfv2.get_index()[2] == 123450);
+    assert(dfv2.get_column<double>("col_1")[0] == 4.0);
+    assert(dfv2.get_column<double>("col_2")[2] == 13.0);
+    assert(dfv2.get_column<double>("col_4")[0] == 25.0);
+    assert(std::isnan(dfv2.get_column<double>("col_4")[1]));
+    assert(std::isnan(dfv2.get_column<double>("col_4")[2]));
+
+    assert(const_dfv2.get_index().size() == 3);
+    assert(const_dfv2.get_column<double>("col_3").size() == 3);
+    assert(const_dfv2.get_column<double>("col_2").size() == 3);
+    assert(const_dfv2.get_column<double>("col_1").size() == 3);
+    assert(const_dfv2.get_index()[0] == 123450);
+    assert(const_dfv2.get_index()[1] == 123449);
+    assert(const_dfv2.get_index()[2] == 123450);
+    assert(const_dfv2.get_column<double>("col_1")[0] == 4.0);
+    assert(const_dfv2.get_column<double>("col_2")[2] == 13.0);
+    assert(const_dfv2.get_column<double>("col_4")[0] == 25.0);
+    assert(std::isnan(const_dfv2.get_column<double>("col_4")[1]));
+    assert(std::isnan(const_dfv2.get_column<double>("col_4")[2]));
+
+    dfv2.get_column<double>("col_1")[0] = 101.0;
+    assert(dfv2.get_column<double>("col_1")[0] == 101.0);
+    assert(const_dfv2.get_column<double>("col_1")[0] == 101.0);
+    assert(df.get_column<double>("col_1")[3] == 101.0);
+
+    auto  memory_use = dfv2.get_memory_usage<double>("col_3");
+
+    std::cout << "View Memory Usage:\n" << memory_use << std::endl;
+}
+
+ + C++ DataFrame diff --git a/docs/HTML/get_data_by_rand.html b/docs/HTML/get_data_by_rand.html index d3e62fd44..205b3e7ef 100644 --- a/docs/HTML/get_data_by_rand.html +++ b/docs/HTML/get_data_by_rand.html @@ -63,7 +63,7 @@

 template<typename ... Ts>
-DataFrame<I>
+DataFrame<I, H>
 get_data_by_rand(random_policy spec,
                  double n,
                  std::size_t seed = 0) const;
@@ -86,14 +86,14 @@
        
         

 template<typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_rand(random_policy spec,
                  double n,
                  std::size_t seed = 0);
         
- It behaves like get_data_by_rand(), but it returns a DataFrameView. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.
+ It behaves like get_data_by_rand(), but it returns a View. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.
NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
NOTE: The columns in the result are not padded with NaN.
NOTE: Views could not be const, becuase you can change original data through views.
@@ -110,7 +110,7 @@

 template<typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_rand(random_policy spec,
                  double n,
                  std::size_t seed = 0) const;
diff --git a/docs/HTML/get_data_by_sel.html b/docs/HTML/get_data_by_sel.html
index d5c179e2c..745a4a001 100644
--- a/docs/HTML/get_data_by_sel.html
+++ b/docs/HTML/get_data_by_sel.html
@@ -62,7 +62,7 @@
        
         

 template<typename T, typename F, typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_sel(const char *name,
                 F &sel_functor);
         
@@ -90,7 +90,7 @@

 template<typename T, typename F, typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_sel(const char *name,
                 F &sel_functor) const;
         
@@ -141,7 +141,7 @@

 template<typename T1, typename T2, typename F,
           typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 F &sel_functor);
@@ -172,7 +172,7 @@
         

 template<typename T1, typename T2, typename F,
           typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 F &sel_functor) const;
@@ -229,7 +229,7 @@
         

 template<typename T1, typename T2, typename T3,
          typename F, typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 const char *name3,
@@ -263,7 +263,7 @@
         

 template<typename T1, typename T2, typename T3,
          typename F, typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 const char *name3,
@@ -328,7 +328,7 @@
 template<typename T1, typename T2,
          typename T3, typename T4,
          typename F, typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 const char *name3,
@@ -366,7 +366,7 @@
 template<typename T1, typename T2,
          typename T3, typename T4,
          typename F, typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 const char *name3,
@@ -440,7 +440,7 @@
          typename T3, typename T4,
          typename T5,
          typename F, typename ... Ts>
-DataFramePtrView<I>
+PtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 const char *name3,
@@ -482,7 +482,7 @@
          typename T3, typename T4,
          typename T5,
          typename F, typename ... Ts>
-DataFrameConstPtrView<I>
+ConstPtrView
 get_view_by_sel(const char *name1,
                 const char *name2,
                 const char *name3,
diff --git a/docs/HTML/get_memory_usage.html b/docs/HTML/get_memory_usage.html
index 07e5393eb..882c9e206 100644
--- a/docs/HTML/get_memory_usage.html
+++ b/docs/HTML/get_memory_usage.html
@@ -85,17 +85,17 @@
 
   
 
-  
static void test_get_view_by_loc()  {
+
static void test_get_view_by_loc()  {
 
     std::cout << "\nTesting get_view_by_loc() ..." << std::endl;
 
-    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
-    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
-    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
-    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
-    std::vector<double> d4 = { 22, 23, 24, 25 };
-    std::vector<std::string> s1 = { "11", "22", "33", "xx", "yy", "gg", "string" };
-    MyDataFrame         df;
+    StlVecType<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
+    StlVecType<double>         d1 = { 1, 2, 3, 4, 5, 6, 7 };
+    StlVecType<double>         d2 = { 8, 9, 10, 11, 12, 13, 14 };
+    StlVecType<double>         d3 = { 15, 16, 17, 18, 19, 20, 21 };
+    StlVecType<double>         d4 = { 22, 23, 24, 25 };
+    StlVecType<std::string>    s1 = { "11", "22", "33", "xx", "yy", "gg", "string" };
+    MyDataFrame                 df;
 
     df.load_data(std::move(idx),
                  std::make_pair("col_1", d1),
@@ -108,22 +108,30 @@
 
     std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl;
 
-    typedef DataFrameView<unsigned long> MyDataFrameView;
+    typedef MyDataFrame::View MyDataFrameView;
+    typedef MyDataFrame::ConstView MyDataFrameConstView;
 
-    MyDataFrameView dfv = df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });
+    const MyDataFrame     &const_df = df;
+    MyDataFrameView       dfv = df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });
+    MyDataFrameView       dfv2 = df.get_view_by_loc<double, std::string>(Index2D<long> { -5, -1 });
+    MyDataFrameConstView  dfcv = const_df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });
+    MyDataFrameConstView  dfcv2 = const_df.get_view_by_loc<double, std::string>(Index2D<long> { -5, -1 });
 
     dfv.shrink_to_fit<double, std::string>();
     dfv.write<std::ostream, double, std::string>(std::cout);
+    dfv2.write<std::ostream, double, std::string>(std::cout);
     dfv.get_column<double>("col_3")[0] = 88.0;
     assert(dfv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[3]);
     assert(dfv.get_column<double>("col_3")[0] == 88.0);
+    assert(dfcv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[3]);
+    assert(dfcv.get_column<double>("col_3")[0] == 88.0);
 
     auto  memory_use2 = dfv.get_memory_usage<double>("col_3");
 
     std::cout << "View Memory Usage:\n" << memory_use2 << std::endl;
 }
 
- + C++ DataFrame diff --git a/docs/HTML/get_reindexed.html b/docs/HTML/get_reindexed.html index 3c47a37b9..f45a8c973 100644 --- a/docs/HTML/get_reindexed.html +++ b/docs/HTML/get_reindexed.html @@ -34,7 +34,7 @@

 template<typename T, typename ... Ts>
-StdDataFrame<T>
+DataFrame<T, H>
 get_reindexed(const char *col_to_be_index,
               const char *old_index_name = nullptr) const;
         
@@ -56,7 +56,7 @@

 template<typename T, typename ... Ts>
-DataFrameView<T>
+typename DataFrame<T, H>::View
 get_reindexed_view(const char *col_to_be_index,
                    const char *old_index_name = nullptr);
         
@@ -78,7 +78,7 @@

 template<typename T, typename ... Ts>
-DataFrameConstView<T>
+typename DataFrame<T, H>::ConstView
 get_reindexed_view(const char *col_to_be_index,
                    const char *old_index_name = nullptr) const;
         
diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index ec6d92ce1..7c9626d18 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -1375,7 +1375,7 @@ class DataFrame : public ThreadGranularity { // concatenated // template - [[nodiscard]] DataFrame> + [[nodiscard]] DataFrame concat(const RHS_T &rhs, concat_policy cp = concat_policy::all_columns) const; @@ -2415,7 +2415,7 @@ class DataFrame : public ThreadGranularity { // the result as a column. // template - [[nodiscard]] DataFrame> + [[nodiscard]] DataFrame get_reindexed(const char *col_to_be_index, const char *old_index_name = nullptr) const; diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index f2cc88d4b..4f382633c 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -2155,7 +2155,7 @@ get_view(const StlVecType &col_names) const { template template -DataFrame> DataFrame:: +DataFrame DataFrame:: get_reindexed(const char *col_to_be_index, const char *old_index_name) const { DataFrame> result; diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index 44fa94464..c005621ff 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -683,7 +683,7 @@ DataFrame::self_concat(const RHS_T &rhs, bool add_new_columns) { template template -DataFrame> +DataFrame DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { static_assert( From c9010040a84ce00355f3e49698da1c0c8b924d51 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 1 Jan 2023 12:41:56 -0500 Subject: [PATCH 23/25] Adjusted docs for aligned memory allocator 4 + code clean up --- docs/HTML/DataFrameTypes.html | 378 ++++++++++++++++++ include/DataFrame/DataFrame.h | 16 +- include/DataFrame/Internals/DataFrame.tcc | 4 +- include/DataFrame/Internals/DataFrame_get.tcc | 6 +- .../DataFrame/Internals/DataFrame_join.tcc | 4 +- 5 files changed, 392 insertions(+), 16 deletions(-) create mode 100644 docs/HTML/DataFrameTypes.html diff --git a/docs/HTML/DataFrameTypes.html b/docs/HTML/DataFrameTypes.html new file mode 100644 index 000000000..589afcec7 --- /dev/null +++ b/docs/HTML/DataFrameTypes.html @@ -0,0 +1,378 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DataFrame Instance
Public Types
Description
+

+align_value
+        
+        
+
+ An integer value specifying the byte alignment boundary in memory allocation for the DataFrame type.
+
+

+template<typename T>
+AllocatorType
+        
+        
+
+ Type of allocator used to allocate memory for this type of DataFrame.
+ It is either std::allocator or a custom allocator to allocate memory on custom byte boundaries.
+
+

+size_type
+        
+        
+
+ std::size_t
+
+

+IndexType
+        
+        
+
+ Index column type for this DataFrame
+
+

+IndexVecType
+        
+        
+
+ Type of vector used for the index column. It is either a std::vector or one of the vector views depending on whether this is a DataFrame or a DataFrame view.
+ Also, the allocator depends on the align_value.
+
+

+View
+        
+        
+
+ A DataFrame view. This is a view on a contiguous slice of another DataFrane of the same type.
+ You can read and change data in this view.
+
+

+ConstView
+        
+        
+
+ A const DataFrame view. This is a view on a contiguous slice of another DataFrane of the same type.
+ This is a read-only view.
+
+

+PtrView
+        
+        
+
+ A DataFrame view. This is a view on a disjoined slice of another DataFrane of the same type.
+ You can read and change data in this view.
+
+

+ConstPtrView
+        
+        
+
+ A const DataFrame view. This is a view on a disjoined slice of another DataFrane of the same type.
+ This is a read-only view.
+
+

+template<typename T>
+ColumnVecType
+        
+        
+
+ Type of vector used for data columns. It is either a std::vector or one of the vector views depending on whether this is a DataFrame or a DataFrame view.
+ Also, the allocator depends on the align_value.
+
+

+template<typename T>
+StlVecType
+        
+        
+
+ An stl::vector type with an allocator that is compatible with this DataFrame type.
+
Library-wide
Types
Description
+

+template<typename T>
+struct Index2D  {
+    T   begin {};
+    T   end {};
+};
+        
+        
+
+ It represents a range with begin and end within a continuous memory space
+
+

+template<typename T>
+StdDataFrame
+        
+        
+
+ A DataFrame with index type I that uses system default byte boundary for memory allocations.
+
+

+template<typename T>
+StdDataFrame64
+        
+        
+
+ A DataFrame with index type I that uses 64 bytes boundary for memory allocations.
+
+

+template<typename T>
+StdDataFrame128
+        
+        
+
+ A DataFrame with index type I that uses 128 bytes boundary for memory allocations.
+
+

+template<typename T>
+StdDataFrame256
+        
+        
+
+ A DataFrame with index type I that uses 256 bytes boundary for memory allocations.
+
+

+template<typename T>
+StdDataFrame512
+        
+        
+
+ A DataFrame with index type I that uses 512 bytes boundary for memory allocations.
+
+

+template<typename T>
+StdDataFrame1024
+        
+        
+
+ A DataFrame with index type I that uses 1024 bytes boundary for memory allocations.
+
+

+DF_INDEX_COL_NAME
+        
+        
+
+ A const char * name referring to the index column in general.
+
DataFrame
Exceptions
Description
+

+struct DataFrameError{ }
+        
+
+ It is derived from std::runtime_error. It is the base of all DataFrame exceptions.
+ It might be also thrown in cases where other exceptions may not be applicable. +
+

+struct BadRange{ }
+        
+
+ It is derived from DataFrameError. It might be thrown in cases where the query is asking for out-of-range data.
+ For example, when you try to access data or index column that is out of range. +
+

+struct ColNotFound{ }
+        
+
+ It is derived from DataFrameError. It might be thrown in cases where the operation is asking for non-existence column. +
+

+struct InconsistentData{ }
+        
+
+ It is derived from DataFrameError. It might be thrown in cases where data is inconsisten.
+ For example, when you are trying to populate a collumn with a data vector that is longer than the index column. +
+

+struct NotFeasible{ }
+        
+
+ It is derived from DataFrameError. It might be thrown in cases where the operation is not feasible.
+ For example, asking to interpolate missing data in a string column. +
+

+struct NotImplemented{ }
+        
+
+ It is derived from DataFrameError. It might be thrown in cases where the operation is not yet implemented. +
+ + C++ DataFrame + + + + + diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index 7c9626d18..f5191b6fb 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -1218,11 +1218,11 @@ class DataFrame : public ThreadGranularity { // Name of the column // template - [[nodiscard]] DataFrame> + [[nodiscard]] DataFrame value_counts(const char *col_name) const; template - [[nodiscard]] DataFrame> + [[nodiscard]] DataFrame value_counts(size_type index) const; // It bucketizes the data and index into intervals, based on index values @@ -1317,7 +1317,7 @@ class DataFrame : public ThreadGranularity { // (See join_policy definition) // template - [[nodiscard]] DataFrame> + [[nodiscard]] DataFrame join_by_index(const RHS_T &rhs, join_policy jp) const; // It joins the data between self (lhs) and rhs and returns the joined data @@ -1350,8 +1350,7 @@ class DataFrame : public ThreadGranularity { // (See join_policy definition) // template - [[nodiscard]] DataFrame> + [[nodiscard]] DataFrame join_by_column(const RHS_T &rhs, const char *name, join_policy jp) const; // It concatenates rhs to the end of self and returns the result as @@ -1615,7 +1614,7 @@ class DataFrame : public ThreadGranularity { // in the returned vector // template - [[nodiscard]] HeteroVector + [[nodiscard]] HeteroVector get_row(size_type row_num, const StlVecType &col_names) const; @@ -1631,7 +1630,7 @@ class DataFrame : public ThreadGranularity { // The row number // template - [[nodiscard]] HeteroVector + [[nodiscard]] HeteroVector get_row(size_type row_num) const; // It returns a vector of unique values in the named column in the same @@ -2468,8 +2467,7 @@ class DataFrame : public ThreadGranularity { // the list only once. // template - [[nodiscard]] DataFrame> + [[nodiscard]] DataFrame describe() const; // This method combines the content of column col_name between self and diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index f26da5642..e4a0eef14 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -1388,7 +1388,7 @@ groupby3_async(const char *col_name1, template template -DataFrame> +DataFrame DataFrame::value_counts (const char *col_name) const { const ColumnVecType &vec = get_column(col_name); @@ -1449,7 +1449,7 @@ DataFrame::value_counts (const char *col_name) const { template template -DataFrame> +DataFrame DataFrame::value_counts(size_type index) const { return (value_counts(column_list_[index].first.c_str())); diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index 4f382633c..aa51432fc 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -215,7 +215,7 @@ DataFrame::get_index() { return (indices_); } template template -HeteroVector DataFrame:: +HeteroVector::align_value> DataFrame:: get_row(size_type row_num, const StlVecType &col_names) const { if (row_num >= indices_.size()) { @@ -262,7 +262,7 @@ get_row(size_type row_num, const StlVecType &col_names) const { template template -HeteroVector DataFrame:: +HeteroVector::align_value> DataFrame:: get_row(size_type row_num) const { if (row_num >= indices_.size()) { @@ -2312,7 +2312,7 @@ DataFrame::get_columns_info () const { template template -DataFrame> +DataFrame DataFrame::describe() const { DataFrame> result; diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index c005621ff..a61036f61 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -38,7 +38,7 @@ namespace hmdf template template -DataFrame> +DataFrame DataFrame:: join_by_index (const RHS_T &rhs, join_policy mp) const { @@ -97,7 +97,7 @@ join_by_index (const RHS_T &rhs, join_policy mp) const { template template -DataFrame> +DataFrame DataFrame:: join_by_column (const RHS_T &rhs, const char *name, join_policy mp) const { From f40e0c35249f6351d2da069b698744ed03ef01ce Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 1 Jan 2023 12:57:16 -0500 Subject: [PATCH 24/25] Fixed stupid Windows compiler problem --- docs/HTML/DataFrameTypes.html | 4 ---- include/DataFrame/DataFrame.h | 4 ++-- include/DataFrame/Internals/DataFrame_get.tcc | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/HTML/DataFrameTypes.html b/docs/HTML/DataFrameTypes.html index 589afcec7..8ef610ed0 100644 --- a/docs/HTML/DataFrameTypes.html +++ b/docs/HTML/DataFrameTypes.html @@ -283,10 +283,6 @@ - - - - DataFrame
Exceptions Description diff --git a/include/DataFrame/DataFrame.h b/include/DataFrame/DataFrame.h index f5191b6fb..b5de88987 100644 --- a/include/DataFrame/DataFrame.h +++ b/include/DataFrame/DataFrame.h @@ -1614,7 +1614,7 @@ class DataFrame : public ThreadGranularity { // in the returned vector // template - [[nodiscard]] HeteroVector + [[nodiscard]] HeteroVector get_row(size_type row_num, const StlVecType &col_names) const; @@ -1630,7 +1630,7 @@ class DataFrame : public ThreadGranularity { // The row number // template - [[nodiscard]] HeteroVector + [[nodiscard]] HeteroVector get_row(size_type row_num) const; // It returns a vector of unique values in the named column in the same diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index aa51432fc..30e271c86 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -215,7 +215,7 @@ DataFrame::get_index() { return (indices_); } template template -HeteroVector::align_value> DataFrame:: +HeteroVector DataFrame:: get_row(size_type row_num, const StlVecType &col_names) const { if (row_num >= indices_.size()) { @@ -262,7 +262,7 @@ get_row(size_type row_num, const StlVecType &col_names) const { template template -HeteroVector::align_value> DataFrame:: +HeteroVector DataFrame:: get_row(size_type row_num) const { if (row_num >= indices_.size()) { From 1ffcad12bdce888aaa1bb65e53e9fc4b49ef89df Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Sun, 1 Jan 2023 21:07:33 -0500 Subject: [PATCH 25/25] Adjusted docs for aligned memory allocator 5 --- docs/HTML/DataFrame.html | 100 +++++++++++++++++----------------- docs/HTML/DataFrameTypes.html | 50 ++++++++--------- 2 files changed, 76 insertions(+), 74 deletions(-) diff --git a/docs/HTML/DataFrame.html b/docs/HTML/DataFrame.html index 9ec9635e4..60e831a7d 100644 --- a/docs/HTML/DataFrame.html +++ b/docs/HTML/DataFrame.html @@ -31,7 +31,7 @@ } body { - background-image: linear-gradient(AntiqueWhite, HoneyDew, BlanchedAlmond); + background-image: linear-gradient(LemonChiffon, Beige, Khaki, BlanchedAlmond, FloralWhite); } .row { @@ -65,23 +65,33 @@
- C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame + C++ DataFrame

- This is a templatized and heterogeneous C++ container with data-analysis functionality and interface. + DataFrame is a templatized and heterogeneous C++ container designed for data analysis for statistical, machine-learning, or financial applications.

-
+


DataFrame class is defined as:
template<typename I, typename H>
@@ -92,43 +102,27 @@
   I specifies the index column type
H specifies a heterogenous vector type to contain DataFrame columns. H can only be:
    -
  • HeteroVector: This is an actual heterogenous vector that would contain data. This will result in a "standard" data frame
  • -
  • HeteroPtrView: This is a heterogenous vector view. It will result in a data frame view into a disjoined slice of another data frame.
  • -
  • HeteroConstPtrView: The const version of HeteroPtrView.
  • -
  • HeteroView: This is a heterogenous vector view. It will result in a data frame view into a contiguous slice of another data frame. This view is slightly more efficient than HeteroPtrView
  • -
  • HeteroConstView: The const version of HeteroView.
  • +
  • HeteroVector<std::size_t A = 0>: This is an actual heterogenous vector that would contain data. This will result in a "standard" data frame
  • +
  • HeteroPtrView<std::size_t A = 0>: This is a heterogenous vector view. It will result in a data frame view into a disjoined slice of another data frame.
  • +
  • HeteroConstPtrView<std::size_t A = 0>: The const version of HeteroPtrView.
  • +
  • HeteroView<std::size_t A = 0>: This is a heterogenous vector view. It will result in a data frame view into a contiguous slice of another data frame. This view is slightly more efficient than HeteroPtrView
  • +
  • HeteroConstView<std::size_t A = 0>: The const version of HeteroView.
+ Template parameter A referrers to byte boundary alignment to be used in memory allocations. The default is system default boundaries for each type. See Memory Alignment section below

Some of the methods in DataFrame return another DataFrame or one of the above views depending on what you asked for. DataFrame and view instances should be indistinguishable from the user's point of view.
- There are a few convenient typedef’s that are handy:
-
template<typename I>
-using StdDataFrame = DataFrame<I, HeteroVector>;
+  See Views section below. Also, see DataFrame Library Types for convenient typedef's
-template<typename I> -using DataFrameView = DataFrame<I, HeteroView>; - -template<typename I> -using DataFrameConstView = DataFrame<I, HeteroConstView>; - -template<typename I> -using DataFramePtrView = DataFrame<I, HeteroPtrView>; - -template<typename I> -using DataFrameConstPtrView = DataFrame<I, HeteroConstPtrView>; -
- - -
+


DataFrame library interface is separated into two main categories:
    -
  1. Accessing, adding, slicing & dicing, joining, & groupby'ing ... (The first column in the table below)
  2. -
  3. Analytical algorithms being statistical, machine-learning, financial analysis … (The second and third columns in the table below)
  4. +
  5. Accessing, adding, slicing & dicing, joining, & groupby'ing ... (The first column in the table below)
  6. +
  7. Analytical algorithms being statistical, machine-learning, financial analysis … (The second and third columns in the table below)
I employ regular parameterized methods (i.e. member functions) to implement item (1). For item (2), I chose the visitor pattern.
Please see the table below for a comprehensive list of methods, visitors, and types along with documentation and sample code for each feature

- -
+
-

Table of Features (with Code Samples)

+

Table of Functionalities — with Code Samples

- + @@ -550,7 +544,7 @@

Table of Features (with Code Samples)

DataFrame Member MethodsDataFrame
Member Functions
- + @@ -826,7 +820,7 @@

Table of Features (with Code Samples)

DataFrame Built-in VisitorsDataFrame
Built-in Visitors
- + @@ -1055,7 +1049,7 @@

Table of Features (with Code Samples)

DataFrame Built-in Financial VisitorsDataFrame
Built-in Financial Visitors
- + @@ -1207,7 +1201,7 @@

Table of Features (with Code Samples)

DataFrame TypesDataFrame
Types
- + @@ -1298,7 +1292,7 @@

Table of Features (with Code Samples)

-
+


Multithreading

    @@ -1311,7 +1305,7 @@

    Multithreading

-
+


Views

@@ -1333,7 +1327,7 @@

Views

For more understanding, look at this document further and/or the test files.

-
+


Visitors

@@ -1361,7 +1355,16 @@

Visitors

  • Because algorithms are self-contained, they can be passed to other algorithms to be used
  • -
    +


    + +

    Memory Alignment

    +

    + DataFrame gives you ability to allocate memory on custom alignment boundaries.
    + You can use this feature to take advantage of SIMD instructions in modern CPU’s. Since DataFrame algorithms are all done on vectors of data — columns, this can come handy in conjunction with compiler optimizations.
    +There are convenient typedef’s that define DataFrame’s that allocate memory, for example, on 64, 128, 256, … bytes boundaries. See DataFrame Library Types +

    + +


    Numeric Generators

    @@ -1370,7 +1373,7 @@

    Numeric Generators

    For the definition and defaults of RandGenParams, see this document and file DataFrameTypes.h

    -
    +


    Code Structure

    @@ -1385,7 +1388,7 @@

    Code Structure

    test directory contains all the test source files, mocked data files, and test output files. The main test source files are dataframe_tester.cc and dataframe_tester_2.cc. It contains test cases for all functionalities of DataFrame. It is not in a very organized structure. I plan to make the test cases more organized.

    -
    +


    Build Instructions

    @@ -1394,7 +1397,8 @@

    Build Instructions

    Using cmake:
    Please see README file. Thanks to @justinjk007, you should be able to build this in Linux, Windows, Mac, and more

    -
    + +


    Motivation

    @@ -1402,9 +1406,7 @@

    Motivation

    I welcome all contributions from people with expertise, interest, and time to do it. I will add more functionalities from time to time, but currently my spare time is limited.

    -
    - -

    +
    diff --git a/docs/HTML/DataFrameTypes.html b/docs/HTML/DataFrameTypes.html index 8ef610ed0..0d5b1974c 100644 --- a/docs/HTML/DataFrameTypes.html +++ b/docs/HTML/DataFrameTypes.html @@ -34,115 +34,115 @@
    Stand-alone Numeric GeneratorsStand-alone
    Numeric Generators
    
    -align_value
    +View
             
             
    - An integer value specifying the byte alignment boundary in memory allocation for the DataFrame type.
    + A DataFrame view. This is a view on a contiguous slice of another DataFrane of the same type.
    + You can read and change data in this view.
    
    -template<typename T>
    -AllocatorType
    +ConstView
             
             
    - Type of allocator used to allocate memory for this type of DataFrame.
    - It is either std::allocator or a custom allocator to allocate memory on custom byte boundaries.
    + A const DataFrame view. This is a view on a contiguous slice of another DataFrane of the same type.
    + This is a read-only view.
    
    -size_type
    +PtrView
             
             
    - std::size_t
    + A DataFrame view. This is a view on a disjoined slice of another DataFrane of the same type.
    + You can read and change data in this view.
    
    -IndexType
    +ConstPtrView
             
             
    - Index column type for this DataFrame
    + A const DataFrame view. This is a view on a disjoined slice of another DataFrane of the same type.
    + This is a read-only view.
    
    -IndexVecType
    +align_value
             
             
    - Type of vector used for the index column. It is either a std::vector or one of the vector views depending on whether this is a DataFrame or a DataFrame view.
    - Also, the allocator depends on the align_value.
    + An integer value specifying the byte alignment boundary in memory allocation for the DataFrame type.
    
    -View
    +template<typename T>
    +AllocatorType
             
             
    - A DataFrame view. This is a view on a contiguous slice of another DataFrane of the same type.
    - You can read and change data in this view.
    + Type of allocator used to allocate memory for this type of DataFrame.
    + It is either std::allocator or a custom allocator to allocate memory on custom byte boundaries.
    
    -ConstView
    +size_type
             
             
    - A const DataFrame view. This is a view on a contiguous slice of another DataFrane of the same type.
    - This is a read-only view.
    + std::size_t
    
    -PtrView
    +IndexType
             
             
    - A DataFrame view. This is a view on a disjoined slice of another DataFrane of the same type.
    - You can read and change data in this view.
    + Index column type for this DataFrame
    
    -ConstPtrView
    +IndexVecType
             
             
    - A const DataFrame view. This is a view on a disjoined slice of another DataFrane of the same type.
    - This is a read-only view.
    + Type of vector used for the index column. It is either a std::vector or one of the vector views depending on whether this is a DataFrame or a DataFrame view.
    + Also, the allocator depends on the align_value.