Merge branch 'master' into StratifiedSplit

This commit is contained in:
Anush V Kini
2020-11-14 11:34:48 +05:30
555 changed files with 12831 additions and 12826 deletions
+12 -50
View File
@@ -1,16 +1,10 @@
clone_depth: 10
environment:
BOOST_PROG_OPTION : "C:/projects/mlpack/\
boost_program_options-vc140.1.60.0.0/lib/native/address-model-64/lib/*.*"
BOOST_MATH : "C:/projects/mlpack/\
boost_math_c99-vc140.1.60.0.0/lib/native/address-model-64/lib/*.*"
BOOST_RANDOM : "C:/projects/mlpack/\
boost_random-vc140.1.60.0.0/lib/native/address-model-64/lib/*.*"
BOOST_SERIALIZATION : "C:/projects/mlpack/\
boost_serialization-vc140.1.60.0.0/lib/native/address-model-64/lib/*.*"
BOOST_UNIT_TEST : "C:/projects/mlpack/\
boost_unit_test_framework-vc140.1.60.0.0/lib/native/address-model-64/lib/*.*"
ARMADILLO_DOWNLOAD : "https://data.kurg.org/armadillo-8.400.0.tar.xz"
ARMADILLO_LIBRARY : "C:/projects/mlpack/armadillo-8.400.0/\
build/Debug/armadillo.lib"
@@ -22,50 +16,36 @@ environment:
JENKINS_DOC : "C:/projects/mlpack/dist/win-installer/jenkinsdoc.zip"
GIT_VERSION_FILE : "C:/projects/mlpack/src/mlpack/core/util/gitversion.hpp"
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
VSVER: Visual Studio 14 2015 Win64
MSBUILD: C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
VSVER: Visual Studio 15 2017 Win64
MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
# Currently, the VS2019 build seems to always time out. This seems to be an
# AppVeyor issue.
# - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
# VSVER: Visual Studio 16 2019
# MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
VSVER: Visual Studio 16 2019
MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
# We have removed the VS studio 15 2017 build since it is not possible to complete
# or finish the build due to the `compiler out of heap space issues`.
# Therefore, in the meanwhile, we are only doing the installation for VS 16 2019.
configuration: Release
os: Visual Studio 2015
os: Visual Studio 2019
install:
- ps: nuget install boost -o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
- ps: >
nuget install boost_unit_test_framework-vc140
-o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
- ps: >
nuget install boost_program_options-vc140
-o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
- ps: >
nuget install boost_random-vc140
-o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
- ps: >
nuget install boost_serialization-vc140
-o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
- ps: >
nuget install boost_math_c99-vc140
-o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
- ps: >
nuget install unofficial-flayan-cereal
-o "${env:APPVEYOR_BUILD_FOLDER}"
- ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}"
- set path=C:\Program Files (x86)\WiX Toolset v3.11\bin;%path%
build_script:
- mkdir boost_libs
- ps: cp ${env:BOOST_PROG_OPTION} C:\projects\mlpack\boost_libs\
- ps: cp ${env:BOOST_MATH} C:\projects\mlpack\boost_libs\
- ps: cp ${env:BOOST_RANDOM} C:\projects\mlpack\boost_libs\
- ps: cp ${env:BOOST_SERIALIZATION} C:\projects\mlpack\boost_libs\
- ps: cp ${env:BOOST_UNIT_TEST} C:\projects\mlpack\boost_libs\
- echo TEST_ARMA is %ARMADILLO_DOWNLOAD%
- >
appveyor DownloadFile %ARMADILLO_DOWNLOAD%
@@ -89,6 +69,7 @@ build_script:
-DLAPACK_LIBRARIES:FILEPATH=%BLAS_LIBRARY%
-DARMADILLO_INCLUDE_DIR="C:/projects/mlpack/armadillo-8.400.0/include"
-DARMADILLO_LIBRARY:FILEPATH=%ARMADILLO_LIBRARY%
-DCEREAL_INCLUDE_DIR="C:/projects/mlpack/unofficial-flayan-cereal.1.2.2/build/native/include"
-DBOOST_INCLUDEDIR:PATH=%BOOST_INCLUDE%
-DBOOST_LIBRARYDIR:PATH="C:/projects/mlpack/boost_libs"
-DDEBUG=OFF
@@ -96,6 +77,7 @@ build_script:
-DBUILD_PYTHON_BINDINGS=OFF
-DBUILD_GO_BINDINGS=OFF
-DBUILD_R_BINDINGS=OFF
-DBUILD_TESTS=OFF
-DCMAKE_BUILD_TYPE=Release ..
- >
"%MSBUILD%" "C:\projects\mlpack\build\mlpack.sln"
@@ -139,9 +121,6 @@ build_script:
- ps: >
cp C:\projects\mlpack\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll
C:\projects\mlpack\dist\win-installer\staging\
- ps: >
cp C:\projects\mlpack\boost_libs\boost_unit_test_framework-vc*.dll
C:\projects\mlpack\dist\win-installer\staging\
- ps: >
cp C:\projects\mlpack\build\include\mlpack
C:\projects\mlpack\dist\win-installer\staging -recurse
@@ -239,20 +218,3 @@ cache:
- packages -> **\packages.config
- armadillo.tar.xz -> appveyor.yaml
test_script:
# Copy all DLLs into the right place before running the test.
- ps: cp C:\projects\mlpack\boost_libs\*.* C:\projects\mlpack\build\
- ps: >
cp C:\projects\mlpack\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.*
C:\projects\mlpack\build\
- cd "%APPVEYOR_BUILD_FOLDER%/build/"
- >
Release\mlpack_test.exe
--report_level=detailed
--log_level=test_suite --log_format=XML > mlpack_test.xml & exit 0
# Attempt to upload results to AppVeyor.
- ps: >
$wc = New-Object 'System.Net.WebClient';
$wc.UploadFile(
"https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)",
(Resolve-Path .\mlpack_test.xml));
+17 -17
View File
@@ -59,24 +59,24 @@ jobs:
steps:
- template: macos-steps.yaml
- job: WindowsVS15
timeoutInMinutes: 360
displayName: Windows VS15
pool:
vmImage: vs2017-win2016
strategy:
matrix:
Plain:
CMakeArgs: '-DDEBUG=ON -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=OFF'
python.version: '2.7'
CMakeGenerator: '-G "Visual Studio 15 2017 Win64"'
MSBuildVersion: '15.0'
ArchiveNoLibs: 'mlpack-windows-vs15-no-libs.zip'
ArchiveLibs: 'mlpack-windows-vs15.zip'
ArchiveTests: 'mlpack_test-vs15.xml'
# - job: WindowsVS15
# timeoutInMinutes: 360
# displayName: Windows VS15
# pool:
# vmImage: vs2017-win2016
# strategy:
# matrix:
# Plain:
# CMakeArgs: '-DDEBUG=ON -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=OFF'
# python.version: '2.7'
# CMakeGenerator: '-G "Visual Studio 15 2017 Win64"'
# MSBuildVersion: '15.0'
# ArchiveNoLibs: 'mlpack-windows-vs15-no-libs.zip'
# ArchiveLibs: 'mlpack-windows-vs15.zip'
# ArchiveTests: 'mlpack_test-vs15.xml'
steps:
- template: windows-steps.yaml
# steps:
# - template: windows-steps.yaml
- job: WindowsVS16
timeoutInMinutes: 360
+6 -1
View File
@@ -37,6 +37,11 @@ steps:
# Install armadillo.
curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo*
cmake . && make && sudo make install && cd ..
# Install cereal.
wget https://github.com/USCiLab/cereal/archive/v1.3.0.tar.gz
tar -xvzpf v1.3.0.tar.gz # Unpack into cereal-1.3.0/.
cd cereal-1.3.0/
displayName: 'Install Build Dependencies'
# Configure mlpack (CMake)
@@ -47,7 +52,7 @@ steps:
export GOPATH=$PWD/src/mlpack/bindings/go
go get -u -t gonum.org/v1/gonum/...
fi
cmake $(CMakeArgs) -DPYTHON_EXECUTABLE=`which python` ..
cmake $(CMakeArgs) -DPYTHON_EXECUTABLE=`which python` -DCEREAL_INCLUDE_DIR=../cereal-1.3.0/include/ ..
displayName: 'CMake'
# Build mlpack
+1 -1
View File
@@ -14,7 +14,7 @@ steps:
set -e
sudo xcode-select --switch /Applications/Xcode_12.2.app/Contents/Developer
unset BOOST_ROOT
brew install openblas armadillo boost
brew install openblas armadillo boost cereal
if [ "$(binding)" == "python" ]; then
pip install --upgrade pip
+3 -9
View File
@@ -10,19 +10,14 @@ steps:
- powershell: |
nuget install OpenBLAS -o $(Agent.ToolsDirectory)
nuget install boost -o $(Agent.ToolsDirectory) -Version 1.60.0
nuget install boost_unit_test_framework-vc140 -o $(Agent.ToolsDirectory) -Version 1.60.0
nuget install boost_program_options-vc140 -o $(Agent.ToolsDirectory) -Version 1.60.0
nuget install boost_random-vc140 -o $(Agent.ToolsDirectory) -Version 1.60.0
nuget install boost_serialization-vc140 -o $(Agent.ToolsDirectory) -Version 1.60.0
nuget install boost_math_c99-vc140 -o $(Agent.ToolsDirectory) -Version 1.60.0
nuget install OpenBLAS -o $(Agent.ToolsDirectory)
nuget install unofficial-flayan-cereal -o $(Agent.ToolsDirectory)
mkdir -p $(Agent.ToolsDirectory)/boost_libs
cp $(Agent.ToolsDirectory)/boost_program_options-vc140.1.60.0.0/lib/native/address-model-64/lib/*.* $(Agent.ToolsDirectory)/boost_libs
cp $(Agent.ToolsDirectory)/boost_math_c99-vc140.1.60.0.0/lib/native/address-model-64/lib/*.* $(Agent.ToolsDirectory)/boost_libs
cp $(Agent.ToolsDirectory)/boost_random-vc140.1.60.0.0/lib/native/address-model-64/lib/*.* $(Agent.ToolsDirectory)/boost_libs
cp $(Agent.ToolsDirectory)/boost_serialization-vc140.1.60.0.0/lib/native/address-model-64/lib/*.* $(Agent.ToolsDirectory)/boost_libs
cp $(Agent.ToolsDirectory)/boost_unit_test_framework-vc140.1.60.0.0/lib/native/address-model-64/lib/*.* $(Agent.ToolsDirectory)/boost_libs
displayName: 'Fetch build dependencies'
# Configure armadillo
@@ -66,6 +61,7 @@ steps:
-DARMADILLO_LIBRARY="..\armadillo-8.400.0\Release\armadillo.lib" `
-DBOOST_INCLUDEDIR=$(Agent.ToolsDirectory)\boost.1.60.0.0\lib\native\include `
-DBOOST_LIBRARYDIR=$(Agent.ToolsDirectory)\boost_libs `
-DCEREAL_INCLUDE_DIR=$(Agent.ToolsDirectory)\unofficial-flayan-cereal.1.2.2\build\native\include `
-DBUILD_JULIA_BINDINGS=OFF `
-DCMAKE_BUILD_TYPE=Release ..
displayName: 'Configure mlpack'
@@ -78,8 +74,6 @@ steps:
msbuildVersion: $(MSBuildVersion)
configuration: 'Release'
msbuildArchitecture: 'x64'
platform: 'x64'
msbuildArguments: /m /p:BuildInParallel=true
maximumCpuCount: false
clean: false
displayName: 'Build mlpack'
@@ -94,7 +88,7 @@ steps:
# Run tests via ctest.
- bash: |
cd build
CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test -C Release .
CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test -C Release . -j1
displayName: 'Run tests via ctest'
# Copy artifacts
+1 -1
View File
@@ -65,7 +65,7 @@ jobs:
- name: Install Build Dependencies
run: |
sudo apt-get update
sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ libboost-all-dev
sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ libboost-all-dev libcereal-dev
curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo*
cmake . && make && sudo make install && cd ..
+48
View File
@@ -0,0 +1,48 @@
name: Update Catch
on:
workflow_dispatch:
schedule:
- cron: '0 10 1/16 * *'
jobs:
updateCatch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Latest Catch Tagged Release
id: catch-header
run: |
# Ping version information upstream.
CATCH_RELEASE_JSON=$(curl -sL https://api.github.com/repos/catchorg/Catch2/releases/latest)
CATCH_RELEASE_VERSION=$(jq -r ".tag_name" <<< "$CATCH_RELEASE_JSON" | tr -d v)
echo ::set-output name=release_tag::$(echo $CATCH_RELEASE_VERSION)
# Extract out version information from git repository.
CATCH_VERSION_MAJOR=$(grep -i ".*#define CATCH_VERSION_MAJOR.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*")
CATCH_VERSION_MINOR=$(grep -i ".*#define CATCH_VERSION_MINOR.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*")
CATCH_VERSION_PATCH=$(grep -i ".*#define CATCH_VERSION_PATCH.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*")
# Combine values to match release tag information.
CATCH_VERSION_VALUE=${CATCH_VERSION_MAJOR}.${CATCH_VERSION_MINOR}.${CATCH_VERSION_PATCH}
# Set the current release tag.
echo ::set-output name=current_tag::$(echo $CATCH_VERSION_VALUE)
- name: Update Catch
if: steps.catch-header.outputs.current_tag != steps.catch-header.outputs.release_tag
env:
CURRENT_TAG: ${{ steps.catch-header.outputs.current_tag }}
RELEASE_TAG: ${{ steps.catch-header.outputs.release_tag }}
run: |
# Delete the catch.hpp.
rm -f src/mlpack/tests/catch.hpp
# Download the release.
curl -sL https://github.com/catchorg/Catch2/releases/latest/download/catch.hpp -o src/mlpack/tests/catch.hpp
- name: Create Pull Request For Catch
if: steps.catch-header.outputs.current_tag != steps.catch-header.outputs.release_tag
uses: peter-evans/create-pull-request@v3
with:
commit-message: Upgrade Catch to ${{ steps.catch-header.outputs.release_tag }}
title: Upgrade Catch to ${{ steps.catch-header.outputs.release_tag }}
body: |
Updates [catchorg/Catch2](https://github.com/catchorg/Catch2) to ${{ steps.catch-header.outputs.release_tag }}.
Auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request).
labels: update dependencies, automated PR
branch: catch-header-updates-${{ steps.catch-header.outputs.release_tag }}
+44
View File
@@ -0,0 +1,44 @@
name: Update CLI11
on:
workflow_dispatch:
schedule:
- cron: '0 10 1/16 * *'
jobs:
updateCLI11:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Latest CLI11 Tagged Release
id: cli11-header
run: |
# Ping version information upstream.
CLI11_RELEASE_JSON=$(curl -sL https://api.github.com/repos/CLIUtils/CLI11/releases/latest)
CLI11_RELEASE_VERSION=$(jq -r ".tag_name" <<< "$CLI11_RELEASE_JSON" | tr -d v)
echo ::set-output name=release_tag::$(echo $CLI11_RELEASE_VERSION)
# Extract out version information from git repository.
CLI11_VERSION_VALUE=$(grep -i ".*#define CLI11_VERSION.*" src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp | grep -Po "(\d+\.)+\d+")
# Set the current release tag.
echo ::set-output name=current_tag::$(echo $CLI11_VERSION_VALUE)
- name: Update CLI11
if: steps.cli11-header.outputs.current_tag != steps.cli11-header.outputs.release_tag
env:
CURRENT_TAG: ${{ steps.cli11-header.outputs.current_tag }}
RELEASE_TAG: ${{ steps.cli11-header.outputs.release_tag }}
run: |
# Delete the CLI11.hpp.
rm -f src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp
# Download the release.
curl -sL https://github.com/CLIUtils/CLI11/releases/latest/download/CLI11.hpp -o src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp
- name: Create Pull Request For CLI11
if: steps.cli11-header.outputs.current_tag != steps.cli11-header.outputs.release_tag
uses: peter-evans/create-pull-request@v3
with:
commit-message: Upgrade CLI11 to ${{ steps.cli11-header.outputs.release_tag }}
title: Upgrade CLI11 to ${{ steps.cli11-header.outputs.release_tag }}
body: |
Updates [CLIUtils/CLI11](https://github.com/CLIUtils/CLI11) to ${{ steps.cli11-header.outputs.release_tag }}.
Auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request).
labels: update dependencies, automated PR
branch: cli11-header-updates-${{ steps.cli11-header.outputs.release_tag }}
@@ -1,4 +1,4 @@
# ConfigureGenerate.cmake: generate an mlpack binding file given input
# ConfigureFile.cmake: generate an mlpack binding file given input
# arguments.
#
# This file depends on the following variables being set:
+11 -1
View File
@@ -28,7 +28,17 @@ function(find_r_module module)
string(REGEX MATCHALL "[0-9._]*" _version_compare "${_version_compare}")
string(REGEX REPLACE "" "" _version_compare "${_version_compare}")
string(REGEX REPLACE "" "" _version_compare "${_version_compare}")
if ("${_version_compare}" GREATER_EQUAL "${VERSION_REQ}")
# Compare the version of the package using compareVersion().
execute_process(COMMAND ${RSCRIPT_EXECUTABLE} "-e"
"compareVersion('${_version_compare}', '${VERSION_REQ}')"
RESULT_VARIABLE _compareVersion_status
OUTPUT_VARIABLE _compareVersion_result
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Extract compareVersion() result i.e. 1 -> Newer, 0 -> Equal and -1 -> Later.
string(REGEX REPLACE "\\[\\1\\]" "" _compareVersion_result "${_compareVersion_result}")
if ("${_compareVersion_result}" GREATER "-1")
set(R_${module_upper}
"${_${module}_location} (found suitable version \"${_version_compare}\", minimum required is \"${VERSION_REQ}\")"
CACHE STRING "Location of R module ${module}"
+56
View File
@@ -0,0 +1,56 @@
#Findcereal.cmake
find_path(CEREAL_INCLUDE_DIR
NAMES cereal
PATHS "$ENV{ProgramFiles}/cereal/include"
)
if(CEREAL_INCLUDE_DIR)
# ------------------------------------------------------------------------
# Extract version information from <CEREAL>
# ------------------------------------------------------------------------
set(CEREAL_FOUND YES)
set(CEREAL_VERSION_MAJOR 0)
set(CEREAL_VERSION_MINOR 0)
set(CEREAL_VERSION_PATCH 0)
if(EXISTS "${CEREAL_INCLUDE_DIR}/cereal/version.hpp")
# Read and parse cereal version header file for version number
file(READ "${CEREAL_INCLUDE_DIR}/cereal/version.hpp"
_CEREAL_HEADER_CONTENTS)
string(REGEX REPLACE ".*#define CEREAL_VERSION_MAJOR ([0-9]+).*" "\\1"
CEREAL_VERSION_MAJOR "${_CEREAL_HEADER_CONTENTS}")
string(REGEX REPLACE ".*#define CEREAL_VERSION_MINOR ([0-9]+).*" "\\1"
CEREAL_VERSION_MINOR "${_CEREAL_HEADER_CONTENTS}")
string(REGEX REPLACE ".*#define CEREAL_VERSION_PATCH ([0-9]+).*" "\\1"
CEREAL_VERSION_PATCH "${_CEREAL_HEADER_CONTENTS}")
elseif(EXISTS "${CEREAL_INCLUDE_DIR}/cereal/details/polymorphic_impl_fwd.hpp")
set(CEREAL_VERSION_MAJOR 1)
set(CEREAL_VERSION_MINOR 2)
set(CEREAL_VERSION_PATCH 0)
elseif(EXISTS "${CEREAL_INCLUDE_DIR}/cereal/types/valarray.hpp")
set(CEREAL_VERSION_MAJOR 1)
set(CEREAL_VERSION_MINOR 1)
set(CEREAL_VERSION_PATCH 2)
elseif(EXISTS "${CEREAL_INCLUDE_DIR}/cereal/cereal.hpp")
set(CEREAL_VERSION_MAJOR 1)
set(CEREAL_VERSION_MINOR 1)
set(CEREAL_VERSION_PATCH 1)
else()
set(CEREAL_FOUND NO)
endif()
set(CEREAL_VERSION_STRING "${CEREAL_VERSION_MAJOR}.${CEREAL_VERSION_MINOR}.${CEREAL_VERSION_PATCH}")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(cereal
REQUIRED_VARS CEREAL_INCLUDE_DIR
VERSION_VAR CEREAL_VERSION_STRING
)
mark_as_advanced(CEREAL_INCLUDE_DIR)
+5 -5
View File
@@ -54,9 +54,9 @@ Rcpp::RawVector Serialize${MODEL_SAFE_TYPE}Ptr(SEXP ptr)
{
std::ostringstream oss;
{
boost::archive::binary_oarchive oa(oss);
oa << boost::serialization::make_nvp(\"${MODEL_SAFE_TYPE}\",
*Rcpp::as<${MODEL_PTR_TYPEDEF}>(ptr));
cereal::BinaryOutputArchive oa(oss);
oa(cereal::make_nvp(\"${MODEL_SAFE_TYPE}\",
*Rcpp::as<${MODEL_PTR_TYPEDEF}>(ptr)));
}
Rcpp::RawVector raw_vec(oss.str().size());
@@ -76,8 +76,8 @@ SEXP Deserialize${MODEL_SAFE_TYPE}Ptr(Rcpp::RawVector str)
std::istringstream iss(std::string((char *) &str[0], str.size()));
{
boost::archive::binary_iarchive ia(iss);
ia >> boost::serialization::make_nvp(\"${MODEL_SAFE_TYPE}\", *ptr);
cereal::BinaryInputArchive ia(iss);
ia(cereal::make_nvp(\"${MODEL_SAFE_TYPE}\", *ptr));
}
// R will be responsible for freeing this.
+6 -6
View File
@@ -55,9 +55,9 @@ char* Serialize${MODEL_SAFE_TYPE}Ptr(void* ptr, size_t* length)
{
std::ostringstream oss;
{
boost::archive::binary_oarchive oa(oss);
cereal::BinaryOutputArchive oa(oss);
${MODEL_TYPE}* model = (${MODEL_TYPE}*) ptr;
oa << boost::serialization::make_nvp(\"${MODEL_SAFE_TYPE}\", model);
oa(CEREAL_POINTER(model));
}
*length = oss.str().length();
@@ -72,16 +72,16 @@ char* Serialize${MODEL_SAFE_TYPE}Ptr(void* ptr, size_t* length)
// Deserialize a ${MODEL_TYPE} pointer.
void* Deserialize${MODEL_SAFE_TYPE}Ptr(const char* buffer, const size_t length)
{
${MODEL_TYPE}* t = new ${MODEL_TYPE}();
${MODEL_TYPE}* model = new ${MODEL_TYPE}();
std::istringstream iss(std::string(buffer, length));
{
boost::archive::binary_iarchive ia(iss);
ia >> boost::serialization::make_nvp(\"${MODEL_SAFE_TYPE}\", t);
cereal::BinaryInputArchive ia(iss);
ia(CEREAL_POINTER(model));
}
// Julia will be responsible for freeing this.
return (void*) t;
return (void*) model;
}
")
endforeach ()
+5 -4
View File
@@ -22,6 +22,7 @@ option(BUILD_GO_SHLIB "Build Go shared library." OFF)
set(ARMADILLO_VERSION "8.400.0")
set(ENSMALLEN_VERSION "2.10.0")
set(BOOST_VERSION "1.58")
set(CEREAL_VERSION "1.1.2")
if (WIN32)
option(BUILD_SHARED_LIBS
@@ -140,7 +141,7 @@ set(COMPILER_SUPPORT_LIBRARIES "")
# If we are using MSVC, we need /bigobj.
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /Zm400")
endif ()
# If we are using MINGW, we need sections and big-obj, otherwise we create too
@@ -353,7 +354,6 @@ else ()
set(STB_AVAILABLE "1")
endif ()
# Find ensmallen.
# Once ensmallen is readily available in package repos, the automatic downloader
# here can be removed.
@@ -413,6 +413,9 @@ else ()
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} "${ENSMALLEN_INCLUDE_DIR}")
endif ()
find_package(cereal "${CEREAL_VERSION}" REQUIRED)
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${CEREAL_INCLUDE_DIR})
# Unfortunately this configuration variable is necessary and will need to be
# updated as time goes on and new versions are released.
set(Boost_ADDITIONAL_VERSIONS
@@ -441,8 +444,6 @@ set(Boost_ADDITIONAL_VERSIONS
set(Boost_NO_BOOST_CMAKE 1)
find_package(Boost "${BOOST_VERSION}"
COMPONENTS
unit_test_framework
serialization
REQUIRED
)
+1 -1
View File
@@ -4,7 +4,7 @@
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = mlpack
PROJECT_NUMBER = 3.4.1
PROJECT_NUMBER = 3.4.2
OUTPUT_DIRECTORY = ./doc
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
+3
View File
@@ -1,5 +1,8 @@
### mlpack ?.?.?
###### ????-??-??
### mlpack 3.4.2
###### 2020-10-26
* Added Mean Absolute Percentage Error.
* Added Softmin activation function as layer in ann/layer.
+5 -4
View File
@@ -23,7 +23,7 @@ src="https://cdn.rawgit.com/mlpack/mlpack.org/e7d36ed8/mlpack-black.svg" style="
<p align="center">
<em>
Download:
<a href="https://www.mlpack.org/files/mlpack-3.4.1.tar.gz">current stable version (3.4.1)</a>
<a href="https://www.mlpack.org/files/mlpack-3.4.2.tar.gz">current stable version (3.4.2)</a>
</em>
</p>
@@ -101,10 +101,10 @@ Citations are beneficial for the growth and improvement of mlpack.
mlpack has the following dependencies:
Armadillo >= 8.400.0
Boost (math_c99, unit_test_framework, serialization,
spirit) >= 1.58.0
Boost (math_c99, spirit) >= 1.58.0
CMake >= 3.2.2
ensmallen >= 2.10.0
cereal >= 1.1.2
All of those should be available in your distribution's package manager. If
not, you will have to compile each of them by hand. See the documentation for
@@ -134,6 +134,7 @@ installed with these R packages.
RcppEnsmallen >= 0.2.10.0
BH >= 1.58
roxygen2
Rcereal >= 1.1.2
If the STB library headers are available, image loading support will be
compiled.
@@ -152,7 +153,7 @@ on Ubuntu, you can install mlpack with the following command:
Note: Older Ubuntu versions may not have the most recent version of mlpack
available---for instance, at the time of this writing, Ubuntu 16.04 only has
mlpack 3.4.1 available. Options include upgrading your Ubuntu version, finding
mlpack 3.4.2 available. Options include upgrading your Ubuntu version, finding
a PPA or other non-official sources, or installing with a manual build.
There are some useful pages to consult in addition to this section:
@@ -104,16 +104,16 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>false</ConformanceMode>
<AdditionalIncludeDirectories>C:\boost\boost_1_66_0;C:\mlpack\armadillo-8.500.1\include;C:\mlpack\mlpack-3.4.1\build\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\boost\boost_1_66_0;C:\mlpack\armadillo-8.500.1\include;C:\mlpack\mlpack-3.4.2\build\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>C:\mlpack\mlpack-3.4.1\build\Debug\mlpack.lib;C:\boost\boost_1_66_0\lib64-msvc-14.1\libboost_serialization-vc141-mt-gd-x64-1_66.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>C:\mlpack\mlpack-3.4.2\build\Debug\mlpack.lib;C:\boost\boost_1_66_0\lib64-msvc-14.1\libboost_serialization-vc141-mt-gd-x64-1_66.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>xcopy /y "C:\mlpack\mlpack-3.4.1\build\Debug\mlpack.dll" $(OutDir)
xcopy /y "C:\mlpack\mlpack-3.4.1\packages\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll" $(OutDir)
<Command>xcopy /y "C:\mlpack\mlpack-3.4.2\build\Debug\mlpack.dll" $(OutDir)
xcopy /y "C:\mlpack\mlpack-3.4.2\packages\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll" $(OutDir)
xcopy /y "$(ProjectDir)..\..\..\..\src\mlpack\tests\data\german.csv" "$(ProjectDir)data\german.csv*"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
+2 -2
View File
@@ -682,8 +682,8 @@ mlpack models. These could be used, for instance, to allow the user to save a
trained model (like a linear regression model) or load an input model. The
first parameter to the @c PARAM_MODEL_IN() or @c PARAM_MODEL_OUT() macro should
be the C++ type of the model to be serialized; this type @b must have a function
<tt>template<typename Archive> void Serialize(Archive&, const unsigned int)</tt>
(i.e. the type must be serializable via mlpack's boost::serialization shim).
<tt>template<typename Archive> void serialize(Archive&)</tt>
(i.e. the type must be serializable via cereal).
For example, to allow a user to specify an input model of type
`LinearRegression`, the follow definition could be used:
+10 -10
View File
@@ -30,7 +30,7 @@ to build mlpack on Windows, see \ref build_windows (alternatively, you can read
is based on older versions).
You can download the latest mlpack release from here:
<a href="https://www.mlpack.org/files/mlpack-3.4.1.tar.gz">mlpack-3.4.1</a>
<a href="https://www.mlpack.org/files/mlpack-3.4.2.tar.gz">mlpack-3.4.2</a>
@section build_simple Simple Linux build instructions
@@ -38,9 +38,9 @@ Assuming all dependencies are installed in the system, you can run the commands
below directly to build and install mlpack.
@code
$ wget https://www.mlpack.org/files/mlpack-3.4.1.tar.gz
$ tar -xvzpf mlpack-3.4.1.tar.gz
$ mkdir mlpack-3.4.1/build && cd mlpack-3.4.1/build
$ wget https://www.mlpack.org/files/mlpack-3.4.2.tar.gz
$ tar -xvzpf mlpack-3.4.2.tar.gz
$ mkdir mlpack-3.4.2/build && cd mlpack-3.4.2/build
$ cmake ../
$ make -j4 # The -j is the number of cores you want to use for a build.
$ sudo make install
@@ -65,8 +65,8 @@ configure mlpack.
First we should unpack the mlpack source and create a build directory.
@code
$ tar -xvzpf mlpack-3.4.1.tar.gz
$ cd mlpack-3.4.1
$ tar -xvzpf mlpack-3.4.2.tar.gz
$ cd mlpack-3.4.2
$ mkdir build
@endcode
@@ -78,8 +78,8 @@ mlpack depends on the following libraries, which need to be installed on the
system and have headers present:
- Armadillo >= 8.400.0 (with LAPACK support)
- Boost (math_c99, serialization, unit_test_framework, heap,
spirit) >= 1.58
- Boost (math_c99, unit_test_framework, heap, spirit) >= 1.58
- cereal >= 1.1.2
- ensmallen >= 2.10.0 (will be downloaded if not found)
In addition, mlpack has the following optional dependencies:
@@ -99,7 +99,7 @@ In Ubuntu (>= 18.04) and Debian (>= 10) all of these dependencies can be
installed through apt:
@code
# apt-get install libboost-math-dev libboost-test-dev libboost-serialization-dev
# apt-get install libboost-math-dev libboost-test-dev libcereal-dev
libarmadillo-dev binutils-dev python3-pandas python3-numpy cython3
python3-setuptools
@endcode
@@ -124,7 +124,7 @@ On Fedora, Red Hat, or CentOS, these same dependencies can be obtained via dnf:
@code
# dnf install boost-devel boost-test boost-math armadillo-devel binutils-devel
python3-Cython python3-setuptools python3-numpy python3-pandas ensmallen-devel
stbi-devel
stbi-devel cereal-devel
@endcode
(It's also possible to use python3 packages from the package manager---mlpack
+7 -8
View File
@@ -447,11 +447,11 @@ Multiple images are saved according to the vector of filenames specified.
@section formatmodels Loading and saving models
Using \c boost::serialization, mlpack is able to load and save machine learning
Using \c cereal, mlpack is able to load and save machine learning
models with ease. These models can currently be saved in three formats:
- binary (.bin); this is not human-readable, but it is small
- text (.txt); this is sort of human-readable and relatively small
- json (.json); this is sort of human-readable and relatively small
- xml (.xml); this is human-readable but very verbose and large
The type of file to save is determined by the given file extension, as with the
@@ -471,7 +471,7 @@ options; for more information, see the documentation for each program
@section formatmodelscpp Loading and saving models in C++
mlpack uses the \c boost::serialization library internally to perform loading
mlpack uses the \c cereal library internally to perform loading
and saving of models, and provides convenience overloads of mlpack::data::Load()
and mlpack::data::Save() to load and save these models.
@@ -479,13 +479,12 @@ To be serializable, a class must implement the method
\code
template<typename Archive>
void serialize(Archive& ar, const unsigned int version);
void serialize(Archive& ar);
\endcode
\note
For more information on this method and how it works, see the
boost::serialization documentation at
http://www.boost.org/libs/serialization/doc/.
cereal documentation at https://uscilab.github.io/cereal/index.html.
\note
Examples of serialize() methods can be found in most classes; one fairly
@@ -503,11 +502,11 @@ mlpack::math::Range object.
\code
// Create range and save it.
mlpack::math::Range r(0.0, 5.0);
mlpack::data::Save("range.txt", "range", r);
mlpack::data::Save("range.json", "range", r);
// Load into new range.
mlpack::math::Range newRange;
mlpack::data::Load("range.txt", "range", newRange);
mlpack::data::Load("range.json", "range", newRange);
\endcode
It is important to be sure that you load the appropriate type; if you save, for
+3 -3
View File
@@ -32,9 +32,9 @@ build and install mlpack. You can copy-paste the commands into your shell.
@code{.sh}
sudo apt-get install libboost-all-dev g++ cmake libarmadillo-dev python-pip wget
sudo pip install cython setuptools distutils numpy pandas
wget https://www.mlpack.org/files/mlpack-3.4.1.tar.gz
tar -xvzpf mlpack-3.4.1.tar.gz
mkdir -p mlpack-3.4.1/build/ && cd mlpack-3.4.1/build/
wget https://www.mlpack.org/files/mlpack-3.4.2.tar.gz
tar -xvzpf mlpack-3.4.2.tar.gz
mkdir -p mlpack-3.4.2/build/ && cd mlpack-3.4.2/build/
cmake ../ && make -j4 && sudo make install
@endcode
+4 -4
View File
@@ -29,17 +29,17 @@ mlpack and dependencies in Release Mode).
@code
- C:\boost\boost_1_71_0\lib\native\include
- C:\mlpack\armadillo-9.800.3\include
- C:\mlpack\mlpack-3.4.1\build\include
- C:\mlpack\mlpack-3.4.2\build\include
@endcode
- Under Linker > Input > Additional Dependencies add:
@code
- C:\mlpack\mlpack-3.4.1\build\Debug\mlpack.lib
- C:\mlpack\mlpack-3.4.2\build\Debug\mlpack.lib
- C:\boost\boost_1_71_0\lib64-msvc-14.2\libboost_serialization-vc142-mt-gd-x64-1_71.lib
@endcode
- Under Build Events > Post-Build Event > Command Line add:
@code
- xcopy /y "C:\mlpack\mlpack-3.4.1\build\Debug\mlpack.dll" $(OutDir)
- xcopy /y "C:\mlpack\mlpack-3.4.1\packages\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll" $(OutDir)
- xcopy /y "C:\mlpack\mlpack-3.4.2\build\Debug\mlpack.dll" $(OutDir)
- xcopy /y "C:\mlpack\mlpack-3.4.2\packages\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll" $(OutDir)
@endcode
@note Recent versions of Visual Studio set "Conformance Mode" enabled by default. This causes some issues with
+16 -16
View File
@@ -225,7 +225,7 @@ class ExampleTree
// tree using the given MetricType.
ExampleTree(const MatType& data, MetricType& metric);
// Initialize the tree from a given boost::serialization archive. SFINAE (the
// Initialize the tree from a given cereal archive. SFINAE (the
// second argument) is necessary to ensure that the archive is loading, not
// saving.
template<typename Archive>
@@ -330,16 +330,16 @@ class ExampleTree
// Serialize the tree (load from the given archive / save to the given
// archive, depending on its type).
template<typename Archive>
void Serialize(Archive& ar, const unsigned int version);
void serialize(Archive& ar, const uint32_t version);
protected:
// A default constructor; only meant to be used by boost::serialization. This
// must be protected so that boost::serialization will work; it does not need
// A default constructor; only meant to be used by cereal. This
// must be protected so that cereal will work; it does not need
// to return a valid tree.
ExampleTree();
// Friend access must be given for the default constructor.
friend class boost::serialization::access;
friend class cereal::access;
};
@endcode
@@ -378,7 +378,7 @@ calculation, and (usually) provides a decent bound on the minimum distance
between \f$p\f$ and any descendant point of the node.
- **Trees need to be able to be serialized.** mlpack uses the
boost::serialization library for saving and loading objects. Trees---which can
cereal library for saving and loading objects. Trees---which can
be a part of machine learning models---therefore must have the ability to be
saved and loaded. Making this all work requires a protected constructor (part
of the API) and generally makes it impossible to hold references instead of
@@ -481,10 +481,10 @@ It is possible to implement both these constructors as one by using \c
boost::optional.
The third constructor requires the tree to be initializable from a \c
boost::serialization archive:
cereal archive:
@code
// Initialize the tree from a given boost::serialization archive. SFINAE (the
// Initialize the tree from a given cereal archive. SFINAE (the
// second argument) is necessary to ensure that the archive is loading, not
// saving.
template<typename Archive>
@@ -507,7 +507,7 @@ will be required:
and, if the data matrix is represented internally with a pointer, this
destructor will need to release the memory for the data matrix (in the case that
the tree was created via \c boost::serialization ).
the tree was created via \c cereal ).
Note that these constructors are not necessarily the only constructors that a
\c TreeType implementation can provide. One important example of when more
@@ -778,22 +778,22 @@ the node plus one or two levels of children.
// Serialize the tree (load from the given archive / save to the given
// archive, depending on its type).
template<typename Archive>
void Serialize(Archive& ar, const unsigned int version);
void serialize(Archive& ar);
protected:
// A default constructor; only meant to be used by boost::serialization. This
// must be protected so that boost::serialization will work; it does not need
// A default constructor; only meant to be used by cereal. This
// must be protected so that cereal will work; it does not need
// to return a valid tree.
ExampleTree();
// Friend access must be given for the default constructor.
friend class boost::serialization::access;
friend class cereal::access;
@endcode
On the other hand, the specifics of the functionality required for the
\c Serialize() function are somewhat more difficult. The \c Serialize()
function will be called either when a tree is being saved to disk or loaded from
disk. The \c boost::serialization documentation is fairly comprehensive, but
disk. The \c cereal documentation is fairly comprehensive.
when writing a \c Serialize() method for mlpack trees you should use
\c data::CreateNVP() instead of \c BOOST_SERIALIZATION_NVP(). This is because
mlpack classes implement \c Serialize() instead of \c serialize() in order to
@@ -803,10 +803,10 @@ be useful to look at other \c Serialize() methods contained in other mlpack
classes as an example.
An important note is that it is very difficult to use references with
\c boost::serialization, because \c Serialize() may be called at any time during
\c cereal, because \c serialize() may be called at any time during
the object's lifetime, and references cannot be re-seated. In general this will
require the use of pointers, which then require manual memory management.
Therefore, be careful that \c Serialize() (and the tree's destructor) properly
Therefore, be careful that \c serialize() (and the tree's destructor) properly
handle memory management!
@section treetype_traits The TreeTraits trait class
+73 -47
View File
@@ -573,8 +573,8 @@ a new reference set. This is functionally equivalent to creating a new model.
@section model_saving_loading_anntut Saving & Loading
Using \c boost::serialization (for more information about the internals see
[Serialization - Boost C++ Libraries](www.boost.org/libs/serialization/doc/)),
Using \c cereal (for more information about the internals see
[the Cereal website](http://uscilab.github.io/cereal/)),
mlpack is able to load and save machine learning models with ease. To save a
trained neural network to disk. The example below builds a model on the \c
thyroid dataset and then saves the model to the file \c model.xml for later use.
@@ -589,7 +589,7 @@ arma::mat trainData = dataset.submat(0, 0, dataset.n_rows - 4,
dataset.n_cols - 1);
// Split the data from the training set.
arma::mat trainLabelsTemp = dataset.submat(dataset.n_rows - 3, 0,
arma::mat trainLabels = dataset.submat(dataset.n_rows - 3, 0,
dataset.n_rows - 1, dataset.n_cols - 1);
// Initialize the network.
@@ -615,50 +615,76 @@ Now, we can look at the output model file, \c model.xml:
@code
$ cat model.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="15">
<model class_id="0" tracking_level="0" version="0">
<parameter class_id="1" tracking_level="1" version="0" object_id="_0">
<n_rows>66</n_rows>
<n_cols>1</n_cols>
<n_elem>66</n_elem>
<vec_state>0</vec_state>
<item>-7.55971528334903642e+00</item>
<item>-9.95435955058058930e+00</item>
<item>9.31133928948225353e+00</item>
<item>-5.36784434861701953e+00</item>
...
</parameter>
<width>0</width>
<height>0</height>
<currentInput object_id="_1">
<n_rows>0</n_rows>
<n_cols>0</n_cols>
<n_elem>0</n_elem>
<vec_state>0</vec_state>
</currentInput>
<network class_id="2" tracking_level="0" version="0">
<count>3</count>
<item_version>0</item_version>
<item class_id="3" tracking_level="0" version="0">
<which>18</which>
<value class_id="4" tracking_level="1" version="0" object_id="_2">
<inSize>21</inSize>
<outSize>3</outSize>
</value>
</item>
<item>
<which>2</which>
<value class_id="5" tracking_level="1" version="0" object_id="_3"></value>
</item>
<item>
<which>20</which>
<value class_id="6" tracking_level="1" version="0" object_id="_4"></value>
</item>
</network>
</model>
</boost_serialization>
<?xml version="1.0" encoding="utf-8"?>
<cereal>
<model>
<cereal_class_version>0</cereal_class_version>
<parameter>
<n_rows>60</n_rows>
<n_cols>1</n_cols>
<vec_state>0</vec_state>
<elem>10.461979353567767</elem>
<elem>-10.040855482151116</elem>
<elem>0.18048901768535316</elem>
<elem>4.8989495084787169</elem>
<elem>-4.4381643782652276</elem>
<elem>0.049477846402230616</elem>
<elem>2.5271808924795987</elem>
<elem>-3.96993488526287</elem>
...
</parameter>
<width>0</width>
<height>0</height>
<reset>true</reset>
<value0>
<vecSize>3</vecSize>
<value0>
<which>30</which>
<value0>
<cereal_class_version>0</cereal_class_version>
<smartPointer>
<ptr_wrapper>
<valid>1</valid>
<data>
<cereal_class_version>0</cereal_class_version>
<inSize>19</inSize>
<outSize>3</outSize>
</data>
</ptr_wrapper>
</smartPointer>
</value0>
</value0>
<value1>
<which>6</which>
<value0>
<cereal_class_version>0</cereal_class_version>
<smartPointer>
<ptr_wrapper>
<valid>1</valid>
<data>
<cereal_class_version>0</cereal_class_version>
</data>
</ptr_wrapper>
</smartPointer>
</value0>
</value1>
<value2>
<which>32</which>
<value0>
<cereal_class_version>0</cereal_class_version>
<smartPointer>
<ptr_wrapper>
<valid>1</valid>
<data>
<cereal_class_version>0</cereal_class_version>
</data>
</ptr_wrapper>
</smartPointer>
</value0>
</value2>
</value0>
</model>
</cereal>
@endcode
As you can see, the \c \<parameter\> section of \c model.xml contains the trained
+221
View File
@@ -0,0 +1,221 @@
#!/usr/bin/env bash
#
# Release a new version of mlpack.
#
# Usage: release-mlpack.sh X Y Z
#
# where X is the major version, Y is the minor version, and Z is the patch
# version. Run this from the root of the repository.
#
# Make sure HISTORY.md is updated first!
set +e
if [ "$#" -ne "4" ];
then
echo "Usage: mlpack-release.sh <github username> <major> <minor> <patch>";
exit 1;
fi
# First, check for any unlicensed files.
output=$(
for i in $(find src/ -iname '*.[hc]pp');
do
echo -n $i": ";
cat $i | grep 'mlpack is free software;' | wc -l;
done |\
grep -v ': 1' |\
grep -v 'arma_extend' |\
grep -v 'boost_backport' |\
grep -v 'arma_config.hpp' |\
grep -v 'gitversion.hpp' |\
grep -v 'CLI11.hpp' |\
grep -v 'bindings/R/mlpack/src/boost/serialization' |\
grep -v 'tests/catch.hpp');
lines=`echo $output | grep -v '^[ ]*$' | wc -l`;
if [ "0$lines" -gt "0" ];
then
echo "Unlicensed files found! Aborting release.";
echo "$output";
exit 1;
fi
# Now, check that there are no local changes.
lines=`git diff | wc -l | sed -e 's/^\s*//g'`;
if [ "$lines" != "0" ]; then
echo "git diff returned a nonzero result!";
echo "";
git diff;
exit 1;
fi
# Next, make sure the origin is right.
dest_remote_name=`git remote -v |\
grep "mlpack/mlpack (fetch)" |\
head -1 |\
awk -F' ' '{ print $1 }'`;
if [ "a$dest_remote_name" == "a" ]; then
echo "No git remote found for https://github.com/mlpack/mlpack!";
echo "Make sure that you've got the ensmallen repository as a remote, and" \
"that the master branch from that remote is checked out.";
echo "You can do this with a fresh repository via \`git clone" \
"https://github.com/mlpack/mlpack\`.";
exit 1;
fi
# Also check that we're on the master branch, from the correct origin.
current_branch=`git branch --no-color | grep '^\* ' | awk -F' ' '{ print $2 }'`;
current_origin=`git rev-parse --abbrev-ref --symbolic-full-name @{u} |\
awk -F'/' '{ print $1 }'`;
if [ "a$current_branch" != "amaster" ]; then
echo "Current branch is $current_branch.";
echo "This script has to be run from the master branch.";
exit 1;
elif [ "a$current_origin" != "a$dest_remote_name" ]; then
echo "Current branch does not track from remote mlpack repository!";
echo "Instead, it tracks from $current_origin/master.";
echo "Make sure to check out a branch that tracks $dest_remote_name/master.";
exit 1;
fi
# Make sure `hub` is installed.
hub_output="`which hub`" || true;
if [ "a$hub_output" == "a" ]; then
echo "The Hub command-line tool must be installed for this script to run" \
"successfully.";
echo "See https://hub.github.com for more details and installation" \
"instructions.";
echo "";
echo "(apt-get install hub on Debian and Ubuntu)";
echo "(brew install hub via Homebrew)";
exit 1;
fi
# Check git remotes: we need to make sure we have a fork to push to.
github_user=$1;
remote_name`git remote -v |\
grep "$github_user/mlpack (push)" |\
head -1 |\
awk -F' ' '{ print $1 }'`;
if [ "a$remote_name" == "a" ]; then
echo "No git remote found for $github_user/mlpack!";
echo "Adding remote '$github_user'.";
git remote add $github_user https://github.com/$github_user/mlpack;
remote_name="$github_user";
fi
git fetch $github_user;
# Make sure everything is up to date.
git pull;
# Make updates to files that will be needed for the release.
MAJOR="$2";
MINOR="$3";
PATCH="$4";
# Update version.
sed --in-place -E 's/PROJECT_NUMBER([ \t]*)= .*$/PROJECT_NUMBER\1= '$MAJOR'.'$MINOR'.'$PATCH'/' \
Doxyfile;
sed --in-place 's/MLPACK_VERSION_MAJOR [0-9]*$/MLPACK_VERSION_MAJOR '$MAJOR'/' \
src/mlpack/core/util/version.hpp;
sed --in-place 's/MLPACK_VERSION_MINOR [0-9]*$/MLPACK_VERSION_MINOR '$MINOR'/' \
src/mlpack/core/util/version.hpp;
sed --in-place 's/MLPACK_VERSION_PATCH [0-9]*$/MLPACK_VERSION_PATCH '$PATCH'/' \
src/mlpack/core/util/version.hpp;
sed --in-place 's/ VERSION [0-9]*\.[0-9]*/ VERSION '$MAJOR'.'$MINOR'/' \
src/mlpack/CMakeLists.txt;
sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \
doc/guide/build.hpp;
sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \
doc/guide/python_quickstart.hpp;
sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \
doc/guide/sample_ml_app.hpp;
sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \
doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj;
sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \
README.md;
sed --in-place 's/([0-9]\.[0-9]\.[0-9])/('$MAJOR'.'$MINOR'.'$PATCH')/g' \
README.md;
sed --in-place 's/mlpack [0-9]\.[0-9]\.[0-9]/mlpack '$MAJOR'.'$MINOR'.'$PATCH'/g' \
README.md;
sed --in-place 's/### mlpack ?[.]?[.]?/### mlpack '$MAJOR'.'$MINOR'.'$PATCH'/g' HISTORY.md;
year=`date +%Y`;
month=`date +%m`;
day=`date +%d`;
sed --in-place 's/###### ????-??-??/###### '$year'-'$month'-'$day'/g' \
HISTORY.md;
# Get the latest release of ensmallen.
git clone https://github.com/mlpack/ensmallen /tmp/ensmallen;
cd /tmp/ensmallen;
ens_ver=`git describe --tags $(git rev-list --tags --max-count=1)`;
echo "Latest version of ensmallen: $ens_ver"
cd -;
sed --in-place "s/ensmallen-latest.tar.gz/ensmallen-$ens_ver.tar.gz/" CMakeLists.txt;
rm -rf /tmp/ensmallen;
# Make these changes on a release branch.
git checkout -b release-$MAJOR.$MINOR.$PATCH;
git add Doxyfile src/mlpack/core/util/version.hpp src/mlpack/CMakeLists.txt \
doc/guide/build.hpp doc/guide/python_quickstart.hpp \
doc/guide/sample_ml_app.hpp \
doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj \
CMakeLists.txt \
README.md \
HISTORY.md;
git commit -m "Update and release version $MAJOR.$MINOR.$PATCH.";
changelog_str=`cat HISTORY.md |\
awk '/^### /{f=0} /^### mlpack '"$MAJOR"'.'"$MINOR"'.'"$PATCH"'/{f=1} f{print}' |\
grep -v '^#' |\
tr '\n' '!' |\
sed -e 's/! [ ]*/ /g' |\
tr '!' '\n'`;
echo "Changelog string:"
echo "$changelog_str"
# Update version again and add a new block for HISTORY.md.
sed --in-place 's/MLPACK_VERSION_PATCH [0-9]*$/MLPACK_VERSION_PATCH '$(($PATCH + 1))'/' \
src/mlpack/core/util/version.hpp;
sed --in-place 's/ensmallen-'$ens_ver'.tar.gz/ensmallen-latest.tar.gz/' CMakeLists.txt;
echo "### mlpack ?.?.?" > HISTORY.md.new;
echo "###### ????-??-??" >> HISTORY.md.new;
echo "" >> HISTORY.md.new;
cat HISTORY.md >> HISTORY.md.new;
mv HISTORY.md.new HISTORY.md;
git add HISTORY.md;
git add src/mlpack/core/util/version.hpp CMakeLists.txt;
git commit -m "Add new block for next release to HISTORY.md.";
# Push to new branch.
git push --set-upstream $github_user release-$MAJOR.$MINOR.$PATCH;
# Next, we have to actually open the PR for the release.
hub pull-request \
-b mlpack:master \
-h $github_user:release-$MAJOR.$MINOR.$PATCH \
-m "Release version $MAJOR.$MINOR.$PATCH" \
-m "This automatically-generated pull request adds the commits necessary to
make the $MAJOR.$MINOR.$PATCH release." \
-m "Once the PR is merged, mlpack-bot will tag the release as HEAD~1 (so
that it doesn't include the new HISTORY block) and publish it." \
-m "Or, well, hopefully that will happen someday." \
-m "When you merge this PR, be sure to merge it using a *rebase*." \
-m "### Changelog" \
-m "$changelog_str" \
-l "t: release"
echo "";
echo "Switching back to 'master' branch.";
echo "If you want to access the release branch again, use \`git checkout " \
"release-$MAJOR.$MINOR.$PATCH\`.";
echo 0;
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
#
# This script is used to update the website after an mlpack release is made.
# Push access to the mlpack.org website repository is needed. Generally, this
# script will be run by mlpack-bot, so it never needs to be run by hand.
#
# Usage: update-website-after-release.sh <major> <minor> <patch>
MAJOR=$1;
MINOR=$2;
PATCH=$3;
# Make sure that the mlpack repository exists.
dest_remote_name=`git remote -v |\
grep "mlpack/mlpack (fetch)" |\
head -1 |\
awk -F' ' '{ print $1 }'`;
if [ "a$dest_remote_name" == "a" ]; then
echo "No git remote found for mlpack/mlpack!";
echo "Make sure that you've got the mlpack repository as a remote, and" \
"that the master branch from that remote is checked out.";
echo "You can do this with a fresh repository via \`git clone" \
"https://github.com/mlpack/mlpack\`.";
exit 1;
fi
# Update the checked out repository, so that we can get the tags.
git fetch $dest_remote_name;
# Check out a copy of the ensmallen.org repository.
git clone git@github.com:mlpack/mlpack.org /tmp/mlpack.org/;
# Create the release file.
git archive --prefix=mlpack-$MAJOR.$MINOR.$PATCH/ $MAJOR.$MINOR.$PATCH |\
gzip > /tmp/mlpack.org/files/mlpack-$MAJOR.$MINOR.$PATCH.tar.gz;
# Now update the website.
wd=`pwd`;
cd /tmp/mlpack.org/;
# These may be specific to the old website.
sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' index.md;
sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' docs.md;
sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' getstarted.md;
sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' community.md;
git add index.md docs.md getstarted.md community.md;
# These may be specific to the new website.
sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' html/index.html;
sed --in-place 's/Version [0-9]\.[0-9]\.[0-9]/Version '$MAJOR'.'$MINOR'.'$PATCH'/g' html/index.html;
sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' html/getstarted.html;
sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' html/config/install.md;
git add html/index.html html/getstarted.html html/config/install.md;
git commit -m "Update links to latest stable version.";
git add files/mlpack-$MAJOR.$MINOR.$PATCH.tar.gz;
git commit -m "Release version $MAJOR.$MINOR.$PATCH.";
# Finally, push, and we're done.
git push origin;
cd $wd;
rm -rf /tmp/mlpack.org;
+9 -39
View File
@@ -23,6 +23,7 @@ if (BUILD_R_BINDINGS)
set(RcppArmadillo_Version "0.${ARMADILLO_VERSION}")
set(RcppEnsmallen_Version "0.${ENSMALLEN_VERSION}")
set(BH_Version "${BOOST_VERSION}")
set(Rcereal_Version "${CEREAL_VERSION}")
# Import find_r_module.
include(${CMAKE_SOURCE_DIR}/CMake/FindRModule.cmake)
@@ -54,18 +55,22 @@ if (BUILD_R_BINDINGS)
if (NOT R_TESTTHAT)
set(R_NOT_FOUND_MSG "${R_NOT_FOUND_MSG}\n - testthat")
endif ()
find_r_module(Rcereal "${Rcereal_Version}")
if (NOT R_RCEREAL)
set(R_NOT_FOUND_MSG "${R_NOT_FOUND_MSG}\n - Rcereal")
endif ()
## We need to check here if R and other dependencies is even available, as
## it is require to build R-bindings.
if (FORCE_BUILD_R_BINDINGS)
if (NOT R_FOUND OR NOT R_RCPP OR NOT R_RCPPARMADILLO OR NOT R_RCPPENSMALLEN
OR NOT R_BH OR NOT R_ROXYGEN2 OR NOT R_TESTTHAT)
OR NOT R_BH OR NOT R_ROXYGEN2 OR NOT R_TESTTHAT OR NOT R_RCEREAL)
unset(BUILD_R_BINDINGS CACHE)
message(FATAL_ERROR "Could not Build R Bindings, Following modules are not available:${R_NOT_FOUND_MSG}")
endif()
else ()
if (NOT R_FOUND OR NOT R_RCPP OR NOT R_RCPPARMADILLO OR NOT R_RCPPENSMALLEN
OR NOT R_BH OR NOT R_ROXYGEN2 OR NOT R_TESTTHAT)
OR NOT R_BH OR NOT R_ROXYGEN2 OR NOT R_TESTTHAT OR NOT R_RCEREAL)
unset(BUILD_R_BINDINGS CACHE)
not_found_return("Not building R bindings, Following modules are not available:${R_NOT_FOUND_MSG}")
endif()
@@ -97,33 +102,6 @@ if (BUILD_R_BINDINGS)
"# Generated by roxygen2: do not edit by hand"
"\n\n")
# These are all the files we need to compile R bindings for mlpack that are
# not a part of mlpack itself.
# Soon may be mlpack use cereal package for serialization.
# Then we can remove these boost files.
set(BOOST_SOURCES
"${CMAKE_SOURCE_DIR}/src/mlpack/core/boost_backport/unordered_map.hpp"
"${CMAKE_SOURCE_DIR}/src/mlpack/core/boost_backport/unordered_collections_load_imp.hpp"
"${CMAKE_SOURCE_DIR}/src/mlpack/core/boost_backport/unordered_collections_save_imp.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/archive_exception.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_archive.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_oarchive.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_oserializer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_iarchive.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_iserializer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_pointer_iserializer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_pointer_oserializer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_text_oprimitive.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/basic_serializer_map.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/binary_iarchive.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/binary_oarchive.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/extended_type_info_typeid.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/extended_type_info.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/utf8_codecvt_facet.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/void_cast.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/boost/serialization/variant.hpp"
)
set(CPP_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/r_util.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/src/rcpp_mlpack.h"
@@ -174,8 +152,6 @@ if (BUILD_R_BINDINGS)
${CMAKE_CURRENT_BINARY_DIR}/mlpack/R/
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_CURRENT_BINARY_DIR}/mlpack/tests/testthat
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_CURRENT_BINARY_DIR}/mlpack/src/boost/serialization/
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_CURRENT_BINARY_DIR}/mlpack/src/mlpack/bindings/R/tests
)
@@ -188,12 +164,6 @@ if (BUILD_R_BINDINGS)
endif()
# Copy all necessary files for building package.
foreach(boost_file ${BOOST_SOURCES})
add_custom_command(TARGET r_copy PRE_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different
${boost_file}
${CMAKE_CURRENT_BINARY_DIR}/mlpack/src/boost/serialization/)
endforeach()
foreach(cpp_file ${CPP_SOURCES})
add_custom_command(TARGET r_copy PRE_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different
@@ -307,9 +277,9 @@ if (BUILD_R_BINDINGS)
-DGENERATE_CPP_IN=${CMAKE_SOURCE_DIR}/src/mlpack/bindings/R/generate_R.cpp.in
-DGENERATE_CPP_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/build/generate_r_${name}.cpp
-DPROGRAM_MAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_main.cpp
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake
DEPENDS ${CMAKE_SOURCE_DIR}/src/mlpack/bindings/R/generate_R.cpp.in
${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake
${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake
${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/src/${name}.cpp)
add_executable(generate_r_${name}
+2 -1
View File
@@ -15,7 +15,8 @@ Imports: Rcpp (>= 0.12.12)
LinkingTo: Rcpp,
RcppArmadillo (>= @RcppArmadillo_Version@),
BH (>= @BH_Version@),
RcppEnsmallen (>= @RcppEnsmallen_Version@)
RcppEnsmallen (>= @RcppEnsmallen_Version@),
Rcereal (>= @Rcereal_Version@)
Suggests: testthat (>= 2.1.0)
URL: https://www.mlpack.org/doc/mlpack-@PACKAGE_VERSION@/r_documentation.html,
https://github.com/mlpack/mlpack
@@ -41,32 +41,21 @@
// To suppress warnings related to core/util/arma_util.hpp.
#define MLPACK_CORE_UTIL_ARMA_CONFIG_HPP
// Undefine macro due to macro collision.
#undef Realloc
#undef Free
@R_SRC@
#include <mlpack/core.hpp>
// These are all the boost files, we need to compile R bindings for mlpack that
// are not a part of mlpack itself.
#include <boost/serialization/archive_exception.cpp>
#include <boost/serialization/basic_archive.cpp>
#include <boost/serialization/basic_oarchive.cpp>
#include <boost/serialization/basic_oserializer.cpp>
#include <boost/serialization/basic_iarchive.cpp>
#include <boost/serialization/basic_iserializer.cpp>
#include <boost/serialization/basic_pointer_iserializer.cpp>
#include <boost/serialization/basic_pointer_oserializer.cpp>
#include <boost/serialization/basic_text_oprimitive.cpp>
#include <boost/serialization/binary_iarchive.cpp>
#include <boost/serialization/binary_oarchive.cpp>
#include <boost/serialization/extended_type_info_typeid.cpp>
#include <boost/serialization/extended_type_info.cpp>
#include <boost/serialization/basic_serializer_map.cpp>
#include <boost/serialization/void_cast.cpp>
#include <boost/serialization/utf8_codecvt_facet.cpp>
#undef ARMA_EXTRA_MAT_PROTO
#undef ARMA_EXTRA_MAT_MEAT
// Define R Internal macro again after including cereal headers.
#define Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (R_SIZE_T)((n) * sizeof(t)) )
#define Free(p) (R_chk_free( (void *)(p) ), (p) = NULL)
// instead of including RcppArmadillo.h -- which re-includes parts
// of Armadillo already brought in by mlpack, we just include pieces
// needed for sugar wrapping etc
@@ -1,3 +1,3 @@
PKG_CXXFLAGS = -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. $(SHLIB_OPENMP_CXXFLAGS) -ftrack-macro-expansion=0
PKG_CXXFLAGS = -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
CXX_STD = CXX11
@@ -1,154 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// archive_exception.cpp:
// (C) Copyright 2009 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#if (defined _MSC_VER) && (_MSC_VER == 1200)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
#include <exception>
#include <string>
#include <cstring>
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/archive_exception.hpp>
namespace boost {
namespace archive {
BOOST_ARCHIVE_DECL
unsigned int
archive_exception::append(unsigned int l, const char * a){
while(l < (sizeof(m_buffer) - 1)){
char c = *a++;
if('\0' == c)
break;
m_buffer[l++] = c;
}
m_buffer[l] = '\0';
return l;
}
BOOST_ARCHIVE_DECL
archive_exception::archive_exception(
exception_code c,
const char * e1,
const char * e2
) BOOST_NOEXCEPT :
code(c)
{
unsigned int length = 0;
switch(code){
case no_exception:
length = append(length, "uninitialized exception");
break;
case unregistered_class:
length = append(length, "unregistered class");
if(NULL != e1){
length = append(length, " - ");
length = append(length, e1);
}
break;
case invalid_signature:
length = append(length, "invalid signature");
break;
case unsupported_version:
length = append(length, "unsupported version");
break;
case pointer_conflict:
length = append(length, "pointer conflict");
break;
case incompatible_native_format:
length = append(length, "incompatible native format");
if(NULL != e1){
length = append(length, " - ");
length = append(length, e1);
}
break;
case array_size_too_short:
length = append(length, "array size too short");
break;
case input_stream_error:
length = append(length, "input stream error");
if(NULL != e1){
length = append(length, "-");
length = append(length, e1);
}
if(NULL != e2){
length = append(length, "-");
length = append(length, e2);
}
break;
case invalid_class_name:
length = append(length, "class name too long");
break;
case unregistered_cast:
length = append(length, "unregistered void cast ");
length = append(length, (NULL != e1) ? e1 : "?");
length = append(length, "<-");
length = append(length, (NULL != e2) ? e2 : "?");
break;
case unsupported_class_version:
length = append(length, "class version ");
length = append(length, (NULL != e1) ? e1 : "<unknown class>");
break;
case other_exception:
// if get here - it indicates a derived exception
// was sliced by passing by value in catch
length = append(length, "unknown derived exception");
break;
case multiple_code_instantiation:
length = append(length, "code instantiated in more than one module");
if(NULL != e1){
length = append(length, " - ");
length = append(length, e1);
}
break;
case output_stream_error:
length = append(length, "output stream error");
if(NULL != e1){
length = append(length, "-");
length = append(length, e1);
}
if(NULL != e2){
length = append(length, "-");
length = append(length, e2);
}
break;
default:
BOOST_ASSERT(false);
length = append(length, "programming error");
break;
}
}
BOOST_ARCHIVE_DECL
archive_exception::archive_exception(archive_exception const & oth) BOOST_NOEXCEPT :
std::exception(oth),
code(oth.code)
{
std::memcpy(m_buffer,oth.m_buffer,sizeof m_buffer);
}
BOOST_ARCHIVE_DECL
archive_exception::~archive_exception() BOOST_NOEXCEPT_OR_NOTHROW {}
BOOST_ARCHIVE_DECL const char *
archive_exception::what() const BOOST_NOEXCEPT_OR_NOTHROW {
return m_buffer;
}
BOOST_ARCHIVE_DECL
archive_exception::archive_exception() BOOST_NOEXCEPT :
code(no_exception)
{}
} // archive
} // boost
@@ -1,93 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_archive.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
//////////////////////////////////////////////////////////////////////
//
// objects are stored as
//
// class_id* // -1 for a null pointer
// if a new class id
// [
// exported key - class name*
// tracking level - always/never
// class version
// ]
//
// if tracking
// [
// object_id
// ]
//
// [ // if a new object id
// data...
// ]
//
// * required only for pointers - optional for objects
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/basic_archive.hpp>
namespace boost {
namespace archive {
///////////////////////////////////////////////////////////////////////
// constants used in archive signature
//This should never ever change. note that is not an std::string
// string.
BOOST_SYMBOL_VISIBLE const char *
BOOST_ARCHIVE_SIGNATURE(){
return "serialization::archive";
}
// this should change if the capabilities are added to the library
// such that archives can be created which can't be read by previous
// versions of this library
// 1 - initial version
// 2 - made address tracking optional
// 3 - numerous changes - can't guarentee compatibility with previous versions
// 4 - Boost 1.34
// added item_version to properly support versioning for collections
// 5 - Boost 1.36
// changed serialization of collections: adding version even for primitive
// types caused backwards compatibility breaking change in 1.35
// 6 - Boost 1.41 17 Nov 2009
// serializing collection sizes as std::size_t
// 7 Boost 1.42 2 Feb 2010
// error - changed binary version to 16 bits w/o changing library version #
// That is - binary archives are recorded with #6 even though they are
// different from the previous versions. This means that binary archives
// created with versions 1.42 and 1.43 will have to be fixed with a special
// program which fixes the library version # in the header
// Boost 1.43 6 May 2010
// no change
// 8 - Boost 1.44
// separated version_type into library_version_type and class_version_type
// changed version_type to be stored as 8 bits.
// 10- fixed base64 output/input.
// 11- not changes
// 12- improved serialization of collections
// 13- simplified visibility, removed Borland, removed pfto
// 14- improved visibility, refactor map/set
// 15- corrections to optional and collection loading
// 16- eliminated dependency on <codecvt> which is buggy in some libraries
// and now officially deprecated in the standard
// 17- Boost 1.68 August 2018
// 18- addressed undefined behavior in archive constuctors.
// init() called from base wrote archive header before archive
// was fully constructed.
BOOST_SYMBOL_VISIBLE library_version_type
BOOST_ARCHIVE_VERSION(){
return library_version_type(18);
}
} // namespace archive
} // namespace boost
@@ -1,601 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_archive.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
#include <boost/assert.hpp>
#include <set>
#include <list>
#include <vector>
#include <cstddef> // size_t, NULL
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
} // namespace std
#endif
#include <boost/integer_traits.hpp>
#define BOOST_ARCHIVE_SOURCE
// include this to prevent linker errors when the
// same modules are marked export and import.
#define BOOST_SERIALIZATION_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/serialization/state_saver.hpp>
#include <boost/serialization/throw_exception.hpp>
#include <boost/serialization/tracking.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/archive/detail/decl.hpp>
#include <boost/archive/basic_archive.hpp>
#include <boost/archive/detail/basic_iserializer.hpp>
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
#include <boost/archive/detail/basic_iarchive.hpp>
#include <boost/archive/detail/auto_link_archive.hpp>
using namespace boost::serialization;
namespace boost {
namespace archive {
namespace detail {
class basic_iarchive_impl {
friend class basic_iarchive;
library_version_type m_archive_library_version;
unsigned int m_flags;
//////////////////////////////////////////////////////////////////////
// information about each serialized object loaded
// indexed on object_id
struct aobject
{
void * address;
bool loaded_as_pointer;
class_id_type class_id;
aobject(
void *a,
class_id_type class_id_
) :
address(a),
loaded_as_pointer(false),
class_id(class_id_)
{}
aobject() :
address(NULL),
loaded_as_pointer(false),
class_id(-2)
{}
};
typedef std::vector<aobject> object_id_vector_type;
object_id_vector_type object_id_vector;
//////////////////////////////////////////////////////////////////////
// used to implement the reset_object_address operation.
struct moveable_objects {
object_id_type start;
object_id_type end;
object_id_type recent;
bool is_pointer;
moveable_objects() :
start(0),
end(0),
recent(0),
is_pointer(false)
{}
} m_moveable_objects;
void reset_object_address(
const void * new_address,
const void *old_address
);
//////////////////////////////////////////////////////////////////////
// used by load object to look up class id given basic_serializer
struct cobject_type
{
const basic_iserializer * m_bis;
const class_id_type m_class_id;
cobject_type(
std::size_t class_id,
const basic_iserializer & bis
) :
m_bis(& bis),
m_class_id(class_id)
{}
cobject_type(const cobject_type & rhs) :
m_bis(rhs.m_bis),
m_class_id(rhs.m_class_id)
{}
// the following cannot be defined because of the const
// member. This will generate a link error if an attempt
// is made to assign. This should never be necessary
cobject_type & operator=(const cobject_type & rhs);
bool operator<(const cobject_type &rhs) const
{
return *m_bis < *(rhs.m_bis);
}
};
typedef std::set<cobject_type> cobject_info_set_type;
cobject_info_set_type cobject_info_set;
//////////////////////////////////////////////////////////////////////
// information about each serialized class indexed on class_id
class cobject_id
{
public:
cobject_id & operator=(const cobject_id & rhs){
bis_ptr = rhs.bis_ptr;
bpis_ptr = rhs.bpis_ptr;
file_version = rhs.file_version;
tracking_level = rhs.tracking_level;
initialized = rhs.initialized;
return *this;
}
const basic_iserializer * bis_ptr;
const basic_pointer_iserializer * bpis_ptr;
version_type file_version;
tracking_type tracking_level;
bool initialized;
cobject_id(const basic_iserializer & bis_) :
bis_ptr(& bis_),
bpis_ptr(NULL),
file_version(0),
tracking_level(track_never),
initialized(false)
{}
cobject_id(const cobject_id &rhs):
bis_ptr(rhs.bis_ptr),
bpis_ptr(rhs.bpis_ptr),
file_version(rhs.file_version),
tracking_level(rhs.tracking_level),
initialized(rhs.initialized)
{}
};
typedef std::vector<cobject_id> cobject_id_vector_type;
cobject_id_vector_type cobject_id_vector;
//////////////////////////////////////////////////////////////////////
// address of the most recent object serialized as a poiner
// whose data itself is now pending serialization
struct pending {
void * object;
const basic_iserializer * bis;
version_type version;
pending() :
object(NULL),
bis(NULL),
version(0)
{}
} m_pending;
basic_iarchive_impl(unsigned int flags) :
m_archive_library_version(BOOST_ARCHIVE_VERSION()),
m_flags(flags)
{}
void set_library_version(library_version_type archive_library_version){
m_archive_library_version = archive_library_version;
}
bool
track(
basic_iarchive & ar,
void * & t
);
void
load_preamble(
basic_iarchive & ar,
cobject_id & co
);
class_id_type register_type(
const basic_iserializer & bis
);
// redirect through virtual functions to load functions for this archive
template<class T>
void load(basic_iarchive & ar, T & t){
ar.vload(t);
}
//public:
void
next_object_pointer(void * t){
m_pending.object = t;
}
void delete_created_pointers();
class_id_type register_type(
const basic_pointer_iserializer & bpis
);
void load_object(
basic_iarchive & ar,
void * t,
const basic_iserializer & bis
);
const basic_pointer_iserializer * load_pointer(
basic_iarchive & ar,
void * & t,
const basic_pointer_iserializer * bpis,
const basic_pointer_iserializer * (*finder)(
const boost::serialization::extended_type_info & type
)
);
};
inline void
basic_iarchive_impl::reset_object_address(
void const * const new_address,
void const * const old_address
){
if(m_moveable_objects.is_pointer)
return;
// this code handles a couple of situations.
// a) where reset_object_address is applied to an untracked object.
// In such a case the call is really superfluous and its really an
// an error. But we don't have access to the types here so we can't
// know that. However, this code will effectively turn this situation
// into a no-op and every thing will work fine - albeat with a small
// execution time penalty.
// b) where the call to reset_object_address doesn't immediatly follow
// the << operator to which it corresponds. This would be a bad idea
// but the code may work anyway. Naturally, a bad practice on the part
// of the programmer but we can't detect it - as above. So maybe we
// can save a few more people from themselves as above.
object_id_type i = m_moveable_objects.recent;
for(; i < m_moveable_objects.end; ++i){
if(old_address == object_id_vector[i].address)
break;
}
for(; i < m_moveable_objects.end; ++i){
const aobject & ao = object_id_vector[i];
if(ao.loaded_as_pointer)
continue;
void const * const this_address = ao.address;
// calculate displacement from this level
// warning - pointer arithmetic on void * is in herently non-portable
// but expected to work on all platforms in current usage
if(this_address > old_address){
std::size_t member_displacement
= reinterpret_cast<std::size_t>(this_address)
- reinterpret_cast<std::size_t>(old_address);
object_id_vector[i].address = reinterpret_cast<void *>(
reinterpret_cast<std::size_t>(new_address) + member_displacement
);
}
else{
std::size_t member_displacement
= reinterpret_cast<std::size_t>(old_address)
- reinterpret_cast<std::size_t>(this_address);
object_id_vector[i].address = reinterpret_cast<void *>(
reinterpret_cast<std::size_t>(new_address) - member_displacement
);
}
}
}
inline void
basic_iarchive_impl::delete_created_pointers()
{
object_id_vector_type::iterator i;
for(
i = object_id_vector.begin();
i != object_id_vector.end();
++i
){
if(i->loaded_as_pointer){
// borland complains without this minor hack
const int j = i->class_id;
const cobject_id & co = cobject_id_vector[j];
//const cobject_id & co = cobject_id_vector[i->class_id];
// with the appropriate input serializer,
// delete the indicated object
co.bis_ptr->destroy(i->address);
}
}
}
inline class_id_type
basic_iarchive_impl::register_type(
const basic_iserializer & bis
){
class_id_type cid(cobject_info_set.size());
cobject_type co(cid, bis);
std::pair<cobject_info_set_type::const_iterator, bool>
result = cobject_info_set.insert(co);
if(result.second){
cobject_id_vector.push_back(cobject_id(bis));
BOOST_ASSERT(cobject_info_set.size() == cobject_id_vector.size());
}
cid = result.first->m_class_id;
// borland complains without this minor hack
const int tid = cid;
cobject_id & coid = cobject_id_vector[tid];
coid.bpis_ptr = bis.get_bpis_ptr();
return cid;
}
void
basic_iarchive_impl::load_preamble(
basic_iarchive & ar,
cobject_id & co
){
if(! co.initialized){
if(co.bis_ptr->class_info()){
class_id_optional_type cid(class_id_type(0));
load(ar, cid); // to be thrown away
load(ar, co.tracking_level);
load(ar, co.file_version);
}
else{
// override tracking with indicator from class information
co.tracking_level = co.bis_ptr->tracking(m_flags);
co.file_version = version_type(
co.bis_ptr->version()
);
}
co.initialized = true;
}
}
bool
basic_iarchive_impl::track(
basic_iarchive & ar,
void * & t
){
object_id_type oid;
load(ar, oid);
// if its a reference to a old object
if(object_id_type(object_id_vector.size()) > oid){
// we're done
t = object_id_vector[oid].address;
return false;
}
return true;
}
inline void
basic_iarchive_impl::load_object(
basic_iarchive & ar,
void * t,
const basic_iserializer & bis
){
m_moveable_objects.is_pointer = false;
serialization::state_saver<bool> ss_is_pointer(m_moveable_objects.is_pointer);
// if its been serialized through a pointer and the preamble's been done
if(t == m_pending.object && & bis == m_pending.bis){
// read data
(bis.load_object_data)(ar, t, m_pending.version);
return;
}
const class_id_type cid = register_type(bis);
const int i = cid;
cobject_id & co = cobject_id_vector[i];
load_preamble(ar, co);
// save the current move stack position in case we want to truncate it
boost::serialization::state_saver<object_id_type> ss_start(m_moveable_objects.start);
// note: extra line used to evade borland issue
const bool tracking = co.tracking_level;
object_id_type this_id;
m_moveable_objects.start =
this_id = object_id_type(object_id_vector.size());
// if we tracked this object when the archive was saved
if(tracking){
// if it was already read
if(!track(ar, t))
// we're done
return;
// add a new enty into the tracking list
object_id_vector.push_back(aobject(t, cid));
// and add an entry for this object
m_moveable_objects.end = object_id_type(object_id_vector.size());
}
// read data
(bis.load_object_data)(ar, t, co.file_version);
m_moveable_objects.recent = this_id;
}
inline const basic_pointer_iserializer *
basic_iarchive_impl::load_pointer(
basic_iarchive &ar,
void * & t,
const basic_pointer_iserializer * bpis_ptr,
const basic_pointer_iserializer * (*finder)(
const boost::serialization::extended_type_info & type_
)
){
m_moveable_objects.is_pointer = true;
serialization::state_saver<bool> w(m_moveable_objects.is_pointer);
class_id_type cid;
load(ar, cid);
if(NULL_POINTER_TAG == cid){
t = NULL;
return bpis_ptr;
}
// if its a new class type - i.e. never been registered
if(class_id_type(cobject_info_set.size()) <= cid){
// if its either abstract
if(NULL == bpis_ptr
// or polymorphic
|| bpis_ptr->get_basic_serializer().is_polymorphic()){
// is must have been exported
char key[BOOST_SERIALIZATION_MAX_KEY_SIZE];
class_name_type class_name(key);
load(ar, class_name);
// if it has a class name
const serialization::extended_type_info *eti = NULL;
if(0 != key[0])
eti = serialization::extended_type_info::find(key);
if(NULL == eti)
boost::serialization::throw_exception(
archive_exception(archive_exception::unregistered_class)
);
bpis_ptr = (*finder)(*eti);
}
BOOST_ASSERT(NULL != bpis_ptr);
// class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer());
BOOST_VERIFY(register_type(bpis_ptr->get_basic_serializer()) == cid);
int i = cid;
cobject_id_vector[i].bpis_ptr = bpis_ptr;
}
int i = cid;
cobject_id & co = cobject_id_vector[i];
bpis_ptr = co.bpis_ptr;
if (bpis_ptr == NULL) {
boost::serialization::throw_exception(
archive_exception(archive_exception::unregistered_class)
);
}
load_preamble(ar, co);
// extra line to evade borland issue
const bool tracking = co.tracking_level;
// if we're tracking and the pointer has already been read
if(tracking && ! track(ar, t))
// we're done
return bpis_ptr;
// save state
serialization::state_saver<object_id_type> w_start(m_moveable_objects.start);
// allocate space on the heap for the object - to be constructed later
t = bpis_ptr->heap_allocation();
BOOST_ASSERT(NULL != t);
if(! tracking){
bpis_ptr->load_object_ptr(ar, t, co.file_version);
}
else{
serialization::state_saver<void *> x(m_pending.object);
serialization::state_saver<const basic_iserializer *> y(m_pending.bis);
serialization::state_saver<version_type> z(m_pending.version);
m_pending.bis = & bpis_ptr->get_basic_serializer();
m_pending.version = co.file_version;
// predict next object id to be created
const size_t ui = object_id_vector.size();
serialization::state_saver<object_id_type> w_end(m_moveable_objects.end);
// add to list of serialized objects so that we can properly handle
// cyclic strucures
object_id_vector.push_back(aobject(t, cid));
// remember that that the address of these elements could change
// when we make another call so don't use the address
bpis_ptr->load_object_ptr(
ar,
t,
m_pending.version
);
object_id_vector[ui].loaded_as_pointer = true;
}
return bpis_ptr;
}
} // namespace detail
} // namespace archive
} // namespace boost
//////////////////////////////////////////////////////////////////////
// implementation of basic_iarchive functions
namespace boost {
namespace archive {
namespace detail {
BOOST_ARCHIVE_DECL void
basic_iarchive::next_object_pointer(void *t){
pimpl->next_object_pointer(t);
}
BOOST_ARCHIVE_DECL
basic_iarchive::basic_iarchive(unsigned int flags) :
pimpl(new basic_iarchive_impl(flags))
{}
BOOST_ARCHIVE_DECL
basic_iarchive::~basic_iarchive()
{}
BOOST_ARCHIVE_DECL void
basic_iarchive::set_library_version(library_version_type archive_library_version){
pimpl->set_library_version(archive_library_version);
}
BOOST_ARCHIVE_DECL void
basic_iarchive::reset_object_address(
const void * new_address,
const void * old_address
){
pimpl->reset_object_address(new_address, old_address);
}
BOOST_ARCHIVE_DECL void
basic_iarchive::load_object(
void *t,
const basic_iserializer & bis
){
pimpl->load_object(*this, t, bis);
}
// load a pointer object
BOOST_ARCHIVE_DECL const basic_pointer_iserializer *
basic_iarchive::load_pointer(
void * &t,
const basic_pointer_iserializer * bpis_ptr,
const basic_pointer_iserializer * (*finder)(
const boost::serialization::extended_type_info & type_
)
){
return pimpl->load_pointer(*this, t, bpis_ptr, finder);
}
BOOST_ARCHIVE_DECL void
basic_iarchive::register_basic_serializer(const basic_iserializer & bis){
pimpl->register_type(bis);
}
BOOST_ARCHIVE_DECL void
basic_iarchive::delete_created_pointers()
{
pimpl->delete_created_pointers();
}
BOOST_ARCHIVE_DECL boost::archive::library_version_type
basic_iarchive::get_library_version() const{
return pimpl->m_archive_library_version;
}
BOOST_ARCHIVE_DECL unsigned int
basic_iarchive::get_flags() const{
return pimpl->m_flags;
}
} // namespace detail
} // namespace archive
} // namespace boost
@@ -1,34 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_iserializer.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <cstddef> // NULL
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/detail/basic_iserializer.hpp>
namespace boost {
namespace archive {
namespace detail {
BOOST_ARCHIVE_DECL
basic_iserializer::basic_iserializer(
const boost::serialization::extended_type_info & eti
) :
basic_serializer(eti),
m_bpis(NULL)
{}
BOOST_ARCHIVE_DECL
basic_iserializer::~basic_iserializer(){}
} // namespace detail
} // namespace archive
} // namespace boost
@@ -1,470 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_oarchive.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
#include <boost/assert.hpp>
#include <set>
#include <cstddef> // NULL
#include <boost/limits.hpp>
// including this here to work around an ICC in intel 7.0
// normally this would be part of basic_oarchive.hpp below.
#define BOOST_ARCHIVE_SOURCE
// include this to prevent linker errors when the
// same modules are marked export and import.
#define BOOST_SERIALIZATION_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/serialization/state_saver.hpp>
#include <boost/serialization/throw_exception.hpp>
#include <boost/serialization/extended_type_info.hpp>
#include <boost/archive/detail/decl.hpp>
#include <boost/archive/basic_archive.hpp>
#include <boost/archive/detail/basic_oserializer.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
#include <boost/archive/detail/basic_oarchive.hpp>
#include <boost/archive/archive_exception.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4251 4231 4660 4275)
#endif
using namespace boost::serialization;
namespace boost {
namespace archive {
namespace detail {
class basic_oarchive_impl {
friend class basic_oarchive;
unsigned int m_flags;
//////////////////////////////////////////////////////////////////////
// information about each serialized object saved
// keyed on address, class_id
struct aobject
{
const void * address;
class_id_type class_id;
object_id_type object_id;
bool operator<(const aobject &rhs) const
{
BOOST_ASSERT(NULL != address);
BOOST_ASSERT(NULL != rhs.address);
if( address < rhs.address )
return true;
if( address > rhs.address )
return false;
return class_id < rhs.class_id;
}
aobject & operator=(const aobject & rhs)
{
address = rhs.address;
class_id = rhs.class_id;
object_id = rhs.object_id;
return *this;
}
aobject(
const void *a,
class_id_type class_id_,
object_id_type object_id_
) :
address(a),
class_id(class_id_),
object_id(object_id_)
{}
aobject() : address(NULL){}
};
// keyed on class_id, address
typedef std::set<aobject> object_set_type;
object_set_type object_set;
//////////////////////////////////////////////////////////////////////
// information about each serialized class saved
// keyed on type_info
struct cobject_type
{
const basic_oserializer * m_bos_ptr;
const class_id_type m_class_id;
bool m_initialized;
cobject_type(
std::size_t class_id,
const basic_oserializer & bos
) :
m_bos_ptr(& bos),
m_class_id(class_id),
m_initialized(false)
{}
cobject_type(const basic_oserializer & bos) :
m_bos_ptr(& bos),
m_initialized(false)
{}
cobject_type(
const cobject_type & rhs
) :
m_bos_ptr(rhs.m_bos_ptr),
m_class_id(rhs.m_class_id),
m_initialized(rhs.m_initialized)
{}
// the following cannot be defined because of the const
// member. This will generate a link error if an attempt
// is made to assign. This should never be necessary
// use this only for lookup argument
cobject_type & operator=(const cobject_type &rhs);
bool operator<(const cobject_type &rhs) const {
return *m_bos_ptr < *(rhs.m_bos_ptr);
}
};
// keyed on type_info
typedef std::set<cobject_type> cobject_info_set_type;
cobject_info_set_type cobject_info_set;
// list of objects initially stored as pointers - used to detect errors
// keyed on object id
std::set<object_id_type> stored_pointers;
// address of the most recent object serialized as a poiner
// whose data itself is now pending serialization
const void * pending_object;
const basic_oserializer * pending_bos;
basic_oarchive_impl(unsigned int flags) :
m_flags(flags),
pending_object(NULL),
pending_bos(NULL)
{}
const cobject_type &
find(const basic_oserializer & bos);
const basic_oserializer *
find(const serialization::extended_type_info &ti) const;
//public:
const cobject_type &
register_type(const basic_oserializer & bos);
void save_object(
basic_oarchive & ar,
const void *t,
const basic_oserializer & bos
);
void save_pointer(
basic_oarchive & ar,
const void * t,
const basic_pointer_oserializer * bpos
);
};
//////////////////////////////////////////////////////////////////////
// basic_oarchive implementation functions
// given a type_info - find its bos
// return NULL if not found
inline const basic_oserializer *
basic_oarchive_impl::find(const serialization::extended_type_info & ti) const {
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#endif
class bosarg :
public basic_oserializer
{
bool class_info() const {
BOOST_ASSERT(false);
return false;
}
// returns true if objects should be tracked
bool tracking(const unsigned int) const {
BOOST_ASSERT(false);
return false;
}
// returns class version
version_type version() const {
BOOST_ASSERT(false);
return version_type(0);
}
// returns true if this class is polymorphic
bool is_polymorphic() const{
BOOST_ASSERT(false);
return false;
}
void save_object_data(
basic_oarchive & /*ar*/, const void * /*x*/
) const {
BOOST_ASSERT(false);
}
public:
bosarg(const serialization::extended_type_info & eti) :
boost::archive::detail::basic_oserializer(eti)
{}
};
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
bosarg bos(ti);
cobject_info_set_type::const_iterator cit
= cobject_info_set.find(cobject_type(bos));
// it should already have been "registered" - see below
if(cit == cobject_info_set.end()){
// if an entry is not found in the table it is because a pointer
// of a derived class has been serialized through its base class
// but the derived class hasn't been "registered"
return NULL;
}
// return pointer to the real class
return cit->m_bos_ptr;
}
inline const basic_oarchive_impl::cobject_type &
basic_oarchive_impl::find(const basic_oserializer & bos)
{
std::pair<cobject_info_set_type::iterator, bool> cresult =
cobject_info_set.insert(cobject_type(cobject_info_set.size(), bos));
return *(cresult.first);
}
inline const basic_oarchive_impl::cobject_type &
basic_oarchive_impl::register_type(
const basic_oserializer & bos
){
cobject_type co(cobject_info_set.size(), bos);
std::pair<cobject_info_set_type::const_iterator, bool>
result = cobject_info_set.insert(co);
return *(result.first);
}
inline void
basic_oarchive_impl::save_object(
basic_oarchive & ar,
const void *t,
const basic_oserializer & bos
){
// if its been serialized through a pointer and the preamble's been done
if(t == pending_object && pending_bos == & bos){
// just save the object data
ar.end_preamble();
(bos.save_object_data)(ar, t);
return;
}
// get class information for this object
const cobject_type & co = register_type(bos);
if(bos.class_info()){
if( ! co.m_initialized){
ar.vsave(class_id_optional_type(co.m_class_id));
ar.vsave(tracking_type(bos.tracking(m_flags)));
ar.vsave(version_type(bos.version()));
(const_cast<cobject_type &>(co)).m_initialized = true;
}
}
// we're not tracking this type of object
if(! bos.tracking(m_flags)){
// just windup the preamble - no object id to write
ar.end_preamble();
// and save the data
(bos.save_object_data)(ar, t);
return;
}
// look for an existing object id
object_id_type oid(object_set.size());
// lookup to see if this object has already been written to the archive
basic_oarchive_impl::aobject ao(t, co.m_class_id, oid);
std::pair<basic_oarchive_impl::object_set_type::const_iterator, bool>
aresult = object_set.insert(ao);
oid = aresult.first->object_id;
// if its a new object
if(aresult.second){
// write out the object id
ar.vsave(oid);
ar.end_preamble();
// and data
(bos.save_object_data)(ar, t);
return;
}
// check that it wasn't originally stored through a pointer
if(stored_pointers.end() != stored_pointers.find(oid)){
// this has to be a user error. loading such an archive
// would create duplicate objects
boost::serialization::throw_exception(
archive_exception(archive_exception::pointer_conflict)
);
}
// just save the object id
ar.vsave(object_reference_type(oid));
ar.end_preamble();
return;
}
// colle
inline void
basic_oarchive_impl::save_pointer(
basic_oarchive & ar,
const void * t,
const basic_pointer_oserializer * bpos_ptr
){
const basic_oserializer & bos = bpos_ptr->get_basic_serializer();
std::size_t original_count = cobject_info_set.size();
const cobject_type & co = register_type(bos);
if(! co.m_initialized){
ar.vsave(co.m_class_id);
// if its a previously unregistered class
if((cobject_info_set.size() > original_count)){
if(bos.is_polymorphic()){
const serialization::extended_type_info *eti = & bos.get_eti();
const char * key = NULL;
if(NULL != eti)
key = eti->get_key();
if(NULL != key){
// the following is required by IBM C++ compiler which
// makes a copy when passing a non-const to a const. This
// is permitted by the standard but rarely seen in practice
const class_name_type cn(key);
if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1))
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::
invalid_class_name)
);
// write out the external class identifier
ar.vsave(cn);
}
else
// without an external class name
// we won't be able to de-serialize it so bail now
boost::serialization::throw_exception(
archive_exception(archive_exception::unregistered_class)
);
}
}
if(bos.class_info()){
ar.vsave(tracking_type(bos.tracking(m_flags)));
ar.vsave(version_type(bos.version()));
}
(const_cast<cobject_type &>(co)).m_initialized = true;
}
else{
ar.vsave(class_id_reference_type(co.m_class_id));
}
// if we're not tracking
if(! bos.tracking(m_flags)){
// just save the data itself
ar.end_preamble();
serialization::state_saver<const void *> x(pending_object);
serialization::state_saver<const basic_oserializer *> y(pending_bos);
pending_object = t;
pending_bos = & bpos_ptr->get_basic_serializer();
bpos_ptr->save_object_ptr(ar, t);
return;
}
object_id_type oid(object_set.size());
// lookup to see if this object has already been written to the archive
basic_oarchive_impl::aobject ao(t, co.m_class_id, oid);
std::pair<basic_oarchive_impl::object_set_type::const_iterator, bool>
aresult = object_set.insert(ao);
oid = aresult.first->object_id;
// if the saved object already exists
if(! aresult.second){
// append the object id to he preamble
ar.vsave(object_reference_type(oid));
// and windup.
ar.end_preamble();
return;
}
// append id of this object to preamble
ar.vsave(oid);
ar.end_preamble();
// and save the object itself
serialization::state_saver<const void *> x(pending_object);
serialization::state_saver<const basic_oserializer *> y(pending_bos);
pending_object = t;
pending_bos = & bpos_ptr->get_basic_serializer();
bpos_ptr->save_object_ptr(ar, t);
// add to the set of object initially stored through pointers
stored_pointers.insert(oid);
}
} // namespace detail
} // namespace archive
} // namespace boost
//////////////////////////////////////////////////////////////////////
// implementation of basic_oarchive functions
namespace boost {
namespace archive {
namespace detail {
BOOST_ARCHIVE_DECL
basic_oarchive::basic_oarchive(unsigned int flags)
: pimpl(new basic_oarchive_impl(flags))
{}
BOOST_ARCHIVE_DECL
basic_oarchive::~basic_oarchive()
{}
BOOST_ARCHIVE_DECL void
basic_oarchive::save_object(
const void *x,
const basic_oserializer & bos
){
pimpl->save_object(*this, x, bos);
}
BOOST_ARCHIVE_DECL void
basic_oarchive::save_pointer(
const void * t,
const basic_pointer_oserializer * bpos_ptr
){
pimpl->save_pointer(*this, t, bpos_ptr);
}
BOOST_ARCHIVE_DECL void
basic_oarchive::register_basic_serializer(const basic_oserializer & bos){
pimpl->register_type(bos);
}
BOOST_ARCHIVE_DECL library_version_type
basic_oarchive::get_library_version() const{
return BOOST_ARCHIVE_VERSION();
}
BOOST_ARCHIVE_DECL unsigned int
basic_oarchive::get_flags() const{
return pimpl->m_flags;
}
BOOST_ARCHIVE_DECL void
basic_oarchive::end_preamble(){
}
BOOST_ARCHIVE_DECL helper_collection &
basic_oarchive::get_helper_collection(){
return *this;
}
} // namespace detail
} // namespace archive
} // namespace boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
@@ -1,34 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_oserializer.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <cstddef> // NULL
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/detail/basic_oserializer.hpp>
namespace boost {
namespace archive {
namespace detail {
BOOST_ARCHIVE_DECL
basic_oserializer::basic_oserializer(
const boost::serialization::extended_type_info & eti
) :
basic_serializer(eti),
m_bpos(NULL)
{}
BOOST_ARCHIVE_DECL
basic_oserializer::~basic_oserializer(){}
} // namespace detail
} // namespace archive
} // namespace boost
@@ -1,31 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_pointer_iserializer.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
namespace boost {
namespace archive {
namespace detail {
BOOST_ARCHIVE_DECL
basic_pointer_iserializer::basic_pointer_iserializer(
const boost::serialization::extended_type_info & eti
) :
basic_serializer(eti)
{}
BOOST_ARCHIVE_DECL
basic_pointer_iserializer::~basic_pointer_iserializer() {}
} // namespace detail
} // namespace archive
} // namespace boost
@@ -1,31 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_pointer_oserializer.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
namespace boost {
namespace archive {
namespace detail {
BOOST_ARCHIVE_DECL
basic_pointer_oserializer::basic_pointer_oserializer(
const boost::serialization::extended_type_info & eti
) :
basic_serializer(eti)
{}
BOOST_ARCHIVE_DECL
basic_pointer_oserializer::~basic_pointer_oserializer() {}
} // namespace detail
} // namespace archive
} // namespace boost
@@ -1,112 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// serializer_map.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#if (defined _MSC_VER) && (_MSC_VER == 1200)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
#include <set>
#include <utility>
#define BOOST_ARCHIVE_SOURCE
// include this to prevent linker errors when the
// same modules are marked export and import.
#define BOOST_SERIALIZATION_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/serialization/throw_exception.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/archive/detail/basic_serializer.hpp>
#include <boost/archive/detail/basic_serializer_map.hpp>
namespace boost {
namespace serialization {
class extended_type_info;
}
namespace archive {
namespace detail {
bool
basic_serializer_map::type_info_pointer_compare::operator()(
const basic_serializer * lhs, const basic_serializer * rhs
) const {
return *lhs < *rhs;
}
BOOST_ARCHIVE_DECL bool
basic_serializer_map::insert(const basic_serializer * bs){
// attempt to insert serializer into it's map
// the following is commented out - rather than being just
// deleted as a reminder not to try this.
// const std::pair<map_type::iterator, bool> result =
m_map.insert(bs);
// At first it seemed like a good idea. It enforced the
// idea that a type be exported from at most one code module
// (DLL or mainline). This would enforce a "one definition rule"
// across code modules. This seems a good idea to me.
// But it seems that it's just too hard for many users to implement.
// Ideally, I would like to make this exception a warning -
// but there isn't anyway to do that.
// if this fails, it's because it's been instantiated
// in multiple modules - DLLS - a recipe for problems.
// So trap this here
// if(!result.second){
// boost::serialization::throw_exception(
// archive_exception(
// archive_exception::multiple_code_instantiation,
// bs->get_debug_info()
// )
// );
// }
return true;
}
BOOST_ARCHIVE_DECL void
basic_serializer_map::erase(const basic_serializer * bs){
map_type::iterator it = m_map.begin();
map_type::iterator it_end = m_map.end();
while(it != it_end){
// note item 9 from Effective STL !!! it++
if(*it == bs)
m_map.erase(it++);
else
it++;
}
// note: we can't do this since some of the eti records
// we're pointing to might be expired and the comparison
// won't work. Leave this as a reminder not to "optimize" this.
//it = m_map.find(bs);
//assert(it != m_map.end());
//if(*it == bs)
// m_map.erase(it);
}
BOOST_ARCHIVE_DECL const basic_serializer *
basic_serializer_map::find(
const boost::serialization::extended_type_info & eti
) const {
const basic_serializer_arg bs(eti);
map_type::const_iterator it;
it = m_map.find(& bs);
if(it == m_map.end()){
BOOST_ASSERT(false);
return 0;
}
return *it;
}
} // namespace detail
} // namespace archive
} // namespace boost
@@ -1,29 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_text_oprimitive.cpp:
// (C) Copyright 2004 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#if (defined _MSC_VER) && (_MSC_VER == 1200)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
#include <ostream>
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/detail/auto_link_archive.hpp>
#include <boost/archive/impl/basic_text_oprimitive.ipp>
namespace boost {
namespace archive {
// explicitly instantiate for this type of text stream
template class basic_text_oprimitive<std::ostream> ;
} // namespace archive
} // namespace boost
@@ -1,40 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// binary_iarchive.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <istream>
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/detail/archive_serializer_map.hpp>
#include <boost/archive/impl/archive_serializer_map.ipp>
#include <boost/archive/impl/basic_binary_iprimitive.ipp>
#include <boost/archive/impl/basic_binary_iarchive.ipp>
namespace boost {
namespace archive {
// explicitly instantiate for this type of stream
template class detail::archive_serializer_map<binary_iarchive>;
template class basic_binary_iprimitive<
binary_iarchive,
std::istream::char_type,
std::istream::traits_type
>;
template class basic_binary_iarchive<binary_iarchive> ;
template class binary_iarchive_impl<
binary_iarchive,
std::istream::char_type,
std::istream::traits_type
>;
} // namespace archive
} // namespace boost
@@ -1,38 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// binary_oarchive.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <ostream>
#define BOOST_ARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/detail/archive_serializer_map.hpp>
#include <boost/archive/impl/basic_binary_oprimitive.ipp>
#include <boost/archive/impl/basic_binary_oarchive.ipp>
namespace boost {
namespace archive {
template class detail::archive_serializer_map<binary_oarchive>;
template class basic_binary_oprimitive<
binary_oarchive,
std::ostream::char_type,
std::ostream::traits_type
>;
template class basic_binary_oarchive<binary_oarchive> ;
template class binary_oarchive_impl<
binary_oarchive,
std::ostream::char_type,
std::ostream::traits_type
>;
} // namespace archive
} // namespace boost
@@ -1,196 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// extended_type_info.cpp: implementation for portable version of type_info
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#if (defined _MSC_VER) && (_MSC_VER == 1200)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
#include <algorithm>
#include <set>
#include <utility>
#include <boost/assert.hpp>
#include <cstddef> // NULL
#include <cstring>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{ using ::strcmp; }
#endif
#include <boost/config.hpp> // msvc needs this to suppress warning
#include <boost/core/no_exceptions_support.hpp>
// it marks our code with proper attributes as being exported when
// we're compiling it while marking it import when just the headers
// is being included.
#define BOOST_SERIALIZATION_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/serialization/singleton.hpp>
#include <boost/serialization/force_include.hpp>
#include <boost/serialization/extended_type_info.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#endif
namespace boost {
namespace serialization {
namespace detail {
struct key_compare
{
bool
operator()(
const extended_type_info * lhs,
const extended_type_info * rhs
) const {
// performance shortcut
if(lhs == rhs)
return false;
const char * l = lhs->get_key();
BOOST_ASSERT(NULL != l);
const char * r = rhs->get_key();
BOOST_ASSERT(NULL != r);
// performance shortcut
// shortcut to exploit string pooling
if(l == r)
return false;
// for exported types, use the string key so that
// multiple instances in different translation units
// can be matched up
return std::strcmp(l, r) < 0;
}
};
typedef std::multiset<const extended_type_info *, key_compare> ktmap;
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#endif
class extended_type_info_arg : public extended_type_info
{
virtual bool
is_less_than(const extended_type_info & /*rhs*/) const {
BOOST_ASSERT(false);
return false;
};
virtual bool
is_equal(const extended_type_info & /*rhs*/) const {
BOOST_ASSERT(false);
return false;
};
virtual const char * get_debug_info() const {
return get_key();
}
virtual void * construct(unsigned int /*count*/, ...) const{
BOOST_ASSERT(false);
return NULL;
}
virtual void destroy(void const * const /*p*/) const {
BOOST_ASSERT(false);
}
public:
extended_type_info_arg(const char * key) :
extended_type_info(0, key)
{}
~extended_type_info_arg(){
}
};
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
} // namespace detail
BOOST_SERIALIZATION_DECL void
extended_type_info::key_register() const{
if(NULL == get_key())
return;
singleton<detail::ktmap>::get_mutable_instance().insert(this);
}
BOOST_SERIALIZATION_DECL void
extended_type_info::key_unregister() const{
if(NULL == get_key())
return;
// note: it's been discovered that at least one platform is not guaranteed
// to destroy singletons reverse order of construction. So we can't
// use a runtime assert here. Leave this in a reminder not to do this!
// BOOST_ASSERT(! singleton<detail::ktmap>::is_destroyed());
if(! singleton<detail::ktmap>::is_destroyed()){
detail::ktmap & x = singleton<detail::ktmap>::get_mutable_instance();
detail::ktmap::iterator start = x.lower_bound(this);
detail::ktmap::iterator end = x.upper_bound(this);
// remove entry in map which corresponds to this type
for(;start != end; ++start){
if(this == *start){
x.erase(start);
break;
}
}
}
}
BOOST_SERIALIZATION_DECL const extended_type_info *
extended_type_info::find(const char *key) {
BOOST_ASSERT(NULL != key);
const detail::ktmap & k = singleton<detail::ktmap>::get_const_instance();
const detail::extended_type_info_arg eti_key(key);
const detail::ktmap::const_iterator it = k.find(& eti_key);
if(k.end() == it)
return NULL;
return *(it);
}
BOOST_SERIALIZATION_DECL
extended_type_info::extended_type_info(
const unsigned int type_info_key,
const char * key
) :
m_type_info_key(type_info_key),
m_key(key)
{
}
BOOST_SERIALIZATION_DECL
extended_type_info::~extended_type_info(){
}
BOOST_SERIALIZATION_DECL bool
extended_type_info::operator<(const extended_type_info &rhs) const {
// short cut for a common cases
if(this == & rhs)
return false;
if(m_type_info_key == rhs.m_type_info_key){
return is_less_than(rhs);
}
if(m_type_info_key < rhs.m_type_info_key)
return true;
return false;
}
BOOST_SERIALIZATION_DECL bool
extended_type_info::operator==(const extended_type_info &rhs) const {
// short cut for a common cases
if(this == & rhs)
return true;
if(m_type_info_key != rhs.m_type_info_key){
return false;
}
return is_equal(rhs);
}
} // namespace serialization
} // namespace boost
@@ -1,167 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// extended_type_info_typeid.cpp: specific implementation of type info
// that is based on typeid
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <algorithm>
#include <set>
#include <boost/assert.hpp>
#include <typeinfo>
#include <cstddef> // NULL
#include <boost/core/no_exceptions_support.hpp>
// it marks our code with proper attributes as being exported when
// we're compiling it while marking it import when just the headers
// is being included.
#define BOOST_SERIALIZATION_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/serialization/singleton.hpp>
#include <boost/serialization/extended_type_info_typeid.hpp>
namespace boost {
namespace serialization {
namespace typeid_system {
#define EXTENDED_TYPE_INFO_TYPE_KEY 1
struct type_compare
{
bool
operator()(
const extended_type_info_typeid_0 * lhs,
const extended_type_info_typeid_0 * rhs
) const {
return lhs->is_less_than(*rhs);
}
};
typedef std::multiset<
const extended_type_info_typeid_0 *,
type_compare
> tkmap;
BOOST_SERIALIZATION_DECL bool
extended_type_info_typeid_0::is_less_than(
const boost::serialization::extended_type_info & rhs
) const {
// shortcut for common case
if(this == & rhs)
return false;
return 0 != m_ti->before(
*(static_cast<const extended_type_info_typeid_0 &>(rhs).m_ti)
);
}
BOOST_SERIALIZATION_DECL bool
extended_type_info_typeid_0::is_equal(
const boost::serialization::extended_type_info & rhs
) const {
return
// note: std::type_info == operator returns an int !!!
// the following permits conversion to bool without a warning.
! (
* m_ti
!= *(static_cast<const extended_type_info_typeid_0 &>(rhs).m_ti)
)
;
}
BOOST_SERIALIZATION_DECL
extended_type_info_typeid_0::extended_type_info_typeid_0(
const char * key
) :
extended_type_info(EXTENDED_TYPE_INFO_TYPE_KEY, key),
m_ti(NULL)
{}
BOOST_SERIALIZATION_DECL
extended_type_info_typeid_0::~extended_type_info_typeid_0()
{}
BOOST_SERIALIZATION_DECL void
extended_type_info_typeid_0::type_register(const std::type_info & ti){
m_ti = & ti;
singleton<tkmap>::get_mutable_instance().insert(this);
}
BOOST_SERIALIZATION_DECL void
extended_type_info_typeid_0::type_unregister()
{
if(NULL != m_ti){
// note: previously this conditional was a runtime assertion with
// BOOST_ASSERT. We've changed it because we've discovered that at
// least one platform is not guaranteed to destroy singletons in
// reverse order of distruction.
// BOOST_ASSERT(! singleton<tkmap>::is_destroyed());
if(! singleton<tkmap>::is_destroyed()){
tkmap & x = singleton<tkmap>::get_mutable_instance();
// remove all entries in map which corresponds to this type
// make sure that we don't use any invalidated iterators
for(;;){
const tkmap::iterator & it = x.find(this);
if(it == x.end())
break;
x.erase(it);
};
}
}
m_ti = NULL;
}
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#endif
// this derivation is used for creating search arguments
class extended_type_info_typeid_arg :
public extended_type_info_typeid_0
{
virtual void * construct(unsigned int /*count*/, ...) const{
BOOST_ASSERT(false);
return NULL;
}
virtual void destroy(void const * const /*p*/) const {
BOOST_ASSERT(false);
}
public:
extended_type_info_typeid_arg(const std::type_info & ti) :
extended_type_info_typeid_0(NULL)
{
// note absense of self register and key as this is used only as
// search argument given a type_info reference and is not to
// be added to the map.
m_ti = & ti;
}
~extended_type_info_typeid_arg(){
m_ti = NULL;
}
};
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
BOOST_SERIALIZATION_DECL const extended_type_info *
extended_type_info_typeid_0::get_extended_type_info(
const std::type_info & ti
) const {
typeid_system::extended_type_info_typeid_arg etia(ti);
const tkmap & t = singleton<tkmap>::get_const_instance();
const tkmap::const_iterator it = t.find(& etia);
if(t.end() == it)
return NULL;
return *(it);
}
} // namespace detail
} // namespace serialization
} // namespace boost
@@ -1,22 +0,0 @@
// Copyright Vladimir Prus 2004.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/config.hpp>
#ifdef BOOST_NO_STD_WSTREAMBUF
#error "wide char i/o not supported on this platform"
#endif
// include boost implementation of utf8 codecvt facet
# define BOOST_ARCHIVE_SOURCE
#include <boost/archive/detail/decl.hpp>
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace archive { namespace detail {
#define BOOST_UTF8_DECL BOOST_ARCHIVE_DECL
#define BOOST_UTF8_END_NAMESPACE }}}
#include <boost/detail/utf8_codecvt_facet.ipp>
#undef BOOST_UTF8_END_NAMESPACE
#undef BOOST_UTF8_DECL
#undef BOOST_UTF8_BEGIN_NAMESPACE
@@ -1,178 +0,0 @@
#ifndef BOOST_SERIALIZATION_VARIANT_HPP
#define BOOST_SERIALIZATION_VARIANT_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// variant.hpp - non-intrusive serialization of variant types
//
// copyright (c) 2005
// troy d. straszheim <troy@resophonic.com>
// http://www.resophonic.com
//
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org for updates, documentation, and revision history.
//
// thanks to Robert Ramey, Peter Dimov, and Richard Crossley.
//
#include <boost/mpl/front.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/serialization/throw_exception.hpp>
#include <boost/variant.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
namespace boost {
namespace serialization {
template<class Archive>
struct variant_save_visitor :
boost::static_visitor<>
{
variant_save_visitor(Archive& ar) :
m_ar(ar)
{}
template<class T>
void operator()(T const & value) const
{
m_ar << BOOST_SERIALIZATION_NVP(value);
}
private:
Archive & m_ar;
};
template<class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
void save(
Archive & ar,
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const & v,
unsigned int /*version*/
){
int which = v.which();
ar << BOOST_SERIALIZATION_NVP(which);
variant_save_visitor<Archive> visitor(ar);
v.apply_visitor(visitor);
}
template<class S>
struct variant_impl {
struct load_null {
template<class Archive, class V>
static void invoke(
Archive & /*ar*/,
int /*which*/,
V & /*v*/,
const unsigned int /*version*/
){}
};
struct load_impl {
template<class Archive, class V>
static void invoke(
Archive & ar,
int which,
V & v,
const unsigned int version
){
if(which == 0){
// note: A non-intrusive implementation (such as this one)
// necessary has to copy the value. This wouldn't be necessary
// with an implementation that de-serialized to the address of the
// aligned storage included in the variant.
typedef typename mpl::front<S>::type head_type;
head_type value;
ar >> BOOST_SERIALIZATION_NVP(value);
v = value;
head_type * new_address = & boost::get<head_type>(v);
ar.reset_object_address(new_address, & value);
return;
}
typedef typename mpl::pop_front<S>::type type;
variant_impl<type>::load(ar, which - 1, v, version);
}
};
template<class Archive, class V>
static void load(
Archive & ar,
int which,
V & v,
const unsigned int version
){
typedef typename mpl::eval_if<mpl::empty<S>,
mpl::identity<load_null>,
mpl::identity<load_impl>
>::type typex;
typex::invoke(ar, which, v, version);
}
};
template<class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
void load(
Archive & ar,
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& v,
const unsigned int version
){
int which;
typedef typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;
ar >> BOOST_SERIALIZATION_NVP(which);
if(which >= mpl::size<types>::value)
// this might happen if a type was removed from the list of variant types
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::unsupported_version
)
);
variant_impl<types>::load(ar, which, v, version);
}
template<class Archive,BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
inline void serialize(
Archive & ar,
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & v,
const unsigned int file_version
){
split_free(ar,v,file_version);
}
} // namespace serialization
} // namespace boost
//template<typename T0_, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename T)>
#include <boost/serialization/tracking.hpp>
namespace boost {
namespace serialization {
template<BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
struct tracking_level<
variant<BOOST_VARIANT_ENUM_PARAMS(T)>
>{
typedef mpl::integral_c_tag tag;
typedef mpl::int_< ::boost::serialization::track_always> type;
BOOST_STATIC_CONSTANT(int, value = type::value);
};
} // namespace serialization
} // namespace boost
#endif //BOOST_SERIALIZATION_VARIANT_HPP
@@ -1,382 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// void_cast.cpp: implementation of run-time casting of void pointers
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// <gennadiy.rozental@tfn.com>
// See http://www.boost.org for updates, documentation, and revision history.
#if (defined _MSC_VER) && (_MSC_VER == 1200)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
// STL
#include <set>
#include <functional>
#include <algorithm>
#include <cstddef> // NULL
#ifdef BOOST_SERIALIZATION_LOG
#include <iostream>
#endif
// BOOST
#include <boost/config.hpp>
#include <boost/assert.hpp>
#define BOOST_SERIALIZATION_SOURCE
#include <boost/serialization/config.hpp>
// it marks our code with proper attributes as being exported when
// we're compiling it while marking it import when just the headers
// is being included.
#include <boost/serialization/singleton.hpp>
#include <boost/serialization/extended_type_info.hpp>
#include <boost/serialization/void_cast.hpp>
namespace boost {
namespace serialization {
namespace void_cast_detail {
// note that void_casters are keyed on value of
// member extended type info records - NOT their
// addresses. This is necessary in order for the
// void cast operations to work across dll and exe
// module boundries.
bool void_caster::operator<(const void_caster & rhs) const {
// include short cut to save time and eliminate
// problems when when base class aren't virtual
if(m_derived != rhs.m_derived){
if(*m_derived < *rhs.m_derived)
return true;
if(*rhs.m_derived < *m_derived)
return false;
}
// m_derived == rhs.m_derived
if(m_base != rhs.m_base)
return *m_base < *rhs.m_base;
else
return false;
}
struct void_caster_compare {
bool operator()(const void_caster * lhs, const void_caster * rhs) const {
return *lhs < *rhs;
}
};
typedef std::set<const void_caster *, void_caster_compare> set_type;
typedef boost::serialization::singleton<set_type> void_caster_registry;
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#endif
// implementation of shortcut void caster
class void_caster_shortcut : public void_caster
{
bool m_includes_virtual_base;
void const *
vbc_upcast(
void const * const t
) const;
void const *
vbc_downcast(
void const * const t
) const;
virtual void const *
upcast(void const * const t) const{
if(m_includes_virtual_base)
return vbc_upcast(t);
return static_cast<const char *> ( t ) - m_difference;
}
virtual void const *
downcast(void const * const t) const{
if(m_includes_virtual_base)
return vbc_downcast(t);
return static_cast<const char *> ( t ) + m_difference;
}
virtual bool is_shortcut() const {
return true;
}
virtual bool has_virtual_base() const {
return m_includes_virtual_base;
}
public:
void_caster_shortcut(
extended_type_info const * derived,
extended_type_info const * base,
std::ptrdiff_t difference,
bool includes_virtual_base,
void_caster const * const parent
) :
void_caster(derived, base, difference, parent),
m_includes_virtual_base(includes_virtual_base)
{
recursive_register(includes_virtual_base);
}
virtual ~void_caster_shortcut(){
recursive_unregister();
}
};
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
void const *
void_caster_shortcut::vbc_downcast(
void const * const t
) const {
// try to find a chain that gives us what we want
const void_cast_detail::set_type & s
= void_cast_detail::void_caster_registry::get_const_instance();
void_cast_detail::set_type::const_iterator it;
for(it = s.begin(); it != s.end(); ++it){
// if the current candidate casts to the desired target type
if ((*it)->m_derived == m_derived){
// and if it's not us
if ((*it)->m_base != m_base){
// try to cast from the candidate base to our base
const void * t_new;
t_new = void_downcast(*(*it)->m_base, *m_base, t);
// if we were successful
if(NULL != t_new){
// recast to our derived
const void_caster * vc = *it;
return vc->downcast(t_new);
}
}
}
}
return NULL;
}
void const *
void_caster_shortcut::vbc_upcast(
void const * const t
) const {
// try to find a chain that gives us what we want
const void_cast_detail::set_type & s
= void_cast_detail::void_caster_registry::get_const_instance();
void_cast_detail::set_type::const_iterator it;
for(it = s.begin(); it != s.end(); ++it){
// if the current candidate casts from the desired base type
if((*it)->m_base == m_base){
// and if it's not us
if ((*it)->m_derived != m_derived){
// try to cast from the candidate derived to our our derived
const void * t_new;
t_new = void_upcast(*m_derived, *(*it)->m_derived, t);
if(NULL != t_new)
return (*it)->upcast(t_new);
}
}
}
return NULL;
}
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#endif
// just used as a search key
class void_caster_argument : public void_caster
{
virtual void const *
upcast(void const * const /*t*/) const {
BOOST_ASSERT(false);
return NULL;
}
virtual void const *
downcast( void const * const /*t*/) const {
BOOST_ASSERT(false);
return NULL;
}
virtual bool has_virtual_base() const {
BOOST_ASSERT(false);
return false;
}
public:
void_caster_argument(
extended_type_info const * derived,
extended_type_info const * base
) :
void_caster(derived, base)
{}
virtual ~void_caster_argument(){};
};
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
// implementation of void caster base class
BOOST_SERIALIZATION_DECL void
void_caster::recursive_register(bool includes_virtual_base) const {
void_cast_detail::set_type & s
= void_cast_detail::void_caster_registry::get_mutable_instance();
#ifdef BOOST_SERIALIZATION_LOG
std::clog << "recursive_register\n";
std::clog << m_derived->get_debug_info();
std::clog << "<-";
std::clog << m_base->get_debug_info();
std::clog << "\n";
#endif
std::pair<void_cast_detail::set_type::const_iterator, bool> result;
// comment this out for now.
result = s.insert(this);
//assert(result.second);
// generate all implied void_casts.
void_cast_detail::set_type::const_iterator it;
for(it = s.begin(); it != s.end(); ++it){
if(* m_derived == * (*it)->m_base){
const void_caster_argument vca(
(*it)->m_derived,
m_base
);
void_cast_detail::set_type::const_iterator i;
i = s.find(& vca);
if(i == s.end()){
new void_caster_shortcut(
(*it)->m_derived,
m_base,
m_difference + (*it)->m_difference,
(*it)->has_virtual_base() || includes_virtual_base,
this
);
}
}
if(* (*it)->m_derived == * m_base){
const void_caster_argument vca(
m_derived,
(*it)->m_base
);
void_cast_detail::set_type::const_iterator i;
i = s.find(& vca);
if(i == s.end()){
new void_caster_shortcut(
m_derived,
(*it)->m_base,
m_difference + (*it)->m_difference,
(*it)->has_virtual_base() || includes_virtual_base,
this
);
}
}
}
}
BOOST_SERIALIZATION_DECL void
void_caster::recursive_unregister() const {
// note: it's been discovered that at least one platform is not guaranteed
// to destroy singletons reverse order of construction. So we can't
// use a runtime assert here. Leave this in a reminder not to do this!
// BOOST_ASSERT(! void_caster_registry::is_destroyed());
if(void_caster_registry::is_destroyed())
return;
#ifdef BOOST_SERIALIZATION_LOG
std::clog << "recursive_unregister\n";
std::clog << m_derived->get_debug_info();
std::clog << "<-";
std::clog << m_base->get_debug_info();
std::clog << "\n";
#endif
void_cast_detail::set_type & s
= void_caster_registry::get_mutable_instance();
// delete all shortcuts which use this primitive
void_cast_detail::set_type::iterator it;
for(it = s.begin(); it != s.end();){
const void_caster * vc = *it;
if(vc == this){
s.erase(it++);
}
else
if(vc->m_parent == this){
s.erase(it);
delete vc;
it = s.begin();
}
else
it++;
}
}
} // namespace void_cast_detail
BOOST_SYMBOL_VISIBLE void const *
void_upcast(
extended_type_info const & derived,
extended_type_info const & base,
void const * const t
);
// Given a void *, assume that it really points to an instance of one type
// and alter it so that it would point to an instance of a related type.
// Return the altered pointer. If there exists no sequence of casts that
// can transform from_type to to_type, return a NULL.
BOOST_SERIALIZATION_DECL void const *
void_upcast(
extended_type_info const & derived,
extended_type_info const & base,
void const * const t
){
// same types - trivial case
if (derived == base)
return t;
// check to see if base/derived pair is found in the registry
const void_cast_detail::set_type & s
= void_cast_detail::void_caster_registry::get_const_instance();
const void_cast_detail::void_caster_argument ca(& derived, & base);
void_cast_detail::set_type::const_iterator it;
it = s.find(& ca);
if (s.end() != it)
return (*it)->upcast(t);
return NULL;
}
BOOST_SYMBOL_VISIBLE void const *
void_downcast(
extended_type_info const & derived,
extended_type_info const & base,
void const * const t
);
BOOST_SERIALIZATION_DECL void const *
void_downcast(
extended_type_info const & derived,
extended_type_info const & base,
void const * const t
){
// same types - trivial case
if (derived == base)
return t;
// check to see if base/derived pair is found in the registry
const void_cast_detail::set_type & s
= void_cast_detail::void_caster_registry::get_const_instance();
const void_cast_detail::void_caster_argument ca(& derived, & base);
void_cast_detail::set_type::const_iterator it;
it = s.find(&ca);
if (s.end() != it)
return(*it)->downcast(t);
return NULL;
}
} // namespace serialization
} // namespace boost
@@ -42,4 +42,8 @@
// To suppress warnings related to core/util/arma_util.hpp.
#define MLPACK_CORE_UTIL_ARMA_CONFIG_HPP
// Undefine macro due to macro collision.
#undef Realloc
#undef Free
#endif
+3
View File
@@ -8,6 +8,9 @@
#define BINDING_TYPE BINDING_TYPE_R
#include <${INCLUDE_FILE}>
#define Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (R_SIZE_T)((n) * sizeof(t)) )
#define Free(p) (R_chk_free( (void *)(p) ), (p) = NULL)
// [[Rcpp::export]]
void ${PROGRAM_NAME}_mlpackMain()
{
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -230,9 +230,9 @@ if (BUILD_GO_BINDINGS)
-DGENERATE_CPP_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/go/generate_go_${name}.cpp
-DPROGRAM_MAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_main.cpp
-DPROGRAM_NAME=${name}
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake
DEPENDS ${CMAKE_SOURCE_DIR}/src/mlpack/bindings/go/generate_go.cpp.in
${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake)
${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake)
add_executable(generate_go_${name}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/go/src/mlpack.org/v1/mlpack/capi/${name}.h
+8 -8
View File
@@ -109,8 +109,8 @@ if (BUILD_JULIA_BINDINGS)
"\"\"\"\n"
" serialize_bin(stream::IO, model)\n"
"\n"
"Serialize an mlpack model `model` in the binary boost::serialization\n"
"format to the given `stream`. Example:\n"
"Serialize an mlpack model `model` in the binary cereal format to the \n"
"given `stream`. Example:\n"
"\n"
"```julia\n"
"_, model, _, _ = mlpack.logistic_regression(training=x, labels=y)\n"
@@ -134,10 +134,10 @@ if (BUILD_JULIA_BINDINGS)
"lr_model = mlpack.deserialize_bin(stream, LogisticRegression)\n"
"```\n"
"\n"
"Only use this if you have saved the model in the boost::serialization\n"
"binary format using `serialize_bin()` or an mlpack binding in another\n"
"language! If you used `Serialization.serialize()` to serialize your\n"
"model, then use `Serialization.deserialize()` to deserialize it.\n"
"Only use this if you have saved the model in the cereal binary format \n"
"using `serialize_bin()` or an mlpack binding in another language! If \n"
"you used `Serialization.serialize()` to serialize your model, then use\n"
"`Serialization.deserialize()` to deserialize it.\n"
"\n"
"Then, the returned model can be passed to appropriate mlpack functions\n"
"for machine learning tasks.\n"
@@ -197,9 +197,9 @@ if (BUILD_JULIA_BINDINGS)
-DGENERATE_CPP_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/julia/mlpack/build/generate_jl_${name}.cpp
-DPROGRAM_MAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_main.cpp
-DMLPACK_JL_LIB_SUFFIX=${CMAKE_SHARED_LIBRARY_SUFFIX}
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake
DEPENDS ${CMAKE_SOURCE_DIR}/src/mlpack/bindings/julia/generate_jl.cpp.in
${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake)
${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake)
add_executable(generate_jl_${name}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/julia/mlpack/build/generate_jl_${name}.cpp
@@ -24,6 +24,7 @@ template<typename T>
void PrintInputProcessing(
util::ParamData& d,
const std::string& functionName,
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
const typename std::enable_if<!std::is_same<T,
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
@@ -27,6 +27,7 @@ template<typename T>
void PrintInputProcessing(
util::ParamData& d,
const std::string& /* functionName */,
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
const typename std::enable_if<!std::is_same<T,
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
@@ -26,6 +26,7 @@ template<typename T>
void PrintOutputProcessing(
util::ParamData& d,
const std::string& functionName,
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
const typename std::enable_if<!std::is_same<T,
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
@@ -29,6 +29,7 @@ template<typename T>
void PrintOutputProcessing(
util::ParamData& d,
const std::string& /* functionName */,
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
const typename std::enable_if<!std::is_same<T,
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
@@ -19,7 +19,9 @@ namespace bindings {
namespace markdown {
/**
* Return false, because the type is not serializable.
* Return false, because the type is not serializable. This includes Armadillo
* types, which we say aren't serializable (in this context) because they aren't
* mlpack models.
*/
template<typename T>
bool IsSerializable(
@@ -28,17 +30,6 @@ bool IsSerializable(
return false;
}
/**
* Return false, because even though the type is serializable, it is an
* Armadillo type not an mlpack model.
*/
template<typename T>
bool IsSerializable(
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
{
return false;
}
/**
* Return true, because the type is serializable.
*/
+1 -1
View File
@@ -180,7 +180,7 @@ void PrintDocs(const std::string& bindingName,
}
if (hasOutputOptions)
{
{
// Next, iterate through the list of output options.
cout << "### Output options" << endl;
cout << endl;
+5 -6
View File
@@ -15,10 +15,9 @@ macro (post_python_bindings)
PROPERTY INCLUDE_DIRECTORIES)
add_custom_target(python_configure
COMMAND ${CMAKE_COMMAND}
-D SETUP_PY_IN=${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/setup.py.in
-D SETUP_PY_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/setup.py
-D GENERATE_CPP_IN=${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/setup.py.in
-D GENERATE_CPP_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/setup.py
-D PACKAGE_VERSION="${PACKAGE_VERSION}"
-D Boost_SERIALIZATION_LIBRARY="${Boost_SERIALIZATION_LIBRARY_RELEASE}"
-D Boost_LIBRARY_DIRS="${Boost_LIBRARY_DIRS}"
-D ARMADILLO_LIBRARIES="${ARMADILLO_LIBRARIES}"
-D MLPACK_LIBRARY=$<TARGET_LINKER_FILE:mlpack>
@@ -29,7 +28,7 @@ macro (post_python_bindings)
-D CYTHON_INCLUDE_DIRECTORIES="${CYTHON_INCLUDE_DIRECTORIES}"
-D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-D OUTPUT_DIR=${CMAKE_BINARY_DIR}
-P "${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/ConfigureSetup.cmake"
-P "${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake"
BYPRODUCTS "${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/setup.py"
COMMENT "Configuring setup.py...")
add_dependencies(python_configure python_copy)
@@ -262,9 +261,9 @@ if (BUILD_PYTHON_BINDINGS)
-DGENERATE_CPP_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/generate_pyx_${name}.cpp
-DPROGRAM_MAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_main.cpp
-DPROGRAM_NAME=${name}
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake
-P ${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake
DEPENDS ${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/generate_pyx.cpp.in
${CMAKE_SOURCE_DIR}/CMake/ConfigureGenerate.cmake)
${CMAKE_SOURCE_DIR}/CMake/ConfigureFile.cmake)
add_executable(generate_pyx_${name}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/generate_pyx_${name}.cpp
@@ -1,46 +0,0 @@
# ConfigureSetup.cmake: generate the setup.py file given several environment
# variables.
#
# This file depends on the following variables being set:
#
# - SETUP_PY_IN: location of input file
# - SETUP_PY_OUT: location of output file
# - PACKAGE_VERSION: version of package
# - Boost_SERIALIZATION_LIBRARY: location of Boost serialization library
# - Boost_LIBRARY_DIRS: paths to boost libraries
# - ARMADILLO_LIBRARIES: space-separated list of Armadillo dependencies
# - MLPACK_LIBRARY: location of mlpack library
# - MLPACK_PYXS: list of pyx files
# - OpenMP_CXX_FLAGS: OpenMP C++ compilation flags
# - DISABLE_CFLAGS: list of CFLAGS or CXXFLAGS to be disabled
# - CYTHON_INCLUDE_DIRECTORIES: include directories for Cython
# - MLPACK_LIBDIR: path to mlpack libraries
# - OUTPUT_DIR: binary output directory for CMake
# It's possible that the FindBoost CMake script may have returned a Boost
# library with "lib" improperly prepended to it. So we need to see if the file
# exists, and if it doesn't, but it has a "lib" in it, then we will try
# stripping the "lib" off the front.
message(STATUS "Run with ${Boost_SERIALIZATION_LIBRARY}.")
if (NOT EXISTS "${Boost_SERIALIZATION_LIBRARY}")
message(STATUS "Did not find serialization library ${Boost_SERIALIZATION_LIBRARY}!")
# Split the filename to see if it starts with lib.
set(Boost_SERIALIZATION_LIBRARY_ORIG "${Boost_SERIALIZATION_LIBRARY}")
get_filename_component(SER_LIB_DIRECTORY "${Boost_SERIALIZATION_LIBRARY}"
DIRECTORY)
get_filename_component(SER_LIB_FILENAME "${Boost_SERIALIZATION_LIBRARY}" NAME)
message(STATUS "Name component is ${SER_LIB_FILENAME}, and directory is ${SER_LIB_DIRECTORY}.")
# Strip any preceding "lib/".
string(REGEX REPLACE "^lib" "" STRIPPED_FILENAME "${SER_LIB_FILENAME}")
message(STATUS "Regex gave us ${STRIPPED_FILENAME}.")
set(Boost_SERIALIZATION_LIBRARY "${SER_LIB_DIRECTORY}/${STRIPPED_FILENAME}")
message(STATUS "New library ${Boost_SERIALIZATION_LIBRARY}.")
if (NOT EXISTS "${Boost_SERIALIZATION_LIBRARY}")
# We didn't find it, so for ease of debugging just revert to the original.
set (Boost_SERIALIZATION_LIBRARY "${Boost_SERIALIZATION_LIBRARY_ORIG}")
endif ()
endif ()
configure_file(${SETUP_PY_IN} ${SETUP_PY_OUT})
@@ -2,7 +2,7 @@
* @file bindings/python/mlpack/serialization.hpp
* @author Ryan Curtin
*
* Simple utilities for boost::serialization.
* Simple utilities for cereal.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
@@ -23,9 +23,9 @@ std::string SerializeOut(T* t, const std::string& name)
{
std::ostringstream oss;
{
boost::archive::binary_oarchive b(oss);
cereal::BinaryOutputArchive b(oss);
b << boost::serialization::make_nvp(name.c_str(), *t);
b(cereal::make_nvp(name.c_str(), *t));
}
return oss.str();
}
@@ -34,9 +34,8 @@ template<typename T>
void SerializeIn(T* t, const std::string& str, const std::string& name)
{
std::istringstream iss(str);
boost::archive::binary_iarchive b(iss);
b >> boost::serialization::make_nvp(name.c_str(), *t);
cereal::BinaryInputArchive b(iss);
b(cereal::make_nvp(name.c_str(), *t));
}
} // namespace python
+1 -2
View File
@@ -40,8 +40,7 @@ library_dirs = list(filter(None, ['${MLPACK_LIBDIR}'] +
# We'll link with the exact paths to each library using extra_objects, instead
# of linking with 'libraries' and 'library_dirs', because of differences in
# Windows and Linux linking behavior.
libraries = ['${MLPACK_LIBRARY}',
'${Boost_SERIALIZATION_LIBRARY}'] + \
libraries = ['${MLPACK_LIBRARY}'] + \
'${ARMADILLO_LIBRARIES}'.split(' ')
# Potentially faulty assumption: we can always link against libraries directly
+1
View File
@@ -2,6 +2,7 @@
set(DIRS
arma_extend
boost_backport
cereal
cv
data
dists
+2 -5
View File
@@ -1,13 +1,10 @@
# Define the files we need to compile.
# Anything not in this list will not be compiled into mlpack.
set(SOURCES
serialize_armadillo.hpp
arma_extend.hpp
SpMat_extra_bones.hpp
SpMat_extra_meat.hpp
Mat_extra_bones.hpp
Mat_extra_meat.hpp
Cube_extra_bones.hpp
Cube_extra_meat.hpp
SpMat_extra_bones.hpp
)
# add directory name to sources
@@ -1,3 +0,0 @@
//! Add a serialization operator.
template<typename Archive>
void serialize(Archive& ar, const unsigned int version);
@@ -1,38 +0,0 @@
// Add a serialization operator.
template<typename eT>
template<typename Archive>
void Cube<eT>::serialize(Archive& ar, const unsigned int /* version */)
{
using boost::serialization::make_nvp;
using boost::serialization::make_array;
const uword old_n_elem = n_elem;
// This is accurate from Armadillo 3.6.0 onwards.
// We can't use BOOST_SERIALIZATION_NVP() because of the access::rw() call.
ar & make_nvp("n_rows", access::rw(n_rows));
ar & make_nvp("n_cols", access::rw(n_cols));
ar & make_nvp("n_elem_slice", access::rw(n_elem_slice));
ar & make_nvp("n_slices", access::rw(n_slices));
ar & make_nvp("n_elem", access::rw(n_elem));
// mem_state will always be 0 on load, so we don't need to save it.
if (Archive::is_loading::value)
{
// Clean any mat pointers.
delete_mat();
// Don't free if local memory is being used.
if (mem_state == 0 && mem != NULL && old_n_elem > arma_config::mat_prealloc)
{
memory::release(access::rw(mem));
}
access::rw(mem_state) = 0;
// We also need to allocate the memory we're using.
init_cold();
}
ar & make_array(access::rwp(mem), n_elem);
}
@@ -8,10 +8,6 @@
// Written by Conrad Sanderson - http://conradsanderson.id.au
// Written by Ryan Curtin
//! Add a serialization operator.
template<typename Archive>
void serialize(Archive& ar, const unsigned int version);
/**
* These will help us refer the proper vector / column types, only with
* specifying the matrix type we want to use.
@@ -20,7 +16,3 @@ void serialize(Archive& ar, const unsigned int version);
typedef Col<elem_type> vec_type;
typedef Col<elem_type> col_type;
typedef Row<elem_type> row_type;
/*
* Add row_col_iterator and row_col_const_iterator to arma::Mat.
*/
@@ -1,44 +0,0 @@
// Copyright (C) 2008-2016 National ICT Australia (NICTA)
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// -------------------------------------------------------------------
//
// Written by Conrad Sanderson - http://conradsanderson.id.au
// Written by Ryan Curtin
// Add a serialization operator.
template<typename eT>
template<typename Archive>
void Mat<eT>::serialize(Archive& ar, const unsigned int /* version */)
{
using boost::serialization::make_nvp;
using boost::serialization::make_array;
const uword old_n_elem = n_elem;
// This is accurate from Armadillo 3.6.0 onwards.
// We can't use BOOST_SERIALIZATION_NVP() because of the access::rw() call.
ar & make_nvp("n_rows", access::rw(n_rows));
ar & make_nvp("n_cols", access::rw(n_cols));
ar & make_nvp("n_elem", access::rw(n_elem));
ar & make_nvp("vec_state", access::rw(vec_state));
// mem_state will always be 0 on load, so we don't need to save it.
if (Archive::is_loading::value)
{
// Don't free if local memory is being used.
if (mem_state == 0 && mem != NULL && old_n_elem > arma_config::mat_prealloc)
{
memory::release(access::rw(mem));
}
access::rw(mem_state) = 0;
// We also need to allocate the memory we're using.
init_cold();
}
ar & make_array(access::rwp(mem), n_elem);
}
-23
View File
@@ -1,23 +0,0 @@
The files in this directory are taken from newer versions of Armadillo in order
to still support older versions of Armadillo. Therefore some files are licensed
under the Mozilla Public License v2.0 (MPL2).
These are the files under the MPL:
- fn_ind2sub.hpp
- SpMat_extra_bones.hpp
- SpMat_extra_meat.hpp
- operator_minus.hpp
- hdf5_misc.hpp
- Mat_extra_bones.hpp
- Mat_extra_meat.hpp
If you want a copy of mlpack without MPL code included, you will need to
* Remove all of the above-listed files.
* Remove the above-listed files from CMakeLists.txt.
* Remove the above-listed files from arma_extend.hpp.
* Modify the root CMakeLists.txt to require a sufficiently new version of
* Armadillo that none of the above backports are required, by changing the line
"find_package(Armadillo x.yyy.z REQUIRED)" to reference a sufficiently new
version instead of x.yyy.z.
@@ -9,17 +9,10 @@
// Written by Ryan Curtin
// Written by Matthew Amidon
/**
* Add a batch constructor for SpMat, if the version is older than 3.810.0, and
* also a serialize() function for Armadillo.
*/
template<typename Archive>
void serialize(Archive& ar, const unsigned int version);
/**
* These will help us refer the proper vector / column types, only with
* specifying the matrix type we want to use.
*/
typedef SpCol<elem_type> vec_type;
typedef SpCol<elem_type> col_type;
typedef SpRow<elem_type> row_type;
typedef SpRow<elem_type> row_type;
@@ -1,44 +0,0 @@
// Copyright (C) 2008-2015 National ICT Australia (NICTA)
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// -------------------------------------------------------------------
//
// Written by Conrad Sanderson - http://conradsanderson.id.au
// Written by Ryan Curtin
// Written by Matthew Amidon
/**
* Add a serialization function.
*/
template<typename eT>
template<typename Archive>
void SpMat<eT>::serialize(Archive& ar, const unsigned int /* version */)
{
using boost::serialization::make_nvp;
using boost::serialization::make_array;
// This is accurate from Armadillo 3.6.0 onwards.
// We can't use BOOST_SERIALIZATION_NVP() because of the access::rw() call.
ar & make_nvp("n_rows", access::rw(n_rows));
ar & make_nvp("n_cols", access::rw(n_cols));
ar & make_nvp("n_elem", access::rw(n_elem));
ar & make_nvp("n_nonzero", access::rw(n_nonzero));
ar & make_nvp("vec_state", access::rw(vec_state));
// Now we have to serialize the values, row indices, and column pointers.
// If we are loading, we need to initialize space for these things.
if (Archive::is_loading::value)
{
const uword new_n_nonzero = n_nonzero; // Save this; we're about to nuke it.
init(n_rows, n_cols); // Allocate column pointers.
mem_resize(new_n_nonzero); // Allocate storage.
// These calls will set the sentinel values at the end of the storage and
// column pointers, if necessary, so we don't need to worry about them.
}
ar & make_array(access::rwp(values), n_nonzero);
ar & make_array(access::rwp(row_indices), n_nonzero);
ar & make_array(access::rwp(col_ptrs), n_cols + 1);
}
+3 -36
View File
@@ -9,43 +9,10 @@
#ifndef MLPACK_CORE_ARMA_EXTEND_ARMA_EXTEND_HPP
#define MLPACK_CORE_ARMA_EXTEND_ARMA_EXTEND_HPP
// Add batch constructor for sparse matrix (if version <= 3.810.0).
#define ARMA_EXTRA_SPMAT_PROTO mlpack/core/arma_extend/SpMat_extra_bones.hpp
#define ARMA_EXTRA_SPMAT_MEAT mlpack/core/arma_extend/SpMat_extra_meat.hpp
// Add row_col_iterator and row_col_const_iterator for Mat.
// Add vec_type, col_type, and row_type to Mat and SpMat.
// TODO: refactor and remove these!
#define ARMA_EXTRA_MAT_PROTO mlpack/core/arma_extend/Mat_extra_bones.hpp
#define ARMA_EXTRA_MAT_MEAT mlpack/core/arma_extend/Mat_extra_meat.hpp
// Add boost serialization for Cube.
#define ARMA_EXTRA_CUBE_PROTO mlpack/core/arma_extend/Cube_extra_bones.hpp
#define ARMA_EXTRA_CUBE_MEAT mlpack/core/arma_extend/Cube_extra_meat.hpp
// Manually set ARMA_{64,32}BIT_WORD for _WIN64 or win32
#if defined(_MSC_VER)
#ifdef _WIN64
#define ARMA_64BIT_WORD
#ifdef ARMA_32BIT_WORD
#undef ARMA_32BIT_WORD
#endif
#else
#define ARMA_32BIT_WORD
#ifdef ARMA_64BIT_WORD
#undef ARMA_64BIT_WORD
#endif
#endif
#endif
// Force definition of old HDF5 API. Thanks to Mike Roberts for helping find
// this workaround.
#if !defined(H5_USE_110_API)
#define H5_USE_110_API
#endif
// Include everything we'll need for serialize().
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/array.hpp>
#define ARMA_EXTRA_SPMAT_PROTO mlpack/core/arma_extend/SpMat_extra_bones.hpp
#include <armadillo>
@@ -0,0 +1,109 @@
// Copyright (C) 2008-2016 National ICT Australia (NICTA)
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// -------------------------------------------------------------------
//
// Written by Conrad Sanderson - http://conradsanderson.id.au
// Written by Ryan Curtin
#ifndef MLPACK_CORE_ARMA_EXTEND_SERIALIZE_ARMADILLO_HPP
#define MLPACK_CORE_ARMA_EXTEND_SERIALIZE_ARMADILLO_HPP
#include <cereal/archives/binary.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/json.hpp>
#include <mlpack/core/cereal/array_wrapper.hpp>
#include <armadillo>
/**
* Add an external serialization function for SpMat.
*/
namespace cereal {
template<typename Archive, typename eT>
void serialize(Archive& ar, arma::SpMat<eT>& mat)
{
// This is accurate from Armadillo 3.6.0 onwards.
arma::uword n_rows = mat.n_rows;
arma::uword n_cols = mat.n_cols;
arma::uword n_nonzero = mat.n_nonzero;
arma::uword vec_state = mat.vec_state;
ar(CEREAL_NVP(n_rows));
ar(CEREAL_NVP(n_cols));
ar(CEREAL_NVP(n_nonzero));
ar(CEREAL_NVP(vec_state));
// Now we have to serialize the values, row indices, and column pointers.
// If we are loading, we need to initialize space for these things.
if (cereal::is_loading<Archive>())
{
mat.zeros(n_rows, n_cols);
arma::access::rw(mat.vec_state) = vec_state;
mat.mem_resize(n_nonzero); // Allocate storage.
// These calls will set the sentinel values at the end of the stored
// column pointers, if necessary, so we don't need to worry about them.
}
// Serialize the values held in the sparse matrix.
for (size_t i = 0; i < mat.n_nonzero; ++i)
ar(cereal::make_nvp("value", arma::access::rw(mat.values[i])));
for (size_t i = 0; i < mat.n_nonzero; ++i)
ar(cereal::make_nvp("row_index", arma::access::rw(mat.row_indices[i])));
for (size_t i = 0; i < mat.n_cols + 1; ++i)
ar(cereal::make_nvp("col_ptr", arma::access::rw(mat.col_ptrs[i])));
}
// Add an external serialization function for Mat.
template<typename Archive, typename eT>
void serialize(Archive& ar, arma::Mat<eT>& mat)
{
// This is accurate from Armadillo 3.6.0 onwards.
arma::uword n_rows = mat.n_rows;
arma::uword n_cols = mat.n_cols;
arma::uword vec_state = mat.vec_state;
ar(CEREAL_NVP(n_rows));
ar(CEREAL_NVP(n_cols));
ar(CEREAL_NVP(vec_state));
if (cereal::is_loading<Archive>())
{
mat.set_size(n_rows, n_cols);
arma::access::rw(mat.vec_state) = vec_state;
}
// Directly serialize the contents of the matrix's memory.
for (size_t i = 0; i < mat.n_elem; ++i)
ar(cereal::make_nvp("elem", arma::access::rw(mat.mem[i])));
}
// Add a serialization function for armadillo Cube
template<typename Archive, typename eT>
void serialize(Archive& ar, arma::Cube<eT>& cube)
{
// This is accurate from Armadillo 3.6.0 onwards.
arma::uword n_rows = cube.n_rows;
arma::uword n_cols = cube.n_cols;
arma::uword n_slices = cube.n_slices;
ar(CEREAL_NVP(n_rows));
ar(CEREAL_NVP(n_cols));
ar(CEREAL_NVP(n_slices));
if (cereal::is_loading<Archive>())
cube.set_size(n_rows, n_cols, n_slices);
// Directly serialize the contents of the cube's memory.
for (size_t i = 0; i < cube.n_elem; ++i)
ar(cereal::make_nvp("elem", arma::access::rw(cube.mem[i])));
}
} // end namespace cereal
#endif // MLPACK_CORE_ARMA_EXTEND_SERIALIZE_ARMADILLO_HPP
@@ -2,19 +2,13 @@
# Anything not in this list will not be compiled into mlpack.
set(SOURCES
bernoulli.hpp
boost_backport_serialization.hpp
detail/bernoulli_details.hpp
detail/polygamma.hpp
detail/unchecked_bernoulli.hpp
math_fwd.hpp
policy.hpp
unordered_collections_load_imp.hpp
unordered_collections_save_imp.hpp
vector.hpp
string_view.hpp
string_view_fwd.hpp
collections_load_imp.hpp
collections_save_imp.hpp
boost_backport_string_view.hpp
)
-1
View File
@@ -1,7 +1,6 @@
The files in this directory are taken from Boost 1.56.0 and Boost 1.61.0 in
order to backport:
* Serialization support for unordered_map (added in Boost 1.56).
* Trigamma and polygamma function calculation for the gamma_distribution.hpp
file (added in Boost 1.58.0, files taken from Boost 1.61.0)
@@ -1,44 +0,0 @@
/**
* @file core/boost_backport/boost_backport_serialization.hpp
* @author Yannis Mentekidis
*
* Centralized control of what boost files to include. We have backported the
* following boost functionality here:
*
* * unordered_set serialization support (added in boost 1.56.0)
* * vector serialization (changed after boost 1.58.0)
*
* If the detected boost version is greater than 1.58.0, we include the normal
* serialization functions (not the backported ones). For all older versions we
* include the backported headers.
*/
#ifndef MLPACK_CORE_BOOST_BACKPORT_SERIALIZATION_HPP
#define MLPACK_CORE_BOOST_BACKPORT_SERIALIZATION_HPP
#include <boost/version.hpp>
#include <boost/serialization/unordered_map.hpp>
#if BOOST_VERSION == 105800
/**
* Boost versions 1.58.0 and earlier have a different vector serialization
* behaivor as compared to later versions. Notably, loading a
* std::vector<arma::mat> does not clear the vector before the load
* in v1.58 and earlier; while in the later versions, the vector is cleared
* before loading. This causes some tests related to serialization to fail
* with versions 1.58. This backport solves the issue.
*/
#ifdef BOOST_SERIALIZATION_VECTOR_HPP
#pragma message "Detected Boost version is 1.58. Including\
boost/serialization/vector.hpp before mlpack/core.hpp can cause problems. It\
should only be necessary to include mlpack/core.hpp and not\
boost/serialization/vector.hpp."
#endif
#include "mlpack/core/boost_backport/collections_load_imp.hpp"
#include "mlpack/core/boost_backport/collections_save_imp.hpp"
#include "mlpack/core/boost_backport/vector.hpp"
#else
#include <boost/serialization/vector.hpp>
#endif
#endif // MLPACK_CORE_BOOST_BACKPORT_SERIALIZATION_HPP
@@ -1,105 +0,0 @@
#ifndef BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
#define BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
#if defined(_MSC_VER) && (_MSC_VER <= 1020)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// collections_load_imp.hpp: serialization for loading stl collections
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
// helper function templates for serialization of collections
#include <boost/assert.hpp>
#include <cstddef> // size_t
#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
} // namespace std
#endif
#include <boost/detail/workaround.hpp>
#include <boost/archive/detail/basic_iarchive.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/detail/stack_constructor.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/item_version_type.hpp>
#include <boost/serialization/detail/is_default_constructible.hpp>
#include <boost/utility/enable_if.hpp>
namespace boost{
namespace serialization {
namespace stl {
//////////////////////////////////////////////////////////////////////
// implementation of serialization for STL containers
//
template<
class Archive,
class T
>
typename boost::enable_if<
typename detail::is_default_constructible<
typename T::value_type
>,
void
>::type
collection_load_impl(
Archive & ar,
T & t,
collection_size_type count,
item_version_type
){
t.resize(count);
typename T::iterator hint;
hint = t.begin();
while(count-- > 0){
ar >> boost::serialization::make_nvp("item", *hint++);
}
}
template<
class Archive,
class T
>
typename boost::disable_if<
typename detail::is_default_constructible<
typename T::value_type
>,
void
>::type
collection_load_impl(
Archive & ar,
T & t,
collection_size_type count,
item_version_type item_version
){
t.clear();
while(count-- > 0){
detail::stack_construct<Archive, typename T::value_type> u(ar, item_version);
ar >> boost::serialization::make_nvp("item", u.reference());
t.push_back(u.reference());
ar.reset_object_address(& t.back() , & u.reference());
}
}
} // namespace stl
} // namespace serialization
} // namespace boost
#endif //BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
@@ -1,82 +0,0 @@
#ifndef BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
#define BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// collections_save_imp.hpp: serialization for stl collections
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
// helper function templates for serialization of collections
#include <boost/config.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/item_version_type.hpp>
namespace boost{
namespace serialization {
namespace stl {
//////////////////////////////////////////////////////////////////////
// implementation of serialization for STL containers
//
template<class Archive, class Container>
inline void save_collection(
Archive & ar,
const Container &s,
collection_size_type count)
{
ar << BOOST_SERIALIZATION_NVP(count);
// record number of elements
const item_version_type item_version(
version<typename Container::value_type>::value
);
#if 0
boost::archive::library_version_type library_version(
ar.get_library_version()
);
if(boost::archive::library_version_type(3) < library_version){
ar << BOOST_SERIALIZATION_NVP(item_version);
}
#else
ar << BOOST_SERIALIZATION_NVP(item_version);
#endif
typename Container::const_iterator it = s.begin();
while(count-- > 0){
// note borland emits a no-op without the explicit namespace
boost::serialization::save_construct_data_adl(
ar,
&(*it),
item_version
);
ar << boost::serialization::make_nvp("item", *it++);
}
}
template<class Archive, class Container>
inline void save_collection(Archive & ar, const Container &s)
{
// record number of elements
collection_size_type count(s.size());
save_collection(ar, s, count);
}
} // namespace stl
} // namespace serialization
} // namespace boost
#endif //BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
@@ -1,77 +0,0 @@
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
#define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// unordered_collections_load_imp.hpp: serialization for loading stl collections
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// (C) Copyright 2014 Jim Bell
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
// helper function templates for serialization of collections
#include <boost/assert.hpp>
#include <cstddef> // size_t
#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
} // namespace std
#endif
#include <boost/detail/workaround.hpp>
#include <boost/archive/detail/basic_iarchive.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/detail/stack_constructor.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/item_version_type.hpp>
namespace boost{
namespace serialization {
namespace stl {
//////////////////////////////////////////////////////////////////////
// implementation of serialization for STL containers
//
template<class Archive, class Container, class InputFunction>
inline void load_unordered_collection(Archive & ar, Container &s)
{
s.clear();
collection_size_type count;
collection_size_type bucket_count;
boost::serialization::item_version_type item_version(0);
boost::archive::library_version_type library_version(
ar.get_library_version()
);
// retrieve number of elements
ar >> BOOST_SERIALIZATION_NVP(count);
ar >> BOOST_SERIALIZATION_NVP(bucket_count);
if(boost::archive::library_version_type(3) < library_version){
ar >> BOOST_SERIALIZATION_NVP(item_version);
}
s.rehash(bucket_count);
InputFunction ifunc;
while(count-- > 0){
ifunc(ar, s, item_version);
}
}
} // namespace stl
} // namespace serialization
} // namespace boost
#endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
@@ -1,89 +0,0 @@
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
#define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// hash_collections_save_imp.hpp: serialization for stl collections
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// (C) Copyright 2014 Jim Bell
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
// helper function templates for serialization of collections
#include <boost/config.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/item_version_type.hpp>
namespace boost{
namespace serialization {
namespace stl {
//////////////////////////////////////////////////////////////////////
// implementation of serialization for STL containers
//
template<class Archive, class Container>
inline void save_unordered_collection(Archive & ar, const Container &s)
{
collection_size_type count(s.size());
const collection_size_type bucket_count(s.bucket_count());
const item_version_type item_version(
version<typename Container::value_type>::value
);
#if 0
/* should only be necessary to create archives of previous versions
* which is not currently supported. So for now comment this out
*/
boost::archive::library_version_type library_version(
ar.get_library_version()
);
// retrieve number of elements
ar << BOOST_SERIALIZATION_NVP(count);
ar << BOOST_SERIALIZATION_NVP(bucket_count);
if(boost::archive::library_version_type(3) < library_version){
// record number of elements
// make sure the target type is registered so we can retrieve
// the version when we load
ar << BOOST_SERIALIZATION_NVP(item_version);
}
#else
ar << BOOST_SERIALIZATION_NVP(count);
ar << BOOST_SERIALIZATION_NVP(bucket_count);
ar << BOOST_SERIALIZATION_NVP(item_version);
#endif
typename Container::const_iterator it = s.begin();
while(count-- > 0){
// note borland emits a no-op without the explicit namespace
boost::serialization::save_construct_data_adl(
ar,
&(*it),
boost::serialization::version<
typename Container::value_type
>::value
);
ar << boost::serialization::make_nvp("item", *it++);
}
}
} // namespace stl
} // namespace serialization
} // namespace boost
#endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
@@ -1,234 +0,0 @@
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_SERIALIZATION_UNORDERED_MAP_HPP
#define BOOST_SERIALIZATION_UNORDERED_MAP_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// serialization/unordered_map.hpp:
// serialization for stl unordered_map templates
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// (C) Copyright 2014 Jim Bell
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp>
#include <unordered_map>
#include <boost/serialization/utility.hpp>
#include "unordered_collections_save_imp.hpp"
#include "unordered_collections_load_imp.hpp"
#include <boost/serialization/split_free.hpp>
namespace boost {
namespace serialization {
namespace stl {
// map input
template<class Archive, class Container>
struct archive_input_unordered_map
{
inline void operator()(
Archive &ar,
Container &s,
const unsigned int v
){
typedef typename Container::value_type type;
detail::stack_construct<Archive, type> t(ar, v);
// borland fails silently w/o full namespace
ar >> boost::serialization::make_nvp("item", t.reference());
std::pair<typename Container::const_iterator, bool> result =
s.insert(t.reference());
// note: the following presumes that the map::value_type was NOT tracked
// in the archive. This is the usual case, but here there is no way
// to determine that.
if(result.second){
ar.reset_object_address(
& (result.first->second),
& t.reference().second
);
}
}
};
// multimap input
template<class Archive, class Container>
struct archive_input_unordered_multimap
{
inline void operator()(
Archive &ar,
Container &s,
const unsigned int v
){
typedef typename Container::value_type type;
detail::stack_construct<Archive, type> t(ar, v);
// borland fails silently w/o full namespace
ar >> boost::serialization::make_nvp("item", t.reference());
typename Container::const_iterator result
= s.insert(t.reference());
// note: the following presumes that the map::value_type was NOT tracked
// in the archive. This is the usual case, but here there is no way
// to determine that.
ar.reset_object_address(
& result->second,
& t.reference()
);
}
};
} // stl
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void save(
Archive & ar,
const std::unordered_map<
Key, HashFcn, EqualKey, Allocator
> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::save_unordered_collection<
Archive,
std::unordered_map<
Key, HashFcn, EqualKey, Allocator
>
>(ar, t);
}
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void load(
Archive & ar,
std::unordered_map<
Key, HashFcn, EqualKey, Allocator
> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::load_unordered_collection<
Archive,
std::unordered_map<
Key, HashFcn, EqualKey, Allocator
>,
boost::serialization::stl::archive_input_unordered_map<
Archive,
std::unordered_map<
Key, HashFcn, EqualKey, Allocator
>
>
>(ar, t);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void serialize(
Archive & ar,
std::unordered_map<
Key, HashFcn, EqualKey, Allocator
> &t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
// unordered_multimap
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void save(
Archive & ar,
const std::unordered_multimap<
Key, HashFcn, EqualKey, Allocator
> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::save_unordered_collection<
Archive,
std::unordered_multimap<
Key, HashFcn, EqualKey, Allocator
>
>(ar, t);
}
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void load(
Archive & ar,
std::unordered_multimap<
Key, HashFcn, EqualKey, Allocator
> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::load_unordered_collection<
Archive,
std::unordered_multimap<
Key, HashFcn, EqualKey, Allocator
>,
boost::serialization::stl::archive_input_unordered_multimap<
Archive,
std::unordered_multimap<
Key, HashFcn, EqualKey, Allocator
>
>
>(ar, t);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void serialize(
Archive & ar,
std::unordered_multimap<
Key, HashFcn, EqualKey, Allocator
> &t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
} // namespace serialization
} // namespace boost
#endif // BOOST_SERIALIZATION_UNORDERED_MAP_HPP
-227
View File
@@ -1,227 +0,0 @@
#ifndef BOOST_SERIALIZATION_VECTOR_HPP
#define BOOST_SERIALIZATION_VECTOR_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// vector.hpp: serialization for stl vector templates
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// fast array serialization (C) Copyright 2005 Matthias Troyer
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <vector>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/archive/detail/basic_iarchive.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/item_version_type.hpp>
#include <boost/serialization/collections_save_imp.hpp>
#include <boost/serialization/collections_load_imp.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/detail/get_data.hpp>
#include <boost/serialization/detail/stack_constructor.hpp>
#include <boost/mpl/bool_fwd.hpp>
#include <boost/mpl/if.hpp>
// default is being compatible with version 1.34.1 files, not 1.35 files
#ifndef BOOST_SERIALIZATION_VECTOR_VERSIONED
#define BOOST_SERIALIZATION_VECTOR_VERSIONED(V) (V==4 || V==5)
#endif
// function specializations must be defined in the appropriate
// namespace - boost::serialization
#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
#define STD _STLP_STD
#else
#define STD std
#endif
namespace boost {
namespace serialization {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// vector< T >
// the default versions
template<class Archive, class U, class Allocator>
inline void save(
Archive & ar,
const std::vector<U, Allocator> &t,
const unsigned int /* file_version */,
mpl::false_
){
boost::serialization::stl::save_collection<Archive, STD::vector<U, Allocator> >(
ar, t
);
}
template<class Archive, class U, class Allocator>
inline void load(
Archive & ar,
std::vector<U, Allocator> &t,
const unsigned int /* file_version */,
mpl::false_
){
const boost::archive::library_version_type library_version(
ar.get_library_version()
);
// retrieve number of elements
item_version_type item_version(0);
collection_size_type count;
ar >> BOOST_SERIALIZATION_NVP(count);
if(boost::archive::library_version_type(3) < library_version){
ar >> BOOST_SERIALIZATION_NVP(item_version);
}
t.reserve(count);
stl::collection_load_impl(ar, t, count, item_version);
}
// the optimized versions
template<class Archive, class U, class Allocator>
inline void save(
Archive & ar,
const std::vector<U, Allocator> &t,
const unsigned int /* file_version */,
mpl::true_
){
const collection_size_type count(t.size());
ar << BOOST_SERIALIZATION_NVP(count);
if (!t.empty())
ar << boost::serialization::make_array(detail::get_data(t),t.size());
}
template<class Archive, class U, class Allocator>
inline void load(
Archive & ar,
std::vector<U, Allocator> &t,
const unsigned int /* file_version */,
mpl::true_
){
collection_size_type count(t.size());
ar >> BOOST_SERIALIZATION_NVP(count);
t.resize(count);
unsigned int item_version=0;
if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) {
ar >> BOOST_SERIALIZATION_NVP(item_version);
}
if (!t.empty())
ar >> boost::serialization::make_array(detail::get_data(t),t.size());
}
// dispatch to either default or optimized versions
template<class Archive, class U, class Allocator>
inline void save(
Archive & ar,
const std::vector<U, Allocator> &t,
const unsigned int file_version
){
typedef typename
boost::serialization::use_array_optimization<Archive>::template apply<
typename remove_const<U>::type
>::type use_optimized;
save(ar,t,file_version, use_optimized());
}
template<class Archive, class U, class Allocator>
inline void load(
Archive & ar,
std::vector<U, Allocator> &t,
const unsigned int file_version
){
#ifdef BOOST_SERIALIZATION_VECTOR_135_HPP
if (ar.get_library_version()==boost::archive::library_version_type(5))
{
load(ar,t,file_version, boost::is_arithmetic<U>());
return;
}
#endif
typedef typename
boost::serialization::use_array_optimization<Archive>::template apply<
typename remove_const<U>::type
>::type use_optimized;
load(ar,t,file_version, use_optimized());
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<class Archive, class U, class Allocator>
inline void serialize(
Archive & ar,
std::vector<U, Allocator> & t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// vector<bool>
template<class Archive, class Allocator>
inline void save(
Archive & ar,
const std::vector<bool, Allocator> &t,
const unsigned int /* file_version */
){
// record number of elements
collection_size_type count (t.size());
ar << BOOST_SERIALIZATION_NVP(count);
std::vector<bool>::const_iterator it = t.begin();
while(count-- > 0){
bool tb = *it++;
ar << boost::serialization::make_nvp("item", tb);
}
}
template<class Archive, class Allocator>
inline void load(
Archive & ar,
std::vector<bool, Allocator> &t,
const unsigned int /* file_version */
){
// retrieve number of elements
collection_size_type count;
ar >> BOOST_SERIALIZATION_NVP(count);
t.resize(count);
for(collection_size_type i = collection_size_type(0); i < count; ++i){
bool b;
ar >> boost::serialization::make_nvp("item", b);
t[i] = b;
}
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<class Archive, class Allocator>
inline void serialize(
Archive & ar,
std::vector<bool, Allocator> & t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
} // serialization
} // namespace boost
#include <boost/serialization/collection_traits.hpp>
BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector)
#undef STD
#endif // BOOST_SERIALIZATION_VECTOR_HPP
+23
View File
@@ -0,0 +1,23 @@
# Define the files that we need to compile.
# Anything not in this list will not be compiled into mlpack.
set(SOURCES
array_wrapper.hpp
is_loading.hpp
is_saving.hpp
pair_associative_container.hpp
pointer_wrapper.hpp
pointer_vector_wrapper.hpp
pointer_variant_wrapper.hpp
pointer_vector_variant_wrapper.hpp
unordered_map.hpp
)
# add directory name to sources
set(DIR_SRCS)
foreach(file ${SOURCES})
set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file})
endforeach()
# Append sources (with directory name) to list of all mlpack sources (used at
# parent scope).
set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE)
+91
View File
@@ -0,0 +1,91 @@
/**
* @file core/cereal/array_wrapper.hpp
* @author Omar Shrit
*
* Implementation of an array wrapper.
*
* This implementation allows to seriliaze an array easily using cereal.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_CEREAL_ARRAY_WRAPPER_HPP
#define MLPACK_CORE_CEREAL_ARRAY_WRAPPER_HPP
#include <cereal/archives/binary.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/json.hpp>
namespace cereal {
/**
* This class is used as a shim for cereal to be able to serialize a raw pointer array.
*/
template<class T>
class ArrayWrapper
{
public:
ArrayWrapper(T*& addr, std::size_t& size) :
arrayAddress(addr),
arraySize(size)
{}
template<class Archive>
void save(Archive& ar) const
{
ar(CEREAL_NVP(arraySize));
for (size_t i = 0; i < arraySize; ++i)
ar(cereal::make_nvp("item", arrayAddress[i]));
}
template<class Archive>
void load(Archive& ar)
{
ar(CEREAL_NVP(arraySize));
delete[] arrayAddress;
if (arraySize == 0)
{
arrayAddress = NULL;
return;
}
arrayAddress = new T[arraySize];
for (size_t i = 0; i < arraySize; ++i)
ar(cereal::make_nvp("item", arrayAddress[i]));
}
private:
ArrayWrapper& operator=(ArrayWrapper rhs);
T*& arrayAddress;
size_t& arraySize;
};
/**
* This function is used to serialized old c-style array
*
* @param t C Style array.
* @param s the size of the array.
*/
template<class T, class S>
inline
ArrayWrapper<T> make_array(T*& t, S& s)
{
return ArrayWrapper<T>(t, s);
}
/**
* Cereal does not support the serialization of raw pointer.
* This macro enable developers to serialize old c-style array by using the
* above ArrayWrapper class which serialize each member independently.
*
* @param T C Style array.
* @param S Size of the array.
*/
#define CEREAL_POINTER_ARRAY(T, S) cereal::make_array(T, S)
} // namespace cereal
#endif // CEREAL_ARRAY_WRAPPER_HPP
+57
View File
@@ -0,0 +1,57 @@
/**
* @file core/cereal/is_loading.hpp
* @author Ryan Curtin
*
* Implementation of is_loading function.
*
* This implementation provides backward compatibilty with older
* version of cereal that does not have Archive::is_loading struct.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_CEREAL_IS_LOADING_HPP
#define MLPACK_CORE_CEREAL_IS_LOADING_HPP
#include <cereal/archives/binary.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/json.hpp>
namespace cereal {
template<typename Archive>
struct is_cereal_archive
{
// Archive::is_loading is not implemented yet, so we can use std::is_same<>
// to check if it is a loading archive.
constexpr static bool value = std::is_same<Archive,
cereal::BinaryInputArchive>::value ||
// #if (BINDING_TYPE != BINDING_TYPE_R)
std::is_same<Archive, cereal::JSONInputArchive>::value ||
// #endif
std::is_same<Archive, cereal::XMLInputArchive>::value;
};
template<typename Archive>
bool is_loading(
const typename std::enable_if<
is_cereal_archive<Archive>::value, Archive>::type* = 0)
{
return true;
}
template<typename Archive>
bool is_loading(
const typename std::enable_if<
!is_cereal_archive<Archive>::value, Archive>::type* = 0)
{
return false;
}
} // namespace cereal
#endif // CEREAL_IS_LOADING_HPP
+58
View File
@@ -0,0 +1,58 @@
/**
* @file core/cereal/is_saving.hpp
* @author Ryan Curtin
* @author Omar Shrit
*
* Implementation of is_saving function.
*
* This implementation provides backward compatibilty with older
* version of cereal that does not have Archive::is_saving struct.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_CEREAL_IS_SAVING_HPP
#define MLPACK_CORE_CEREAL_IS_SAVING_HPP
#include <cereal/archives/binary.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/json.hpp>
namespace cereal {
template<typename Archive>
struct is_cereal_archive_saving
{
// Archive::is_saving is not implemented yet, so we can use std::is_same<>
// to check if it is a loading archive.
constexpr static bool value = std::is_same<Archive,
cereal::BinaryOutputArchive>::value ||
// #if (BINDING_TYPE != BINDING_TYPE_R)
std::is_same<Archive, cereal::JSONOutputArchive>::value ||
// #endif
std::is_same<Archive, cereal::XMLOutputArchive>::value;
};
template<typename Archive>
bool is_saving(
const typename std::enable_if<
is_cereal_archive_saving<Archive>::value, Archive>::type* = 0)
{
return true;
}
template<typename Archive>
bool is_saving(
const typename std::enable_if<
!is_cereal_archive_saving<Archive>::value, Archive>::type* = 0)
{
return false;
}
} // namespace cereal
#endif // CEREAL_IS_SAVING_HPP
@@ -0,0 +1,82 @@
/**
* This file is backported from cereal 1.3 to support the serialization
* of objects of type associative containers (std::map, std::pair, etc.)
*
* This file add the support for serialization of containers for any
* version of cereal starting from 1.1.2 that is required by Ubuntu
* 16.04
*
*/
/*! \file pair_associative_container.hpp
\brief Support for the PairAssociativeContainer refinement of the
AssociativeContainer concept.
\ingroup TypeConcepts */
/*
Copyright (c) 2014, Randolph Voorhies, Shane Grant
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of cereal nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
#define CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
#include "cereal/cereal.hpp"
namespace cereal
{
//! Saving for std-like pair associative containers
template <class Archive, template <typename...> class Map, typename... Args, typename = typename Map<Args...>::mapped_type> inline
void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, Map<Args...> const & map )
{
ar( make_size_tag( static_cast<size_type>(map.size()) ) );
for( const auto & i : map )
ar( make_map_item(i.first, i.second) );
}
//! Loading for std-like pair associative containers
template <class Archive, template <typename...> class Map, typename... Args, typename = typename Map<Args...>::mapped_type> inline
void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, Map<Args...> & map )
{
size_type size;
ar( make_size_tag( size ) );
map.clear();
auto hint = map.begin();
for( size_t i = 0; i < size; ++i )
{
typename Map<Args...>::key_type key;
typename Map<Args...>::mapped_type value;
ar( make_map_item(key, value) );
#ifdef CEREAL_OLDER_GCC
hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) );
#else // NOT CEREAL_OLDER_GCC
hint = map.emplace_hint( hint, std::move( key ), std::move( value ) );
#endif // NOT CEREAL_OLDER_GCC
}
}
} // namespace cereal
#endif // CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
@@ -0,0 +1,159 @@
/**
* @file core/cereal/pointer_variant_wrapper.hpp
* @author Omar Shrit
*
* Implementation of a boost::variant wrapper to enable the serialization of
* the pointers inside boost variant in cereal
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_CEREAL_POINTER_VARIANT_WRAPPER_HPP
#define MLPACK_CORE_CEREAL_POINTER_VARIANT_WRAPPER_HPP
#include <cereal/archives/json.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/types/boost_variant.hpp>
#include <boost/variant.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/static_visitor.hpp>
#include "pointer_wrapper.hpp"
namespace cereal {
// Forward declaration.
template<typename... VariantTypes>
class PointerVariantWrapper;
/**
* Serialize a boost variant in which the variant it self is a raw pointer.
* This wrapper will wrap each variant independently by encapsulating each variant
* into the PoninterWrapper we have created already.
*
* @param t A reference to boost variant that holds raw pointer.
*/
template<typename... VariantTypes>
inline PointerVariantWrapper<VariantTypes...>
make_pointer_variant(boost::variant<VariantTypes...>& t)
{
return PointerVariantWrapper<VariantTypes...>(t);
}
template<class Archive>
struct save_visitor : public boost::static_visitor<void>
{
save_visitor(Archive& ar) : ar(ar) {}
template<class T>
void operator()(const T* value) const
{
ar(CEREAL_POINTER(value));
}
template<typename... Types>
void operator()(boost::variant<Types*...>& value) const
{
ar(make_pointer_variant(value));
}
Archive& ar;
};
template<typename T>
struct load_visitor : public boost::static_visitor<void>
{
template<typename Archive, typename VariantType>
static void load_impl(Archive& ar, VariantType& variant, std::true_type)
{
// Note that T will be a pointer type.
T loadVariant;
ar(CEREAL_POINTER(loadVariant));
variant = loadVariant;
}
template<typename Archive, typename VariantType>
static void load_impl(Archive& ar, VariantType& value, std::false_type)
{
// This must be a nested boost::variant.
T loadVariant;
ar(make_pointer_variant(loadVariant));
value = loadVariant;
}
template<typename Archive, typename VariantType>
static void load(Archive& ar, VariantType& variant)
{
// Delegate to the proper load_impl() overload depending on whether T is a
// pointer type. If T is not a pointer type, then we expect it to be a
// nested boost::variant.
load_impl(ar, variant, typename std::is_pointer<T>::type());
}
};
/**
* The objective of this class is to create a wrapper for
* boost::variant.
* Cereal supports the serialization of boost::variant, but
* we need to serialize it if it holds a raw pointers.
* This class depeds on the PointerWrapper we have already created in which it is
* used to serialize each variant independently
*/
template<typename... VariantTypes>
class PointerVariantWrapper
{
public:
PointerVariantWrapper(boost::variant<VariantTypes...>& pointerVar) :
pointerVariant(pointerVar)
{}
template<class Archive>
void save(Archive& ar) const
{
// which represents the index in std::variant.
int which = pointerVariant.which();
ar(CEREAL_NVP(which));
save_visitor<Archive> s(ar);
boost::apply_visitor(s, pointerVariant);
}
template<class Archive>
void load(Archive& ar)
{
// Load the size of the serialized type.
int which;
ar(CEREAL_NVP(which));
// Create function pointers to each overload of load_visitor<T>::load, for
// all T in VariantTypes.
using LoadFuncType = void(*)(Archive&, boost::variant<VariantTypes...>&);
LoadFuncType loadFuncArray[] = { &load_visitor<VariantTypes>::load... };
if (which >= int(sizeof(loadFuncArray)/sizeof(loadFuncArray[0])))
throw std::runtime_error("Invalid 'which' selector when"
"deserializing boost::variant");
loadFuncArray[which](ar, pointerVariant);
}
private:
boost::variant<VariantTypes...>& pointerVariant;
};
/**
* Cereal does not support the serialization of raw pointer.
* This macro enable developers to serialize boost::variant that holds raw
* pointers by using the above PointerVariantWrapper class which replace the
* internal raw pointers by smart pointer internally.
*
* @param T boost::variant that holds raw pointer to be serialized.
*/
#define CEREAL_VARIANT_POINTER(T) cereal::make_pointer_variant(T)
} // namespace cereal
#endif // CEREAL_POINTER_VARIANT_WRAPPER_HPP
@@ -0,0 +1,97 @@
/**
* @file core/cereal/pointer_vector_variant_wrapper.hpp
* @author Omar Shrit
*
* Implementation of a boost::variant wrapper to enable the serialization of
* the pointers inside boost variant in cereal
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP
#define MLPACK_CORE_CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP
#include "pointer_wrapper.hpp"
#include "pointer_variant_wrapper.hpp"
#include "pointer_vector_wrapper.hpp"
namespace cereal {
// Forward declaration
template<typename... VariantTypes>
class PointerVectorVariantWrapper;
/**
* Serialize a std::vector of boost variants in which the variant in each boost
* variant is a raw pointer.
* This wrapper will wrap each boost variant independently by encapsulating each
* boost variant into the PoninterVariantWrapper we have created already.
*
* @param t A reference to a vector of boost variants that holds raw pointer.
*/
template<typename... VariantTypes>
inline PointerVectorVariantWrapper<VariantTypes...>
make_vector_pointer_variant(std::vector<boost::variant<VariantTypes...>>& t)
{
return PointerVectorVariantWrapper<VariantTypes...>(t);
}
/**
* The objective of this class is to create a wrapper for
* a vector of boost::variant that holds pointer.
* Cereal supports the serialization of boost::variant, but
* we need to serialize it if it holds a vector of boost::variant that holds a
* pointers.
*/
template<typename... VariantTypes>
class PointerVectorVariantWrapper
{
public:
PointerVectorVariantWrapper(
std::vector<boost::variant<VariantTypes...>>& vecPointerVar)
: vectorPointerVariant(vecPointerVar)
{}
template<class Archive>
void save(Archive& ar) const
{
size_t vecSize = vectorPointerVariant.size();
ar(CEREAL_NVP(vecSize));
for (size_t i = 0; i < vectorPointerVariant.size(); ++i)
{
ar(CEREAL_VARIANT_POINTER(vectorPointerVariant.at(i)));
}
}
template<class Archive>
void load(Archive& ar)
{
size_t vecSize = 0;
ar(CEREAL_NVP(vecSize));
vectorPointerVariant.resize(vecSize);
for (size_t i = 0; i < vectorPointerVariant.size(); ++i)
{
ar(CEREAL_VARIANT_POINTER(vectorPointerVariant.at(i)));
}
}
private:
std::vector<boost::variant<VariantTypes...>>& vectorPointerVariant;
};
/**
* Cereal does not support the serialization of raw pointer.
* This macro enable developers to serialize a std vector that holds boost::variants
* that holds raw pointers by using the above PointerVectorVariantWrapper class
* which replace the internal raw pointers by smart pointer internally.
*
* @param T std::vector<boost::variant> that holds raw pointer to be serialized.
*/
#define CEREAL_VECTOR_VARIANT_POINTER(T) cereal::make_vector_pointer_variant(T)
} // namespace cereal
#endif // CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP
@@ -0,0 +1,97 @@
/**
* @file core/cereal/pointer_vector_wrapper.hpp
* @author Omar Shrit
*
* Implementation of a vector wrapper to enable the serialization of
* the size of the vector in cereal
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_CEREAL_POINTER_VECTOR_WRAPPER_HPP
#define MLPACK_CORE_CEREAL_POINTER_VECTOR_WRAPPER_HPP
#include <cereal/archives/json.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/types/vector.hpp>
#include "pointer_wrapper.hpp"
namespace cereal {
/**
* The objective of this class is to create a wrapper for
* std::vector that hold pointers by adding also the size of the vector.
* Cereal supports the serialization of the std vector, but
* we need to serialize the vector if it holds raw pointer.
* This wrapper uses the PointerWrapper we have already created, it serialize
* each pointer in the vector independently.
*
* We need to add the size of the vector if it holds a raw pointers, during the
* serialization, so we can know the size of the number pointer to allocated
* during the deserialization process.
*/
template<class T>
class PointerVectorWrapper
{
public:
PointerVectorWrapper(std::vector<T*>& pointerVec)
: pointerVector(pointerVec)
{}
template<class Archive>
void save(Archive& ar) const
{
size_t vecSize = pointerVector.size();
ar(CEREAL_NVP(vecSize));
for (size_t i = 0; i < pointerVector.size(); ++i)
{
ar(CEREAL_POINTER(pointerVector.at(i)));
}
}
template<class Archive>
void load(Archive& ar)
{
size_t vecSize = 0;
ar(CEREAL_NVP(vecSize));
pointerVector.resize(vecSize);
for (size_t i = 0; i < pointerVector.size(); ++i)
{
ar(CEREAL_POINTER(pointerVector.at(i)));
}
}
private:
std::vector<T*>& pointerVector;
};
/**
* Serialize an std::vector that holds raw pointer object by encapsulating them
* into a smart pointer.
*
* @param t A reference to std::vector that holds raw pointer to be serialized.
*/
template<class T>
inline PointerVectorWrapper<T>
make_pointer_vector(std::vector<T*>& t)
{
return PointerVectorWrapper<T>(t);
}
/**
* Cereal does not support the serialization of raw pointer.
* This macro enable developers to serialize std vectors that holds raw
* pointers by using the above PointerVectorWrapper class which replace the internal
* raw pointers by smart pointer internally.
*
* @param T std::vector that holds raw pointer to be serialized.
*/
#define CEREAL_VECTOR_POINTER(T) cereal::make_pointer_vector(T)
} // namespace cereal
#endif // CEREAL_POINTER_VECTOR_WRAPPER_HPP
+100
View File
@@ -0,0 +1,100 @@
/**
* @file core/cereal/pointer_wrapper.hpp
* @author Omar Shrit
*
* Implementation of a pointer wrapper to enable the serialization of
* raw pointers in cereal
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_CEREAL_POINTER_WRAPPER_HPP
#define MLPACK_CORE_CEREAL_POINTER_WRAPPER_HPP
#include <cereal/archives/binary.hpp>
#include <cereal/archives/json.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/types/memory.hpp>
#if __cplusplus <= 201103L && !defined(_MSC_VER)
namespace std {
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
} // namepace std
#endif
namespace cereal {
/**
* The objective of this class is to create a wrapper for
* raw pointer by encapsulating them in a smart pointer of type unique_ptr.
*
* Cereal does not support the serialization of raw pointer out of the box.
* Therefore, we have created this wrapper to serialize raw pointer in cereal
* as a smart pointer since because it will be difficult to change all pointer
* type in mlpack.
*/
template<class T>
class PointerWrapper
{
public:
PointerWrapper(T*& pointer)
: localPointer(pointer)
{}
template<class Archive>
void save(Archive& ar, const uint32_t /*version*/) const
{
std::unique_ptr<T> smartPointer;
if (this->localPointer != NULL)
smartPointer = std::unique_ptr<T>(localPointer);
ar(CEREAL_NVP(smartPointer));
localPointer = smartPointer.release();
}
template<class Archive>
void load(Archive& ar, const uint32_t /*version*/)
{
std::unique_ptr<T> smartPointer;
ar(CEREAL_NVP(smartPointer));
localPointer = smartPointer.release();
}
T*& release() { return localPointer; }
private:
T*& localPointer;
};
/**
* Serialize raw pointer object by encapsulating the pointer into a smart
* pointer.
*
* @param t A reference to raw pointer to be serialized.
*/
template<class T>
inline PointerWrapper<T>
make_pointer(T*& t)
{
return PointerWrapper<T>(t);
}
/**
* Cereal does not support the serialization of raw pointer.
* This macro enable developers to serialize a raw pointer by using the
* above PointerWrapper class which replace the raw pointer by a smart pointer
* internally.
*
* @param T Raw pointer to be serialized.
*/
#define CEREAL_POINTER(T) cereal::make_pointer(T)
} // namespace cereal
#endif // CEREAL_POINTER_WRAPPER_HPP
+45
View File
@@ -0,0 +1,45 @@
/**
* This file is backported from cereal 1.3 to support the serialization
* of objects of type associative containers (std::map, std::pair, etc.)
*
* This file add the support for serialization of containers for any
* version of cereal starting from 1.1.2 that is required by Ubuntu
* 16.04
*
*/
/*! \file unordered_map.hpp
\brief Support for types found in \<unordered_map\>
\ingroup STLSupport */
/*
Copyright (c) 2014, Randolph Voorhies, Shane Grant
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of cereal nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_TYPES_UNORDERED_MAP_HPP_
#define CEREAL_TYPES_UNORDERED_MAP_HPP_
#include "pair_associative_container.hpp"
#include <unordered_map>
#endif // CEREAL_TYPES_UNORDERED_MAP_HPP_
-1
View File
@@ -25,7 +25,6 @@ set(SOURCES
save.hpp
save_impl.hpp
save_image.cpp
serialization_template_version.hpp
split_data.hpp
imputer.hpp
binarize.hpp
+3 -3
View File
@@ -151,10 +151,10 @@ class DatasetMapper
* Serialize the dataset information.
*/
template<typename Archive>
void serialize(Archive& ar, const unsigned int /* version */)
void serialize(Archive& ar, const uint32_t /* version */)
{
ar & BOOST_SERIALIZATION_NVP(types);
ar & BOOST_SERIALIZATION_NVP(maps);
ar(CEREAL_NVP(types));
ar(CEREAL_NVP(maps));
}
//! Return the policy of the mapper.
+3 -3
View File
@@ -3,7 +3,7 @@
* @author Ryan Curtin
*
* Define the formats that can be used by mlpack's Load() and Save() mechanisms
* via boost::serialization.
* via cereal.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
@@ -16,11 +16,11 @@
namespace mlpack {
namespace data {
//! Define the formats we can read through boost::serialization.
//! Define the formats we can read through cereal.
enum format
{
autodetect,
text,
json,
xml,
binary
};
+8 -6
View File
@@ -14,8 +14,9 @@
#define MLPACK_CORE_UTIL_HAS_SERIALIZE_HPP
#include <mlpack/core/util/sfinae_utility.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/cereal.hpp>
#include <type_traits>
namespace mlpack {
@@ -31,11 +32,12 @@ template<typename T>
struct HasSerializeFunction
{
template<typename C>
using NonStaticSerialize = void(C::*)(boost::archive::xml_oarchive&,
const unsigned int);
using NonStaticSerialize = void(C::*)(cereal::XMLOutputArchive&,
const uint32_t version);
template<typename /* C */>
using StaticSerialize = void(*)(boost::archive::xml_oarchive&,
const unsigned int);
using StaticSerialize = void(*)(cereal::XMLOutputArchive&,
const uint32_t version);
static const bool value = HasSerializeCheck<T, NonStaticSerialize>::value ||
HasSerializeCheck<T, StaticSerialize>::value;
+101 -101
View File
@@ -1,102 +1,102 @@
/**
/**
* @file core/data/image_info.hpp
* @author Mehul Kumar Nirala
*
* An image information holder.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_DATA_IMAGE_INFO_HPP
#define MLPACK_CORE_DATA_IMAGE_INFO_HPP
#include <mlpack/prereqs.hpp>
#include "extension.hpp"
namespace mlpack {
namespace data {
/**
* Checks if the given image filename is supported.
*
* @param fileName Name of the image file.
* @param save Set to true to check if the file format can be saved, else loaded.
* @return Boolean value indicating success if it is an image.
*/
inline bool ImageFormatSupported(const std::string& fileName,
const bool save = false);
/**
* Implements meta-data of images required by data::Load and
* data::Save for loading and saving images into arma::Mat.
*/
class ImageInfo
{
public:
/**
* Instantiate the ImageInfo object with the given image width, height,
* number of channels and quality parameter.
*
* @param width Image width.
* @param height Image height.
* @param channels Number of channels in the image.
* @param quality Compression of the image if saved as jpg (0 - 100).
*/
ImageInfo(const size_t width = 0,
const size_t height = 0,
const size_t channels = 3,
const size_t quality = 90);
//! Get the image width.
const size_t& Width() const { return width; }
//! Modify the image width.
size_t& Width() { return width; }
//! Get the image height.
const size_t& Height() const { return height; }
//! Modify the image height.
size_t& Height() { return height; }
//! Get the image channels.
const size_t& Channels() const { return channels; }
//! Modify the image channels.
size_t& Channels() { return channels; }
//! Get the image quality.
const size_t& Quality() const { return quality; }
//! Modify the image quality.
size_t& Quality() { return quality; }
template<typename Archive>
void serialize(Archive& ar, const unsigned int /* version */)
{
ar & BOOST_SERIALIZATION_NVP(width);
ar & BOOST_SERIALIZATION_NVP(channels);
ar & BOOST_SERIALIZATION_NVP(height);
ar & BOOST_SERIALIZATION_NVP(quality);
}
private:
// To store the image width.
size_t width;
// To store the image height.
size_t height;
// To store the number of channels in the image.
size_t channels;
// Compression of the image if saved as jpg (0 - 100).
size_t quality;
};
} // namespace data
} // namespace mlpack
// Include implementation of Image.
#include "image_info_impl.hpp"
#endif
* @author Mehul Kumar Nirala
*
* An image information holder.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_DATA_IMAGE_INFO_HPP
#define MLPACK_CORE_DATA_IMAGE_INFO_HPP
#include <mlpack/prereqs.hpp>
#include "extension.hpp"
namespace mlpack {
namespace data {
/**
* Checks if the given image filename is supported.
*
* @param fileName Name of the image file.
* @param save Set to true to check if the file format can be saved, else loaded.
* @return Boolean value indicating success if it is an image.
*/
inline bool ImageFormatSupported(const std::string& fileName,
const bool save = false);
/**
* Implements meta-data of images required by data::Load and
* data::Save for loading and saving images into arma::Mat.
*/
class ImageInfo
{
public:
/**
* Instantiate the ImageInfo object with the given image width, height,
* number of channels and quality parameter.
*
* @param width Image width.
* @param height Image height.
* @param channels Number of channels in the image.
* @param quality Compression of the image if saved as jpg (0 - 100).
*/
ImageInfo(const size_t width = 0,
const size_t height = 0,
const size_t channels = 3,
const size_t quality = 90);
//! Get the image width.
const size_t& Width() const { return width; }
//! Modify the image width.
size_t& Width() { return width; }
//! Get the image height.
const size_t& Height() const { return height; }
//! Modify the image height.
size_t& Height() { return height; }
//! Get the image channels.
const size_t& Channels() const { return channels; }
//! Modify the image channels.
size_t& Channels() { return channels; }
//! Get the image quality.
const size_t& Quality() const { return quality; }
//! Modify the image quality.
size_t& Quality() { return quality; }
template<typename Archive>
void serialize(Archive& ar, const uint32_t /* version */)
{
ar(CEREAL_NVP(width));
ar(CEREAL_NVP(channels));
ar(CEREAL_NVP(height));
ar(CEREAL_NVP(quality));
}
private:
// To store the image width.
size_t width;
// To store the image height.
size_t height;
// To store the number of channels in the image.
size_t channels;
// Compression of the image if saved as jpg (0 - 100).
size_t quality;
};
} // namespace data
} // namespace mlpack
// Include implementation of Image.
#include "image_info_impl.hpp"
#endif
+4 -4
View File
@@ -34,7 +34,7 @@ namespace data /** Functions to load and save matrices and models. */ {
*
* - CSV (arma::csv_ascii), denoted by .csv, or optionally .txt
* - TSV (arma::raw_ascii), denoted by .tsv, .csv, or .txt
* - ASCII (arma::raw_ascii), denoted by .txt
* - ASCII (arma::raw_ascii), denoted by .json
* - Armadillo ASCII (arma::arma_ascii), also denoted by .txt
* - PGM (arma::pgm_binary), denoted by .pgm
* - PPM (arma::ppm_binary), denoted by .ppm
@@ -338,14 +338,14 @@ extern template bool Load<double, IncrementPolicy>(
* is used and the filetype cannot be determined, an error will be given.
*
* The supported types of files are the same as what is supported by the
* boost::serialization library:
* cereal library:
*
* - text, denoted by .txt
* - json, denoted by .json
* - xml, denoted by .xml
* - binary, denoted by .bin
*
* The format parameter can take any of the values in the 'format' enum:
* 'format::autodetect', 'format::text', 'format::xml', and 'format::binary'.
* 'format::autodetect', 'format::json', 'format::xml', and 'format::binary'.
* The autodetect functionality operates on the file extension (so, "file.txt"
* would be autodetected as text).
*
+15 -16
View File
@@ -20,13 +20,13 @@
#include "extension.hpp"
#include <boost/serialization/serialization.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/binary.hpp>
#include <cereal/archives/json.hpp>
namespace mlpack {
namespace data {
@@ -47,8 +47,8 @@ bool Load(const std::string& filename,
f = format::xml;
else if (extension == "bin")
f = format::binary;
else if (extension == "txt")
f = format::text;
else if (extension == "json")
f = format::json;
else
{
if (fatal)
@@ -84,28 +84,27 @@ bool Load(const std::string& filename,
return false;
}
try
{
if (f == format::xml)
{
boost::archive::xml_iarchive ar(ifs);
ar >> boost::serialization::make_nvp(name.c_str(), t);
cereal::XMLInputArchive ar(ifs);
ar(cereal::make_nvp(name.c_str(), t));
}
else if (f == format::text)
else if (f == format::json)
{
boost::archive::text_iarchive ar(ifs);
ar >> boost::serialization::make_nvp(name.c_str(), t);
cereal::JSONInputArchive ar(ifs);
ar(cereal::make_nvp(name.c_str(), t));
}
else if (f == format::binary)
{
boost::archive::binary_iarchive ar(ifs);
ar >> boost::serialization::make_nvp(name.c_str(), t);
cereal::BinaryInputArchive ar(ifs);
ar(cereal::make_nvp(name.c_str(), t));
}
return true;
}
catch (boost::archive::archive_exception& e)
catch (cereal::Exception& e)
{
if (fatal)
Log::Fatal << e.what() << std::endl;

Some files were not shown because too many files have changed in this diff Show More