├── .github └── workflows │ ├── pytest.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── DEVELOPMENT_GUIDE.md ├── Doxyfile ├── LICENSE.txt ├── LICENSE_cereal-1.2.2 ├── LICENSE_doxy2swig ├── LICENSE_rapidjson ├── LICENSE_rapidxml ├── README.md ├── benchmarks ├── benchmark_rss_v1.cpp ├── benchmark_sorting.cpp └── run_benchmark.sh ├── build_tools ├── build_source.sh ├── compile.sh ├── env.sh ├── test_source.sh └── test_wheels.sh ├── docs ├── .buildinfo ├── _modules │ ├── index.html │ └── pyrfr │ │ └── regression.html ├── _sources │ ├── index.txt │ ├── installation.txt │ └── regression.txt ├── _static │ ├── ajax-loader.gif │ ├── basic.css │ ├── classic.css │ ├── comment-bright.png │ ├── comment-close.png │ ├── comment.png │ ├── doctools.js │ ├── down-pressed.png │ ├── down.png │ ├── file.png │ ├── jquery-1.11.1.js │ ├── jquery.js │ ├── minus.png │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── sidebar.js │ ├── underscore-1.3.1.js │ ├── underscore.js │ ├── up-pressed.png │ ├── up.png │ └── websupport.js ├── genindex.html ├── index.html ├── installation.html ├── objects.inv ├── py-modindex.html ├── regression.html ├── search.html └── searchindex.js ├── documentation ├── .gitignore ├── Makefile ├── conf.py ├── index.rst ├── installation.rst └── regression.rst ├── include ├── cereal │ ├── access.hpp │ ├── archives │ │ ├── adapters.hpp │ │ ├── binary.hpp │ │ ├── json.hpp │ │ ├── portable_binary.hpp │ │ └── xml.hpp │ ├── cereal.hpp │ ├── details │ │ ├── helpers.hpp │ │ ├── polymorphic_impl.hpp │ │ ├── polymorphic_impl_fwd.hpp │ │ ├── static_object.hpp │ │ ├── traits.hpp │ │ └── util.hpp │ ├── external │ │ ├── base64.hpp │ │ ├── rapidjson │ │ │ ├── allocators.h │ │ │ ├── document.h │ │ │ ├── encodedstream.h │ │ │ ├── encodings.h │ │ │ ├── error │ │ │ │ ├── en.h │ │ │ │ └── error.h │ │ │ ├── filereadstream.h │ │ │ ├── filewritestream.h │ │ │ ├── fwd.h │ │ │ ├── internal │ │ │ │ ├── biginteger.h │ │ │ │ ├── diyfp.h │ │ │ │ ├── dtoa.h │ │ │ │ ├── ieee754.h │ │ │ │ ├── itoa.h │ │ │ │ ├── meta.h │ │ │ │ ├── pow10.h │ │ │ │ ├── regex.h │ │ │ │ ├── stack.h │ │ │ │ ├── strfunc.h │ │ │ │ ├── strtod.h │ │ │ │ └── swap.h │ │ │ ├── istreamwrapper.h │ │ │ ├── memorybuffer.h │ │ │ ├── memorystream.h │ │ │ ├── msinttypes │ │ │ │ ├── inttypes.h │ │ │ │ └── stdint.h │ │ │ ├── ostreamwrapper.h │ │ │ ├── pointer.h │ │ │ ├── prettywriter.h │ │ │ ├── rapidjson.h │ │ │ ├── reader.h │ │ │ ├── schema.h │ │ │ ├── stream.h │ │ │ ├── stringbuffer.h │ │ │ └── writer.h │ │ └── rapidxml │ │ │ ├── license.txt │ │ │ ├── manual.html │ │ │ ├── rapidxml.hpp │ │ │ ├── rapidxml_iterators.hpp │ │ │ ├── rapidxml_print.hpp │ │ │ └── rapidxml_utils.hpp │ ├── macros.hpp │ └── types │ │ ├── array.hpp │ │ ├── base_class.hpp │ │ ├── bitset.hpp │ │ ├── boost_variant.hpp │ │ ├── chrono.hpp │ │ ├── common.hpp │ │ ├── complex.hpp │ │ ├── concepts │ │ └── pair_associative_container.hpp │ │ ├── deque.hpp │ │ ├── forward_list.hpp │ │ ├── functional.hpp │ │ ├── list.hpp │ │ ├── map.hpp │ │ ├── memory.hpp │ │ ├── polymorphic.hpp │ │ ├── queue.hpp │ │ ├── set.hpp │ │ ├── stack.hpp │ │ ├── string.hpp │ │ ├── tuple.hpp │ │ ├── unordered_map.hpp │ │ ├── unordered_set.hpp │ │ ├── utility.hpp │ │ ├── valarray.hpp │ │ └── vector.hpp └── rfr │ ├── data_containers │ ├── array_wrapper.hpp │ ├── data_container.hpp │ ├── data_container_utils.hpp │ ├── default_data_container.hpp │ └── default_data_container_with_instances.hpp │ ├── forests │ ├── classification_forest.hpp │ ├── fanova_forest.hpp │ ├── forest_options.hpp │ ├── mondrian_forest.hpp │ ├── quantile_regression_forest.hpp │ └── regression_forest.hpp │ ├── nodes │ ├── k_ary_mondrian_node.hpp │ ├── k_ary_node.hpp │ └── temporary_node.hpp │ ├── splits │ ├── binary_split_one_feature_rss_loss.hpp │ ├── classification_split.hpp │ └── split_base.hpp │ ├── trees │ ├── binary_fanova_tree.hpp │ ├── k_ary_mondrian_tree.hpp │ ├── k_ary_tree.hpp │ ├── tree_base.hpp │ └── tree_options.hpp │ └── util.hpp ├── lib └── doxy2swig │ ├── LICENSE │ ├── README.md │ └── doxy2swig.py ├── local_lcov.sh ├── pyproject.toml ├── pyrfr ├── MANIFEST.in ├── examples │ ├── pyrfr_covariance_example.py │ ├── pyrfr_oob_error.py │ ├── pyrfr_pickle_example.py │ ├── pyrfr_simple_example.py │ └── pyrfr_with_instances_example.py ├── pyrfr │ ├── .gitignore │ ├── __init__.py │ ├── regression.i │ └── util.i └── setup.py ├── test_data_sets ├── Skin_NonSkin_features.csv ├── Skin_NonSkin_responses.csv ├── corrupted_toy_data_set_responses.csv ├── corrupted_toy_data_set_weights.csv ├── diabetes_features.csv ├── diabetes_responses.csv ├── features13.csv ├── online_lda_features.csv ├── online_lda_responses.csv ├── responses13.csv ├── sat_instance_features.csv ├── sat_performance_matrix.csv ├── sat_saps_configurations.csv ├── sinx_features.csv ├── sinx_features_test.csv ├── sinx_noise_features.csv ├── sinx_noise_features_test.csv ├── sinx_noise_responses.csv ├── sinx_noise_responses_test.csv ├── sinx_responses.csv ├── sinx_responses_test.csv ├── sinxy_features.csv ├── sinxy_features_test.csv ├── sinxy_responses.csv ├── sinxy_responses_test.csv ├── toy_data_set_features.csv ├── toy_data_set_responses.csv ├── toy_data_set_weights.csv └── ut_reference.py └── tests ├── CMakeLists.txt ├── __init__.py ├── profiling_example.cpp ├── pyrfr_unit_test_basics.py ├── pyrfr_unit_test_binary_regression_forest.py ├── pyrfr_unit_test_binary_regression_forest_transformed_data.py ├── pyrfr_unit_test_fanova_forest.py ├── pyrfr_unit_test_mondrian_forest.py ├── pyrfr_unit_test_quantile_regression_forest.py ├── unit_test_binary_nodes.cpp ├── unit_test_binary_splits.cpp ├── unit_test_binary_tree.cpp ├── unit_test_classification_forest.cpp ├── unit_test_data_containers.cpp ├── unit_test_fanova.cpp ├── unit_test_mondrian_forest.cpp ├── unit_test_regression_forest.cpp └── unit_test_utils.cpp /.github/workflows/pytest.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | # Allow to manually trigger through github API 5 | workflow_dispatch: 6 | 7 | # Triggers with push to main 8 | push: 9 | branches: 10 | - main 11 | 12 | # Triggers with push to a pr aimed at main 13 | pull_request: 14 | branches: 15 | - main 16 | 17 | schedule: 18 | # Every day at 7AM UTC 19 | - cron: '0 07 * * *' 20 | 21 | jobs: 22 | ubuntu: 23 | 24 | runs-on: ubuntu-latest 25 | strategy: 26 | matrix: 27 | python-version: ["3.7", "3.8", "3.9", "3.10"] 28 | swig: ['3.0', '4.0'] 29 | fail-fast: false 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - name: Setup Python ${{ matrix.python-version }} 35 | uses: actions/setup-python@v3 36 | with: 37 | python-version: ${{ matrix.python-version }} 38 | 39 | - name: Install test dependencies 40 | run: | 41 | chmod u+x ./build_tools/env.sh 42 | ./build_tools/env.sh 43 | lcov --directory . --zerocounters 44 | 45 | - name: Overwrite Swig 46 | if: ${{ matrix.swig == '3.0'}} 47 | run: | 48 | sudo apt-get update 49 | sudo apt-get remove swig 50 | sudo apt-get install swig3.0 51 | sudo ln -s /usr/bin/swig3.0 /usr/bin/swig 52 | 53 | - name: Use swig 54 | run: /usr/bin/swig -version 55 | 56 | - name: Use cmake 57 | run: cmake --version 58 | 59 | - name: Use g++ 60 | run: g++ --version 61 | 62 | - name: Use boost 63 | run: whereis boost && dpkg -s libboost-dev | grep 'Version' 64 | 65 | - name: Run Ctest 66 | run: | 67 | mkdir build 68 | cd build 69 | cmake .. -DSWIG_EXECUTABLE=/usr/bin/swig 70 | make 71 | ctest --output-on-failure 72 | 73 | - name: Coverage 74 | timeout-minutes: 45 75 | run: | 76 | lcov --directory . --capture --rc lcov_branch_coverage=1 --output-file coverage.info 77 | lcov --remove coverage.info 'tests/*' '/usr/*' '/usr/include/*' '*/include/cereal/*' --output-file coverage.info 78 | lcov --list coverage.info 79 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | benchmarks/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/.gitmodules -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8 FATAL_ERROR) 2 | project (RFR CXX) 3 | 4 | # add a version number 5 | set (RFR_VERSION_MAJOR 0) 6 | set (RFR_VERSION_MINOR 9) 7 | set (RFR_VERSION_RELEASE 0) 8 | 9 | # Print debug information about boost 10 | set(Boost_DEBUG 1) 11 | 12 | IF(NOT CMAKE_BUILD_TYPE) 13 | SET(CMAKE_BUILD_TYPE "DEBUG") 14 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") # enabling coverage 15 | #SET(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage") 16 | 17 | #SET(CMAKE_BUILD_TYPE "RELESE") 18 | #SET(CMAKE_BUILD_TYPE "RELWITHDEBINFO") 19 | #SET(CMAKE_BUILD_TYPE "MINSIZEREL") 20 | ENDIF() 21 | 22 | # required libaries 23 | find_package(Boost COMPONENTS unit_test_framework) 24 | find_package(Doxygen) 25 | find_package(PythonInterp 3) 26 | find_package(SWIG) 27 | 28 | enable_testing() 29 | 30 | # define all include directories within the project for different splits, data containers, node types etc... 31 | include_directories ("${PROJECT_SOURCE_DIR}/include") 32 | include_directories ("${Boost_INCLUDE_DIR}") 33 | 34 | 35 | # the documentation 36 | if(DOXYGEN_FOUND) 37 | configure_file(${PROJECT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) 38 | add_custom_target(doxygen_doc 39 | COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile 40 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 41 | COMMENT "Generating API documentation with Doxygen" VERBATIM) 42 | endif(DOXYGEN_FOUND) 43 | 44 | 45 | 46 | if(PYTHONINTERP_FOUND AND SWIG_FOUND) 47 | file(COPY ${PROJECT_SOURCE_DIR}/pyrfr DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 48 | file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/pyrfr ${CMAKE_CURRENT_BINARY_DIR}/python_package) 49 | 50 | configure_file(${PROJECT_SOURCE_DIR}/pyrfr/setup.py ${CMAKE_CURRENT_BINARY_DIR}/python_package/setup.py) 51 | configure_file(${PROJECT_SOURCE_DIR}/pyrfr/pyrfr/__init__.py ${CMAKE_CURRENT_BINARY_DIR}/python_package/pyrfr/__init__.py) 52 | 53 | file(COPY ${PROJECT_SOURCE_DIR}/include DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python_package) 54 | file(COPY ${PROJECT_SOURCE_DIR}/LICENSE.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python_package) 55 | file(COPY ${PROJECT_SOURCE_DIR}/LICENSE_cereal-1.2.2 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python_package) 56 | file(COPY ${PROJECT_SOURCE_DIR}/LICENSE_doxy2swig DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python_package) 57 | file(COPY ${PROJECT_SOURCE_DIR}/LICENSE_rapidjson DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python_package) 58 | file(COPY ${PROJECT_SOURCE_DIR}/LICENSE_rapidxml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python_package) 59 | 60 | 61 | add_custom_target(pyrfr_docstrings 62 | COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/lib/doxy2swig/doxy2swig.py -a -t -f -q -c ${CMAKE_CURRENT_BINARY_DIR}/doc/xml/index.xml ${CMAKE_CURRENT_BINARY_DIR}/python_package/pyrfr/docstrings.i 63 | DEPENDS doxygen_doc 64 | COMMENT "Generating Python Docstrings" VERBATIM 65 | ) 66 | 67 | #file(COPY documentation DESTINATION ${CMAKE_BINARY_DIR}) 68 | #file(RENAME ${CMAKE_BINARY_DIR}/documentation ${CMAKE_BINARY_DIR}/github_docs) 69 | #file(COPY include DESTINATION ${CMAKE_BINARY_DIR}) 70 | #configure_file(${PROJECT_SOURCE_DIR}/documentation/conf.py ${CMAKE_CURRENT_BINARY_DIR}/github_docs/conf.py) 71 | #add_custom_target(github_documentation 72 | # COMMAND make html 73 | # DEPENDS pyrfr_build 74 | # WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/github_docs 75 | # COMMENT "Generating github pages" 76 | #) 77 | 78 | add_custom_target(pyrfr_build ALL 79 | COMMAND ${PYTHON_EXECUTABLE} setup.py build_ext --inplace --swig ${SWIG_EXECUTABLE} 80 | DEPENDS pyrfr_docstrings 81 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python_package 82 | ) 83 | endif(PYTHONINTERP_FOUND AND SWIG_FOUND) 84 | 85 | 86 | # add all the unit tests in the tests directory 87 | add_subdirectory(tests) 88 | 89 | 90 | IF(CMAKE_COMPILER_IS_GNUCXX) 91 | ADD_DEFINITIONS("-Wall -O3 -g") 92 | ELSEIF(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") 93 | ADD_DEFINITIONS("-Wall -fPIC -pg -O3 -std=c++11") 94 | ELSE() 95 | MESSAGE(FATAL_ERROR "CMakeLists.txt has not been tested/written for your compiler.") 96 | ENDIF() 97 | -------------------------------------------------------------------------------- /DEVELOPMENT_GUIDE.md: -------------------------------------------------------------------------------- 1 | # Building and Testing locally 2 | For now, please refer to `.github/workflows/pytest.yml`. TODO 3 | 4 | # Releasing 5 | First we create release files through github actions. 6 | Then we will test them and finally upload them to PYPI 7 | 8 | #### Creating Release files 9 | 1. Increase the version number in `CMakeLists.txt` as well. 10 | 2. Tag the same version `v*` on github or locally and push. 11 | 3. Wait for the github actions to build all the wheels and sdist. 12 | 4. Download these release files to some folder we will call `./release` 13 | 14 | #### Checking installation worked 15 | ```bash 16 | pip install ./release/pyrfr-.tar.gz 17 | python -c "import pyrfr" # Should import with no problem 18 | ``` 19 | 20 | You could also try running the tests. TODO 21 | 22 | #### Uploading to PYPI 23 | ```bash 24 | pip install twine 25 | 26 | # Make sure ./release has all the wheels and tar.gz you wish to push 27 | 28 | # Make sure at this point you updated the version in CMakeLists.txt 29 | twine upload ./release/* 30 | ``` 31 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | This license applies to all files provided by the AutoML team. This repository 2 | contains files that are licensed under different licenses and they can be 3 | identified by having their own license header. 4 | 5 | =============================================================================== 6 | 7 | Copyright 2021 AutoML 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, this 13 | list of conditions and the following disclaimer. 14 | 15 | 2. Redistributions in binary form must reproduce the above copyright notice, 16 | this list of conditions and the following disclaimer in the documentation 17 | and/or other materials provided with the distribution. 18 | 19 | 3. Neither the name of the copyright holder nor the names of its contributors 20 | may be used to endorse or promote products derived from this software 21 | without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 27 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | POSSIBILITY OF SUCH DAMAGE. 34 | -------------------------------------------------------------------------------- /LICENSE_cereal-1.2.2: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of cereal nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /LICENSE_doxy2swig: -------------------------------------------------------------------------------- 1 | Original work Copyright (c) Prabhu Ramachandran 2 | Modified work Copyright (c) 2015, Michael Thon 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /LICENSE_rapidxml: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RFR 2 | 3 | A extensible C++ library for random forests with Python bindings with a BSD3 license. 4 | 5 | ## Requirements 6 | 7 | For the C++ library itself, you need no additional libaries, only a C++11 capable compiler. 8 | Technically, you need Boost if you want to compile the unit tests. 9 | The development is done using GCC 7.2. 10 | You probably have to set CMAKE\_CXX\_FLAGS to -std=c++11 when using older compilers. 11 | 12 | ``` 13 | CMAKE 14 | DOXYGEN (if you want docstrings, which you probably do) 15 | SWIG > 3.0 16 | ``` 17 | 18 | 19 | ## Installing the Python Bindings 20 | We upload the latest version to PYPI, so you can install it via 21 | ``` 22 | pip install pyrfr 23 | ``` 24 | Development is done with Python 3.7-3.10 on Ubuntu and the unittests are executed via github actions. 25 | We do no longer support Python 2. Contact us if you experience any irregularities. 26 | 27 | ## USAGE 28 | 29 | For now, the file `./tests/pyrfr_unit_test_*.py` inside the repository serve as the 30 | only real documentation of the Python bindings besides the docstrings. 31 | -------------------------------------------------------------------------------- /benchmarks/benchmark_rss_v1.cpp: -------------------------------------------------------------------------------- 1 | // g++ -I../include --std=c++11 -O2 -pg -o benchmark_rss_v1 benchmark_rss_v1.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | #include "rfr/data_containers/mostly_continuous_data_container.hpp" 13 | #include "rfr/splits/binary_split_one_feature_rss_loss.hpp" 14 | #include "rfr/nodes/k_ary_node.hpp" 15 | #include "rfr/trees/k_ary_tree.hpp" 16 | #include "rfr/forests/regression_forest.hpp" 17 | 18 | 19 | typedef double num_type; 20 | typedef double response_type; 21 | typedef unsigned int index_type; 22 | typedef std::default_random_engine rng_type; 23 | 24 | typedef rfr::data_containers::mostly_continuous_data data_type; 25 | typedef rfr::splits::binary_split_one_feature_rss_loss split_type; 26 | typedef rfr::nodes::k_ary_node<2, split_type, rng_type, num_type, response_type, index_type> node_type; 27 | typedef rfr::nodes::temporary_node tmp_node_type; 28 | typedef rfr::trees::k_ary_random_tree<2, split_type, rng_type, num_type, response_type, index_type> tree_type; 29 | typedef rfr::forests::regression_forest< tree_type, rng_type, num_type, response_type, index_type> forest_type; 30 | 31 | 32 | 33 | int main (int argc, char** argv){ 34 | 35 | if (argc != 5){ 36 | std::cout<<"need arguments: "< dist1(-1.0,1.0); 51 | std::uniform_int_distribution dist2(0,num_data_points); 52 | 53 | auto random_num = std::bind(dist1, rng); 54 | auto random_ind = std::bind(dist2, rng); 55 | 56 | for (auto i=0u; i < num_data_points; i++){ 57 | 58 | num_type feature_vector[num_features]; 59 | std::generate_n(feature_vector, num_features, random_num); 60 | response_type response = random_num(); 61 | 62 | data.add_data_point(feature_vector, num_features, response); 63 | } 64 | 65 | rfr::forests::forest_options forest_opts; 66 | forest_opts.adjust_limits_to_data(data); 67 | 68 | forest_opts.num_data_points_per_tree = sample_size; 69 | forest_opts.do_bootstrapping = true; 70 | forest_opts.num_trees = num_trees; 71 | forest_opts.tree_opts.max_features = num_features/2; 72 | 73 | 74 | forest_type the_forest(forest_opts); 75 | 76 | the_forest.fit(data, rng); 77 | 78 | return(0); 79 | } 80 | -------------------------------------------------------------------------------- /benchmarks/run_benchmark.sh: -------------------------------------------------------------------------------- 1 | O_level=$1 2 | num_feats=100 3 | num_datapoints=100000 4 | num_samples=50000 5 | num_trees=64 6 | 7 | #g++ -I../include/ -O$O_level -Wall -o benchmark_sorting -std=c++11 benchmark_sorting.cpp 8 | #./benchmark_sorting $num_feats $num_datapoints $num_samples 9 | 10 | #g++ -I../include/ -O$O_level -Wall -o benchmark_sorting_profile -std=c++11 benchmark_sorting.cpp 11 | #./benchmark_sorting_profile $num_feats $num_datapoints $num_samples 12 | #gprof benchmark_sorting_profile gmon.out > analysis.txt 13 | 14 | g++ -I../include/ -O$O_level -Wall -pg -o benchmark_rss_v1 -std=c++11 benchmark_rss_v1.cpp 15 | time ./benchmark_rss_v1 $num_feats $num_datapoints $num_samples $num_trees 16 | gprof benchmark_rss_v1 gmon.out > analysis_v1.txt 17 | gprof benchmark_rss_v1 | python /home/sfalkner/.local/lib/python3.5/site-packages/gprof2dot.py -s | dot -Tpng -o graph_v1.png 18 | 19 | g++ -I../include/ -O$O_level -Wall -pg -o benchmark_rss_v2 -std=c++11 benchmark_rss_v2.cpp 20 | time ./benchmark_rss_v2 $num_feats $num_datapoints $num_samples $num_trees 21 | gprof benchmark_rss_v2 gmon.out > analysis_v2.txt 22 | gprof benchmark_rss_v2 | python /home/sfalkner/.local/lib/python3.5/site-packages/gprof2dot.py -s | dot -Tpng -o graph_v2.png 23 | -------------------------------------------------------------------------------- /build_tools/build_source.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e # Immediatly exit on any error 3 | set -x # Print each command before running 4 | 5 | # Build the package 6 | # Install the environment 7 | chmod u+x ./build_tools/env.sh 8 | ./build_tools/env.sh 9 | 10 | # Build the package 11 | mkdir build 12 | cd build 13 | cmake .. && make pyrfr_docstrings 14 | cd python_package 15 | 16 | # Also build the distribution 17 | python3 -m pip install twine 18 | python3 setup.py sdist -d ../../dist 19 | 20 | # Check whether the source distribution will render correctly 21 | twine check ../../dist/*.tar.gz --strict 22 | -------------------------------------------------------------------------------- /build_tools/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # The wheels are built in a docker image by `cibuildwheel` seen in release.yml. 3 | # This docker image comes from quay.io with minimal support. It is CentOS 4 | 5 | # This scripts install dependancies for compiling the CPP code before finally 6 | # compiling it 7 | 8 | set -e # Immediatly exit on any error 9 | set -x # Print each command before running 10 | 11 | # Build dependancies 12 | pip3 install cmake numpy 13 | 14 | # Not sure why this is needed 15 | echo 'echo "pyuic5 $@"' > /usr/local/bin/pyuic5 16 | chmod +x /usr/local/bin/pyuic5 17 | 18 | # More build dependancies 19 | yum install -y curl gsl-devel pcre-devel 20 | 21 | # Install SWIG 22 | curl -LO https://downloads.sourceforge.net/swig/swig-4.0.2.tar.gz 23 | tar xzvf swig-4.0.2.tar.gz 24 | cd swig-4.0.2 25 | ./configure 26 | make 27 | make install 28 | cd .. 29 | rm -rf swig-4.0.2* 30 | 31 | # Debug to make sure it's installed 32 | swig -version 33 | 34 | # Install the package building dependencies 35 | # -- one line at a time for easy debug -- 36 | # yum errors out with not much info if one package installation failed 37 | yum -y install boost 38 | yum -y install boost-thread 39 | yum -y install boost-devel 40 | yum -y install doxygen 41 | yum -y install openssl-devel 42 | yum -y install cmake 43 | yum -y install tree 44 | yum -y install rsync 45 | cmake --version 46 | 47 | # After installing the dependencies build the python package 48 | mkdir build 49 | cd build 50 | cmake .. && make pyrfr_docstrings 51 | 52 | # Copy the files for testing 53 | cp -r ../test_data_sets python_package 54 | 55 | # Copy from /project/build to /project 56 | rsync -a --delete --exclude '*build*' python_package/ ../ 57 | 58 | # Wheel building process will create a package from the contents of /project. 59 | # For debug purposes, show the contents of this directory 60 | tree /project 61 | -------------------------------------------------------------------------------- /build_tools/env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | 5 | # Install the environment requirements 6 | # order is important so boost is properly recognized by cmake 7 | sudo apt update 8 | sudo apt upgrade -y 9 | sudo apt install -y build-essential libboost-all-dev swig doxygen git cmake 10 | sudo apt-get install -y swig 11 | 12 | # ctest related requirements 13 | sudo apt-get install -y ruby-dev 14 | sudo gem install coveralls-lcov 15 | sudo apt-get install -y lcov 16 | 17 | # python package requirements 18 | python3 -m pip install --upgrade pip 19 | pip3 install --user -U pip-tools 20 | -------------------------------------------------------------------------------- /build_tools/test_source.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | # Test the distribution on an isolated venv 7 | # Directory structure is such that 8 | # PWD=random_forest_run/random_forest_run/ 9 | cd ../../ 10 | 11 | python -m venv test_env 12 | source test_env/bin/activate 13 | 14 | python -m pip install pytest numpy 15 | python -m pip install random_forest_run/random_forest_run/dist/*.tar.gz 16 | 17 | sed -i -- "s/[^']\+test_data_sets/random_forest_run\/random_forest_run\/test_data_sets/" random_forest_run/random_forest_run/tests/* 18 | pytest random_forest_run/random_forest_run/tests/*.py 19 | -------------------------------------------------------------------------------- /build_tools/test_wheels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e # Immediatly exit on any error 3 | set -x # Print each command before running 4 | 5 | # The wheel builder will currently have the REPO cloned into /project. 6 | # Also unittest from pyrfr are compiled and have local paths embedded. 7 | # Modify such path so they are now pointing to /project 8 | sed -i -- "s/[^']\+test_data_sets/\/project\/test_data_sets/" /project/tests/* 9 | pytest -v /project/tests/*py 10 | 11 | # Test that there are no links to system libraries 12 | python -m threadpoolctl -i pyrfr 13 | -------------------------------------------------------------------------------- /docs/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: f699001d11de72884b82d3ffbc01fa2d 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/_modules/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Overview: module code — pyrfr 0.5 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 41 | 42 |
43 |
44 |
45 |
46 | 47 |

