Skip to content

Commit

Permalink
Merge branch 'a-mutant' into 'master'
Browse files Browse the repository at this point in the history
A mutant

See merge request correaa/boost-multi!1293
  • Loading branch information
correaa committed Nov 27, 2024
2 parents 76e6e6a + 95f44d9 commit 325ded9
Show file tree
Hide file tree
Showing 14 changed files with 802 additions and 760 deletions.
7 changes: 3 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ clang++ mull:
allow_failure: true
script:
- apt-get -qq update
- apt-get -qq install --no-install-recommends -y --quiet curl wget ca-certificates g++ clang-11 make libboost-timer-dev libboost-serialization-dev libblas-dev libfftw3-dev liblapack-dev pkg-config
- apt-get -qq install --no-install-recommends -y --quiet gnupg curl wget ca-certificates g++ clang-11 make libboost-timer-dev libboost-serialization-dev libblas-dev libfftw3-dev liblapack-dev pkg-config
- wget --no-verbose -O cmake-install.sh https://github.com/Kitware/CMake/releases/download/v3.30.0-rc4/cmake-3.30.0-rc4-linux-`arch`.sh # for CMAKE_TEST_LAUNCHER
- sh cmake-install.sh --skip-license --prefix=/usr
- cmake --version
Expand All @@ -229,12 +229,11 @@ clang++ mull:
- apt-get -qq install --no-install-recommends -y --quiet mull-11 libclang-cpp11
- mkdir build && cd build
- mull-runner-11 --version
- CXX=clang++-11 cmake .. -DCMAKE_CXX_FLAGS="-O1 -fexperimental-new-pass-manager -fpass-plugin=/usr/lib/mull-ir-frontend-11 -g -grecord-command-line -fprofile-instr-generate -fcoverage-mapping" -DCMAKE_TEST_LAUNCHER="mull-runner-11;--strict;--ld-search-path=/lib/x86_64-linux-gnu"
- CXX=clang++-11 cmake .. -DCMAKE_CXX_FLAGS="-O3 -DNDEBUG -fexperimental-new-pass-manager -fpass-plugin=/usr/lib/mull-ir-frontend-11 -g -grecord-command-line -fprofile-instr-generate -fcoverage-mapping"
- cmake --build . --parallel 2 || cmake --build . --parallel 1 --verbose
# - mull-runner-11 --strict ./test/swap.cpp.x
- ctest -j 2 --output-on-failure --verbose
- cd test
- ls *.x | xargs -n 1 sh -c 'mull-runner-11 $0 || exit 255'
- ls *.x | xargs -n 1 sh -c 'echo $0 && ((mull-runner-11 --ld-search-path=/usr/lib/x86_64-linux-gnu $0 -test-program=ctest -- -j2) || exit 255)'
needs: ["clang++"]

# deb:
Expand Down
55 changes: 23 additions & 32 deletions include/boost/multi/array_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ struct elements_iterator_t // NOLINT(cppcoreguidelines-special-member-functions
return *this;
}
BOOST_MULTI_HD constexpr auto operator-=(difference_type n) -> elements_iterator_t& {
auto const nn = std::apply(xs_, ns_);
ns_ = xs_.from_linear(nn - n);
// auto const nn = std::apply(xs_, ns_);
// ns_ = xs_.from_linear(nn - n);
n_ -= n;
return *this;
}
Expand All @@ -784,7 +784,7 @@ struct elements_iterator_t // NOLINT(cppcoreguidelines-special-member-functions
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // TODO(correaa) use checked span
#endif

BOOST_MULTI_HD /*[[gnu::pure]]*/ constexpr auto operator-(elements_iterator_t const& other) const -> difference_type {
BOOST_MULTI_HD constexpr auto operator-(elements_iterator_t const& other) const -> difference_type {
assert(base_ == other.base_ && l_ == other.l_);
return n_ - other.n_;
}
Expand Down Expand Up @@ -2335,13 +2335,6 @@ struct array_iterator<Element, 1, Ptr, IsConst, IsMove> // NOLINT(fuchsia-multi
static constexpr dimensionality_type rank_v = 1;
using rank = std::integral_constant<dimensionality_type, rank_v>;

constexpr auto operator<(array_iterator const& other) const -> bool {
assert(other.stride_ == stride_);
assert((ptr_ - other.ptr_)%stride_ == 0);
return (ptr_ - other.ptr_)/stride_ < 0;
// return distance_to_(other) > 0;
}

BOOST_MULTI_HD explicit constexpr array_iterator(Ptr ptr, typename const_subarray<Element, 1, Ptr>::index stride)
: ptr_{ptr}, stride_{stride} {}

Expand Down Expand Up @@ -2398,18 +2391,18 @@ struct array_iterator<Element, 1, Ptr, IsConst, IsMove> // NOLINT(fuchsia-multi
return this->ptr_ == other.ptr_;
}

