Skip to content

Commit b2ba242

Browse files
committed
Merge branch 'array_traits-in-detail' into 'master'
array traits See merge request correaa/boost-multi!1758
2 parents dc17a59 + cf99166 commit b2ba242

9 files changed

Lines changed: 62 additions & 41 deletions

File tree

.gitlab-ci-correaa.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ vs2022-shell:
400400
stage: build
401401
allow_failure: false
402402
interruptible: true
403+
cache: []
403404
before_script: [] # override global before_script (bash commands don't work on Windows shell runner)
404405
script:
405406
- pwd
@@ -475,6 +476,7 @@ vs2022-shell cudatk-17:
475476
stage: build
476477
allow_failure: false
477478
interruptible: true
479+
cache: []
478480
only:
479481
refs:
480482
- master
@@ -499,6 +501,7 @@ vs2022-shell cudatk:
499501
stage: build
500502
allow_failure: false
501503
interruptible: true
504+
cache: []
502505
script:
503506
- whoami
504507
- $env:Path += ";C:/vcpkg/installed/x64-windows/bin;${CI_PROJECT_DIR}/vcpkg/installed/x64-windows/bin;C:\Program Files\CMake\bin;C:\Program Files\7-Zip;C:\local\boost_1_86_0\lib"

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ project(
4949
VERSION 0.88.0
5050
LANGUAGES CXX)
5151

52+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
53+
5254
message(STATUS "Boost.Multi: standalone mode ON")
5355

5456
add_library(multi INTERFACE)

include/boost/multi/adaptors/blas/core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2025 Alfredo A. Correa
1+
// Copyright 2019-2026 Alfredo A. Correa
22
// Distributed under the Boost Software License, Version 1.0.
33
// https://www.boost.org/LICENSE_1_0.txt
44

include/boost/multi/adaptors/fftw/test/core.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
184184
in.base(), in.layout(), out.base(), out.layout());
185185
pln.execute(in.base(), out.base());
186186

187-
BOOST_TEST( power(in) - (power(out)/static_cast<double>(num_elements(out))) < 1e-7 );
187+
BOOST_TEST( power(in) - (power(out)/static_cast<double>(out.num_elements())) < 1e-7 );
188188
}
189189

190190
// BOOST_AUTO_TEST_CASE(fftw_2D_power_plan_modern)
@@ -201,7 +201,7 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
201201
},
202202
in.base(), in.layout(), out.base(), out.layout());
203203
pln.execute(in.base(), out.base());
204-
BOOST_TEST( power(in) - (power(out)/static_cast<double>(num_elements(out))) < 1e-8 );
204+
BOOST_TEST( power(in) - (power(out)/static_cast<double>(out.num_elements())) < 1e-8 );
205205
}
206206

207207
// BOOST_AUTO_TEST_CASE(fftw_2D_power_plan_modern_measure)
@@ -213,12 +213,15 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
213213
multi::array<complex, 2> in({16, 16});
214214
std::iota(in.elements().begin(), in.elements().end(), 1.2); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic): test code
215215
multi::array<complex, 2> out(extensions(in));
216-
auto const pln = multi::fftw::plan::forward({
217-
{true, true}
216+
217+
auto const pln = multi::fftw::plan::forward(
218+
{
219+
{true, true}
218220
},
219-
in.base(), in.layout(), out.base(), out.layout());
221+
in.base(), in.layout(), out.base(), out.layout()
222+
);
220223
pln.execute(in.base(), out.base());
221-
BOOST_TEST( power(in) - (power(out)/static_cast<double>(num_elements(out))) < 1e-8 );
224+
BOOST_TEST( power(in) - (power(out)/static_cast<double>(out.num_elements())) < 1e-8 );
222225
}
223226

224227
// BOOST_AUTO_TEST_CASE(fftw_2D_power_dft)
@@ -233,7 +236,7 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
233236
{true, true}
234237
},
235238
in, out);
236-
BOOST_TEST( power(in) - (power(out)/static_cast<double>(num_elements(out))) < 1e-8 );
239+
BOOST_TEST( power(in) - (power(out)/static_cast<double>(out.num_elements())) < 1e-8 );
237240
}
238241

239242
// BOOST_AUTO_TEST_CASE(fftw_3D_power_in_place_over_ref_inplace)
@@ -255,7 +258,7 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
255258
multi::array_ref<complex, 3>(data_elements(io), extensions(io)),
256259
multi::array_ref<complex, 3>(data_elements(io), extensions(io))
257260
);
258-
BOOST_TEST( powerin - (power(io)/static_cast<double>(num_elements(io))) < 1e-10 );
261+
BOOST_TEST( powerin - (power(io)/static_cast<double>(io.num_elements())) < 1e-10 );
259262
}
260263

