Skip to content

Fix pow(a,b) overload resolution under llvm19 #3110

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

Merged
merged 14 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 2 additions & 26 deletions make/compiler_flags
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,9 @@ INC_GTEST ?= -I $(GTEST)/include -I $(GTEST)
## setup precompiler options
CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS
CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS)
#CPPFLAGS_GTEST ?=
STAN_HAS_CXX17 ?= false
ifeq ($(CXX_TYPE), gcc)
GCC_GE_73 := $(shell [ $(CXX_MAJOR) -gt 7 -o \( $(CXX_MAJOR) -eq 7 -a $(CXX_MINOR) -ge 1 \) ] && echo true)
ifeq ($(GCC_GE_73),true)
STAN_HAS_CXX17 := true
endif
else ifeq ($(CXX_TYPE), clang)
CLANG_GE_5 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true)
ifeq ($(CLANG_GE_5),true)
STAN_HAS_CXX17 := true
endif
else ifeq ($(CXX_TYPE), mingw32-gcc)
MINGW_GE_50 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true)
ifeq ($(MINGW_GE_50),true)
STAN_HAS_CXX17 := true
endif
endif

ifeq ($(STAN_HAS_CXX17), true)
CXXFLAGS_LANG ?= -std=c++17
CXXFLAGS_STANDARD ?= c++17
else
$(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")
CXXFLAGS_LANG ?= -std=c++1y
CXXFLAGS_STANDARD ?= c++1y
endif
CXXFLAGS_LANG ?= -std=c++17
CXXFLAGS_STANDARD ?= c++17
#CXXFLAGS_BOOST ?=
CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS)
#CXXFLAGS_GTEST
Expand Down
90 changes: 90 additions & 0 deletions stan/math/fwd/fun/accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,97 @@
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun/sum.hpp>
#include <stan/math/prim/fun/accumulator.hpp>

#include <vector>
#include <type_traits>

namespace stan {
namespace math {
template <typename T, typename>
class accumulator;
/**
* Class to accumulate values and eventually return their sum. If
* no values are ever added, the return value is 0.
*
* This class is useful for speeding up autodiff of long sums
* because it uses the <code>sum()</code> operation (either from
* <code>stan::math</code> or one defined by argument-dependent lookup.
*
* @tparam T Type of scalar added
*/
template <typename T>
class accumulator<T, require_fvar_t<T>> {
private:
std::vector<T> buf_;

public:
/**
* Add the specified arithmetic type value to the buffer after
* static casting it to the class type <code>T</code>.
*
* <p>See the std library doc for <code>std::is_arithmetic</code>
* for information on what counts as an arithmetic type.
*
* @tparam S Type of argument
* @param x Value to add
*/
template <typename S, typename = require_stan_scalar_t<S>>
inline void add(S x) {
buf_.push_back(x);
}

/**
* Add each entry in the specified matrix, vector, or row vector
* of values to the buffer.
*
* @tparam S type of the matrix
* @param m Matrix of values to add
*/
template <typename S, require_matrix_t<S>* = nullptr>
inline void add(const S& m) {
buf_.push_back(stan::math::sum(m));
}

/**
* Recursively add each entry in the specified standard vector
* to the buffer. This will allow vectors of primitives,
* autodiff variables to be added; if the vector entries
* are collections, their elements are recursively added.
*
* @tparam S Type of value to recursively add.
* @param xs Vector of entries to add
*/
template <typename S>
inline void add(const std::vector<S>& xs) {
for (size_t i = 0; i < xs.size(); ++i) {
this->add(xs[i]);
}
}

#ifdef STAN_OPENCL

/**
* Sum each entry and then push to the buffer.
* @tparam S A Type inheriting from `matrix_cl_base`
* @param xs An OpenCL matrix
*/
template <typename S,
require_all_kernel_expressions_and_none_scalar_t<S>* = nullptr>
inline void add(const S& xs) {
buf_.push_back(stan::math::sum(xs));
}

#endif

/**
* Return the sum of the accumulated values.
*
* @return Sum of accumulated values.
*/
inline T sum() const { return stan::math::sum(buf_); }
};

} // namespace math
} // namespace stan

#endif
Loading