Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix size() and namespace lookups so that we can compile with C++17 #2641

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a31c257
fix ADL lookups and size() functions to all return same integral type
SteveBronder Jan 3, 2022
418a497
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 3, 2022
a51deac
update scalar_seq_view<T*>.size() to return Eigen::Index
SteveBronder Jan 3, 2022
8819e8e
Fix apply includes
SteveBronder Jan 3, 2022
4f4e954
update to use Rtools 4.0
SteveBronder Jan 3, 2022
26a5dc8
fix includes for opencl
SteveBronder Jan 3, 2022
470b62d
fix size namespace calls in test
SteveBronder Jan 4, 2022
9778fa6
Merge commit '46fa82de5489d0ddacae6bb33d4c450bde5eb939' into HEAD
yashikno Jan 4, 2022
39402ca
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 4, 2022
a169c6c
fix namespace qualifier for apply in cvodes_integrator
SteveBronder Jan 4, 2022
7a36db0
Merge remote-tracking branch 'origin/develop' into fix/allow-c17
SteveBronder Jan 6, 2022
c5e7916
fix scalar_seq_view val() compiler error
SteveBronder Jan 6, 2022
fdd8f69
fix ng_binomial_2_lccdf
SteveBronder Jan 7, 2022
b31c38e
update profiling to use forwarding for string value
SteveBronder Jan 11, 2022
bfc7cd9
Merge commit '1a447f26424a80f4cb5a053a1215a1a63c8b1ca6' into HEAD
yashikno Jan 11, 2022
0be15ed
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 11, 2022
6c9a9fb
fix some missing size() values
SteveBronder Jan 11, 2022
f5b3c10
Merge branch 'fix/allow-c17' of github.com:stan-dev/math into fix/all…
SteveBronder Jan 11, 2022
ab6a234
update fvar ops and partials
SteveBronder Jan 11, 2022
e187555
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 11, 2022
9fb0885
update fvar operands and partials
SteveBronder Jan 11, 2022
5f1c891
fixes for neg_binomial_2
SteveBronder Jan 12, 2022
8b67d21
Merge commit 'e15c69f777647c0884ab1ac807c9be9101cef641' into HEAD
yashikno Jan 12, 2022
7079421
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 12, 2022
c583774
fixes for neg_binomial_2
SteveBronder Jan 12, 2022
22034ef
fix expression test includes
SteveBronder Jan 13, 2022
99c5fed
Merge remote-tracking branch 'origin/develop' into fix/allow-c17
SteveBronder Mar 1, 2022
16a1b01
Merge remote-tracking branch 'upstream/develop' into fix/allow-c17
andrjohns Mar 12, 2022
4a0a164
Merge remote-tracking branch 'upstream/develop' into fix/allow-c17
andrjohns Mar 25, 2022
d2a9a8b
Update namespace qualifiers
andrjohns Mar 25, 2022
15a9477
Trigger CI
andrjohns Mar 26, 2022
242e440
Merge remote-tracking branch 'upstream/develop' into fix/allow-c17
andrjohns Mar 27, 2022
3d43abf
Test clang for leak-sanitizer
andrjohns Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 22 additions & 34 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Windows RTools 3.5
name: Windows RTools 4.0

on:
pull_request:
Expand All @@ -22,19 +22,17 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/develop'"

- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '2.x'
- name: Download RTools
run: Invoke-WebRequest -Uri https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe -OutFile ./R35.exe
- name: Install RTools
shell: powershell
run: Start-Process -FilePath ./R35.exe -ArgumentList /VERYSILENT -NoNewWindow -Wait
- name: PATH Setup
shell: powershell
run: echo "C:/Rtools/bin;C:/Rtools/mingw_64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- uses: r-lib/actions/setup-r@v1
with:
r-version: 'release'
- name: Set path for RTools 4.0
if: runner.os == 'Windows'
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Print g++ & make version and path
shell: powershell
run: |
Expand All @@ -56,7 +54,7 @@ jobs:
python.exe runTests.py -j2 test/unit/math/prim
python.exe runTests.py -j2 test/unit/math/rev
python.exe runTests.py -j2 test/unit/math/memory

