Skip to content

Commit 2c71c06

Browse files
committed
Merge commit '0f1ad25835e12bfeccb357db4323ec35841fa837' into HEAD
2 parents 87bf545 + 0f1ad25 commit 2c71c06

42 files changed

Lines changed: 826 additions & 577 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yml

Lines changed: 54 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Windows Rtools44
1+
# Note that the workflows below use Powershell (pwsh) as they were originally written for Windows runners.
2+
name: Rtools & ARM64 CI
23

34
on:
45
pull_request:
@@ -20,101 +21,28 @@ concurrency:
2021

2122
jobs:
2223
prim-rev:
23-
name: prim and rev tests
24-
runs-on: windows-latest
24+
name: ${{ matrix.config.label }} tests (${{ matrix.os }})
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
os: [windows-latest, ubuntu-24.04-arm]
30+
config: [
31+
{ label: misc, tests: 'test/unit/*_test.cpp test/unit/math/*_test.cpp test/unit/math/memory' },
32+
{ label: prim, tests: 'test/unit/math/prim' },
33+
{ label: rev, tests: 'test/unit/math/rev' },
34+
{ label: fwd, tests: 'test/unit/math/fwd' },
35+
{ label: 'non-fun mix', tests: 'test/unit/math/mix/core test/unit/math/mix/meta test/unit/math/mix/*_test.cpp' }
36+
]
2537

2638
steps:
2739
- uses: actions/checkout@v4
2840
- uses: actions/setup-python@v5
2941
with:
3042
python-version: '3.x'
31-
- uses: r-lib/actions/setup-r@v2
32-
with:
33-
r-version: 'release'
34-
rtools-version: '44'
3543

36-
- name: Set path for Rtools44
37-
if: runner.os == 'Windows'
38-
run: echo "C:/rtools44/usr/bin;C:/rtools44/x86_64-w64-mingw32.static.posix/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
39-
40-
- name: Build Math libs
41-
shell: powershell
42-
run: |
43-
make -f make/standalone math-libs -j2
44-
- name: Add TBB to PATH
45-
shell: powershell
46-
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
47-
- name: Run prim and rev unit tests
48-
shell: powershell
49-
run: |
50-
python.exe runTests.py -j2 test/unit/*_test.cpp
51-
python.exe runTests.py -j2 test/unit/math/*_test.cpp
52-
python.exe runTests.py -j2 test/unit/math/prim
53-
python.exe runTests.py -j2 test/unit/math/rev
54-
python.exe runTests.py -j2 test/unit/math/memory
55-
56-
- name: Upload gtest_output xml
57-
uses: actions/upload-artifact@v4
58-
if: failure()
59-
with:
60-
name: gtest_outputs_xml
61-
path: '**/*_test.xml'
62-
63-
fwd-non-fun-mix:
64-
name: fwd tests and non-fun mix tests
65-
runs-on: windows-latest
66-
67-
steps:
68-
- uses: actions/checkout@v4
69-
- uses: actions/setup-python@v5
70-
with:
71-
python-version: '3.x'
7244
- uses: r-lib/actions/setup-r@v2
73-
with:
74-
r-version: 'release'
75-
rtools-version: '44'
76-
77-
- name: Set path for Rtools44
7845
if: runner.os == 'Windows'
79-
run: echo "C:/rtools44/usr/bin;C:/rtools44/x86_64-w64-mingw32.static.posix/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
80-
81-
- name: Build Math libs
82-
shell: powershell
83-
run: |
84-
make -f make/standalone math-libs -j2
85-
- name: Add TBB to PATH
86-
shell: powershell
87-
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
88-
- name: Disable running fwd/mix tests
89-
shell: powershell
90-
run: echo "CXXFLAGS+= -DSTAN_MATH_TESTS_REV_ONLY" | Out-File -Append -FilePath make/local -Encoding utf8
91-
- name: Run fwd unit tests and all the mix tests except those in mix/fun
92-
shell: powershell
93-
run: |
94-
python.exe runTests.py test/unit/math/fwd -j2
95-
python.exe runTests.py test/unit/math/mix/core -j2
96-
python.exe runTests.py test/unit/math/mix/functor -j2
97-
python.exe runTests.py test/unit/math/mix/meta -j2
98-
python.exe runTests.py test/unit/math/mix/prob -j2
99-
python.exe runTests.py test/unit/math/mix/*_test.cpp -j2
100-
101-
- name: Upload gtest_output xml
102-
uses: actions/upload-artifact@v4
103-
if: failure()
104-
with:
105-
name: gtest_outputs_xml
106-
path: '**/*_test.xml'
107-
108-
mix-fun-1:
109-
name: mix/fun tests 1
110-
runs-on: windows-latest
111-
112-
steps:
113-
- uses: actions/checkout@v4
114-
- uses: actions/setup-python@v5
115-
with:
116-
python-version: '3.x'
117-
- uses: r-lib/actions/setup-r@v2
11846
with:
11947
r-version: 'release'
12048
rtools-version: '44'
@@ -124,19 +52,20 @@ jobs:
12452
run: echo "C:/rtools44/usr/bin;C:/rtools44/x86_64-w64-mingw32.static.posix/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
12553