261264
// BOOST_AUTO_TEST_CASE(fftw_2D_const_range_ref)

include/boost/multi/array.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ auto decay(T const (&arr)[N]) noexcept -> multi::array<std::remove_all_extents_t
16871687
}
16881688

16891689
template<class T, std::size_t N>
1690-
struct array_traits<T[N], void, void> { // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) : for backwards compatibility
1690+
struct detail::array_traits<T[N], void, void> { // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) : for backwards compatibility
16911691
using reference = T&;
16921692
using element = std::remove_all_extents_t<T[N]>; // NOSONAR(cpp:S5945) NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) : for backwards compatibility
16931693
using decay_type = multi::array<T, 1>;

include/boost/multi/array_ref.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ template<> inline constexpr bool force_element_trivial_destruction<std::complex<
7171
#include "boost/multi/detail/serialization.hpp"
7272
#include "boost/multi/detail/types.hpp" // for dimensionality_type // IWYU pragma: export
7373

74-
#include <algorithm> // fpr copy_n
75-
#include <array>
74+
#include <algorithm> // for copy_n
75+
#include <array> // for std::array
7676
#include <cstring> // for std::memset in reinterpret_cast
7777
#include <functional> // for std::invoke
7878
#include <iterator> // for std::next
7979
#include <memory> // for std::pointer_traits
8080
#include <new> // for std::launder
81-
// #include <vector> // for std::vector (for conversion)
8281

8382
#if __has_include(<span>)
8483
#if !defined(_MSVC_LANG) || (_MSVC_LANG > 202002L)
@@ -260,14 +259,14 @@ struct array_types : private Layout { // cppcheck-suppress syntaxError ; false
260259
using layout_t::is_compact;
261260

262261
// friend constexpr auto size(array_types const& self) noexcept -> size_type { return self.size(); }
263-
friend BOOST_MULTI_HD constexpr auto extension(array_types const& self) noexcept -> extension_type { return self.extension(); }
264-
friend constexpr auto num_elements(array_types const& self) noexcept -> size_type { return self.num_elements(); }
262+
// friend BOOST_MULTI_HD constexpr auto extension(array_types const& self) noexcept -> extension_type { return self.extension(); }
263+
// friend constexpr auto num_elements(array_types const& self) noexcept -> size_type { return self.num_elements(); }
265264

266-
friend constexpr auto extensions(array_types const& self) noexcept -> extensions_type { return self.extensions(); }
265+
// friend constexpr auto extensions(array_types const& self) noexcept -> extensions_type { return self.extensions(); }
267266
friend constexpr auto sizes(array_types const& self) noexcept -> sizes_type { return self.sizes(); }
268267

269268
// TODO(correaa) [[deprecated("use member syntax for non-salient properties")]]
270-
friend constexpr auto stride(array_types const& self) noexcept -> stride_type { return self.stride(); }
269+
// friend constexpr auto stride(array_types const& self) noexcept -> stride_type { return self.stride(); }
271270

272271
// TODO(correaa) [[deprecated("use member syntax for non-salient properties")]]
273272
friend constexpr auto strides(array_types const& self) noexcept /*-> strides_type*/ { return self.strides(); }
@@ -908,7 +907,7 @@ struct elements_iterator_t
908907
return *this;
909908
}
910909

911-
template<class = void> // TODO(correaa) lazy instantion to workaround MSVC linking limitations iterator copy for restrictions
910+
template<class = void> // TODO(correaa) lazy instantiation to workaround MSVC linking limitations iterator copy for restrictions
912911
BOOST_MULTI_HD constexpr auto operator++(int) -> elements_iterator_t {
913912
elements_iterator_t ret{*this};
914913
++(*this);
@@ -1822,14 +1821,14 @@ struct const_subarray : array_types<T, D, ElementPtr, Layout> {
18221821
BOOST_MULTI_HD constexpr auto cbegin() const& { return begin(); } ///< returns an (explicitly const-)iterator to the beginning
18231822
BOOST_MULTI_HD constexpr auto cend() const& { return end(); } ///< returns an (explicitly const-)iterator to the end
18241823

1825-
using cursor = cursor_t<typename const_subarray::element_ptr, D, typename const_subarray::strides_type>; // Cursor for the array, the cursor is indexable, and it has pointer semantics (returned by `home`)
1826-
using const_cursor = cursor_t<typename const_subarray::element_const_ptr, D, typename const_subarray::strides_type>; // const-cursor for the array
1824+
using cursor = cursor_t<typename const_subarray::element_ptr, D, typename const_subarray::strides_type>; ///< Cursor for access to the array, the cursor is indexable, and it has pointer semantics (returned by `home`)
1825+
using const_cursor = cursor_t<typename const_subarray::element_const_ptr, D, typename const_subarray::strides_type>; ///< Cursor for constant access to the array
18271826

18281827
private:
18291828
BOOST_MULTI_HD constexpr auto home_aux_() const { return cursor(this->base_, this->strides()); }
18301829

18311830
public:
1832-
BOOST_MULTI_HD constexpr auto home() const& -> const_cursor { return home_aux_(); } ///< Return a cursor pointing to the top corner element of the array, the cursor is indexed relative to this location
1831+
BOOST_MULTI_HD constexpr auto home() const& -> const_cursor { return home_aux_(); } ///< Return a cursor pointing to the top corner element of the array, the cursor is indexed relative to this location
18331832

18341833
template<
18351834
class Range,
@@ -4194,8 +4193,16 @@ constexpr auto uninitialized_copy
41944193
// to overwrite the behavior of std::begin and std::end
41954194
// which take rvalue-references as const-references.
41964195

4197-
template<class T> auto begin(T&& rng) -> decltype(std::forward<T>(rng).begin()) { return std::forward<T>(rng).begin(); }
4198-
template<class T> auto end(T&& rng) -> decltype(std::forward<T>(rng).end()) { return std::forward<T>(rng).end(); }
4196+
template<class T> constexpr auto begin(T&& rng) -> decltype(std::forward<T>(rng).begin()) { return std::forward<T>(rng).begin(); } ///< Returns the beginning of the range (generic free function, usually return .begin())
4197+
template<class T> constexpr auto end(T&& rng) -> decltype(std::forward<T>(rng).end()) { return std::forward<T>(rng).end(); } ///< Returns the end of the range (generic free function, usually return .begin())
4198+
4199+
// this has to take argument by forward reference to avoid collison with std::cbegin/std::cend
4200+
template<class T> constexpr auto cbegin(T&& rng) -> decltype(std::forward<T>(rng).begin()) { return std::forward<T>(rng).begin(); } ///< Returns the beginning of the range (for constant access, generic free function, usually return .begin())
4201+
template<class T> constexpr auto cend(T&& rng) -> decltype(std::forward<T>(rng).end()) { return std::forward<T>(rng).end(); } ///< Returns the end of the range (for constant access, generic free function, usually return .begin())
4202+
4203+
template<class T> /*[[deprecated("use extent")]]*/ auto extension(T const& rng) -> decltype(rng.extension()) { return rng.extension(); }
4204+
4205+
template<class T> constexpr auto stride(T const& rng) -> decltype(rng.stride()) { return rng.stride(); }
41994206

42004207
template<class T, std::size_t N, std::size_t M>
42014208
auto transposed(T (&array)[N][M]) -> decltype(auto) { return ~multi::array_ref<T, 2>(array); } // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)

include/boost/multi/utility.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ struct transform_ptr {
228228
#pragma clang diagnostic pop
229229
#endif
230230

231+
namespace detail {
231232
template<class Array, typename Reference = void, typename Element = void>
232233
struct array_traits;
233234

@@ -239,6 +240,7 @@ struct array_traits {
239240
using decay_type = typename Array::decay_type;
240241
using default_allocator_type = typename Array::default_allocator_type;
241242
};
243+
} // namespace detail
242244

243245
template<class Fun>
244246
class value_wrapper_ptr;
@@ -640,7 +642,7 @@ template<class T, std::size_t N>
640642
constexpr auto strides(T (&array)[N]) { return layout(array).strides(); } // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): for backward compatibility
641643

642644
template<class T, std::size_t N>
643-
struct array_traits<std::array<T, N>> {
645+
struct detail::array_traits<std::array<T, N>> {
644646
static constexpr auto dimensionality() -> dimensionality_type { return 1; }
645647

646648
using reference = T&;
@@ -652,7 +654,7 @@ struct array_traits<std::array<T, N>> {
652654
};
653655

654656
template<class T, std::size_t N, std::size_t M>
655-
struct array_traits<std::array<std::array<T, M>, N>> {
657+
struct detail::array_traits<std::array<std::array<T, M>, N>> {
656658
static constexpr auto dimensionality() -> dimensionality_type { return 1 + array_traits<std::array<T, M>>::dimensionality(); }
657659

658660
using reference = std::array<T, M>&;
@@ -717,7 +719,7 @@ constexpr auto stride(std::array<std::array<T, N>, M> const& arr) {
717719

718720
template<class T, std::size_t N>
719721
constexpr auto layout(std::array<T, N> const& arr) {
720-
return multi::layout_t<multi::array_traits<std::array<T, N>>::dimensionality()>{multi::extensions(arr)};
722+
return multi::layout_t<multi::detail::array_traits<std::array<T, N>>::dimensionality()>{multi::extensions(arr)};
721723
}
722724

723725
#ifdef __clang__

mrdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ source-root: include/
66
compilation-database: build-mrdocs/compile_commands.json
77

88
input:
9-
- include/boost/multi/array.hpp
109
- include/boost/multi/array_ref.hpp
10+
- include/boost/multi/array.hpp
1111

1212
output: doc/modules/reference/pages
1313

test/utility.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616

1717
namespace multi = boost::multi;
1818

19-
// TODO(correaa) add test for reinterpret_pointer_cast
20-
2119
#include <boost/core/lightweight_test.hpp>
22-
#define BOOST_AUTO_TEST_CASE(CasenamE) /**/
2320

2421
auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugprone-exception-escape)
25-
BOOST_AUTO_TEST_CASE(std_array_extensions_3d) {
22+
// BOOST_AUTO_TEST_CASE(std_array_extensions_3d)
23+
{
2624
std::array<std::array<std::array<double, 5>, 4>, 3> arr = {};
2725

28-
static_assert(std::is_same<typename multi::array_traits<decltype(arr)>::element, double>{}); // NOLINT(readability-redundant-typename) for C++20
26+
static_assert(std::is_same<typename multi::detail::array_traits<decltype(arr)>::element, double>{}); // NOLINT(readability-redundant-typename) for C++20
2927

3028
BOOST_TEST( multi::dimensionality(arr) == 3 );
3129

@@ -47,10 +45,11 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
4745
BOOST_TEST( multi::extensions(arr) == extensions(marr) );
4846
}
4947

50-
BOOST_AUTO_TEST_CASE(std_array_extensions_2d) {
48+
// BOOST_AUTO_TEST_CASE(std_array_extensions_2d)
49+
{
5150
std::array<std::array<double, 4>, 3> arr = {};
5251

53-
static_assert(std::is_same_v<typename multi::array_traits<decltype(arr)>::element, double>); // NOLINT(readability-redundant-typename) for C++20
52+
static_assert(std::is_same_v<typename multi::detail::array_traits<decltype(arr)>::element, double>); // NOLINT(readability-redundant-typename) for C++20
5453

5554
using multi::dimensionality;
5655
BOOST_TEST( dimensionality(arr) == 2 );
@@ -73,10 +72,11 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
7372
BOOST_TEST( extensions(arr) == extensions(marr) );
7473
}
7574

76-
BOOST_AUTO_TEST_CASE(std_array_extensions_1d) {
75+
// BOOST_AUTO_TEST_CASE(std_array_extensions_1d)
76+
{
7777
std::array<double, 4> arr = {};
7878

79-
static_assert(std::is_same_v<typename multi::array_traits<decltype(arr)>::element, double>); // NOLINT(readability-redundant-typename) for C++20
79+
static_assert(std::is_same_v<typename multi::detail::array_traits<decltype(arr)>::element, double>); // NOLINT(readability-redundant-typename) for C++20
8080

8181
using multi::dimensionality;
8282
BOOST_TEST( dimensionality(arr) == 1 );
@@ -95,7 +95,8 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
9595
BOOST_TEST( num_elements(arr) == 4 );
9696
}
9797

98-
BOOST_AUTO_TEST_CASE(test_utility_1d) {
98+
// BOOST_AUTO_TEST_CASE(test_utility_1d)
99+
{
99100
std::array<int, 10> carr = {
100101
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
101102
};
@@ -119,8 +120,9 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
119120
BOOST_TEST( &carr[7] == &marr[7] );
120121

121122
using multi::num_elements;
122-
BOOST_TEST( num_elements(carr) == num_elements(marr) );
123-
// BOOST_TEST( num_elements(varr) == num_elements(marr) );
123+
BOOST_TEST( num_elements(carr) == marr.num_elements() );
124+
// BOOST_TEST( varr.num_elements() == marr.num_elements() );
125+
using multi::num_elements; // for std::array, which doesn't have member function
124126
BOOST_TEST( num_elements(aarr) == num_elements(aarr) );
125127

126128
using multi::data_elements;
@@ -148,7 +150,8 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
148150
#endif
149151
}
150152

151-
BOOST_AUTO_TEST_CASE(test_utility_2d) {
153+
// BOOST_AUTO_TEST_CASE(test_utility_2d)
154+
{
152155
// clang-format off
153156
std::array<std::array<int, 10>, 3> carr{{
154157
{{ 00, 10, 20, 30, 40, 50, 60, 70, 80, 90 }},
@@ -172,7 +175,8 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
172175
BOOST_TEST( data_elements(carr) == data_elements(marr) );
173176
}
174177

175-
BOOST_AUTO_TEST_CASE(multi_utility_test) {
178+
// BOOST_AUTO_TEST_CASE(multi_utility_test)
179+
{
176180
static_assert(std::is_same_v<std::iterator_traits<int const*>::value_type, int>);
177181

178182
using multi::corigin;

0 commit comments

Comments
 (0)