- name: Upload gtest_output xml
uses: actions/upload-artifact@v2
if: failure()
Expand All @@ -72,14 +70,12 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: '2.x'
- name: Download RTools
run: Invoke-WebRequest -Uri https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe -OutFile ./R35.exe
- name: Install RTools
shell: powershell
run: Start-Process -FilePath ./R35.exe -ArgumentList /VERYSILENT -NoNewWindow -Wait
- name: PATH Setup
shell: powershell
run: echo "C:/Rtools/bin;C:/Rtools/mingw_64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- uses: r-lib/actions/setup-r@v1
with:
r-version: 'release'
- name: Set path for RTools 4.0
if: runner.os == 'Windows'
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Print g++ & make version and path
shell: powershell
run: |
Expand All @@ -93,9 +89,6 @@ jobs:
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Disable running fwd/mix tests
shell: powershell
run: echo "CXXFLAGS+= -DSTAN_MATH_TESTS_REV_ONLY" | Out-File -Append -FilePath make/local -Encoding utf8
- name: Run fwd unit tests and all the mix tests except those in mix/fun
shell: powershell
run: |
Expand All @@ -121,14 +114,12 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: '2.x'
- name: Download RTools
run: Invoke-WebRequest -Uri https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe -OutFile ./R35.exe
- name: Install RTools
shell: powershell
run: Start-Process -FilePath ./R35.exe -ArgumentList /VERYSILENT -NoNewWindow -Wait
- name: PATH Setup
shell: powershell
run: echo "C:/Rtools/bin;C:/Rtools/mingw_64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- uses: r-lib/actions/setup-r@v1
with:
r-version: 'release'
- name: Set path for RTools 4.0
if: runner.os == 'Windows'
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Print g++ & make version and path
shell: powershell
run: |
Expand All @@ -142,14 +133,11 @@ jobs:
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Disable running fwd/mix tests
shell: powershell
run: echo "CXXFLAGS+= -DSTAN_MATH_TESTS_REV_ONLY" | Out-File -Append -FilePath make/local -Encoding utf8
- name: Run mix/fun unit tests
shell: powershell
run: |
python.exe runTests.py test/unit/math/mix/fun