template<bool OtherIsConst, std::enable_if_t<OtherIsConst != IsConst, int> =0> // NOLINT(modernize-use-constraints) TODO(correaa) for C++20
template<bool OtherIsConst, std::enable_if_t<OtherIsConst != IsConst, int> =0> // NOLINT(modernize-use-constraints) for C++20
constexpr auto operator==(array_iterator<Element, 1, Ptr, OtherIsConst> const& other) const -> bool {
assert(this->stride_ == other.stride_);
assert(stride_ != 0);
return this->ptr_ == other.ptr_;
}

// constexpr auto operator!=(array_iterator<Element, 1, Ptr, true> const& other) const -> bool {
// assert(this->stride_ == other.stride_);
// return this->ptr_ != other.ptr_;
// }

// friend constexpr auto operator==(array_iterator const& self, array_iterator const& other) -> bool {return self.ptr_ == other.ptr_;}
constexpr auto operator<(array_iterator const& other) const -> bool {
assert(other.stride_ == stride_);
assert(stride_ != 0);
return (stride_>=0)?(ptr_ < other.ptr_):(other.ptr_ < ptr_);
}

BOOST_MULTI_HD constexpr auto operator*() const -> decltype(auto) {
if constexpr(IsMove) {
Expand Down Expand Up @@ -2881,13 +2874,13 @@ struct const_subarray<T, 1, ElementPtr, Layout> // NOLINT(fuchsia-multiple-inhe
}

private:
constexpr auto strided_aux_(difference_type diff) const -> const_subarray {
constexpr auto strided_aux_(difference_type diff) const {
auto const new_layout = typename types::layout_t{this->layout().sub(), this->layout().stride()*diff, this->layout().offset(), this->layout().nelems()};
return {new_layout, types::base_};
return subarray<T, 1, ElementPtr, Layout>(new_layout, types::base_);
}

public:
constexpr auto strided(difference_type diff) const& -> basic_const_array { return strided_aux_(diff);}
constexpr auto strided(difference_type diff) const& -> const_subarray { return strided_aux_(diff);}

BOOST_MULTI_HD constexpr auto sliced(index first, index last, difference_type stride) const& -> basic_const_array { return sliced(first, last).strided(stride); }
// BOOST_MULTI_HD constexpr auto sliced(index first, index last, difference_type stride) && -> const_subarray { return sliced(first, last).strided(stride); }
Expand Down Expand Up @@ -3755,30 +3748,28 @@ constexpr auto operator/(RandomAccessIterator data, multi::extensions_t<D> exten
-> multi::array_ptr<typename std::iterator_traits<RandomAccessIterator>::value_type, D, RandomAccessIterator>
{return {data, extensions};}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // TODO(correaa) use checked span
#endif

template<class In, class T, dimensionality_type N, class TP, class = std::enable_if_t<(N > 1)>, class = decltype((void)adl_begin(*In{}), adl_end(*In{}))>
constexpr auto uninitialized_copy
// require N>1 (this is important because it forces calling placement new on the pointer
(In first, In last, multi::array_iterator<T, N, TP> dest) {

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // TODO(correaa) use checked span
#endif

while(first != last) { // NOLINT(altera-unroll-loops) TODO(correaa) consider using an algorithm
adl_uninitialized_copy(adl_begin(*first), adl_end(*first), adl_begin(*dest));
++first;
++dest;
}

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

return dest;
}

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

// begin and end for forwarding reference are needed in this namespace
// to overwrite the behavior of std::begin and std::end
// which take rvalue-references as const-references.
Expand Down
25 changes: 14 additions & 11 deletions include/boost/multi/detail/adl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ template<class T, class InputIt, class Size, class ForwardIt>
constexpr auto alloc_uninitialized_copy_n(std::allocator<T>& /*alloc*/, InputIt first, Size count, ForwardIt d_first) {
return adl_uninitialized_copy_n(first, count, d_first);}

template<class T, class InputIt, class Size, class ForwardIt>
constexpr auto alloc_uninitialized_move_n(std::allocator<T>& /*alloc*/, InputIt first, Size count, ForwardIt d_first) {
return adl_uninitialized_move_n(first, count, d_first);}
// template<class T, class InputIt, class Size, class ForwardIt>
// constexpr auto alloc_uninitialized_move_n(std::allocator<T>& /*alloc*/, InputIt first, Size count, ForwardIt d_first) {
// return adl_uninitialized_move_n(first, count, d_first);}

template<class Alloc, class InputIt, class Size, class ForwardIt, class = decltype(std::addressof(*ForwardIt{}))>
auto alloc_uninitialized_copy_n(Alloc& alloc, InputIt first, Size count, ForwardIt d_first) {
Expand All @@ -387,14 +387,16 @@ auto alloc_uninitialized_copy_n(Alloc& alloc, InputIt first, Size count, Forward
}
}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // TODO(correaa) use checked span
#endif

template<class Alloc, class InputIt, class Size, class ForwardIt>
auto alloc_uninitialized_move_n(Alloc& alloc, InputIt first, Size count, ForwardIt d_first) {
ForwardIt current = d_first;
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // TODO(correaa) use checked span
#endif

try {
for(; count > 0; ++first, ++current, --count) { // NOLINT(altera-unroll-loops) TODO(correaa) consider using an algorithm
std::allocator_traits<Alloc>::construct(alloc, std::addressof(*current), std::move(*first));
Expand All @@ -406,11 +408,12 @@ auto alloc_uninitialized_move_n(Alloc& alloc, InputIt first, Size count, Forward
}
throw;
}
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

template<class T, class InputIt, class ForwardIt>
constexpr auto alloc_uninitialized_copy(std::allocator<T>&/*allocator*/, InputIt first, InputIt last, ForwardIt d_first) {
return adl_uninitialized_copy(first, last, d_first);
Expand Down
4 changes: 2 additions & 2 deletions include/boost/multi/detail/tuple_zip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ template<class T0, class... Ts> class tuple<T0, Ts...> : tuple<Ts...> { // NOLI
return this->at_aux_(priority<1>{}, idx);
}

template<std::size_t N, std::enable_if_t<(N==0), int> =0>
template<std::size_t N, std::enable_if_t<(N==0), int> =0> // NOLINT(modernize-use-constraints) for C++20
constexpr auto get() const& -> T0 const& { // NOLINT(readability-identifier-length) std naming
return head();
}

template<std::size_t N, std::enable_if_t<(N!=0), int> =0>
template<std::size_t N, std::enable_if_t<(N!=0), int> =0> // NOLINT(modernize-use-constraints) for C++20
constexpr auto get() const& -> auto const& { // NOLINT(readability-identifier-length) std naming
return this->tail().template get<N - 1>(); // this-> for msvc 19.14 compilation
}
Expand Down
34 changes: 19 additions & 15 deletions include/boost/multi/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ struct move_ptr : private std::move_iterator<Ptr> {
using std::move_iterator<Ptr>::move_iterator;

BOOST_MULTI_HD constexpr /*implicit*/ operator Ptr() const {return std::move_iterator<Ptr>::base();} // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) // NOSONAR(cpp:S1709) decay to lvalue should be easy
BOOST_MULTI_HD constexpr auto operator+=(difference_type n) -> move_ptr& {static_cast<std::move_iterator<Ptr>&>(*this) += n; return *this;}
BOOST_MULTI_HD constexpr auto operator-=(difference_type n) -> move_ptr& {static_cast<std::move_iterator<Ptr>&>(*this) -= n; return *this;}
BOOST_MULTI_HD constexpr auto operator+=(difference_type n) -> move_ptr& { static_cast<std::move_iterator<Ptr>&>(*this) += n; return *this; }
BOOST_MULTI_HD constexpr auto operator-=(difference_type n) -> move_ptr& { static_cast<std::move_iterator<Ptr>&>(*this) -= n; return *this; }

BOOST_MULTI_HD constexpr auto operator+(difference_type n) const -> move_ptr {move_ptr ret{*this}; ret += n; return ret;}
BOOST_MULTI_HD constexpr auto operator-(difference_type n) const -> move_ptr {move_ptr ret{*this}; ret -= n; return ret;}
BOOST_MULTI_HD constexpr auto operator+(difference_type n) const -> move_ptr { move_ptr ret{*this}; ret += n; return ret; }
BOOST_MULTI_HD constexpr auto operator-(difference_type n) const -> move_ptr { move_ptr ret{*this}; ret -= n; return ret; }

BOOST_MULTI_HD constexpr auto operator-(move_ptr const& other) const -> difference_type {return static_cast<std::move_iterator<Ptr> const&>(*this) - static_cast<std::move_iterator<Ptr> const&>(other);}
BOOST_MULTI_HD constexpr auto operator-(move_ptr const& other) const -> difference_type { return static_cast<std::move_iterator<Ptr> const&>(*this) - static_cast<std::move_iterator<Ptr> const&>(other); }

constexpr auto operator*() const -> decltype(auto) {return *static_cast<std::move_iterator<Ptr> const&>(*this);}
BOOST_MULTI_HD constexpr auto operator[](difference_type n) const -> decltype(auto) {return *((*this) + n);}
BOOST_MULTI_HD constexpr auto operator<(move_ptr const& other) const -> bool { return static_cast<std::move_iterator<Ptr> const&>(*this) < static_cast<std::move_iterator<Ptr> const&>(other); }

BOOST_MULTI_HD constexpr auto operator==(move_ptr const& other) const -> bool {return static_cast<std::move_iterator<Ptr> const&>(*this) == static_cast<std::move_iterator<Ptr> const&>(other);}
BOOST_MULTI_HD constexpr auto operator!=(move_ptr const& other) const -> bool {return static_cast<std::move_iterator<Ptr> const&>(*this) != static_cast<std::move_iterator<Ptr> const&>(other);}
constexpr auto operator*() const -> decltype(auto) { return *static_cast<std::move_iterator<Ptr> const&>(*this); }
BOOST_MULTI_HD constexpr auto operator[](difference_type n) const -> decltype(auto) { return *((*this) + n); }

BOOST_MULTI_HD constexpr auto operator==(move_ptr const& other) const -> bool { return static_cast<std::move_iterator<Ptr> const&>(*this) == static_cast<std::move_iterator<Ptr> const&>(other); }
BOOST_MULTI_HD constexpr auto operator!=(move_ptr const& other) const -> bool { return static_cast<std::move_iterator<Ptr> const&>(*this) != static_cast<std::move_iterator<Ptr> const&>(other); }
};

template<class T> struct ref_add_const {using type = T const;}; // this is not the same as std::add_const
Expand Down Expand Up @@ -119,15 +121,17 @@ struct transform_ptr {
#pragma clang diagnostic pop
#endif

constexpr auto operator+(difference_type n) const -> transform_ptr {transform_ptr ret{*this}; ret += n; return ret;}
constexpr auto operator-(difference_type n) const -> transform_ptr {transform_ptr ret{*this}; ret -= n; return ret;}
constexpr auto operator+(difference_type n) const -> transform_ptr { transform_ptr ret{*this}; ret += n; return ret; }
constexpr auto operator-(difference_type n) const -> transform_ptr { transform_ptr ret{*this}; ret -= n; return ret; }

constexpr auto operator-(transform_ptr const& other) const -> difference_type { return p_ - other.p_; }

constexpr auto operator-(transform_ptr const& other) const -> difference_type {return p_ - other.p_;}
constexpr auto operator[](difference_type n) const -> reference { return *((*this) + n); } // NOLINT(readability-const-return-type) transformed_view might return by const value.

constexpr auto operator[](difference_type n) const -> reference {return *((*this) + n);} // NOLINT(readability-const-return-type) transformed_view might return by const value.
constexpr auto operator==(transform_ptr const& other) const -> bool { return p_ == other.p_; }
constexpr auto operator!=(transform_ptr const& other) const -> bool { return p_ != other.p_; }

constexpr auto operator==(transform_ptr const& other) const -> bool {return p_ == other.p_;}
constexpr auto operator!=(transform_ptr const& other) const -> bool {return p_ != other.p_;}
constexpr auto operator<(transform_ptr const& other) const -> bool { return p_ < other.p_; }

private:
Ptr p_;
Expand Down
15 changes: 6 additions & 9 deletions mull.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# mutators:
# - cxx_all
excludePaths:
- doctest.h
# - gtest
# - gmock
#timeout: # milliseconds
# - 10000 # 10 seconds
# quiet: false # enables additional logging
mutators:
- cxx_add_assign_to_sub_assign # Replaces += with -=
- cxx_add_to_sub # Replaces + with -
- cxx_mul_to_div # Replaces / with *
timeout: 10000 # in milliseconds
quiet: true # enables additional logging
Loading

0 comments on commit 325ded9

Please sign in to comment.