Line data Source code
1 : // SPDX-License-Identifier: BSD-3-Clause 2 : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 3 : /// @file 4 : /// @author Simon Heybrock 5 : #pragma once 6 : 7 : // Warnings are raised by eigen headers with gcc12 8 : #pragma GCC diagnostic push 9 : #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 10 : #include <Eigen/Core> 11 : #pragma GCC diagnostic pop 12 : 13 : #include <Eigen/Geometry> 14 : 15 : #include "scipp/common/numeric.h" 16 : #include "scipp/core/bucket.h" 17 : #include "scipp/core/dtype.h" 18 : #include "scipp/core/spatial_transforms.h" 19 : 20 : namespace scipp::core { 21 : 22 : template <> inline constexpr DType dtype<Eigen::Vector3d>{4000}; 23 : // 4001-4004 defined in spatial_transforms.h 24 : template <> 25 : inline constexpr DType dtype<scipp::span<const Eigen::Vector3d>>{4100}; 26 : template <> inline constexpr DType dtype<scipp::span<Eigen::Vector3d>>{4200}; 27 : 28 7001 : constexpr bool is_structured(DType tp) { 29 20887 : return tp == dtype<Eigen::Vector3d> || tp == dtype<Eigen::Matrix3d> || 30 20765 : tp == dtype<scipp::core::Quaternion> || tp == dtype<Eigen::Affine3d> || 31 20865 : tp == dtype<scipp::core::Translation> || tp == dtype<index_pair>; 32 : } 33 : 34 : } // namespace scipp::core 35 : 36 : namespace scipp::numeric { 37 : 38 28 : template <> inline bool isnan<Eigen::Vector3d>(const Eigen::Vector3d &x) { 39 28 : return x.hasNaN(); 40 : } 41 : 42 14 : template <> inline bool isfinite<Eigen::Vector3d>(const Eigen::Vector3d &x) { 43 14 : return x.allFinite(); 44 : } 45 : 46 0 : template <> inline bool isinf<Eigen::Vector3d>(const Eigen::Vector3d &x) { 47 0 : return !isfinite(x) && !isnan(x); 48 : } 49 : 50 0 : [[nodiscard]] inline bool operator==(const Eigen::Affine3d &a, 51 : const Eigen::Affine3d &b) { 52 0 : return a.matrix() == b.matrix(); 53 : } 54 : 55 0 : [[nodiscard]] inline bool operator!=(const Eigen::Affine3d &a, 56 : const Eigen::Affine3d &b) { 57 0 : return a.matrix() != b.matrix(); 58 : } 59 : 60 : } // namespace scipp::numeric