- name: Upload gtest_output xml
uses: actions/upload-artifact@v2
if: failure()
Expand Down
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ pipeline {
}
steps {
unstash 'MathSetup'
sh "echo CXXFLAGS += -fsanitize=address >> make/local"
sh "echo CXX=${CLANG_CXX} > make/local"
sh "echo CXXFLAGS += -fsanitize=address >> make/local"
script {
if (isUnix()) {
runTests("test/unit", false)
Expand Down
2 changes: 1 addition & 1 deletion make/compiler_flags
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_F


## setup compiler flags
CXXFLAGS_LANG ?= -std=c++1y
CXXFLAGS_LANG ?= -std=c++17
#CXXFLAGS_BOOST ?=
CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS)
#CXXFLAGS_GTEST
Expand Down
35 changes: 21 additions & 14 deletions stan/math/fwd/functor/operands_and_partials.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class operands_and_partials<Op1, Op2, Op3, Op4, Op5, fvar<Dx>> {
namespace internal {

// Vectorized Univariate
template <typename Dx>
class ops_partials_edge<Dx, std::vector<fvar<Dx>>> {
// std::vector<fvar<Dx>>
template <typename Dx, typename Op>
class ops_partials_edge<Dx, Op, require_std_vector_vt<is_fvar, Op>> {
public:
using Op = std::vector<fvar<Dx>>;
using partials_t = Eigen::Matrix<Dx, -1, 1>;
partials_t partials_; // For univariate use-cases
broadcast_array<partials_t> partials_vec_; // For multivariate
Expand All @@ -137,11 +137,12 @@ class ops_partials_edge<Dx, std::vector<fvar<Dx>>> {
}
};

template <typename Dx, int R, int C>
class ops_partials_edge<Dx, Eigen::Matrix<fvar<Dx>, R, C>> {
// Eigen::Matrix<fvar<Dx>, R, C>
template <typename Dx, typename Op>
class ops_partials_edge<Dx, Op, require_eigen_vt<is_fvar, Op>> {
public:
using partials_t = Eigen::Matrix<Dx, R, C>;
using Op = Eigen::Matrix<fvar<Dx>, R, C>;
using partials_t
= Eigen::Matrix<Dx, Op::RowsAtCompileTime, Op::ColsAtCompileTime>;
partials_t partials_; // For univariate use-cases
broadcast_array<partials_t> partials_vec_; // For multivariate
explicit ops_partials_edge(const Op& ops)
Expand All @@ -164,11 +165,15 @@ class ops_partials_edge<Dx, Eigen::Matrix<fvar<Dx>, R, C>> {
};

// Multivariate; vectors of eigen types
template <typename Dx, int R, int C>
class ops_partials_edge<Dx, std::vector<Eigen::Matrix<fvar<Dx>, R, C>>> {
// std::vector<Eigen::Matrix<fvar<Dx>, R, C>>
template <typename Dx, typename Op>
class ops_partials_edge<
Dx, Op,
require_all_t<is_std_vector<Op>, is_eigen<value_type_t<Op>>,
is_fvar<value_type_t<value_type_t<Op>>>>> {
public:
using Op = std::vector<Eigen::Matrix<fvar<Dx>, R, C>>;
using partial_t = Eigen::Matrix<Dx, R, C>;
using partial_t = Eigen::Matrix<Dx, value_type_t<Op>::RowsAtCompileTime,
value_type_t<Op>::ColsAtCompileTime>;
std::vector<partial_t> partials_vec_;
explicit ops_partials_edge(const Op& ops)
: partials_vec_(ops.size()), operands_(ops) {
Expand All @@ -193,10 +198,12 @@ class ops_partials_edge<Dx, std::vector<Eigen::Matrix<fvar<Dx>, R, C>>> {
}
};

template <typename Dx>
class ops_partials_edge<Dx, std::vector<std::vector<fvar<Dx>>>> {
template <typename Dx, typename Op>
class ops_partials_edge<
Dx, Op,
require_all_t<is_std_vector<Op>, is_std_vector<value_type_t<Op>>,
is_fvar<value_type_t<value_type_t<Op>>>>> {
public:
using Op = std::vector<std::vector<fvar<Dx>>>;
using partial_t = std::vector<Dx>;
std::vector<partial_t> partials_vec_;
explicit ops_partials_edge(const Op& ops)
Expand Down
4 changes: 3 additions & 1 deletion stan/math/opencl/kernel_generator/operation_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ class operation_cl : public operation_cl_base {
* expression.
* @return number of elements
*/
inline int size() const { return derived().rows() * derived().cols(); }
inline Eigen::Index size() const {
return derived().rows() * derived().cols();
}

/**
* Number of rows threads need to be launched for. For most expressions this
Expand Down
16 changes: 8 additions & 8 deletions stan/math/opencl/matrix_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class matrix_cl : public matrix_cl_base {

int cols() const { return cols_; }

int size() const { return rows_ * cols_; }
Eigen::Index size() const { return rows_ * cols_; }

const matrix_cl_view& view() const { return view_; }

Expand Down Expand Up @@ -283,7 +283,7 @@ class matrix_cl : public matrix_cl_base {
matrix_cl(const int rows, const int cols,
matrix_cl_view partial_view = matrix_cl_view::Entire)
: rows_(rows), cols_(cols), view_(partial_view) {
if (size() == 0) {
if (this->size() == 0) {
return;
}
cl::Context& ctx = opencl_context.context();
Expand Down Expand Up @@ -321,7 +321,7 @@ class matrix_cl : public matrix_cl_base {
matrix_cl_view partial_view = matrix_cl_view::Entire)
: rows_(A.rows()), cols_(A.cols()), view_(partial_view) {
using Mat_type = std::decay_t<ref_type_for_opencl_t<Mat>>;
if (size() == 0) {
if (this->size() == 0) {
return;
}
initialize_buffer_no_heap_if<
Expand Down Expand Up @@ -457,7 +457,7 @@ class matrix_cl : public matrix_cl_base {
return *this;
}
this->wait_for_read_write_events();
if (size() != a.size()) {
if (this->size() != a.size()) {
buffer_cl_ = cl::Buffer(opencl_context.context(), CL_MEM_READ_WRITE,
sizeof(T) * a.size());
}
Expand Down Expand Up @@ -518,7 +518,7 @@ class matrix_cl : public matrix_cl_base {
template <bool in_order = false>
cl::Event initialize_buffer(const T* A) {
cl::Event transfer_event;
if (size() == 0) {
if (this->size() == 0) {
return transfer_event;
}
cl::Context& ctx = opencl_context.context();
Expand All @@ -538,7 +538,7 @@ class matrix_cl : public matrix_cl_base {
template <bool in_order = false>
cl::Event initialize_buffer(T* A) {
cl::Event transfer_event;
if (size() == 0) {
if (this->size() == 0) {
return transfer_event;
}
cl::Context& ctx = opencl_context.context();
Expand Down Expand Up @@ -577,7 +577,7 @@ class matrix_cl : public matrix_cl_base {
*/
template <bool No_heap, typename U, std::enable_if_t<No_heap>* = nullptr>
void initialize_buffer_no_heap_if(U&& obj) {
if (size() == 0) {
if (this->size() == 0) {
return;
}
initialize_buffer(obj.data());
Expand All @@ -587,7 +587,7 @@ class matrix_cl : public matrix_cl_base {
template <bool No_heap, typename U, std::enable_if_t<!No_heap>* = nullptr>
void initialize_buffer_no_heap_if(U&& obj) {
using U_val = std::decay_t<ref_type_for_opencl_t<U>>;
if (size() == 0) {
if (this->size() == 0) {
return;
}
auto* obj_heap = new U_val(std::move(obj));
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/prim/bernoulli_cdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ return_type_t<T_prob_cl> bernoulli_cdf(const T_n_cl& n,

check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
const size_t N = is_n_vector ? size(n) : size(theta);
const size_t N = is_n_vector ? math::size(n) : math::size(theta);
if (N == 0) {
return 1.0;
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/prim/bernoulli_lccdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ return_type_t<T_prob_cl> bernoulli_lccdf(const T_n_cl& n,

check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
const size_t N = is_n_vector ? size(n) : size(theta);
const size_t N = is_n_vector ? math::size(n) : math::size(theta);
if (N == 0) {
return 0.0;
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/prim/bernoulli_lcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ return_type_t<T_prob_cl> bernoulli_lcdf(const T_n_cl& n,

check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
const size_t N = is_n_vector ? size(n) : size(theta);
const size_t N = is_n_vector ? math::size(n) : math::size(theta);
if (N == 0) {
return 0.0;
}
Expand Down
7 changes: 4 additions & 3 deletions stan/math/opencl/prim/bernoulli_logit_glm_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ return_type_t<T_x_cl, T_alpha_cl, T_beta_cl> bernoulli_logit_glm_lpmf(
const size_t M = x.cols();

if (is_y_vector) {
check_size_match(function, "Rows of ", "x", N, "rows of ", "y", size(y));
check_size_match(function, "Rows of ", "x", N, "rows of ", "y",
math::size(y));
}
check_size_match(function, "Columns of ", "x_cl", M, "size of ", "beta",
size(beta));
math::size(beta));
if (is_alpha_vector) {
check_size_match(function, "Rows of ", "x", N, "size of ", "alpha",
size(alpha));
math::size(alpha));
}

if (N == 0) {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/prim/bernoulli_logit_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ return_type_t<T_prob_cl> bernoulli_logit_lpmf(const T_n_cl& n,

check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
const size_t N = is_n_vector ? size(n) : size(theta);
const size_t N = is_n_vector ? math::size(n) : math::size(theta);
if (N == 0) {
return 0.0;
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/prim/bernoulli_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ return_type_t<T_prob_cl> bernoulli_lpmf(const T_n_cl& n,

check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
const size_t N = is_n_vector ? size(n) : size(theta);
const size_t N = is_n_vector ? math::size(n) : math::size(theta);
if (N == 0) {
return 0.0;
}
Expand Down
4 changes: 2 additions & 2 deletions stan/math/opencl/prim/categorical_logit_glm_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ return_type_t<T_x, T_alpha, T_beta> categorical_logit_glm_lpmf(
static const char* function = "categorical_logit_glm_lpmf";
if (is_y_vector) {
check_size_match(function, "Rows of ", "x", N_instances, "size of ", "y",
size(y));
math::size(y));
}
check_size_match(function, "Columns of ", "beta", N_classes, "size of ",
"alpha", size(alpha));
"alpha", math::size(alpha));
check_size_match(function, "Columns of ", "x", N_attributes, "Rows of",
"beta", beta.rows());

Expand Down
4 changes: 2 additions & 2 deletions stan/math/opencl/prim/cumulative_sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ inline auto cumulative_sum(T_vec&& v) {
= opencl_kernels::cumulative_sum<T_scal>::kernel1.get_option(
"LOCAL_SIZE_");
const int work_groups = std::min(
(v.size() + local_size - 1) / local_size,
static_cast<int>(
static_cast<Eigen::Index>((v.size() + local_size - 1) / local_size),
static_cast<Eigen::Index>(
opencl_context.device()[0].getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>())
* 16);
const int local_size2
Expand Down
9 changes: 5 additions & 4 deletions stan/math/opencl/prim/neg_binomial_2_log_glm_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ neg_binomial_2_log_glm_lpmf(const T_y_cl& y, const T_x_cl& x,
const size_t M = x.cols();

if (is_y_vector) {
check_size_match(function, "Rows of ", "x", N, "rows of ", "y", size(y));
check_size_match(function, "Rows of ", "x", N, "rows of ", "y",
math::size(y));
}
check_size_match(function, "Columns of ", "x", M, "size of ", "beta",
size(beta));
math::size(beta));
if (is_phi_vector) {
check_size_match(function, "Rows of ", "x", N, "size of ", "phi",
size(phi));
math::size(phi));
}
if (is_alpha_vector) {
check_size_match(function, "Rows of ", "x", N, "size of ", "alpha",
size(alpha));
math::size(alpha));
}
if (N == 0) {
return 0;
Expand Down
Loading