All modules for which code is available

48 | 50 | 51 |
52 |
53 |
54 | 71 |
72 |
73 | 85 | 89 | 90 | -------------------------------------------------------------------------------- /docs/_sources/index.txt: -------------------------------------------------------------------------------- 1 | .. pyrfr documentation master file, created by 2 | sphinx-quickstart on Thu Oct 29 21:12:22 2015. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to pyrfr's documentation! 7 | ================================= 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | installation.rst 15 | regression.rst 16 | 17 | 18 | 19 | Indices and tables 20 | ================== 21 | 22 | * :ref:`genindex` 23 | * :ref:`modindex` 24 | * :ref:`search` 25 | 26 | -------------------------------------------------------------------------------- /docs/_sources/installation.txt: -------------------------------------------------------------------------------- 1 | ********* 2 | About pyRFR 3 | ********* 4 | .. role:: bash(code) 5 | :language: bash 6 | 7 | This package serves as the python interface to RFR, an extensible C++ librarry for random forests. 8 | 9 | Requirements 10 | ************ 11 | 12 | For the C++ library itself, you need no additional libaries, only a C++11 capable compiler. The development is done using GCC 4.8 and 5.2. The Python bindings are only tested on Python 3. 13 | 14 | For the Python bindings, you will need 15 | numpy 16 | Cython 17 | 18 | Installation 19 | ************ 20 | Right now, pyRFR is not available on PyPI. To install the Python bindings, execute the following commands: 21 | 22 | :bash:`git clone git@bitbucket.org:aadfreiburg/random_forest_run.git` 23 | 24 | :bash:`cd random_forest_run` 25 | 26 | :bash:`python setup.py install --user` 27 | 28 | 29 | Usage 30 | ***** 31 | For now, the file 32 | 33 | :bash:`./examples/pyrfr_simple_examples.py` 34 | 35 | and the other python scritps inside the repository serves as the only real documentation of the Python bindings. 36 | -------------------------------------------------------------------------------- /docs/_sources/regression.txt: -------------------------------------------------------------------------------- 1 | Regression 2 | ********** 3 | 4 | .. automodule:: pyrfr.regression 5 | :members: 6 | :undoc-members: 7 | :inherited-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /docs/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/ajax-loader.gif -------------------------------------------------------------------------------- /docs/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/comment-bright.png -------------------------------------------------------------------------------- /docs/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/comment-close.png -------------------------------------------------------------------------------- /docs/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/comment.png -------------------------------------------------------------------------------- /docs/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/down-pressed.png -------------------------------------------------------------------------------- /docs/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/down.png -------------------------------------------------------------------------------- /docs/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/file.png -------------------------------------------------------------------------------- /docs/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/minus.png -------------------------------------------------------------------------------- /docs/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/plus.png -------------------------------------------------------------------------------- /docs/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */ 8 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 9 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 10 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ 11 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 12 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 14 | .highlight .ge { font-style: italic } /* Generic.Emph */ 15 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 18 | .highlight .go { color: #333333 } /* Generic.Output */ 19 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 20 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 23 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 24 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 25 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 26 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 27 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 28 | .highlight .kt { color: #902000 } /* Keyword.Type */ 29 | .highlight .m { color: #208050 } /* Literal.Number */ 30 | .highlight .s { color: #4070a0 } /* Literal.String */ 31 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 32 | .highlight .nb { color: #007020 } /* Name.Builtin */ 33 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 34 | .highlight .no { color: #60add5 } /* Name.Constant */ 35 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 36 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 37 | .highlight .ne { color: #007020 } /* Name.Exception */ 38 | .highlight .nf { color: #06287e } /* Name.Function */ 39 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 40 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 41 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 42 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 43 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 45 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 46 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 47 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 48 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 49 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 50 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 51 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 52 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 53 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 54 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 55 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 56 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 57 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 58 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 59 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 60 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 61 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 62 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 63 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 64 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 65 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/up-pressed.png -------------------------------------------------------------------------------- /docs/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/_static/up.png -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/docs/objects.inv -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Search — pyrfr 0.5 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 49 | 50 |
51 |
52 |
53 |
54 | 55 |

Search

56 |
57 | 58 |

59 | Please activate JavaScript to enable the search 60 | functionality. 61 |

62 |
63 |

64 | From here you can search these documents. Enter your search 65 | words into the box below and click "search". Note that the search 66 | function will automatically search for all of the words. Pages 67 | containing fewer words won't appear in the result list. 68 |