12654
- name: Build Math libs
127-
shell: powershell
55+
shell: pwsh
12856
run: |
57+
Add-Content make\local "CPPFLAGS=-w -Wno-psabi -Wno-misleading-indentation`n"
12958
make -f make/standalone math-libs -j2
59+
13060
- name: Add TBB to PATH
131-
shell: powershell
61+
if: runner.os == 'Windows'
62+
shell: pwsh
13263
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
133-
- name: Run mix/fun unit tests
134-
shell: powershell
64+
65+
- name: Run ${{ matrix.config.label }} unit tests
66+
shell: pwsh
13567
run: |
136-
$MixFunTests = Get-ChildItem -Path test\unit\math\mix\fun\* -Include *.cpp | Resolve-Path -Relative
137-
$NumberTests = $MixFunTests.Length
138-
$HalfNumberTests = [math]::Floor($NumberTests / 2)
139-
python.exe runTests.py $MixFunTests[0..$HalfNumberTests]
68+
python runTests.py -j4 ${{ matrix.config.tests }}
14069
14170
- name: Upload gtest_output xml
14271
uses: actions/upload-artifact@v4
@@ -145,16 +74,23 @@ jobs:
14574
name: gtest_outputs_xml
14675
path: '**/*_test.xml'
14776

148-
mix-fun-2:
149-
name: mix/fun tests 2
150-
runs-on: windows-latest
77+
mix-fun:
78+
name: mix fun and prob tests ${{ matrix.group }} (${{ matrix.os }})
79+
runs-on: ${{ matrix.os }}
80+
strategy:
81+
fail-fast: false
82+
matrix:
83+
os: [windows-latest, ubuntu-24.04-arm]
84+
group: [1, 2, 3, 4, 5]
15185

15286
steps:
15387
- uses: actions/checkout@v4
15488
- uses: actions/setup-python@v5
15589
with:
15690
python-version: '3.x'
91+
15792
- uses: r-lib/actions/setup-r@v2
93+
if: runner.os == 'Windows'
15894
with:
15995
r-version: 'release'
16096
rtools-version: '44'
@@ -164,20 +100,32 @@ jobs:
164100
run: echo "C:/rtools44/usr/bin;C:/rtools44/x86_64-w64-mingw32.static.posix/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
165101

166102
- name: Build Math libs
167-
shell: powershell
103+
shell: pwsh
168104
run: |
169-
Add-Content make\local "O=1`n"
105+
Add-Content make\local "CPPFLAGS=-w -Wno-psabi -Wno-misleading-indentation`n"
170106
make -f make/standalone math-libs -j2
107+
171108
- name: Add TBB to PATH
172-
shell: powershell
109+
if: runner.os == 'Windows'
110+
shell: pwsh
173111
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
112+
174113
- name: Run mix/fun unit tests
175-
shell: powershell
114+
shell: pwsh
176115
run: |
177-
$MixFunTests = Get-ChildItem -Path test\unit\math\mix\fun\* -Include *.cpp | Resolve-Path -Relative
178-
$NumberTests = $MixFunTests.Length
179-
$HalfNumberTests = [math]::Floor($NumberTests / 2)
180-
python.exe runTests.py $MixFunTests[($HalfNumberTests + 1)..($NumberTests - 1)]
116+
$MixFunProbTests = Get-ChildItem -Path test\unit\math\mix\fun\*, test\unit\math\mix\prob\* -Include *.cpp | Resolve-Path -Relative
117+
$NumberTests = $MixFunProbTests.Length
118+
$FifthNumberTests = [math]::Floor($NumberTests / 5)
119+
120+
$MixFunProbTestsArray = @( `
121+
$MixFunProbTests[0..($FifthNumberTests - 1)], `
122+
$MixFunProbTests[$FifthNumberTests..(2 * $FifthNumberTests - 1)], `
123+
$MixFunProbTests[(2 * $FifthNumberTests)..(3 * $FifthNumberTests - 1)], `
124+
$MixFunProbTests[(3 * $FifthNumberTests)..(4 * $FifthNumberTests - 1)], `
125+
$MixFunProbTests[(4 * $FifthNumberTests)..($NumberTests - 1)] `
126+
)
127+
128+
python runTests.py -j2 $MixFunProbTestsArray[(${{ matrix.group }} - 1)]
181129
182130
- name: Upload gtest_output xml
183131
uses: actions/upload-artifact@v4

