Skip to content

Commit

Permalink
add mull
Browse files Browse the repository at this point in the history
  • Loading branch information
alfC committed Dec 19, 2024
1 parent 0514951 commit 74166cf
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 160 deletions.
4 changes: 2 additions & 2 deletions include/boost/multi/detail/index_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class range {
}
return begin() + (value - front());
}
template<class Value> [[nodiscard]] constexpr auto contains(Value const& value) const -> bool { return (value >= first_) && (value < last_); }
template<class Value> [[nodiscard]] constexpr auto contains(Value const& value) const -> bool { return (first_ <= value) && (value < last_); }
template<class Value> [[nodiscard]] constexpr auto count(Value const& value) const -> value_type { return contains(value); }

friend constexpr auto intersection(range const& self, range const& other) {
Expand All @@ -220,7 +220,7 @@ class range {
new_first = min(new_first, new_last);
return range<decltype(new_first), decltype(new_last)>(new_first, new_last);
}
[[nodiscard]] constexpr auto contains(value_type const& value) const { return value >= first_ && value < last_; }
// [[nodiscard]] constexpr auto contains(value_type const& value) const { return (first_ <= value) && (value < last_); }
};

template<typename IndexType, typename IndexTypeLast = IndexType> // , class Plus = std::plus<>, class Minus = std::minus<> >
Expand Down
2 changes: 1 addition & 1 deletion include/boost/multi/detail/static_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class static_allocator { // NOSONAR(cpp:S4963) this allocator has special seman
auto allocate([[maybe_unused]] std::size_t n) -> pointer {
assert(n <= N);
assert(!dirty_); // do not attempt to resize a vector with static_allocator
dirty_ = true;
// dirty_ = true;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align" // buffer_ is aligned as T
return reinterpret_cast<pointer>(&buffer_); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
Expand Down
5 changes: 4 additions & 1 deletion mull.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
mutators:
- cxx_add_assign_to_sub_assign # Replaces += with -=
- cxx_add_to_sub # Replaces + with -
- cxx_and_assign_to_or_assign # Replaces &= with |=
- cxx_and_to_or # Replaces & with |
- cxx_assign_const # Replaces `a = b` with `a = 42`
- cxx_mul_to_div # Replaces / with *
- cxx_lt_to_le # Replaces < with <=
timeout: 10000 # in milliseconds
quiet: true # enables additional logging
quiet: true # additional logging?
2 changes: 1 addition & 1 deletion pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if [[ $(uname -m) != 'arm64' ]]; then
export VALGRIND_EXE="valgrind --trace-children=yes --leak-check=full --track-origins=yes --show-leak-kinds=all --suppressions=.valgrind_suppressions --gen-suppressions=all --error-exitcode=1 "

(mkdir -p .build.g++ && cd .build.g++ && CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && cmake --build . && ctest --parallel 2 --output-on-failure) || exit 666
(mkdir -p .build.clang++.mull && cd .build.clang++.mull && CXX=clang++-14 cmake .. -DCMAKE_CXX_FLAGS="-O1 -fpass-plugin=/usr/lib/mull-ir-frontend-14 -g -grecord-command-line -fprofile-instr-generate -fcoverage-mapping" -DCMAKE_TEST_LAUNCHER="mull-runner-14;--strict;--ld-search-path=/usr/lib/x86_64-linux-gnu" && cmake --build . && (ls test/*.x | xargs -n 1 sh -c 'echo $0 && ((mull-runner-14 $0 -test-program=ctest -- -j2 --stop-on-failure) || exit 255)') ) || exit 666
(mkdir -p .build.circle && cd .build.circle && CXX="$HOME/bin/circle" cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_CXX_STANDARD=20 -DDISABLE_MPI=1 -DENABLE_CIRCLE=1 -DCMAKE_THREAD_LIBS_INIT="-lpthread" && cmake --build . && ctest --parallel --output-on-failure --rerun-failed) || exit 666
(mkdir -p .build.clang++-rel && cd .build.clang++-rel && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . && ctest --parallel 2 --output-on-failure) || exit 666
(mkdir -p .build.clang++ && cd .build.clang++ && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Debug && cmake --build . && ctest --parallel 2 --output-on-failure) || exit 666
Expand All @@ -46,7 +47,6 @@ export VALGRIND_EXE="valgrind --trace-children=yes --leak-check=full --track-ori
(mkdir -p .build.culang && cd .build.culang && cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_CUDA=1 -DCMAKE_CUDA_COMPILER=clang++ -DCMAKE_CUDA_HOST_COMPILER=clang++ -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CUDA_ARCHITECTURES=75 && cmake --build . && ctest --parallel --output-on-failure --rerun-failed) || exit 666
(mkdir -p .build.g++.plus && cd .build.g++.plus && CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 -DBLA_VENDOR=OpenBLAS `#-DCMAKE_CXX_CPPCHECK="cppcheck;--enable=all;--suppress=missingIncludeSystem;--inline-suppr;--std=c++17;--checkers-report=cppcheck.report;--error-exitcode=1"` -DCMAKE_CXX_FLAGS="-D_GLIBCXX_DEBUG=1" -DCMAKE_CXX_FLAGS="-fimplicit-constexpr -fanalyzer -Wno-analyzer-null-dereference -Wno-analyzer-possible-null-dereference -Wno-analyzer-malloc-leak -Wno-analyzer-use-of-uninitialized-value -Wno-analyzer-use-after-free" && cmake --build . && ctest --parallel --output-on-failure -T memcheck) || exit 666
(mkdir -p .build.clang++.plus && cd .build.clang++.plus && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 -DBLA_VENDOR=Generic -DCMAKE_CXX_CLANG_TIDY="clang-tidy" `#-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="iwyu;-Xiwyu;--mapping_file=/home/correaa/boost-multi/.iwyu-test.imp;-Xiwyu;--no_fwd_decls"` && cmake --build . && ASAN_OPTIONS="new_delete_type_mismatch=0" ctest --parallel --output-on-failure) || exit 666
(mkdir -p .build.clang++.mull && cd .build.clang++.mull && CXX=clang++-14 cmake .. -DCMAKE_CXX_FLAGS="-O1 -fpass-plugin=/usr/lib/mull-ir-frontend-14 -g -grecord-command-line -fprofile-instr-generate -fcoverage-mapping" -DCMAKE_TEST_LAUNCHER="mull-runner-14;--strict;--ld-search-path=/usr/lib/x86_64-linux-gnu" && cmake --build . && (ls test/*.x | xargs -n 1 sh -c 'echo $0 && ((mull-runner-14 $0 -test-program=ctest -- -j2 --stop-on-failure) || exit 255)') ) || exit 666
#(mkdir -p .build.hip && cd .build.hip && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ -DCMAKE_CXX_FLAGS="-DMULTI_USE_HIP" -DCMAKE_HIP_FLAGS="-DMULTI_USE_HIP" -DENABLE_HIP=1 -DCMAKE_HIP_ARCHITECTURES=gfx90a && cmake --build . ) || exit 666
#(mkdir -p .build.g++-.cov && cd .build.g++-.cov && CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="--coverage -lgcov -fno-inline -fno-inline-small-functions -fno-default-inline" -DCMAKE_EXE_LINKER_FLAGS="-lgcov --coverage" && cmake --build . && ASAN_OPTIONS="new_delete_type_mismatch=0" ctest -j 12 --output-on-failure -T Test `# && lcov --directory . --capture --output-file coverage.info && lcov --remove coverage.info '/usr/*' --output-file coverage.info && lcov --list coverage.info && genhtml coverage.info`) || exit 666

Expand Down
56 changes: 30 additions & 26 deletions test/array_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ BOOST_AUTO_TEST_CASE(array_ref_from_carray) {
BOOST_TEST( &mar[1][1] == &arr[1][1] );

mar[1][1] = 90;
BOOST_TEST( mar[1][1] == 90 );
BOOST_TEST( &mar[1][1] == &arr[1][1] );

auto const& a_const = arr;
Expand Down Expand Up @@ -658,20 +659,21 @@ BOOST_AUTO_TEST_CASE(array_ref_1D) {

BOOST_AUTO_TEST_CASE(array_ref_original_tests_carray) {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) test legacy type
double darr[4][5] = {
{1.0, 2.0},
{2.0, 3.0},
int darr[4][5] = {
{1, 2},
{2, 3},
};
multi::array_ref<double, 2> ref(&darr[0][0], {4, 5});
multi::array_ref<double, 2, double const*> cref(&darr[0][0], {4, 5});
multi::array_ref<double const, 2> crefc(&darr[0][0], {4, 5});
multi::array_cref<double, 2> ref2(&darr[0][0], {4, 5});
multi::array_ref<int, 2> ref(&darr[0][0], {4, 5});
multi::array_ref<int, 2, int const*> cref(&darr[0][0], {4, 5});
multi::array_ref<int const, 2> crefc(&darr[0][0], {4, 5});
multi::array_cref<int, 2> ref2(&darr[0][0], {4, 5});

BOOST_TEST( &ref[1][2] == &cref [1][2] );
BOOST_TEST( &ref[1][2] == &crefc[1][2] );
BOOST_TEST( &ref[1][2] == & ref2[1][2] );

ref[1][1] = 2.0;
ref[1][1] = 20;
BOOST_TEST( ref[1][1] == 20 );

#if defined(__clang__)
#pragma clang diagnostic push
Expand All @@ -680,19 +682,20 @@ BOOST_AUTO_TEST_CASE(array_ref_original_tests_carray) {
#endif

// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) test legacy type
double darr2[4][5] = {
{1.0, 0.0},
{2.0, 3.0},
int darr2[4][5] = {
{10, 00},
{20, 30},
};

darr2[1][0] = 2.0;
darr2[1][0] = 20;
BOOST_TEST( darr2[1][0] == 20 );

// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) test legacy type
auto const& dd = std::as_const(darr2);

BOOST_TEST( &(dd[1][2]) == &(darr2[1][2]) );
BOOST_TEST(( & ref[1].static_array_cast<double, double const*>()[1] == &ref[1][1] ));
BOOST_TEST(( &multi::static_array_cast<double, double const*>(ref[1])[1] == &ref[1][1] ));
BOOST_TEST(( & ref[1].static_array_cast<int, int const*>()[1] == &ref[1][1] ));
BOOST_TEST(( &multi::static_array_cast<int, int const*>(ref[1])[1] == &ref[1][1] ));

#if defined(__clang__)
#pragma clang diagnostic pop
Expand Down Expand Up @@ -1130,31 +1133,32 @@ BOOST_AUTO_TEST_CASE(diagonal) {
}

BOOST_AUTO_TEST_CASE(function_passing) {
multi::array<double, 2> arr({3, 3});
multi::array_ref<double, 2>& arrR = arr;
multi::array<int, 2> arr({3, 3});
multi::array_ref<int, 2>& arrR = arr;

arrR[0][0] = 2.1;
arrR[0][0] = 21;

arr.reextent({5, 5});

assert(&arrR[0][0] == &arr[0][0]);
BOOST_TEST( arr [0][0] == 21 );
BOOST_TEST(&arrR[0][0] == &arr[0][0]);
}

BOOST_AUTO_TEST_CASE(function_passing_2) {
multi::Array<double, 2> arr({3, 3});
[[maybe_unused]] multi::Array<double&, 2> arrR = arr;
multi::Array<int, 2> arr({3, 3});
[[maybe_unused]] multi::Array<int&, 2> arrR = arr;

arrR[0][0] = 5.1;
arrR[0][0] = 51;

[[maybe_unused]] multi::Array<double const&, 2> arrCR = arr;
[[maybe_unused]] multi::Array<int const&, 2> arrCR = arr;

assert(&arrCR[0][0] == &arrR[0][0]);
BOOST_TEST(&arrCR[0][0] == &arrR[0][0]);

[[maybe_unused]] multi::Array<double const&, 2> arrCR2 = arrCR;
[[maybe_unused]] multi::Array<int const&, 2> arrCR2 = arrCR;

arr.reextent({5, 5});

assert(&arrR[0][0] == &arr[0][0]);
BOOST_TEST( arrR[0][0] == 51 );
BOOST_TEST(&arrR[0][0] == &arr[0][0]);
}

BOOST_AUTO_TEST_CASE(function_passing_3) {
Expand Down
2 changes: 2 additions & 0 deletions test/assignments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro

src[0][1][2][3][1] = 99;

BOOST_TEST( src[0][1][2][3][1] == 99 );

// BOOST_TEST( tmp.unrotated().partitioned(2).transposed().rotated().extensions() == src.extensions() );
// BOOST_TEST( extensions(tmp.unrotated().partitioned(2).transposed().rotated()) == extensions(src) );
}
Expand Down
12 changes: 7 additions & 5 deletions test/element_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,16 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
}

BOOST_AUTO_TEST_CASE(elements_rvalues_assignment) {
std::vector<double> vec = {1.0, 2.0, 3.0}; // NOLINT(fuchsia-default-arguments-calls)
std::vector<int> vec = {10, 20, 30}; // NOLINT(fuchsia-default-arguments-calls)

std::move(vec) = std::vector<double>{3.0, 4.0, 5.0}; // NOLINT(fuchsia-default-arguments-calls)
std::move(vec) = std::vector<int>{30, 40, 50}; // NOLINT(fuchsia-default-arguments-calls)

std::move(vec)[1] = 99.0; // it compiles // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) for testing purposes
std::move(vec)[1] = 990; // it compiles // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) for testing purposes

multi::array<double, 1> arr1 = {1.0, 2.0, 3.0};
multi::array<double, 1> const arr2 = {1.0, 2.0, 3.0};
BOOST_TEST( vec[1] == 990 ); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) for testing purposes

multi::array<int, 1> arr1 = {10, 20, 30};
multi::array<int, 1> const arr2 = {10, 20, 30};

std::move(arr1) = arr2; // this compiles TODO(correaa) should it?
}
Expand Down
2 changes: 2 additions & 0 deletions test/flatted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ BOOST_AUTO_TEST_CASE(array_flatted_2d) {
BOOST_TEST( arr.flatted()[4] == 4 );

arr.flatted()[4] = 44;

BOOST_TEST( arr.flatted()[4] == 44 );
}

BOOST_AUTO_TEST_CASE(array_flatted_3d) {
Expand Down
102 changes: 53 additions & 49 deletions test/index_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,87 @@

#include <boost/multi/array_ref.hpp>

#include <boost/core/lightweight_test.hpp>

#include <algorithm> // for equal
#include <numeric> // for accumulate
#include <vector> // for vector

namespace multi = boost::multi;

#include <boost/core/lightweight_test.hpp>
#define BOOST_AUTO_TEST_CASE(CasenamE) /**/

auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugprone-exception-escape)
BOOST_AUTO_TEST_CASE(multi_range_in_constexpr) {
BOOST_TEST(( multi::extension_t<int>{5, 12}.contains(10) ));
BOOST_AUTO_TEST_CASE(multi_range_in_constexpr) {
BOOST_TEST(( multi::extension_t<int>{5, 12}.contains(10) ));

multi::range<int> const irng{ 5, 12 };
multi::range<int> const irng{5, 12};

BOOST_TEST( irng.contains(6) );
BOOST_TEST( !irng.contains(12) );
BOOST_TEST( irng.contains( 6) );
BOOST_TEST( irng.contains(11) );
BOOST_TEST( !irng.contains(12) );

BOOST_TEST( * irng.begin() == 5 );
BOOST_TEST( *(irng.begin() + 1) == 6 );
BOOST_TEST( * irng.begin() == 5 );
BOOST_TEST( *(irng.begin() + 1) == 6 );

BOOST_TEST( irng.first() == 5 );
BOOST_TEST( irng.last() == 12 );
BOOST_TEST( irng.first() == 5 );
BOOST_TEST( irng.last() == 12 );

BOOST_TEST( irng.front() == 5 );
BOOST_TEST( irng.back () == 11 );
BOOST_TEST( irng.front() == 5 );
BOOST_TEST( irng.back () == 11 );

std::vector<int> vec = { 5, 6, 7, 8, 9, 10, 11 }; // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls)
std::vector<int> vec = {5, 6, 7, 8, 9, 10, 11}; // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls)

BOOST_TEST(std::equal(irng.begin(), irng.end(), vec.begin(), vec.end())); // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls)
BOOST_TEST(std::equal(irng.begin(), irng.end(), vec.begin(), vec.end())); // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls)

auto sum = std::accumulate(irng.begin(), irng.end(), 0);
BOOST_TEST( sum == 5 + 6 + 7 + 8 + 9 + 10 + 11 );
}
auto sum = std::accumulate(irng.begin(), irng.end(), 0);
BOOST_TEST( sum == 5 + 6 + 7 + 8 + 9 + 10 + 11 );
}

BOOST_AUTO_TEST_CASE(multi_range2) {
multi::index_extension const iex(10);
BOOST_AUTO_TEST_CASE(multi_range2) {
multi::index_extension const iex(10);

BOOST_TEST( *begin(iex) == 0 );
BOOST_TEST( size(iex) == 10 );
BOOST_TEST( iex[0] == 0 );
BOOST_TEST( iex[1] == 1 );
BOOST_TEST( iex[9] == 9 );
BOOST_TEST( *begin(iex) == 0 );
BOOST_TEST( size(iex) == 10 );
BOOST_TEST( iex[0] == 0 );
BOOST_TEST( iex[1] == 1 );
BOOST_TEST( iex[9] == 9 );

auto const xbeg = begin(iex);
BOOST_TEST( xbeg[0] == iex[0] );
BOOST_TEST( xbeg[1] == iex[1] );
auto const xbeg = begin(iex);
BOOST_TEST( xbeg[0] == iex[0] );
BOOST_TEST( xbeg[1] == iex[1] );

BOOST_TEST( std::accumulate( begin(iex), end(iex), static_cast<multi::index_extension::value_type>(0U)) == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 );
BOOST_TEST( std::accumulate( begin(iex), end(iex), static_cast<multi::index_extension::value_type>(0U)) == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 );

{
multi::iextensions<3> const ies({
{0, 3},
{0, 4},
{0, 5},
});
{
multi::iextensions<3> const ies({
{0, 3},
{0, 4},
{0, 5},
});

using std::get;
using std::get;

auto const ies0 = get<0>(ies);
auto const ies1 = get<1>(ies);
auto const ies2 = get<2>(ies);
auto const ies0 = get<0>(ies);
auto const ies1 = get<1>(ies);
auto const ies2 = get<2>(ies);

BOOST_TEST( ies0.size() == 3 );
BOOST_TEST( ies1.size() == 4 );
BOOST_TEST( ies2.size() == 5 );
BOOST_TEST( ies0.size() == 3 );
BOOST_TEST( ies1.size() == 4 );
BOOST_TEST( ies2.size() == 5 );

BOOST_TEST( get<0>(ies).size() == 3 );
BOOST_TEST( get<1>(ies).size() == 4 );
BOOST_TEST( get<2>(ies).size() == 5 );
BOOST_TEST( get<0>(ies).size() == 3 );
BOOST_TEST( get<1>(ies).size() == 4 );
BOOST_TEST( get<2>(ies).size() == 5 );

#ifndef _MSC_VER // doesn't work in MSVC 14.3 in c++17 mode
auto const [eyes, jays, kays] = ies;
BOOST_TEST( eyes.size() == 3 );
BOOST_TEST( jays.size() == 4 );
BOOST_TEST( kays.size() == 5 );
auto const [eyes, jays, kays] = ies;
BOOST_TEST( eyes.size() == 3 );
BOOST_TEST( jays.size() == 4 );
BOOST_TEST( kays.size() == 5 );
#endif
}
}

return boost::report_errors();
}
return boost::report_errors();}
8 changes: 5 additions & 3 deletions test/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
BOOST_TEST( arrlast + 1 == arrend );
}
{
std::vector<double> vec(10000); // std::vector NOLINT(fuchsia-default-arguments-calls)
multi::array_ref<double, 2> arr(vec.data(), {100, 100});
std::vector<int> vec(10000); // std::vector NOLINT(fuchsia-default-arguments-calls)
multi::array_ref<int, 2> arr(vec.data(), {100, 100});
BOOST_TEST(arr.size() == 100);
begin(arr)[4][3] = 2.0;
begin(arr)[4][3] = 20;

BOOST_TEST(begin(arr)[4][3] == 20);
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ BOOST_AUTO_TEST_CASE(layout_AA) {
BOOST_TEST( size(B2) == 4 );
B2[3][3] = 99;

BOOST_TEST( B2[3][3] == 99 );

multi::array<int, 2> B2copy{B2({0, 2}, {0, 2})};

auto B2copy2 = B2({0, 2}, {0, 2}).decay();
Expand Down
Loading

0 comments on commit 74166cf

Please sign in to comment.