From 8bb8ea1bad84b3fcc6ae6e22c3970e4c5b44ad39 Mon Sep 17 00:00:00 2001 From: Utkarsh Rai Date: Sat, 3 Oct 2020 01:22:46 +0530 Subject: [PATCH 01/19] Added Weight Size to concat and fast_lstm layers and renamed parameters to weights in dropconnect. --- src/mlpack/methods/ann/layer/concat.hpp | 14 ++++++++++---- src/mlpack/methods/ann/layer/concat_impl.hpp | 4 ++-- src/mlpack/methods/ann/layer/dropconnect.hpp | 6 +++--- src/mlpack/methods/ann/layer/fast_lstm.hpp | 6 ++++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/mlpack/methods/ann/layer/concat.hpp b/src/mlpack/methods/ann/layer/concat.hpp index 30bfe4f3b5..bb0d733651 100644 --- a/src/mlpack/methods/ann/layer/concat.hpp +++ b/src/mlpack/methods/ann/layer/concat.hpp @@ -165,9 +165,9 @@ class Concat } //! Return the initial point for the optimization. - const arma::mat& Parameters() const { return parameters; } + const arma::mat& Parameters() const { return weights; } //! Modify the initial point for the optimization. - arma::mat& Parameters() { return parameters; } + arma::mat& Parameters() { return weights; } //! Get the value of run parameter. bool Run() const { return run; } @@ -196,6 +196,12 @@ class Concat //! Get the axis of concatenation. size_t const& ConcatAxis() const { return axis; } + //! Get the size of the weight matrix. + size_t WeightSize() const + { + return 0; + } + /** * Serialize the layer */ @@ -225,8 +231,8 @@ class Concat //! Locally-stored network modules. std::vector > network; - //! Locally-stored model parameters. - arma::mat parameters; + //! Locally-stored model weights. + OutputDataType weights; //! Locally-stored delta visitor. DeltaVisitor deltaVisitor; diff --git a/src/mlpack/methods/ann/layer/concat_impl.hpp b/src/mlpack/methods/ann/layer/concat_impl.hpp index a75fea8697..62de73a74e 100644 --- a/src/mlpack/methods/ann/layer/concat_impl.hpp +++ b/src/mlpack/methods/ann/layer/concat_impl.hpp @@ -33,7 +33,7 @@ Concat::Concat( run(run), channels(1) { - parameters.set_size(0, 0); + weights.set_size(0, 0); } template::Concat( model(model), run(run) { - parameters.set_size(0, 0); + weights.set_size(0, 0); // Parameters to help calculate the number of channels. size_t oldColSize = 1, newColSize = 1; diff --git a/src/mlpack/methods/ann/layer/dropconnect.hpp b/src/mlpack/methods/ann/layer/dropconnect.hpp index a1411845a4..cf96d6237f 100644 --- a/src/mlpack/methods/ann/layer/dropconnect.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect.hpp @@ -115,9 +115,9 @@ class DropConnect std::vector >& Model() { return network; } //! Get the parameters. - OutputDataType const& Parameters() const { return parameters; } + OutputDataType const& Parameters() const { return weights; } //! Modify the parameters. - OutputDataType& Parameters() { return parameters; } + OutputDataType& Parameters() { return weights; } //! Get the output parameter. OutputDataType const& OutputParameter() const { return outputParameter; } @@ -164,7 +164,7 @@ class DropConnect double scale; //! Locally-stored weight object. - OutputDataType parameters; + OutputDataType weights; //! Locally-stored delta object. OutputDataType delta; diff --git a/src/mlpack/methods/ann/layer/fast_lstm.hpp b/src/mlpack/methods/ann/layer/fast_lstm.hpp index b934c0c5ea..eb5d2ef855 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm.hpp @@ -164,6 +164,12 @@ class FastLSTM //! Get the number of output units. size_t OutSize() const { return outSize; } + //! Get the size of the weight matrix. + size_t WeightSize() const + { + return 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize; + } + /** * Serialize the layer */ From 7ef7ec02a5faaca5452d7df2a05cb769fcb0d24e Mon Sep 17 00:00:00 2001 From: Utkarsh Rai Date: Fri, 9 Oct 2020 10:53:12 +0530 Subject: [PATCH 02/19] Replaced the expression with WeightSize().) Added tests. --- src/mlpack/methods/ann/layer/add_impl.hpp | 2 +- .../ann/layer/atrous_convolution_impl.hpp | 3 +- src/mlpack/methods/ann/layer/concat.hpp | 5 +- .../methods/ann/layer/fast_lstm_impl.hpp | 3 +- src/mlpack/methods/ann/layer/linear_impl.hpp | 2 +- src/mlpack/tests/ann_visitor_test.cpp | 75 +++++++++++++++++-- 6 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/mlpack/methods/ann/layer/add_impl.hpp b/src/mlpack/methods/ann/layer/add_impl.hpp index 79f2a4386f..4fc8f42d0b 100644 --- a/src/mlpack/methods/ann/layer/add_impl.hpp +++ b/src/mlpack/methods/ann/layer/add_impl.hpp @@ -23,7 +23,7 @@ template Add::Add(const size_t outSize) : outSize(outSize) { - weights.set_size(outSize, 1); + weights.set_size(WeightSize(), 1); } template diff --git a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp index 3536690037..7d6534a18e 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp @@ -122,8 +122,7 @@ AtrousConvolution< dilationWidth(dilationWidth), dilationHeight(dilationHeight) { - weights.set_size((outSize * inSize * kernelWidth * kernelHeight) + outSize, - 1); + weights.set_size(WeightSize(), 1); // Transform paddingType to lowercase. std::string paddingTypeLow = paddingType; diff --git a/src/mlpack/methods/ann/layer/concat.hpp b/src/mlpack/methods/ann/layer/concat.hpp index bb0d733651..c6e5937167 100644 --- a/src/mlpack/methods/ann/layer/concat.hpp +++ b/src/mlpack/methods/ann/layer/concat.hpp @@ -197,10 +197,7 @@ class Concat size_t const& ConcatAxis() const { return axis; } //! Get the size of the weight matrix. - size_t WeightSize() const - { - return 0; - } + size_t WeightSize() const { return 0; } /** * Serialize the layer diff --git a/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp b/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp index 24b3544fd1..b350a704b3 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp @@ -42,8 +42,7 @@ FastLSTM::FastLSTM( { // Weights for: input to gate layer (4 * outsize * inSize + 4 * outsize) // and output to gate (4 * outSize). - weights.set_size( - 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize, 1); + weights.set_size(WeightSize(), 1); } template diff --git a/src/mlpack/methods/ann/layer/linear_impl.hpp b/src/mlpack/methods/ann/layer/linear_impl.hpp index 79799fea98..875147f7b7 100644 --- a/src/mlpack/methods/ann/layer/linear_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear_impl.hpp @@ -38,7 +38,7 @@ Linear::Linear( outSize(outSize), regularizer(regularizer) { - weights.set_size(outSize * inSize + outSize, 1); + weights.set_size(WeightSize(), 1); } template linear = new Linear<>(randomSize, randomSize); + LayerTypes<> linearLayer = new Linear<>(randomInSize, randomOutSize); - size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), - linear); + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), linearLayer); - REQUIRE(weightSize == randomSize * randomSize + randomSize); + REQUIRE(weightSize == randomInSize * randomOutSize + randomOutSize); } +/** + * Test that WeightSizeVisitor works properly for concat layer. + */ +TEST_CASE("WeightSizeVisitorTestForConcatLayer", "[ANNVisitorTest]") +{ + LayerTypes<> concatLayer = new Concat<>(); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), concatLayer); + + REQUIRE(weightSize == 0); +} + +/** + * Test that WeightSizeVisitor works properly for fast lstm layer. + */ +TEST_CASE("WeightSizeVisitorTestForFastLSTMLayer", "[ANNVisitorTest]") +{ + size_t randomInSize = arma::randi(arma::distr_param(1, 100)); + size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> fastLSTMLayer = new FastLSTM<>(randomInSize, randomOutSize); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), fastLSTMLayer); + + REQUIRE(weightSize == 4 * randomInSize * randomOutSize + 4 * randomOutSize + + 4 * randomOutSize * randomOutSize); +} + +/** + * Test that WeightSizeVisitor works properly for Add layer. + */ +TEST_CASE("WeightSizeVisitorTestForAddLayer", "[ANNVisitorTest]") +{ + size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> addLayer = new Add<>(randomOutSize); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), addLayer); + + REQUIRE(weightSize == randomOutSize); +} + +/** + * Test that WeightSizeVisitor works properly for Atrous Convolution Layer. + */ +TEST_CASE("WeightSizeVisitorTestForAtrousConvolutionLayer", "[ANNVisitorTest]") +{ + size_t randomInSize = arma::randi(arma::distr_param(1, 100)); + size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); + size_t randomKernelWidth = arma::randi(arma::distr_param(1, 100)); + size_t randomKernelHeight = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> atrousConvLayer = new AtrousConvolution<>(randomInSize, randomOutSize, + randomKernelWidth, randomKernelHeight); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), + atrousConvLayer); + + REQUIRE(weightSize == randomOutSize * randomInSize * randomKernelWidth + * randomKernelHeight + randomOutSize); +} From 8f9685a06a81f60fd0c11964af33e1641e05d126 Mon Sep 17 00:00:00 2001 From: Utkarsh Rai Date: Mon, 12 Oct 2020 10:35:14 +0530 Subject: [PATCH 03/19] WeightSize() for dropconnect. --- src/mlpack/methods/ann/layer/dropconnect.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mlpack/methods/ann/layer/dropconnect.hpp b/src/mlpack/methods/ann/layer/dropconnect.hpp index cf96d6237f..2b07cfed8f 100644 --- a/src/mlpack/methods/ann/layer/dropconnect.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect.hpp @@ -150,6 +150,9 @@ class DropConnect scale = 1.0 / (1.0 - ratio); } + //! Return the size of the weight matrix. + size_t WeightSize() const { return 0; } + /** * Serialize the layer. */ From 8b3b5522494e9de1f4b01613c0351ef928ecebf5 Mon Sep 17 00:00:00 2001 From: Utkarsh Rai Date: Tue, 13 Oct 2020 12:26:10 +0530 Subject: [PATCH 04/19] Indentation fix. --- src/mlpack/tests/ann_visitor_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/ann_visitor_test.cpp b/src/mlpack/tests/ann_visitor_test.cpp index 3849e85740..b8690e6bd6 100644 --- a/src/mlpack/tests/ann_visitor_test.cpp +++ b/src/mlpack/tests/ann_visitor_test.cpp @@ -142,7 +142,7 @@ TEST_CASE("WeightSizeVisitorTestForAtrousConvolutionLayer", "[ANNVisitorTest]") randomKernelWidth, randomKernelHeight); size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), - atrousConvLayer); + atrousConvLayer); REQUIRE(weightSize == randomOutSize * randomInSize * randomKernelWidth * randomKernelHeight + randomOutSize); From 3fafb5c390e7baa9119c10a11f0e1a493989ade0 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 1 Nov 2020 11:28:14 +0530 Subject: [PATCH 05/19] Scheduled cron GH-action workflow for updating headers. --- .github/workflows/update-header.yaml | 87 ++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/update-header.yaml diff --git a/.github/workflows/update-header.yaml b/.github/workflows/update-header.yaml new file mode 100644 index 0000000000..4ead6209c5 --- /dev/null +++ b/.github/workflows/update-header.yaml @@ -0,0 +1,87 @@ +name: Update Header Dependencies +on: + workflow_dispatch: + schedule: + - cron: '0 10 1/16 * *' +jobs: + updateHeader: + 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.\d') + # Set the current release tag + echo ::set-output name=current_tag::$(echo $CLI11_VERSION_VALUE) + + - 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 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: 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 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][1] to ${{ steps.cli11-header.outputs.release_tag }}. + Auto-generated by [create-pull-request][2] + [1]: https://github.com/CLIUtils/CLI11 + [2]: https://github.com/peter-evans/create-pull-request + labels: update headers deps, automated pr + branch: cli11-header-updates-${{ steps.cli11-header.outputs.release_tag }} + + - 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][1] to ${{ steps.catch-header.outputs.release_tag }}. + Auto-generated by [create-pull-request][2] + [1]: https://github.com/catchorg/Catch2 + [2]: https://github.com/peter-evans/create-pull-request + labels: update headers deps, automated pr + branch: catch-header-updates-${{ steps.catch-header.outputs.release_tag }} From f66db05652557ada872ac65e2d4be00cb3300f41 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 1 Nov 2020 11:30:23 +0530 Subject: [PATCH 06/19] Test with PR will revert this. --- .github/workflows/update-header.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/update-header.yaml b/.github/workflows/update-header.yaml index 4ead6209c5..8e7a71a548 100644 --- a/.github/workflows/update-header.yaml +++ b/.github/workflows/update-header.yaml @@ -1,5 +1,6 @@ name: Update Header Dependencies on: + pull_request: workflow_dispatch: schedule: - cron: '0 10 1/16 * *' From 6374d5ab3c9f0d4c34d229c8d049570de0fe3a6b Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 1 Nov 2020 11:44:44 +0530 Subject: [PATCH 07/19] One more try. --- .github/workflows/update-header.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/update-header.yaml b/.github/workflows/update-header.yaml index 8e7a71a548..55783c29bd 100644 --- a/.github/workflows/update-header.yaml +++ b/.github/workflows/update-header.yaml @@ -9,6 +9,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} - name: Get Latest CLI11 Tagged Release id: cli11-header run: | From a94772ffaeaa3ba465810163665e762e03388538 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 1 Nov 2020 12:05:14 +0530 Subject: [PATCH 08/19] Split files. --- .github/workflows/update-cli11.yaml | 49 +++++++++++++++ .github/workflows/update-header.yaml | 90 ---------------------------- 2 files changed, 49 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/update-cli11.yaml delete mode 100644 .github/workflows/update-header.yaml diff --git a/.github/workflows/update-cli11.yaml b/.github/workflows/update-cli11.yaml new file mode 100644 index 0000000000..f738cb8857 --- /dev/null +++ b/.github/workflows/update-cli11.yaml @@ -0,0 +1,49 @@ +name: Update CLI11 +on: + pull_request: + workflow_dispatch: + schedule: + - cron: '0 10 1/16 * *' +jobs: + updateCLI11: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + - 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.\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][1] to ${{ steps.cli11-header.outputs.release_tag }}. + Auto-generated by [create-pull-request][2] + [1]: https://github.com/CLIUtils/CLI11 + [2]: https://github.com/peter-evans/create-pull-request + labels: update headers deps, automated pr + branch: cli11-header-updates-${{ steps.cli11-header.outputs.release_tag }} diff --git a/.github/workflows/update-header.yaml b/.github/workflows/update-header.yaml deleted file mode 100644 index 55783c29bd..0000000000 --- a/.github/workflows/update-header.yaml +++ /dev/null @@ -1,90 +0,0 @@ -name: Update Header Dependencies -on: - pull_request: - workflow_dispatch: - schedule: - - cron: '0 10 1/16 * *' -jobs: - updateHeader: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - 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.\d') - # Set the current release tag - echo ::set-output name=current_tag::$(echo $CLI11_VERSION_VALUE) - - - 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 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: 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 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][1] to ${{ steps.cli11-header.outputs.release_tag }}. - Auto-generated by [create-pull-request][2] - [1]: https://github.com/CLIUtils/CLI11 - [2]: https://github.com/peter-evans/create-pull-request - labels: update headers deps, automated pr - branch: cli11-header-updates-${{ steps.cli11-header.outputs.release_tag }} - - - 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][1] to ${{ steps.catch-header.outputs.release_tag }}. - Auto-generated by [create-pull-request][2] - [1]: https://github.com/catchorg/Catch2 - [2]: https://github.com/peter-evans/create-pull-request - labels: update headers deps, automated pr - branch: catch-header-updates-${{ steps.catch-header.outputs.release_tag }} From 4f9e7dc4af726adff6dbd7ad6d5372458615948c Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 1 Nov 2020 12:08:54 +0530 Subject: [PATCH 09/19] Now add catch. --- .github/workflows/update-catch.yaml | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/update-catch.yaml diff --git a/.github/workflows/update-catch.yaml b/.github/workflows/update-catch.yaml new file mode 100644 index 0000000000..6356b95044 --- /dev/null +++ b/.github/workflows/update-catch.yaml @@ -0,0 +1,53 @@ +name: Update Catch +on: + pull_request: + workflow_dispatch: + schedule: + - cron: '0 10 1/16 * *' +jobs: + updateCatch: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + - 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][1] to ${{ steps.catch-header.outputs.release_tag }}. + Auto-generated by [create-pull-request][2] + [1]: https://github.com/catchorg/Catch2 + [2]: https://github.com/peter-evans/create-pull-request + labels: update headers deps, automated pr + branch: catch-header-updates-${{ steps.catch-header.outputs.release_tag }} From 1ffe2780d0efa3a2bb63b2c0b3934fcd03abe3ac Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 1 Nov 2020 17:23:48 +0530 Subject: [PATCH 10/19] This workflow doesn't require for PR. --- .github/workflows/update-catch.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/update-catch.yaml b/.github/workflows/update-catch.yaml index 6356b95044..6ae6be1b75 100644 --- a/.github/workflows/update-catch.yaml +++ b/.github/workflows/update-catch.yaml @@ -1,6 +1,5 @@ name: Update Catch on: - pull_request: workflow_dispatch: schedule: - cron: '0 10 1/16 * *' @@ -9,8 +8,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - name: Get Latest Catch Tagged Release id: catch-header run: | @@ -45,9 +42,7 @@ jobs: 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][1] to ${{ steps.catch-header.outputs.release_tag }}. - Auto-generated by [create-pull-request][2] - [1]: https://github.com/catchorg/Catch2 - [2]: https://github.com/peter-evans/create-pull-request - labels: update headers deps, automated pr + 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 }} From 9586712f2dfe408c90fbeb7aacef1caf9c8ff75c Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 1 Nov 2020 17:23:51 +0530 Subject: [PATCH 11/19] This workflow doesn't require for PR. --- .github/workflows/update-cli11.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/update-cli11.yaml b/.github/workflows/update-cli11.yaml index f738cb8857..1b5ad88cc2 100644 --- a/.github/workflows/update-cli11.yaml +++ b/.github/workflows/update-cli11.yaml @@ -1,6 +1,5 @@ name: Update CLI11 on: - pull_request: workflow_dispatch: schedule: - cron: '0 10 1/16 * *' @@ -9,8 +8,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - name: Get Latest CLI11 Tagged Release id: cli11-header run: | @@ -41,9 +38,7 @@ jobs: 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][1] to ${{ steps.cli11-header.outputs.release_tag }}. - Auto-generated by [create-pull-request][2] - [1]: https://github.com/CLIUtils/CLI11 - [2]: https://github.com/peter-evans/create-pull-request - labels: update headers deps, automated pr + 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 }} From 71555f2946638ce6c45ea448ba50b0f4b12b43d6 Mon Sep 17 00:00:00 2001 From: Marcus Edel Date: Sun, 1 Nov 2020 13:45:17 +0100 Subject: [PATCH 12/19] Style fixes (line length, whitespace/end_of_line, whitespace comments). --- src/mlpack/bindings/markdown/print_docs.cpp | 2 +- src/mlpack/core/cereal/array_wrapper.hpp | 4 +- src/mlpack/core/cereal/is_loading.hpp | 15 +++---- src/mlpack/core/cereal/is_saving.hpp | 15 +++---- src/mlpack/core/data/has_serialize.hpp | 7 +++- src/mlpack/core/metrics/bleu_impl.hpp | 2 +- .../binary_space_tree_impl.hpp | 2 +- src/mlpack/methods/ann/layer/fast_lstm.hpp | 2 +- src/mlpack/methods/ann/layer/linear_impl.hpp | 4 +- src/mlpack/methods/ann/layer/softmin_impl.hpp | 4 +- .../mean_absolute_percentage_error_impl.hpp | 4 +- .../bayesian_linear_regression_impl.hpp | 3 +- src/mlpack/methods/hmm/hmm_util_impl.hpp | 17 ++++++-- .../tests/activation_functions_test.cpp | 2 +- src/mlpack/tests/ann_visitor_test.cpp | 8 ++-- src/mlpack/tests/distribution_test.cpp | 3 +- src/mlpack/tests/hoeffding_tree_test.cpp | 30 ++++++++----- src/mlpack/tests/io_test.cpp | 3 +- src/mlpack/tests/lin_alg_test.cpp | 1 - src/mlpack/tests/loss_functions_test.cpp | 10 +++-- src/mlpack/tests/nbc_test.cpp | 2 +- src/mlpack/tests/pca_test.cpp | 3 +- src/mlpack/tests/range_search_test.cpp | 42 ++++++++++++------- src/mlpack/tests/rl_components_test.cpp | 3 +- src/mlpack/tests/sort_policy_test.cpp | 4 +- src/mlpack/tests/string_encoding_test.cpp | 40 +++++++++++------- 26 files changed, 144 insertions(+), 88 deletions(-) diff --git a/src/mlpack/bindings/markdown/print_docs.cpp b/src/mlpack/bindings/markdown/print_docs.cpp index 10805e8209..45b9807afa 100644 --- a/src/mlpack/bindings/markdown/print_docs.cpp +++ b/src/mlpack/bindings/markdown/print_docs.cpp @@ -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; diff --git a/src/mlpack/core/cereal/array_wrapper.hpp b/src/mlpack/core/cereal/array_wrapper.hpp index 05a675277f..c696f5b727 100644 --- a/src/mlpack/core/cereal/array_wrapper.hpp +++ b/src/mlpack/core/cereal/array_wrapper.hpp @@ -21,7 +21,7 @@ namespace cereal { -/** +/** * This class is used as a shim for cereal to be able to serialize a raw pointer array. */ template @@ -84,7 +84,7 @@ ArrayWrapper make_array(T*& t, S& s) * @param T C Style array. * @param S Size of the array. */ -#define CEREAL_POINTER_ARRAY(T,S) cereal::make_array(T, S) +#define CEREAL_POINTER_ARRAY(T, S) cereal::make_array(T, S) } // namespace cereal diff --git a/src/mlpack/core/cereal/is_loading.hpp b/src/mlpack/core/cereal/is_loading.hpp index d075c3d303..085358b2f4 100644 --- a/src/mlpack/core/cereal/is_loading.hpp +++ b/src/mlpack/core/cereal/is_loading.hpp @@ -5,7 +5,7 @@ * Implementation of is_loading function. * * This implementation provides backward compatibilty with older - * version of cereal that does not have Archive::is_loading struct. + * 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 @@ -28,11 +28,12 @@ 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::value || -//#if (BINDING_TYPE != BINDING_TYPE_R) - std::is_same::value || -//#endif - std::is_same::value; + constexpr static bool value = std::is_same::value || +// #if (BINDING_TYPE != BINDING_TYPE_R) + std::is_same::value || +// #endif + std::is_same::value; }; template @@ -40,7 +41,7 @@ bool is_loading( const typename std::enable_if< is_cereal_archive::value, Archive>::type* = 0) { - return true; + return true; } template diff --git a/src/mlpack/core/cereal/is_saving.hpp b/src/mlpack/core/cereal/is_saving.hpp index 147668853f..e54362913f 100644 --- a/src/mlpack/core/cereal/is_saving.hpp +++ b/src/mlpack/core/cereal/is_saving.hpp @@ -6,7 +6,7 @@ * Implementation of is_saving function. * * This implementation provides backward compatibilty with older - * version of cereal that does not have Archive::is_saving struct. + * 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 @@ -29,11 +29,12 @@ 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::value || -//#if (BINDING_TYPE != BINDING_TYPE_R) - std::is_same::value || -//#endif - std::is_same::value; + constexpr static bool value = std::is_same::value || +// #if (BINDING_TYPE != BINDING_TYPE_R) + std::is_same::value || +// #endif + std::is_same::value; }; template @@ -41,7 +42,7 @@ bool is_saving( const typename std::enable_if< is_cereal_archive_saving::value, Archive>::type* = 0) { - return true; + return true; } template diff --git a/src/mlpack/core/data/has_serialize.hpp b/src/mlpack/core/data/has_serialize.hpp index 0c3b92c73b..7c2c3d114a 100644 --- a/src/mlpack/core/data/has_serialize.hpp +++ b/src/mlpack/core/data/has_serialize.hpp @@ -32,9 +32,12 @@ template struct HasSerializeFunction { template - using NonStaticSerialize = void(C::*)(cereal::XMLOutputArchive&, const uint32_t version); + using NonStaticSerialize = void(C::*)(cereal::XMLOutputArchive&, + const uint32_t version); + template - using StaticSerialize = void(*)(cereal::XMLOutputArchive&, const uint32_t version); + using StaticSerialize = void(*)(cereal::XMLOutputArchive&, + const uint32_t version); static const bool value = HasSerializeCheck::value || HasSerializeCheck::value; diff --git a/src/mlpack/core/metrics/bleu_impl.hpp b/src/mlpack/core/metrics/bleu_impl.hpp index 66fdd626a5..38e9b29437 100644 --- a/src/mlpack/core/metrics/bleu_impl.hpp +++ b/src/mlpack/core/metrics/bleu_impl.hpp @@ -187,7 +187,7 @@ ElemType BLEU::Evaluate( template template -void BLEU::serialize(Archive& ar, +void BLEU::serialize(Archive& ar, const uint32_t version) { ar(CEREAL_NVP(maxOrder)); diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp index cc1b86be18..6e2a934004 100644 --- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp @@ -1131,7 +1131,7 @@ void BinarySpaceTree:: if (node->left) stack.push(node->left); if (node->right) - stack.push(node->right); + stack.push(node->right); } } } diff --git a/src/mlpack/methods/ann/layer/fast_lstm.hpp b/src/mlpack/methods/ann/layer/fast_lstm.hpp index 957c64e670..121c97e176 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm.hpp @@ -165,7 +165,7 @@ class FastLSTM size_t OutSize() const { return outSize; } //! Get the size of the weight matrix. - size_t WeightSize() const + size_t WeightSize() const { return 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize; } diff --git a/src/mlpack/methods/ann/layer/linear_impl.hpp b/src/mlpack/methods/ann/layer/linear_impl.hpp index 183597d4a7..2edfb4802c 100644 --- a/src/mlpack/methods/ann/layer/linear_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear_impl.hpp @@ -70,7 +70,7 @@ template& Linear:: operator=(const Linear& layer) -{ +{ if (this != &layer) { inSize = layer.inSize; @@ -86,7 +86,7 @@ template& Linear:: operator=(Linear&& layer) -{ +{ if (this != &layer) { inSize = layer.inSize; diff --git a/src/mlpack/methods/ann/layer/softmin_impl.hpp b/src/mlpack/methods/ann/layer/softmin_impl.hpp index e2389f5856..6945256b44 100644 --- a/src/mlpack/methods/ann/layer/softmin_impl.hpp +++ b/src/mlpack/methods/ann/layer/softmin_impl.hpp @@ -29,7 +29,7 @@ template void Softmin::Forward( const InputType& input, OutputType& output) -{ +{ InputType softminInput = arma::exp(-(input.each_row() - arma::min(input, 0))); output = softminInput.each_row() / sum(softminInput, 0); @@ -53,7 +53,7 @@ void Softmin::serialize( { // Nothing to do here. } - + } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp index c17badf733..82f054e2b9 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp @@ -32,7 +32,7 @@ MeanAbsolutePercentageError::Forward( const InputType& input, const TargetType& target) { - InputType loss = arma::abs((input - target) / target); + InputType loss = arma::abs((input - target) / target); return arma::accu(loss) * (100 / target.n_cols); } @@ -43,7 +43,7 @@ void MeanAbsolutePercentageError::Backward( const TargetType& target, OutputType& output) -{ +{ output = (((arma::conv_to::from(input < target) * -2) + 1) / target) * (100 / target.n_cols) ; } diff --git a/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp b/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp index 8842cc82e5..d0881dd06a 100644 --- a/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp +++ b/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp @@ -21,7 +21,8 @@ namespace regression { * Serialize the Bayesian linear regression model. */ template -void BayesianLinearRegression::serialize(Archive& ar, const uint32_t /* version */) +void BayesianLinearRegression::serialize(Archive& ar, + const uint32_t /* version */) { ar(CEREAL_NVP(centerData)); ar(CEREAL_NVP(scaleData)); diff --git a/src/mlpack/methods/hmm/hmm_util_impl.hpp b/src/mlpack/methods/hmm/hmm_util_impl.hpp index 24ee4adc6b..017cc65bcd 100644 --- a/src/mlpack/methods/hmm/hmm_util_impl.hpp +++ b/src/mlpack/methods/hmm/hmm_util_impl.hpp @@ -41,14 +41,25 @@ void LoadHMMAndPerformAction(const std::string& modelFile, { const std::string extension = data::Extension(modelFile); if (extension == "xml") - LoadHMMAndPerformActionHelper(modelFile, x); + { + LoadHMMAndPerformActionHelper( + modelFile, x); + } else if (extension == "bin") - LoadHMMAndPerformActionHelper(modelFile, x); + { + LoadHMMAndPerformActionHelper( + modelFile, x); + } else if (extension == "json") - LoadHMMAndPerformActionHelper(modelFile, x); + { + LoadHMMAndPerformActionHelper( + modelFile, x); + } else + { Log::Fatal << "Unknown extension '" << extension << "' for HMM model file " << "(known: 'xml', 'json', 'bin')." << std::endl; + } } template concatLayer = new Concat<>(); - + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), concatLayer); CheckCorrectnessOfWeightSize(concatLayer); @@ -151,12 +151,12 @@ TEST_CASE("WeightSizeVisitorTestForAtrousConvolutionLayer", "[ANNVisitorTest]") size_t randomKernelWidth = arma::randi(arma::distr_param(1, 100)); size_t randomKernelHeight = arma::randi(arma::distr_param(1, 100)); - LayerTypes<> atrousConvLayer = new AtrousConvolution<>(randomInSize, randomOutSize, - randomKernelWidth, randomKernelHeight); + LayerTypes<> atrousConvLayer = new AtrousConvolution<>(randomInSize, + randomOutSize, randomKernelWidth, randomKernelHeight); size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), atrousConvLayer); - + CheckCorrectnessOfWeightSize(atrousConvLayer); } diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 0ec7fd3cb6..7346098d43 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -1518,7 +1518,8 @@ TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") * the weighted mean and covariance reduce to the unweighted sample mean and * covariance. */ -TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest]") +TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", + "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); diff --git a/src/mlpack/tests/hoeffding_tree_test.cpp b/src/mlpack/tests/hoeffding_tree_test.cpp index 8787dfe28f..49c60b0cea 100644 --- a/src/mlpack/tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/hoeffding_tree_test.cpp @@ -173,7 +173,8 @@ TEST_CASE("HoeffdingInformationGainBadSplitTest", "[HoeffdingTreeTest]") counts(1, 0) = 5; counts(1, 1) = 5; - REQUIRE(HoeffdingInformationGain::Evaluate(counts) == Approx(0.0).margin(1e-10)); + REQUIRE(HoeffdingInformationGain::Evaluate(counts) == + Approx(0.0).margin(1e-10)); } /** @@ -216,7 +217,8 @@ TEST_CASE("HoeffdingInformationGainZeroTest", "[HoeffdingTreeTest]") // When nothing has been seen, the information gain should be zero. arma::Mat counts = arma::zeros>(10, 10); - REQUIRE(HoeffdingInformationGain::Evaluate(counts) == Approx(0.0).margin(1e-10)); + REQUIRE(HoeffdingInformationGain::Evaluate(counts) == + Approx(0.0).margin(1e-10)); } /** @@ -225,14 +227,22 @@ TEST_CASE("HoeffdingInformationGainZeroTest", "[HoeffdingTreeTest]") */ TEST_CASE("HoeffdingInformationGainRangeTest", "[HoeffdingTreeTest]") { - REQUIRE(HoeffdingInformationGain::Range(1) == Approx(0).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(2) == Approx(1.0).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(3) == Approx(1.5849625).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(4) == Approx(2).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(5) == Approx(2.32192809).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(10) == Approx(3.32192809).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(100) == Approx(6.64385619).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(1000) == Approx(9.96578428).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(1) == + Approx(0).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(2) == + Approx(1.0).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(3) == + Approx(1.5849625).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(4) == + Approx(2).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(5) == + Approx(2.32192809).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(10) == + Approx(3.32192809).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(100) == + Approx(6.64385619).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(1000) == + Approx(9.96578428).epsilon(1e-7)); } /** diff --git a/src/mlpack/tests/io_test.cpp b/src/mlpack/tests/io_test.cpp index d09b7e97a0..fa363face9 100644 --- a/src/mlpack/tests/io_test.cpp +++ b/src/mlpack/tests/io_test.cpp @@ -795,7 +795,8 @@ TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixParamTest", remove("test.csv"); } -TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixNoTransposeParamTest", "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixNoTransposeParamTest", + "[IOTest]") { AddRequiredCLIOptions(); diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index 7454564c20..a43821d75d 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -190,7 +190,6 @@ TEST_CASE("TestSvecSmat", "[LinAlgTest]") for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) REQUIRE(X(i, j) == Approx(Xtest(i, j)).epsilon(1e-9)); - } TEST_CASE("TestSparseSvec", "[LinAlgTest]") diff --git a/src/mlpack/tests/loss_functions_test.cpp b/src/mlpack/tests/loss_functions_test.cpp index cb814d021e..54b9945c66 100644 --- a/src/mlpack/tests/loss_functions_test.cpp +++ b/src/mlpack/tests/loss_functions_test.cpp @@ -201,7 +201,7 @@ TEST_CASE("KLDivergenceMeanTest", "[LossFunctionsTest]") target = arma::exp(arma::mat("2 1 1 1 1 1 1 1 1 1")); loss = module.Forward(input, target); - REQUIRE(loss == Approx(-1.1 ).epsilon(1e-5)); + REQUIRE(loss == Approx(-1.1).epsilon(1e-5)); // Test the Backward function. module.Backward(input, target, output); @@ -846,7 +846,8 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]") // Test the Backward function. module1.Backward(input, target, output); - REQUIRE(arma::as_scalar(arma::accu(output)) == Approx(-1.48227).epsilon(1e-3)); + REQUIRE(arma::as_scalar(arma::accu(output)) == + Approx(-1.48227).epsilon(1e-3)); REQUIRE(output.n_rows == input.n_rows); REQUIRE(output.n_cols == input.n_cols); CheckMatrices(output, expectedOutput, 0.1); @@ -865,7 +866,8 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]") // Test the Backward function. module2.Backward(input, target, output); - REQUIRE(arma::as_scalar(arma::accu(output)) == Approx(-0.164697).epsilon(1e-3)); + REQUIRE(arma::as_scalar(arma::accu(output)) == + Approx(-0.164697).epsilon(1e-3)); REQUIRE(output.n_rows == input.n_rows); REQUIRE(output.n_cols == input.n_cols); CheckMatrices(output, expectedOutput, 0.1); @@ -885,7 +887,7 @@ TEST_CASE("MeanAbsolutePercentageErrorTest", "[LossFunctionsTest]") // Test the Forward function. Loss should be 95.625. // Loss value calculated manually. double loss = module.Forward(input,target); - REQUIRE(loss == Approx(95.625).epsilon(1e-1)); + REQUIRE(loss == Approx(95.625).epsilon(1e-1)); // Test the Backward function. module.Backward(input, target, output); diff --git a/src/mlpack/tests/nbc_test.cpp b/src/mlpack/tests/nbc_test.cpp index f487060db4..2b785cab0e 100644 --- a/src/mlpack/tests/nbc_test.cpp +++ b/src/mlpack/tests/nbc_test.cpp @@ -81,7 +81,7 @@ TEST_CASE("NaiveBayesClassifierTest", "[NBCTest]") { for (size_t j = 0; j < testResProbs.n_rows; ++j) { - + REQUIRE(testResProbs(j, i) + 0.0001 == Approx(calcProbs(j, i) + 0.0001).epsilon(0.0001)); } diff --git a/src/mlpack/tests/pca_test.cpp b/src/mlpack/tests/pca_test.cpp index fff63d0024..7537804ac9 100644 --- a/src/mlpack/tests/pca_test.cpp +++ b/src/mlpack/tests/pca_test.cpp @@ -316,7 +316,8 @@ TEST_CASE("PCAScalingTest", "[PCATest]") // zero. There is noise, of course... REQUIRE(std::abs(eigvec(0, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); REQUIRE(std::abs(eigvec(1, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); - REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // Large tolerance for noise. + // Large tolerance for noise. + REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // The second component should be focused almost entirely in the third // dimension. diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 7bd714beaf..c490d9074b 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -206,13 +206,20 @@ TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") // Neighbors of point 10. REQUIRE(sortedOutput[newFromOld[10]].size() == 4); REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[9]); - REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.10).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[3]); - REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.25).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[8]); - REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(0.55).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[1]); - REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(0.65).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][0].first == + Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == + newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == + Approx(0.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == + newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == + Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == + newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == + Approx(0.65).epsilon(1e-7)); // Now do it again with a different range: [sqrt(0.5) 1.0]. if (rs->ReferenceTree()) @@ -433,13 +440,20 @@ TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") // Neighbors of point 10. REQUIRE(sortedOutput[newFromOld[10]].size() == 4); REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[5]); - REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(1.22).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[7]); - REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(2.30).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[6]); - REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(3.00).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[4]); - REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(4.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][0].first == + Approx(1.22).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == + newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == + Approx(2.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == + newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == + Approx(3.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == + newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == + Approx(4.05).epsilon(1e-7)); // Clean the memory. delete rs; diff --git a/src/mlpack/tests/rl_components_test.cpp b/src/mlpack/tests/rl_components_test.cpp index 7eb69cb003..8ce209903e 100644 --- a/src/mlpack/tests/rl_components_test.cpp +++ b/src/mlpack/tests/rl_components_test.cpp @@ -196,7 +196,7 @@ TEST_CASE("DoublePoleCartTest", "[RLComponentsTest]") } /** - * Constructs a ContinuousDoublePoleCart instance and check if the main + * Constructs a ContinuousDoublePoleCart instance and check if the main * routine works as it should be. */ TEST_CASE("ContinuousDoublePoleCartTest", "[RLComponentsTest]") @@ -285,5 +285,4 @@ TEST_CASE("GreedyPolicyTest", "[RLComponentsTest]") CartPole::Action action = policy.Sample(actionValue); REQUIRE(actionValue[action.action] == Approx(actionValue.max()).epsilon(1e-7)); - } diff --git a/src/mlpack/tests/sort_policy_test.cpp b/src/mlpack/tests/sort_policy_test.cpp index 6418135f8e..cb73f96cad 100644 --- a/src/mlpack/tests/sort_policy_test.cpp +++ b/src/mlpack/tests/sort_policy_test.cpp @@ -107,7 +107,7 @@ TEST_CASE("NnsNodeToNodeDistance", "[SortPolicyTest]") utility[0] = 0.5; nodeTwo.Bound() |= utility; - REQUIRE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + REQUIRE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == Approx(0.0).margin(1e-5)); } @@ -146,7 +146,7 @@ TEST_CASE("NnsPointToNodeDistance", "[SortPolicyTest]") // And now when the point is inside the bound. point[0] = 0.5; - REQUIRE(NearestNeighborSort::BestPointToNodeDistance(point, &node) == + REQUIRE(NearestNeighborSort::BestPointToNodeDistance(point, &node) == Approx(0.0).margin(1e-5)); } diff --git a/src/mlpack/tests/string_encoding_test.cpp b/src/mlpack/tests/string_encoding_test.cpp index 81af48f843..c7213e92cc 100644 --- a/src/mlpack/tests/string_encoding_test.cpp +++ b/src/mlpack/tests/string_encoding_test.cpp @@ -269,7 +269,8 @@ TEST_CASE("DictionaryEncodingIndividualCharactersTest", "[StringEncodingTest]") * Test the one pass modification of the dictionary encoding algorithm * in case of individual character encoding. */ -TEST_CASE("OnePassDictionaryEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("OnePassDictionaryEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -542,7 +543,7 @@ TEST_CASE("CharExtractDictionaryEncodingSerialization", "[StringEncodingTest]") /** * Test the Bag of Words encoding algorithm. - */ + */ TEST_CASE("BagOfWordsEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -617,7 +618,7 @@ TEST_CASE("BagOfWordsEncodingTest", "[StringEncodingTest]") /** * Test the Bag of Words encoding algorithm. The output is saved into a vector. - */ + */ TEST_CASE("VectorBagOfWordsEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -684,7 +685,8 @@ TEST_CASE("BagOfWordsEncodingIndividualCharactersTest", "[StringEncodingTest]") * Test the Bag of Words encoding algorithm in case of individual * characters encoding. The output type is vector>. */ -TEST_CASE("VectorBagOfWordsEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorBagOfWordsEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -861,7 +863,8 @@ TEST_CASE("VectorRawCountSmoothIdfEncodingTest", "[StringEncodingTest]") * raw count term frequency type and the smooth inverse document frequency type. * These parameters are the default ones. */ -TEST_CASE("RawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("RawCountSmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -942,7 +945,8 @@ TEST_CASE("RawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingT * These parameters are the default ones. The output type is * vector>. */ -TEST_CASE("VectorRawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorRawCountSmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1068,7 +1072,8 @@ TEST_CASE("VectorTfIdfRawCountEncodingTest", "[StringEncodingTest]") * raw count term frequency type and the non-smooth inverse document frequency * type. */ -TEST_CASE("RawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("RawCountTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1099,7 +1104,8 @@ TEST_CASE("RawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest] * raw count term frequency type and the non-smooth inverse document frequency * type. The output type is vector>. */ -TEST_CASE("VectorRawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorRawCountTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1129,7 +1135,8 @@ TEST_CASE("VectorRawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodin * Test the Tf-Idf encoding algorithm for individual characters with the * binary term frequency type and the smooth inverse document frequency type. */ -TEST_CASE("BinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("BinarySmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1160,7 +1167,8 @@ TEST_CASE("BinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTes * binary term frequency type and the smooth inverse document frequency type. * The output type is vector>. */ -TEST_CASE("VectorBinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorBinarySmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1222,7 +1230,8 @@ TEST_CASE("BinaryTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") * sublinear term frequency type and the smooth inverse document frequency * type. */ -TEST_CASE("SublinearSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("SublinearSmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1254,7 +1263,8 @@ TEST_CASE("SublinearSmoothIdfEncodingIndividualCharactersTest", "[StringEncoding * sublinear term frequency type and the non-smooth inverse document frequency * type. */ -TEST_CASE("SublinearTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("SublinearTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1286,7 +1296,8 @@ TEST_CASE("SublinearTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest * standard term frequency type and the smooth inverse document frequency * type. */ -TEST_CASE("TermFrequencySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("TermFrequencySmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1367,7 +1378,8 @@ TEST_CASE("TermFrequencySmoothIdfEncodingIndividualCharactersTest", "[StringEnco * standard term frequency type and the non-smooth inverse document frequency * type. */ -TEST_CASE("TermFrequencyTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("TermFrequencyTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", From ed36e473912dd15481997a9ddbf44c0934609582 Mon Sep 17 00:00:00 2001 From: Marcus Edel Date: Sun, 1 Nov 2020 14:50:37 +0100 Subject: [PATCH 13/19] More style fixes (line length, whitespace/end_of_line, whitespace comments). --- .../rectangle_tree/rectangle_tree_impl.hpp | 2 +- .../methods/ann/layer/dropconnect_impl.hpp | 2 +- .../mean_absolute_percentage_error_impl.hpp | 2 +- .../tests/activation_functions_test.cpp | 3 +-- src/mlpack/tests/lmnn_test.cpp | 26 +++++++++---------- src/mlpack/tests/loss_functions_test.cpp | 5 ++-- src/mlpack/tests/main_tests/kde_test.cpp | 10 +++---- src/mlpack/tests/main_tests/krann_test.cpp | 6 +++-- src/mlpack/tests/nbc_test.cpp | 1 - src/mlpack/tests/pca_test.cpp | 3 ++- src/mlpack/tests/range_search_test.cpp | 8 +++--- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp index 30d09c1300..03acfb0e74 100644 --- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp @@ -1431,7 +1431,7 @@ void RectangleTree(dataset); ar(CEREAL_POINTER(datasetTemp)); - } + } ar(CEREAL_NVP(points)); ar(CEREAL_NVP(auxiliaryInfo)); diff --git a/src/mlpack/methods/ann/layer/dropconnect_impl.hpp b/src/mlpack/methods/ann/layer/dropconnect_impl.hpp index ccbda1c888..9b22c91951 100644 --- a/src/mlpack/methods/ann/layer/dropconnect_impl.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect_impl.hpp @@ -108,7 +108,7 @@ template void DropConnect::serialize( Archive& ar, const uint32_t /* version */) { - // Delete the old network first, if needed. + // Delete the old network first, if needed. if (cereal::is_loading()) { boost::apply_visitor(DeleteVisitor(), baseLayer); diff --git a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp index 82f054e2b9..52b6281a18 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp @@ -45,7 +45,7 @@ void MeanAbsolutePercentageError::Backward( { output = (((arma::conv_to::from(input < target) * -2) + 1) / - target) * (100 / target.n_cols) ; + target) * (100 / target.n_cols); } template diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 011df12840..d88c0a5109 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -573,7 +573,7 @@ void CheckSoftminActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; - softmin.Forward(input,activations); + softmin.Forward(input, activations); for (size_t i = 0; i < activations.n_elem; ++i) { REQUIRE(activations.at(i) == Approx(target.at(i)).epsilon(1e-5)); @@ -607,7 +607,6 @@ void CheckSoftminDerivativeCorrect(const arma::colvec input, { REQUIRE(derivatives.at(i) == Approx(target.at(i)).epsilon(1e-5)); } - } /** diff --git a/src/mlpack/tests/lmnn_test.cpp b/src/mlpack/tests/lmnn_test.cpp index 52d014c9aa..cb07173563 100644 --- a/src/mlpack/tests/lmnn_test.cpp +++ b/src/mlpack/tests/lmnn_test.cpp @@ -120,7 +120,7 @@ TEST_CASE("LMNNInitialPointTest", "[LMNNTest]") for (int col = 0; col < 5; col++) { if (row == col) - REQUIRE(initialPoint(row, col) == Approx( 1.0).epsilon(1e-7)); + REQUIRE(initialPoint(row, col) == Approx(1.0).epsilon(1e-7)); else REQUIRE(initialPoint(row, col) == Approx(0.0).margin(1e-5)); } @@ -207,8 +207,8 @@ TEST_CASE("LMNNSeparableObjectiveTest", "[LMNNTest]") // Result calculated by hand. arma::mat coordinates = arma::eye(2, 2); - REQUIRE(lmnnfn.Evaluate(coordinates, 0, 1) == Approx( 1.576).epsilon(1e-7)); - REQUIRE(lmnnfn.Evaluate(coordinates, 1, 1) == Approx( 1.576).epsilon(1e-7)); + REQUIRE(lmnnfn.Evaluate(coordinates, 0, 1) == Approx(1.576).epsilon(1e-7)); + REQUIRE(lmnnfn.Evaluate(coordinates, 1, 1) == Approx(1.576).epsilon(1e-7)); REQUIRE(lmnnfn.Evaluate(coordinates, 2, 1) == Approx(1.576).epsilon(1e-7)); REQUIRE(lmnnfn.Evaluate(coordinates, 3, 1) == Approx(1.576).epsilon(1e-7)); REQUIRE(lmnnfn.Evaluate(coordinates, 4, 1) == Approx(1.576).epsilon(1e-7)); @@ -326,21 +326,21 @@ TEST_CASE("LMNNSeparableEvaluateWithGradientTest", "[LMNNTest]") objective = lmnnfn.EvaluateWithGradient(coordinates, 4, gradient, 1); - REQUIRE(objective == Approx( 1.576).epsilon(1e-7)); + REQUIRE(objective == Approx(1.576).epsilon(1e-7)); - REQUIRE(gradient(0, 0) == Approx( -0.048).epsilon(1e-7)); - REQUIRE(gradient(0, 1) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 0) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 1) == Approx( 2.0).epsilon(1e-7)); + REQUIRE(gradient(0, 0) == Approx(-0.048).epsilon(1e-7)); + REQUIRE(gradient(0, 1) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 0) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 1) == Approx(2.0).epsilon(1e-7)); objective = lmnnfn.EvaluateWithGradient(coordinates, 5, gradient, 1); REQUIRE(objective == Approx( 1.576).epsilon(1e-7)); - REQUIRE(gradient(0, 0) == Approx( -0.048).epsilon(1e-7)); - REQUIRE(gradient(0, 1) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 0) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 1) == Approx( 2.0).epsilon(1e-7)); + REQUIRE(gradient(0, 0) == Approx(-0.048).epsilon(1e-7)); + REQUIRE(gradient(0, 1) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 0) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 1) == Approx(2.0).epsilon(1e-7)); } // Check that final objective value using SGD optimizer is optimal. @@ -450,7 +450,7 @@ TEST_CASE("LMNNAccuracyTest", "[LMNNTest]") REQUIRE(initAccuracy < finalAccuracy); // Since this is a very simple dataset final accuracy should be around 100%. - REQUIRE(finalAccuracy == Approx( 100.0).epsilon(1e-7)); + REQUIRE(finalAccuracy == Approx(100.0).epsilon(1e-7)); } // Check that accuracy while learning square distance matrix is the same as when diff --git a/src/mlpack/tests/loss_functions_test.cpp b/src/mlpack/tests/loss_functions_test.cpp index 54b9945c66..42762bd96d 100644 --- a/src/mlpack/tests/loss_functions_test.cpp +++ b/src/mlpack/tests/loss_functions_test.cpp @@ -886,12 +886,13 @@ TEST_CASE("MeanAbsolutePercentageErrorTest", "[LossFunctionsTest]") // Test the Forward function. Loss should be 95.625. // Loss value calculated manually. - double loss = module.Forward(input,target); + double loss = module.Forward(input, target); REQUIRE(loss == Approx(95.625).epsilon(1e-1)); // Test the Backward function. module.Backward(input, target, output); - REQUIRE(arma::as_scalar(arma::accu(output)) == Approx(-105.625).epsilon(1e-3)); + REQUIRE(arma::as_scalar(arma::accu(output)) == + Approx(-105.625).epsilon(1e-3)); REQUIRE(output.n_rows == input.n_rows); REQUIRE(output.n_cols == input.n_cols); CheckMatrices(output, expectedOutput, 0.1); diff --git a/src/mlpack/tests/main_tests/kde_test.cpp b/src/mlpack/tests/main_tests/kde_test.cpp index f4604f9475..325130c928 100644 --- a/src/mlpack/tests/main_tests/kde_test.cpp +++ b/src/mlpack/tests/main_tests/kde_test.cpp @@ -87,7 +87,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEGaussianRTreeResultsMain", // Check whether results are equal. for (size_t i = 0; i < query.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** @@ -128,7 +128,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDETriangularBallTreeResultsMain", // Check whether results are equal. for (size_t i = 0; i < query.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** @@ -170,7 +170,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEMonoResultsMain", // Check whether results are equal. for (size_t i = 0; i < reference.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** @@ -239,7 +239,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEModelReuse", // Check estimations are the same. for (size_t i = 0; i < samples; ++i) - REQUIRE(oldEstimations[i] == Approx( newEstimations[i]).epsilon(relError)); + REQUIRE(oldEstimations[i] == Approx(newEstimations[i]).epsilon(relError)); } /** @@ -282,7 +282,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEGaussianSingleKDTreeResultsMain", // Check whether results are equal. for (size_t i = 0; i < query.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** diff --git a/src/mlpack/tests/main_tests/krann_test.cpp b/src/mlpack/tests/main_tests/krann_test.cpp index 244b88c8c5..b61044f104 100644 --- a/src/mlpack/tests/main_tests/krann_test.cpp +++ b/src/mlpack/tests/main_tests/krann_test.cpp @@ -453,7 +453,8 @@ TEST_CASE_METHOD(KRANNTestFixture, "KRANNDifferentTreeType", // Check that initial output matrices and the output matrices using // saved model are equal - CHECK(output_model->TreeType() == 0); + const bool check = output_model->TreeType() == 0; + CHECK(check == true); CHECK(IO::GetParam("output_model")->TreeType() == 8); delete output_model; @@ -491,7 +492,8 @@ TEST_CASE_METHOD(KRANNTestFixture, "KRANNDifferentSingleSampleLimit", // Check that initial output matrices and the output matrices using // saved model are equal. - CHECK( IO::GetParam("output_model")->SingleSampleLimit() == (int) 15); + CHECK(IO::GetParam("output_model")->SingleSampleLimit() == + (int) 15); CHECK(output_model->SingleSampleLimit() == (int) 20); delete output_model; } diff --git a/src/mlpack/tests/nbc_test.cpp b/src/mlpack/tests/nbc_test.cpp index 2b785cab0e..ddc0487315 100644 --- a/src/mlpack/tests/nbc_test.cpp +++ b/src/mlpack/tests/nbc_test.cpp @@ -81,7 +81,6 @@ TEST_CASE("NaiveBayesClassifierTest", "[NBCTest]") { for (size_t j = 0; j < testResProbs.n_rows; ++j) { - REQUIRE(testResProbs(j, i) + 0.0001 == Approx(calcProbs(j, i) + 0.0001).epsilon(0.0001)); } diff --git a/src/mlpack/tests/pca_test.cpp b/src/mlpack/tests/pca_test.cpp index 7537804ac9..6ccefbbaeb 100644 --- a/src/mlpack/tests/pca_test.cpp +++ b/src/mlpack/tests/pca_test.cpp @@ -329,7 +329,8 @@ TEST_CASE("PCAScalingTest", "[PCATest]") // the first (plus tolerance). REQUIRE(std::abs(eigvec(0, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); REQUIRE(std::abs(eigvec(1, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); - REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // Large tolerance for noise. + // Large tolerance for noise. + REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // The eigenvalues should sum to three. REQUIRE(accu(eigval) == Approx(3.0).epsilon(0.001)); diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index c490d9074b..bb79228017 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -280,9 +280,11 @@ TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") // Neighbors of point 10. REQUIRE(sortedOutput[newFromOld[10]].size() == 2); REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[2]); - REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.85).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][0].first == + Approx(0.85).epsilon(1e-7)); REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[0]); - REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.95).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].first == + Approx(0.95).epsilon(1e-7)); // Now do it again with a different range: [1.0 inf]. if (rs->ReferenceTree()) @@ -1056,7 +1058,7 @@ TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon (1e-7)); + Approx(ballSorted[i][j].first).epsilon(1e-7)); } } } From 0aabdca00d9f9cab545943377cc6246c17f63a22 Mon Sep 17 00:00:00 2001 From: Marcus Edel Date: Sun, 1 Nov 2020 14:55:44 +0100 Subject: [PATCH 14/19] Remove extra space. --- src/mlpack/tests/lmnn_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/lmnn_test.cpp b/src/mlpack/tests/lmnn_test.cpp index cb07173563..b767f4a940 100644 --- a/src/mlpack/tests/lmnn_test.cpp +++ b/src/mlpack/tests/lmnn_test.cpp @@ -335,7 +335,7 @@ TEST_CASE("LMNNSeparableEvaluateWithGradientTest", "[LMNNTest]") objective = lmnnfn.EvaluateWithGradient(coordinates, 5, gradient, 1); - REQUIRE(objective == Approx( 1.576).epsilon(1e-7)); + REQUIRE(objective == Approx(1.576).epsilon(1e-7)); REQUIRE(gradient(0, 0) == Approx(-0.048).epsilon(1e-7)); REQUIRE(gradient(0, 1) == Approx(0.0).epsilon(1e-7)); From 04bcb9be5a93117971fcd8f2783bbd5614b6580e Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Mon, 2 Nov 2020 15:56:56 +0530 Subject: [PATCH 15/19] Detecting version more accurately. --- .github/workflows/update-cli11.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-cli11.yaml b/.github/workflows/update-cli11.yaml index 1b5ad88cc2..571d7b0e8c 100644 --- a/.github/workflows/update-cli11.yaml +++ b/.github/workflows/update-cli11.yaml @@ -16,7 +16,7 @@ jobs: 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.\d') + 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) From 6d280d2d1d8a36c005c2152cb0ac0aafcb116a5e Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Tue, 3 Nov 2020 14:09:24 +0530 Subject: [PATCH 16/19] Apply suggestions from code review Co-authored-by: Marcus Edel --- .github/workflows/update-catch.yaml | 10 +++++----- .github/workflows/update-cli11.yaml | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/update-catch.yaml b/.github/workflows/update-catch.yaml index 6ae6be1b75..af133ac853 100644 --- a/.github/workflows/update-catch.yaml +++ b/.github/workflows/update-catch.yaml @@ -11,17 +11,17 @@ jobs: - name: Get Latest Catch Tagged Release id: catch-header run: | - # Ping version information upstream + # 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 + # 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 + # Combine values to match release tag information. CATCH_VERSION_VALUE=${CATCH_VERSION_MAJOR}.${CATCH_VERSION_MINOR}.${CATCH_VERSION_PATCH} - # Set the current release tag + # Set the current release tag. echo ::set-output name=current_tag::$(echo $CATCH_VERSION_VALUE) - name: Update Catch @@ -32,7 +32,7 @@ jobs: run: | # Delete the catch.hpp. rm -f src/mlpack/tests/catch.hpp - # Download the release + # 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 diff --git a/.github/workflows/update-cli11.yaml b/.github/workflows/update-cli11.yaml index 571d7b0e8c..6bca961098 100644 --- a/.github/workflows/update-cli11.yaml +++ b/.github/workflows/update-cli11.yaml @@ -11,13 +11,13 @@ jobs: - name: Get Latest CLI11 Tagged Release id: cli11-header run: | - # Ping version information upstream + # 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 + # 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 + # Set the current release tag. echo ::set-output name=current_tag::$(echo $CLI11_VERSION_VALUE) - name: Update CLI11 @@ -28,7 +28,7 @@ jobs: run: | # Delete the CLI11.hpp. rm -f src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp - # Download the release + # 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 From e2b876057cba992878b24b12e9b5ffc3dd7cffd9 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Tue, 3 Nov 2020 14:27:07 +0530 Subject: [PATCH 17/19] Specify Links Correctly. --- .github/workflows/update-catch.yaml | 4 ++-- .github/workflows/update-cli11.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-catch.yaml b/.github/workflows/update-catch.yaml index af133ac853..a4f7de2c4d 100644 --- a/.github/workflows/update-catch.yaml +++ b/.github/workflows/update-catch.yaml @@ -42,7 +42,7 @@ jobs: 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] + 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 }} diff --git a/.github/workflows/update-cli11.yaml b/.github/workflows/update-cli11.yaml index 6bca961098..e935183cdf 100644 --- a/.github/workflows/update-cli11.yaml +++ b/.github/workflows/update-cli11.yaml @@ -38,7 +38,7 @@ jobs: 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] + 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 }} From 1a5a1c564ae47c18b60b4037ce87b624ea65200a Mon Sep 17 00:00:00 2001 From: Yashwants19 Date: Tue, 3 Nov 2020 23:24:48 +0000 Subject: [PATCH 18/19] Upgrade Catch to 2.13.3 --- src/mlpack/tests/catch.hpp | 7348 +++++++++++++++++++++++++++--------- 1 file changed, 5603 insertions(+), 1745 deletions(-) diff --git a/src/mlpack/tests/catch.hpp b/src/mlpack/tests/catch.hpp index 7962f28bde..2a2d77a27f 100644 --- a/src/mlpack/tests/catch.hpp +++ b/src/mlpack/tests/catch.hpp @@ -1,12 +1,12 @@ /* - * Catch v2.4.1 - * Generated: 2018-09-28 15:50:15.645795 + * Catch v2.13.3 + * Generated: 2020-10-31 18:20:31.045274 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved. + * Copyright (c) 2020 Two Blue Cubes Ltd. All rights reserved. * * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file BOOST_LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED @@ -14,8 +14,8 @@ #define CATCH_VERSION_MAJOR 2 -#define CATCH_VERSION_MINOR 4 -#define CATCH_VERSION_PATCH 1 +#define CATCH_VERSION_MINOR 13 +#define CATCH_VERSION_PATCH 3 #ifdef __clang__ # pragma clang system_header @@ -36,10 +36,11 @@ # pragma clang diagnostic ignored "-Wcovered-switch-default" # endif #elif defined __GNUC__ - // GCC likes to warn on REQUIREs, and we cannot suppress them - // locally because g++'s support for _Pragma is lacking in older, - // still supported, versions -# pragma GCC diagnostic ignored "-Wparentheses" + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details + # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-variable" # pragma GCC diagnostic ignored "-Wpadded" @@ -131,30 +132,51 @@ namespace Catch { #endif -#if defined(CATCH_CPP17_OR_GREATER) -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +// We have to avoid both ICC and Clang, because they try to mask themselves +// as gcc, and we want only GCC in this block +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) + +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + #endif -#ifdef __clang__ +#if defined(__clang__) -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ - _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") -# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ - _Pragma( "clang diagnostic pop" ) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic pop" ) +// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug +// which results in calls to destructors being emitted for each temporary, +// without a matching initialization. In practice, this can result in something +// like `std::string::~string` being called on an uninitialized value. +// +// For example, this code will likely segfault under IBM XL: +// ``` +// REQUIRE(std::string("12") + "34" == "1234") +// ``` +// +// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. +# if !defined(__ibmxl__) && !defined(__CUDACC__) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ +# endif -# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS \ - _Pragma( "clang diagnostic pop" ) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) #endif // __clang__ @@ -179,6 +201,7 @@ namespace Catch { // Android somehow still does not support std::to_string #if defined(__ANDROID__) # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE #endif //////////////////////////////////////////////////////////////////////////////// @@ -203,20 +226,19 @@ namespace Catch { // some versions of cygwin (most) do not support std::to_string. Use the libstd check. // https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ - && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) -# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING # endif #endif // __CYGWIN__ //////////////////////////////////////////////////////////////////////////////// // Visual C++ -#ifdef _MSC_VER +#if defined(_MSC_VER) -# if _MSC_VER >= 1900 // Visual Studio 2015 or newer -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -# endif +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) // Universal Windows platform does not support SEH // Or console colours (or console at all...) @@ -226,6 +248,20 @@ namespace Catch { # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH # endif +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(__clang__) // Handle Clang masquerading for msvc +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL +# endif // __clang__ + +#endif // _MSC_VER + +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC #endif // _MSC_VER //////////////////////////////////////////////////////////////////////////////// @@ -240,6 +276,12 @@ namespace Catch { # define CATCH_INTERNAL_CONFIG_NO_WCHAR #endif // __DJGPP__ +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN +#endif + //////////////////////////////////////////////////////////////////////////////// // Use of __COUNTER__ is suppressed during code analysis in @@ -252,30 +294,56 @@ namespace Catch { #endif //////////////////////////////////////////////////////////////////////////////// -// Check if string_view is available and usable -// The check is split apart to work around v140 (VS2015) preprocessor issue... -#if defined(__has_include) -#if __has_include() && defined(CATCH_CPP17_OR_GREATER) -# define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW -#endif + +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE #endif -//////////////////////////////////////////////////////////////////////////////// -// Check if variant is available and usable +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Various stdlib support checks that require __has_include #if defined(__has_include) -# if __has_include() && defined(CATCH_CPP17_OR_GREATER) -# if defined(__clang__) && (__clang_major__ < 8) - // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 - // fix should be in clang 8, workaround in libstdc++ 8.2 -# include -# if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) -# define CATCH_CONFIG_NO_CPP17_VARIANT -# else -# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT -# endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) -# endif // defined(__clang__) && (__clang_major__ < 8) -# endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) -#endif // __has_include + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # include + # if __cpp_lib_byte > 0 + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) # define CATCH_CONFIG_COUNTER @@ -296,8 +364,8 @@ namespace Catch { # define CATCH_CONFIG_CPP11_TO_STRING #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) -# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL #endif #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) @@ -308,6 +376,10 @@ namespace Catch { # define CATCH_CONFIG_CPP17_VARIANT #endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif + #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE #endif @@ -320,17 +392,57 @@ namespace Catch { # define CATCH_CONFIG_DISABLE_EXCEPTIONS #endif +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN +#endif + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC +#endif + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +#endif #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS #endif #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS #endif #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS +#endif + +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) +#endif + +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS #endif #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) @@ -343,6 +455,10 @@ namespace Catch { #define CATCH_CATCH_ANON(type) catch (type) #endif +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#endif + // end catch_compiler_capabilities.h #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) @@ -356,6 +472,10 @@ namespace Catch { #include #include +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + namespace Catch { struct CaseSensitive { enum Choice { @@ -382,12 +502,12 @@ namespace Catch { line( _line ) {} - SourceLineInfo( SourceLineInfo const& other ) = default; - SourceLineInfo( SourceLineInfo && ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo& operator = ( SourceLineInfo && ) = default; + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; - bool empty() const noexcept; + bool empty() const noexcept { return file[0] == '\0'; } bool operator == ( SourceLineInfo const& other ) const noexcept; bool operator < ( SourceLineInfo const& other ) const noexcept; @@ -397,6 +517,11 @@ namespace Catch { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; + // Use this in variadic streaming macros to allow // >> +StreamEndStop // as well as @@ -423,9 +548,10 @@ namespace Catch { } // end namespace Catch #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ - CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION // end catch_tag_alias_autoregistrar.h // start catch_test_registry.h @@ -433,7 +559,6 @@ namespace Catch { // start catch_interfaces_testcase.h #include -#include namespace Catch { @@ -444,8 +569,6 @@ namespace Catch { virtual ~ITestInvoker(); }; - using ITestCasePtr = std::shared_ptr; - class TestCase; struct IConfig; @@ -455,6 +578,7 @@ namespace Catch { virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; }; + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); std::vector const& getAllTestCasesSorted( IConfig const& config ); @@ -467,55 +591,30 @@ namespace Catch { #include #include #include +#include namespace Catch { - class StringData; - /// A non-owning string class (similar to the forthcoming std::string_view) /// Note that, because a StringRef may be a substring of another string, - /// it may not be null terminated. c_str() must return a null terminated - /// string, however, and so the StringRef will internally take ownership - /// (taking a copy), if necessary. In theory this ownership is not externally - /// visible - but it does mean (substring) StringRefs should not be shared between - /// threads. + /// it may not be null terminated. class StringRef { public: using size_type = std::size_t; + using const_iterator = const char*; private: - friend struct StringRefTestAccess; - - char const* m_start; - size_type m_size; - - char* m_data = nullptr; - - void takeOwnership(); - static constexpr char const* const s_empty = ""; - public: // construction/ assignment - StringRef() noexcept - : StringRef( s_empty, 0 ) - {} + char const* m_start = s_empty; + size_type m_size = 0; - StringRef( StringRef const& other ) noexcept - : m_start( other.m_start ), - m_size( other.m_size ) - {} - - StringRef( StringRef&& other ) noexcept - : m_start( other.m_start ), - m_size( other.m_size ), - m_data( other.m_data ) - { - other.m_data = nullptr; - } + public: // construction + constexpr StringRef() noexcept = default; StringRef( char const* rawChars ) noexcept; - StringRef( char const* rawChars, size_type size ) noexcept + constexpr StringRef( char const* rawChars, size_type size ) noexcept : m_start( rawChars ), m_size( size ) {} @@ -525,69 +624,333 @@ namespace Catch { m_size( stdString.size() ) {} - ~StringRef() noexcept { - delete[] m_data; + explicit operator std::string() const { + return std::string(m_start, m_size); } - auto operator = ( StringRef const &other ) noexcept -> StringRef& { - delete[] m_data; - m_data = nullptr; - m_start = other.m_start; - m_size = other.m_size; - return *this; - } - - operator std::string() const; - - void swap( StringRef& other ) noexcept; - public: // operators auto operator == ( StringRef const& other ) const noexcept -> bool; - auto operator != ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); + } - auto operator[] ( size_type index ) const noexcept -> char; + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } public: // named queries - auto empty() const noexcept -> bool { + constexpr auto empty() const noexcept -> bool { return m_size == 0; } - auto size() const noexcept -> size_type { + constexpr auto size() const noexcept -> size_type { return m_size; } - auto numberOfCharacters() const noexcept -> size_type; + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception auto c_str() const -> char const*; public: // substrings and searches - auto substr( size_type start, size_type size ) const noexcept -> StringRef; + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; - // Returns the current start pointer. - // Note that the pointer can change when if the StringRef is a substring - auto currentData() const noexcept -> char const*; + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; - private: // ownership queries - may not be consistent between calls - auto isOwned() const noexcept -> bool; - auto isSubstring() const noexcept -> bool; + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } + + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } }; - auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string; - auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string; - auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string; - auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; - inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { return StringRef( rawChars, size ); } - } // namespace Catch -inline auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { return Catch::StringRef( rawChars, size ); } // end catch_stringref.h +// start catch_preprocessor.hpp + + +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) + +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif + +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif + +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) + +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template