Skip to content

Commit

Permalink
Fix std::make_unique use in AnyODE
Browse files Browse the repository at this point in the history
  • Loading branch information
bjodah committed Sep 4, 2017
1 parent a0fbbf9 commit cdd085c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 38 deletions.
7 changes: 4 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
build:
image: bjodah/bjodahimg16dev:latest
image: bjodah/bjodahimg16dev:v1.3
environment:
- PYCVODES_LAPACK=lapack,blas
commands:
- ./scripts/ci.sh pycvodes
- cd tests/; make; cd -
- cd tests/; make CXX=clang++ EXTRA_FLAGS=-fsanitize=address -B; cd -
- cd tests/; make CXX=clang++ EXTRA_FLAGS=-fsanitize=undefined -B; cd -
- cd tests/; make EXTRA_FLAGS=-DNDEBUG; cd -
- cd tests/; make CXX=clang++-5.0 EXTRA_FLAGS=-fsanitize=address -B; cd -
- cd tests/; make CXX=clang++-5.0 EXTRA_FLAGS=-fsanitize=undefined -B; cd -
- (cd examples/; ipython2 nbconvert --to=html --ExecutePreprocessor.enabled=True --ExecutePreprocessor.timeout=300 *.ipynb)
- (cd examples/; ../scripts/render_index.sh *.html)
- python3 -m pip install --user -e .[docs]
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.8.1
======
- Explicit use of std::make_unique from the C++14 standard.

v0.8.0
======
- Use new (templated) AnyODE.
Expand Down
29 changes: 1 addition & 28 deletions external/anyode/include/anyode/anyode_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,13 @@
namespace AnyODE {

#ifdef NDEBUG
#if __cplusplus >= 201402L
using std::make_unique;
#else
template <class T, class ...Args>
typename std::enable_if
<
!std::is_array<T>::value,
std::unique_ptr<T>
>::type
make_unique(Args&& ...args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

template <class T>
typename std::enable_if
<
std::is_array<T>::value,
std::unique_ptr<T>
>::type
make_unique(std::size_t n)
{
typedef typename std::remove_extent<T>::type RT;
return std::unique_ptr<T>(new RT[n]);
}
#endif

template<typename T> using buffer_t = std::unique_ptr<T[]>;
template<typename T> using buffer_ptr_t = T*;
template<typename T> constexpr T* buffer_get_raw_ptr(buffer_t<T>& buf) {
return buf.get();
}
template<typename T> inline constexpr buffer_t<T> buffer_factory(std::size_t n) {
return make_unique<T[]>(n);
return std::make_unique<T[]>(n);
}

#else
Expand Down
9 changes: 4 additions & 5 deletions external/anyode/include/anyode/anyode_iterative.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <anyode/anyode.hpp>
#include <anyode/anyode_blas_lapack.hpp> // dgemv, dgesvd
#include <anyode/anyode_matrix.hpp> // DenseMatrix
#include <anyode/anyode_buffer.hpp> // make_unique
#include <anyode/anyode_decomposition.hpp> // SVD

namespace AnyODE {
Expand All @@ -29,7 +28,7 @@ namespace AnyODE {
auto status = AnyODE::Status::success;
const int ny = this->get_ny();
if (m_jac_cache == nullptr){
m_jac_cache = make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
m_jac_cache = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
}
status = this->dense_jac_cmaj(t, y, fy, m_jac_cache->m_data, m_jac_cache->m_ld);
m_jac_cache->dot_vec(vec, out);
Expand All @@ -49,7 +48,7 @@ namespace AnyODE {
ignore(gamma);
// See "Preconditioning (Jacobian data)" in cvs_guide.pdf (4.6.10 for 2.7.0)
if (m_jac_cache == nullptr)
m_jac_cache = make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
m_jac_cache = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);

if (jac_ok){
jac_recomputed = false;
Expand All @@ -58,9 +57,9 @@ namespace AnyODE {
jac_recomputed = true;
}
if (m_M_cache == nullptr)
m_M_cache = make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
m_M_cache = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
m_M_cache->set_to_eye_plus_scaled_mtx(-gamma, *m_jac_cache);
m_decomp_cache = make_unique<Decomp_t>(m_M_cache.get());
m_decomp_cache = std::make_unique<Decomp_t>(m_M_cache.get());
m_decomp_cache->factorize();
m_nprec_setup++;
return status;
Expand Down
4 changes: 2 additions & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test: test_cvodes_anyode test_cvodes_anyode_autorestart test_cvodes_anyode_svd t
./test_cvodes_anyode_svd --abortx 1
./test_cvodes_cxx --abortx 1
./test_sundials_cxx --abortx 1
ifeq ($(CXX),clang++)
ifeq ($(CXX),clang++-5.0)
@echo "skipping openmp when using clang"
else
./test_cvodes_anyode_parallel --abortx 1
Expand All @@ -34,7 +34,7 @@ test_%: test_%.cpp ../pycvodes/include/cvodes_cxx.hpp catch.hpp
$(CXX) $(CXXFLAGS) $(INCLUDE) $(DEFINES) -o $@ $< $(LIBS)

test_cvodes_anyode_parallel: test_cvodes_anyode_parallel.cpp ../pycvodes/include/cvodes_*.hpp catch.hpp
ifeq ($(CXX),clang++)
ifeq ($(CXX),clang++-5.0)
@echo "skipping openmp when using clang"
else
$(CXX) $(CXXFLAGS) $(OPENMP_FLAG) $(INCLUDE) $(DEFINES) -o $@ $< $(LIBS) $(OPENMP_LIB)
Expand Down

0 comments on commit cdd085c

Please sign in to comment.