pybind11/tests/test_eigen_tensor.inl

339 lines
11 KiB
Plaintext
Raw Normal View History

First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
/*
tests/eigen_tensor.cpp -- automatic conversion of Eigen Tensor
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#include <pybind11/eigen/tensor.h>
PYBIND11_NAMESPACE_BEGIN(eigen_tensor_test)
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
namespace py = pybind11;
PYBIND11_WARNING_DISABLE_MSVC(4127)
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
template <typename M>
void reset_tensor(M &x) {
for (int i = 0; i < x.dimension(0); i++) {
for (int j = 0; j < x.dimension(1); j++) {
for (int k = 0; k < x.dimension(2); k++) {
x(i, j, k) = i * (5 * 2) + j * 2 + k;
}
}
}
}
template <typename M>
bool check_tensor(M &x) {
for (int i = 0; i < x.dimension(0); i++) {
for (int j = 0; j < x.dimension(1); j++) {
for (int k = 0; k < x.dimension(2); k++) {
if (x(i, j, k) != (i * (5 * 2) + j * 2 + k)) {
return false;
}
}
}
}
return true;
}
template <int Options>
Eigen::Tensor<double, 3, Options> &get_tensor() {
static Eigen::Tensor<double, 3, Options> *x;
if (!x) {
x = new Eigen::Tensor<double, 3, Options>(3, 5, 2);
reset_tensor(*x);
}
return *x;
}
template <int Options>
Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> &get_tensor_map() {
static Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> *x;
if (!x) {
x = new Eigen::TensorMap<Eigen::Tensor<double, 3, Options>>(get_tensor<Options>());
}
return *x;
}
template <int Options>
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options> &get_fixed_tensor() {
static Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options> *x;
if (!x) {
Eigen::aligned_allocator<Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>>
allocator;
x = new (allocator.allocate(1))
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>();
reset_tensor(*x);
}
return *x;
}
template <int Options>
const Eigen::Tensor<double, 3, Options> &get_const_tensor() {
return get_tensor<Options>();
}
template <int Options>
struct CustomExample {
CustomExample() : member(get_tensor<Options>()), view_member(member) {}
Eigen::Tensor<double, 3, Options> member;
Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> view_member;
};
template <int Options>
void init_tensor_module(pybind11::module &m) {
const char *needed_options = "";
if (Options == Eigen::ColMajor) {
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
needed_options = "F";
} else {
needed_options = "C";
}
m.attr("needed_options") = needed_options;
m.def("setup", []() {
reset_tensor(get_tensor<Options>());
reset_tensor(get_fixed_tensor<Options>());
});
m.def("is_ok", []() {
return check_tensor(get_tensor<Options>()) && check_tensor(get_fixed_tensor<Options>());
});
py::class_<CustomExample<Options>>(m, "CustomExample", py::module_local())
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
.def(py::init<>())
.def_readonly(
"member", &CustomExample<Options>::member, py::return_value_policy::reference_internal)
.def_readonly("member_view",
&CustomExample<Options>::view_member,
py::return_value_policy::reference_internal);
m.def(
"copy_fixed_tensor",
[]() { return &get_fixed_tensor<Options>(); },
py::return_value_policy::copy);
2024-04-02 15:14:08 +00:00
m.def("copy_tensor", []() { return &get_tensor<Options>(); }, py::return_value_policy::copy);
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
m.def(
"copy_const_tensor",
[]() { return &get_const_tensor<Options>(); },
py::return_value_policy::copy);
m.def(
"move_fixed_tensor_copy",
[]() -> Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options> {
return get_fixed_tensor<Options>();
},
py::return_value_policy::move);
m.def(
"move_tensor_copy",
[]() -> Eigen::Tensor<double, 3, Options> { return get_tensor<Options>(); },
py::return_value_policy::move);
m.def(
"move_const_tensor",
[]() -> const Eigen::Tensor<double, 3, Options> & { return get_const_tensor<Options>(); },
py::return_value_policy::move);
m.def(
"take_fixed_tensor",
[]() {
Eigen::aligned_allocator<
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>>
allocator;
clang-tidy upgrade (to version 18) (#5272) * `container: silkeh/clang:18-bookworm` in .github/workflows/format.yml * clang-tidy auto-fix (trivial, in test only) * Disable `performance-enum-size` (noisy, low value) * Temporarily turn off 3 diagnostics (to be tackled one-by-one). * Add explicit `switch` `default` to resolve clang-tidy `bugprone-switch-missing-default-case` Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_numpy_dtypes.cpp:212:5: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case] * Add clang-17 and clang-18 testing. * Add `NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)` in test_tagbased_polymorphic.cpp Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_tagbased_polymorphic.cpp:77:40: warning: The value '150' provided to the cast expression is not in the valid range of values for 'Kind' [clang-analyzer-optin.core.EnumCastOutOfRange] * Fix inconsistent pybind11/eigen/tensor.h behavior: This existing comment in pybind11/eigen/tensor.h ``` // move, take_ownership don't make any sense for a ref/map: ``` is at odds with the `delete src;` three lines up. In real-world client code `take_ownership` will not exist (unless the client code is untested and unused). I.e. the `delete` is essentially only useful to avoid leaks in the pybind11 unit tests. While upgrading to clang-tidy 18, the warning below appeared. Apparently it is produced during LTO, and it appears difficult to suppress. Regardless, the best way to resolve this is to remove the `delete` and to simply make the test objects `static` in the unit test code. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` lto-wrapper: warning: using serial compilation of 3 LTRANS jobs lto-wrapper: note: see the ‘-flto’ option documentation for more information In function ‘cast_impl’, inlined from ‘cast’ at /mounted_pybind11/include/pybind11/eigen/tensor.h:414:25, inlined from ‘operator()’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:296:40, inlined from ‘_FUN’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:267:21: /mounted_pybind11/include/pybind11/eigen/tensor.h:475:17: warning: ‘operator delete’ called on unallocated object ‘<anonymous>’ [-Wfree-nonheap-object] 475 | delete src; | ^ /mounted_pybind11/include/pybind11/eigen/../pybind11.h: In function ‘_FUN’: /mounted_pybind11/include/pybind11/eigen/../pybind11.h:297:75: note: declared here 297 | std::move(args_converter).template call<Return, Guard>(cap->f), | ^ ``` * Disable `bugprone-chained-comparison`: this clang-tidy check is incompatible with the Catch2 `REQUIRE` macro (26 warnings like the one below). ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: warning: chained comparison 'v0 <= v1 == v2' may generate unintended results, use parentheses to specify order of evaluation or a logical operator to separate comparison expressions [bugprone-chained-comparison] 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: note: operand 'v0' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:17: note: operand 'v1' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:24: note: operand 'v2' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ ``` * Add 8 `// NOLINT(bugprone-empty-catch)` * Resolve clang-tidy `bugprone-multi-level-implicit-pointer-conversion` warnings. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` pybind11/detail/internals.h:556:53: warning: multilevel pointer conversion from 'internals **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/detail/type_caster_base.h:431:20: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:904:81: warning: multilevel pointer conversion from '_object *const *' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const double *>::type *' (aka 'const double **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const VectorizeTestClass *>::type *' (aka 'const VectorizeTestClass **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:75:44: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:83:42: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] ``` * Introduce `PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY` to resolve PyPy build errors: ``` In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:75:17: error: no matching function for call to 'PyPyUnicode_FSConverter' if (PyUnicode_FSConverter(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^~~~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:970:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSConverter(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^ In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:83:17: error: no matching function for call to 'PyPyUnicode_FSDecoder' if (PyUnicode_FSDecoder(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:972:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSDecoder(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^ ``` * clang-tidy auto-fix * Fix silly oversight.
2024-07-29 18:10:03 +00:00
static auto *obj = new (allocator.allocate(1))
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>(
get_fixed_tensor<Options>());
clang-tidy upgrade (to version 18) (#5272) * `container: silkeh/clang:18-bookworm` in .github/workflows/format.yml * clang-tidy auto-fix (trivial, in test only) * Disable `performance-enum-size` (noisy, low value) * Temporarily turn off 3 diagnostics (to be tackled one-by-one). * Add explicit `switch` `default` to resolve clang-tidy `bugprone-switch-missing-default-case` Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_numpy_dtypes.cpp:212:5: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case] * Add clang-17 and clang-18 testing. * Add `NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)` in test_tagbased_polymorphic.cpp Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_tagbased_polymorphic.cpp:77:40: warning: The value '150' provided to the cast expression is not in the valid range of values for 'Kind' [clang-analyzer-optin.core.EnumCastOutOfRange] * Fix inconsistent pybind11/eigen/tensor.h behavior: This existing comment in pybind11/eigen/tensor.h ``` // move, take_ownership don't make any sense for a ref/map: ``` is at odds with the `delete src;` three lines up. In real-world client code `take_ownership` will not exist (unless the client code is untested and unused). I.e. the `delete` is essentially only useful to avoid leaks in the pybind11 unit tests. While upgrading to clang-tidy 18, the warning below appeared. Apparently it is produced during LTO, and it appears difficult to suppress. Regardless, the best way to resolve this is to remove the `delete` and to simply make the test objects `static` in the unit test code. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` lto-wrapper: warning: using serial compilation of 3 LTRANS jobs lto-wrapper: note: see the ‘-flto’ option documentation for more information In function ‘cast_impl’, inlined from ‘cast’ at /mounted_pybind11/include/pybind11/eigen/tensor.h:414:25, inlined from ‘operator()’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:296:40, inlined from ‘_FUN’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:267:21: /mounted_pybind11/include/pybind11/eigen/tensor.h:475:17: warning: ‘operator delete’ called on unallocated object ‘<anonymous>’ [-Wfree-nonheap-object] 475 | delete src; | ^ /mounted_pybind11/include/pybind11/eigen/../pybind11.h: In function ‘_FUN’: /mounted_pybind11/include/pybind11/eigen/../pybind11.h:297:75: note: declared here 297 | std::move(args_converter).template call<Return, Guard>(cap->f), | ^ ``` * Disable `bugprone-chained-comparison`: this clang-tidy check is incompatible with the Catch2 `REQUIRE` macro (26 warnings like the one below). ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: warning: chained comparison 'v0 <= v1 == v2' may generate unintended results, use parentheses to specify order of evaluation or a logical operator to separate comparison expressions [bugprone-chained-comparison] 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: note: operand 'v0' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:17: note: operand 'v1' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:24: note: operand 'v2' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ ``` * Add 8 `// NOLINT(bugprone-empty-catch)` * Resolve clang-tidy `bugprone-multi-level-implicit-pointer-conversion` warnings. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` pybind11/detail/internals.h:556:53: warning: multilevel pointer conversion from 'internals **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/detail/type_caster_base.h:431:20: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:904:81: warning: multilevel pointer conversion from '_object *const *' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const double *>::type *' (aka 'const double **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const VectorizeTestClass *>::type *' (aka 'const VectorizeTestClass **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:75:44: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:83:42: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] ``` * Introduce `PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY` to resolve PyPy build errors: ``` In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:75:17: error: no matching function for call to 'PyPyUnicode_FSConverter' if (PyUnicode_FSConverter(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^~~~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:970:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSConverter(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^ In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:83:17: error: no matching function for call to 'PyPyUnicode_FSDecoder' if (PyUnicode_FSDecoder(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:972:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSDecoder(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^ ``` * clang-tidy auto-fix * Fix silly oversight.
2024-07-29 18:10:03 +00:00
return obj; // take_ownership will fail.
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
},
py::return_value_policy::take_ownership);
m.def(
"take_tensor",
clang-tidy upgrade (to version 18) (#5272) * `container: silkeh/clang:18-bookworm` in .github/workflows/format.yml * clang-tidy auto-fix (trivial, in test only) * Disable `performance-enum-size` (noisy, low value) * Temporarily turn off 3 diagnostics (to be tackled one-by-one). * Add explicit `switch` `default` to resolve clang-tidy `bugprone-switch-missing-default-case` Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_numpy_dtypes.cpp:212:5: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case] * Add clang-17 and clang-18 testing. * Add `NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)` in test_tagbased_polymorphic.cpp Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_tagbased_polymorphic.cpp:77:40: warning: The value '150' provided to the cast expression is not in the valid range of values for 'Kind' [clang-analyzer-optin.core.EnumCastOutOfRange] * Fix inconsistent pybind11/eigen/tensor.h behavior: This existing comment in pybind11/eigen/tensor.h ``` // move, take_ownership don't make any sense for a ref/map: ``` is at odds with the `delete src;` three lines up. In real-world client code `take_ownership` will not exist (unless the client code is untested and unused). I.e. the `delete` is essentially only useful to avoid leaks in the pybind11 unit tests. While upgrading to clang-tidy 18, the warning below appeared. Apparently it is produced during LTO, and it appears difficult to suppress. Regardless, the best way to resolve this is to remove the `delete` and to simply make the test objects `static` in the unit test code. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` lto-wrapper: warning: using serial compilation of 3 LTRANS jobs lto-wrapper: note: see the ‘-flto’ option documentation for more information In function ‘cast_impl’, inlined from ‘cast’ at /mounted_pybind11/include/pybind11/eigen/tensor.h:414:25, inlined from ‘operator()’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:296:40, inlined from ‘_FUN’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:267:21: /mounted_pybind11/include/pybind11/eigen/tensor.h:475:17: warning: ‘operator delete’ called on unallocated object ‘<anonymous>’ [-Wfree-nonheap-object] 475 | delete src; | ^ /mounted_pybind11/include/pybind11/eigen/../pybind11.h: In function ‘_FUN’: /mounted_pybind11/include/pybind11/eigen/../pybind11.h:297:75: note: declared here 297 | std::move(args_converter).template call<Return, Guard>(cap->f), | ^ ``` * Disable `bugprone-chained-comparison`: this clang-tidy check is incompatible with the Catch2 `REQUIRE` macro (26 warnings like the one below). ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: warning: chained comparison 'v0 <= v1 == v2' may generate unintended results, use parentheses to specify order of evaluation or a logical operator to separate comparison expressions [bugprone-chained-comparison] 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: note: operand 'v0' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:17: note: operand 'v1' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:24: note: operand 'v2' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ ``` * Add 8 `// NOLINT(bugprone-empty-catch)` * Resolve clang-tidy `bugprone-multi-level-implicit-pointer-conversion` warnings. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` pybind11/detail/internals.h:556:53: warning: multilevel pointer conversion from 'internals **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/detail/type_caster_base.h:431:20: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:904:81: warning: multilevel pointer conversion from '_object *const *' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const double *>::type *' (aka 'const double **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const VectorizeTestClass *>::type *' (aka 'const VectorizeTestClass **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:75:44: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:83:42: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] ``` * Introduce `PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY` to resolve PyPy build errors: ``` In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:75:17: error: no matching function for call to 'PyPyUnicode_FSConverter' if (PyUnicode_FSConverter(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^~~~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:970:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSConverter(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^ In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:83:17: error: no matching function for call to 'PyPyUnicode_FSDecoder' if (PyUnicode_FSDecoder(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:972:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSDecoder(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^ ``` * clang-tidy auto-fix * Fix silly oversight.
2024-07-29 18:10:03 +00:00
[]() {
static auto *obj = new Eigen::Tensor<double, 3, Options>(get_tensor<Options>());
return obj; // take_ownership will fail.
},
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
py::return_value_policy::take_ownership);
m.def(
"take_const_tensor",
[]() -> const Eigen::Tensor<double, 3, Options> * {
clang-tidy upgrade (to version 18) (#5272) * `container: silkeh/clang:18-bookworm` in .github/workflows/format.yml * clang-tidy auto-fix (trivial, in test only) * Disable `performance-enum-size` (noisy, low value) * Temporarily turn off 3 diagnostics (to be tackled one-by-one). * Add explicit `switch` `default` to resolve clang-tidy `bugprone-switch-missing-default-case` Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_numpy_dtypes.cpp:212:5: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case] * Add clang-17 and clang-18 testing. * Add `NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)` in test_tagbased_polymorphic.cpp Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_tagbased_polymorphic.cpp:77:40: warning: The value '150' provided to the cast expression is not in the valid range of values for 'Kind' [clang-analyzer-optin.core.EnumCastOutOfRange] * Fix inconsistent pybind11/eigen/tensor.h behavior: This existing comment in pybind11/eigen/tensor.h ``` // move, take_ownership don't make any sense for a ref/map: ``` is at odds with the `delete src;` three lines up. In real-world client code `take_ownership` will not exist (unless the client code is untested and unused). I.e. the `delete` is essentially only useful to avoid leaks in the pybind11 unit tests. While upgrading to clang-tidy 18, the warning below appeared. Apparently it is produced during LTO, and it appears difficult to suppress. Regardless, the best way to resolve this is to remove the `delete` and to simply make the test objects `static` in the unit test code. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` lto-wrapper: warning: using serial compilation of 3 LTRANS jobs lto-wrapper: note: see the ‘-flto’ option documentation for more information In function ‘cast_impl’, inlined from ‘cast’ at /mounted_pybind11/include/pybind11/eigen/tensor.h:414:25, inlined from ‘operator()’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:296:40, inlined from ‘_FUN’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:267:21: /mounted_pybind11/include/pybind11/eigen/tensor.h:475:17: warning: ‘operator delete’ called on unallocated object ‘<anonymous>’ [-Wfree-nonheap-object] 475 | delete src; | ^ /mounted_pybind11/include/pybind11/eigen/../pybind11.h: In function ‘_FUN’: /mounted_pybind11/include/pybind11/eigen/../pybind11.h:297:75: note: declared here 297 | std::move(args_converter).template call<Return, Guard>(cap->f), | ^ ``` * Disable `bugprone-chained-comparison`: this clang-tidy check is incompatible with the Catch2 `REQUIRE` macro (26 warnings like the one below). ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: warning: chained comparison 'v0 <= v1 == v2' may generate unintended results, use parentheses to specify order of evaluation or a logical operator to separate comparison expressions [bugprone-chained-comparison] 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: note: operand 'v0' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:17: note: operand 'v1' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:24: note: operand 'v2' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ ``` * Add 8 `// NOLINT(bugprone-empty-catch)` * Resolve clang-tidy `bugprone-multi-level-implicit-pointer-conversion` warnings. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` pybind11/detail/internals.h:556:53: warning: multilevel pointer conversion from 'internals **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/detail/type_caster_base.h:431:20: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:904:81: warning: multilevel pointer conversion from '_object *const *' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const double *>::type *' (aka 'const double **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const VectorizeTestClass *>::type *' (aka 'const VectorizeTestClass **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:75:44: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:83:42: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] ``` * Introduce `PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY` to resolve PyPy build errors: ``` In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:75:17: error: no matching function for call to 'PyPyUnicode_FSConverter' if (PyUnicode_FSConverter(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^~~~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:970:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSConverter(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^ In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:83:17: error: no matching function for call to 'PyPyUnicode_FSDecoder' if (PyUnicode_FSDecoder(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:972:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSDecoder(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^ ``` * clang-tidy auto-fix * Fix silly oversight.
2024-07-29 18:10:03 +00:00
static auto *obj = new Eigen::Tensor<double, 3, Options>(get_tensor<Options>());
return obj; // take_ownership will fail.
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
},
py::return_value_policy::take_ownership);
m.def(
"take_view_tensor",
[]() -> const Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> * {
clang-tidy upgrade (to version 18) (#5272) * `container: silkeh/clang:18-bookworm` in .github/workflows/format.yml * clang-tidy auto-fix (trivial, in test only) * Disable `performance-enum-size` (noisy, low value) * Temporarily turn off 3 diagnostics (to be tackled one-by-one). * Add explicit `switch` `default` to resolve clang-tidy `bugprone-switch-missing-default-case` Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_numpy_dtypes.cpp:212:5: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case] * Add clang-17 and clang-18 testing. * Add `NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)` in test_tagbased_polymorphic.cpp Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu tests/test_tagbased_polymorphic.cpp:77:40: warning: The value '150' provided to the cast expression is not in the valid range of values for 'Kind' [clang-analyzer-optin.core.EnumCastOutOfRange] * Fix inconsistent pybind11/eigen/tensor.h behavior: This existing comment in pybind11/eigen/tensor.h ``` // move, take_ownership don't make any sense for a ref/map: ``` is at odds with the `delete src;` three lines up. In real-world client code `take_ownership` will not exist (unless the client code is untested and unused). I.e. the `delete` is essentially only useful to avoid leaks in the pybind11 unit tests. While upgrading to clang-tidy 18, the warning below appeared. Apparently it is produced during LTO, and it appears difficult to suppress. Regardless, the best way to resolve this is to remove the `delete` and to simply make the test objects `static` in the unit test code. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` lto-wrapper: warning: using serial compilation of 3 LTRANS jobs lto-wrapper: note: see the ‘-flto’ option documentation for more information In function ‘cast_impl’, inlined from ‘cast’ at /mounted_pybind11/include/pybind11/eigen/tensor.h:414:25, inlined from ‘operator()’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:296:40, inlined from ‘_FUN’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:267:21: /mounted_pybind11/include/pybind11/eigen/tensor.h:475:17: warning: ‘operator delete’ called on unallocated object ‘<anonymous>’ [-Wfree-nonheap-object] 475 | delete src; | ^ /mounted_pybind11/include/pybind11/eigen/../pybind11.h: In function ‘_FUN’: /mounted_pybind11/include/pybind11/eigen/../pybind11.h:297:75: note: declared here 297 | std::move(args_converter).template call<Return, Guard>(cap->f), | ^ ``` * Disable `bugprone-chained-comparison`: this clang-tidy check is incompatible with the Catch2 `REQUIRE` macro (26 warnings like the one below). ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: warning: chained comparison 'v0 <= v1 == v2' may generate unintended results, use parentheses to specify order of evaluation or a logical operator to separate comparison expressions [bugprone-chained-comparison] 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: note: operand 'v0' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:17: note: operand 'v1' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ /mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:24: note: operand 'v2' is here 127 | REQUIRE(ret == 42); | ^ /build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE' 17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) | ^~~~~~~~~~~ /build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST' 2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ | ^~~~~~~~~~~ ``` * Add 8 `// NOLINT(bugprone-empty-catch)` * Resolve clang-tidy `bugprone-multi-level-implicit-pointer-conversion` warnings. ________ Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143) Target: x86_64-pc-linux-gnu ________ ``` pybind11/detail/internals.h:556:53: warning: multilevel pointer conversion from 'internals **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/detail/type_caster_base.h:431:20: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:904:81: warning: multilevel pointer conversion from '_object *const *' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const double *>::type *' (aka 'const double **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const VectorizeTestClass *>::type *' (aka 'const VectorizeTestClass **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:75:44: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] pybind11/stl/filesystem.h:83:42: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion] ``` * Introduce `PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY` to resolve PyPy build errors: ``` In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:75:17: error: no matching function for call to 'PyPyUnicode_FSConverter' if (PyUnicode_FSConverter(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^~~~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:970:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSConverter(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter' ^ In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18: /Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:83:17: error: no matching function for call to 'PyPyUnicode_FSDecoder' if (PyUnicode_FSDecoder(buf, reinterpret_cast<void *>(&native)) != 0) { ^~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^~~~~~~~~~~~~~~~~~~~~ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:972:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument PyAPI_FUNC(int) PyUnicode_FSDecoder(struct _object *arg0, struct _object **arg1); ^ /Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder' ^ ``` * clang-tidy auto-fix * Fix silly oversight.
2024-07-29 18:10:03 +00:00
static auto *obj
= new Eigen::TensorMap<Eigen::Tensor<double, 3, Options>>(get_tensor<Options>());
return obj; // take_ownership will fail.
First draft of Eigen::Tensor support (#4201) * First draft of Eigen::Tensor support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix build errors * Weird allocator stuff? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unused + additional allocator junk * Disable warning * Use constexpr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove auto constexpr function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try again for older C++ * Oops forgot constexpr * Move to new files as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix weird tests * Fix nits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Oops, forgot import * Fix clang 3.6 bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More comprehensive test suite * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor allocators to make things more clear * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to std::copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Switch to DSizes instead of array * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix python + dummy c++ change to trigger build * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Alignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add include guard * Forgot inline * Fix compiler warning * Remove bad test * Better type signatures * Add guards to make compiler requirements more explicit * style: pre-commit fixes * Force rerun of tests due to flake * style: pre-commit fixes * Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC * Move headers out of detail * style: pre-commit fixes * Fix cmake * Improve casting * style: pre-commit fixes * Add a ton more tests + refactor * Improve names * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * Fix tests * style: pre-commit fixes * Update * Add a test to verify that strange numpy arrays work * Fix dumb compiler warning * Better tests * Better tests * Fix tests * style: pre-commit fixes * More test fixes * style: pre-commit fixes * A ton more test coverage * Fix tests * style: pre-commit fixes * style: pre-commit fixes * Add back constexpr * Another test * style: pre-commit fixes * Improve tests * Whoops * Less magic numbers * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * Update tests/test_eigen_tensor.py Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com> * style: pre-commit fixes * Fix tests * style: pre-commit fixes * Fix memory leak * style: pre-commit fixes * Fix order * style: pre-commit fixes * Add test to make sure unsafe casts fail * Minor bug fix to work on 32 bit machines * Implement convert flag * style: pre-commit fixes * Switch to correct TensorMap const use * style: pre-commit fixes * Support older versions of eigen * Weird c++ compilers * Fix Eigen bug * Fix another eigen bug * Yet another eigen bug * Potential flakes? * style: pre-commit fixes * Rerun tests with dummy exception to find out what is going on * Another dummy test run * Ablate more * Found the broken test? * One step closer * one step further * Double check * one thing at a time * Give up and disable the test * Clang lies about being gcc * Oops, fix matrix test * style: pre-commit fixes * Add tests to verify scalar conversions * style: pre-commit fixes * Fix nits * Support no_array * Fix tests * style: pre-commit fixes * Silence compiler warning * Improve build system for ancient compilers * Make clang happy * Make gcc happy * Implement Skylion's suggestions * Fix warning * Inline const pointer check * Implement suggestions * style: pre-commit fixes * Improve tests * Typo * style: pre-commit fixes * Support Google's build environment * style: pre-commit fixes * Update include/pybind11/eigen/tensor.h Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes * Test cleanup per Skylion * Switch to remvove_cv_t * Cleaner test * style: pre-commit fixes * Remove tensor from eigen.h, update tests * style: pre-commit fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
},
py::return_value_policy::take_ownership);
m.def(
"reference_tensor",
[]() { return &get_tensor<Options>(); },
py::return_value_policy::reference);
m.def(
"reference_tensor_v2",
[]() -> Eigen::Tensor<double, 3, Options> & { return get_tensor<Options>(); },
py::return_value_policy::reference);
m.def(
"reference_tensor_internal",
[]() { return &get_tensor<Options>(); },
py::return_value_policy::reference_internal);
m.def(
"reference_fixed_tensor",
[]() { return &get_tensor<Options>(); },
py::return_value_policy::reference);
m.def(
"reference_const_tensor",
[]() { return &get_const_tensor<Options>(); },
py::return_value_policy::reference);
m.def(
"reference_const_tensor_v2",
[]() -> const Eigen::Tensor<double, 3, Options> & { return get_const_tensor<Options>(); },
py::return_value_policy::reference);
m.def(
"reference_view_of_tensor",
[]() -> Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> {
return get_tensor_map<Options>();
},
py::return_value_policy::reference);
m.def(
"reference_view_of_tensor_v2",
// NOLINTNEXTLINE(readability-const-return-type)
[]() -> const Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> {
return get_tensor_map<Options>(); // NOLINT(readability-const-return-type)
}, // NOLINT(readability-const-return-type)
py::return_value_policy::reference);
m.def(
"reference_view_of_tensor_v3",
[]() -> Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> * {
return &get_tensor_map<Options>();
},
py::return_value_policy::reference);
m.def(
"reference_view_of_tensor_v4",
[]() -> const Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> * {
return &get_tensor_map<Options>();
},
py::return_value_policy::reference);
m.def(
"reference_view_of_tensor_v5",
[]() -> Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> & {
return get_tensor_map<Options>();
},
py::return_value_policy::reference);
m.def(
"reference_view_of_tensor_v6",
[]() -> const Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> & {
return get_tensor_map<Options>();
},
py::return_value_policy::reference);
m.def(
"reference_view_of_fixed_tensor",
[]() {
return Eigen::TensorMap<
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>>(
get_fixed_tensor<Options>());
},
py::return_value_policy::reference);
m.def("round_trip_tensor",
[](const Eigen::Tensor<double, 3, Options> &tensor) { return tensor; });
m.def(
"round_trip_tensor_noconvert",
[](const Eigen::Tensor<double, 3, Options> &tensor) { return tensor; },
py::arg("tensor").noconvert());
m.def("round_trip_tensor2",
[](const Eigen::Tensor<int32_t, 3, Options> &tensor) { return tensor; });
m.def("round_trip_fixed_tensor",
[](const Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options> &tensor) {
return tensor;
});
m.def(
"round_trip_view_tensor",
[](Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> view) { return view; },
py::return_value_policy::reference);
m.def(
"round_trip_view_tensor_ref",
[](Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> &view) { return view; },
py::return_value_policy::reference);
m.def(
"round_trip_view_tensor_ptr",
[](Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> *view) { return view; },
py::return_value_policy::reference);
m.def(
"round_trip_aligned_view_tensor",
[](Eigen::TensorMap<Eigen::Tensor<double, 3, Options>, Eigen::Aligned> view) {
return view;
},
py::return_value_policy::reference);
m.def(
"round_trip_const_view_tensor",
[](Eigen::TensorMap<const Eigen::Tensor<double, 3, Options>> view) {
return Eigen::Tensor<double, 3, Options>(view);
},
py::return_value_policy::move);
m.def(
"round_trip_rank_0",
[](const Eigen::Tensor<double, 0, Options> &tensor) { return tensor; },
py::return_value_policy::move);
m.def(
"round_trip_rank_0_noconvert",
[](const Eigen::Tensor<double, 0, Options> &tensor) { return tensor; },
py::arg("tensor").noconvert(),
py::return_value_policy::move);
m.def(
"round_trip_rank_0_view",
[](Eigen::TensorMap<Eigen::Tensor<double, 0, Options>> &tensor) { return tensor; },
py::return_value_policy::reference);
}
void test_module(py::module_ &m) {
auto f_style = m.def_submodule("f_style");
auto c_style = m.def_submodule("c_style");
init_tensor_module<Eigen::ColMajor>(f_style);
init_tensor_module<Eigen::RowMajor>(c_style);
}
PYBIND11_NAMESPACE_END(eigen_tensor_test)