From df591b290f3544bc81a8da42b1681dc2cfecbee0 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 17 Jun 2022 17:54:30 +0530 Subject: [PATCH 1/3] correction in ann layers --- src/mlpack/methods/ann/layer/add_impl.hpp | 4 +- .../methods/ann/layer/alpha_dropout_impl.hpp | 1 + .../methods/ann/layer/concatenate_impl.hpp | 1 + .../methods/ann/layer/convolution_impl.hpp | 3 +- src/mlpack/methods/ann/layer/dropout_impl.hpp | 1 + .../methods/ann/layer/log_softmax_impl.hpp | 3 +- src/mlpack/methods/ann/layer/padding.hpp | 14 ++++- src/mlpack/methods/ann/layer/padding_impl.hpp | 55 +++++++++++++++++++ .../ann/layer/radial_basis_function_impl.hpp | 1 + src/mlpack/methods/ann/layer/softmax_impl.hpp | 2 +- 10 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/mlpack/methods/ann/layer/add_impl.hpp b/src/mlpack/methods/ann/layer/add_impl.hpp index 8cd582c5ab..ff557ec42a 100644 --- a/src/mlpack/methods/ann/layer/add_impl.hpp +++ b/src/mlpack/methods/ann/layer/add_impl.hpp @@ -20,7 +20,9 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -AddType::AddType() : outSize(0) +AddType::AddType() : + Layer(), + outSize(0) { // Nothing to do. } diff --git a/src/mlpack/methods/ann/layer/alpha_dropout_impl.hpp b/src/mlpack/methods/ann/layer/alpha_dropout_impl.hpp index 91a150f410..6409f57c3a 100644 --- a/src/mlpack/methods/ann/layer/alpha_dropout_impl.hpp +++ b/src/mlpack/methods/ann/layer/alpha_dropout_impl.hpp @@ -26,6 +26,7 @@ template AlphaDropoutType::AlphaDropoutType( const double ratio, const double alphaDash) : + Layer(), ratio(ratio), alphaDash(alphaDash) { diff --git a/src/mlpack/methods/ann/layer/concatenate_impl.hpp b/src/mlpack/methods/ann/layer/concatenate_impl.hpp index 8980e0c606..486431cb52 100644 --- a/src/mlpack/methods/ann/layer/concatenate_impl.hpp +++ b/src/mlpack/methods/ann/layer/concatenate_impl.hpp @@ -22,6 +22,7 @@ namespace ann /** Artificial Neural Network. */ { template ConcatenateType:: ConcatenateType(const MatType& concat) : + Layer(), concat(concat) { // Nothing to do here. diff --git a/src/mlpack/methods/ann/layer/convolution_impl.hpp b/src/mlpack/methods/ann/layer/convolution_impl.hpp index 5e4f2c618e..57731a9df5 100644 --- a/src/mlpack/methods/ann/layer/convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/convolution_impl.hpp @@ -29,7 +29,7 @@ ConvolutionType< BackwardConvolutionRule, GradientConvolutionRule, MatType ->::ConvolutionType() +>::ConvolutionType() : Layer() { // Nothing to do here. } @@ -87,6 +87,7 @@ ConvolutionType< const std::tuple& padW, const std::tuple& padH, const std::string& paddingTypeIn) : + Layer(), maps(maps), kernelWidth(kernelWidth), kernelHeight(kernelHeight), diff --git a/src/mlpack/methods/ann/layer/dropout_impl.hpp b/src/mlpack/methods/ann/layer/dropout_impl.hpp index 012de36f62..1ac7001bc4 100644 --- a/src/mlpack/methods/ann/layer/dropout_impl.hpp +++ b/src/mlpack/methods/ann/layer/dropout_impl.hpp @@ -22,6 +22,7 @@ namespace ann /** Artificial Neural Network. */ { template DropoutType::DropoutType( const double ratio) : + Layer(), ratio(ratio), scale(1.0 / (1.0 - ratio)) { diff --git a/src/mlpack/methods/ann/layer/log_softmax_impl.hpp b/src/mlpack/methods/ann/layer/log_softmax_impl.hpp index 37b2e296bd..5330bffd13 100644 --- a/src/mlpack/methods/ann/layer/log_softmax_impl.hpp +++ b/src/mlpack/methods/ann/layer/log_softmax_impl.hpp @@ -19,7 +19,8 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -LogSoftMaxType::LogSoftMaxType() +LogSoftMaxType::LogSoftMaxType() : + Layer() { // Nothing to do here. } diff --git a/src/mlpack/methods/ann/layer/padding.hpp b/src/mlpack/methods/ann/layer/padding.hpp index 018a28479b..21507f9a31 100644 --- a/src/mlpack/methods/ann/layer/padding.hpp +++ b/src/mlpack/methods/ann/layer/padding.hpp @@ -36,8 +36,6 @@ class PaddingType : public Layer * @param padWRight Right padding width of the input. * @param padHTop Top padding height of the input. * @param padHBottom Bottom padding height of the input. - * @param inputWidth Width of the input. - * @param inputHeight Height of the input. */ PaddingType(const size_t padWLeft = 0, const size_t padWRight = 0, @@ -47,6 +45,18 @@ class PaddingType : public Layer //! Clone the PaddingType object. This handles polymorphism correctly. PaddingType* Clone() const { return new PaddingType(*this); } + //! Virtual destructor. + virtual ~PaddingType() { } + + //! Copy the given PaddingType. + PaddingType(const PaddingType& other); + //! Take ownership of the given PaddingType. + PaddingType(PaddingType&& other); + //! Copy the given PaddingType. + PaddingType& operator=(const PaddingType& other); + //! Take ownership of the given PaddingType. + PaddingType& operator=(PaddingType&& other); + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/padding_impl.hpp b/src/mlpack/methods/ann/layer/padding_impl.hpp index 2c2811209b..97b112898b 100644 --- a/src/mlpack/methods/ann/layer/padding_impl.hpp +++ b/src/mlpack/methods/ann/layer/padding_impl.hpp @@ -25,6 +25,7 @@ PaddingType::PaddingType( const size_t padWRight, const size_t padHTop, const size_t padHBottom) : + Layer(), padWLeft(padWLeft), padWRight(padWRight), padHTop(padHTop), @@ -34,6 +35,60 @@ PaddingType::PaddingType( // Nothing to do here. } +template +PaddingType::PaddingType(const PaddingType& other) : + Layer(other), + padWLeft(other.padWLeft), + padWRight(other.padWRight), + padHTop(other.padHTop), + padHBottom(other.padHBottom), + totalInMaps(other.totalInMaps) +{ + // Nothing to do here. +} + +template +PaddingType::PaddingType(PaddingType&& other) : + Layer(std::move(other)), + padWLeft(std::move(other.padWLeft)), + padWRight(std::move(other.padWRight)), + padHTop(std::move(other.padHTop)), + padHBottom(std::move(other.padHBottom)), + totalInMaps(std::move(other.totalInMaps)) +{ + // Nothing to do here. +} + +template +PaddingType& +PaddingType::operator=(const PaddingType& other) +{ + if (this != &other) + Layer::operator=(other); + padWLeft = other.padWLeft; + padWRight = other.padWRight; + padHTop = other.padHTop; + padHBottom = other.padHBottom; + totalInMaps = other.totalInMaps; + + return *this; +} + +template +PaddingType& +PaddingType::operator=(PaddingType&& other) +{ + if (this != &other) + Layer::operator=(std::move(other)); + padWLeft = std::move(other.padWLeft); + padWRight = std::move(other.padWRight); + padHTop = std::move(other.padHTop); + padHBottom = std::move(other.padHBottom); + totalInMaps = std::move(other.totalInMaps); + + return *this; +} + template void PaddingType::Forward(const MatType& input, MatType& output) { diff --git a/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp b/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp index 55887792cd..6953baef6e 100644 --- a/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp +++ b/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp @@ -30,6 +30,7 @@ RBFType::RBFType( const size_t outSize, MatType& centres, double betas) : + Layer(), outSize(outSize), betas(betas), centres(centres) diff --git a/src/mlpack/methods/ann/layer/softmax_impl.hpp b/src/mlpack/methods/ann/layer/softmax_impl.hpp index 626dbfbffd..7cb3fcb7b7 100644 --- a/src/mlpack/methods/ann/layer/softmax_impl.hpp +++ b/src/mlpack/methods/ann/layer/softmax_impl.hpp @@ -35,7 +35,7 @@ SoftmaxType::SoftmaxType(const SoftmaxType& other) : template SoftmaxType::SoftmaxType(SoftmaxType&& other) : - Layer(other) + Layer(std::move(other)) { // Nothing to do here. } From d83c3c035c8d5255d1f21bc52657217a22d3f1f4 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Fri, 17 Jun 2022 18:27:57 -0400 Subject: [PATCH 2/3] Comment out catch workflow. --- .github/workflows/update-catch.yaml | 99 +++++++++++++++-------------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/.github/workflows/update-catch.yaml b/.github/workflows/update-catch.yaml index c29b0ca1e4..b65a34d02c 100644 --- a/.github/workflows/update-catch.yaml +++ b/.github/workflows/update-catch.yaml @@ -1,49 +1,52 @@ -name: Update Catch -on: - workflow_dispatch: - schedule: - - cron: '0 10 1/16 * *' -jobs: - updateCatch: - if: ${{ github.repository == 'mlpack/mlpack' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Get Latest Catch Tagged Release - id: catch-header - run: | - # Ping version information upstream. - CATCH_RELEASE_JSON=$(curl -sL https://api.github.com/repos/catchorg/Catch2/releases/latest) - CATCH_RELEASE_VERSION=$(jq -r ".tag_name" <<< "$CATCH_RELEASE_JSON" | tr -d v) - echo ::set-output name=release_tag::$(echo $CATCH_RELEASE_VERSION) - # Extract out version information from git repository. - CATCH_VERSION_MAJOR=$(grep -i ".*#define CATCH_VERSION_MAJOR.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*") - CATCH_VERSION_MINOR=$(grep -i ".*#define CATCH_VERSION_MINOR.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*") - CATCH_VERSION_PATCH=$(grep -i ".*#define CATCH_VERSION_PATCH.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*") - # Combine values to match release tag information. - CATCH_VERSION_VALUE=${CATCH_VERSION_MAJOR}.${CATCH_VERSION_MINOR}.${CATCH_VERSION_PATCH} - # Set the current release tag. - echo ::set-output name=current_tag::$(echo $CATCH_VERSION_VALUE) +# This is commented out until we update to Catch version 3. Note that that +# can't be done until mlpack has C++17 as a minimum requirement. - - name: Update Catch - if: steps.catch-header.outputs.current_tag != steps.catch-header.outputs.release_tag - env: - CURRENT_TAG: ${{ steps.catch-header.outputs.current_tag }} - RELEASE_TAG: ${{ steps.catch-header.outputs.release_tag }} - run: | - # Delete the catch.hpp. - rm -f src/mlpack/tests/catch.hpp - # Download the release. - curl -sL https://github.com/catchorg/Catch2/releases/latest/download/catch.hpp -o src/mlpack/tests/catch.hpp - - - name: Create Pull Request For Catch - if: steps.catch-header.outputs.current_tag != steps.catch-header.outputs.release_tag - uses: peter-evans/create-pull-request@v3 - with: - commit-message: Upgrade Catch to ${{ steps.catch-header.outputs.release_tag }} - title: Upgrade Catch to ${{ steps.catch-header.outputs.release_tag }} - body: | - Updates [catchorg/Catch2](https://github.com/catchorg/Catch2) to ${{ steps.catch-header.outputs.release_tag }}. - Auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request). - labels: update dependencies, automated PR - branch: catch-header-updates-${{ steps.catch-header.outputs.release_tag }} +#name: Update Catch +#on: +# workflow_dispatch: +# schedule: +# - cron: '0 10 1/16 * *' +#jobs: +# updateCatch: +# if: ${{ github.repository == 'mlpack/mlpack' }} +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# - name: Get Latest Catch Tagged Release +# id: catch-header +# run: | +# # Ping version information upstream. +# CATCH_RELEASE_JSON=$(curl -sL https://api.github.com/repos/catchorg/Catch2/releases/latest) +# CATCH_RELEASE_VERSION=$(jq -r ".tag_name" <<< "$CATCH_RELEASE_JSON" | tr -d v) +# echo ::set-output name=release_tag::$(echo $CATCH_RELEASE_VERSION) +# # Extract out version information from git repository. +# CATCH_VERSION_MAJOR=$(grep -i ".*#define CATCH_VERSION_MAJOR.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*") +# CATCH_VERSION_MINOR=$(grep -i ".*#define CATCH_VERSION_MINOR.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*") +# CATCH_VERSION_PATCH=$(grep -i ".*#define CATCH_VERSION_PATCH.*" src/mlpack/tests/catch.hpp | grep -o "[0-9]*") +# # Combine values to match release tag information. +# CATCH_VERSION_VALUE=${CATCH_VERSION_MAJOR}.${CATCH_VERSION_MINOR}.${CATCH_VERSION_PATCH} +# # Set the current release tag. +# echo ::set-output name=current_tag::$(echo $CATCH_VERSION_VALUE) +# +# - name: Update Catch +# if: steps.catch-header.outputs.current_tag != steps.catch-header.outputs.release_tag +# env: +# CURRENT_TAG: ${{ steps.catch-header.outputs.current_tag }} +# RELEASE_TAG: ${{ steps.catch-header.outputs.release_tag }} +# run: | +# # Delete the catch.hpp. +# rm -f src/mlpack/tests/catch.hpp +# # Download the release. +# curl -sL https://github.com/catchorg/Catch2/releases/latest/download/catch.hpp -o src/mlpack/tests/catch.hpp +# +# - name: Create Pull Request For Catch +# if: steps.catch-header.outputs.current_tag != steps.catch-header.outputs.release_tag +# uses: peter-evans/create-pull-request@v3 +# with: +# commit-message: Upgrade Catch to ${{ steps.catch-header.outputs.release_tag }} +# title: Upgrade Catch to ${{ steps.catch-header.outputs.release_tag }} +# body: | +# Updates [catchorg/Catch2](https://github.com/catchorg/Catch2) to ${{ steps.catch-header.outputs.release_tag }}. +# Auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request). +# labels: update dependencies, automated PR +# branch: catch-header-updates-${{ steps.catch-header.outputs.release_tag }} From 34c50e8109764ca2fb5c6dda72b94d503814e52a Mon Sep 17 00:00:00 2001 From: Shubham Agrawal <58412969+shubham1206agra@users.noreply.github.com> Date: Sat, 18 Jun 2022 10:34:55 +0530 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Ryan Curtin --- src/mlpack/methods/ann/layer/padding_impl.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mlpack/methods/ann/layer/padding_impl.hpp b/src/mlpack/methods/ann/layer/padding_impl.hpp index 97b112898b..69aa6dde60 100644 --- a/src/mlpack/methods/ann/layer/padding_impl.hpp +++ b/src/mlpack/methods/ann/layer/padding_impl.hpp @@ -64,12 +64,14 @@ PaddingType& PaddingType::operator=(const PaddingType& other) { if (this != &other) + { Layer::operator=(other); padWLeft = other.padWLeft; padWRight = other.padWRight; padHTop = other.padHTop; padHBottom = other.padHBottom; totalInMaps = other.totalInMaps; + } return *this; } @@ -79,12 +81,14 @@ PaddingType& PaddingType::operator=(PaddingType&& other) { if (this != &other) + { Layer::operator=(std::move(other)); padWLeft = std::move(other.padWLeft); padWRight = std::move(other.padWRight); padHTop = std::move(other.padHTop); padHBottom = std::move(other.padHBottom); totalInMaps = std::move(other.totalInMaps); + } return *this; }