69 |
70 | 71 | 72 | 73 |
74 | 75 |
76 | 77 |
78 | 79 |
80 |
81 |
82 | 86 |
87 |
88 | 100 | 104 | 105 | -------------------------------------------------------------------------------- /documentation/.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | -------------------------------------------------------------------------------- /documentation/index.rst: -------------------------------------------------------------------------------- 1 | .. pyrfr documentation master file, created by 2 | sphinx-quickstart on Thu Oct 29 21:12:22 2015. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to pyrfr's documentation! 7 | ================================= 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | installation.rst 15 | regression.rst 16 | 17 | 18 | 19 | Indices and tables 20 | ================== 21 | 22 | * :ref:`genindex` 23 | * :ref:`modindex` 24 | * :ref:`search` 25 | 26 | -------------------------------------------------------------------------------- /documentation/installation.rst: -------------------------------------------------------------------------------- 1 | ********* 2 | About pyRFR 3 | ********* 4 | .. role:: bash(code) 5 | :language: bash 6 | 7 | This package serves as the python interface to RFR, an extensible C++ librarry for random forests. 8 | 9 | Requirements 10 | ************ 11 | 12 | For the C++ library itself, you need no additional libaries, only a C++11 capable compiler. The development is done using GCC 4.8 and 5.2. The Python bindings are only tested on Python 3. 13 | 14 | For the Python bindings, you will need 15 | numpy 16 | Cython 17 | 18 | Installation 19 | ************ 20 | Right now, pyRFR is not available on PyPI. To install the Python bindings, execute the following commands: 21 | 22 | :bash:`git clone git@bitbucket.org:aadfreiburg/random_forest_run.git` 23 | 24 | :bash:`cd random_forest_run` 25 | 26 | :bash:`python setup.py install --user` 27 | 28 | 29 | Usage 30 | ***** 31 | For now, the file 32 | 33 | :bash:`./examples/pyrfr_simple_examples.py` 34 | 35 | and the other python scritps inside the repository serves as the only real documentation of the Python bindings. 36 | -------------------------------------------------------------------------------- /documentation/regression.rst: -------------------------------------------------------------------------------- 1 | Regression 2 | ********** 3 | 4 | .. automodule:: pyrfr.regression 5 | :members: 6 | :undoc-members: 7 | :inherited-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /include/cereal/details/polymorphic_impl_fwd.hpp: -------------------------------------------------------------------------------- 1 | /*! \file polymorphic_impl_fwd.hpp 2 | \brief Internal polymorphism support forward declarations 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* This code is heavily inspired by the boost serialization implementation by the following authors 32 | 33 | (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 34 | Use, modification and distribution is subject to the Boost Software 35 | License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) 36 | 37 | See http://www.boost.org for updates, documentation, and revision history. 38 | 39 | (C) Copyright 2006 David Abrahams - http://www.boost.org. 40 | 41 | See /boost/serialization/export.hpp and /boost/archive/detail/register_archive.hpp for their 42 | implementation. 43 | */ 44 | 45 | #ifndef CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 46 | #define CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 47 | 48 | namespace cereal 49 | { 50 | namespace detail 51 | { 52 | //! Forward declaration, see polymorphic_impl.hpp for more information 53 | template 54 | struct RegisterPolymorphicCaster; 55 | 56 | //! Forward declaration, see polymorphic_impl.hpp for more information 57 | struct PolymorphicCasters; 58 | 59 | //! Forward declaration, see polymorphic_impl.hpp for more information 60 | template 61 | struct PolymorphicRelation; 62 | } // namespace detail 63 | } // namespace cereal 64 | 65 | #endif // CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 66 | -------------------------------------------------------------------------------- /include/cereal/details/util.hpp: -------------------------------------------------------------------------------- 1 | /*! \file util.hpp 2 | \brief Internal misc utilities 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_DETAILS_UTIL_HPP_ 31 | #define CEREAL_DETAILS_UTIL_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | #ifdef _MSC_VER 37 | namespace cereal 38 | { 39 | namespace util 40 | { 41 | //! Demangles the type encoded in a string 42 | /*! @internal */ 43 | inline std::string demangle( std::string const & name ) 44 | { return name; } 45 | 46 | //! Gets the demangled name of a type 47 | /*! @internal */ 48 | template inline 49 | std::string demangledName() 50 | { return typeid( T ).name(); } 51 | } // namespace util 52 | } // namespace cereal 53 | #else // clang or gcc 54 | #include 55 | #include 56 | namespace cereal 57 | { 58 | namespace util 59 | { 60 | //! Demangles the type encoded in a string 61 | /*! @internal */ 62 | inline std::string demangle(std::string mangledName) 63 | { 64 | int status = 0; 65 | char *demangledName = nullptr; 66 | std::size_t len; 67 | 68 | demangledName = abi::__cxa_demangle(mangledName.c_str(), 0, &len, &status); 69 | 70 | std::string retName(demangledName); 71 | free(demangledName); 72 | 73 | return retName; 74 | } 75 | 76 | //! Gets the demangled name of a type 77 | /*! @internal */ 78 | template inline 79 | std::string demangledName() 80 | { return demangle(typeid(T).name()); } 81 | } 82 | } // namespace cereal 83 | #endif // clang or gcc branch of _MSC_VER 84 | #endif // CEREAL_DETAILS_UTIL_HPP_ 85 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/error/en.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_ERROR_EN_H_ 16 | #define CEREAL_RAPIDJSON_ERROR_EN_H_ 17 | 18 | #include "error.h" 19 | 20 | #ifdef __clang__ 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(switch-enum) 23 | CEREAL_RAPIDJSON_DIAG_OFF(covered-switch-default) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Maps error code of parsing into error message. 29 | /*! 30 | \ingroup CEREAL_RAPIDJSON_ERRORS 31 | \param parseErrorCode Error code obtained in parsing. 32 | \return the error message. 33 | \note User can make a copy of this function for localization. 34 | Using switch-case is safer for future modification of error codes. 35 | */ 36 | inline const CEREAL_RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { 37 | switch (parseErrorCode) { 38 | case kParseErrorNone: return CEREAL_RAPIDJSON_ERROR_STRING("No error."); 39 | 40 | case kParseErrorDocumentEmpty: return CEREAL_RAPIDJSON_ERROR_STRING("The document is empty."); 41 | case kParseErrorDocumentRootNotSingular: return CEREAL_RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); 42 | 43 | case kParseErrorValueInvalid: return CEREAL_RAPIDJSON_ERROR_STRING("Invalid value."); 44 | 45 | case kParseErrorObjectMissName: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a name for object member."); 46 | case kParseErrorObjectMissColon: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); 47 | case kParseErrorObjectMissCommaOrCurlyBracket: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); 48 | 49 | case kParseErrorArrayMissCommaOrSquareBracket: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); 50 | 51 | case kParseErrorStringUnicodeEscapeInvalidHex: return CEREAL_RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); 52 | case kParseErrorStringUnicodeSurrogateInvalid: return CEREAL_RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); 53 | case kParseErrorStringEscapeInvalid: return CEREAL_RAPIDJSON_ERROR_STRING("Invalid escape character in string."); 54 | case kParseErrorStringMissQuotationMark: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); 55 | case kParseErrorStringInvalidEncoding: return CEREAL_RAPIDJSON_ERROR_STRING("Invalid encoding in string."); 56 | 57 | case kParseErrorNumberTooBig: return CEREAL_RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); 58 | case kParseErrorNumberMissFraction: return CEREAL_RAPIDJSON_ERROR_STRING("Miss fraction part in number."); 59 | case kParseErrorNumberMissExponent: return CEREAL_RAPIDJSON_ERROR_STRING("Miss exponent in number."); 60 | 61 | case kParseErrorTermination: return CEREAL_RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); 62 | case kParseErrorUnspecificSyntaxError: return CEREAL_RAPIDJSON_ERROR_STRING("Unspecific syntax error."); 63 | 64 | default: return CEREAL_RAPIDJSON_ERROR_STRING("Unknown error."); 65 | } 66 | } 67 | 68 | CEREAL_RAPIDJSON_NAMESPACE_END 69 | 70 | #ifdef __clang__ 71 | CEREAL_RAPIDJSON_DIAG_POP 72 | #endif 73 | 74 | #endif // CEREAL_RAPIDJSON_ERROR_EN_H_ 75 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_FILEREADSTREAM_H_ 16 | #define CEREAL_RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 25 | CEREAL_RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | CEREAL_RAPIDJSON_ASSERT(fp_ != 0); 46 | CEREAL_RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 56 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | CEREAL_RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | CEREAL_RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // CEREAL_RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_FILEWRITESTREAM_H_ 16 | #define CEREAL_RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for input using fread(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | CEREAL_RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | CEREAL_RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | CEREAL_RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // CEREAL_RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_IEEE754_ 16 | #define CEREAL_RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | CEREAL_RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static unsigned EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return static_cast(order) + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = CEREAL_RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = CEREAL_RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = CEREAL_RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = CEREAL_RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | CEREAL_RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // CEREAL_RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_POW10_ 16 | #define CEREAL_RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | CEREAL_RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | CEREAL_RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // CEREAL_RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Custom strlen() which works on different character types. 24 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 25 | \param s Null-terminated input string. 26 | \return Number of characters in the string. 27 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 28 | */ 29 | template 30 | inline SizeType StrLen(const Ch* s) { 31 | const Ch* p = s; 32 | while (*p) ++p; 33 | return SizeType(p - s); 34 | } 35 | 36 | //! Returns number of code points in a encoded string. 37 | template 38 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 39 | GenericStringStream is(s); 40 | const typename Encoding::Ch* end = s + length; 41 | SizeType count = 0; 42 | while (is.src_ < end) { 43 | unsigned codepoint; 44 | if (!Encoding::Decode(is, &codepoint)) 45 | return false; 46 | count++; 47 | } 48 | *outCount = count; 49 | return true; 50 | } 51 | 52 | } // namespace internal 53 | CEREAL_RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 56 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) CEREAL_RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | CEREAL_RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | CEREAL_RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/istreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_ 16 | #define CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | #ifdef _MSC_VER 27 | CEREAL_RAPIDJSON_DIAG_PUSH 28 | CEREAL_RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized 29 | CEREAL_RAPIDJSON_DIAG_OFF(4127) // ignore assert(false) for triggering exception 30 | #endif 31 | 32 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. 35 | /*! 36 | The classes can be wrapped including but not limited to: 37 | 38 | - \c std::istringstream 39 | - \c std::stringstream 40 | - \c std::wistringstream 41 | - \c std::wstringstream 42 | - \c std::ifstream 43 | - \c std::fstream 44 | - \c std::wifstream 45 | - \c std::wfstream 46 | 47 | \tparam StreamType Class derived from \c std::basic_istream. 48 | */ 49 | 50 | template 51 | class BasicIStreamWrapper { 52 | public: 53 | typedef typename StreamType::char_type Ch; 54 | BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {} 55 | 56 | Ch Peek() const { 57 | typename StreamType::int_type c = stream_.peek(); 58 | return CEREAL_RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast(c) : '\0'; 59 | } 60 | 61 | Ch Take() { 62 | typename StreamType::int_type c = stream_.get(); 63 | if (CEREAL_RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) { 64 | count_++; 65 | return static_cast(c); 66 | } 67 | else 68 | return '\0'; 69 | } 70 | 71 | // tellg() may return -1 when failed. So we count by ourself. 72 | size_t Tell() const { return count_; } 73 | 74 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 75 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 76 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 77 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 78 | 79 | // For encoding detection only. 80 | const Ch* Peek4() const { 81 | CEREAL_RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream. 82 | int i; 83 | bool hasError = false; 84 | for (i = 0; i < 4; ++i) { 85 | typename StreamType::int_type c = stream_.get(); 86 | if (c == StreamType::traits_type::eof()) { 87 | hasError = true; 88 | stream_.clear(); 89 | break; 90 | } 91 | peekBuffer_[i] = static_cast(c); 92 | } 93 | for (--i; i >= 0; --i) 94 | stream_.putback(peekBuffer_[i]); 95 | return !hasError ? peekBuffer_ : 0; 96 | } 97 | 98 | private: 99 | BasicIStreamWrapper(const BasicIStreamWrapper&); 100 | BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); 101 | 102 | StreamType& stream_; 103 | size_t count_; //!< Number of characters read. Note: 104 | mutable Ch peekBuffer_[4]; 105 | }; 106 | 107 | typedef BasicIStreamWrapper IStreamWrapper; 108 | typedef BasicIStreamWrapper WIStreamWrapper; 109 | 110 | #if defined(__clang__) || defined(_MSC_VER) 111 | CEREAL_RAPIDJSON_DIAG_POP 112 | #endif 113 | 114 | CEREAL_RAPIDJSON_NAMESPACE_END 115 | 116 | #endif // CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_ 117 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 16 | #define CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | CEREAL_RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_MEMORYSTREAM_H_ 16 | #define CEREAL_RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 23 | CEREAL_RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | #ifdef _MSC_VER 27 | CEREAL_RAPIDJSON_DIAG_PUSH 28 | CEREAL_RAPIDJSON_DIAG_OFF( 4127 ) // ignore assert(false) for triggering exception 29 | #endif 30 | 31 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | //! Represents an in-memory input byte stream. 34 | /*! 35 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 36 | 37 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 38 | 39 | Differences between MemoryStream and StringStream: 40 | 1. StringStream has encoding but MemoryStream is a byte stream. 41 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 42 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 43 | \note implements Stream concept 44 | */ 45 | struct MemoryStream { 46 | typedef char Ch; // byte 47 | 48 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 49 | 50 | Ch Peek() const { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 51 | Ch Take() { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 52 | size_t Tell() const { return static_cast(src_ - begin_); } 53 | 54 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 55 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 56 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 57 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 58 | 59 | // For encoding detection only. 60 | const Ch* Peek4() const { 61 | return Tell() + 4 <= size_ ? src_ : 0; 62 | } 63 | 64 | const Ch* src_; //!< Current read position. 65 | const Ch* begin_; //!< Original head of the string. 66 | const Ch* end_; //!< End of stream. 67 | size_t size_; //!< Size of the stream. 68 | }; 69 | 70 | CEREAL_RAPIDJSON_NAMESPACE_END 71 | 72 | #if defined(__clang__) || defined(_MSC_VER) 73 | CEREAL_RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | #endif // CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 77 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | CEREAL_RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | CEREAL_RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_STRINGBUFFER_H_ 16 | #define CEREAL_RAPIDJSON_STRINGBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | #if CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS 22 | #include // std::move 23 | #endif 24 | 25 | #include "internal/stack.h" 26 | 27 | #if defined(__clang__) 28 | CEREAL_RAPIDJSON_DIAG_PUSH 29 | CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat) 30 | #endif 31 | 32 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Represents an in-memory output stream. 35 | /*! 36 | \tparam Encoding Encoding of the stream. 37 | \tparam Allocator type for allocating memory buffer. 38 | \note implements Stream concept 39 | */ 40 | template 41 | class GenericStringBuffer { 42 | public: 43 | typedef typename Encoding::Ch Ch; 44 | 45 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 46 | 47 | #if CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS 48 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} 49 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { 50 | if (&rhs != this) 51 | stack_ = std::move(rhs.stack_); 52 | return *this; 53 | } 54 | #endif 55 | 56 | void Put(Ch c) { *stack_.template Push() = c; } 57 | void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } 58 | void Flush() {} 59 | 60 | void Clear() { stack_.Clear(); } 61 | void ShrinkToFit() { 62 | // Push and pop a null terminator. This is safe. 63 | *stack_.template Push() = '\0'; 64 | stack_.ShrinkToFit(); 65 | stack_.template Pop(1); 66 | } 67 | 68 | void Reserve(size_t count) { stack_.template Reserve(count); } 69 | Ch* Push(size_t count) { return stack_.template Push(count); } 70 | Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } 71 | void Pop(size_t count) { stack_.template Pop(count); } 72 | 73 | const Ch* GetString() const { 74 | // Push and pop a null terminator. This is safe. 75 | *stack_.template Push() = '\0'; 76 | stack_.template Pop(1); 77 | 78 | return stack_.template Bottom(); 79 | } 80 | 81 | size_t GetSize() const { return stack_.GetSize(); } 82 | 83 | static const size_t kDefaultCapacity = 256; 84 | mutable internal::Stack stack_; 85 | 86 | private: 87 | // Prohibit copy constructor & assignment operator. 88 | GenericStringBuffer(const GenericStringBuffer&); 89 | GenericStringBuffer& operator=(const GenericStringBuffer&); 90 | }; 91 | 92 | //! String buffer with UTF8 encoding 93 | typedef GenericStringBuffer > StringBuffer; 94 | 95 | template 96 | inline void PutReserve(GenericStringBuffer& stream, size_t count) { 97 | stream.Reserve(count); 98 | } 99 | 100 | template 101 | inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { 102 | stream.PutUnsafe(c); 103 | } 104 | 105 | //! Implement specialized version of PutN() with memset() for better performance. 106 | template<> 107 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 108 | std::memset(stream.stack_.Push(n), c, n * sizeof(c)); 109 | } 110 | 111 | CEREAL_RAPIDJSON_NAMESPACE_END 112 | 113 | #if defined(__clang__) 114 | CEREAL_RAPIDJSON_DIAG_POP 115 | #endif 116 | 117 | #endif // CEREAL_RAPIDJSON_STRINGBUFFER_H_ 118 | -------------------------------------------------------------------------------- /include/cereal/external/rapidxml/license.txt: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /include/cereal/external/rapidxml/rapidxml_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CEREAL_RAPIDXML_UTILS_HPP_INCLUDED 2 | #define CEREAL_RAPIDXML_UTILS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective. 8 | 9 | #include "rapidxml.hpp" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace cereal { 16 | namespace rapidxml 17 | { 18 | 19 | //! Represents data loaded from a file 20 | template 21 | class file 22 | { 23 | 24 | public: 25 | 26 | //! Loads file into the memory. Data will be automatically destroyed by the destructor. 27 | //! \param filename Filename to load. 28 | file(const char *filename) 29 | { 30 | using namespace std; 31 | 32 | // Open stream 33 | basic_ifstream stream(filename, ios::binary); 34 | if (!stream) 35 | throw runtime_error(string("cannot open file ") + filename); 36 | stream.unsetf(ios::skipws); 37 | 38 | // Determine stream size 39 | stream.seekg(0, ios::end); 40 | size_t size = stream.tellg(); 41 | stream.seekg(0); 42 | 43 | // Load data and add terminating 0 44 | m_data.resize(size + 1); 45 | stream.read(&m_data.front(), static_cast(size)); 46 | m_data[size] = 0; 47 | } 48 | 49 | //! Loads file into the memory. Data will be automatically destroyed by the destructor 50 | //! \param stream Stream to load from 51 | file(std::basic_istream &stream) 52 | { 53 | using namespace std; 54 | 55 | // Load data and add terminating 0 56 | stream.unsetf(ios::skipws); 57 | m_data.assign(istreambuf_iterator(stream), istreambuf_iterator()); 58 | if (stream.fail() || stream.bad()) 59 | throw runtime_error("error reading stream"); 60 | m_data.push_back(0); 61 | } 62 | 63 | //! Gets file data. 64 | //! \return Pointer to data of file. 65 | Ch *data() 66 | { 67 | return &m_data.front(); 68 | } 69 | 70 | //! Gets file data. 71 | //! \return Pointer to data of file. 72 | const Ch *data() const 73 | { 74 | return &m_data.front(); 75 | } 76 | 77 | //! Gets file data size. 78 | //! \return Size of file data, in characters. 79 | std::size_t size() const 80 | { 81 | return m_data.size(); 82 | } 83 | 84 | private: 85 | 86 | std::vector m_data; // File data 87 | 88 | }; 89 | 90 | //! Counts children of node. Time complexity is O(n). 91 | //! \return Number of children of node 92 | template 93 | inline std::size_t count_children(xml_node *node) 94 | { 95 | xml_node *child = node->first_node(); 96 | std::size_t count = 0; 97 | while (child) 98 | { 99 | ++count; 100 | child = child->next_sibling(); 101 | } 102 | return count; 103 | } 104 | 105 | //! Counts attributes of node. Time complexity is O(n). 106 | //! \return Number of attributes of node 107 | template 108 | inline std::size_t count_attributes(xml_node *node) 109 | { 110 | xml_attribute *attr = node->first_attribute(); 111 | std::size_t count = 0; 112 | while (attr) 113 | { 114 | ++count; 115 | attr = attr->next_attribute(); 116 | } 117 | return count; 118 | } 119 | 120 | } 121 | } // namespace cereal 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /include/cereal/types/array.hpp: -------------------------------------------------------------------------------- 1 | /*! \file array.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_ARRAY_HPP_ 31 | #define CEREAL_TYPES_ARRAY_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::array primitive types 39 | //! using binary serialization, if supported 40 | template inline 41 | typename std::enable_if, Archive>::value 42 | && std::is_arithmetic::value, void>::type 43 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 44 | { 45 | ar( binary_data( array.data(), sizeof(array) ) ); 46 | } 47 | 48 | //! Loading for std::array primitive types 49 | //! using binary serialization, if supported 50 | template inline 51 | typename std::enable_if, Archive>::value 52 | && std::is_arithmetic::value, void>::type 53 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 54 | { 55 | ar( binary_data( array.data(), sizeof(array) ) ); 56 | } 57 | 58 | //! Saving for std::array all other types 59 | template inline 60 | typename std::enable_if, Archive>::value 61 | || !std::is_arithmetic::value, void>::type 62 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 63 | { 64 | for( auto const & i : array ) 65 | ar( i ); 66 | } 67 | 68 | //! Loading for std::array all other types 69 | template inline 70 | typename std::enable_if, Archive>::value 71 | || !std::is_arithmetic::value, void>::type 72 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 73 | { 74 | for( auto & i : array ) 75 | ar( i ); 76 | } 77 | } // namespace cereal 78 | 79 | #endif // CEREAL_TYPES_ARRAY_HPP_ 80 | -------------------------------------------------------------------------------- /include/cereal/types/chrono.hpp: -------------------------------------------------------------------------------- 1 | /*! \file chrono.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_CHRONO_HPP_ 31 | #define CEREAL_TYPES_CHRONO_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving std::chrono::duration 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::duration const & dur ) 40 | { 41 | ar( CEREAL_NVP_("count", dur.count()) ); 42 | } 43 | 44 | //! Loading std::chrono::duration 45 | template inline 46 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::duration & dur ) 47 | { 48 | R count; 49 | ar( CEREAL_NVP_("count", count) ); 50 | 51 | dur = std::chrono::duration{count}; 52 | } 53 | 54 | //! Saving std::chrono::time_point 55 | template inline 56 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::time_point const & dur ) 57 | { 58 | ar( CEREAL_NVP_("time_since_epoch", dur.time_since_epoch()) ); 59 | } 60 | 61 | //! Loading std::chrono::time_point 62 | template inline 63 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::time_point & dur ) 64 | { 65 | D elapsed; 66 | ar( CEREAL_NVP_("time_since_epoch", elapsed) ); 67 | 68 | dur = std::chrono::time_point{elapsed}; 69 | } 70 | } // namespace cereal 71 | 72 | #endif // CEREAL_TYPES_CHRONO_HPP_ 73 | -------------------------------------------------------------------------------- /include/cereal/types/complex.hpp: -------------------------------------------------------------------------------- 1 | /*! \file complex.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_COMPLEX_HPP_ 31 | #define CEREAL_TYPES_COMPLEX_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Serializing (save) for std::complex 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::complex const & comp ) 40 | { 41 | ar( CEREAL_NVP_("real", comp.real()), 42 | CEREAL_NVP_("imag", comp.imag()) ); 43 | } 44 | 45 | //! Serializing (load) for std::complex 46 | template inline 47 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::complex & bits ) 48 | { 49 | T real, imag; 50 | ar( CEREAL_NVP_("real", real), 51 | CEREAL_NVP_("imag", imag) ); 52 | bits = {real, imag}; 53 | } 54 | } // namespace cereal 55 | 56 | #endif // CEREAL_TYPES_COMPLEX_HPP_ 57 | -------------------------------------------------------------------------------- /include/cereal/types/concepts/pair_associative_container.hpp: -------------------------------------------------------------------------------- 1 | /*! \file pair_associative_container.hpp 2 | \brief Support for the PairAssociativeContainer refinement of the 3 | AssociativeContainer concept. 4 | \ingroup TypeConcepts */ 5 | /* 6 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of cereal nor the 17 | names of its contributors may be used to endorse or promote products 18 | derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 24 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 32 | #define CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 33 | 34 | #include "cereal/cereal.hpp" 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std-like pair associative containers 39 | template class Map, typename... Args, typename = typename Map::mapped_type> inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, Map const & map ) 41 | { 42 | ar( make_size_tag( static_cast(map.size()) ) ); 43 | 44 | for( const auto & i : map ) 45 | ar( make_map_item(i.first, i.second) ); 46 | } 47 | 48 | //! Loading for std-like pair associative containers 49 | template class Map, typename... Args, typename = typename Map::mapped_type> inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, Map & map ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | map.clear(); 56 | 57 | auto hint = map.begin(); 58 | for( size_t i = 0; i < size; ++i ) 59 | { 60 | typename Map::key_type key; 61 | typename Map::mapped_type value; 62 | 63 | ar( make_map_item(key, value) ); 64 | #ifdef CEREAL_OLDER_GCC 65 | hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) ); 66 | #else // NOT CEREAL_OLDER_GCC 67 | hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); 68 | #endif // NOT CEREAL_OLDER_GCC 69 | } 70 | } 71 | } // namespace cereal 72 | 73 | #endif // CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 74 | -------------------------------------------------------------------------------- /include/cereal/types/deque.hpp: -------------------------------------------------------------------------------- 1 | /*! \file deque.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_DEQUE_HPP_ 31 | #define CEREAL_TYPES_DEQUE_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::deque 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::deque const & deque ) 41 | { 42 | ar( make_size_tag( static_cast(deque.size()) ) ); 43 | 44 | for( auto const & i : deque ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::deque 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::deque & deque ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | deque.resize( static_cast( size ) ); 56 | 57 | for( auto & i : deque ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_DEQUE_HPP_ 63 | -------------------------------------------------------------------------------- /include/cereal/types/forward_list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file forward_list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FORWARD_LIST_HPP_ 31 | #define CEREAL_TYPES_FORWARD_LIST_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::forward_list all other types 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::forward_list const & forward_list ) 41 | { 42 | // write the size - note that this is slow because we need to traverse 43 | // the entire list. there are ways we could avoid this but this was chosen 44 | // since it works in the most general fashion with any archive type 45 | size_type const size = std::distance( forward_list.begin(), forward_list.end() ); 46 | 47 | ar( make_size_tag( size ) ); 48 | 49 | // write the list 50 | for( const auto & i : forward_list ) 51 | ar( i ); 52 | } 53 | 54 | //! Loading for std::forward_list all other types from 55 | template 56 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::forward_list & forward_list ) 57 | { 58 | size_type size; 59 | ar( make_size_tag( size ) ); 60 | 61 | forward_list.resize( static_cast( size ) ); 62 | 63 | for( auto & i : forward_list ) 64 | ar( i ); 65 | } 66 | } // namespace cereal 67 | 68 | #endif // CEREAL_TYPES_FORWARD_LIST_HPP_ 69 | -------------------------------------------------------------------------------- /include/cereal/types/functional.hpp: -------------------------------------------------------------------------------- 1 | /*! \file functional.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2016, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FUNCTIONAL_HPP_ 31 | #define CEREAL_TYPES_FUNCTIONAL_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving for std::less 38 | template inline 39 | void serialize( Archive &, std::less & ) 40 | { } 41 | } // namespace cereal 42 | 43 | #endif // CEREAL_TYPES_FUNCTIONAL_HPP_ 44 | -------------------------------------------------------------------------------- /include/cereal/types/list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_LIST_HPP_ 31 | #define CEREAL_TYPES_LIST_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::list 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::list const & list ) 41 | { 42 | ar( make_size_tag( static_cast(list.size()) ) ); 43 | 44 | for( auto const & i : list ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::list 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::list & list ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | list.resize( static_cast( size ) ); 56 | 57 | for( auto & i : list ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_LIST_HPP_ 63 | -------------------------------------------------------------------------------- /include/cereal/types/map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_MAP_HPP_ 31 | #define CEREAL_TYPES_MAP_HPP_ 32 | 33 | #include "cereal/types/concepts/pair_associative_container.hpp" 34 | #include 35 | 36 | #endif // CEREAL_TYPES_MAP_HPP_ 37 | -------------------------------------------------------------------------------- /include/cereal/types/set.hpp: -------------------------------------------------------------------------------- 1 | /*! \file set.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_SET_HPP_ 31 | #define CEREAL_TYPES_SET_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace set_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, SetT const & set ) 43 | { 44 | ar( make_size_tag( static_cast(set.size()) ) ); 45 | 46 | for( const auto & i : set ) 47 | ar( i ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, SetT & set ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | set.clear(); 58 | 59 | auto hint = set.begin(); 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename SetT::key_type key; 63 | 64 | ar( key ); 65 | #ifdef CEREAL_OLDER_GCC 66 | hint = set.insert( hint, std::move( key ) ); 67 | #else // NOT CEREAL_OLDER_GCC 68 | hint = set.emplace_hint( hint, std::move( key ) ); 69 | #endif // NOT CEREAL_OLDER_GCC 70 | } 71 | } 72 | } 73 | 74 | //! Saving for std::set 75 | template inline 76 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::set const & set ) 77 | { 78 | set_detail::save( ar, set ); 79 | } 80 | 81 | //! Loading for std::set 82 | template inline 83 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::set & set ) 84 | { 85 | set_detail::load( ar, set ); 86 | } 87 | 88 | //! Saving for std::multiset 89 | template inline 90 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::multiset const & multiset ) 91 | { 92 | set_detail::save( ar, multiset ); 93 | } 94 | 95 | //! Loading for std::multiset 96 | template inline 97 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::multiset & multiset ) 98 | { 99 | set_detail::load( ar, multiset ); 100 | } 101 | } // namespace cereal 102 | 103 | #endif // CEREAL_TYPES_SET_HPP_ 104 | -------------------------------------------------------------------------------- /include/cereal/types/stack.hpp: -------------------------------------------------------------------------------- 1 | /*! \file stack.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STACK_HPP_ 31 | #define CEREAL_TYPES_STACK_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | // The default container for stack is deque, so let's include that too 37 | #include "cereal/types/deque.hpp" 38 | 39 | namespace cereal 40 | { 41 | namespace stack_detail 42 | { 43 | //! Allows access to the protected container in stack 44 | template inline 45 | C const & container( std::stack const & stack ) 46 | { 47 | struct H : public std::stack 48 | { 49 | static C const & get( std::stack const & s ) 50 | { 51 | return s.*(&H::c); 52 | } 53 | }; 54 | 55 | return H::get( stack ); 56 | } 57 | } 58 | 59 | //! Saving for std::stack 60 | template inline 61 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::stack const & stack ) 62 | { 63 | ar( CEREAL_NVP_("container", stack_detail::container( stack )) ); 64 | } 65 | 66 | //! Loading for std::stack 67 | template inline 68 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::stack & stack ) 69 | { 70 | C container; 71 | ar( CEREAL_NVP_("container", container) ); 72 | stack = std::stack( std::move( container ) ); 73 | } 74 | } // namespace cereal 75 | 76 | #endif // CEREAL_TYPES_STACK_HPP_ 77 | -------------------------------------------------------------------------------- /include/cereal/types/string.hpp: -------------------------------------------------------------------------------- 1 | /*! \file string.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STRING_HPP_ 31 | #define CEREAL_TYPES_STRING_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serialization for basic_string types, if binary data is supported 39 | template inline 40 | typename std::enable_if, Archive>::value, void>::type 41 | CEREAL_SAVE_FUNCTION_NAME(Archive & ar, std::basic_string const & str) 42 | { 43 | // Save number of chars + the data 44 | ar( make_size_tag( static_cast(str.size()) ) ); 45 | ar( binary_data( str.data(), str.size() * sizeof(CharT) ) ); 46 | } 47 | 48 | //! Serialization for basic_string types, if binary data is supported 49 | template inline 50 | typename std::enable_if, Archive>::value, void>::type 51 | CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string & str) 52 | { 53 | size_type size; 54 | ar( make_size_tag( size ) ); 55 | str.resize(static_cast(size)); 56 | ar( binary_data( const_cast( str.data() ), static_cast(size) * sizeof(CharT) ) ); 57 | } 58 | } // namespace cereal 59 | 60 | #endif // CEREAL_TYPES_STRING_HPP_ 61 | 62 | -------------------------------------------------------------------------------- /include/cereal/types/unordered_map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file unordered_map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UNORDERED_MAP_HPP_ 31 | #define CEREAL_TYPES_UNORDERED_MAP_HPP_ 32 | 33 | #include "cereal/types/concepts/pair_associative_container.hpp" 34 | #include 35 | 36 | #endif // CEREAL_TYPES_UNORDERED_MAP_HPP_ 37 | -------------------------------------------------------------------------------- /include/cereal/types/unordered_set.hpp: -------------------------------------------------------------------------------- 1 | /*! \file unordered_set.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UNORDERED_SET_HPP_ 31 | #define CEREAL_TYPES_UNORDERED_SET_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace unordered_set_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, SetT const & set ) 43 | { 44 | ar( make_size_tag( static_cast(set.size()) ) ); 45 | 46 | for( const auto & i : set ) 47 | ar( i ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, SetT & set ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | set.clear(); 58 | set.reserve( static_cast( size ) ); 59 | 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename SetT::key_type key; 63 | 64 | ar( key ); 65 | set.emplace( std::move( key ) ); 66 | } 67 | } 68 | } 69 | 70 | //! Saving for std::unordered_set 71 | template inline 72 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_set const & unordered_set ) 73 | { 74 | unordered_set_detail::save( ar, unordered_set ); 75 | } 76 | 77 | //! Loading for std::unordered_set 78 | template inline 79 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_set & unordered_set ) 80 | { 81 | unordered_set_detail::load( ar, unordered_set ); 82 | } 83 | 84 | //! Saving for std::unordered_multiset 85 | template inline 86 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_multiset const & unordered_multiset ) 87 | { 88 | unordered_set_detail::save( ar, unordered_multiset ); 89 | } 90 | 91 | //! Loading for std::unordered_multiset 92 | template inline 93 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_multiset & unordered_multiset ) 94 | { 95 | unordered_set_detail::load( ar, unordered_multiset ); 96 | } 97 | } // namespace cereal 98 | 99 | #endif // CEREAL_TYPES_UNORDERED_SET_HPP_ 100 | -------------------------------------------------------------------------------- /include/cereal/types/utility.hpp: -------------------------------------------------------------------------------- 1 | /*! \file utility.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UTILITY_HPP_ 31 | #define CEREAL_TYPES_UTILITY_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serializing for std::pair 39 | template inline 40 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, std::pair & pair ) 41 | { 42 | ar( CEREAL_NVP_("first", pair.first), 43 | CEREAL_NVP_("second", pair.second) ); 44 | } 45 | } // namespace cereal 46 | 47 | #endif // CEREAL_TYPES_UTILITY_HPP_ 48 | -------------------------------------------------------------------------------- /include/cereal/types/valarray.hpp: -------------------------------------------------------------------------------- 1 | /*! \file valarray.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | 5 | /* 6 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of cereal nor the 17 | names of its contributors may be used to endorse or promote products 18 | derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 24 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef CEREAL_TYPES_VALARRAY_HPP_ 33 | #define CEREAL_TYPES_VALARRAY_HPP_ 34 | 35 | #include "cereal/cereal.hpp" 36 | #include 37 | 38 | namespace cereal 39 | { 40 | //! Saving for std::valarray arithmetic types, using binary serialization, if supported 41 | template inline 42 | typename std::enable_if, Archive>::value 43 | && std::is_arithmetic::value, void>::type 44 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray const & valarray ) 45 | { 46 | ar( make_size_tag( static_cast(valarray.size()) ) ); // number of elements 47 | ar( binary_data( &valarray[0], valarray.size() * sizeof(T) ) ); // &valarray[0] ok since guaranteed contiguous 48 | } 49 | 50 | //! Loading for std::valarray arithmetic types, using binary serialization, if supported 51 | template inline 52 | typename std::enable_if, Archive>::value 53 | && std::is_arithmetic::value, void>::type 54 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray & valarray ) 55 | { 56 | size_type valarraySize; 57 | ar( make_size_tag( valarraySize ) ); 58 | 59 | valarray.resize( static_cast( valarraySize ) ); 60 | ar( binary_data( &valarray[0], static_cast( valarraySize ) * sizeof(T) ) ); 61 | } 62 | 63 | //! Saving for std::valarray all other types 64 | template inline 65 | typename std::enable_if, Archive>::value 66 | || !std::is_arithmetic::value, void>::type 67 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray const & valarray ) 68 | { 69 | ar( make_size_tag( static_cast(valarray.size()) ) ); // number of elements 70 | for(auto && v : valarray) 71 | ar(v); 72 | } 73 | 74 | //! Loading for std::valarray all other types 75 | template inline 76 | typename std::enable_if, Archive>::value 77 | || !std::is_arithmetic::value, void>::type 78 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray & valarray ) 79 | { 80 | size_type valarraySize; 81 | ar( make_size_tag( valarraySize ) ); 82 | 83 | valarray.resize( static_cast( valarraySize ) ); 84 | for(auto && v : valarray) 85 | ar(v); 86 | } 87 | } // namespace cereal 88 | 89 | #endif // CEREAL_TYPES_VALARRAY_HPP_ 90 | -------------------------------------------------------------------------------- /include/rfr/data_containers/array_wrapper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RFR_ARRAY_CONTAINER_HPP 2 | #define RFR_ARRAY_CONTAINER_HPP 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | namespace rfr{ namespace data_containers{ 11 | 12 | template 13 | class array_data_container : public rfr::data_containers::data_container_base{ 14 | 15 | private: 16 | index_type n_data_points; 17 | index_type n_features; 18 | num_type * feature_array; 19 | response_type * response_array; 20 | index_type * type_array; 21 | index_type response_t; 22 | 23 | public: 24 | 25 | array_data_container( num_type * features, 26 | response_type * responses, 27 | index_type * types, 28 | index_type n_data_points, 29 | index_type n_features): 30 | 31 | n_data_points(n_data_points), 32 | n_features(n_features), 33 | feature_array(features), 34 | response_array(responses), 35 | type_array(types), 36 | response_t(0){ 37 | 38 | //properly round the feature values for categorical features 39 | for (auto i=0u; i 0){ 41 | for (auto j=0u; j < n_data_points; j++) 42 | feature_array[j*n_features + i] = std::round(feature_array[j*n_features + i]); 43 | } 44 | } 45 | } 46 | 47 | virtual ~array_data_container() {}; 48 | 49 | virtual num_type feature (index_type feature_index, index_type sample_index) const { 50 | return (feature_array[sample_index*n_features + feature_index]); 51 | } 52 | 53 | 54 | virtual std::vector features (index_type feature_index, std::vector &sample_indices) const { 55 | std::vector rv; 56 | rv.reserve(sample_indices.size()); 57 | 58 | for (auto i: sample_indices) 59 | rv.push_back(feature_array[i*n_features+feature_index]); 60 | 61 | return(rv); 62 | } 63 | 64 | 65 | virtual response_type response (index_type sample_index) const{ 66 | return (response_array[sample_index]); 67 | } 68 | 69 | virtual void add_data_point (num_type* features, index_type num_elements, response_type response){ 70 | throw std::runtime_error("Array data containers do not support adding new data points."); 71 | } 72 | 73 | virtual std::vector retrieve_data_point (index_type index) const{ 74 | std::vector rv(n_features); 75 | for (auto i = 0u; i < rv.size(); i++) 76 | rv[i] = feature_array[index*n_features + i]; 77 | return(rv); 78 | } 79 | 80 | virtual index_type get_type_of_feature (index_type feature_index) const{ 81 | return(type_array[feature_index]); 82 | } 83 | 84 | virtual void set_type_of_feature (index_type feature_index, index_type feature_type){ 85 | throw std::runtime_error("Array data containers do not support changing a feature type."); 86 | } 87 | 88 | 89 | virtual index_type get_type_of_response () const{ 90 | return(response_t); 91 | } 92 | 93 | virtual void set_type_of_response (index_type resp_t){ 94 | if (resp_t > 0){ 95 | for (auto i=0u; i < n_data_points; i++){ 96 | if (!(response_array[i] < resp_t)) 97 | throw std::runtime_error("Response value not consistent with provided type. Data contains a value larger than allowed."); 98 | if (response_array[i] < 0) 99 | throw std::runtime_error("Response values contain a negative value, can't make that a categorical value."); 100 | } 101 | response_t = resp_t; 102 | } 103 | } 104 | 105 | 106 | virtual index_type num_features() const {return(n_features);} 107 | virtual index_type num_data_points() const {return(n_data_points);} 108 | }; 109 | 110 | }} // namespace rfr 111 | #endif // RFR_ARRAY_CONTAINER_HPP 112 | -------------------------------------------------------------------------------- /include/rfr/data_containers/data_container_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RFR_DATA_CONTAINER_UTIL_HPP 2 | #define RFR_DATA_CONTAINER_UTIL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace rfr{ 12 | 13 | 14 | /** \brief A utility function that reads a csv file containing only numerical values 15 | * 16 | * A very common use case should be reading the 'training data' from a file in csv format. This function does that assuming that each row has the same number of entries. It does NOT read any header information. 17 | * 18 | * \param filename the CSV file to be read 19 | * \return The data in a 2d 'array' ready to be used by the data container classes 20 | * 21 | */ 22 | template 23 | std::vector< std::vector > read_csv_file( std::string filename){ 24 | 25 | std::vector< std::vector > csv_values; 26 | 27 | std::fstream file(filename, std::ios::in); 28 | if (file) 29 | { 30 | std::string line; 31 | while (std::getline(file, line)){ 32 | size_t i=0; 33 | std::istringstream s(line); 34 | std::string field; 35 | while (std::getline(s, field,',')){ 36 | if (i==csv_values.size()){ 37 | csv_values.push_back( std::vector(1,strtod(field.c_str(), 0))); 38 | } 39 | else{ 40 | // convert data into double value, and store 41 | (csv_values[i]).push_back(strtod(field.c_str(), 0)); 42 | } 43 | i++; 44 | } 45 | } 46 | } 47 | else 48 | throw std::runtime_error("Couldn't open file " + filename); 49 | return(csv_values); 50 | } 51 | 52 | template 53 | void print_vector(const std::vector &v) { 54 | for(auto it = v.begin(); it!=v.end(); it++) 55 | std::cout<<*it<<" "; 56 | std::cout< 61 | void print_matrix(const std::vector > &v) { 62 | for(auto it = v.begin(); it!=v.end(); it++) 63 | print_vector(*it); 64 | } 65 | 66 | 67 | } // namespace rfr 68 | #endif // RFR_DATA_CONTAINER_UTIL_HPP 69 | -------------------------------------------------------------------------------- /include/rfr/forests/classification_forest.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RFR_CLASSIFICATION_FOREST_HPP 2 | #define RFR_CLASSIFICATION_FOREST_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | #include "rfr/trees/tree_options.hpp" 14 | #include "rfr/forests/forest_options.hpp" 15 | 16 | namespace rfr{ namespace forests{ 17 | 18 | 19 | template 20 | class classification_forest{ 21 | private: 22 | forest_options forest_opts; 23 | 24 | std::vector the_trees; 25 | 26 | public: 27 | 28 | classification_forest(forest_options forest_opts): forest_opts(forest_opts){ 29 | the_trees.resize(forest_opts.num_trees); 30 | } 31 | 32 | void fit(const rfr::data_containers::data_container_base &data, rng_type &rng){ 33 | 34 | if ((!forest_opts.do_bootstrapping) && (data.num_data_points() < forest_opts.num_data_points_per_tree)){ 35 | std::cout<<"You cannot use more data points per tree than actual data point present without bootstrapping!"; 36 | return; 37 | } 38 | 39 | std::vector data_indices( data.num_data_points()); 40 | std::iota(data_indices.begin(), data_indices.end(), 0); 41 | std::vector data_indices_to_be_used( forest_opts.num_data_points_per_tree); 42 | 43 | for (auto &tree : the_trees){ 44 | // prepare the data(sub)set 45 | if (forest_opts.do_bootstrapping){ 46 | std::uniform_int_distribution dist (0,data.num_data_points()-1); 47 | auto dice = std::bind(dist, rng); 48 | std::generate_n(data_indices_to_be_used.begin(), data_indices_to_be_used.size(), dice); 49 | } 50 | else{ 51 | std::shuffle(data_indices.begin(), data_indices.end(), rng); 52 | data_indices_to_be_used.assign(data_indices.begin(), data_indices.begin()+ forest_opts.num_data_points_per_tree); 53 | } 54 | tree.fit(data, forest_opts.tree_opts, data_indices_to_be_used, rng); 55 | } 56 | } 57 | 58 | 59 | /* \brief combines the prediction of all trees in the forest 60 | * 61 | * Every random tree makes an individual prediction. We want the estimated probability of membership 62 | * in each of the classes. 63 | */ 64 | std::tuple predict_class( num_type * feature_vector){ 65 | int max_class = *std::max_element(begin(data.response), end(data.response)); 66 | int min_class = *std::min_element(begin(data.response), end(data.response)); 67 | int length = max_class - min_class+1; 68 | std::vector classvector(length, 0); 69 | std::vector class_probs(length, 0); 70 | int N = 0; 71 | for (auto &tree: the_trees){ 72 | num_type c; 73 | 74 | c = tree.predict_class(feature_vector); 75 | // recompute the sum and the sum of squared response values 76 | classvector[c - min_class] += 1 ; 77 | N++; 78 | } 79 | for (int i = 0; i (class_probs); 83 | } 84 | 85 | void save_latex_representation(const char* filename_template){ 86 | for (auto i = 0u; i 15 | struct forest_options{ 16 | index_t num_trees; ///< number of trees in the forest 17 | index_t num_data_points_per_tree; ///< number of datapoints used in each tree 18 | 19 | bool do_bootstrapping; ///< flag to toggle bootstrapping 20 | bool compute_oob_error; ///< flag to enable/disable computing the out-of-bag error 21 | 22 | bool compute_law_of_total_variance; ///< flag to enable/disable computation with the lotv 23 | 24 | rfr::trees::tree_options tree_opts; ///< the options for each tree 25 | 26 | /* serialize function for saving forests */ 27 | template 28 | void serialize(Archive & archive) 29 | { 30 | archive( num_trees,num_data_points_per_tree, do_bootstrapping, compute_oob_error, tree_opts); 31 | } 32 | 33 | 34 | /** (Re)set to default values for the forest. 35 | * 36 | * 37 | */ 38 | void set_default_values(){ 39 | num_trees = 0; 40 | num_data_points_per_tree = 0; 41 | 42 | do_bootstrapping = true; 43 | compute_oob_error = false; 44 | compute_law_of_total_variance = true; 45 | 46 | } 47 | 48 | 49 | /** adjusts all relevant variables to the data */ 50 | void adjust_limits_to_data (const rfr::data_containers::base &data){ 51 | num_data_points_per_tree = data.num_data_points(); 52 | } 53 | 54 | /** Default constructor that initializes the values with their default */ 55 | forest_options(){ set_default_values(); tree_opts.set_default_values();} 56 | 57 | /** Constructor to feed in tree values but leave the forest parameters at their default.*/ 58 | forest_options(rfr::trees::tree_options & to): tree_opts(to) { set_default_values();} 59 | 60 | /** Constructor that adjusts to the data. */ 61 | forest_options (rfr::trees::tree_options & to, rfr::data_containers::base &data): tree_opts(to){ 62 | set_default_values(); 63 | tree_opts.set_default_values(); 64 | adjust_limits_to_data(data); 65 | } 66 | 67 | std::string to_string() const { 68 | std::string str = ""; 69 | str += " number of trees :" + std::to_string(num_trees) + "\n"; 70 | str += " number of data points :" + std::to_string(num_data_points_per_tree) + "\n"; 71 | str += " do_bootstrapping :" + std::to_string(do_bootstrapping) + "\n"; 72 | str += " min samples in leaf :" + std::to_string(tree_opts.min_samples_in_leaf) + "\n"; 73 | str += " life time :" + std::to_string(tree_opts.life_time) + "\n"; 74 | str += "compute_law_of_total_var:" + std::to_string(compute_law_of_total_variance) + "\n"; 75 | return str; 76 | } 77 | }; 78 | 79 | }}//namespace rfr::forests 80 | #endif 81 | -------------------------------------------------------------------------------- /include/rfr/forests/quantile_regression_forest.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RFR_QUANTILE_REGRESSION_FOREST_HPP 2 | #define RFR_QUANTILE_REGRESSION_FOREST_HPP 3 | 4 | #include "rfr/forests/regression_forest.hpp" 5 | 6 | namespace rfr{ namespace forests{ 7 | 8 | 9 | template 10 | class quantile_regression_forest: public rfr::forests::regression_forest { 11 | private: 12 | typedef rfr::forests::regression_forest super; 13 | 14 | public: 15 | 16 | quantile_regression_forest() : super() {}; 17 | quantile_regression_forest (forest_options forest_opts): super(forest_opts) {}; 18 | 19 | 20 | 21 | virtual ~quantile_regression_forest() {}; 22 | 23 | /* \brief implements the quantile regression forests of Meinshausen (2006) 24 | * 25 | * \param feature_vector you guessed it :) 26 | * \param quantiles a vector of all the quantiles to predict. 27 | * 28 | * \return std::vector list of the corresponding response values 29 | */ 30 | 31 | std::vector predict_quantiles (const std::vector &feature_vector, std::vector quantiles) const { 32 | 33 | std::sort(quantiles.begin(), quantiles.end()); 34 | 35 | if (*quantiles.begin() < 0) 36 | throw std::runtime_error("quantiles cannot be <0."); 37 | 38 | if (quantiles.back() > 1) 39 | throw std::runtime_error("quantiles cannot be >1."); 40 | 41 | 42 | std::vector > value_weight_pairs; 43 | 44 | for (auto &t: super::the_trees){ 45 | auto l = t.get_leaf(feature_vector); 46 | 47 | auto values = l.responses(); 48 | auto weights = l.weights(); 49 | 50 | auto stat = l.leaf_statistic(); 51 | 52 | num_t factor = 1./(stat.sum_of_weights()*super::the_trees.size()); 53 | for (auto i=0u; i &a, const std::pair &b) {return (a.first < b.first);} 59 | ); 60 | 61 | std::vector rv; 62 | rv.reserve(quantiles.size()); 63 | 64 | num_t tw = 0; 65 | index_t index = 0; 66 | 67 | for (auto q: quantiles){ 68 | while ( (index < value_weight_pairs.size()) && (tw < q) ){ 69 | tw += value_weight_pairs[index].second; 70 | index++; 71 | } 72 | 73 | auto mew = std::min(index, value_weight_pairs.size()-1); 74 | 75 | rv.push_back((value_weight_pairs[mew]).first); 76 | } 77 | 78 | return(rv); 79 | } 80 | 81 | }; 82 | 83 | 84 | }}//namespace rfr::forests 85 | #endif 86 | -------------------------------------------------------------------------------- /include/rfr/nodes/temporary_node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RFR_TEMPORARY_NODE_HPP 2 | #define RFR_TEMPORARY_NODE_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace rfr{ namespace nodes{ 9 | 10 | template 11 | /* \brief class to hold necessary information during the fitting of a tree 12 | * 13 | * When fitting a tree, every split creates two or more children. This class is used 14 | * to temporarily store all information needed to continue splitting. 15 | */ 16 | struct temporary_node{ 17 | 18 | index_t node_index; 19 | index_t parent_index; 20 | typename std::vector >::iterator begin, end; 21 | index_t node_level; 22 | 23 | 24 | /* \param note_id the unique ID of the node 25 | * \param b iterator to the first element of the data_info vector associated with the node 26 | * \param e iterator beyond the last element of the data_info vector associated with the node 27 | * \param node_lvl the node's level in the tree 28 | */ 29 | temporary_node (index_t node_id, index_t parent_id, index_t node_lvl, 30 | typename std::vector>::iterator b, 31 | typename std::vector>::iterator e): 32 | node_index(node_id), parent_index(parent_id), begin(b), end(e), node_level(node_lvl) 33 | {} 34 | 35 | 36 | num_t total_weight (){ 37 | num_t tw = 0.; 38 | for (auto it = begin; it != end; ++it){ 39 | tw += (*it).weight; 40 | } 41 | return(tw); 42 | } 43 | 44 | void print_info() const{ 45 | std::cout<<"node_index = "< 5 | #include 6 | #include 7 | #include "rfr/data_containers/data_container.hpp" 8 | 9 | 10 | 11 | namespace rfr{ namespace splits{ 12 | 13 | 14 | 15 | template 16 | struct data_info_t{ 17 | index_t index; 18 | response_t response; 19 | response_t prediction_value; 20 | num_t feature; 21 | num_t weight; 22 | 23 | data_info_t (): index(0), response(0), prediction_value(0), feature(NAN), weight(NAN) {} 24 | data_info_t (index_t i, response_t r, response_t p, num_t f, num_t w): index(i), response(r), prediction_value(p), feature(f), weight(w) {} 25 | }; 26 | 27 | 28 | 29 | 30 | template 31 | class k_ary_split_base{ 32 | public: 33 | 34 | virtual ~k_ary_split_base() {}; 35 | 36 | /** \brief member function to find the optimal split for a subset of the data and features 37 | * 38 | * Defining the interface that every split has to implement. Unfortunately, virtual constructors are 39 | * not allowed in C++, so this function is called instead. Code in the nodes and the tree will only use the 40 | * default constructor and the methods below for training and prediction. 41 | * 42 | * \param data the container holding the training data 43 | * \param features_to_try a vector with the indices of all the features that can be considered for this split 44 | * \param infos_begin iterator to the first data_info element to be considered 45 | * \param infos_end iterator beyond the last data_info element to be considered 46 | * \param info_split_its iterators into indices specifying where to split the data for the children. Number of iterators is k+1, for easier iteration 47 | * \param min_samples_in_child smallest acceptable number of samples in any of the children 48 | * \param min_weight_in_child smallest acceptable weight in any of the children 49 | * \param rng (pseudo) random number generator as a source for stochasticity 50 | * 51 | * \return float the loss of the found split 52 | */ 53 | 54 | virtual num_t find_best_split(const rfr::data_containers::base &data, 55 | const std::vector &features_to_try, 56 | typename std::vector >::iterator infos_begin, 57 | typename std::vector >::iterator infos_end, 58 | std::array >::iterator, k+1> &info_split_its, 59 | index_t min_samples_in_child, 60 | num_t min_weight_in_child, 61 | rng_t &rng) = 0; 62 | 63 | /** \brief tells into which child a given feature vector falls 64 | * 65 | * \param feature_vector an array containing a valid (in terms of size and values!) feature vector 66 | * 67 | * \return index_t index of the child into which this feature falls 68 | */ 69 | virtual index_t operator() (const std::vector &feature_vector) const = 0; 70 | 71 | /** \brief some debug output that prints a informative representation to std::cout*/ 72 | virtual void print_info() const = 0; 73 | 74 | /** \brief hopefully all trees can create a LaTeX document as a visualization, this contributes the text of the split.*/ 75 | virtual std::string latex_representation() const = 0; 76 | }; 77 | 78 | 79 | 80 | }}//namespace rfr::splits 81 | #endif 82 | -------------------------------------------------------------------------------- /include/rfr/trees/tree_base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RFR_TREE_BASE_HPP 2 | #define RFR_TREE_BASE_HPP 3 | 4 | #include 5 | 6 | #include "rfr/trees/tree_options.hpp" 7 | #include "rfr/data_containers/data_container.hpp" 8 | 9 | 10 | 11 | namespace rfr{ namespace trees{ 12 | 13 | template 14 | class tree_base{ 15 | public: 16 | 17 | virtual ~tree_base() {} 18 | 19 | /** \brief member function to fit the tree to the whole data 20 | * 21 | * The interface is very general, and allows for deterministic and randomized decision tree at this point. 22 | * For a random forest, some randomness has to be introduced, and the number of features 23 | * considered for every step has to be set to be less than actual the number. In its 24 | * standard implementation this function just calls the second fit method with an indicex vector = [0, ..., num_data_points-1]. 25 | * 26 | * 27 | * \param data the container holding the training data 28 | * \param tree_opts a tree_options opject that controls certain aspects of "growing" the tree 29 | * \param rng a (pseudo) random number generator 30 | */ 31 | virtual void fit(const rfr::data_containers::base &data, 32 | rfr::trees::tree_options tree_opts, 33 | rng_type &rng){ 34 | 35 | std::vector sample_weights(data.num_data_points(), 1.); 36 | fit(data, tree_opts, sample_weights,rng); 37 | } 38 | 39 | /** \brief fits a (possibly randomized) decision tree to a subset of the data 40 | * 41 | * At each node, if it is 'splitworthy', a random subset of all features is considered for the 42 | * split. Depending on the split_type provided, greedy or randomized choices can be 43 | * made. Just make sure the max_features in tree_opts to a number smaller than the number of features! 44 | * 45 | * \param data the container holding the training data 46 | * \param tree_opts a tree_options opject that controls certain aspects of "growing" the tree 47 | * \param sample_weights vector containing the weights of all datapoints, can be used for subsampling (no checks are done here!) 48 | * \param rng a (pseudo) random number generator 49 | */ 50 | virtual void fit(const rfr::data_containers::base &data, 51 | rfr::trees::tree_options tree_opts, 52 | const std::vector &sample_weights, 53 | rng_type &rng) = 0; 54 | 55 | 56 | 57 | /** \brief predicts the response value for a single feature vector 58 | * 59 | * \param feature_vector an array containing a valid (in terms of size and values!) feature vector 60 | * 61 | * \return num_t the prediction of the response value (usually the mean of all responses in the corresponding leaf) 62 | */ 63 | virtual response_t predict (const std::vector &feature_vector) const = 0; 64 | 65 | 66 | 67 | /** \brief returns all response values in the leaf into which the given feature vector falls 68 | * 69 | * \param feature_vector an array containing a valid (in terms of size and values!) feature vector 70 | * 71 | * \return std::vector all response values in that leaf 72 | */ 73 | virtual std::vector const &leaf_entries (const std::vector &feature_vector) const = 0; 74 | 75 | 76 | 77 | 78 | virtual index_t number_of_nodes() const = 0; 79 | virtual index_t number_of_leafs() const = 0; 80 | virtual index_t depth() const = 0; 81 | 82 | /** \brief creates a LaTeX document visualizing the tree*/ 83 | virtual void save_latex_representation(const char* filename) const = 0; 84 | 85 | }; 86 | 87 | 88 | 89 | }}//namespace rfr::trees 90 | #endif 91 | -------------------------------------------------------------------------------- /include/rfr/trees/tree_options.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RFR_TREE_OPTIONS_HPP 2 | #define RFR_TREE_OPTIONS_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include "cereal/cereal.hpp" 8 | 9 | 10 | #include "rfr/data_containers/data_container.hpp" 11 | 12 | namespace rfr{ namespace trees{ 13 | 14 | template 15 | struct tree_options{ 16 | index_t max_features; ///< number of features to consider for each split 17 | index_t max_depth; ///< maximum depth for the tree 18 | 19 | index_t min_samples_to_split; ///< minumum number of samples to try splitting 20 | num_t min_weight_to_split; ///< minumum weight of samples to try splitting 21 | 22 | index_t min_samples_in_leaf; ///< minimum total sample weights in a leaf 23 | num_t min_weight_in_leaf; ///< minimum total sample weights in a leaf 24 | 25 | index_t max_num_nodes; ///< maxmimum total number of nodes in the tree 26 | index_t max_num_leaves; ///< maxmimum total number of leaves in the tree 27 | 28 | response_t epsilon_purity; ///< minimum difference between two response values to be considered different*/ 29 | 30 | num_t life_time; ///< life time of a mondrian tree 31 | bool hierarchical_smoothing; ///< flag to enable/disable hierachical smoothing for mondrian forests 32 | 33 | 34 | /** serialize function for saving forests */ 35 | template 36 | void serialize(Archive & archive) 37 | { 38 | archive( max_features, max_depth, min_samples_to_split, min_weight_to_split, min_samples_in_leaf, min_weight_in_leaf, max_num_nodes, epsilon_purity, /*min_samples_node,*/ life_time, hierarchical_smoothing); 39 | } 40 | 41 | /** (Re)set to default values with no limits on the size of the tree 42 | * 43 | * If nothing is know about the data, this member can be used 44 | * to get a valid setting for the tree_options struct. But beware 45 | * this setting could lead to a huge tree depending on the amount of 46 | * data. There is no limit to the size, and nodes are split into pure 47 | * leafs. For each split, every feature is considered! This not only 48 | * slows the training down, but also makes this tree deterministic! 49 | */ 50 | void set_default_values(){ 51 | max_features = std::numeric_limits::max(); 52 | max_depth = std::numeric_limits::max(); 53 | 54 | min_samples_to_split = 2; 55 | min_samples_in_leaf = 1; 56 | min_weight_to_split = 2; 57 | min_weight_in_leaf = 1; 58 | 59 | max_num_nodes = std::numeric_limits::max(); 60 | max_num_leaves = std::numeric_limits::max(); 61 | 62 | epsilon_purity = 1e-10; 63 | 64 | life_time = 1000; 65 | hierarchical_smoothing = false; 66 | } 67 | 68 | 69 | /** Default constructor that initializes the values with their default 70 | */ 71 | tree_options(){ set_default_values();} 72 | 73 | /** Constructor that adjusts the number of features considered at each split proportional to the square root of the number of features. 74 | * 75 | */ 76 | tree_options (rfr::data_containers::base &data){ 77 | set_default_values(); 78 | max_features = static_cast(std::sqrt(data.num_features()) + 0.5); 79 | } 80 | 81 | 82 | void adjust_limits_to_data (const rfr::data_containers::base &data){ 83 | max_features = std::min(max_features, data.num_features()); 84 | } 85 | 86 | 87 | void print_info(){ 88 | std::cout<<"max_features : "<< max_features <= 3.0.7 is required. 60 | Without this, the class documentation including constructor lists (`-c`) and attribute 61 | lists (`-a`) will not be available from python. -------------------------------------------------------------------------------- /local_lcov.sh: -------------------------------------------------------------------------------- 1 | cd build 2 | lcov --directory . --capture --output-file coverage.info 3 | lcov --remove coverage.info 'tests/*' '/usr/*' '/usr/include/*' '*/include/cereal/*' --output-file coverage.info 4 | lcov --list coverage.info 5 | mkdir gcov_html 6 | genhtml coverage.info --output-directory gcov_html 7 | firefox gcov_html/index.html 8 | cd .. 9 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | # Minimum requirements for the build system to execute. 3 | requires = [ 4 | "setuptools", 5 | "wheel", 6 | ] 7 | -------------------------------------------------------------------------------- /pyrfr/MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include include * 2 | recursive-include pyrfr *.i 3 | include LICENSE_cereal-1.2.2 4 | include LICENSE.txt 5 | include LICENSE_doxy2swig 6 | include LICENSE_rapidjson 7 | include LICENSE_rapidxml 8 | include pyproject.toml 9 | -------------------------------------------------------------------------------- /pyrfr/examples/pyrfr_covariance_example.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("..") 3 | import os 4 | here = os.path.dirname(os.path.realpath(__file__)) 5 | 6 | import time 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | 10 | import pyrfr.regression as reg 11 | 12 | 13 | num_points = 8 14 | 15 | 16 | features = np.array([np.linspace(-1,1,num_points)]).transpose() 17 | x2 = np.array([np.linspace(-1,1,100)]).transpose() 18 | responses = np.exp(-np.power(features/0.3,2)).flatten() + 0.05*np.random.randn(features.shape[0]) 19 | 20 | 21 | 22 | 23 | data = reg.default_data_container(1) 24 | 25 | for f,r in zip(features, responses): 26 | data.add_data_point(f,r) 27 | 28 | rng = reg.default_random_engine() 29 | 30 | # create an instance of a regerssion forest using binary splits and the RSS loss 31 | the_forest = reg.binary_rss_forest() 32 | the_forest.options.num_trees = 64 33 | the_forest.options.num_data_points_per_tree = num_points 34 | the_forest.options.tree_opts.min_samples_in_leaf = 1 35 | 36 | 37 | the_forest.fit(data, rng) 38 | 39 | fig, (ax1,ax2, ax3) = plt.subplots(3, sharex=True) 40 | 41 | 42 | predictions = np.array([ the_forest.predict_mean_var(x) for x in x2]) 43 | ax1.fill_between(x2[:,0], predictions[:,0] - predictions[:,1], predictions[:,0] + predictions[:,1], alpha=0.3) 44 | ax1.plot(x2, predictions[:,0]) 45 | ax1.scatter(features, responses) 46 | ax1.plot(x2, np.exp(-np.power(x2/0.3,2)).flatten(), color='red') 47 | 48 | 49 | cov = np.array([the_forest.covariance(np.array([0], dtype=np.double), x) for x in x2])/the_forest.covariance(np.array([0], dtype=np.double), np.array([0],dtype=np.double)) 50 | ax2.plot(x2[:,0], cov) 51 | 52 | kernel = np.array([the_forest.kernel([0], x.tolist()) for x in x2]) 53 | ax3.plot(x2, kernel) 54 | 55 | plt.show() 56 | 57 | 58 | -------------------------------------------------------------------------------- /pyrfr/examples/pyrfr_oob_error.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("../build") 3 | 4 | import os 5 | here = os.path.dirname(os.path.realpath(__file__)) 6 | 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | 10 | 11 | import pyrfr.regression 12 | 13 | 14 | data_set_prefix = '%(here)s/../test_data_sets/diabetes_' % {"here":here} 15 | 16 | features = np.loadtxt(data_set_prefix+'features.csv', delimiter=",") 17 | responses = np.loadtxt(data_set_prefix+'responses.csv', delimiter=",") 18 | types = np.zeros([features.shape[1]],dtype=np.uint) 19 | 20 | 21 | num_train_samples = 400 22 | 23 | 24 | indices = np.array(range(features.shape[0])) 25 | np.random.shuffle(indices) 26 | 27 | 28 | features_train = features[indices[:num_train_samples]] 29 | features_test = features[indices[num_train_samples:]] 30 | 31 | responses_train = responses[indices[:num_train_samples]] 32 | responses_test = responses[indices[num_train_samples:]] 33 | 34 | 35 | 36 | 37 | data = pyrfr.regression.default_data_container(features_train.shape[1]) 38 | 39 | for f,r in zip(features_train, responses_train): 40 | data.add_data_point(f.tolist(), r) 41 | 42 | # create an instance of a regerssion forest using binary splits and the RSS loss 43 | the_forest = pyrfr.regression.binary_rss_forest() 44 | 45 | #reset to reseed the rng for the next fit 46 | rng = pyrfr.regression.default_random_engine(42) 47 | # create an instance of a regerssion forest using binary splits and the RSS loss 48 | the_forest = pyrfr.regression.binary_rss_forest() 49 | 50 | the_forest.options.num_trees = 16 51 | # the forest's parameters 52 | the_forest.options.compute_oob_error = True 53 | the_forest.options.do_bootstrapping=True # default: false 54 | the_forest.options.num_data_points_per_tree=(data.num_data_points()//4)* 3 # means same number as data points 55 | the_forest.options.tree_opts.max_features = data.num_features()//2 # 0 would mean all the features 56 | the_forest.options.tree_opts.min_samples_to_split = 0 # 0 means split until pure 57 | the_forest.options.tree_opts.min_samples_in_leaf = 0 # 0 means no restriction 58 | the_forest.options.tree_opts.max_depth=1024 # 0 means no restriction 59 | the_forest.options.tree_opts.epsilon_purity = 1e-8 # when checking for purity, the data points can differ by this epsilon 60 | 61 | the_forest.fit(data, rng) 62 | 63 | 64 | 65 | 66 | predictions_test = [the_forest.predict(f.tolist()) for f in features_test] 67 | print(np.sqrt(np.mean((predictions_test - responses_test) ** 2))) 68 | print(the_forest.out_of_bag_error()) 69 | -------------------------------------------------------------------------------- /pyrfr/examples/pyrfr_pickle_example.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("..") 3 | import os 4 | here = os.path.dirname(os.path.realpath(__file__)) 5 | 6 | import pickle 7 | import tempfile 8 | 9 | import numpy as np 10 | import pyrfr.regression 11 | 12 | 13 | 14 | data_set_prefix = '%(here)s/../test_data_sets/diabetes_' % {"here":here} 15 | 16 | features = np.loadtxt(data_set_prefix+'features.csv', delimiter=",") 17 | responses = np.loadtxt(data_set_prefix+'responses.csv', delimiter=",") 18 | 19 | data = pyrfr.regression.default_data_container(10) 20 | 21 | data.import_csv_files(data_set_prefix+'features.csv', data_set_prefix+'responses.csv') 22 | 23 | 24 | # create an instance of a regerssion forest using binary splits and the RSS loss 25 | the_forest = pyrfr.regression.binary_rss_forest() 26 | 27 | #reset to reseed the rng for the next fit 28 | rng = pyrfr.regression.default_random_engine(42) 29 | # create an instance of a regerssion forest using binary splits and the RSS loss 30 | the_forest = pyrfr.regression.binary_rss_forest() 31 | 32 | the_forest.options.num_trees = 16 33 | # the forest's parameters 34 | the_forest.options.compute_oob_error = True 35 | the_forest.options.do_bootstrapping=True # default: false 36 | the_forest.options.num_data_points_per_tree=(data.num_data_points()//4)* 3 # means same number as data points 37 | the_forest.options.tree_opts.max_features = data.num_features()//2 # 0 would mean all the features 38 | the_forest.options.tree_opts.min_samples_to_split = 0 # 0 means split until pure 39 | the_forest.options.tree_opts.min_samples_in_leaf = 0 # 0 means no restriction 40 | the_forest.options.tree_opts.max_depth=1024 # 0 means no restriction 41 | the_forest.options.tree_opts.epsilon_purity = 1e-8 # when checking for purity, the data points can differ by this epsilon 42 | 43 | the_forest.fit(data, rng) 44 | 45 | 46 | predictions_1 = [ the_forest.predict(f.tolist()) for f in features] 47 | 48 | with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as f: 49 | fname = f.name 50 | pickle.dump(the_forest, f) 51 | 52 | 53 | with open(fname, 'r+b') as fh: 54 | a_second_forest = pickle.load(fh) 55 | os.remove(fname) 56 | 57 | 58 | predictions_2 = [ a_second_forest.predict(f.tolist()) for f in features] 59 | 60 | 61 | if (np.allclose(predictions_1, predictions_2)): 62 | print("successfully pickled/unpickled the forest") 63 | else: 64 | print("something went wrong") 65 | 66 | 67 | -------------------------------------------------------------------------------- /pyrfr/examples/pyrfr_simple_example.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("../build/") 3 | import os 4 | here = os.path.dirname(os.path.realpath(__file__)) 5 | 6 | import time 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | 10 | from sklearn.ensemble import RandomForestRegressor 11 | import pyrfr.regression as reg 12 | 13 | 14 | 15 | 16 | data_set_prefix = '%(here)s/../test_data_sets/diabetes_' % {"here":here} 17 | data = reg.default_data_container(10) 18 | data.import_csv_files(data_set_prefix+'features.csv', data_set_prefix+'responses.csv') 19 | 20 | 21 | 22 | 23 | 24 | 25 | rng = reg.default_random_engine() 26 | 27 | # create an instance of a regerssion forest using binary splits and the RSS loss 28 | 29 | the_forest = reg.binary_rss_forest() 30 | the_forest.options.num_trees = 64 31 | the_forest.options.num_data_points_per_tree = 200 32 | 33 | 34 | print(the_forest.options.num_trees) 35 | the_forest.fit(data, rng) 36 | 37 | # you can save the forest to disk 38 | the_forest.save_to_binary_file("/tmp/pyrfr_test.bin") 39 | 40 | 41 | num_datapoints_old = the_forest.options.num_data_points_per_tree 42 | 43 | 44 | # loading it works like that 45 | the_forest = reg.binary_rss_forest() 46 | the_forest.load_from_binary_file("/tmp/pyrfr_test.bin") 47 | 48 | # you can save a LaTeX document that you can compile with pdflatex 49 | the_forest.save_latex_representation("/tmp/rfr_test") 50 | 51 | 52 | # the predict method will return a tuple containing the predicted mean and the standard deviation. 53 | feature_vector = data.retrieve_data_point(0) 54 | print(feature_vector) 55 | print(the_forest.predict(feature_vector)) 56 | 57 | # it is possible to get the actual response values from the corresponding 58 | # leaf in each tree that the given feature vector falls into 59 | # The method returns a nested list 60 | print(the_forest.all_leaf_values(feature_vector)) 61 | 62 | # quantile regression forest estimations 63 | the_forest = reg.qr_forest() 64 | the_forest.options.num_trees = 64 65 | the_forest.options.num_data_points_per_tree = 200 66 | 67 | the_forest.fit(data,rng) 68 | alphas =[0.25, 0.5, 0.75] 69 | print("="*50) 70 | print(the_forest.predict_quantiles(feature_vector, alphas)) 71 | -------------------------------------------------------------------------------- /pyrfr/examples/pyrfr_with_instances_example.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import csv 4 | from operator import itemgetter 5 | 6 | import numpy as np 7 | import matplotlib.pyplot as plt 8 | 9 | sys.path.append("../build") 10 | import pyrfr.regression 11 | 12 | print(pyrfr.regression.__file__) 13 | here = os.path.dirname(os.path.realpath(__file__)) 14 | data_set_folder = '%(here)s/../test_data_sets/' % {"here":here} 15 | 16 | 17 | with open(os.path.join(data_set_folder, 'sat_saps_configurations.csv')) as fh: 18 | reader = csv.reader(fh) 19 | configurations = np.array(([l[5:] for l in list(reader)[1:]]), dtype=np.float) 20 | 21 | 22 | print("read {} configurations".format(len(configurations))) 23 | 24 | 25 | instance_dict = {} 26 | with open(os.path.join(data_set_folder, 'sat_instance_features.csv')) as fh: 27 | reader = csv.reader(fh) 28 | #skip header 29 | next(reader) 30 | 31 | for row in reader: 32 | instance_dict[row[0]] = np.array(row[1:],dtype=np.double) 33 | num_instance_features = len(row)-1 34 | 35 | 36 | print("read {} instances with {} features each".format(len(instance_dict), num_instance_features)) 37 | 38 | 39 | performance_matrix_dict = {} 40 | with open(os.path.join(data_set_folder, 'sat_performance_matrix.csv')) as fh: 41 | reader = csv.reader(fh) 42 | 43 | for row in reader: 44 | performance_matrix_dict[row[0]]=np.array(row[1:],dtype=np.double) 45 | 46 | 47 | #print([performance_matrix_dict[i] for i in instance_names]) 48 | 49 | 50 | s1 = set(instance_dict) 51 | s2 = set(performance_matrix_dict.keys()) 52 | common_instances = s1 & s2 53 | 54 | print("{} of the instances have features and runtime data".format(len(common_instances))) 55 | 56 | 57 | instances = np.zeros([len(common_instances), num_instance_features], dtype=np.double) 58 | performance_matrix = np.zeros([len(configurations),len(common_instances)], dtype=np.double) 59 | 60 | print(configurations.shape, instances.shape, performance_matrix.shape) 61 | 62 | i=0 63 | for instance in common_instances: 64 | instances[i] = instance_dict[instance] 65 | performance_matrix[:,i] = performance_matrix_dict[instance] 66 | i+=1 67 | 68 | 69 | data = pyrfr.regression.default_data_container_with_instances(configurations.shape[1], instances.shape[1]) 70 | 71 | 72 | for c in configurations: 73 | data.add_configuration(c.tolist()) 74 | 75 | for i in instances: 76 | data.add_instance(i.tolist()) 77 | 78 | 79 | 80 | 81 | for i in range(1000): 82 | i = np.random.randint(performance_matrix.shape[0]) 83 | j = np.random.randint(performance_matrix.shape[1]) 84 | data.add_data_point(i,j, performance_matrix[i,j]) 85 | 86 | 87 | #reset to reseed the rng for the next fit 88 | rng = pyrfr.regression.default_random_engine(42) 89 | # create an instance of a regerssion forest using binary splits and the RSS loss 90 | the_forest = pyrfr.regression.binary_rss_forest() 91 | 92 | the_forest.options.num_trees = 16 93 | # the forest's parameters 94 | the_forest.options.do_bootstrapping=True # default: false 95 | the_forest.options.num_data_points_per_tree=data.num_data_points() # means same number as data points 96 | the_forest.options.tree_opts.max_features = data.num_features()//2 # 0 would mean all the features 97 | the_forest.options.tree_opts.min_samples_to_split = 0 # 0 means split until pure 98 | the_forest.options.tree_opts.min_samples_in_leaf = 0 # 0 means no restriction 99 | the_forest.options.tree_opts.max_depth=1024 # 0 means no restriction 100 | the_forest.options.tree_opts.epsilon_purity = 1e-8 # when checking for purity, the data points can differ by this epsilon 101 | 102 | 103 | the_forest.fit(data, rng) 104 | -------------------------------------------------------------------------------- /pyrfr/pyrfr/.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | *.cpp 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /pyrfr/pyrfr/__init__.py: -------------------------------------------------------------------------------- 1 | __version__='${RFR_VERSION_MAJOR}.${RFR_VERSION_MINOR}.${RFR_VERSION_RELEASE}' 2 | __version_info__=(${RFR_VERSION_MAJOR}, ${RFR_VERSION_MINOR}, ${RFR_VERSION_RELEASE}) 3 | -------------------------------------------------------------------------------- /pyrfr/pyrfr/util.i: -------------------------------------------------------------------------------- 1 | %module util 2 | 3 | 4 | %{ 5 | #include "rfr/util.hpp" 6 | 7 | typedef double num_t; 8 | typedef double response_t; 9 | typedef unsigned int index_t; 10 | %} 11 | 12 | %include "docstrings.i" 13 | %include "exception.i" 14 | 15 | %exception { 16 | try { 17 | $action 18 | } catch (const std::exception& e) { 19 | SWIG_exception(SWIG_RuntimeError, e.what()); 20 | } catch (const std::string& e) { 21 | SWIG_exception(SWIG_RuntimeError, e.c_str()); 22 | } 23 | } 24 | 25 | typedef double num_t; 26 | typedef double response_t; 27 | typedef unsigned int index_t; 28 | 29 | %ignore rfr::util::merge_two_vectors; 30 | %include "rfr/util.hpp" 31 | %rename (run_stats) rfr::util::running_statistics; 32 | 33 | 34 | %template(running_statistics) rfr::util::running_statistics; 35 | //%template(running_covariance) rfr::util::running_covariance; 36 | %template(weighted_running_stats) rfr::util::weighted_running_statistics; 37 | 38 | -------------------------------------------------------------------------------- /pyrfr/setup.py: -------------------------------------------------------------------------------- 1 | # Setuptools must go above distutils 2 | # https://stackoverflow.com/a/53356077/5332072 3 | from setuptools.command.install import install 4 | 5 | import distutils.command.install as orig 6 | from distutils.command.build import build 7 | from distutils.core import Extension, setup 8 | 9 | 10 | 11 | # Customize installation according to https://stackoverflow.com/a/21236111 12 | class CustomBuild(build): 13 | def run(self): 14 | self.run_command("build_ext") 15 | build.run(self) 16 | 17 | 18 | class CustomInstall(install): 19 | def run(self): 20 | self.run_command("build_ext") 21 | orig.install.run(self) 22 | 23 | 24 | include_dirs = ["./include"] 25 | extra_compile_args = ["-O2", "-std=c++11"] 26 | # extra_compile_args = ['-g', '-std=c++11', '-O0', '-Wall'] 27 | 28 | 29 | extensions = [ 30 | Extension( 31 | name="pyrfr._regression", 32 | sources=["pyrfr/regression.i"], 33 | include_dirs=include_dirs, 34 | swig_opts=["-c++", "-modern", "-py3", "-features", "nondynamic"] 35 | + ["-I{}".format(s) for s in include_dirs], 36 | extra_compile_args=extra_compile_args, 37 | ), 38 | Extension( 39 | name="pyrfr._util", 40 | sources=["pyrfr/util.i"], 41 | include_dirs=include_dirs, 42 | swig_opts=["-c++", "-modern", "-py3", "-features", "nondynamic"] 43 | + ["-I{}".format(s) for s in include_dirs], 44 | extra_compile_args=extra_compile_args, 45 | ), 46 | ] 47 | 48 | print(extensions) 49 | 50 | setup( 51 | name="pyrfr", 52 | version="${RFR_VERSION_MAJOR}.${RFR_VERSION_MINOR}.${RFR_VERSION_RELEASE}", 53 | author="Stefan Falkner, Matthias Feurer, Rene Sass, Eddie Bergman", 54 | author_email="sfalkner@cs.uni-freiburg.de", 55 | license="BSD-3-Clause", 56 | classifiers=[ 57 | "Development Status :: 3 - Alpha", 58 | "License :: OSI Approved :: BSD License", 59 | ], 60 | packages=["pyrfr"], 61 | ext_modules=extensions, 62 | python_requires=">=3.7", 63 | package_data={"pyrfr": ["docstrings.i"]}, 64 | py_modules=["pyrfr"], 65 | cmdclass={"build": CustomBuild, "install": CustomInstall}, 66 | long_description="# Pyrfr\nhttps://github.com/automl/random_forest_run", 67 | long_description_content_type="text/markdown", 68 | url="https://github.com/automl/random_forest_run", 69 | ) 70 | -------------------------------------------------------------------------------- /test_data_sets/corrupted_toy_data_set_responses.csv: -------------------------------------------------------------------------------- 1 | 1.000000000000000000e+00 2 | 1.000000000000000000e+00 3 | 1.000000000000000000e+00 4 | 1.000000000000000000e+00 5 | 1.000000000000000000e+00 6 | 1.000000000000000000e+00 7 | 1.000000000000000000e+00 8 | 1.000000000000000000e+00 9 | 1.000000000000000000e+00 10 | 1.000000000000000000e+00 11 | 1.000000000000000000e+00 12 | 1.000000000000000000e+00 13 | 1.000000000000000000e+00 14 | 1.000000000000000000e+00 15 | 1.000000000000000000e+00 16 | 1.000000000000000000e+00 17 | 1.000000000000000000e+00 18 | 1.000000000000000000e+00 19 | 1.000000000000000000e+00 20 | 1.000000000000000000e+00 21 | 2.000000000000000000e+00 22 | 2.000000000000000000e+00 23 | 2.000000000000000000e+00 24 | 2.000000000000000000e+00 25 | 2.000000000000000000e+00 26 | 2.000000000000000000e+00 27 | 2.000000000000000000e+00 28 | 2.000000000000000000e+00 29 | 2.000000000000000000e+00 30 | 2.000000000000000000e+00 31 | 2.000000000000000000e+00 32 | 2.000000000000000000e+00 33 | 2.000000000000000000e+00 34 | 2.000000000000000000e+00 35 | 2.000000000000000000e+00 36 | 2.000000000000000000e+00 37 | 2.000000000000000000e+00 38 | 2.000000000000000000e+00 39 | 2.000000000000000000e+00 40 | 2.000000000000000000e+00 41 | 2.000000000000000000e+00 42 | 2.000000000000000000e+00 43 | 2.000000000000000000e+00 44 | 2.000000000000000000e+00 45 | 2.000000000000000000e+00 46 | 2.000000000000000000e+00 47 | 2.000000000000000000e+00 48 | 2.000000000000000000e+00 49 | 2.000000000000000000e+00 50 | 2.000000000000000000e+00 51 | 2.000000000000000000e+00 52 | 2.000000000000000000e+00 53 | 2.000000000000000000e+00 54 | 2.000000000000000000e+00 55 | 2.000000000000000000e+00 56 | 2.000000000000000000e+00 57 | 2.000000000000000000e+00 58 | 2.000000000000000000e+00 59 | 2.000000000000000000e+00 60 | 2.000000000000000000e+00 61 | 3.000000000000000000e+00 62 | 3.000000000000000000e+00 63 | 3.000000000000000000e+00 64 | 3.000000000000000000e+00 65 | 3.000000000000000000e+00 66 | 3.000000000000000000e+00 67 | 3.000000000000000000e+00 68 | 3.000000000000000000e+00 69 | 3.000000000000000000e+00 70 | 3.000000000000000000e+00 71 | 3.000000000000000000e+00 72 | 3.000000000000000000e+00 73 | 3.000000000000000000e+00 74 | 3.000000000000000000e+00 75 | 3.000000000000000000e+00 76 | 3.000000000000000000e+00 77 | 3.000000000000000000e+00 78 | 3.000000000000000000e+00 79 | 3.000000000000000000e+00 80 | 3.000000000000000000e+00 81 | 4.000000000000000000e+00 82 | 4.000000000000000000e+00 83 | 4.000000000000000000e+00 84 | 4.000000000000000000e+00 85 | 4.000000000000000000e+00 86 | 4.000000000000000000e+00 87 | 4.000000000000000000e+00 88 | 4.000000000000000000e+00 89 | 4.000000000000000000e+00 90 | 4.000000000000000000e+00 91 | 4.000000000000000000e+00 92 | 4.000000000000000000e+00 93 | 4.000000000000000000e+00 94 | 4.000000000000000000e+00 95 | 4.000000000000000000e+00 96 | 4.000000000000000000e+00 97 | 4.000000000000000000e+00 98 | 4.000000000000000000e+00 99 | 4.000000000000000000e+00 100 | -------------------------------------------------------------------------------- /test_data_sets/corrupted_toy_data_set_weights.csv: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | 1 12 | 1 13 | 1 14 | 1 15 | 1 16 | 1 17 | 1 18 | 1 19 | 1 20 | 1 21 | 1 22 | 1 23 | 1 24 | 1 25 | 1 26 | 1 27 | 1 28 | 1 29 | 1 30 | 1 31 | 1 32 | 1 33 | 1 34 | 1 35 | -------------------------------------------------------------------------------- /test_data_sets/toy_data_set_responses.csv: -------------------------------------------------------------------------------- 1 | 1.000000000000000000e+00 2 | 1.000000000000000000e+00 3 | 1.000000000000000000e+00 4 | 1.000000000000000000e+00 5 | 1.000000000000000000e+00 6 | 1.000000000000000000e+00 7 | 1.000000000000000000e+00 8 | 1.000000000000000000e+00 9 | 1.000000000000000000e+00 10 | 1.000000000000000000e+00 11 | 1.000000000000000000e+00 12 | 1.000000000000000000e+00 13 | 1.000000000000000000e+00 14 | 1.000000000000000000e+00 15 | 1.000000000000000000e+00 16 | 1.000000000000000000e+00 17 | 1.000000000000000000e+00 18 | 1.000000000000000000e+00 19 | 1.000000000000000000e+00 20 | 1.000000000000000000e+00 21 | 2.000000000000000000e+00 22 | 2.000000000000000000e+00 23 | 2.000000000000000000e+00 24 | 2.000000000000000000e+00 25 | 2.000000000000000000e+00 26 | 2.000000000000000000e+00 27 | 2.000000000000000000e+00 28 | 2.000000000000000000e+00 29 | 2.000000000000000000e+00 30 | 2.000000000000000000e+00 31 | 2.000000000000000000e+00 32 | 2.000000000000000000e+00 33 | 2.000000000000000000e+00 34 | 2.000000000000000000e+00 35 | 2.000000000000000000e+00 36 | 2.000000000000000000e+00 37 | 2.000000000000000000e+00 38 | 2.000000000000000000e+00 39 | 2.000000000000000000e+00 40 | 2.000000000000000000e+00 41 | 2.000000000000000000e+00 42 | 2.000000000000000000e+00 43 | 2.000000000000000000e+00 44 | 2.000000000000000000e+00 45 | 2.000000000000000000e+00 46 | 2.000000000000000000e+00 47 | 2.000000000000000000e+00 48 | 2.000000000000000000e+00 49 | 2.000000000000000000e+00 50 | 2.000000000000000000e+00 51 | 2.000000000000000000e+00 52 | 2.000000000000000000e+00 53 | 2.000000000000000000e+00 54 | 2.000000000000000000e+00 55 | 2.000000000000000000e+00 56 | 2.000000000000000000e+00 57 | 2.000000000000000000e+00 58 | 2.000000000000000000e+00 59 | 2.000000000000000000e+00 60 | 2.000000000000000000e+00 61 | 3.000000000000000000e+00 62 | 3.000000000000000000e+00 63 | 3.000000000000000000e+00 64 | 3.000000000000000000e+00 65 | 3.000000000000000000e+00 66 | 3.000000000000000000e+00 67 | 3.000000000000000000e+00 68 | 3.000000000000000000e+00 69 | 3.000000000000000000e+00 70 | 3.000000000000000000e+00 71 | 3.000000000000000000e+00 72 | 3.000000000000000000e+00 73 | 3.000000000000000000e+00 74 | 3.000000000000000000e+00 75 | 3.000000000000000000e+00 76 | 3.000000000000000000e+00 77 | 3.000000000000000000e+00 78 | 3.000000000000000000e+00 79 | 3.000000000000000000e+00 80 | 3.000000000000000000e+00 81 | 4.000000000000000000e+00 82 | 4.000000000000000000e+00 83 | 4.000000000000000000e+00 84 | 4.000000000000000000e+00 85 | 4.000000000000000000e+00 86 | 4.000000000000000000e+00 87 | 4.000000000000000000e+00 88 | 4.000000000000000000e+00 89 | 4.000000000000000000e+00 90 | 4.000000000000000000e+00 91 | 4.000000000000000000e+00 92 | 4.000000000000000000e+00 93 | 4.000000000000000000e+00 94 | 4.000000000000000000e+00 95 | 4.000000000000000000e+00 96 | 4.000000000000000000e+00 97 | 4.000000000000000000e+00 98 | 4.000000000000000000e+00 99 | 4.000000000000000000e+00 100 | 4.000000000000000000e+00 101 | -------------------------------------------------------------------------------- /test_data_sets/toy_data_set_weights.csv: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | 1 12 | 1 13 | 1 14 | 1 15 | 1 16 | 1 17 | 1 18 | 1 19 | 1 20 | 1 21 | 1 22 | 1 23 | 1 24 | 1 25 | 1 26 | 1 27 | 1 28 | 1 29 | 1 30 | 1 31 | 1 32 | 1 33 | 1 34 | 1 35 | 1 36 | 1 37 | 1 38 | 1 39 | 1 40 | 1 41 | 1 42 | 1 43 | 1 44 | 1 45 | 1 46 | 1 47 | 1 48 | 1 49 | 1 50 | 1 51 | 1 52 | 1 53 | 1 54 | 1 55 | 1 56 | 1 57 | 1 58 | 1 59 | 1 60 | 1 61 | 1 62 | 1 63 | 1 64 | 1 65 | 1 66 | 1 67 | 1 68 | 1 69 | 1 70 | 1 71 | 1 72 | 1 73 | 1 74 | 1 75 | 1 76 | 1 77 | 1 78 | 1 79 | 1 80 | 1 81 | 1 82 | 1 83 | 1 84 | 1 85 | 1 86 | 1 87 | 1 88 | 1 89 | 1 90 | 1 91 | 1 92 | 1 93 | 1 94 | 1 95 | 1 96 | 1 97 | 1 98 | 1 99 | 1 100 | 1 101 | -------------------------------------------------------------------------------- /test_data_sets/ut_reference.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import itertools 3 | 4 | 5 | 6 | features = np.loadtxt("toy_data_set_features.csv", delimiter=",") 7 | responses= np.loadtxt("toy_data_set_responses.csv", delimiter=",") 8 | 9 | indices = np.arange(len(responses)) 10 | 11 | def calc_loss(l_indices, r_indices): 12 | l1 = np.var(responses[l_indices])*len(l_indices) 13 | l2 = np.var(responses[r_indices])*len(r_indices) 14 | return(l1+l2) 15 | 16 | 17 | 18 | 19 | # find best split for the continuous first feature 20 | def loss1 (split_value): 21 | left_indices = indices[(features[:,0] <= split_value)] 22 | right_indices= indices[(features[:,0] > split_value)] 23 | if (len(left_indices)*len(right_indices) == 0): 24 | return np.inf 25 | return(calc_loss(left_indices, right_indices)) 26 | 27 | losses = list(map(loss1, features[:,0])) 28 | best_index = (np.argmin(losses)) 29 | 30 | print(losses[best_index], features[best_index,0]) 31 | tmp = np.array(features[:,0] <= features[best_index,0],dtype=np.int) 32 | print("Reference for the () operator") 33 | print(",".join(map(str, tmp))) 34 | 35 | 36 | # find best split for the categorical second feature 37 | 38 | print(list(map(lambda i: np.mean(responses[indices[features[:,1] == i]]), range(1,4)))) 39 | print("The way the C++ implementation works, the category with the smallest mean will always fall into the left child!") 40 | print("here this is category 2") 41 | 42 | for conf in (itertools.product([0,1], [0], [0,1])): 43 | left_indices = np.array([], dtype=np.int); 44 | right_indices = np.array([], dtype=np.int); 45 | print(conf) 46 | 47 | if not any(conf) or all(conf): 48 | print("skip") 49 | continue 50 | 51 | for i in range(0,3): 52 | if conf[i] == 1: 53 | left_indices = np.hstack([left_indices, indices[features[:,1]==i+1] ]) 54 | else: 55 | right_indices = np.hstack([right_indices, indices[features[:,1]==i+1] ]) 56 | print(calc_loss(left_indices, right_indices)) 57 | 58 | print("So the final split set has to contain 1 and 2") 59 | tmp = np.array(features[:,1] <= 2,dtype=np.int) 60 | print("Reference for the () operator") 61 | print(",".join(map(str, tmp))) 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} unit_test_*.cpp) 2 | 3 | #colon separated list for tests to skip 4 | set (SKIP_TESTS "unit_test_classification_forest.cpp") 5 | 6 | # Build all the unit tests 7 | foreach(TEST_SOURCE ${TESTS}) 8 | # construct target name from file name 9 | string(REPLACE ".cpp" "" TMP "${TEST_SOURCE}") 10 | string(REPLACE "unit_test" "ut" TEST_TARGET "${TMP}") 11 | 12 | # only build the tests that are not 13 | list(FIND SKIP_TESTS "${TEST_SOURCE}" TO_BE_SKIPPED) 14 | if (TO_BE_SKIPPED EQUAL -1) 15 | add_executable(${TEST_TARGET} ${TEST_SOURCE}) 16 | set_target_properties(${TEST_TARGET} PROPERTIES COMPILE_DEFINITIONS "BOOST_TEST_DYN_LINK;BOOST_TEST_MODULE=${TEST_TARGET}") 17 | set_target_properties(${TEST_TARGET} PROPERTIES CXX_STANDARD 11) 18 | target_link_libraries(${TEST_TARGET} ${Boost_LIBRARIES}) 19 | add_test("${TEST_TARGET}" "${TEST_TARGET}" "${PROJECT_SOURCE_DIR}/test_data_sets/") 20 | else() 21 | message("Skipping ${TEST_SOURCE}") 22 | endif() 23 | endforeach() 24 | 25 | 26 | if(PYTHONINTERP_FOUND AND SWIG_FOUND) 27 | file(GLOB PYRFR_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} pyrfr_unit_test_*.py) 28 | 29 | foreach(PYRFR_TEST ${PYRFR_TESTS}) 30 | configure_file(${PYRFR_TEST} ${CMAKE_CURRENT_BINARY_DIR}/../python_package/tests/${PYRFR_TEST}) 31 | endforeach() 32 | 33 | add_test(NAME pyrfr_test 34 | COMMAND ${PYTHON_EXECUTABLE} -m unittest discover -p pyrfr_unit_test*.py -s tests 35 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../python_package 36 | ) 37 | 38 | 39 | endif(PYTHONINTERP_FOUND AND SWIG_FOUND) 40 | 41 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/automl/random_forest_run/1ba17650e734edd3ea536efc91d32815c4874e72/tests/__init__.py -------------------------------------------------------------------------------- /tests/profiling_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "rfr/data_containers/mostly_continuous_data_container.hpp" 5 | #include "rfr/splits/binary_split_one_feature_rss_loss.hpp" 6 | #include "rfr/nodes/temporary_node.hpp" 7 | #include "rfr/nodes/k_ary_node.hpp" 8 | #include "rfr/trees/tree_options.hpp" 9 | #include "rfr/trees/k_ary_tree.hpp" 10 | #include "rfr/forests/regression_forest.hpp" 11 | #include "rfr/forests/forest_options.hpp" 12 | 13 | 14 | 15 | typedef double num_type; 16 | typedef double response_type; 17 | typedef unsigned int index_type; 18 | typedef std::default_random_engine rng_type; 19 | 20 | typedef rfr::data_containers::mostly_continuous_data data_container_type; 21 | 22 | typedef rfr::splits::binary_split_one_feature_rss_loss split_type; 23 | typedef rfr::nodes::k_ary_node<2, split_type, rng_type, num_type, response_type, index_type> node_type; 24 | typedef rfr::nodes::temporary_node tmp_node_type; 25 | 26 | typedef rfr::trees::k_ary_random_tree<2, split_type, rng_type, num_type, response_type, index_type> tree_type; 27 | 28 | 29 | int main (int argc, char** argv){ 30 | data_container_type data; 31 | 32 | char *filename = (char*) malloc(1024*sizeof(char)); 33 | 34 | strcpy(filename, argv[1]); 35 | strcat(filename, "/hectors_nn_features.csv"); 36 | std::cout< tree_opts; 49 | tree_opts.min_samples_to_split = 2; 50 | tree_opts.min_samples_in_leaf = 1; 51 | tree_opts.max_features = 14; 52 | 53 | 54 | rfr::forests::forest_options forest_opts(tree_opts); 55 | 56 | forest_opts.num_data_points_per_tree = 567; 57 | forest_opts.num_trees = 256; 58 | forest_opts.do_bootstrapping = true; 59 | 60 | rfr::forests::regression_forest< tree_type, rng_type, num_type, response_type, index_type> the_forest(forest_opts); 61 | 62 | rng_type rng; 63 | rng.seed(101); 64 | 65 | the_forest.fit(data, rng); 66 | free(filename); 67 | } 68 | -------------------------------------------------------------------------------- /tests/pyrfr_unit_test_basics.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("${CMAKE_BINARY_DIR}") 3 | 4 | import os 5 | import pickle 6 | import tempfile 7 | import unittest 8 | import math 9 | 10 | import pyrfr.regression as reg 11 | 12 | 13 | class TestBinaryRssRegressionForest(unittest.TestCase): 14 | 15 | def setUp(self): 16 | data_set_prefix = '${CMAKE_SOURCE_DIR}/test_data_sets/' 17 | self.data = reg.default_data_container(64) 18 | self.data.import_csv_files(data_set_prefix+'features13.csv', data_set_prefix+'responses13.csv') 19 | 20 | 21 | self.forest = reg.binary_rss_forest() 22 | self.forest.options.num_trees = 64 23 | self.forest.options.do_bootstrapping = True 24 | self.forest.options.num_data_points_per_tree = 200 25 | 26 | self.assertEqual(self.forest.options.num_trees, 64) 27 | self.assertTrue (self.forest.options.do_bootstrapping) 28 | self.assertEqual(self.forest.options.num_data_points_per_tree, 200) 29 | 30 | self.rng = reg.default_random_engine(1) 31 | 32 | def tearDown(self): 33 | self.data = None 34 | self.forest = None 35 | 36 | 37 | def test_nondynamic_objects(self): 38 | 39 | def try_set_min_depth(d): 40 | self.forest.options.tree_opts.min_depth = d 41 | self.assertRaises(Exception, try_set_min_depth, 5) 42 | 43 | def set_num_features_wrongly(n): 44 | self.forest.options.num_features = n 45 | self.assertRaises(Exception, set_num_features_wrongly, 5) 46 | 47 | 48 | def add_foo_attr(): 49 | self.forest.foo=5 50 | self.assertRaises(Exception, add_foo_attr) 51 | 52 | 53 | 54 | def test_data_container(self): 55 | data = reg.default_data_container(10) 56 | 57 | data.add_data_point([1]*10, 2) 58 | data.retrieve_data_point(0) 59 | 60 | 61 | if __name__ == '__main__': 62 | unittest.main() 63 | -------------------------------------------------------------------------------- /tests/pyrfr_unit_test_fanova_forest.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("${CMAKE_BINARY_DIR}") 3 | 4 | import os 5 | import pickle 6 | import tempfile 7 | import unittest 8 | 9 | import pyrfr.regression as reg 10 | 11 | 12 | class TestfANOVAForest(unittest.TestCase): 13 | 14 | def setUp(self): 15 | data_set_prefix = '${CMAKE_SOURCE_DIR}/test_data_sets/' 16 | self.data = reg.default_data_container(3) 17 | self.data.import_csv_files(data_set_prefix+'online_lda_features.csv', data_set_prefix+'online_lda_responses.csv') 18 | 19 | self.rng = reg.default_random_engine(1) 20 | self.forest_constructor = reg.fanova_forest 21 | 22 | def tearDown(self): 23 | self.data = None 24 | 25 | def test_options_constructor(self): 26 | fopts = reg.forest_opts() 27 | fopts.num_trees = 16 28 | fopts.num_data_points_per_tree = self.data.num_data_points() 29 | 30 | the_forest = self.forest_constructor(fopts) 31 | self.assertEqual(the_forest.num_trees(), 0) 32 | the_forest.fit(self.data, self.rng) 33 | 34 | self.assertEqual(the_forest.num_trees(), 16) 35 | the_forest.predict( self.data.retrieve_data_point(0)) 36 | 37 | def test_options_member(self): 38 | 39 | the_forest = self.forest_constructor() 40 | fopts = reg.forest_opts() 41 | the_forest.options.num_trees = 7 42 | the_forest.options.num_data_points_per_tree = self.data.num_data_points() 43 | the_forest.fit(self.data, self.rng) 44 | the_forest.predict( self.data.retrieve_data_point(0)) 45 | self.assertEqual(the_forest.num_trees(), 7) 46 | 47 | 48 | if __name__ == '__main__': 49 | unittest.main() 50 | -------------------------------------------------------------------------------- /tests/pyrfr_unit_test_mondrian_forest.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("${CMAKE_BINARY_DIR}") 3 | 4 | import os 5 | import pickle 6 | import tempfile 7 | import unittest 8 | 9 | import pyrfr.regression as reg 10 | 11 | 12 | class TestMondrianForest(unittest.TestCase): 13 | 14 | def setUp(self): 15 | data_set_prefix = '${CMAKE_SOURCE_DIR}/test_data_sets/' 16 | self.data = reg.default_data_container(3) 17 | self.data.import_csv_files(data_set_prefix+'online_lda_features.csv', data_set_prefix+'online_lda_responses.csv') 18 | 19 | self.rng = reg.default_random_engine(1) 20 | self.forest_constructor = reg.binary_mondrian_forest 21 | 22 | def tearDown(self): 23 | self.data = None 24 | 25 | def test_options_constructor(self): 26 | fopts = reg.forest_opts() 27 | fopts.num_trees = 16 28 | fopts.num_data_points_per_tree = self.data.num_data_points() 29 | 30 | the_forest = self.forest_constructor(fopts) 31 | self.assertEqual(the_forest.num_trees(), 0) 32 | the_forest.fit(self.data, self.rng) 33 | 34 | self.assertEqual(the_forest.num_trees(), 16) 35 | the_forest.predict( self.data.retrieve_data_point(0)) 36 | 37 | 38 | if __name__ == '__main__': 39 | unittest.main() 40 | -------------------------------------------------------------------------------- /tests/pyrfr_unit_test_quantile_regression_forest.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("${CMAKE_BINARY_DIR}") 3 | 4 | import os 5 | import pickle 6 | import tempfile 7 | import unittest 8 | 9 | import pyrfr.regression as reg 10 | 11 | 12 | class TestQuantileRegressionForest(unittest.TestCase): 13 | 14 | def setUp(self): 15 | data_set_prefix = '${CMAKE_SOURCE_DIR}/test_data_sets/' 16 | self.data = reg.default_data_container(64) 17 | self.data.import_csv_files(data_set_prefix+'features13.csv', data_set_prefix+'responses13.csv') 18 | 19 | self.rng = reg.default_random_engine(1) 20 | self.forest_constructor = reg.qr_forest 21 | 22 | def tearDown(self): 23 | self.data = None 24 | 25 | def test_options_constructor(self): 26 | fopts = reg.forest_opts() 27 | fopts.num_trees = 16 28 | fopts.num_data_points_per_tree = self.data.num_data_points() 29 | 30 | the_forest = self.forest_constructor(fopts) 31 | the_forest.fit(self.data, self.rng) 32 | 33 | 34 | def test_options_member(self): 35 | 36 | the_forest = self.forest_constructor() 37 | 38 | fopts = reg.forest_opts() 39 | the_forest.options.num_trees = 7 40 | the_forest.options.num_data_points_per_tree = self.data.num_data_points() 41 | 42 | the_forest.fit(self.data, self.rng) 43 | 44 | self.assertEqual(the_forest.num_trees(), 7) 45 | 46 | 47 | 48 | if __name__ == '__main__': 49 | unittest.main() 50 | -------------------------------------------------------------------------------- /tests/unit_test_classification_forest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | #include "rfr/data_containers/default_data_container.hpp" 7 | #include "rfr/splits/classification_split.hpp" 8 | #include "rfr/nodes/temporary_node.hpp" 9 | #include "rfr/nodes/k_ary_node.hpp" 10 | #include "rfr/trees/tree_options.hpp" 11 | #include "rfr/trees/k_ary_tree.hpp" 12 | #include "rfr/forests/classification_forest.hpp" 13 | #include "rfr/forests/forest_options.hpp" 14 | 15 | typedef double num_type; 16 | typedef unsigned int response_type; 17 | typedef unsigned int index_type; 18 | typedef std::default_random_engine rng_type; 19 | 20 | typedef rfr::data_containers::default_container data_container_type; 21 | 22 | typedef rfr::splits::classification_split split_type; 23 | typedef rfr::nodes::k_ary_node<2, split_type, rng_type, num_type, response_type, index_type> node_type; 24 | typedef rfr::nodes::temporary_node tmp_node_type; 25 | 26 | typedef rfr::trees::k_ary_random_tree<2, split_type, rng_type, num_type, response_type, index_type> tree_type; 27 | 28 | 29 | BOOST_AUTO_TEST_CASE( data_container_tests ){ 30 | data_container_type data; 31 | 32 | 33 | char *filename = (char*) malloc(1024*sizeof(char)); 34 | 35 | strcpy(filename, boost::unit_test::framework::master_test_suite().argv[1]); 36 | //strcat(filename, "toy_data_set_features.csv"); 37 | strcat(filename, "Skin_NonSkin_features.csv"); 38 | std::cout< tree_opts; 48 | tree_opts.min_samples_to_split = 10; 49 | tree_opts.min_samples_in_leaf = 5; 50 | tree_opts.max_features = 10; 51 | 52 | 53 | rfr::forests::forest_options forest_opts(tree_opts); 54 | 55 | forest_opts.num_data_points_per_tree = 2*data.num_data_points(); 56 | forest_opts.num_trees = 10; 57 | forest_opts.do_bootstrapping = true; 58 | 59 | rfr::forests::classification_forest< tree_type, rng_type, num_type, response_type, index_type> the_forest(forest_opts); 60 | 61 | rng_type rng; 62 | 63 | the_forest.fit(data, rng); 64 | the_forest.print_info(); 65 | 66 | std::tuple tmp; 67 | std::vector data_point_five = data.retrieve_data_point(5); 68 | // there should be the predicted class 69 | tmp = the_forest.predict_class(data_point_five.data()); 70 | 71 | the_forest.save_latex_representation("/tmp/tree"); 72 | 73 | std::cout<(tmp) <<" "<(tmp)<<"\n"; 74 | free(filename); 75 | } 76 | --------------------------------------------------------------------------------