mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Specialized enable_borrowed_ranges for VectorwiseOp class range iteration
libeigen/eigen!2127 Closes #2882
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
1a2b80727c
commit
d0654a201b
@@ -732,4 +732,14 @@ EIGEN_DEVICE_FUNC inline typename DenseBase<Derived>::RowwiseReturnType DenseBas
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
/* Enable use of VectorwiseOp types inside
|
||||
* of std::ranges algorithms. */
|
||||
#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L
|
||||
namespace std {
|
||||
template <typename VecwiseOp, Eigen::DirectionType Direction>
|
||||
inline constexpr bool ranges::enable_borrowed_range<Eigen::internal::subvector_stl_iterator<VecwiseOp, Direction>> =
|
||||
true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // EIGEN_PARTIAL_REDUX_H
|
||||
|
||||
@@ -304,6 +304,13 @@ if(NOT EIGEN_TEST_NO_EXCEPTIONS)
|
||||
endif()
|
||||
ei_add_test(prec_inverse_4x4)
|
||||
ei_add_test(vectorwiseop)
|
||||
if("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
if(MSVC)
|
||||
ei_add_test(vectorwiseop_ranges "/std:c++20")
|
||||
else()
|
||||
ei_add_test(vectorwiseop_ranges "-std=c++20")
|
||||
endif()
|
||||
endif()
|
||||
ei_add_test(special_numbers)
|
||||
ei_add_test(rvalue_types)
|
||||
ei_add_test(dense_storage)
|
||||
@@ -497,6 +504,7 @@ if(EIGEN_TEST_SYCL)
|
||||
set(EIGEN_SYCL OFF)
|
||||
endif()
|
||||
|
||||
|
||||
cmake_dependent_option(EIGEN_TEST_BUILD_DOCUMENTATION "Test building the doxygen documentation" OFF "EIGEN_BUILD_DOC" OFF)
|
||||
if(EIGEN_TEST_BUILD_DOCUMENTATION)
|
||||
add_dependencies(buildtests doc)
|
||||
|
||||
@@ -241,11 +241,11 @@ EIGEN_DECLARE_TEST(vectorwiseop) {
|
||||
CALL_SUBTEST_3(vectorwiseop_array(ArrayXXf(3, 4)));
|
||||
CALL_SUBTEST_4(vectorwiseop_matrix(Matrix4cf()));
|
||||
CALL_SUBTEST_5(vectorwiseop_matrix(Matrix4f()));
|
||||
CALL_SUBTEST_5(vectorwiseop_matrix(Vector4f()));
|
||||
CALL_SUBTEST_5(vectorwiseop_matrix(Matrix<float, 4, 5>()));
|
||||
CALL_SUBTEST_6(vectorwiseop_matrix(
|
||||
CALL_SUBTEST_6(vectorwiseop_matrix(Vector4f()));
|
||||
CALL_SUBTEST_7(vectorwiseop_matrix(Matrix<float, 4, 5>()));
|
||||
CALL_SUBTEST_8(vectorwiseop_matrix(
|
||||
MatrixXd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
CALL_SUBTEST_7(vectorwiseop_matrix(VectorXd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
CALL_SUBTEST_7(vectorwiseop_matrix(RowVectorXd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
CALL_SUBTEST_8(vectorwiseop_mixedscalar());
|
||||
CALL_SUBTEST_9(vectorwiseop_matrix(VectorXd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
CALL_SUBTEST_10(vectorwiseop_matrix(RowVectorXd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
CALL_SUBTEST_11(vectorwiseop_mixedscalar());
|
||||
}
|
||||
|
||||
31
test/vectorwiseop_ranges.cpp
Normal file
31
test/vectorwiseop_ranges.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
|
||||
// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#define TEST_ENABLE_TEMPORARY_TRACKING
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L
|
||||
#include <ranges>
|
||||
#endif
|
||||
|
||||
void vectorwiseop_use_in_std_ranges() {
|
||||
// verify basic std::ranges functionality; noop if ranges not present
|
||||
#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L
|
||||
Matrix3f a = Matrix3f::Random();
|
||||
int count = 0;
|
||||
std::ranges::for_each(a.colwise(), [&count](auto&& col) { count += col.count(); });
|
||||
VERIFY_IS_EQUAL(count, 9);
|
||||
std::ranges::for_each(a.rowwise(), [&count](auto&& row) { count += row.count(); });
|
||||
VERIFY_IS_EQUAL(count, 18);
|
||||
#endif
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(vectorwiseop_ranges) { CALL_SUBTEST_1(vectorwiseop_use_in_std_ranges()); }
|
||||
Reference in New Issue
Block a user