Skip to content

Commit 429dbc8

Browse files
committed
Merge remote-tracking branch 'origin/develop' into 5.0-breaking-changes
2 parents 76d2a05 + 4c626fd commit 429dbc8

46 files changed

Lines changed: 347 additions & 148 deletions

Some content is hidden

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

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ If this is a **feature request**, show what you expect to happen if the feature
2525

2626

2727
#### Current Version:
28-
v4.8.1
28+
v4.9.0

.github/workflows/main.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Windows Rtools40
1+
name: Windows Rtools44
22

33
on:
44
pull_request:
@@ -30,16 +30,16 @@ jobs:
3030
python-version: '3.x'
3131
- uses: r-lib/actions/setup-r@v2
3232
with:
33-
r-version: 4.1.3
33+
r-version: 'release'
34+
rtools-version: '44'
3435

35-
- name: Set path for Rtools40
36+
- name: Set path for Rtools44
3637
if: runner.os == 'Windows'
37-
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
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
3839

3940
- name: Build Math libs
4041
shell: powershell
4142
run: |
42-
Add-Content make\local "O=1`n"
4343
make -f make/standalone math-libs -j2
4444
- name: Add TBB to PATH
4545
shell: powershell
@@ -71,16 +71,16 @@ jobs:
7171
python-version: '3.x'
7272
- uses: r-lib/actions/setup-r@v2
7373
with:
74-
r-version: 4.1.3
74+
r-version: 'release'
75+
rtools-version: '44'
7576

76-
- name: Set path for Rtools40
77+
- name: Set path for Rtools44
7778
if: runner.os == 'Windows'
78-
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
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
7980

8081
- name: Build Math libs
8182
shell: powershell
8283
run: |
83-
Add-Content make\local "O=1`n"
8484
make -f make/standalone math-libs -j2
8585
- name: Add TBB to PATH
8686
shell: powershell
@@ -116,16 +116,16 @@ jobs:
116116
python-version: '3.x'
117117
- uses: r-lib/actions/setup-r@v2
118118
with:
119-
r-version: 4.1.3
119+
r-version: 'release'
120+
rtools-version: '44'
120121

121-
- name: Set path for Rtools40
122+
- name: Set path for Rtools44
122123
if: runner.os == 'Windows'
123-
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
124+
run: echo "C:/rtools44/usr/bin;C:/rtools44/x86_64-w64-mingw32.static.posix/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
124125

125126
- name: Build Math libs
126127
shell: powershell
127128
run: |
128-
Add-Content make\local "O=1`n"
129129
make -f make/standalone math-libs -j2
130130
- name: Add TBB to PATH
131131
shell: powershell
@@ -156,11 +156,12 @@ jobs:
156156
python-version: '3.x'
157157
- uses: r-lib/actions/setup-r@v2
158158
with:
159-
r-version: 4.1.3
159+
r-version: 'release'
160+
rtools-version: '44'
160161

161-
- name: Set path for Rtools40
162+
- name: Set path for Rtools44
162163
if: runner.os == 'Windows'
163-
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
164+
run: echo "C:/rtools44/usr/bin;C:/rtools44/x86_64-w64-mingw32.static.posix/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
164165

165166
- name: Build Math libs
166167
shell: powershell

Jenkinsfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.stan.Utils
55
def runTests(String testPath, boolean jumbo = false) {
66
try {
77
sh "cat make/local"
8+
sh "make print-compiler-flags"
89
if (jumbo && !params.disableJumbo) {
910
sh "python3 runTests.py -j${env.PARALLEL} ${testPath} --jumbo --debug"
1011
} else {
@@ -142,8 +143,8 @@ pipeline {
142143
}
143144
post {
144145
always {
145-
recordIssues(
146-
enabledForFailure: true,
146+
recordIssues(
147+
enabledForFailure: true,
147148
tools: [cppLint(),groovyScript(parserId: 'mathDependencies', pattern: '**/dependencies.log')]
148149
)
149150
deleteDir()
@@ -575,7 +576,7 @@ pipeline {
575576
always {
576577
node("linux") {
577578
recordIssues(
578-
enabledForFailure: false,
579+
enabledForFailure: false,
579580
tool: clang()
580581
)
581582
}

RELEASE-NOTES.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
Stan Math Library Release Notes
22

3+
======================================================================
4+
v4.9.0 (3 June 2024)
5+
======================================================================
6+
7+
- Stan now detects if your compiler supports C++17 and will issue a warning if it is not available. Support for pre-C++17 compilers may be removed as early as next version. (#3063)
8+
- Added a new distribution: `wiener_full_lpdf`. (#2822)
9+
- Replaced `static const` objects with `static constexpr` when available. (#2830)
10+
- Gradients for the `hypergeometric_pFq` function rewritten for increased speed and stability. (#2961)
11+
- Added the Hypergeometric 1F0 function and gradients. (#2962)
12+
- Removed macro usage in the definitions of the `require_` templates. (#2965)
13+
- Added a sparse matrix implimentation for `arena_matrix`. (#2971)
14+
- Added hand-calculated derivatives for the multivariate normal lpdf. (#2980)
15+
- Added derivatives for the `multi_student_t_cholesky_lpdf`. (#2990)
16+
- Added constrain function for creating matrices holding row or column simplexes. (#2992)
17+
- Updated TBB Windows build rules for compatibility with RTools make. (#2999)
18+
- Improved efficiency of `von_mises_lpdf` gradient calculation, credit to @venpopov. (#3010)
19+
- Fixed a few additional issues in checking the inputs to distributions defined over cholesky matrices. (#3012)
20+
- Functions which are wrappers around CVODES and IDAS routines from Sundials now throw `domain_error`, rather than a mix of `domain_error` and `runtime_error`. (#3013)
21+
- Fixed the stack_allocator being able to return non-8-byte aligned pointers. (#3014)
22+
- Upgrade bundled Boost headers to 1.84. (#3001, #3018, #3019)
23+
- Fixed a bug where `linspaced_array` was returning its results truncated to integers. (#3023)
24+
- Fixed the return type of `max(int, int)` being a double. (#3024)
25+
- Added 'override' to built-in make variables. (#3028)
26+
- Maded `sqrt(x)` have a finite gradient at `x=0`. Allows `distance(x,y)` to work for `x=y` too. (#3033)
27+
- Improved stability of the `von_mises_lpdf` function to avoid numeric overflow. Now it's no longer necessary to use the normal_lpdf for kappa>100, allowing vectorizing of the likelihood. (#3036)
28+
- Updated the `weibull_cdf` and `weibull_lcdf` functions for numerical stability as well as correct handling of `y == 0.0`. (#3037)
29+
- Improved speed of `inv_Phi` and `std_normal_qf` functions. (#3046)
30+
- Fixed spurious linker issue with `csr_matrix_times_vector`. (#3048, #3053)
31+
- Improved error messages when variables dimensions do not match in operations that require it. (#3049)
32+
- Added support for Windows ARM64 with RTools ARM64 toolchain. (#3051)
33+
- Fixed `clean-all` error when using external SUNDIALS libraries. (#3054)
34+
- Fixed several small floating-point accuracy issues with ARM64 platforms. (#3059)
35+
- The RNGs for the multinomial and multinomial_logit distributions now accept a zero total count, resulting in a zero integer vector. (#3061)
36+
- Fixed a data race in profiling in multiple threads. (#3066)
37+
- Backported SUNDIALS bugfix for hashmap integer overflow. (#3072)
38+
339
======================================================================
440
v4.8.1 (23 January 2024)
541
======================================================================

doxygen/contributor_help_pages/developer_doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ These are the more common make flags that could be set:
184184
These are the rest of the variables that can be set:
185185

186186
- C++ compiler flags
187-
- `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++1y`
187+
- `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++17`
188188
- `CXXFLAGS_WARNINGS`: compiler options to squash compiler warnings
189189
- `CXXFLAGS_BOOST`: Boost-specific compiler flags
190190
- `CXXFLAGS_EIGEN`: Eigen-specific compiler flags

doxygen/doxygen.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "Stan Math Library"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 4.8.1
51+
PROJECT_NUMBER = 4.9.0
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

lib/sundials_6.1.1/STAN_CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file documents changes done for the stan-math project
2+
3+
- Backported bugfix for hashmap int overflow on Windows (https://github.com/LLNL/sundials/pull/421)

lib/sundials_6.1.1/src/sundials/sundials_hashmap.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef _SUNDIALS_HASHMAP_H
2121
#define _SUNDIALS_HASHMAP_H
2222

23+
#include <stdint.h>
2324
#include <string.h>
2425
#include <stdlib.h>
2526

@@ -30,10 +31,10 @@
3031
This is a 64-bit implementation of the 'a' modification of the
3132
Fowler–Noll–Vo hash (i.e., FNV1-a).
3233
*/
33-
static unsigned long fnv1a_hash(const char* str)
34+
static uint64_t fnv1a_hash(const char* str)
3435
{
35-
const unsigned long prime = 14695981039346656037U; /* prime */
36-
unsigned long hash = 1099511628211U; /* offset basis */
36+
const uint64_t prime = 14695981039346656037U; /* prime */
37+
uint64_t hash = 1099511628211U; /* offset basis */
3738
char c;
3839
while ((c = *str++))
3940
hash = (hash^c) * prime;

make/compiler_flags

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ endif
1717

1818
## Set OS specific library filename extensions
1919
ifeq ($(OS),Windows_NT)
20-
WINARM64 := $(shell echo | $(CXX) -E -dM - | findstr __aarch64__)
2120
LIBRARY_SUFFIX ?= .dll
21+
STR_SEARCH ?= findstr
2222
endif
2323

2424
ifeq ($(OS),Darwin)
2525
LIBRARY_SUFFIX ?= .dylib
26+
STR_SEARCH ?= grep
2627
endif
2728

2829
ifeq ($(OS),Linux)
2930
LIBRARY_SUFFIX ?= .so
31+
STR_SEARCH ?= grep
3032
endif
3133

3234
## Set default compiler
@@ -42,6 +44,11 @@ ifeq (default,$(origin CXX))
4244
endif
4345
endif
4446

47+
ARM64_CHECK := $(shell echo | $(CXX) -E -dM - | $(STR_SEARCH) __aarch64__)
48+
ifneq ($(ARM64_CHECK),)
49+
ARM64 = true
50+
endif
51+
4552
# Detect compiler type
4653
# - CXX_TYPE: {gcc, clang, mingw32-gcc, other}
4754
# - CXX_MAJOR: major version of CXX
@@ -63,7 +70,6 @@ CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion 2>&1)
6370
CXX_MAJOR := $(word 1,$(subst ., ,$(CXX_VERSION)))
6471
CXX_MINOR := $(word 2,$(subst ., ,$(CXX_VERSION)))
6572

66-
6773
################################################################################
6874
# Set optional compiler flags for performance
6975
#
@@ -114,10 +120,32 @@ INC_GTEST ?= -I $(GTEST)/include -I $(GTEST)
114120
CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS
115121
CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS)
116122
#CPPFLAGS_GTEST ?=
123+
STAN_HAS_CXX17 ?= false
124+
ifeq ($(CXX_TYPE), gcc)
125+
GCC_GE_73 := $(shell [ $(CXX_MAJOR) -gt 7 -o \( $(CXX_MAJOR) -eq 7 -a $(CXX_MINOR) -ge 1 \) ] && echo true)
126+
ifeq ($(GCC_GE_73),true)
127+
STAN_HAS_CXX17 := true
128+
endif
129+
else ifeq ($(CXX_TYPE), clang)
130+
CLANG_GE_5 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true)
131+
ifeq ($(CLANG_GE_5),true)
132+
STAN_HAS_CXX17 := true
133+
endif
134+
else ifeq ($(CXX_TYPE), mingw32-gcc)
135+
MINGW_GE_50 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true)
136+
ifeq ($(MINGW_GE_50),true)
137+
STAN_HAS_CXX17 := true
138+
endif
139+
endif
117140

118-
119-
## setup compiler flags
120-
CXXFLAGS_LANG ?= -std=c++1y
141+
ifeq ($(STAN_HAS_CXX17), true)
142+
CXXFLAGS_LANG ?= -std=c++17
143+
CXXFLAGS_STANDARD ?= c++17
144+
else
145+
$(warning "Stan cannot detect if your compiler has the C++17 standard. If it does, please set STAN_HAS_CXX17=true in your make/local file. C++17 support is mandatory in the next release of Stan. Defaulting to C++14")
146+
CXXFLAGS_LANG ?= -std=c++1y
147+
CXXFLAGS_STANDARD ?= c++1y
148+
endif
121149
#CXXFLAGS_BOOST ?=
122150
CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS)
123151
#CXXFLAGS_GTEST
@@ -154,6 +182,7 @@ ifeq ($(OS),Windows_NT)
154182
CXXFLAGS_WARNINGS ?= -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes
155183
CPPFLAGS_GTEST ?= -DGTEST_HAS_PTHREAD=0
156184
CPPFLAGS_OS ?= -D_USE_MATH_DEFINES
185+
CPPFLAGS_OS += -D_GLIBCXX11_USE_C99_COMPLEX
157186
## Detecting Process Bitness:
158187
## http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx
159188
ifeq ($(PROCESSOR_ARCHITECTURE)$(PROCESSOR_ARCHITEW6432),x86)
@@ -164,7 +193,7 @@ ifeq ($(OS),Windows_NT)
164193

165194
make/ucrt:
166195
pound := \#
167-
UCRT_STRING := $(shell echo '$(pound)include <windows.h>' | $(CXX) -E -dM - | findstr _UCRT)
196+
UCRT_STRING := $(shell echo '$(pound)include <windows.h>' | $(CXX) -E -dM - | $(STR_SEARCH) _UCRT)
168197
ifneq (,$(UCRT_STRING))
169198
IS_UCRT ?= true
170199
else
@@ -211,8 +240,16 @@ endif
211240
## makes reentrant version lgamma_r available from cmath
212241
CXXFLAGS_OS += -D_REENTRANT
213242

243+
ifeq ($(ARM64), true)
244+
CXXFLAGS_OS += -ffp-contract=off
245+
endif
246+
214247
## silence warnings occuring due to the TBB and Eigen libraries
215248
CXXFLAGS_WARNINGS += -Wno-ignored-attributes
249+
## https://github.com/oneapi-src/oneTBB/issues/307
250+
ifeq ($(CXX_TYPE), gcc)
251+
CXXFLAGS_WARNINGS += -Wno-class-memaccess
252+
endif
216253

217254
################################################################################
218255
# Setup OpenCL
@@ -272,13 +309,19 @@ CXXFLAGS_TBB ?= -I $(TBB_INC)
272309
else
273310
CXXFLAGS_TBB ?= -I $(TBB)/include
274311
endif
275-
LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" -Wl,--disable-new-dtags
312+
313+
# MacOS ld does not support --disable-new-dtags
314+
ifneq ($(OS),Darwin)
315+
LDFLAGS_TBB_DTAGS ?= -Wl,--disable-new-dtags
316+
endif
276317

277318
# Windows LLVM/Clang does not support -rpath, but is not needed on Windows anyway
278-
ifeq ($(WINARM64),)
279-
LDFLAGS_TBB += -Wl,-rpath,"$(TBB_LIB)"
319+
ifneq ($(OS), Windows_NT)
320+
LDFLAGS_TBB_RPATH ?= -Wl,-rpath,"$(TBB_LIB)"
280321
endif
281322

323+
LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" $(LDFLAGS_TBB_DTAGS) $(LDFLAGS_TBB_RPATH)
324+
282325
LDLIBS_TBB ?= -ltbb
283326

284327
else
@@ -299,7 +342,7 @@ CXXFLAGS_TBB ?= -I $(TBB)/include
299342
LDFLAGS_TBB ?= -Wl,-L,"$(TBB_BIN_ABSOLUTE_PATH)" $(LDFLAGS_FLTO_FLTO) $(LDFLAGS_OPTIM_TBB)
300343

301344
# Windows LLVM/Clang does not support -rpath, but is not needed on Windows anyway
302-
ifeq ($(WINARM64),)
345+
ifneq ($(OS), Windows_NT)
303346
LDFLAGS_TBB += -Wl,-rpath,"$(TBB_BIN_ABSOLUTE_PATH)"
304347
endif
305348
LDLIBS_TBB ?= -ltbb

make/libraries

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ ifeq (Windows_NT, $(OS))
141141
TBB_CXXFLAGS += -D_UCRT
142142
endif
143143
# TBB does not have assembly code for Windows ARM64, so we need to use GCC builtins
144-
ifneq ($(WINARM64),)
145-
TBB_CXXFLAGS += -DTBB_USE_GCC_BUILTINS
146-
CXXFLAGS_TBB += -DTBB_USE_GCC_BUILTINS
147-
endif
144+
ifeq ($(ARM64),true)
145+
TBB_CXXFLAGS += -DTBB_USE_GCC_BUILTINS
146+
CXXFLAGS_TBB += -DTBB_USE_GCC_BUILTINS
147+
WINARM64 = true
148+
endif
148149
SH_CHECK := $(shell command -v sh 2>/dev/null)
149150
ifdef SH_CHECK
150151
WINDOWS_HAS_SH ?= true
@@ -175,11 +176,11 @@ endif
175176
$(TBB_BIN)/tbb.def: $(TBB_BIN)/tbb-make-check
176177
@mkdir -p $(TBB_BIN)
177178
touch $(TBB_BIN)/version_$(notdir $(TBB))
178-
tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y CXXFLAGS="$(TBB_CXXFLAGS)"
179+
tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=$(CXXFLAGS_STANDARD) CXXFLAGS="$(TBB_CXXFLAGS)"
179180

180181
$(TBB_BIN)/tbbmalloc.def: $(TBB_BIN)/tbb-make-check
181182
@mkdir -p $(TBB_BIN)
182-
tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y malloc CXXFLAGS="$(TBB_CXXFLAGS)"
183+
tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=$(CXXFLAGS_STANDARD) malloc CXXFLAGS="$(TBB_CXXFLAGS)"
183184

184185
$(TBB_BIN)/libtbb.dylib: $(TBB_BIN)/tbb.def
185186
$(TBB_BIN)/libtbbmalloc.dylib: $(TBB_BIN)/tbbmalloc.def

0 commit comments

Comments
 (0)