Skip to content

Commit 6dc3149

Browse files
Upgrade ensmallen to 2.18.0 (#45)
* Upgrade ensmallen to 2.18.0 * Update RcppArmadillo requirement to mirror underlying armadillo requirement in ensmallen * Clean up notation in vignette * Add new Rcpp outputstreams * Add additional changes * Remove URLs to the mlpack ensmallen * Update github action to latest version * Update notes * Fix URI Co-authored-by: coatless <[email protected]> Co-authored-by: James Balamuta <[email protected]>
1 parent a7e5612 commit 6dc3149

File tree

13 files changed

+258
-66
lines changed

13 files changed

+258
-66
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
13
on:
24
push:
3-
branches:
4-
- master
5+
branches: [main, master]
56
pull_request:
6-
branches:
7-
- master
7+
branches: [main, master]
88

99
name: R-CMD-check
1010

@@ -20,62 +20,35 @@ jobs:
2020
config:
2121
- {os: macOS-latest, r: 'release'}
2222
- {os: windows-latest, r: 'release'}
23-
- {os: windows-latest, r: 'oldrel'}
24-
#- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
25-
#- {os: ubuntu-20.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
26-
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
23+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
24+
- {os: ubuntu-latest, r: 'release'}
25+
- {os: ubuntu-latest, r: 'oldrel-1'}
2726

2827
env:
29-
MAKEFLAGS: "-j 2"
30-
R_BUILD_ARGS: "--no-build-vignettes"
31-
R_CHECK_ARGS: "--no-build-vignettes"
32-
_R_CHECK_FORCE_SUGGESTS: 0
33-
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
34-
RSPM: ${{ matrix.config.rspm }}
3528
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
29+
R_KEEP_PKG_SOURCE: yes
3630

3731
steps:
3832
- uses: actions/checkout@v2
3933

40-
- uses: r-lib/actions/setup-r@master
34+
- uses: r-lib/actions/setup-pandoc@v1
35+
36+
- uses: r-lib/actions/setup-r@v1
4137
with:
4238
r-version: ${{ matrix.config.r }}
39+
http-user-agent: ${{ matrix.config.http-user-agent }}
40+
use-public-rspm: true
4341

44-
- uses: r-lib/actions/setup-pandoc@master
45-
46-
- name: Query dependencies
47-
run: |
48-
install.packages('remotes')
49-
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
50-
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
51-
shell: Rscript {0}
52-
53-
- name: Cache R packages
54-
if: runner.os != 'Windows'
55-
uses: actions/cache@v1
42+
- uses: r-lib/actions/setup-r-dependencies@v1
5643
with:
57-
path: ${{ env.R_LIBS_USER }}
58-
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
59-
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
44+
extra-packages: rcmdcheck
6045

61-
- name: Install system dependencies
62-
if: runner.os == 'Linux'
63-
run: |
64-
while read -r cmd
65-
do
66-
eval sudo $cmd
67-
done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "20.04"), sep = "\n")')
68-
- name: Install dependencies
69-
run: |
70-
remotes::install_deps(dependencies = TRUE)
71-
remotes::install_cran("rcmdcheck")
72-
shell: Rscript {0}
46+
- uses: r-lib/actions/check-r-package@v1
7347

74-
- name: Check
75-
env:
76-
_R_CHECK_CRAN_INCOMING_REMOTE_: false
77-
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
78-
shell: Rscript {0}
48+
- name: Show testthat output
49+
if: always()
50+
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
51+
shell: bash
7952

8053
- name: Upload check results
8154
if: failure()

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2021-10-22 James Balamuta <[email protected]>
2+
3+
* DESCRIPTION (Version): Release 2.18.0 and increase RcppArmadillo requirement
4+
* NEWS.md: Update for Ensmallen release 2.18.0
5+
* inst/include/ensmallen_bits: Upgraded to Ensmallen 2.18.0
6+
* inst/include/ensmallen.hpp: ditto
7+
* src/RcppExports.cpp: Re-generate RcppExport
8+
* vignettes/using-rcppensmallen.Rmd: Clean up notation and bump linking note.
9+
* .github/workflows/r-cmd-check.yaml: Updated github actions runner for R CMD check
10+
111
2021-07-24 James Balamuta <[email protected]>
212

