Sergiu Deitsch | 182cb01 | 2022-02-01 21:11:14 +0100 | [diff] [blame] | 1 | // Ceres Solver - A fast non-linear least squares minimizer |
| 2 | // Copyright 2022 Google Inc. All rights reserved. |
| 3 | // http://ceres-solver.org/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | // this list of conditions and the following disclaimer in the documentation |
| 12 | // and/or other materials provided with the distribution. |
| 13 | // * Neither the name of Google Inc. nor the names of its contributors may be |
| 14 | // used to endorse or promote products derived from this software without |
| 15 | // specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | // POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Author: sergiu.deitsch@gmail.com (Sergiu Deitsch) |
| 30 | |
| 31 | #include "ceres/internal/jet_traits.h" |
| 32 | |
| 33 | #include <Eigen/Core> |
| 34 | #include <type_traits> |
| 35 | #include <utility> |
| 36 | |
Sameer Agarwal | caf614a | 2022-04-21 17:41:10 -0700 | [diff] [blame] | 37 | namespace ceres::internal { |
Sergiu Deitsch | 182cb01 | 2022-02-01 21:11:14 +0100 | [diff] [blame] | 38 | |
| 39 | using J = Jet<double, 2>; |
| 40 | // Don't care about the dual part for scalar part categorization and comparison |
| 41 | // tests |
| 42 | template <typename T> |
| 43 | using J0 = Jet<T, 0>; |
| 44 | using J0d = J0<double>; |
| 45 | |
Sergiu Deitsch | 182cb01 | 2022-02-01 21:11:14 +0100 | [diff] [blame] | 46 | // Extract the ranks of given types |
| 47 | using Ranks001 = Ranks_t<Jet<double, 0>, double, Jet<double, 1>>; |
| 48 | using Ranks1 = Ranks_t<Jet<double, 1>>; |
| 49 | using Ranks110 = Ranks_t<Jet<double, 1>, Jet<double, 1>, double>; |
| 50 | using Ranks023 = Ranks_t<double, Jet<double, 2>, Jet<double, 3>>; |
| 51 | using EmptyRanks = Ranks_t<>; |
| 52 | |
| 53 | // Ensure extracted ranks match the expected integer sequence |
| 54 | static_assert( |
| 55 | std::is_same<Ranks001, std::integer_sequence<int, 0, 0, 1>>::value, |
| 56 | "ranks do not match"); |
| 57 | static_assert(std::is_same<Ranks1, std::integer_sequence<int, 1>>::value, |
| 58 | "ranks do not match"); |
| 59 | static_assert( |
| 60 | std::is_same<Ranks110, std::integer_sequence<int, 1, 1, 0>>::value, |
| 61 | "ranks do not match"); |
| 62 | static_assert( |
| 63 | std::is_same<Ranks023, std::integer_sequence<int, 0, 2, 3>>::value, |
| 64 | "ranks do not match"); |
| 65 | static_assert(std::is_same<EmptyRanks, std::integer_sequence<int>>::value, |
| 66 | "ranks sequence is not empty"); |
| 67 | |
| 68 | // Extract the underlying floating-point type |
| 69 | static_assert(std::is_same<UnderlyingScalar_t<double>, double>::value, |
| 70 | "underlying type is not a double"); |
| 71 | static_assert(std::is_same<UnderlyingScalar_t<J0d>, double>::value, |
| 72 | "underlying type is not a double"); |
| 73 | static_assert(std::is_same<UnderlyingScalar_t<J0<J0d>>, double>::value, |
| 74 | "underlying type is not a double"); |
| 75 | static_assert(std::is_same<UnderlyingScalar_t<J0<J0<J0d>>>, double>::value, |
| 76 | "underlying type is not a double"); |
| 77 | |
| 78 | static_assert(CompatibleJetOperands_v<Jet<double, 1>, Jet<double, 1>>, |
| 79 | "Jets must be compatible"); |
| 80 | static_assert(CompatibleJetOperands_v<Jet<double, 1>, double>, |
| 81 | "Jet and scalar must be compatible"); |
| 82 | static_assert(CompatibleJetOperands_v<Jet<double, 2>>, |
| 83 | "single Jet must be compatible"); |
| 84 | static_assert(!CompatibleJetOperands_v<Jet<double, 1>, double, Jet<double, 2>>, |
| 85 | "Jets and scalar must not be compatible"); |
| 86 | static_assert(!CompatibleJetOperands_v<double, double>, |
| 87 | "scalars must not be compatible"); |
| 88 | static_assert(!CompatibleJetOperands_v<double>, |
| 89 | "single scalar must not be compatible"); |
| 90 | static_assert(!CompatibleJetOperands_v<>, |
| 91 | "empty arguments must not be compatible"); |
| 92 | |
| 93 | static_assert(!PromotableJetOperands_v<double>, |
| 94 | "single scalar must not be Jet promotable"); |
| 95 | static_assert(!PromotableJetOperands_v<double, float, int>, |
| 96 | "multiple scalars must not be Jet promotable"); |
| 97 | static_assert(PromotableJetOperands_v<J0d, float, int>, |
| 98 | "Jet and several scalars must be promotable"); |
| 99 | static_assert(PromotableJetOperands_v<J0<J0d>, float, int>, |
| 100 | "nested Jet and several scalars must be promotable"); |
| 101 | static_assert(!PromotableJetOperands_v<Eigen::Array<double, 2, 3>, float, int>, |
| 102 | "Eigen::Array must not be Jet promotable"); |
| 103 | static_assert(!PromotableJetOperands_v<Eigen::Matrix<double, 3, 2>, float, int>, |
| 104 | "Eigen::Matrix must not be Jet promotable"); |
| 105 | |
Sameer Agarwal | caf614a | 2022-04-21 17:41:10 -0700 | [diff] [blame] | 106 | } // namespace ceres::internal |