blob: 4d8479b27b896c0a14d1ef1e6eb6e50f45ab97c3 [file] [log] [blame]
Sergiu Deitsch182cb012022-02-01 21:11:14 +01001// 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 Agarwalcaf614a2022-04-21 17:41:10 -070037namespace ceres::internal {
Sergiu Deitsch182cb012022-02-01 21:11:14 +010038
39using J = Jet<double, 2>;
40// Don't care about the dual part for scalar part categorization and comparison
41// tests
42template <typename T>
43using J0 = Jet<T, 0>;
44using J0d = J0<double>;
45
Sergiu Deitsch182cb012022-02-01 21:11:14 +010046// Extract the ranks of given types
47using Ranks001 = Ranks_t<Jet<double, 0>, double, Jet<double, 1>>;
48using Ranks1 = Ranks_t<Jet<double, 1>>;
49using Ranks110 = Ranks_t<Jet<double, 1>, Jet<double, 1>, double>;
50using Ranks023 = Ranks_t<double, Jet<double, 2>, Jet<double, 3>>;
51using EmptyRanks = Ranks_t<>;
52
53// Ensure extracted ranks match the expected integer sequence
54static_assert(
55 std::is_same<Ranks001, std::integer_sequence<int, 0, 0, 1>>::value,
56 "ranks do not match");
57static_assert(std::is_same<Ranks1, std::integer_sequence<int, 1>>::value,
58 "ranks do not match");
59static_assert(
60 std::is_same<Ranks110, std::integer_sequence<int, 1, 1, 0>>::value,
61 "ranks do not match");
62static_assert(
63 std::is_same<Ranks023, std::integer_sequence<int, 0, 2, 3>>::value,
64 "ranks do not match");
65static_assert(std::is_same<EmptyRanks, std::integer_sequence<int>>::value,
66 "ranks sequence is not empty");
67
68// Extract the underlying floating-point type
69static_assert(std::is_same<UnderlyingScalar_t<double>, double>::value,
70 "underlying type is not a double");
71static_assert(std::is_same<UnderlyingScalar_t<J0d>, double>::value,
72 "underlying type is not a double");
73static_assert(std::is_same<UnderlyingScalar_t<J0<J0d>>, double>::value,
74 "underlying type is not a double");
75static_assert(std::is_same<UnderlyingScalar_t<J0<J0<J0d>>>, double>::value,
76 "underlying type is not a double");
77
78static_assert(CompatibleJetOperands_v<Jet<double, 1>, Jet<double, 1>>,
79 "Jets must be compatible");
80static_assert(CompatibleJetOperands_v<Jet<double, 1>, double>,
81 "Jet and scalar must be compatible");
82static_assert(CompatibleJetOperands_v<Jet<double, 2>>,
83 "single Jet must be compatible");
84static_assert(!CompatibleJetOperands_v<Jet<double, 1>, double, Jet<double, 2>>,
85 "Jets and scalar must not be compatible");
86static_assert(!CompatibleJetOperands_v<double, double>,
87 "scalars must not be compatible");
88static_assert(!CompatibleJetOperands_v<double>,
89 "single scalar must not be compatible");
90static_assert(!CompatibleJetOperands_v<>,
91 "empty arguments must not be compatible");
92
93static_assert(!PromotableJetOperands_v<double>,
94 "single scalar must not be Jet promotable");
95static_assert(!PromotableJetOperands_v<double, float, int>,
96 "multiple scalars must not be Jet promotable");
97static_assert(PromotableJetOperands_v<J0d, float, int>,
98 "Jet and several scalars must be promotable");
99static_assert(PromotableJetOperands_v<J0<J0d>, float, int>,
100 "nested Jet and several scalars must be promotable");
101static_assert(!PromotableJetOperands_v<Eigen::Array<double, 2, 3>, float, int>,
102 "Eigen::Array must not be Jet promotable");
103static_assert(!PromotableJetOperands_v<Eigen::Matrix<double, 3, 2>, float, int>,
104 "Eigen::Matrix must not be Jet promotable");
105
Sameer Agarwalcaf614a2022-04-21 17:41:10 -0700106} // namespace ceres::internal