stan/math/prim/constraint/cholesky_corr_constrain.hpp

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ cholesky_corr_constrain(const EigVec& y, int K) {
4343
}
4444

4545
// FIXME to match above after debugged
46-
template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
46+
template <typename EigVec, typename Lp,
47+
require_eigen_vector_t<EigVec>* = nullptr,
48+
require_convertible_t<return_type_t<EigVec>, Lp>* = nullptr>
4749
inline Eigen::Matrix<value_type_t<EigVec>, Eigen::Dynamic, Eigen::Dynamic>
48-
cholesky_corr_constrain(const EigVec& y, int K, return_type_t<EigVec>& lp) {
50+
cholesky_corr_constrain(const EigVec& y, int K, Lp& lp) {
4951
using Eigen::Dynamic;
5052
using Eigen::Matrix;
5153
using std::sqrt;
@@ -75,28 +77,39 @@ cholesky_corr_constrain(const EigVec& y, int K, return_type_t<EigVec>& lp) {
7577
}
7678

7779
/**
78-
* Return The cholesky of a `KxK` correlation matrix. If the `Jacobian`
79-
* parameter is `true`, the log density accumulator is incremented with the log
80-
* absolute Jacobian determinant of the transform. All of the transforms are
81-
* specified with their Jacobians in the *Stan Reference Manual* chapter
82-
* Constraint Transforms.
83-
* @tparam Jacobian if `true`, increment log density accumulator with log
84-
* absolute Jacobian determinant of constraining transform
85-
* @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with
86-
* inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows
87-
* and 1 column
80+
* Return The cholesky of a `KxK` correlation matrix.
81+
* This overload handles looping over the elements of a standard vector.
82+
* @tparam T A standard vector with inner type inheriting from
83+
* `Eigen::DenseBase` or a `var_value` with inner type inheriting from
84+
* `Eigen::DenseBase` with compile time dynamic rows and 1 column
85+
* @param y Linearly Serialized vector of size `(K * (K - 1))/2` holding the
86+
* column major order elements of the lower triangurlar
87+
* @param K The size of the matrix to return
88+
*/
89+
template <typename T, require_std_vector_t<T>* = nullptr>
90+
inline auto cholesky_corr_constrain(const T& y, int K) {
91+
return apply_vector_unary<T>::apply(
92+
y, [K](auto&& v) { return cholesky_corr_constrain(v, K); });
93+
}
94+
95+
/**
96+
* Return The cholesky of a `KxK` correlation matrix.
97+
* This overload handles looping over the elements of a standard vector.
98+
* @tparam T A standard vector with inner type inheriting from
99+
* `Eigen::DenseBase` or a `var_value` with inner type inheriting from
100+
* `Eigen::DenseBase` with compile time dynamic rows and 1 column
101+
* @tparam Lp Scalar type for the lp argument. The scalar type of T should be
102+
* convertable to this.
88103
* @param y Linearly Serialized vector of size `(K * (K - 1))/2` holding the
89104
* column major order elements of the lower triangurlar
90105
* @param K The size of the matrix to return
91106
* @param[in,out] lp log density accumulator
92107
*/
93-
template <bool Jacobian, typename T, require_not_std_vector_t<T>* = nullptr>
94-
inline auto cholesky_corr_constrain(const T& y, int K, return_type_t<T>& lp) {
95-
if (Jacobian) {
96-
return cholesky_corr_constrain(y, K, lp);
97-
} else {
98-
return cholesky_corr_constrain(y, K);
99-
}
108+
template <typename T, typename Lp, require_std_vector_t<T>* = nullptr,
109+
require_convertible_t<return_type_t<T>, Lp>* = nullptr>
110+
inline auto cholesky_corr_constrain(const T& y, int K, Lp& lp) {
111+
return apply_vector_unary<T>::apply(
112+
y, [&lp, K](auto&& v) { return cholesky_corr_constrain(v, K, lp); });
100113
}
101114

102115
/**
@@ -107,19 +120,24 @@ inline auto cholesky_corr_constrain(const T& y, int K, return_type_t<T>& lp) {
107120
* Constraint Transforms.
108121
* @tparam Jacobian if `true`, increment log density accumulator with log
109122
* absolute Jacobian determinant of constraining transform
110-
* @tparam T A standard vector with inner type inheriting from
111-
* `Eigen::DenseBase` or a `var_value` with inner type inheriting from
112-
* `Eigen::DenseBase` with compile time dynamic rows and 1 column
123+
* @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with
124+
* inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows
125+
* and 1 column, or a standard vector thereof
126+
* @tparam Lp A scalar type for the lp argument. The scalar type of T should be
127+
* convertable to this.
113128
* @param y Linearly Serialized vector of size `(K * (K - 1))/2` holding the
114129
* column major order elements of the lower triangurlar
115130
* @param K The size of the matrix to return
116131
* @param[in,out] lp log density accumulator
117132
*/
118-
template <bool Jacobian, typename T, require_std_vector_t<T>* = nullptr>
119-
inline auto cholesky_corr_constrain(const T& y, int K, return_type_t<T>& lp) {
120-
return apply_vector_unary<T>::apply(y, [&lp, K](auto&& v) {
121-
return cholesky_corr_constrain<Jacobian>(v, K, lp);
122-
});
133+
template <bool Jacobian, typename T, typename Lp,
134+
require_convertible_t<return_type_t<T>, Lp>* = nullptr>
135+
inline auto cholesky_corr_constrain(const T& y, int K, Lp& lp) {
136+
if constexpr (Jacobian) {
137+
return cholesky_corr_constrain(y, K, lp);
138+
} else {
139+
return cholesky_corr_constrain(y, K);
140+
}
123141
}
124142

125143
} // namespace math

stan/math/prim/constraint/cholesky_corr_free.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ namespace stan {
1111
namespace math {
1212

1313
template <typename T, require_eigen_t<T>* = nullptr>
14-
auto cholesky_corr_free(const T& x) {
14+
inline auto cholesky_corr_free(const T& x) {
1515
using Eigen::Dynamic;
1616
using Eigen::Matrix;
17+
using std::sqrt;
1718

1819
check_square("cholesky_corr_free", "x", x);
1920
// should validate lower-triangular, unit lengths
@@ -24,9 +25,9 @@ auto cholesky_corr_free(const T& x) {
2425
int k = 0;
2526
for (int i = 1; i < x.rows(); ++i) {
2627
z.coeffRef(k++) = corr_free(x_ref.coeff(i, 0));
27-
double sum_sqs = square(x_ref.coeff(i, 0));
28+
auto sum_sqs = square(x_ref.coeff(i, 0));
2829
for (int j = 1; j < i; ++j) {
29-
z.coeffRef(k++) = corr_free(x_ref.coeff(i, j) / std::sqrt(1.0 - sum_sqs));
30+
z.coeffRef(k++) = corr_free(x_ref.coeff(i, j) / sqrt(1.0 - sum_sqs));
3031
sum_sqs += square(x_ref.coeff(i, j));
3132
}
3233
}
@@ -41,7 +42,7 @@ auto cholesky_corr_free(const T& x) {
4142
* @param x The standard vector to untransform.
4243
*/
4344
template <typename T, require_std_vector_t<T>* = nullptr>
44-
auto cholesky_corr_free(const T& x) {
45+
inline auto cholesky_corr_free(const T& x) {
4546
return apply_vector_unary<T>::apply(
4647
x, [](auto&& v) { return cholesky_corr_free(v); });
4748
}

0 commit comments

Comments
 (0)