1// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2013 Google Inc. All rights reserved.
3// http://code.google.com/p/ceres-solver/
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: sameeragarwal@google.com (Sameer Agarwal)
30//         mierle@gmail.com (Keir Mierle)
31
32#ifndef CERES_PUBLIC_INTERNAL_VARIADIC_EVALUATE_H_
33#define CERES_PUBLIC_INTERNAL_VARIADIC_EVALUATE_H_
34
35#include <stddef.h>
36
37#include "ceres/jet.h"
38#include "ceres/internal/eigen.h"
39#include "ceres/internal/fixed_array.h"
40#include "glog/logging.h"
41
42namespace ceres {
43namespace internal {
44
45// This block of quasi-repeated code calls the user-supplied functor, which may
46// take a variable number of arguments. This is accomplished by specializing the
47// struct based on the size of the trailing parameters; parameters with 0 size
48// are assumed missing.
49template<typename Functor, typename T, int N0, int N1, int N2, int N3, int N4,
50         int N5, int N6, int N7, int N8, int N9>
51struct VariadicEvaluate {
52  static bool Call(const Functor& functor, T const *const *input, T* output) {
53    return functor(input[0],
54                   input[1],
55                   input[2],
56                   input[3],
57                   input[4],
58                   input[5],
59                   input[6],
60                   input[7],
61                   input[8],
62                   input[9],
63                   output);
64  }
65};
66
67template<typename Functor, typename T, int N0, int N1, int N2, int N3, int N4,
68         int N5, int N6, int N7, int N8>
69struct VariadicEvaluate<Functor, T, N0, N1, N2, N3, N4, N5, N6, N7, N8, 0> {
70  static bool Call(const Functor& functor, T const *const *input, T* output) {
71    return functor(input[0],
72                   input[1],
73                   input[2],
74                   input[3],
75                   input[4],
76                   input[5],
77                   input[6],
78                   input[7],
79                   input[8],
80                   output);
81  }
82};
83
84template<typename Functor, typename T, int N0, int N1, int N2, int N3, int N4,
85         int N5, int N6, int N7>
86struct VariadicEvaluate<Functor, T, N0, N1, N2, N3, N4, N5, N6, N7, 0, 0> {
87  static bool Call(const Functor& functor, T const *const *input, T* output) {
88    return functor(input[0],
89                   input[1],
90                   input[2],
91                   input[3],
92                   input[4],
93                   input[5],
94                   input[6],
95                   input[7],
96                   output);
97  }
98};
99
100template<typename Functor, typename T, int N0, int N1, int N2, int N3, int N4,
101         int N5, int N6>
102struct VariadicEvaluate<Functor, T, N0, N1, N2, N3, N4, N5, N6, 0, 0, 0> {
103  static bool Call(const Functor& functor, T const *const *input, T* output) {
104    return functor(input[0],
105                   input[1],
106                   input[2],
107                   input[3],
108                   input[4],
109                   input[5],
110                   input[6],
111                   output);
112  }
113};
114
115template<typename Functor, typename T, int N0, int N1, int N2, int N3, int N4,
116         int N5>
117struct VariadicEvaluate<Functor, T, N0, N1, N2, N3, N4, N5, 0, 0, 0, 0> {
118  static bool Call(const Functor& functor, T const *const *input, T* output) {
119    return functor(input[0],
120                   input[1],
121                   input[2],
122                   input[3],
123                   input[4],
124                   input[5],
125                   output);
126  }
127};
128
129template<typename Functor, typename T, int N0, int N1, int N2, int N3, int N4>
130struct VariadicEvaluate<Functor, T, N0, N1, N2, N3, N4, 0, 0, 0, 0, 0> {
131  static bool Call(const Functor& functor, T const *const *input, T* output) {
132    return functor(input[0],
133                   input[1],
134                   input[2],
135                   input[3],
136                   input[4],
137                   output);
138  }
139};
140
141template<typename Functor, typename T, int N0, int N1, int N2, int N3>
142struct VariadicEvaluate<Functor, T, N0, N1, N2, N3, 0, 0, 0, 0, 0, 0> {
143  static bool Call(const Functor& functor, T const *const *input, T* output) {
144    return functor(input[0],
145                   input[1],
146                   input[2],
147                   input[3],
148                   output);
149  }
150};
151
152template<typename Functor, typename T, int N0, int N1, int N2>
153struct VariadicEvaluate<Functor, T, N0, N1, N2, 0, 0, 0, 0, 0, 0, 0> {
154  static bool Call(const Functor& functor, T const *const *input, T* output) {
155    return functor(input[0],
156                   input[1],
157                   input[2],
158                   output);
159  }
160};
161
162template<typename Functor, typename T, int N0, int N1>
163struct VariadicEvaluate<Functor, T, N0, N1, 0, 0, 0, 0, 0, 0, 0, 0> {
164  static bool Call(const Functor& functor, T const *const *input, T* output) {
165    return functor(input[0],
166                   input[1],
167                   output);
168  }
169};
170
171template<typename Functor, typename T, int N0>
172struct VariadicEvaluate<Functor, T, N0, 0, 0, 0, 0, 0, 0, 0, 0, 0> {
173  static bool Call(const Functor& functor, T const *const *input, T* output) {
174    return functor(input[0],
175                   output);
176  }
177};
178
179}  // namespace internal
180}  // namespace ceres
181
182#endif  // CERES_PUBLIC_INTERNAL_VARIADIC_EVALUATE_H_
183