313
* .github/workflows/pkgdown.yaml: Add github actions runner for pkgdown

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: RcppEnsmallen
22
Title: Header-Only C++ Mathematical Optimization Library for 'Armadillo'
3-
Version: 0.2.17.0.1
3+
Version: 0.2.18.0.1
44
Authors@R: c(
55
person("James Joseph", "Balamuta", email = "[email protected]",
66
role = c("aut", "cre", "cph"),
@@ -22,13 +22,13 @@ Description: 'Ensmallen' is a templated C++ mathematical optimization library
2222
'RcppArmadillo' (the 'Rcpp' bindings/bridge to 'Armadillo') is licensed under
2323
the GNU GPL version 2 or later. Thus, 'RcppEnsmallen' is also licensed under
2424
similar terms. Note that 'Ensmallen' requires a compiler that supports
25-
'C++11' and 'Armadillo' 8.400 or later.
25+
'C++11' and 'Armadillo' 9.800 or later.
2626
Depends: R (>= 3.3.0)
2727
License: GPL (>= 2)
2828
URL: https://github.com/coatless/rcppensmallen, https://github.com/mlpack/ensmallen, http://ensmallen.org/
2929
BugReports: https://github.com/coatless/rcppensmallen/issues
3030
Encoding: UTF-8
31-
LinkingTo: Rcpp, RcppArmadillo (>= 0.8.400.0.0)
31+
LinkingTo: Rcpp, RcppArmadillo (>= 0.9.800.0.0)
3232
Imports: Rcpp
3333
RoxygenNote: 7.1.1
3434
Roxygen: list(markdown = TRUE)

NEWS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# RcppEnsmallen 0.2.18.0.1
2+
3+
- Upgraded to ensmallen 2.18.0: "Fairmount Bagel" (2021-10-21)
4+
- Add gradient value clipping and gradient norm scaling callback
5+
(mlpack/ensmallen#315).
6+
- Remove superfluous CMake option to build the tests
7+
(mlpack/ensmallen#313).
8+
- Bump minimum Armadillo version to 9.800
9+
(mlpack/ensmallen#318).
10+
- Update Catch2 to 2.13.7
11+
(mlpack/ensmallen#322).
12+
- Remove redundant template argument for C++20 compatibility
13+
(mlpack/ensmallen#324).
14+
- Fix MOEAD test stability
15+
(mlpack/ensmallen#327).
16+
- Update GitHub Actions to the standard `r-lib/actions` configuration.
17+
([#45](https://github.com/coatless/rcppensmallen/pull/45))
18+
119
# RcppEnsmallen 0.2.17.0.1
220

321
- Upgraded to ensmallen 2.17.0: "Pachis Din Me Pesa Double" (2021-07-06)

inst/include/ensmallen.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
// Callbacks.
7575
#include "ensmallen_bits/callbacks/callbacks.hpp"
7676
#include "ensmallen_bits/callbacks/early_stop_at_min_loss.hpp"
77+
#include "ensmallen_bits/callbacks/grad_clip_by_norm.hpp"
78+
#include "ensmallen_bits/callbacks/grad_clip_by_value.hpp"
7779
#include "ensmallen_bits/callbacks/print_loss.hpp"
7880
#include "ensmallen_bits/callbacks/progress_bar.hpp"
7981
#include "ensmallen_bits/callbacks/query_front.hpp"

inst/include/ensmallen_bits/callbacks/early_stop_at_min_loss.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class EarlyStopAtMinLossType
3232
* @param patienceIn The number of epochs to wait after the minimum loss has
3333
* been reached or no improvement has been made (Default: 10).
3434
*/
35-
EarlyStopAtMinLossType<MatType>(const size_t patienceIn = 10) :
35+
EarlyStopAtMinLossType(const size_t patienceIn = 10) :
3636
callbackUsed(false),
3737
patience(patienceIn),
3838
bestObjective(std::numeric_limits<double>::max()),
@@ -47,7 +47,7 @@ class EarlyStopAtMinLossType
4747
* @param patienceIn The number of epochs to wait after the minimum loss has
4848
* been reached or no improvement has been made (Default: 10).
4949
*/
50-
EarlyStopAtMinLossType<MatType>(
50+
EarlyStopAtMinLossType(
5151
std::function<double(const MatType&)> func,
5252
const size_t patienceIn = 10)
5353
: callbackUsed(true),
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @file grad_clip_by_norm.hpp
3+
* @author Marcus Edel
4+
*
5+
* Clip the gradients by multiplying the unit vector of the gradients with the
6+
* threshold.
7+
*
8+
* ensmallen is free software; you may redistribute it and/or modify it under
9+
* the terms of the 3-clause BSD license. You should have received a copy of
10+
* the 3-clause BSD license along with ensmallen. If not, see
11+
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
12+
*/
13+
#ifndef ENSMALLEN_CALLBACKS_GRAD_CLIP_BY_NORM_HPP
14+
#define ENSMALLEN_CALLBACKS_GRAD_CLIP_BY_NORM_HPP
15+
16+
namespace ens {
17+
18+
/**
19+
* Clip the gradients by multiplying the unit vector of the gradients with the
20+
* threshold.
21+
*/
22+
class GradClipByNorm
23+
{
24+
public:
25+
/**
26+
* Set up the gradient clip by norm callback class with the maximum clipping
27+
* value.
28+
*
29+
* @param maxNorm The maximum clipping value.
30+
*/
31+
GradClipByNorm(const double maxNorm) : maxNorm(maxNorm)
32+
{ /* Nothing to do here. */ }
33+
34+
/**
35+
* Callback function called at any call to Gradient().
36+
*
37+
* @param optimizer The optimizer used to update the function.
38+
* @param function Function to optimize.
39+
* @param coordinates Starting point.
40+
* @param gradient Matrix that holds the gradient.
41+
*/
42+
template<typename OptimizerType, typename FunctionType, typename MatType>
43+
void Gradient(OptimizerType& /* optimizer */,
44+
FunctionType& /* function */,
45+
const MatType& /* coordinates */,
46+
MatType& gradient)
47+
{
48+
const double gradientNorm = arma::norm(gradient);
49+
if (gradientNorm > maxNorm)
50+
gradient = maxNorm * gradient / gradientNorm;
51+
}
52+
53+
private:
54+
//! The maximum clipping value for gradient clipping.
55+
const double maxNorm;
56+
};
57+
58+
} // namespace ens
59+
60+
#endif
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @file grad_clip_by_value.hpp
3+
* @author Marcus Edel
4+
*
5+
* Clips the gradient to a specified min and max.
6+
*
7+
* ensmallen is free software; you may redistribute it and/or modify it under
8+
* the terms of the 3-clause BSD license. You should have received a copy of
9+
* the 3-clause BSD license along with ensmallen. If not, see
10+
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
11+
*/
12+
#ifndef ENSMALLEN_CALLBACKS_GRAD_CLIP_BY_VALUE_HPP
13+
#define ENSMALLEN_CALLBACKS_GRAD_CLIP_BY_VALUE_HPP
14+
15+
namespace ens {
16+
17+
/**
18+
* Clip the gradient to a specified min and max.
19+
*/
20+
class GradClipByValue
21+
{
22+
public:
23+
/**
24+
* Set up the gradient clip by value callback class with the min and max
25+
* value.
26+
*
27+
* @param min The minimum value to clip to.
28+
* @param max The maximum value to clip to.
29+
*/
30+
GradClipByValue(const double min, const double max) : lower(min), upper(max)
31+
{ /* Nothing to do here. */ }
32+
33+
/**
34+
* Callback function called at any call to Gradient().
35+
*
36+
* @param optimizer The optimizer used to update the function.
37+
* @param function Function to optimize.
38+
* @param coordinates Starting point.
39+
* @param gradient Matrix that holds the gradient.
40+
*/
41+
template<typename OptimizerType, typename FunctionType, typename MatType>
42+
void Gradient(OptimizerType& /* optimizer */,
43+
FunctionType& /* function */,
44+
const MatType& /* coordinates */,
45+
MatType& gradient)
46+
{
47+
gradient = arma::clamp(gradient, lower, upper);
48+
}
49+
50+
private:
51+
//! The minimum value to clip to.
52+
const double lower;
53+
54+
//! The maximum value to clip to.
55+
const double upper;
56+
};
57+
58+
} // namespace ens
59+
60+
#endif

0 commit comments

Comments
 (0)